use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project athenz by yahoo.
the class CryptoTest method testExtractX509CSRFieldsURINull.
@Test
public void testExtractX509CSRFieldsURINull() throws IOException {
Path path = Paths.get("src/test/resources/valid_email.csr");
String csr = new String(Files.readAllBytes(path));
PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(csr);
assertNotNull(certReq);
List<String> uris = Crypto.extractX509CSRURIs(certReq);
assertEquals(0, uris.size());
}
use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project athenz by yahoo.
the class CryptoTest method testExtractX509CSRFieldsURISingle.
@Test
public void testExtractX509CSRFieldsURISingle() throws IOException {
Path path = Paths.get("src/test/resources/valid_single_uri.csr");
String csr = new String(Files.readAllBytes(path));
PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(csr);
assertNotNull(certReq);
List<String> uris = Crypto.extractX509CSRURIs(certReq);
assertEquals(1, uris.size());
assertEquals(uris.get(0), "spiffe://athenz/domain1/service1");
}
use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project athenz by yahoo.
the class CryptoTest method testExtractX509CSRFieldsURIDouble.
@Test
public void testExtractX509CSRFieldsURIDouble() throws IOException {
Path path = Paths.get("src/test/resources/valid_multiple_uri.csr");
String csr = new String(Files.readAllBytes(path));
PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(csr);
assertNotNull(certReq);
List<String> uris = Crypto.extractX509CSRURIs(certReq);
assertEquals(2, uris.size());
assertEquals(uris.get(0), "spiffe://athenz/domain1/service1");
assertEquals(uris.get(1), "spiffe://athenz/domain1/service2");
}
use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project athenz by yahoo.
the class KeyStoreCertSigner method generateX509Certificate.
@Override
public String generateX509Certificate(String provider, String certIssuer, String csr, String keyUsage, int certExpiryMins, Priority priority) {
int certExpiryTime = (certExpiryMins == 0) ? this.maxCertExpiryTimeMins : certExpiryMins;
PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(csr);
// keyUsage is ignored
X509Certificate cert = Crypto.generateX509Certificate(certReq, caPrivateKey, caCertificate, certExpiryTime, false);
return Crypto.convertToPEMFormat(cert);
}
use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project athenz by yahoo.
the class SelfCertSignerFactory method create.
@Override
public CertSigner create() {
// extract the private key for this self cert signer
final String pKeyFileName = System.getProperty(ZTSConsts.ZTS_PROP_SELF_SIGNER_PRIVATE_KEY_FNAME);
final String pKeyPassword = System.getProperty(ZTSConsts.ZTS_PROP_SELF_SIGNER_PRIVATE_KEY_PASSWORD);
final String csrDn = System.getProperty(ZTSConsts.ZTS_PROP_SELF_SIGNER_CERT_DN, "cn=Self Signed Athenz CA,o=Athenz,c=US");
final int maxCertExpiryTimeMins = Integer.parseInt(System.getProperty(ZTSConsts.ZTS_PROP_CERTSIGN_MAX_EXPIRY_TIME, "43200"));
if (StringUtil.isEmpty(pKeyFileName)) {
LOGGER.error("No private key path available for Self Cert Signer Factory");
return null;
}
File caKey = new File(pKeyFileName);
PrivateKey caPrivateKey = Crypto.loadPrivateKey(caKey, pKeyPassword);
// now generate a CSR for our own CA and self sign it
String csr;
try {
csr = Crypto.generateX509CSR(caPrivateKey, csrDn, null);
} catch (IllegalArgumentException | OperatorCreationException | IOException ex) {
LOGGER.error("Unable to generate X509 CSR for dn: {}, error: {}", csrDn, ex.getMessage());
return null;
}
// generate our self-signed certificate
X500Principal subject = new X500Principal(csrDn);
X500Name issuer = X500Name.getInstance(subject.getEncoded());
PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(csr);
X509Certificate caCertificate = Crypto.generateX509Certificate(certReq, caPrivateKey, issuer, 30 * 24 * 60, true);
return new KeyStoreCertSigner(caCertificate, caPrivateKey, maxCertExpiryTimeMins);
}
Aggregations