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());
}
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);
}
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);
}
}
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());
}
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;
}
Aggregations