use of java.security.cert.CertificateException in project scdl by passy.
the class PinningTrustManagerImpl method initializeSystemTrustManagers.
private TrustManager[] initializeSystemTrustManagers() throws CertificateException {
try {
final TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
tmf.init((KeyStore) null);
return tmf.getTrustManagers();
} catch (final NoSuchAlgorithmException nsae) {
throw new CertificateException(nsae);
} catch (final KeyStoreException e) {
throw new CertificateException(e);
}
}
use of java.security.cert.CertificateException in project scdl by passy.
the class SystemKeyStore method getTrustRoot.
public X509Certificate getTrustRoot(final X509Certificate[] chain) throws CertificateException {
try {
final CertPath certPath = certificateFactory.generateCertPath(Arrays.asList(chain));
final PKIXCertPathValidatorResult result = (PKIXCertPathValidatorResult) validator.validate(certPath, parameters);
if (result == null) {
return null;
} else {
return result.getTrustAnchor().getTrustedCert();
}
} catch (final CertPathValidatorException e) {
return null;
} catch (final InvalidAlgorithmParameterException e) {
throw new CertificateException(e);
}
}
use of java.security.cert.CertificateException in project robovm by robovm.
the class ProvisioningProfile method getCertFingerprint.
private static String getCertFingerprint(byte[] certData) {
try {
CertificateFactory x509CertFact = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) x509CertFact.generateCertificate(new ByteArrayInputStream(certData));
MessageDigest md = MessageDigest.getInstance("SHA-1");
return toHexString(md.digest(cert.getEncoded()));
} catch (CertificateException e) {
throw new RuntimeException(e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
use of java.security.cert.CertificateException in project robovm by robovm.
the class BcKeyStoreSpi method decodeCertificate.
private Certificate decodeCertificate(DataInputStream dIn) throws IOException {
String type = dIn.readUTF();
byte[] cEnc = new byte[dIn.readInt()];
dIn.readFully(cEnc);
try {
CertificateFactory cFact = CertificateFactory.getInstance(type, BouncyCastleProvider.PROVIDER_NAME);
ByteArrayInputStream bIn = new ByteArrayInputStream(cEnc);
return cFact.generateCertificate(bIn);
} catch (NoSuchProviderException ex) {
throw new IOException(ex.toString());
} catch (CertificateException ex) {
throw new IOException(ex.toString());
}
}
use of java.security.cert.CertificateException in project robovm by robovm.
the class X509CertFactoryImpl method engineGenerateCertPath.
/**
* @see java.security.cert.CertificateFactorySpi#engineGenerateCertPath(InputStream,String)
* method documentation for more info
*/
public CertPath engineGenerateCertPath(InputStream inStream, String encoding) throws CertificateException {
if (inStream == null) {
throw new CertificateException("inStream == null");
}
if (!inStream.markSupported()) {
inStream = new RestoringInputStream(inStream);
}
try {
inStream.mark(1);
int ch;
// check if it is PEM encoded form
if ((ch = inStream.read()) == '-') {
// decode PEM chunk into ASN.1 form and decode CertPath object
return X509CertPathImpl.getInstance(decodePEM(inStream, FREE_BOUND_SUFFIX), encoding);
} else if (ch == 0x30) {
// ASN.1 Sequence
inStream.reset();
// decode ASN.1 form
return X509CertPathImpl.getInstance(inStream, encoding);
} else {
throw new CertificateException("Unsupported encoding");
}
} catch (IOException e) {
throw new CertificateException(e);
}
}
Aggregations