Search in sources :

Example 21 with CertificateEncodingException

use of java.security.cert.CertificateEncodingException in project robovm by robovm.

the class CertificateEncodingExceptionTest method testCertificateEncodingException03.

/**
     * Test for <code>CertificateEncodingException(String)</code> constructor
     * Assertion: constructs CertificateEncodingException when <code>msg</code>
     * is null
     */
public void testCertificateEncodingException03() {
    String msg = null;
    CertificateEncodingException tE = new CertificateEncodingException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 22 with CertificateEncodingException

use of java.security.cert.CertificateEncodingException in project robovm by robovm.

the class CertificateEncodingExceptionTest method testCertificateEncodingException05.

/**
     * Test for <code>CertificateEncodingException(Throwable)</code>
     * constructor Assertion: constructs CertificateEncodingException when
     * <code>cause</code> is not null
     */
public void testCertificateEncodingException05() {
    CertificateEncodingException tE = new CertificateEncodingException(tCause);
    if (tE.getMessage() != null) {
        String toS = tCause.toString();
        String getM = tE.getMessage();
        assertTrue("getMessage() should contain ".concat(toS), (getM.indexOf(toS) != -1));
    }
    assertNotNull("getCause() must not return null", tE.getCause());
    assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
}
Also used : CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 23 with CertificateEncodingException

use of java.security.cert.CertificateEncodingException in project robovm by robovm.

the class CMSSignedDataGenerator method generate.

/**
     * Similar method to the other generate methods. The additional argument
     * addDefaultAttributes indicates whether or not a default set of signed attributes
     * need to be added automatically. If the argument is set to false, no
     * attributes will get added at all.
     * @deprecated use setDirectSignature() on SignerInformationGenerator.
     */
public CMSSignedData generate(String eContentType, final CMSProcessable content, boolean encapsulate, Provider sigProvider, boolean addDefaultAttributes) throws NoSuchAlgorithmException, CMSException {
    boolean isCounterSignature = (eContentType == null);
    final ASN1ObjectIdentifier contentTypeOID = isCounterSignature ? null : new ASN1ObjectIdentifier(eContentType);
    for (Iterator it = signerInfs.iterator(); it.hasNext(); ) {
        SignerInf signer = (SignerInf) it.next();
        try {
            signerGens.add(signer.toSignerInfoGenerator(rand, sigProvider, addDefaultAttributes));
        } catch (OperatorCreationException e) {
            throw new CMSException("exception creating signerInf", e);
        } catch (IOException e) {
            throw new CMSException("exception encoding attributes", e);
        } catch (CertificateEncodingException e) {
            throw new CMSException("error creating sid.", e);
        }
    }
    signerInfs.clear();
    if (content != null) {
        return generate(new CMSTypedData() {

            public ASN1ObjectIdentifier getContentType() {
                return contentTypeOID;
            }

            public void write(OutputStream out) throws IOException, CMSException {
                content.write(out);
            }

            public Object getContent() {
                return content.getContent();
            }
        }, encapsulate);
    } else {
        return generate(new CMSAbsentContent(contentTypeOID), encapsulate);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) CertificateEncodingException(java.security.cert.CertificateEncodingException) IOException(java.io.IOException) OperatorCreationException(org.bouncycastle.operator.OperatorCreationException) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 24 with CertificateEncodingException

use of java.security.cert.CertificateEncodingException in project robovm by robovm.

the class PinFailureLogger method writeToLog.

protected static synchronized void writeToLog(String cn, boolean chainContainsUserCert, boolean pinIsEnforcing, List<X509Certificate> chain) {
    StringBuilder sb = new StringBuilder();
    sb.append(cn);
    sb.append("|");
    sb.append(chainContainsUserCert);
    sb.append("|");
    sb.append(pinIsEnforcing);
    sb.append("|");
    for (X509Certificate cert : chain) {
        try {
            sb.append(Base64.encode(cert.getEncoded()));
        } catch (CertificateEncodingException e) {
            sb.append("Error: could not encode certificate");
        }
        sb.append("|");
    }
    DropBox.addText("exp_det_cert_pin_failure", sb.toString());
}
Also used : CertificateEncodingException(java.security.cert.CertificateEncodingException) X509Certificate(java.security.cert.X509Certificate)

Example 25 with CertificateEncodingException

use of java.security.cert.CertificateEncodingException in project robovm by robovm.

the class X509CRLObject method isRevoked.

/**
     * Checks whether the given certificate is on this CRL.
     *
     * @param cert the certificate to check for.
     * @return true if the given certificate is on this CRL,
     * false otherwise.
     */
public boolean isRevoked(Certificate cert) {
    if (!cert.getType().equals("X.509")) {
        throw new RuntimeException("X.509 CRL used with non X.509 Cert");
    }
    TBSCertList.CRLEntry[] certs = c.getRevokedCertificates();
    X500Name caName = c.getIssuer();
    if (certs != null) {
        BigInteger serial = ((X509Certificate) cert).getSerialNumber();
        for (int i = 0; i < certs.length; i++) {
            if (isIndirect && certs[i].hasExtensions()) {
                Extension currentCaName = certs[i].getExtensions().getExtension(Extension.certificateIssuer);
                if (currentCaName != null) {
                    caName = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
                }
            }
            if (certs[i].getUserCertificate().getValue().equals(serial)) {
                X500Name issuer;
                if (cert instanceof X509Certificate) {
                    issuer = X500Name.getInstance(((X509Certificate) cert).getIssuerX500Principal().getEncoded());
                } else {
                    try {
                        issuer = org.bouncycastle.asn1.x509.Certificate.getInstance(cert.getEncoded()).getIssuer();
                    } catch (CertificateEncodingException e) {
                        throw new RuntimeException("Cannot process certificate");
                    }
                }
                if (!caName.equals(issuer)) {
                    return false;
                }
                return true;
            }
        }
    }
    return false;
}
Also used : Extension(org.bouncycastle.asn1.x509.Extension) BigInteger(java.math.BigInteger) CertificateEncodingException(java.security.cert.CertificateEncodingException) X509CRLEntry(java.security.cert.X509CRLEntry) X500Name(org.bouncycastle.asn1.x500.X500Name) X509Certificate(java.security.cert.X509Certificate) IssuingDistributionPoint(org.bouncycastle.asn1.x509.IssuingDistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint)

Aggregations

CertificateEncodingException (java.security.cert.CertificateEncodingException)210 X509Certificate (java.security.cert.X509Certificate)94 IOException (java.io.IOException)76 Certificate (java.security.cert.Certificate)29 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)27 KeyStoreException (java.security.KeyStoreException)19 MessageDigest (java.security.MessageDigest)19 ArrayList (java.util.ArrayList)19 X500Name (org.bouncycastle.asn1.x500.X500Name)16 CertificateException (java.security.cert.CertificateException)14 BigInteger (java.math.BigInteger)11 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)10 Bundle (android.os.Bundle)9 PublicKey (java.security.PublicKey)9 Date (java.util.Date)9 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 File (java.io.File)8 PrivateKey (java.security.PrivateKey)8 DEROctetString (org.bouncycastle.asn1.DEROctetString)8