use of java.security.cert.CertificateParsingException in project robovm by robovm.
the class CertificateParsingExceptionTest method testCertificateParsingException05.
/**
* Test for <code>CertificateParsingException(Throwable)</code>
* constructor Assertion: constructs CertificateParsingException when
* <code>cause</code> is not null
*/
public void testCertificateParsingException05() {
CertificateParsingException tE = new CertificateParsingException(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);
}
use of java.security.cert.CertificateParsingException in project robovm by robovm.
the class CertificateParsingExceptionTest method testCertificateParsingException01.
/**
* Test for <code>CertificateParsingException()</code> constructor
* Assertion: constructs CertificateParsingException with no detail message
*/
public void testCertificateParsingException01() {
CertificateParsingException tE = new CertificateParsingException();
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of java.security.cert.CertificateParsingException in project robovm by robovm.
the class X509CertificateTest method generateCertificates_X509_DER_TrailingData.
private void generateCertificates_X509_DER_TrailingData(CertificateFactory f) throws Exception {
byte[] certBytes = getResourceAsBytes(CERTS_X509_DER);
byte[] certsPlusExtra = new byte[certBytes.length + 4096];
System.arraycopy(certBytes, 0, certsPlusExtra, 0, certBytes.length);
ByteArrayInputStream bais = new ByteArrayInputStream(certsPlusExtra);
assertEquals(certsPlusExtra.length, bais.available());
// RI is broken
try {
Collection<? extends X509Certificate> certs = (Collection<? extends X509Certificate>) f.generateCertificates(bais);
if (StandardNames.IS_RI) {
fail("RI fails on this test.");
}
} catch (CertificateParsingException e) {
if (StandardNames.IS_RI) {
return;
}
throw e;
}
// Bouncycastle is broken
if ("BC".equals(f.getProvider().getName())) {
assertEquals(0, bais.available());
} else {
assertEquals(4096, bais.available());
}
}
use of java.security.cert.CertificateParsingException in project robovm by robovm.
the class X509V3CertificateGenerator method generate.
/**
* generate an X509 certificate, based on the current issuer and subject
* using the default provider, and the passed in source of randomness
* (if required).
* <p>
* <b>Note:</b> this differs from the deprecated method in that the default provider is
* used - not "BC".
* </p>
*/
public X509Certificate generate(PrivateKey key, SecureRandom random) throws CertificateEncodingException, IllegalStateException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
TBSCertificate tbsCert = generateTbsCert();
byte[] signature;
try {
signature = X509Util.calculateSignature(sigOID, signatureAlgorithm, key, random, tbsCert);
} catch (IOException e) {
throw new ExtCertificateEncodingException("exception encoding TBS cert", e);
}
try {
return generateJcaObject(tbsCert, signature);
} catch (CertificateParsingException e) {
throw new ExtCertificateEncodingException("exception producing certificate object", e);
}
}
use of java.security.cert.CertificateParsingException in project robovm by robovm.
the class X509V3CertificateGenerator method generate.
/**
* generate an X509 certificate, based on the current issuer and subject,
* using the passed in provider for the signing and the supplied source
* of randomness, if required.
*/
public X509Certificate generate(PrivateKey key, String provider, SecureRandom random) throws CertificateEncodingException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
TBSCertificate tbsCert = generateTbsCert();
byte[] signature;
try {
signature = X509Util.calculateSignature(sigOID, signatureAlgorithm, provider, key, random, tbsCert);
} catch (IOException e) {
throw new ExtCertificateEncodingException("exception encoding TBS cert", e);
}
try {
return generateJcaObject(tbsCert, signature);
} catch (CertificateParsingException e) {
throw new ExtCertificateEncodingException("exception producing certificate object", e);
}
}
Aggregations