Search in sources :

Example 36 with ASN1Object

use of org.eclipse.titan.designer.AST.ASN1.ASN1Object in project titan.EclipsePlug-ins by eclipse.

the class ObjectClassSyntax_Parser method parseObject.

private ASN1Object parseObject() {
    ASN1Object object = null;
    if (mBlock != null) {
        final Asn1Parser parser = BlockLevelTokenStreamTracker.getASN1ParserForBlock(mBlock, internalIndex);
        if (parser != null) {
            object = parser.pr_special_Object().object;
            internalIndex += parser.nof_consumed_tokens();
            final List<SyntacticErrorStorage> errors = parser.getErrorStorage();
            if (null != errors && !errors.isEmpty()) {
                for (int i = 0; i < errors.size(); i++) {
                    ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) mBlock.getLocation().getFile(), errors.get(i), IMarker.SEVERITY_ERROR);
                }
            }
        }
    }
    return object;
}
Also used : Asn1Parser(org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser) SyntacticErrorStorage(org.eclipse.titan.common.parsers.SyntacticErrorStorage) ASN1Object(org.eclipse.titan.designer.AST.ASN1.ASN1Object)

Example 37 with ASN1Object

use of org.eclipse.titan.designer.AST.ASN1.ASN1Object in project jruby-openssl by jruby.

the class PEMInputOutput method readPrivateKey.

/**
 * c: PEM_read_PrivateKey + PEM_read_bio_PrivateKey
 * CAUTION: KeyPair#getPublic() may be null.
 */
public static KeyPair readPrivateKey(final Reader in, char[] passwd) throws PasswordRequiredException, IOException {
    final String BEG_STRING_ECPRIVATEKEY = BEF_G + PEM_STRING_ECPRIVATEKEY;
    final String BEG_STRING_PKCS8INF = BEF_G + PEM_STRING_PKCS8INF;
    final String BEG_STRING_PKCS8 = BEF_G + PEM_STRING_PKCS8;
    final BufferedReader reader = makeBuffered(in);
    String line;
    while ((line = reader.readLine()) != null) {
        if (line.indexOf(BEG_STRING_RSA) != -1) {
            try {
                return readKeyPair(reader, passwd, "RSA", BEF_E + PEM_STRING_RSA);
            } catch (Exception e) {
                throw mapReadException("problem creating RSA private key: ", e);
            }
        } else if (line.indexOf(BEG_STRING_DSA) != -1) {
            try {
                return readKeyPair(reader, passwd, "DSA", BEF_E + PEM_STRING_DSA);
            } catch (Exception e) {
                throw mapReadException("problem creating DSA private key: ", e);
            }
        } else if (line.indexOf(BEG_STRING_ECPRIVATEKEY) != -1) {
            try {
                return readKeyPair(reader, passwd, "ECDSA", BEF_E + PEM_STRING_ECPRIVATEKEY);
            } catch (Exception e) {
                throw mapReadException("problem creating DSA private key: ", e);
            }
        } else if (line.indexOf(BEG_STRING_PKCS8INF) != -1) {
            try {
                byte[] bytes = readBase64Bytes(reader, BEF_E + PEM_STRING_PKCS8INF);
                PrivateKeyInfo info = PrivateKeyInfo.getInstance(bytes);
                String type = getPrivateKeyTypeFromObjectId(info.getPrivateKeyAlgorithm().getAlgorithm());
                return org.jruby.ext.openssl.impl.PKey.readPrivateKey(((ASN1Object) info.parsePrivateKey()).getEncoded(ASN1Encoding.DER), type);
            } catch (Exception e) {
                throw mapReadException("problem creating private key: ", e);
            }
        } else if (line.indexOf(BEG_STRING_PKCS8) != -1) {
            try {
                byte[] bytes = readBase64Bytes(reader, BEF_E + PEM_STRING_PKCS8);
                EncryptedPrivateKeyInfo eIn = EncryptedPrivateKeyInfo.getInstance(bytes);
                AlgorithmIdentifier algId = eIn.getEncryptionAlgorithm();
                PrivateKey privKey;
                if (algId.getAlgorithm().toString().equals("1.2.840.113549.1.5.13")) {
                    // PBES2
                    privKey = derivePrivateKeyPBES2(eIn, algId, passwd);
                } else {
                    privKey = derivePrivateKeyPBES1(eIn, algId, passwd);
                }
                return new KeyPair(null, privKey);
            } catch (Exception e) {
                throw mapReadException("problem creating private key: ", e);
            }
        }
    }
    return null;
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) ECPrivateKey(java.security.interfaces.ECPrivateKey) BufferedReader(java.io.BufferedReader) EncryptedPrivateKeyInfo(org.bouncycastle.asn1.pkcs.EncryptedPrivateKeyInfo) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DEROctetString(org.bouncycastle.asn1.DEROctetString) ASN1Object(org.bouncycastle.asn1.ASN1Object) GeneralSecurityException(java.security.GeneralSecurityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) CertificateEncodingException(java.security.cert.CertificateEncodingException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) CMSException(org.bouncycastle.cms.CMSException) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) IOException(java.io.IOException) CRLException(java.security.cert.CRLException) CertificateException(java.security.cert.CertificateException) EncryptedPrivateKeyInfo(org.bouncycastle.asn1.pkcs.EncryptedPrivateKeyInfo) PrivateKeyInfo(org.bouncycastle.asn1.pkcs.PrivateKeyInfo) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Aggregations

IOException (java.io.IOException)26 Asn1Object (com.android.hotspot2.asn1.Asn1Object)25 Asn1Constructed (com.android.hotspot2.asn1.Asn1Constructed)15 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 X509Certificate (java.security.cert.X509Certificate)11 Asn1Integer (com.android.hotspot2.asn1.Asn1Integer)10 DERBitString (com.android.org.bouncycastle.asn1.DERBitString)10 DERIA5String (com.android.org.bouncycastle.asn1.DERIA5String)10 DERPrintableString (com.android.org.bouncycastle.asn1.DERPrintableString)10 ByteBuffer (java.nio.ByteBuffer)10 KeyPair (java.security.KeyPair)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Set (java.util.Set)6 ASN1Object (org.bouncycastle.asn1.ASN1Object)6 I18Name (com.android.anqp.I18Name)5 Asn1Oid (com.android.hotspot2.asn1.Asn1Oid)5 Asn1String (com.android.hotspot2.asn1.Asn1String)5 OidMappings (com.android.hotspot2.asn1.OidMappings)5