use of de.carne.certmgr.certs.x509.X509ExtensionData 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.x509.X509ExtensionData in project certmgr by hdecarne.
the class CertOptionsController method onCmdDeleteExtension.
@SuppressWarnings("unused")
@FXML
void onCmdDeleteExtension(ActionEvent evt) {
ExtensionDataModel extensionDataItem = this.ctlExtensionData.getSelectionModel().getSelectedItem();
if (extensionDataItem != null) {
X509ExtensionData extensionData = extensionDataItem.getExtensionData();
if (extensionData instanceof BasicConstraintsExtensionData) {
this.basicConstraintsExtension.set(null);
} else if (extensionData instanceof KeyUsageExtensionData) {
this.keyUsageExtension.set(null);
} else if (extensionData instanceof ExtendedKeyUsageExtensionData) {
this.extendedKeyUsageExtension.set(null);
} else if (extensionData instanceof SubjectAlternativeNameExtensionData) {
this.subjectAlternativeExtension.set(null);
} else if (extensionData instanceof CRLDistributionPointsExtensionData) {
this.crlDistributionPointsExtension.set(null);
}
this.ctlExtensionData.getItems().remove(extensionDataItem);
}
}
use of de.carne.certmgr.certs.x509.X509ExtensionData 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));
}
}
use of de.carne.certmgr.certs.x509.X509ExtensionData in project certmgr by hdecarne.
the class CertOptionsTemplates method wrap.
public static Template wrap(UserCertStoreEntry storeEntry) {
String dnInput = X500Names.toString(storeEntry.dn());
String aliasInput = dnInput;
try {
LdapName dn = new LdapName(aliasInput);
for (Rdn rdn : dn.getRdns()) {
if (DN_ALIAS_KEY.equals(rdn.getType())) {
aliasInput = String.valueOf(rdn.getValue());
break;
}
}
} catch (InvalidNameException e) {
Exceptions.ignore(e);
}
CertOptionsPreset preset = new CertOptionsPreset(aliasInput, dnInput);
try {
if (storeEntry.hasCRT()) {
X509Certificate crt = storeEntry.getCRT();
PublicKey publicKey = crt.getPublicKey();
preset.setKeyAlg(KeyHelper.getKeyAlg(publicKey));
preset.setKeySize(KeyHelper.getKeySize(publicKey));
Set<String> criticalExtensionOIDs = crt.getCriticalExtensionOIDs();
if (criticalExtensionOIDs != null) {
for (String criticalExtensionOID : criticalExtensionOIDs) {
if (!INVALID_PRESET_EXTENSIONS.contains(criticalExtensionOID)) {
X509ExtensionData criticalExtension = X509ExtensionData.decode(criticalExtensionOID, true, crt.getExtensionValue(criticalExtensionOID));
preset.addExtension(criticalExtension);
}
}
}
Set<String> nonCriticalExtensionOIDs = crt.getNonCriticalExtensionOIDs();
if (nonCriticalExtensionOIDs != null) {
for (String nonCriticalExtensionOID : nonCriticalExtensionOIDs) {
if (!INVALID_PRESET_EXTENSIONS.contains(nonCriticalExtensionOID)) {
X509ExtensionData nonCriticalExtension = X509ExtensionData.decode(nonCriticalExtensionOID, false, crt.getExtensionValue(nonCriticalExtensionOID));
preset.addExtension(nonCriticalExtension);
}
}
}
}
} catch (IOException e) {
Exceptions.warn(e);
}
return new Template(preset.aliasInput(), preset);
}
use of de.carne.certmgr.certs.x509.X509ExtensionData in project certmgr by hdecarne.
the class UserCertStoreTest method accessExtensionValues.
private void accessExtensionValues(X509Extension extension) throws IOException {
Set<String> criticalExtensionOIDs = extension.getCriticalExtensionOIDs();
if (criticalExtensionOIDs != null) {
for (String criticalExtensionOID : extension.getCriticalExtensionOIDs()) {
X509ExtensionData extensionData = X509ExtensionData.decode(criticalExtensionOID, true, extension.getExtensionValue(criticalExtensionOID));
extensionData.toValueString();
}
}
Set<String> nonCriticalExtensionOIDs = extension.getNonCriticalExtensionOIDs();
if (nonCriticalExtensionOIDs != null) {
for (String nonCriticalExtensionOID : nonCriticalExtensionOIDs) {
X509ExtensionData extensionData = X509ExtensionData.decode(nonCriticalExtensionOID, true, extension.getExtensionValue(nonCriticalExtensionOID));
extensionData.toValueString();
}
}
}
Aggregations