Search in sources :

Example 21 with ASN1Integer

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();
}
Also used : BigInteger(java.math.BigInteger) BasicConstraints(org.bouncycastle.asn1.x509.BasicConstraints)

Example 22 with ASN1Integer

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();
}
Also used : ASN1Integer(org.bouncycastle.asn1.ASN1Integer) DERBitString(org.bouncycastle.asn1.DERBitString) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERBMPString(org.bouncycastle.asn1.DERBMPString) DERGeneralString(org.bouncycastle.asn1.DERGeneralString) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERIA5String(org.bouncycastle.asn1.DERIA5String) IssuingDistributionPoint(org.bouncycastle.asn1.x509.IssuingDistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint)

Example 23 with ASN1Integer

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();
}
Also used : IssuingDistributionPoint(org.bouncycastle.asn1.x509.IssuingDistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint)

Example 24 with ASN1Integer

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);
    }
}
Also used : ASN1Integer(org.bouncycastle.asn1.ASN1Integer)

Example 25 with ASN1Integer

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();
}
Also used : UserNotice(org.bouncycastle.asn1.x509.UserNotice) NoticeReference(org.bouncycastle.asn1.x509.NoticeReference) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) Vector(java.util.Vector)

Aggregations

ASN1Integer (org.bouncycastle.asn1.ASN1Integer)121 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)54 BigInteger (java.math.BigInteger)49 DERSequence (org.bouncycastle.asn1.DERSequence)48 IOException (java.io.IOException)43 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)40 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)29 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)21 DEROctetString (org.bouncycastle.asn1.DEROctetString)21 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)20 ArrayList (java.util.ArrayList)18 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)17 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)15 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)15 X509Certificate (java.security.cert.X509Certificate)14 Date (java.util.Date)12 DLSequence (org.bouncycastle.asn1.DLSequence)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 KeyPair (java.security.KeyPair)11 HashMap (java.util.HashMap)11