Example usage for org.bouncycastle.asn1 DERSequence DERSequence

List of usage examples for org.bouncycastle.asn1 DERSequence DERSequence

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 DERSequence DERSequence.

Prototype

public DERSequence(ASN1Encodable[] elements) 

Source Link

Document

Create a sequence containing an array of objects.

Usage

From source file:com.android.verity.BootSignature.java

License:Apache License

public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(formatVersion);//from   w  w  w .j av  a  2 s.  c  o  m
    v.add(algorithmIdentifier);
    v.add(getAuthenticatedAttributes());
    v.add(signature);
    return new DERSequence(v);
}

From source file:com.android.verity.BootKey.java

License:Apache License

public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(algorithmIdentifier);/*from  ww w  . ja v  a 2s. c  o  m*/
    v.add(keyMaterial);
    return new DERSequence(v);
}

From source file:com.android.verity.BootKey.java

License:Apache License

public byte[] getInnerKeystore() throws Exception {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(formatVersion);/*from ww  w. j  av  a 2  s  .  co  m*/
    v.add(new DERSequence(keyBag));
    return new DERSequence(v).getEncoded();
}

From source file:com.android.verity.BootKey.java

License:Apache License

public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(formatVersion);/*from  w  w  w  . j a  v a 2s . c  om*/
    v.add(new DERSequence(keyBag));
    v.add(signature);
    return new DERSequence(v);
}

From source file:com.aqnote.shared.cryptology.cert.gen.CertGenerator.java

License:Open Source License

private void addAuthorityInfoAccess(X509v3CertificateBuilder certBuilder) throws CertIOException {
    ASN1EncodableVector aia_ASN = new ASN1EncodableVector();
    GeneralName crlName = new GeneralName(GeneralName.uniformResourceIdentifier,
            new DERIA5String(CertConstant.MAD_CA_URL));
    AccessDescription caIssuers = new AccessDescription(AccessDescription.id_ad_caIssuers, crlName);
    GeneralName ocspName = new GeneralName(GeneralName.uniformResourceIdentifier,
            new DERIA5String(CertConstant.MAD_OCSP_URL));
    AccessDescription ocsp = new AccessDescription(AccessDescription.id_ad_ocsp, ocspName);
    aia_ASN.add(caIssuers);/*from   w  ww. j  a va  2 s. co m*/
    aia_ASN.add(ocsp);
    certBuilder.addExtension(Extension.authorityInfoAccess, false, new DERSequence(aia_ASN));
}

From source file:com.aqnote.shared.encrypt.cert.gen.BCCertGenerator.java

License:Open Source License

private static void addAuthorityInfoAccess(X509v3CertificateBuilder certBuilder) throws CertIOException {
    ASN1EncodableVector aia_ASN = new ASN1EncodableVector();
    GeneralName crlName = new GeneralName(GeneralName.uniformResourceIdentifier,
            new DERIA5String(CertConstant.MAD_CA_URL));
    AccessDescription caIssuers = new AccessDescription(AccessDescription.id_ad_caIssuers, crlName);
    GeneralName ocspName = new GeneralName(GeneralName.uniformResourceIdentifier,
            new DERIA5String(CertConstant.MAD_OCSP_URL));
    AccessDescription ocsp = new AccessDescription(AccessDescription.id_ad_ocsp, ocspName);
    aia_ASN.add(caIssuers);//from   w  w  w  .  j  av  a  2  s . c o  m
    aia_ASN.add(ocsp);
    certBuilder.addExtension(Extension.authorityInfoAccess, false, new DERSequence(aia_ASN));
}

From source file:com.difference.historybook.server.CertManager.java

License:Apache License

/**
 * Create a self-signed certificate and store in a keystore (if it doesn't already exist)
 * /* w  ww  .  ja va2  s  .  com*/
 * @param keystore path to the keystore to save to
 * @param password password to use to encrypt keystore
 * @param alias name to give the certificate in the keystore
 * @param x500String X500 name for the certificate. (e.g. "CN=localhost,OU=issuer)
 * @param duration length of time a newly created certificate should remain valid (in seconds)
 * 
 * @throws @RuntimeException if an error occurs in creating the certificate
 */
public static void initialize(Path keystore, String password, String alias, String commonName,
        String organization, long duration) {
    if (keystore.toFile().exists()) {
        LOG.info("Keystore {} found.", keystore);
        return;
    }

    try {
        Security.addProvider(new BouncyCastleProvider());

        // generate a key pair
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", PROVIDER_NAME);
        keyPairGenerator.initialize(KEY_LENGTH, new SecureRandom());
        KeyPair keyPair = keyPairGenerator.generateKeyPair();
        PublicKey pubKey = keyPair.getPublic();
        PrivateKey privateKey = keyPair.getPrivate();

        // build name
        X500NameBuilder nameBuilder = new X500NameBuilder(BCStyle.INSTANCE);
        nameBuilder.addRDN(BCStyle.CN, commonName);
        nameBuilder.addRDN(BCStyle.O, organization);
        nameBuilder.addRDN(BCStyle.OU, organization);
        X500Name issuerName = nameBuilder.build();
        X500Name subjectName = issuerName;

        // build serial
        BigInteger serial = BigInteger.valueOf(new Random().nextInt());

        // build a certificate generator
        X509v3CertificateBuilder certBuilder = new JcaX509v3CertificateBuilder(issuerName, serial,
                new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000), // yesterday
                new Date(System.currentTimeMillis() + duration * 1000), subjectName, pubKey);

        KeyUsage usage = new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment);
        certBuilder.addExtension(Extension.keyUsage, true, usage);

        ASN1EncodableVector purposes = new ASN1EncodableVector();
        purposes.add(KeyPurposeId.id_kp_serverAuth);
        certBuilder.addExtension(Extension.extendedKeyUsage, false, new DERSequence(purposes));

        X509Certificate[] chain = new X509Certificate[1];
        chain[0] = signCertificate(certBuilder, keyPair.getPrivate());

        KeyStore keyStore = KeyStore.getInstance("JKS");
        keyStore.load(null, null);

        keyStore.setKeyEntry(alias, privateKey, password.toCharArray(), chain);
        keyStore.store(new FileOutputStream(keystore.toFile()), password.toCharArray());
        Files.setPosixFilePermissions(keystore, ImmutableSet.of(PosixFilePermission.OWNER_READ));
        LOG.info("Created keystore at {}.", keystore);
    } catch (NoSuchAlgorithmException | NoSuchProviderException | CertificateException | KeyStoreException
            | IOException | OperatorCreationException e) {
        LOG.error(e.getLocalizedMessage());
        throw new RuntimeException(e);
    }
}

From source file:com.github.horrorho.inflatabledonkey.data.der.BackupEscrow.java

License:Open Source License

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector vector = DER.vector(new DEROctetString(wrappedKey()), new DEROctetString(data()),
            new DEROctetString(x()), new ASN1Integer(y), new DEROctetString(masterKeyPublic()));

    DERSequence sequence = new DERSequence(vector);
    return DER.toApplicationSpecific(APPLICATION_TAG, sequence);
}

From source file:com.github.horrorho.inflatabledonkey.data.der.DER.java

License:Open Source License

static DERSequence toSequence(List<? extends ASN1Encodable> collection) {
    return new DERSequence(vector(collection));
}

From source file:com.github.horrorho.inflatabledonkey.data.der.ECDSASignature.java

License:Open Source License

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector vector = DER.vector(new ASN1Integer(r), new ASN1Integer(s));

    return new DERSequence(vector);
}