Search in sources :

Example 21 with CRLException

use of java.security.cert.CRLException in project j2objc by google.

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 22 with CRLException

use of java.security.cert.CRLException in project j2objc by google.

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 = ((Class<?>) 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 : Constructor(java.lang.reflect.Constructor) CRLException(java.security.cert.CRLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CRLException(java.security.cert.CRLException)

Example 23 with CRLException

use of java.security.cert.CRLException in project XobotOS by xamarin.

the class JDKX509CertificateFactory method engineGenerateCRL.

/**
     * Generates a certificate revocation list (CRL) object and initializes
     * it with the data read from the input stream inStream.
     */
public CRL engineGenerateCRL(InputStream inStream) throws CRLException {
    if (currentCrlStream == null) {
        currentCrlStream = inStream;
        sCrlData = null;
        sCrlDataObjectCount = 0;
    } else if (// reset if input stream has changed
    currentCrlStream != inStream) {
        currentCrlStream = inStream;
        sCrlData = null;
        sCrlDataObjectCount = 0;
    }
    try {
        if (sCrlData != null) {
            if (sCrlDataObjectCount != sCrlData.size()) {
                return getCRL();
            } else {
                sCrlData = null;
                sCrlDataObjectCount = 0;
                return null;
            }
        }
        int limit = ProviderUtil.getReadLimit(inStream);
        PushbackInputStream pis = new PushbackInputStream(inStream);
        int tag = pis.read();
        if (tag == -1) {
            return null;
        }
        pis.unread(tag);
        if (// assume ascii PEM encoded.
        tag != 0x30) {
            return readPEMCRL(pis);
        } else {
            // lazy evaluate to help processing of large CRLs
            return readDERCRL(new ASN1InputStream(pis, limit, true));
        }
    } catch (CRLException e) {
        throw e;
    } catch (Exception e) {
        throw new CRLException(e.toString());
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) PushbackInputStream(java.io.PushbackInputStream) CRLException(java.security.cert.CRLException) CertificateParsingException(java.security.cert.CertificateParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CRLException(java.security.cert.CRLException)

Example 24 with CRLException

use of java.security.cert.CRLException in project XobotOS by xamarin.

the class X509CertFactoryImpl method getCRL.

/**
     * Returns the CRL object corresponding to the provided encoding.
     * Resulting object is retrieved from the cache
     * if it contains such correspondence
     * and is constructed on the base of encoding
     * and stored in the cache otherwise.
     * @throws IOException if some decoding errors occur
     * (in the case of cache miss).
     */
private static CRL getCRL(byte[] encoding) throws CRLException, IOException {
    if (encoding.length < CRL_CACHE_SEED_LENGTH) {
        throw new CRLException("encoding.length < CRL_CACHE_SEED_LENGTH");
    }
    synchronized (CRL_CACHE) {
        long hash = CRL_CACHE.getHash(encoding);
        if (CRL_CACHE.contains(hash)) {
            X509CRL res = (X509CRL) CRL_CACHE.get(hash, encoding);
            if (res != null) {
                return res;
            }
        }
        X509CRL res = new X509CRLImpl(encoding);
        CRL_CACHE.put(hash, encoding, res);
        return res;
    }
}
Also used : X509CRL(java.security.cert.X509CRL) CRLException(java.security.cert.CRLException)

Example 25 with CRLException

use of java.security.cert.CRLException in project XobotOS by xamarin.

the class MiscPEMGenerator method createPemObject.

private PemObject createPemObject(Object o) throws IOException {
    String type;
    byte[] encoding;
    if (o instanceof PemObject) {
        return (PemObject) o;
    }
    if (o instanceof PemObjectGenerator) {
        return ((PemObjectGenerator) o).generate();
    }
    if (o instanceof X509Certificate) {
        type = "CERTIFICATE";
        try {
            encoding = ((X509Certificate) o).getEncoded();
        } catch (CertificateEncodingException e) {
            throw new PemGenerationException("Cannot encode object: " + e.toString());
        }
    } else if (o instanceof X509CRL) {
        type = "X509 CRL";
        try {
            encoding = ((X509CRL) o).getEncoded();
        } catch (CRLException e) {
            throw new PemGenerationException("Cannot encode object: " + e.toString());
        }
    } else if (o instanceof KeyPair) {
        return createPemObject(((KeyPair) o).getPrivate());
    } else if (o instanceof PrivateKey) {
        PrivateKeyInfo info = new PrivateKeyInfo((ASN1Sequence) ASN1Object.fromByteArray(((Key) o).getEncoded()));
        if (o instanceof RSAPrivateKey) {
            type = "RSA PRIVATE KEY";
            encoding = info.getPrivateKey().getEncoded();
        } else if (o instanceof DSAPrivateKey) {
            type = "DSA PRIVATE KEY";
            DSAParameter p = DSAParameter.getInstance(info.getAlgorithmId().getParameters());
            ASN1EncodableVector v = new ASN1EncodableVector();
            v.add(new DERInteger(0));
            v.add(new DERInteger(p.getP()));
            v.add(new DERInteger(p.getQ()));
            v.add(new DERInteger(p.getG()));
            BigInteger x = ((DSAPrivateKey) o).getX();
            BigInteger y = p.getG().modPow(x, p.getP());
            v.add(new DERInteger(y));
            v.add(new DERInteger(x));
            encoding = new DERSequence(v).getEncoded();
        } else if (((PrivateKey) o).getAlgorithm().equals("ECDSA")) {
            type = "EC PRIVATE KEY";
            encoding = info.getPrivateKey().getEncoded();
        } else {
            throw new IOException("Cannot identify private key");
        }
    } else if (o instanceof PublicKey) {
        type = "PUBLIC KEY";
        encoding = ((PublicKey) o).getEncoded();
    } else if (o instanceof X509AttributeCertificate) {
        type = "ATTRIBUTE CERTIFICATE";
        encoding = ((X509V2AttributeCertificate) o).getEncoded();
    } else if (o instanceof PKCS10CertificationRequest) {
        type = "CERTIFICATE REQUEST";
        encoding = ((PKCS10CertificationRequest) o).getEncoded();
    } else if (o instanceof ContentInfo) {
        type = "PKCS7";
        encoding = ((ContentInfo) o).getEncoded();
    } else {
        throw new PemGenerationException("unknown object passed - can't encode.");
    }
    return new PemObject(type, encoding);
}
Also used : X509CRL(java.security.cert.X509CRL) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) PrivateKey(java.security.PrivateKey) X509AttributeCertificate(org.bouncycastle.x509.X509AttributeCertificate) DERInteger(org.bouncycastle.asn1.DERInteger) PemObjectGenerator(org.bouncycastle.util.io.pem.PemObjectGenerator) DERSequence(org.bouncycastle.asn1.DERSequence) ContentInfo(org.bouncycastle.asn1.cms.ContentInfo) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) DSAParameter(org.bouncycastle.asn1.x509.DSAParameter) CRLException(java.security.cert.CRLException) PKCS10CertificationRequest(org.bouncycastle.jce.PKCS10CertificationRequest) KeyPair(java.security.KeyPair) PemGenerationException(org.bouncycastle.util.io.pem.PemGenerationException) PublicKey(java.security.PublicKey) CertificateEncodingException(java.security.cert.CertificateEncodingException) IOException(java.io.IOException) X509V2AttributeCertificate(org.bouncycastle.x509.X509V2AttributeCertificate) X509Certificate(java.security.cert.X509Certificate) PemObject(org.bouncycastle.util.io.pem.PemObject) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) BigInteger(java.math.BigInteger) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) PrivateKeyInfo(org.bouncycastle.asn1.pkcs.PrivateKeyInfo) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) PublicKey(java.security.PublicKey) Key(java.security.Key) PrivateKey(java.security.PrivateKey) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey)

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