Search in sources :

Example 6 with KeyPairAlgorithm

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

the class CertOptionsController method applyPreset.

private void applyPreset(CertOptionsPreset preset) {
    this.ctlAliasInput.setText(preset.aliasInput());
    this.ctlDNInput.setText(preset.dnInput());
    KeyPairAlgorithm keyAlg = preset.getKeyAlg();
    if (keyAlg != null) {
        this.ctlKeyAlgOption.setValue(preset.getKeyAlg());
    }
    Integer keySize = preset.getKeySize();
    if (keySize != null) {
        this.ctlKeySizeOption.setValue(preset.getKeySize());
    }
    this.basicConstraintsExtension.set(null);
    this.keyUsageExtension.set(null);
    this.extendedKeyUsageExtension.set(null);
    this.subjectAlternativeExtension.set(null);
    this.crlDistributionPointsExtension.set(null);
    this.ctlExtensionData.getItems().clear();
    for (X509ExtensionData extensionData : preset.getExtensions()) {
        if (extensionData instanceof BasicConstraintsExtensionData) {
            this.basicConstraintsExtension.set((BasicConstraintsExtensionData) extensionData);
        } else if (extensionData instanceof KeyUsageExtensionData) {
            this.keyUsageExtension.set((KeyUsageExtensionData) extensionData);
        } else if (extensionData instanceof ExtendedKeyUsageExtensionData) {
            this.extendedKeyUsageExtension.set((ExtendedKeyUsageExtensionData) extensionData);
        } else if (extensionData instanceof SubjectAlternativeNameExtensionData) {
            this.subjectAlternativeExtension.set((SubjectAlternativeNameExtensionData) extensionData);
        } else if (extensionData instanceof CRLDistributionPointsExtensionData) {
            this.crlDistributionPointsExtension.set((CRLDistributionPointsExtensionData) extensionData);
        }
        this.ctlExtensionData.getItems().add(new ExtensionDataModel(extensionData));
    }
}
Also used : X509ExtensionData(de.carne.certmgr.certs.x509.X509ExtensionData) KeyPairAlgorithm(de.carne.certmgr.certs.security.KeyPairAlgorithm) ExtendedKeyUsageExtensionData(de.carne.certmgr.certs.x509.ExtendedKeyUsageExtensionData) KeyUsageExtensionData(de.carne.certmgr.certs.x509.KeyUsageExtensionData) ExtendedKeyUsageExtensionData(de.carne.certmgr.certs.x509.ExtendedKeyUsageExtensionData) SubjectAlternativeNameExtensionData(de.carne.certmgr.certs.x509.SubjectAlternativeNameExtensionData) BasicConstraintsExtensionData(de.carne.certmgr.certs.x509.BasicConstraintsExtensionData) CRLDistributionPointsExtensionData(de.carne.certmgr.certs.x509.CRLDistributionPointsExtensionData)

Example 7 with KeyPairAlgorithm

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

the class UserCertStoreTest method basicRequest.

private GenerateCertRequest basicRequest() {
    KeyPairAlgorithm keyPairAlgorithm = Check.notNull(KeyPairAlgorithm.getDefaultSet(null, false).getDefault());
    GenerateCertRequest request = new GenerateCertRequest(X500Names.fromString("CN=TestCert"), keyPairAlgorithm, Check.notNull(keyPairAlgorithm.getStandardKeySizes(null).getDefault()));
    Date notBefore = new Date();
    Date notAfter = new Date(notBefore.getTime() + 1000 * 60 * 24);
    request.setNotBefore(notBefore);
    request.setNotAfter(notAfter);
    return request;
}
Also used : KeyPairAlgorithm(de.carne.certmgr.certs.security.KeyPairAlgorithm) GenerateCertRequest(de.carne.certmgr.certs.x509.GenerateCertRequest) Date(java.util.Date)

Example 8 with KeyPairAlgorithm

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

the class KeyPairAlgorithmTest method testGetDefaultSet.

/**
 * Test the algorithm provisioning.
 */
@Test
public void testGetDefaultSet() {
    Set<KeyPairAlgorithm> standardAlgorithms = KeyPairAlgorithm.getDefaultSet(null, false);
    System.out.println("Standard algorithms:");
    for (KeyPairAlgorithm standardAlgorithm : standardAlgorithms) {
        System.out.println(standardAlgorithm);
    }
    Set<KeyPairAlgorithm> expertAlgorithms = KeyPairAlgorithm.getDefaultSet(null, true);
    System.out.println("Expert algorithms:");
    for (KeyPairAlgorithm expertAlgorithm : expertAlgorithms) {
        System.out.println(expertAlgorithm);
    }
    // The standard ones should always be available
    Assert.assertTrue(standardAlgorithms.size() == 3);
    // The exact number of expert ones will vary, but should always be more
    Assert.assertTrue(expertAlgorithms.size() > standardAlgorithms.size());
}
Also used : KeyPairAlgorithm(de.carne.certmgr.certs.security.KeyPairAlgorithm) Test(org.junit.Test)

Example 9 with KeyPairAlgorithm

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

the class SignatureAlgorithmTest method testGetDefaultSet.

/**
 * Test the algorithm provisioning.
 */
@Test
public void testGetDefaultSet() {
    for (KeyPairAlgorithm keyPairAlgorithm : KeyPairAlgorithm.getDefaultSet(null, true)) {
        Set<SignatureAlgorithm> expertAlgorithms = SignatureAlgorithm.getDefaultSet(keyPairAlgorithm.algorithm(), null, true);
        System.out.println(keyPairAlgorithm.algorithm() + " expert algorithms:");
        for (SignatureAlgorithm expertAlgorithm : expertAlgorithms) {
            System.out.println(keyPairAlgorithm.algorithm() + "/" + expertAlgorithm);
        }
    }
    for (KeyPairAlgorithm keyPairAlgorithm : KeyPairAlgorithm.getDefaultSet(null, false)) {
        Set<SignatureAlgorithm> standardAlgorithms = SignatureAlgorithm.getDefaultSet(keyPairAlgorithm.algorithm(), null, false);
        System.out.println(keyPairAlgorithm.algorithm() + " standard algorithms:");
        for (SignatureAlgorithm standardAlgorithm : standardAlgorithms) {
            System.out.println(keyPairAlgorithm.algorithm() + "/" + standardAlgorithm);
        }
        Assert.assertTrue(standardAlgorithms.size() > 0);
    }
}
Also used : KeyPairAlgorithm(de.carne.certmgr.certs.security.KeyPairAlgorithm) SignatureAlgorithm(de.carne.certmgr.certs.security.SignatureAlgorithm) Test(org.junit.Test)

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