Search in sources :

Example 1 with UserNotice

use of org.bouncycastle.asn1.x509.UserNotice in project keystore-explorer by kaikramer.

the class X509Ext method getCertificatePoliciesStringValue.

private String getCertificatePoliciesStringValue(byte[] value) throws IOException {
    // @formatter:off
    /*
		 * CertificatePolicies ::= ASN1Sequence SIZE (1..MAX) OF PolicyInformation
		 *
		 * PolicyInformation ::= ASN1Sequence
		 * {
		 *      policyIdentifier CertPolicyId,
		 *      policyQualifiers ASN1Sequence SIZE (1..MAX) OF PolicyQualifierInfo OPTIONAL
		 * }
		 *
		 * CertPolicyId ::= OBJECT IDENTIFIER
		 *
		 * PolicyQualifierInfo ::= ASN1Sequence
		 * {
		 *      policyQualifierId PolicyQualifierId,
		 *      qualifier ANY DEFINED BY policyQualifierId
		 * }
		 *
		 * PolicyQualifierId ::= OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice )
		 *
		 * Qualifier ::= CHOICE
		 * {
		 *      cPSuri CPSuri,
		 *      userNotice UserNotice
		 * }
		 *
		 * CPSuri ::= DERIA5String
		 *
		 * UserNotice ::= ASN1Sequence
		 * {
		 *      noticeRef NoticeReference OPTIONAL,
		 *      explicitText DisplayText OPTIONAL
		 * }
		 *
		 * NoticeReference ::= ASN1Sequence
		 * {
		 *      organization DisplayText,
		 *      noticeNumbers ASN1Sequence OF ASN1Integer
		 * }
		 *
		 * DisplayText ::= CHOICE
		 * {
		 *      ia5String DERIA5String (SIZE (1..200)),
		 *      visibleString VisibleString (SIZE (1..200)),
		 *      bmpString BMPString (SIZE (1..200)),
		 *      utf8String UTF8String (SIZE (1..200))
		 * }
		 */
    // @formatter:on
    StringBuilder sb = new StringBuilder();
    CertificatePolicies certificatePolicies = CertificatePolicies.getInstance(value);
    int certPolicy = 0;
    for (PolicyInformation policyInformation : certificatePolicies.getPolicyInformation()) {
        certPolicy++;
        sb.append(MessageFormat.format(res.getString("CertificatePolicy"), certPolicy));
        sb.append(NEWLINE);
        ASN1ObjectIdentifier policyIdentifier = policyInformation.getPolicyIdentifier();
        String policyIdentifierStr = ObjectIdUtil.toString(policyIdentifier);
        sb.append(INDENT);
        sb.append(MessageFormat.format(res.getString("PolicyIdentifier"), policyIdentifierStr));
        sb.append(NEWLINE);
        ASN1Sequence policyQualifiers = policyInformation.getPolicyQualifiers();
        if (policyQualifiers != null) {
            // Optional
            int policyQual = 0;
            for (ASN1Encodable policyQualifier : policyQualifiers.toArray()) {
                ASN1Sequence policyQualifierInfo = (ASN1Sequence) policyQualifier;
                sb.append(INDENT.toString(1));
                sb.append(MessageFormat.format(res.getString("PolicyQualifierInformation"), certPolicy, ++policyQual));
                sb.append(NEWLINE);
                ASN1ObjectIdentifier policyQualifierId = (ASN1ObjectIdentifier) policyQualifierInfo.getObjectAt(0);
                CertificatePolicyQualifierType certificatePolicyQualifierType = CertificatePolicyQualifierType.resolveOid(policyQualifierId.getId());
                if (certificatePolicyQualifierType != null) {
                    sb.append(INDENT.toString(2));
                    sb.append(certificatePolicyQualifierType.friendly());
                    sb.append(NEWLINE);
                    if (certificatePolicyQualifierType == PKIX_CPS_POINTER_QUALIFIER) {
                        DERIA5String cpsPointer = (DERIA5String) policyQualifierInfo.getObjectAt(1);
                        sb.append(INDENT.toString(2));
                        sb.append(MessageFormat.format(res.getString("CpsPointer"), "<a href=\"" + cpsPointer + "\">" + cpsPointer + "</a>"));
                        sb.append(NEWLINE);
                    } else if (certificatePolicyQualifierType == PKIX_USER_NOTICE_QUALIFIER) {
                        ASN1Encodable userNoticeObj = policyQualifierInfo.getObjectAt(1);
                        UserNotice userNotice = UserNotice.getInstance(userNoticeObj);
                        sb.append(INDENT.toString(2));
                        sb.append(res.getString("UserNotice"));
                        sb.append(NEWLINE);
                        NoticeReference noticeReference = userNotice.getNoticeRef();
                        DisplayText explicitText = userNotice.getExplicitText();
                        if (noticeReference != null) {
                            // Optional
                            sb.append(INDENT.toString(3));
                            sb.append(res.getString("NoticeReference"));
                            sb.append(NEWLINE);
                            DisplayText organization = noticeReference.getOrganization();
                            String organizationString = organization.getString();
                            sb.append(INDENT.toString(4));
                            sb.append(MessageFormat.format(res.getString("Organization"), organizationString));
                            sb.append(NEWLINE);
                            ASN1Integer[] noticeNumbers = noticeReference.getNoticeNumbers();
                            StringBuilder sbNoticeNumbers = new StringBuilder();
                            for (ASN1Integer noticeNumber : noticeNumbers) {
                                sbNoticeNumbers.append(noticeNumber.getValue().intValue());
                                sbNoticeNumbers.append(", ");
                            }
                            sbNoticeNumbers.setLength(sbNoticeNumbers.length() - 2);
                            sb.append(INDENT.toString(4));
                            sb.append(MessageFormat.format(res.getString("NoticeNumbers"), sbNoticeNumbers.toString()));
                            sb.append(NEWLINE);
                        }
                        if (explicitText != null) {
                            // Optional
                            String explicitTextString = explicitText.getString();
                            sb.append(INDENT.toString(3));
                            sb.append(MessageFormat.format(res.getString("ExplicitText"), explicitTextString));
                            sb.append(NEWLINE);
                        }
                    }
                }
            }
        }
    }
    return sb.toString();
}
Also used : PolicyInformation(org.bouncycastle.asn1.x509.PolicyInformation) UserNotice(org.bouncycastle.asn1.x509.UserNotice) 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) NoticeReference(org.bouncycastle.asn1.x509.NoticeReference) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) IssuingDistributionPoint(org.bouncycastle.asn1.x509.IssuingDistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DERIA5String(org.bouncycastle.asn1.DERIA5String) CertificatePolicies(org.bouncycastle.asn1.x509.CertificatePolicies) DisplayText(org.bouncycastle.asn1.x509.DisplayText) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 2 with UserNotice

use of org.bouncycastle.asn1.x509.UserNotice in project keystore-explorer by kaikramer.

the class PolicyInformationUtil method toString.

/**
 * Get string representation of policy qualifier info.
 *
 * @param policyQualifierInfo
 *            Policy qualifier info
 * @return String representation of policy qualifier info
 * @throws IOException
 *             If policy qualifier info is invalid
 */
public static String toString(PolicyQualifierInfo policyQualifierInfo) throws IOException {
    StringBuffer sbPolicyQualifier = new StringBuffer();
    ASN1ObjectIdentifier policyQualifierId = policyQualifierInfo.getPolicyQualifierId();
    CertificatePolicyQualifierType certificatePolicyQualifierType = CertificatePolicyQualifierType.resolveOid(policyQualifierId.getId());
    if (certificatePolicyQualifierType == PKIX_CPS_POINTER_QUALIFIER) {
        DERIA5String cpsPointer = ((DERIA5String) policyQualifierInfo.getQualifier());
        sbPolicyQualifier.append(MessageFormat.format(res.getString("PolicyInformationUtil.CpsPointer"), cpsPointer));
    } else if (certificatePolicyQualifierType == PKIX_USER_NOTICE_QUALIFIER) {
        ASN1Encodable userNoticeObj = policyQualifierInfo.getQualifier();
        UserNotice userNotice = UserNotice.getInstance(userNoticeObj);
        sbPolicyQualifier.append(MessageFormat.format(res.getString("PolicyInformationUtil.UserNotice"), toString(userNotice)));
    }
    return sbPolicyQualifier.toString();
}
Also used : DERIA5String(org.bouncycastle.asn1.DERIA5String) UserNotice(org.bouncycastle.asn1.x509.UserNotice) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 3 with UserNotice

use of org.bouncycastle.asn1.x509.UserNotice in project keystore-explorer by kaikramer.

the class DPolicyQualifierInfoChooser method populate.

private void populate(PolicyQualifierInfo policyQualifierInfo) throws IOException {
    if (policyQualifierInfo == null) {
        jrbCps.setSelected(true);
    } else {
        ASN1ObjectIdentifier policyQualifierId = policyQualifierInfo.getPolicyQualifierId();
        if (policyQualifierId.equals(new ASN1ObjectIdentifier(PKIX_CPS_POINTER_QUALIFIER.oid()))) {
            jrbCps.setSelected(true);
            jtfCps.setText(((DERIA5String) policyQualifierInfo.getQualifier()).getString());
            jtfCps.setCaretPosition(0);
        } else if (policyQualifierId.equals(new ASN1ObjectIdentifier(PKIX_USER_NOTICE_QUALIFIER.oid()))) {
            jrbUserNotice.setSelected(true);
            ASN1Encodable userNoticeObj = policyQualifierInfo.getQualifier();
            UserNotice userNotice = UserNotice.getInstance(userNoticeObj);
            junUserNotice.setUserNotice(userNotice);
        } else {
            jrbCps.setSelected(true);
        }
    }
}
Also used : UserNotice(org.bouncycastle.asn1.x509.UserNotice) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 4 with UserNotice

use of org.bouncycastle.asn1.x509.UserNotice 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)

