Search in sources :

Example 36 with Asn1Object

use of com.android.hotspot2.asn1.Asn1Object in project candlepin by candlepin.

the class X509CRLStreamWriter method readAndReplaceTime.

/**
 * Replace a time in the ASN1 with the current time.
 *
 * @param out
 * @param tagNo
 * @return the time that was replaced
 * @throws IOException
 */
protected Date readAndReplaceTime(OutputStream out, int tagNo) throws IOException {
    int originalLength = readLength(crlIn, null);
    byte[] oldBytes = new byte[originalLength];
    readFullyAndTrack(crlIn, oldBytes, null);
    ASN1Object oldTime;
    ASN1Object newTime;
    if (tagNo == UTC_TIME) {
        ASN1TaggedObject t = new DERTaggedObject(UTC_TIME, new DEROctetString(oldBytes));
        oldTime = ASN1UTCTime.getInstance(t, false);
        newTime = new DERUTCTime(new Date());
    } else {
        ASN1TaggedObject t = new DERTaggedObject(GENERALIZED_TIME, new DEROctetString(oldBytes));
        oldTime = ASN1GeneralizedTime.getInstance(t, false);
        newTime = new DERGeneralizedTime(new Date());
    }
    writeNewTime(out, newTime, originalLength);
    return Time.getInstance(oldTime).getDate();
}
Also used : DERGeneralizedTime(org.bouncycastle.asn1.DERGeneralizedTime) DERUTCTime(org.bouncycastle.asn1.DERUTCTime) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1TaggedObject(org.bouncycastle.asn1.ASN1TaggedObject) ASN1Object(org.bouncycastle.asn1.ASN1Object) DEROctetString(org.bouncycastle.asn1.DEROctetString) Date(java.util.Date)

Example 37 with Asn1Object

use of com.android.hotspot2.asn1.Asn1Object in project tbd-studio-se by Talend.

the class MongoDBConnectionUtil method buildSSLContext_PEM.

private static SSLContext buildSSLContext_PEM(String _keystore, String _keystorePass, String _truststore, String _truststorePass, SSLContext sslContext) {
    SSLContext context = null;
    final String pubCertEndDelimiter = "-----END CERTIFICATE-----";
    final String privateKeyStartDelimiter = "-----BEGIN PRIVATE KEY-----";
    final String privateKeyEndDelimiter = "-----END PRIVATE KEY-----";
    final String privateKeyRSAStartDelimiter = "-----BEGIN RSA PRIVATE KEY-----";
    final String privateKeyRSAEndDelimiter = "-----END RSA PRIVATE KEY-----";
    try {
        context = SSLContext.getInstance("TLS");
        byte[] certAndKey = Files.readAllBytes(Paths.get(new File(_keystore).toURI()));
        String[] tokens = new String(certAndKey).split(pubCertEndDelimiter);
        byte[] certBytes = tokens[0].concat(pubCertEndDelimiter).getBytes();
        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
        java.security.cert.Certificate certificate = certificateFactory.generateCertificate(new ByteArrayInputStream(certBytes));
        // 
        X509Certificate cert = (X509Certificate) certificate;
        PrivateKey key = null;
        KeyFactory kf = KeyFactory.getInstance("RSA");
        if (tokens[1].contains(privateKeyStartDelimiter)) {
            byte[] privatekeyBytes = tokens[1].replace(privateKeyStartDelimiter, "").replace(privateKeyEndDelimiter, "").replace("\r\n", "").replace("\n", "").getBytes();
            byte[] decode = Base64.getDecoder().decode(privatekeyBytes);
            PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(decode);
            key = kf.generatePrivate(spec);
        } else if (tokens[1].contains(privateKeyRSAStartDelimiter)) {
            byte[] privateKeyBytes = tokens[1].replace(privateKeyRSAStartDelimiter, "").replace(privateKeyRSAEndDelimiter, "").replace("\r\n", "").replace("\n", "").getBytes("UTF-8");
            byte[] decodeBytes = Base64.getDecoder().decode(privateKeyBytes);
            ASN1Object fromByteArray = ASN1Sequence.fromByteArray(decodeBytes);
            RSAPrivateKeyStructure asn1PrivKey = new RSAPrivateKeyStructure((ASN1Sequence) fromByteArray);
            RSAPrivateKeySpec rsaPrivKeySpec = new RSAPrivateKeySpec(asn1PrivKey.getModulus(), asn1PrivKey.getPrivateExponent());
            key = kf.generatePrivate(rsaPrivKeySpec);
        }
        KeyStore keystore = KeyStore.getInstance("JKS");
        keystore.load(null);
        keystore.setCertificateEntry("cert-alias", cert);
        keystore.setKeyEntry("key-alias", key, "changeit".toCharArray(), new Certificate[] { cert });
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
        kmf.init(keystore, "changeit".toCharArray());
        KeyManager[] km = kmf.getKeyManagers();
        context.init(km, null, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return context;
}
Also used : PrivateKey(java.security.PrivateKey) SSLContext(javax.net.ssl.SSLContext) CertificateFactory(java.security.cert.CertificateFactory) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) JSONException(org.talend.utils.json.JSONException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) Certificate(java.security.cert.Certificate) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) RSAPrivateKeySpec(java.security.spec.RSAPrivateKeySpec) ByteArrayInputStream(java.io.ByteArrayInputStream) RSAPrivateKeyStructure(org.bouncycastle.asn1.pkcs.RSAPrivateKeyStructure) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) ASN1Object(org.bouncycastle.asn1.ASN1Object) File(java.io.File) KeyManager(javax.net.ssl.KeyManager) KeyFactory(java.security.KeyFactory)

