Search in sources :

Example 1 with GenerateCertRequest

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;
}
Also used : KeyPair(java.security.KeyPair) PKCS10CertificateRequest(de.carne.certmgr.certs.x509.PKCS10CertificateRequest) SignatureAlgorithm(de.carne.certmgr.certs.security.SignatureAlgorithm) CertObjectStore(de.carne.certmgr.certs.CertObjectStore)

Example 2 with GenerateCertRequest

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());
    }
}
Also used : Path(java.nio.file.Path) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) Issuer(de.carne.certmgr.certs.x509.generator.Issuer) IOException(java.io.IOException) GenerateCertRequest(de.carne.certmgr.certs.x509.GenerateCertRequest) UserCertStore(de.carne.certmgr.certs.UserCertStore) UserCertStoreEntry(de.carne.certmgr.certs.UserCertStoreEntry) Test(org.junit.Test)

Example 3 with GenerateCertRequest

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;
}
Also used : KeyPairAlgorithm(de.carne.certmgr.certs.security.KeyPairAlgorithm) X500Principal(javax.security.auth.x500.X500Principal) GenerateCertRequest(de.carne.certmgr.certs.x509.GenerateCertRequest) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 4 with GenerateCertRequest

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();
    }
}
Also used : CertGenerator(de.carne.certmgr.certs.spi.CertGenerator) ValidationException(de.carne.jfx.util.validation.ValidationException) GenerateCertRequest(de.carne.certmgr.certs.x509.GenerateCertRequest) FXML(javafx.fxml.FXML)

Example 5 with GenerateCertRequest

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;
}
Also used : BasicConstraintsExtensionData(de.carne.certmgr.certs.x509.BasicConstraintsExtensionData) GenerateCertRequest(de.carne.certmgr.certs.x509.GenerateCertRequest)

Aggregations

GenerateCertRequest (de.carne.certmgr.certs.x509.GenerateCertRequest)5 KeyPairAlgorithm (de.carne.certmgr.certs.security.KeyPairAlgorithm)2 Date (java.util.Date)2 CertObjectStore (de.carne.certmgr.certs.CertObjectStore)1 UserCertStore (de.carne.certmgr.certs.UserCertStore)1 UserCertStoreEntry (de.carne.certmgr.certs.UserCertStoreEntry)1 SignatureAlgorithm (de.carne.certmgr.certs.security.SignatureAlgorithm)1 CertGenerator (de.carne.certmgr.certs.spi.CertGenerator)1 BasicConstraintsExtensionData (de.carne.certmgr.certs.x509.BasicConstraintsExtensionData)1 PKCS10CertificateRequest (de.carne.certmgr.certs.x509.PKCS10CertificateRequest)1 Issuer (de.carne.certmgr.certs.x509.generator.Issuer)1 ValidationException (de.carne.jfx.util.validation.ValidationException)1 IOException (java.io.IOException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 Path (java.nio.file.Path)1 KeyPair (java.security.KeyPair)1 LocalDate (java.time.LocalDate)1 FXML (javafx.fxml.FXML)1 X500Principal (javax.security.auth.x500.X500Principal)1 Test (org.junit.Test)1