use of de.carne.certmgr.certs.x509.GeneralNames in project keystore-explorer by kaikramer.
the class X509Ext method getDistributionPointNameString.
private String getDistributionPointNameString(DistributionPointName distributionPointName, String baseIndent) throws IOException {
// @formatter:off
/*
* DistributionPointName ::= CHOICE {
* fullname [0] GeneralNames,
* nameRelativeToCRLIssuer [1] RelativeDistinguishedName
* }
*
* RelativeDistinguishedName ::= SET SIZE (1 .. MAX) OF
* AttributeTypeAndValue
*
* AttributeTypeAndValue ::= ASN1Sequence { type AttributeType, value
* AttributeValue }
*/
// @formatter: on
StringBuilder sb = new StringBuilder();
sb.append(baseIndent);
sb.append(res.getString("DistributionPointName"));
sb.append(NEWLINE);
if (distributionPointName.getType() == DistributionPointName.FULL_NAME) {
sb.append(baseIndent);
sb.append(INDENT);
sb.append(res.getString("DistributionPointFullName"));
sb.append(NEWLINE);
GeneralNames generalNames = GeneralNames.getInstance(distributionPointName.getName());
for (GeneralName generalName : generalNames.getNames()) {
sb.append(baseIndent);
sb.append(INDENT);
sb.append(INDENT);
sb.append(GeneralNameUtil.toString(generalName));
sb.append(NEWLINE);
}
} else {
// DistributionPointName.TAG_NAMERELATIVETOCRLISSUER
sb.append(baseIndent);
sb.append(INDENT);
sb.append(res.getString("DistributionPointNameRelativeToCrlIssuer"));
sb.append(NEWLINE);
RDN rdn = RDN.getInstance(distributionPointName.getName());
for (AttributeTypeAndValue attributeTypeAndValue : rdn.getTypesAndValues()) {
ASN1ObjectIdentifier attributeType = attributeTypeAndValue.getType();
ASN1Encodable attributeValue = attributeTypeAndValue.getValue();
String attributeTypeStr = getAttributeTypeString(attributeType);
String attributeValueStr = getAttributeValueString(attributeType, attributeValue);
sb.append(baseIndent);
sb.append(INDENT);
sb.append(INDENT);
sb.append(MessageFormat.format("{0}={1}", attributeTypeStr, attributeValueStr));
sb.append(NEWLINE);
}
}
return sb.toString();
}
use of de.carne.certmgr.certs.x509.GeneralNames in project keystore-explorer by kaikramer.
the class X509Ext method getIssuerAlternativeNameStringValue.
private String getIssuerAlternativeNameStringValue(byte[] value) throws IOException {
// @formatter:off
/*
* IssuerAltName ::= GeneralNames
*
* GeneralNames ::= ASN1Sequence SIZE (1..MAX) OF GeneralName
*/
// @formatter:on
StringBuilder sb = new StringBuilder();
GeneralNames issuerAltName = GeneralNames.getInstance(value);
for (GeneralName generalName : issuerAltName.getNames()) {
sb.append(GeneralNameUtil.toString(generalName));
sb.append(NEWLINE);
}
return sb.toString();
}
use of de.carne.certmgr.certs.x509.GeneralNames in project keystore-explorer by kaikramer.
the class X509Ext method getDistributionPointString.
private String getDistributionPointString(DistributionPoint distributionPoint, String baseIndent) throws IOException {
// @formatter:off
/*
* DistributionPoint ::= ASN1Sequence {
* distributionPoint [0] DistributionPointName OPTIONAL,
* reasons [1] ReasonFlags OPTIONAL,
* cRLIssuer [2] GeneralNames OPTIONAL
* }
*
* GeneralNames ::= ASN1Sequence SIZE (1..MAX) OF GeneralName
*/
// @formatter:on
StringBuilder sb = new StringBuilder();
DistributionPointName distributionPointName = distributionPoint.getDistributionPoint();
ReasonFlags reasons = distributionPoint.getReasons();
GeneralNames crlIssuer = distributionPoint.getCRLIssuer();
if (distributionPointName != null) {
// Optional
sb.append(getDistributionPointNameString(distributionPointName, baseIndent));
}
if (reasons != null) {
// Optional
sb.append(baseIndent);
sb.append(res.getString("DistributionPointReasons"));
sb.append(NEWLINE);
String[] reasonFlags = getReasonFlagsStrings(reasons);
for (String reasonFlag : reasonFlags) {
sb.append(baseIndent);
sb.append(INDENT);
sb.append(reasonFlag);
sb.append(NEWLINE);
}
}
if (crlIssuer != null) {
// Optional
sb.append(baseIndent);
sb.append(res.getString("DistributionPointCrlIssuer"));
sb.append(NEWLINE);
for (GeneralName generalName : crlIssuer.getNames()) {
sb.append(baseIndent);
sb.append(INDENT);
sb.append(GeneralNameUtil.toString(generalName));
sb.append(NEWLINE);
}
}
return sb.toString();
}
use of de.carne.certmgr.certs.x509.GeneralNames in project keystore-explorer by kaikramer.
the class DAuthorityKeyIdentifier method prepopulateWithAuthorityCertDetails.
private void prepopulateWithAuthorityCertDetails(X500Name authorityCertName, BigInteger authorityCertSerialNumber) {
if (authorityCertName != null) {
try {
GeneralName generalName = new GeneralName(GeneralName.directoryName, authorityCertName);
GeneralNames generalNames = new GeneralNames(generalName);
jgnAuthorityCertIssuer.setGeneralNames(generalNames);
} catch (Exception ex) {
DError dError = new DError(this, ex);
dError.setLocationRelativeTo(this);
dError.setVisible(true);
return;
}
}
if (authorityCertSerialNumber != null) {
jtfAuthorityCertSerialNumber.setText("" + authorityCertSerialNumber.toString());
jtfAuthorityCertSerialNumber.setCaretPosition(0);
}
}
use of de.carne.certmgr.certs.x509.GeneralNames in project keystore-explorer by kaikramer.
the class DAuthorityKeyIdentifier method okPressed.
private void okPressed() {
byte[] keyIdentifier = jkiKeyIdentifier.getKeyIdentifier();
GeneralNames authorityCertIssuer = jgnAuthorityCertIssuer.getGeneralNames();
BigInteger authorityCertSerialNumber = null;
String authorityCertSerialNumberStr = jtfAuthorityCertSerialNumber.getText().trim();
if (authorityCertSerialNumberStr.length() != 0) {
try {
authorityCertSerialNumber = new BigInteger(authorityCertSerialNumberStr);
if (authorityCertSerialNumber.compareTo(BigInteger.ONE) < 0) {
JOptionPane.showMessageDialog(this, res.getString("DAuthorityKeyIdentifier.AuthorityCertSerialNumberNonZero.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, res.getString("DAuthorityKeyIdentifier.AuthorityCertSerialNumberNotInteger.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
}
// serial number are required
if ((keyIdentifier == null) && ((authorityCertIssuer.getNames().length == 0) || (authorityCertSerialNumber == null))) {
JOptionPane.showMessageDialog(this, res.getString("DAuthorityKeyIdentifier.ValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
AuthorityKeyIdentifier authorityKeyIdentifier;
if ((keyIdentifier != null) && (authorityCertSerialNumber == null)) {
// only key identifier
authorityKeyIdentifier = new AuthorityKeyIdentifier(keyIdentifier);
} else if (keyIdentifier == null) {
// only issuer / serial
authorityKeyIdentifier = new AuthorityKeyIdentifier(authorityCertIssuer, authorityCertSerialNumber);
} else {
// both
authorityKeyIdentifier = new AuthorityKeyIdentifier(keyIdentifier, authorityCertIssuer, authorityCertSerialNumber);
}
try {
value = authorityKeyIdentifier.getEncoded(ASN1Encoding.DER);
} catch (IOException ex) {
DError dError = new DError(this, ex);
dError.setLocationRelativeTo(this);
dError.setVisible(true);
return;
}
closeDialog();
}
Aggregations