Example 38 with Asn1Object

use of com.android.hotspot2.asn1.Asn1Object in project titan.EclipsePlug-ins by eclipse.

the class Undefined_FieldSpecification method classifyFieldSpecification.

private void classifyFieldSpecification(final CompilationTimeStamp timestamp) {
    final IReferenceChain temporalReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    if (isOptional && (null != defaultSetting1 || null != mDefaultSetting)) {
        location.reportSemanticError("OPTIONAL and DEFAULT are mutually exclusive");
        isOptional = false;
    }
    if (temporalReferenceChain.add(this) && null != governorReference) {
        governorReference.setMyScope(myObjectClass.getMyScope());
        if (null != defaultSetting1) {
            defaultSetting1.setMyScope(myObjectClass.getMyScope());
        }
        if (identifier.isvalidAsnObjectSetFieldReference() && governorReference.refersToSettingType(timestamp, Setting_type.S_OC, temporalReferenceChain)) {
            ObjectSet defaultObjectset = null;
            if (null != mDefaultSetting) {
                defaultObjectset = new ObjectSet_definition(mDefaultSetting);
            }
            final ObjectClass_refd oc = new ObjectClass_refd(governorReference);
            oc.setLocation(governorReference.getLocation());
            fieldSpecification = new ObjectSet_FieldSpecification(identifier, oc, isOptional, defaultObjectset);
        } else if (identifier.isvalidAsnObjectFieldReference() && governorReference.refersToSettingType(timestamp, Setting_type.S_OC, temporalReferenceChain)) {
            ASN1Object defaultObject = null;
            if (null != defaultSetting1) {
                defaultObject = new ReferencedObject(defaultSetting1);
            } else if (null != mDefaultSetting) {
                defaultObject = new Object_Definition(mDefaultSetting);
            }
            fieldSpecification = new Object_FieldSpecification(identifier, new ObjectClass_refd(governorReference), isOptional, defaultObject);
        } else if (identifier.isvalidAsnValueFieldReference() && (governorReference.refersToSettingType(timestamp, Setting_type.S_T, temporalReferenceChain) || governorReference.refersToSettingType(timestamp, Setting_type.S_VS, temporalReferenceChain))) {
            IValue defaultValue = null;
            if (null != defaultSetting1) {
                if (defaultSetting1 instanceof Defined_Reference && null == defaultSetting1.getModuleIdentifier()) {
                    defaultValue = new Undefined_LowerIdentifier_Value(defaultSetting1.getId().newInstance());
                } else {
                    defaultValue = new Referenced_Value(defaultSetting1);
                }
            } else if (null != mDefaultSetting) {
                defaultValue = new Undefined_Block_Value(mDefaultSetting);
            }
            fieldSpecification = new FixedTypeValue_FieldSpecification(identifier, new Referenced_Type(governorReference), false, isOptional, null != defaultSetting1 && null != mDefaultSetting, defaultValue);
        }
    }
    if (null == fieldSpecification) {
        location.reportSemanticError(CANNOTRECOGNISE);
        fieldSpecification = new Erroneous_FieldSpecification(identifier, isOptional, null != defaultSetting1 || null != mDefaultSetting);
    } else {
        if (null != myObjectClass) {
            fieldSpecification.setMyObjectClass(myObjectClass);
        }
    }
    fieldSpecification.setFullNameParent(getNameParent());
    fieldSpecification.setLocation(location);
    temporalReferenceChain.release();
}
Also used : Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) ObjectSet(org.eclipse.titan.designer.AST.ASN1.ObjectSet) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Undefined_Block_Value(org.eclipse.titan.designer.AST.ASN1.values.Undefined_Block_Value) ASN1Object(org.eclipse.titan.designer.AST.ASN1.ASN1Object) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 39 with Asn1Object

use of com.android.hotspot2.asn1.Asn1Object in project titan.EclipsePlug-ins by eclipse.

the class ReferencedObject method getRefdLast.

public Object_Definition getRefdLast(final CompilationTimeStamp timestamp) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(CIRCULAROBJECTREFERENCE, true);
    ASN1Object object = this;
    while (object instanceof ReferencedObject && !object.getIsErroneous(timestamp)) {
        object = ((ReferencedObject) object).getRefd(timestamp, referenceChain);
    }
    referenceChain.release();
    return (Object_Definition) object;
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ASN1Object(org.eclipse.titan.designer.AST.ASN1.ASN1Object)

Example 40 with Asn1Object

use of com.android.hotspot2.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)

Aggregations

IOException (java.io.IOException)27 Asn1Object (com.android.hotspot2.asn1.Asn1Object)25 Asn1Constructed (com.android.hotspot2.asn1.Asn1Constructed)20 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 X509Certificate (java.security.cert.X509Certificate)12 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 ASN1Object (org.bouncycastle.asn1.ASN1Object)9 ByteArrayInputStream (java.io.ByteArrayInputStream)6 KeyPair (java.security.KeyPair)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Set (java.util.Set)6 I18Name (com.android.anqp.I18Name)5 Asn1Octets (com.android.hotspot2.asn1.Asn1Octets)5 Asn1Oid (com.android.hotspot2.asn1.Asn1Oid)5