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);
}
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++;
}
}
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());
}
}
}
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;
}
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);
}
Aggregations