Search in sources :

Example 11 with CertificateExtensions

use of sun.security.x509.CertificateExtensions in project meecrowave by apache.

the class Keystores method createSignedCertificate.

private static X509Certificate createSignedCertificate(final X509Certificate cetrificate, final X509Certificate issuerCertificate, final PrivateKey issuerPrivateKey) {
    try {
        Principal issuer = issuerCertificate.getSubjectDN();
        String issuerSigAlg = issuerCertificate.getSigAlgName();
        byte[] inCertBytes = cetrificate.getTBSCertificate();
        X509CertInfo info = new X509CertInfo(inCertBytes);
        info.set(X509CertInfo.ISSUER, (X500Name) issuer);
        // No need to add the BasicContraint for leaf cert
        if (!cetrificate.getSubjectDN().getName().equals("CN=TOP")) {
            CertificateExtensions exts = new CertificateExtensions();
            BasicConstraintsExtension bce = new BasicConstraintsExtension(true, -1);
            exts.set(BasicConstraintsExtension.NAME, new BasicConstraintsExtension(false, bce.getExtensionValue()));
            info.set(X509CertInfo.EXTENSIONS, exts);
        }
        final X509CertImpl outCert = new X509CertImpl(info);
        outCert.sign(issuerPrivateKey, issuerSigAlg);
        return outCert;
    } catch (final Exception ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : BasicConstraintsExtension(sun.security.x509.BasicConstraintsExtension) X509CertInfo(sun.security.x509.X509CertInfo) X509CertImpl(sun.security.x509.X509CertImpl) CertificateExtensions(sun.security.x509.CertificateExtensions) Principal(java.security.Principal)

Example 12 with CertificateExtensions

use of sun.security.x509.CertificateExtensions in project OpenAttestation by OpenAttestation.

the class X509Builder method keyUsageKeyEncipherment.

public X509Builder keyUsageKeyEncipherment() {
    // for encrypting and transporting other keys
    try {
        v3();
        if (keyUsageExtension == null) {
            keyUsageExtension = new KeyUsageExtension();
        }
        keyUsageExtension.set(KeyUsageExtension.KEY_ENCIPHERMENT, true);
        if (certificateExtensions == null) {
            certificateExtensions = new CertificateExtensions();
        }
        certificateExtensions.set(keyUsageExtension.getExtensionId().toString(), keyUsageExtension);
        info.set(X509CertInfo.EXTENSIONS, certificateExtensions);
    } catch (Exception e) {
        fault(e, "keyUsageKeyEncipherment");
    }
    return this;
}
Also used : CertificateExtensions(sun.security.x509.CertificateExtensions) KeyUsageExtension(sun.security.x509.KeyUsageExtension) ExtendedKeyUsageExtension(sun.security.x509.ExtendedKeyUsageExtension)

Example 13 with CertificateExtensions

use of sun.security.x509.CertificateExtensions in project OpenAttestation by OpenAttestation.

the class X509Builder method keyUsageNonRepudiation.

public X509Builder keyUsageNonRepudiation() {
    // other than CA or CRL; this applies to API clients
    try {
        v3();
        if (keyUsageExtension == null) {
            keyUsageExtension = new KeyUsageExtension();
        }
        keyUsageExtension.set(KeyUsageExtension.NON_REPUDIATION, true);
        if (certificateExtensions == null) {
            certificateExtensions = new CertificateExtensions();
        }
        certificateExtensions.set(keyUsageExtension.getExtensionId().toString(), keyUsageExtension);
        info.set(X509CertInfo.EXTENSIONS, certificateExtensions);
    } catch (Exception e) {
        fault(e, "keyUsageNonRepudiation");
    }
    return this;
}
Also used : CertificateExtensions(sun.security.x509.CertificateExtensions) KeyUsageExtension(sun.security.x509.KeyUsageExtension) ExtendedKeyUsageExtension(sun.security.x509.ExtendedKeyUsageExtension)

Example 14 with CertificateExtensions

use of sun.security.x509.CertificateExtensions in project OpenAttestation by OpenAttestation.

the class X509Builder method keyUsageCertificateAuthority.

public X509Builder keyUsageCertificateAuthority() {
    try {
        v3();
        // certificate authority basic constraint
        // true indicates this is a CA;  -1 means no restriction on path length;  0 or more to set a restriction on max number of certs under this one in the chain
        BasicConstraintsExtension constraintsExtension = new BasicConstraintsExtension(true, -1);
        // certificate signing extension
        if (keyUsageExtension == null) {
            keyUsageExtension = new KeyUsageExtension();
        }
        keyUsageExtension.set(KeyUsageExtension.KEY_CERTSIGN, true);
        // add both
        if (certificateExtensions == null) {
            certificateExtensions = new CertificateExtensions();
        }
        certificateExtensions.set(keyUsageExtension.getExtensionId().toString(), keyUsageExtension);
        certificateExtensions.set(constraintsExtension.getExtensionId().toString(), constraintsExtension);
        info.set(X509CertInfo.EXTENSIONS, certificateExtensions);
    } catch (Exception e) {
        fault(e, "keyUsageCertificateAuthority");
    }
    return this;
}
Also used : BasicConstraintsExtension(sun.security.x509.BasicConstraintsExtension) CertificateExtensions(sun.security.x509.CertificateExtensions) KeyUsageExtension(sun.security.x509.KeyUsageExtension) ExtendedKeyUsageExtension(sun.security.x509.ExtendedKeyUsageExtension)

Example 15 with CertificateExtensions

use of sun.security.x509.CertificateExtensions in project OpenAttestation by OpenAttestation.

the class X509Builder method extKeyUsageIsCritical.

public X509Builder extKeyUsageIsCritical() {
    extendedKeyUsageExtensionIsCritical = true;
    try {
        v3();
        if (extendedKeyUsageExtensionList != null) {
            extendedKeyUsageExtension = new ExtendedKeyUsageExtension(extendedKeyUsageExtensionIsCritical, extendedKeyUsageExtensionList);
            if (certificateExtensions == null) {
                certificateExtensions = new CertificateExtensions();
            }
            certificateExtensions.set(extendedKeyUsageExtension.getExtensionId().toString(), extendedKeyUsageExtension);
            info.set(X509CertInfo.EXTENSIONS, certificateExtensions);
        }
    } catch (Exception e) {
        fault(e, "extKeyUsageIsCritical");
    }
    return this;
}
Also used : ExtendedKeyUsageExtension(sun.security.x509.ExtendedKeyUsageExtension) CertificateExtensions(sun.security.x509.CertificateExtensions)

Aggregations

CertificateExtensions (sun.security.x509.CertificateExtensions)17 ExtendedKeyUsageExtension (sun.security.x509.ExtendedKeyUsageExtension)8 ObjectIdentifier (sun.security.util.ObjectIdentifier)6 KeyUsageExtension (sun.security.x509.KeyUsageExtension)6 SubjectAlternativeNameExtension (sun.security.x509.SubjectAlternativeNameExtension)5 CertificateException (java.security.cert.CertificateException)4 Date (java.util.Date)4 GeneralName (sun.security.x509.GeneralName)4 GeneralNames (sun.security.x509.GeneralNames)4 X509CertImpl (sun.security.x509.X509CertImpl)4 X509CertInfo (sun.security.x509.X509CertInfo)4 IOException (java.io.IOException)3 DerEncoder (sun.security.util.DerEncoder)3 DerOutputStream (sun.security.util.DerOutputStream)3 Iterator (java.util.Iterator)2 DerValue (sun.security.util.DerValue)2 BasicConstraintsExtension (sun.security.x509.BasicConstraintsExtension)2 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 Method (java.lang.reflect.Method)1 BigInteger (java.math.BigInteger)1