use of java.security.cert.CertificateParsingException in project robovm by robovm.
the class X509CertificateTest method generateCertificates_X509_PEM_TrailingData.
private void generateCertificates_X509_PEM_TrailingData(CertificateFactory f) throws Exception {
byte[] certBytes = getResourceAsBytes(CERTS_X509_PEM);
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 CertificateParsingExceptionTest method testCertificateParsingException09.
/**
* Test for <code>CertificateParsingException(String, Throwable)</code>
* constructor Assertion: constructs CertificateParsingException when
* <code>cause</code> is not null <code>msg</code> is not null
*/
public void testCertificateParsingException09() {
CertificateParsingException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new CertificateParsingException(msgs[i], tCause);
String getM = tE.getMessage();
String toS = tCause.toString();
if (msgs[i].length() > 0) {
assertTrue("getMessage() must contain ".concat(msgs[i]), getM.indexOf(msgs[i]) != -1);
if (!getM.equals(msgs[i])) {
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 testCertificateParsingException02.
/**
* Test for <code>CertificateParsingException(String)</code> constructor
* Assertion: constructs CertificateParsingException with detail message
* msg. Parameter <code>msg</code> is not null.
*/
public void testCertificateParsingException02() {
CertificateParsingException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new CertificateParsingException(msgs[i]);
assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
assertNull("getCause() must return null", tE.getCause());
}
}
use of java.security.cert.CertificateParsingException in project robovm by robovm.
the class CertificateParsingExceptionTest method testCertificateParsingException04.
/**
* Test for <code>CertificateParsingException(Throwable)</code>
* constructor Assertion: constructs CertificateParsingException when
* <code>cause</code> is null
*/
public void testCertificateParsingException04() {
Throwable cause = null;
CertificateParsingException tE = new CertificateParsingException(cause);
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of java.security.cert.CertificateParsingException in project XobotOS by xamarin.
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 {
TBSCertificateStructure 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