Search in sources :

Example 56 with CRLException

use of java.security.cert.CRLException in project jdk8u_jdk by JetBrains.

the class AlgorithmChecker method check.

/**
     * Check the signature algorithm with the specified public key.
     *
     * @param key the public key to verify the CRL signature
     * @param crl the target CRL
     * @param variant is the Validator variants of the operation. A null value
     *                passed will set it to Validator.GENERIC.
     */
static void check(PublicKey key, X509CRL crl, String variant) throws CertPathValidatorException {
    X509CRLImpl x509CRLImpl = null;
    try {
        x509CRLImpl = X509CRLImpl.toImpl(crl);
    } catch (CRLException ce) {
        throw new CertPathValidatorException(ce);
    }
    AlgorithmId algorithmId = x509CRLImpl.getSigAlgId();
    check(key, algorithmId, variant);
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) AlgorithmId(sun.security.x509.AlgorithmId) X509CRLImpl(sun.security.x509.X509CRLImpl) CRLException(java.security.cert.CRLException)

Example 57 with CRLException

use of java.security.cert.CRLException in project jdk8u_jdk by JetBrains.

the class CRLExtensions method init.

// helper routine
private void init(DerInputStream derStrm) throws CRLException {
    try {
        DerInputStream str = derStrm;
        byte nextByte = (byte) derStrm.peekByte();
        // check for context specific byte 0; skip it
        if (((nextByte & 0x0c0) == 0x080) && ((nextByte & 0x01f) == 0x000)) {
            DerValue val = str.getDerValue();
            str = val.data;
        }
        DerValue[] exts = str.getSequence(5);
        for (int i = 0; i < exts.length; i++) {
            Extension ext = new Extension(exts[i]);
            parseExtension(ext);
        }
    } catch (IOException e) {
        throw new CRLException("Parsing error: " + e.toString());
    }
}
Also used : IOException(java.io.IOException) CRLException(java.security.cert.CRLException)

Example 58 with CRLException

use of java.security.cert.CRLException in project jdk8u_jdk by JetBrains.

the class CRLExtensions method encode.

/**
     * Encode the extensions in DER form to the stream.
     *
     * @param out the DerOutputStream to marshal the contents to.
     * @param isExplicit the tag indicating whether this is an entry
     * extension (false) or a CRL extension (true).
     * @exception CRLException on encoding errors.
     */
public void encode(OutputStream out, boolean isExplicit) throws CRLException {
    try {
        DerOutputStream extOut = new DerOutputStream();
        Collection<Extension> allExts = map.values();
        Object[] objs = allExts.toArray();
        for (int i = 0; i < objs.length; i++) {
            if (objs[i] instanceof CertAttrSet)
                ((CertAttrSet) objs[i]).encode(extOut);
            else if (objs[i] instanceof Extension)
                ((Extension) objs[i]).encode(extOut);
            else
                throw new CRLException("Illegal extension object");
        }
        DerOutputStream seq = new DerOutputStream();
        seq.write(DerValue.tag_Sequence, extOut);
        DerOutputStream tmp = new DerOutputStream();
        if (isExplicit)
            tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0), seq);
        else
            tmp = seq;
        out.write(tmp.toByteArray());
    } catch (IOException e) {
        throw new CRLException("Encoding error: " + e.toString());
    } catch (CertificateException e) {
        throw new CRLException("Encoding error: " + e.toString());
    }
}
Also used : CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) CRLException(java.security.cert.CRLException)

Example 59 with CRLException

use of java.security.cert.CRLException in project jdk8u_jdk by JetBrains.

the class CRLExtensions method parseExtension.

// Parse the encoded extension
private void parseExtension(Extension ext) throws CRLException {
    try {
        Class<?> extClass = OIDMap.getClass(ext.getExtensionId());
        if (extClass == null) {
            // Unsupported extension
            if (ext.isCritical())
                unsupportedCritExt = true;
            if (map.put(ext.getExtensionId().toString(), ext) != null)
                throw new CRLException("Duplicate extensions not allowed");
            return;
        }
        Constructor<?> cons = extClass.getConstructor(PARAMS);
        Object[] passed = new Object[] { Boolean.valueOf(ext.isCritical()), ext.getExtensionValue() };
        CertAttrSet<?> crlExt = (CertAttrSet<?>) cons.newInstance(passed);
        if (map.put(crlExt.getName(), (Extension) crlExt) != null) {
            throw new CRLException("Duplicate extensions not allowed");
        }
    } catch (InvocationTargetException invk) {
        throw new CRLException(invk.getTargetException().getMessage());
    } catch (Exception e) {
        throw new CRLException(e.toString());
    }
}
Also used : CRLException(java.security.cert.CRLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CRLException(java.security.cert.CRLException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 60 with CRLException

use of java.security.cert.CRLException in project jdk8u_jdk by JetBrains.

the class X509CRLEntryImpl method parse.

private void parse(DerValue derVal) throws CRLException, IOException {
    if (derVal.tag != DerValue.tag_Sequence) {
        throw new CRLException("Invalid encoded RevokedCertificate, " + "starting sequence tag missing.");
    }
    if (derVal.data.available() == 0)
        throw new CRLException("No data encoded for RevokedCertificates");
    revokedCert = derVal.toByteArray();
    // serial number
    DerInputStream in = derVal.toDerInputStream();
    DerValue val = in.getDerValue();
    this.serialNumber = new SerialNumber(val);
    // revocationDate
    int nextByte = derVal.data.peekByte();
    if ((byte) nextByte == DerValue.tag_UtcTime) {
        this.revocationDate = derVal.data.getUTCTime();
    } else if ((byte) nextByte == DerValue.tag_GeneralizedTime) {
        this.revocationDate = derVal.data.getGeneralizedTime();
    } else
        throw new CRLException("Invalid encoding for revocation date");
    if (derVal.data.available() == 0)
        // no extensions
        return;
    // crlEntryExtensions
    this.extensions = new CRLExtensions(derVal.toDerInputStream());
}
Also used : CRLException(java.security.cert.CRLException)

Aggregations

CRLException (java.security.cert.CRLException)63 IOException (java.io.IOException)26 CertificateException (java.security.cert.CertificateException)21 X509CRL (java.security.cert.X509CRL)14 CRL (java.security.cert.CRL)11 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Signature (java.security.Signature)8 CertificateFactory (java.security.cert.CertificateFactory)8 SignatureException (java.security.SignatureException)6 InputStream (java.io.InputStream)5 Certificate (java.security.cert.Certificate)5 X509CRLImpl (sun.security.x509.X509CRLImpl)5 CertificateParsingException (java.security.cert.CertificateParsingException)4 ArrayList (java.util.ArrayList)4 DataInputStream (java.io.DataInputStream)3 CertificateFactorySpi (java.security.cert.CertificateFactorySpi)3 X509CRLEntry (java.security.cert.X509CRLEntry)3 X509Certificate (java.security.cert.X509Certificate)3 X500Principal (javax.security.auth.x500.X500Principal)3 MyCertificateFactorySpi (org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi)3