use of org.bouncycastle.jce.provider.X509CertificateObject in project robovm by robovm.
the class X509V3CertificateGenerator method generateJcaObject.
private X509Certificate generateJcaObject(TBSCertificate tbsCert, byte[] signature) throws CertificateParsingException {
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(tbsCert);
v.add(sigAlgId);
v.add(new DERBitString(signature));
return new X509CertificateObject(Certificate.getInstance(new DERSequence(v)));
}
use of org.bouncycastle.jce.provider.X509CertificateObject in project cas by apereo.
the class WsFederationHelper method getEncryptionCredential.
/**
* Gets encryption credential.
* The encryption private key will need to contain the private keypair in PEM format.
* The encryption certificate is shared with ADFS in DER format, i.e certificate.crt.
*
* @param config the config
* @return the encryption credential
*/
@SneakyThrows
private static Credential getEncryptionCredential(final WsFederationConfiguration config) {
LOGGER.debug("Locating encryption credential private key [{}]", config.getEncryptionPrivateKey());
val br = new BufferedReader(new InputStreamReader(config.getEncryptionPrivateKey().getInputStream(), StandardCharsets.UTF_8));
Security.addProvider(new BouncyCastleProvider());
LOGGER.debug("Parsing credential private key");
try (val pemParser = new PEMParser(br)) {
val privateKeyPemObject = pemParser.readObject();
val converter = new JcaPEMKeyConverter().setProvider(new BouncyCastleProvider());
val kp = FunctionUtils.doIf(Predicates.instanceOf(PEMEncryptedKeyPair.class), Unchecked.supplier(() -> {
LOGGER.debug("Encryption private key is an encrypted keypair");
val ckp = (PEMEncryptedKeyPair) privateKeyPemObject;
val decProv = new JcePEMDecryptorProviderBuilder().build(config.getEncryptionPrivateKeyPassword().toCharArray());
LOGGER.debug("Attempting to decrypt the encrypted keypair based on the provided encryption private key password");
return converter.getKeyPair(ckp.decryptKeyPair(decProv));
}), Unchecked.supplier(() -> {
LOGGER.debug("Extracting a keypair from the private key");
return converter.getKeyPair((PEMKeyPair) privateKeyPemObject);
})).apply(privateKeyPemObject);
val certParser = new X509CertParser();
LOGGER.debug("Locating encryption certificate [{}]", config.getEncryptionCertificate());
certParser.engineInit(config.getEncryptionCertificate().getInputStream());
LOGGER.debug("Invoking certificate engine to parse the certificate [{}]", config.getEncryptionCertificate());
val cert = (X509CertificateObject) certParser.engineRead();
LOGGER.debug("Creating final credential based on the certificate [{}] and the private key", cert.getIssuerDN());
return new BasicX509Credential(cert, kp.getPrivate());
}
}
use of org.bouncycastle.jce.provider.X509CertificateObject in project TLS-Scanner by RUB-NDS.
the class CertificateReportGenerator method setSignatureAndHashAlgorithm.
private static void setSignatureAndHashAlgorithm(CertificateReportImplementation report, org.bouncycastle.asn1.x509.Certificate cert) {
String sigAndHashString = null;
try {
X509CertificateObject x509Cert = new X509CertificateObject(cert);
sigAndHashString = x509Cert.getSigAlgName();
if (sigAndHashString != null) {
String[] algos = sigAndHashString.toUpperCase().split("WITH");
if (algos.length != 2) {
LOGGER.warn("Could not parse " + sigAndHashString + " into a reasonable SignatureAndHash algorithm");
return;
}
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.valueOf(algos[1]);
HashAlgorithm hashAlgorithm = HashAlgorithm.valueOf(algos[0]);
if (hashAlgorithm == null) {
LOGGER.warn("Parsed an unknown HashAlgorithm");
return;
}
if (signatureAlgorithm == null) {
LOGGER.warn("Parsed an unknown SignatureAlgorithm");
return;
}
SignatureAndHashAlgorithm sigHashAlgo = new SignatureAndHashAlgorithm(signatureAlgorithm, hashAlgorithm);
report.setSignatureAndHashAlgorithm(sigHashAlgo);
}
} catch (Exception E) {
LOGGER.debug("Could not extraxt SignatureAndHashAlgorithm from String:" + sigAndHashString, E);
}
}
Aggregations