Search in sources :

Example 1 with KeyPairAlgorithm

use of de.carne.certmgr.certs.security.KeyPairAlgorithm in project certmgr by hdecarne.

the class CertOptionsController method resetSigAlgOptions.

private void resetSigAlgOptions(@Nullable Issuer issuer) {
    CertGenerator generator = this.ctlGeneratorOption.getValue();
    KeyPairAlgorithm keyPairAlgorithm = this.ctlKeyAlgOption.getValue();
    resetSigAlgOptions(generator, keyPairAlgorithm, issuer);
}
Also used : KeyPairAlgorithm(de.carne.certmgr.certs.security.KeyPairAlgorithm) CertGenerator(de.carne.certmgr.certs.spi.CertGenerator)

Example 2 with KeyPairAlgorithm

use of de.carne.certmgr.certs.security.KeyPairAlgorithm in project certmgr by hdecarne.

the class CertOptionsTemplates method storeTemplate.

private static void storeTemplate(Preferences templateNode, Template template) throws IOException {
    templateNode.put(Template.KEY_NAME, template.getName());
    templateNode.put(Template.KEY_ALIAS, template.aliasInput());
    templateNode.put(Template.KEY_DN, template.dnInput());
    KeyPairAlgorithm keyAlg = template.getKeyAlg();
    if (keyAlg != null) {
        templateNode.put(Template.KEY_KEYALG, keyAlg.algorithm());
    }
    Integer keySize = template.getKeySize();
    if (keySize != null) {
        templateNode.putInt(Template.KEY_KEYSIZE, keySize);
    }
    int extensionIndex = 0;
    for (X509ExtensionData extension : template.getExtensions()) {
        Preferences extensionNode = templateNode.node("extension" + extensionIndex);
        extensionNode.put(Template.KEY_EXTENSION_OID, extension.oid());
        extensionNode.putBoolean(Template.KEY_EXTENSION_CRITICAL, extension.getCritical());
        extensionNode.putByteArray(Template.KEY_EXTENSION_DATA, extension.getEncoded());
        extensionIndex++;
    }
}
Also used : X509ExtensionData(de.carne.certmgr.certs.x509.X509ExtensionData) KeyPairAlgorithm(de.carne.certmgr.certs.security.KeyPairAlgorithm) Preferences(java.util.prefs.Preferences) DistributionPoint(de.carne.certmgr.certs.x509.DistributionPoint)

Example 3 with KeyPairAlgorithm

use of de.carne.certmgr.certs.security.KeyPairAlgorithm in project certmgr by hdecarne.

the class KeyPairAlgorithmTest method testKeySizes.

/**
 * Test whether the standard key sizes are valid.
 */
@Test
public void testKeySizes() {
    DefaultSet<KeyPairAlgorithm> algorithms = KeyPairAlgorithm.getDefaultSet(null, true);
    Assert.assertTrue(algorithms.contains(algorithms.getDefault()));
    for (KeyPairAlgorithm algorithm : algorithms) {
        System.out.println("Algorithm: " + algorithm);
        try {
            KeyPairGenerator generator = algorithm.getInstance();
            DefaultSet<Integer> keySizes = algorithm.getStandardKeySizes(null);
            if (keySizes.size() > 0) {
                Integer defaultKeySize = keySizes.getDefault();
                Assert.assertTrue(keySizes.contains(defaultKeySize));
                for (Integer keySize : keySizes) {
                    System.out.println("Key size: " + keySize);
                    try {
                        generator.initialize(keySize);
                    } catch (InvalidParameterException e) {
                        Assert.fail("Cannot get initialize algorithm '" + algorithm + "' with key size " + keySize + ": " + e.getMessage());
                    }
                }
            }
        } catch (GeneralSecurityException e) {
            Assert.fail("Cannot get instance for algorithm '" + algorithm + "': " + e.getMessage());
        }
    }
}
Also used : KeyPairAlgorithm(de.carne.certmgr.certs.security.KeyPairAlgorithm) InvalidParameterException(java.security.InvalidParameterException) GeneralSecurityException(java.security.GeneralSecurityException) KeyPairGenerator(java.security.KeyPairGenerator) Test(org.junit.Test)

Example 4 with KeyPairAlgorithm

use of de.carne.certmgr.certs.security.KeyPairAlgorithm 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 5 with KeyPairAlgorithm

use of de.carne.certmgr.certs.security.KeyPairAlgorithm in project certmgr by hdecarne.

the class CertOptionsController method resetSigAlgOptions.

private void resetSigAlgOptions(@Nullable CertGenerator generator) {
    KeyPairAlgorithm keyPairAlgorithm = this.ctlKeyAlgOption.getValue();
    Issuer issuer = this.ctlIssuerInput.getValue();
    resetSigAlgOptions(generator, keyPairAlgorithm, issuer);
}
Also used : KeyPairAlgorithm(de.carne.certmgr.certs.security.KeyPairAlgorithm) Issuer(de.carne.certmgr.certs.x509.generator.Issuer)

Aggregations

KeyPairAlgorithm (de.carne.certmgr.certs.security.KeyPairAlgorithm)9 Test (org.junit.Test)3 GenerateCertRequest (de.carne.certmgr.certs.x509.GenerateCertRequest)2 X509ExtensionData (de.carne.certmgr.certs.x509.X509ExtensionData)2 Date (java.util.Date)2 SignatureAlgorithm (de.carne.certmgr.certs.security.SignatureAlgorithm)1 CertGenerator (de.carne.certmgr.certs.spi.CertGenerator)1 BasicConstraintsExtensionData (de.carne.certmgr.certs.x509.BasicConstraintsExtensionData)1 CRLDistributionPointsExtensionData (de.carne.certmgr.certs.x509.CRLDistributionPointsExtensionData)1 DistributionPoint (de.carne.certmgr.certs.x509.DistributionPoint)1 ExtendedKeyUsageExtensionData (de.carne.certmgr.certs.x509.ExtendedKeyUsageExtensionData)1 KeyUsageExtensionData (de.carne.certmgr.certs.x509.KeyUsageExtensionData)1 SubjectAlternativeNameExtensionData (de.carne.certmgr.certs.x509.SubjectAlternativeNameExtensionData)1 Issuer (de.carne.certmgr.certs.x509.generator.Issuer)1 GeneralSecurityException (java.security.GeneralSecurityException)1 InvalidParameterException (java.security.InvalidParameterException)1 KeyPairGenerator (java.security.KeyPairGenerator)1 LocalDate (java.time.LocalDate)1 Preferences (java.util.prefs.Preferences)1 X500Principal (javax.security.auth.x500.X500Principal)1