Search in sources :

Example 6 with CertificateException

use of javax.security.cert.CertificateException in project j2objc by google.

the class CertificateExceptionTest method testCertificateException03.

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

Example 7 with CertificateException

use of javax.security.cert.CertificateException in project perun by CESNET.

the class urn_perun_user_attribute_def_virt_userCertExpirations method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attribute = new Attribute(attributeDefinition);
    HashMap<String, String> certsExpirations = new LinkedHashMap<String, String>();
    try {
        Attribute userCertsAttribute = getUserCertsAttribute(sess, user);
        HashMap<String, String> certs = (LinkedHashMap<String, String>) userCertsAttribute.getValue();
        if (certs != null) {
            for (String certDN : certs.keySet()) {
                String cert = certs.get(certDN);
                // Remove --- BEGIN --- and --- END ----
                String certWithoutBegin = cert.replaceFirst("-----BEGIN CERTIFICATE-----", "");
                String rawCert = certWithoutBegin.replaceFirst("-----END CERTIFICATE-----", "");
                X509Certificate x509 = X509Certificate.getInstance(Base64.decodeBase64(rawCert.getBytes()));
                // TODO use some defined date/time format
                DateFormat dateFormat = DateFormat.getDateInstance();
                certsExpirations.put(certDN, dateFormat.format(x509.getNotAfter()));
            }
            attribute = Utils.copyAttributeToViAttributeWithoutValue(userCertsAttribute, attribute);
        }
    } catch (AttributeNotExistsException ex) {
    // FIXME throw new WrongReferenceAttributeValueException("User " + user + " doesn't have assigned urn:perun:user:attribute-def:def:userCertificates attribute", ex);
    } catch (CertificateException e) {
        throw new InternalErrorException("CertificateException - user: " + user + ".", e);
    }
    attribute.setValue(certsExpirations);
    return attribute;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) DateFormat(java.text.DateFormat) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) CertificateException(javax.security.cert.CertificateException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) X509Certificate(javax.security.cert.X509Certificate) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with CertificateException

use of javax.security.cert.CertificateException in project j2objc by google.

the class CertificateExceptionTest method testCertificateException02.

/**
     * Test for <code>CertificateException(String)</code> constructor
     * Assertion: constructs CertificateException with detail message msg.
     * Parameter <code>msg</code> is not null.
     */
public void testCertificateException02() {
    CertificateException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new CertificateException(msgs[i]);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : CertificateException(javax.security.cert.CertificateException)

Example 9 with CertificateException

use of javax.security.cert.CertificateException in project j2objc by google.

the class CertificateExceptionTest method testCertificateException01.

/**
     * Test for <code>CertificateException()</code> constructor Assertion:
     * constructs CertificateException with no detail message
     */
public void testCertificateException01() {
    CertificateException tE = new CertificateException();
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CertificateException(javax.security.cert.CertificateException)

Example 10 with CertificateException

use of javax.security.cert.CertificateException in project j2objc by google.

the class X509CertificateTest method testGetInstance1.

/**
     * getInstance(InputStream inStream) method testing.
     */
public void testGetInstance1() {
    if (this.cert == null) {
        // Test can not be applied.
        return;
    }
    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(cert.getEncoded());
        X509Certificate.getInstance(bais);
    } catch (java.security.cert.CertificateEncodingException e) {
        fail("Unexpected CertificateEncodingException was thrown.");
    } catch (CertificateEncodingException e) {
        fail("Unexpected CertificateEncodingException was thrown.");
    } catch (CertificateException e) {
    // The requested certificate type is not available.
    // Test pass..
    }
    // Regression for HARMONY-756
    try {
        X509Certificate.getInstance((InputStream) null);
        fail("No expected CertificateException");
    } catch (CertificateException e) {
    // expected;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateEncodingException(javax.security.cert.CertificateEncodingException) CertificateException(javax.security.cert.CertificateException)

Aggregations

CertificateException (javax.security.cert.CertificateException)17 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 X509Certificate (java.security.cert.X509Certificate)3 CertificateEncodingException (javax.security.cert.CertificateEncodingException)3 X509Certificate (javax.security.cert.X509Certificate)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 PublicKey (java.security.PublicKey)2 LinkedHashMap (java.util.LinkedHashMap)2 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)2 Attribute (cz.metacentrum.perun.core.api.Attribute)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)1 SideEffect (dalvik.annotation.SideEffect)1 TpmModuleException (gov.niarl.his.privacyca.TpmModule.TpmModuleException)1 IHisPrivacyCAWebService2 (gov.niarl.his.webservices.hisPrivacyCAWebService2.IHisPrivacyCAWebService2)1 BasicSSLSessionInfo (io.undertow.server.BasicSSLSessionInfo)1