use of de.carne.certmgr.certs.x509.GenerateCertRequest in project certmgr by hdecarne.
the class RemoteCertGenerator method generateCert.
@Override
public CertObjectStore generateCert(GenerateCertRequest request, PasswordCallback password) throws IOException {
KeyPair key = KeyHelper.generateKey(request.keyPairAlgorithm(), request.keySize());
SignatureAlgorithm signatureAlgorithm = requiredParameter(request.getSignatureAlgorithm(), "SignatureAlgorithm");
PKCS10CertificateRequest csr = PKCS10CertificateRequest.generateCSR(request.dn(), key, request.getExtensions(), signatureAlgorithm);
CertObjectStore certObjects = new CertObjectStore();
certObjects.addKey(key);
certObjects.addCSR(csr);
return certObjects;
}
use of de.carne.certmgr.certs.x509.GenerateCertRequest in project certmgr by hdecarne.
the class UserCertStoreTest method testCreateAndOpenStore.
/**
* Test create/open store operations.
*/
@Test
public void testCreateAndOpenStore() {
Path storeHome = tempPath.get().resolve(NAME_STORE1);
try {
UserCertStore createdStore = UserCertStore.createStore(storeHome);
GenerateCertRequest request1 = generateRequest(createdStore, CertGenerators.DEFAULT, true);
UserCertStoreEntry generated1 = createdStore.generateEntry(CertGenerators.DEFAULT, request1, TestCerts.password(), TestCerts.password(), "TestCert");
DefaultSet<Issuer> issuers1 = CertGenerators.DEFAULT.getIssuers(createdStore, generated1);
GenerateCertRequest request2 = generateRequest(createdStore, CertGenerators.DEFAULT, false);
request2.setIssuer(issuers1.getDefault());
createdStore.generateEntry(CertGenerators.DEFAULT, request1, TestCerts.password(), TestCerts.password(), "TestCert");
Assert.assertEquals(2, createdStore.size());
} catch (IOException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
try {
UserCertStore.createStore(storeHome);
Assert.fail("Re-creating store succeeded, but should not");
} catch (FileAlreadyExistsException e) {
Exceptions.ignore(e);
} catch (IOException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
try {
UserCertStore openendStore = UserCertStore.openStore(storeHome);
Assert.assertEquals(2, openendStore.size());
} catch (IOException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of de.carne.certmgr.certs.x509.GenerateCertRequest in project certmgr by hdecarne.
the class CertOptionsController method validateAndGetGenerateRequest.
private GenerateCertRequest validateAndGetGenerateRequest(CertGenerator generator) throws ValidationException {
X500Principal dn = validateAndGetDN();
KeyPairAlgorithm keyAlg = validateAndGetKeyAlg();
int keySize = validateAndGetKeySize();
GenerateCertRequest generateRequest = new GenerateCertRequest(dn, keyAlg, keySize);
if (generator.hasFeature(CertGenerator.Feature.CUSTOM_ISSUER)) {
generateRequest.setIssuer(validateAndGetIssuer());
}
if (generator.hasFeature(CertGenerator.Feature.CUSTOM_SIGNATURE_ALGORITHM)) {
generateRequest.setSignatureAlgorithm(validateAndGetSigAlg());
}
if (generator.hasFeature(CertGenerator.Feature.CUSTOM_VALIDITY)) {
Date notBefore = validateAndGetNotBefore();
Date notAfter = validateAndGetNotAfter(notBefore);
generateRequest.setNotBefore(notBefore);
generateRequest.setNotAfter(notAfter);
}
if (generator.hasFeature(CertGenerator.Feature.CUSTOM_EXTENSIONS)) {
for (ExtensionDataModel extensionItem : this.ctlExtensionData.getItems()) {
generateRequest.addExtension(extensionItem.getExtensionData());
}
}
return generateRequest;
}
use of de.carne.certmgr.certs.x509.GenerateCertRequest in project certmgr by hdecarne.
the class CertOptionsController method onCmdGenerate.
@SuppressWarnings("unused")
@FXML
void onCmdGenerate(ActionEvent evt) {
try {
String alias = validateAndGetAlias();
CertGenerator generator = validateAndGetGenerator();
GenerateCertRequest generateRequest = validateAndGetGenerateRequest(generator);
getExecutorService().submit(new GenerateEntryTask(generator, generateRequest, alias));
} catch (ValidationException e) {
ValidationAlerts.error(e).showAndWait();
}
}
use of de.carne.certmgr.certs.x509.GenerateCertRequest in project certmgr by hdecarne.
the class UserCertStoreTest method generateRequest.
private GenerateCertRequest generateRequest(UserCertStore store, CertGenerator generator, boolean ca) {
GenerateCertRequest request = basicRequest();
if (generator.hasFeature(CertGenerator.Feature.CUSTOM_ISSUER)) {
request.setIssuer(generator.getIssuers(store, null).getDefault());
}
if (generator.hasFeature(CertGenerator.Feature.CUSTOM_SIGNATURE_ALGORITHM)) {
request.setSignatureAlgorithm(Check.notNull(generator.getSignatureAlgorithms(request.getIssuer(), request.keyPairAlgorithm(), null, false).getDefault()));
}
request.addExtension(new BasicConstraintsExtensionData(false, ca, null));
return request;
}
Aggregations