use of org.bouncycastle.asn1.ASN1Integer in project keystore-explorer by kaikramer.
the class X509Ext method getBasicConstraintsStringValue.
private String getBasicConstraintsStringValue(byte[] value) throws IOException {
// @formatter:off
/*
* BasicConstraints ::= ASN1Sequence { cA ASN1Boolean DEFAULT FALSE,
* pathLenConstraint ASN1Integer (0..MAX) OPTIONAL }
*/
// @formatter:on
/*
* Getting the DEFAULT returns a false ASN1Boolean when no value present
* which saves the bother of a null check
*/
StringBuilder sb = new StringBuilder();
BasicConstraints basicConstraints = BasicConstraints.getInstance(value);
boolean ca = basicConstraints.isCA();
BigInteger pathLenConstraint = basicConstraints.getPathLenConstraint();
if (ca) {
sb.append(res.getString("SubjectIsCa"));
sb.append(NEWLINE);
} else {
sb.append(res.getString("SubjectIsNotCa"));
sb.append(NEWLINE);
}
if (pathLenConstraint != null) {
sb.append(MessageFormat.format(res.getString("PathLengthConstraint"), pathLenConstraint.intValue()));
sb.append(NEWLINE);
} else {
sb.append(res.getString("NoPathLengthConstraint"));
sb.append(NEWLINE);
}
return sb.toString();
}
use of org.bouncycastle.asn1.ASN1Integer in project keystore-explorer by kaikramer.
the class X509Ext method getMsCaVersionStringValue.
private String getMsCaVersionStringValue(byte[] octets) {
/*
"The extension data is a DWORD value (encoded as X509_INTEGER in the extension);
the low 16 bits are the certificate index, and the high 16 bits are the key index."
*/
ASN1Integer asn1Integer = ASN1Integer.getInstance(octets);
int version = asn1Integer.getValue().intValue();
String certIndex = String.valueOf(version & 0xffff);
String keyIndex = String.valueOf(version >> 16);
StringBuilder sb = new StringBuilder();
sb.append(MessageFormat.format(res.getString("MSCaVersion.CertIndex"), certIndex));
sb.append(NEWLINE);
sb.append(MessageFormat.format(res.getString("MSCaVersion.KeyIndex"), keyIndex));
sb.append(NEWLINE);
return sb.toString();
}
use of org.bouncycastle.asn1.ASN1Integer in project keystore-explorer by kaikramer.
the class X509Ext method getPolicyConstraintsStringValue.
private String getPolicyConstraintsStringValue(byte[] value) throws IOException {
// @formatter:off
/*
* PolicyConstraints ::= ASN1Sequence { requireExplicitPolicy [0]
* SkipCerts OPTIONAL, inhibitPolicyMapping [1] SkipCerts OPTIONAL }
*
* SkipCerts ::= ASN1Integer (0..MAX)
*/
// @formatter:on
StringBuilder sb = new StringBuilder();
PolicyConstraints policyConstraints = PolicyConstraints.getInstance(value);
int requireExplicitPolicy = policyConstraints.getRequireExplicitPolicy();
int inhibitPolicyMapping = policyConstraints.getInhibitPolicyMapping();
if (requireExplicitPolicy != -1) {
// Optional
sb.append(MessageFormat.format(res.getString("RequireExplicitPolicy"), requireExplicitPolicy));
sb.append(NEWLINE);
}
if (inhibitPolicyMapping != -1) {
// Optional
sb.append(MessageFormat.format(res.getString("InhibitPolicyMapping"), inhibitPolicyMapping));
sb.append(NEWLINE);
}
return sb.toString();
}
use of org.bouncycastle.asn1.ASN1Integer in project keystore-explorer by kaikramer.
the class DUserNoticeChooser method populateNoticeNumbers.
private void populateNoticeNumbers(NoticeReference noticeReference) {
ASN1Integer[] noticeNumbers = noticeReference.getNoticeNumbers();
if (noticeNumbers != null) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < noticeNumbers.length; i++) {
ASN1Integer noticeNumber = noticeNumbers[i];
sb.append(noticeNumber.getValue().intValue());
if ((i + 1) < noticeNumbers.length) {
sb.append(" ");
}
}
jtfNoticeNumbers.setText(sb.toString());
jtfNoticeNumbers.setCaretPosition(0);
}
}
use of org.bouncycastle.asn1.ASN1Integer in project keystore-explorer by kaikramer.
the class DUserNoticeChooser method okPressed.
private void okPressed() {
String organizationString = jtfOrganization.getText().trim();
int[] noticeNumberInts = extractNoticeNumbers();
String explicitTextString = jtfExplicitText.getText().trim();
if (noticeNumberInts == null) {
JOptionPane.showMessageDialog(this, res.getString("DUserNoticeChooser.InvalidNoticeNumbers.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
if (((organizationString.length() > 0) && (noticeNumberInts.length == 0)) || ((organizationString.length() == 0) && (noticeNumberInts.length > 0))) {
JOptionPane.showMessageDialog(this, res.getString("DUserNoticeChooser.OrganizationOrNoticeNumbersValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
if ((organizationString.length() == 0) && (noticeNumberInts.length == 0) && (explicitTextString.length() == 0)) {
JOptionPane.showMessageDialog(this, res.getString("DUserNoticeChooser.NoticeRefOrExplicitTextValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
NoticeReference noticeReference = null;
if (organizationString.length() > 0) {
// If organization is present then so is al of notice reference
Vector<ASN1Integer> noticeNumbers = new Vector<ASN1Integer>();
for (int noticeNumber : noticeNumberInts) {
noticeNumbers.add(new ASN1Integer(noticeNumber));
}
noticeReference = new NoticeReference(organizationString, noticeNumbers);
}
userNotice = new UserNotice(noticeReference, explicitTextString);
closeDialog();
}
Aggregations