use of com.liumapp.digitalsign.engine.keystore.entity.CSR in project spring-cloud-digital-sign by SpringForAll.
the class KeyToolsTest method shouldGenerateCertificateSignRequest.
@Ignore
@Test
public void shouldGenerateCertificateSignRequest() throws Exception {
Resource resource = Resource.from("classpath:keystore.ks");
KeyStoreAdapter keyStoreAdapter = KeyTools.keyStoreFrom(resource, "1234");
CSR csr = keyStoreAdapter.generateCSR("test", "456");
assertNotNull(csr);
assertNotNull(csr.toPkcs10());
assertEquals("CN=Andrea Como, ST=Toscana, L=Prato, C=IT", csr.toPkcs10().getSubjectName().toString());
}
use of com.liumapp.digitalsign.engine.keystore.entity.CSR in project spring-cloud-digital-sign by SpringForAll.
the class KeyToolsTest method shouldSignCertificateSignRequest.
@Ignore
@Test
public void shouldSignCertificateSignRequest() throws Exception {
Resource resource = Resource.from("classpath:keystore.ks");
KeyStoreAdapter requesterKeyStore = KeyTools.keyStoreFrom(resource, "1234");
X509Certificate[] certificates = requesterKeyStore.getCertificates("test");
assertEquals(1, certificates.length);
CSR csr = requesterKeyStore.generateCSR("test", "456");
Resource ca = Resource.from("classpath:ca.ks");
KeyStoreAdapter caKeyStore = KeyTools.keyStoreFrom(ca, "ca");
P7B signResponse = caKeyStore.signCSR(csr, "ca", "ca").withValidity(1, ChronoUnit.YEARS).sign();
requesterKeyStore.importCAReply(signResponse, "test", "456");
certificates = requesterKeyStore.getCertificates("test");
assertEquals(2, certificates.length);
}
use of com.liumapp.digitalsign.engine.keystore.entity.CSR in project spring-cloud-digital-sign by SpringForAll.
the class KeyStoreAdapter method generateCSR.
public CSR generateCSR(String alias, String password) throws KeyStoreException {
try {
KeyPair keyPair = getKayPairFor(alias, password).orElseThrow(() -> new KeyStoreException("Cannot find key for alias " + alias));
;
// CSR container format
PKCS10 pkcs10 = new PKCS10(keyPair.getPublic());
Signature signature = Signature.getInstance("SHA256withRSA");
signature.initSign(keyPair.getPrivate());
pkcs10.encodeAndSign(getX500Name(this.keyStore.getCertificate(alias)), signature);
return new CSR(pkcs10);
} catch (NoSuchAlgorithmException | InvalidKeyException | CertificateException | IOException | SignatureException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
throw new KeyStoreException(e);
}
}
Aggregations