Example 5 with UserNotice

use of org.bouncycastle.asn1.x509.UserNotice in project keystore-explorer by kaikramer.

the class JUserNotice method editUserNotice.

private void editUserNotice() {
    Container container = getTopLevelAncestor();
    DUserNoticeChooser dUserNoticeChooser = null;
    if (container instanceof JDialog) {
        dUserNoticeChooser = new DUserNoticeChooser((JDialog) container, title, userNotice);
        dUserNoticeChooser.setLocationRelativeTo(container);
        dUserNoticeChooser.setVisible(true);
    } else if (container instanceof JFrame) {
        dUserNoticeChooser = new DUserNoticeChooser((JFrame) container, title, userNotice);
        dUserNoticeChooser.setLocationRelativeTo(container);
        dUserNoticeChooser.setVisible(true);
    }
    UserNotice newUserNotice = dUserNoticeChooser.getUserNotice();
    if (newUserNotice == null) {
        return;
    }
    setUserNotice(newUserNotice);
}
Also used : Container(java.awt.Container) JFrame(javax.swing.JFrame) UserNotice(org.bouncycastle.asn1.x509.UserNotice) JDialog(javax.swing.JDialog)

Aggregations

UserNotice (org.bouncycastle.asn1.x509.UserNotice)8 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)6 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)4 DERIA5String (org.bouncycastle.asn1.DERIA5String)4 NoticeReference (org.bouncycastle.asn1.x509.NoticeReference)4 PolicyQualifierInfo (org.bouncycastle.asn1.x509.PolicyQualifierInfo)4 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)3 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)3 DisplayText (org.bouncycastle.asn1.x509.DisplayText)3 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)2 DERBMPString (org.bouncycastle.asn1.DERBMPString)2 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)2 DirectoryString (org.bouncycastle.asn1.x500.DirectoryString)2 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)2 DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)2 PolicyInformation (org.bouncycastle.asn1.x509.PolicyInformation)2 Container (java.awt.Container)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1