Search in sources :

Example 1 with DisplayText

use of org.mozilla.jss.netscape.security.x509.DisplayText in project keystore-explorer by kaikramer.

the class X509Ext method getCertificatePoliciesStringValue.

private static 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) DERGeneralString(org.bouncycastle.asn1.DERGeneralString) ASN1IA5String(org.bouncycastle.asn1.ASN1IA5String) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) ASN1BitString(org.bouncycastle.asn1.ASN1BitString) DEROctetString(org.bouncycastle.asn1.DEROctetString) ASN1BMPString(org.bouncycastle.asn1.ASN1BMPString) DERIA5String(org.bouncycastle.asn1.DERIA5String) ASN1PrintableString(org.bouncycastle.asn1.ASN1PrintableString) 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 DisplayText

use of org.mozilla.jss.netscape.security.x509.DisplayText in project keystore-explorer by kaikramer.

the class PolicyInformationUtil method toString.

/**
 * Get string representation of user notice.
 *
 * @param userNotice User notice
 * @return String representation of user notice
 */
public static String toString(UserNotice userNotice) {
    StringBuilder sbUserNotice = new StringBuilder();
    NoticeReference noticeReference = userNotice.getNoticeRef();
    if (noticeReference != null) {
        DisplayText organization = noticeReference.getOrganization();
        if (organization != null) {
            sbUserNotice.append(MessageFormat.format(res.getString("PolicyInformationUtil.Organization"), organization.getString()));
            if ((noticeReference.getNoticeNumbers() != null) || (userNotice.getExplicitText() != null)) {
                sbUserNotice.append(", ");
            }
        }
        ASN1Integer[] noticeNumbers = noticeReference.getNoticeNumbers();
        StringBuilder sbNoticeNumbers = new StringBuilder();
        if (noticeNumbers != null) {
            for (int i = 0; i < noticeNumbers.length; i++) {
                ASN1Integer noticeNumber = noticeNumbers[i];
                sbNoticeNumbers.append(noticeNumber.getValue().intValue());
                if ((i + 1) < noticeNumbers.length) {
                    sbNoticeNumbers.append(" ");
                }
            }
            sbUserNotice.append(MessageFormat.format(res.getString("PolicyInformationUtil.NoticeNumbers"), sbNoticeNumbers.toString()));
            if (userNotice.getExplicitText() != null) {
                sbUserNotice.append(", ");
            }
        }
    }
    DisplayText explicitText = userNotice.getExplicitText();
    if (explicitText != null) {
        sbUserNotice.append(MessageFormat.format(res.getString("PolicyInformationUtil.ExplicitText"), explicitText.getString()));
    }
    return sbUserNotice.toString();
}
Also used : DisplayText(org.bouncycastle.asn1.x509.DisplayText) NoticeReference(org.bouncycastle.asn1.x509.NoticeReference) ASN1Integer(org.bouncycastle.asn1.ASN1Integer)

Example 3 with DisplayText

use of org.mozilla.jss.netscape.security.x509.DisplayText in project keystore-explorer by kaikramer.

the class DUserNoticeChooser method populate.

private void populate(UserNotice userNotice) {
    if (userNotice != null) {
        NoticeReference noticeReference = userNotice.getNoticeRef();
        if (noticeReference != null) {
            DisplayText organization = noticeReference.getOrganization();
            if (organization != null) {
                jtfOrganization.setText(organization.getString());
                jtfOrganization.setCaretPosition(0);
            }
            populateNoticeNumbers(noticeReference);
        }
        DisplayText explicitText = userNotice.getExplicitText();
        if (explicitText != null) {
            jtfExplicitText.setText(explicitText.getString());
            jtfExplicitText.setCaretPosition(0);
        }
    }
}
Also used : DisplayText(org.bouncycastle.asn1.x509.DisplayText) NoticeReference(org.bouncycastle.asn1.x509.NoticeReference)

Example 4 with DisplayText

use of org.mozilla.jss.netscape.security.x509.DisplayText in project jss by dogtagpki.

the class ExtPrettyPrint method getCertificatePoliciesExtension.

private String getCertificatePoliciesExtension() {
    StringBuffer sb = new StringBuffer();
    try {
        sb.append(pp.indent(mIndentSize) + mResource.getString(PrettyPrintResources.TOKEN_IDENTIFIER));
        sb.append(mResource.getString(PrettyPrintResources.TOKEN_CERT_POLICIES) + "- " + mExt.getExtensionId().toString() + "\n");
        sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_CRITICAL));
        if (mExt.isCritical()) {
            sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n");
        } else {
            sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n");
        }
        sb.append(pp.indent(mIndentSize + 4) + mResource.getString(PrettyPrintResources.TOKEN_CERT_POLICIES) + "\n");
        CertificatePoliciesExtension cp = (CertificatePoliciesExtension) mExt;
        @SuppressWarnings("unchecked") Vector<CertificatePolicyInfo> cpv = (Vector<CertificatePolicyInfo>) cp.get("infos");
        Enumeration<CertificatePolicyInfo> e = cpv.elements();
        if (e != null) {
            while (e.hasMoreElements()) {
                CertificatePolicyInfo cpi = e.nextElement();
                sb.append(pp.indent(mIndentSize + 8) + "Policy Identifier: " + cpi.getPolicyIdentifier().getIdentifier().toString() + "\n");
                PolicyQualifiers cpq = cpi.getPolicyQualifiers();
                if (cpq != null) {
                    for (int i = 0; i < cpq.size(); i++) {
                        PolicyQualifierInfo pq = cpq.getInfoAt(i);
                        Qualifier q = pq.getQualifier();
                        if (q instanceof CPSuri) {
                            sb.append(pp.indent(mIndentSize + 12) + "Policy Qualifier Identifier: CPS Pointer Qualifier - " + pq.getId() + "\n");
                            sb.append(pp.indent(mIndentSize + 12) + "Policy Qualifier Data: " + ((CPSuri) q).getURI() + "\n");
                        } else if (q instanceof UserNotice) {
                            sb.append(pp.indent(mIndentSize + 12) + "Policy Qualifier Identifier: CPS User Notice Qualifier - " + pq.getId() + "\n");
                            NoticeReference nref = ((UserNotice) q).getNoticeReference();
                            DisplayText dt = ((UserNotice) q).getDisplayText();
                            sb.append(pp.indent(mIndentSize + 12) + "Policy Qualifier Data: \n");
                            if (nref != null) {
                                sb.append(pp.indent(mIndentSize + 16) + "Organization: " + nref.getOrganization().toString() + "\n");
                                sb.append(pp.indent(mIndentSize + 16) + "Notice Numbers: ");
                                int[] nums = nref.getNumbers();
                                for (int k = 0; k < nums.length; k++) {
                                    if (k != 0) {
                                        sb.append(",");
                                        sb.append(nums[k]);
                                    } else {
                                        sb.append(nums[k]);
                                    }
                                }
                                sb.append("\n");
                            }
                            if (dt != null) {
                                sb.append(pp.indent(mIndentSize + 16) + "Explicit Text: " + dt.toString() + "\n");
                            }
                        }
                    }
                }
            }
        }
        return sb.toString();
    } catch (IOException e) {
        return sb.toString();
    }
}
Also used : CPSuri(org.mozilla.jss.netscape.security.x509.CPSuri) CertificatePolicyInfo(org.mozilla.jss.netscape.security.x509.CertificatePolicyInfo) PolicyQualifierInfo(org.mozilla.jss.netscape.security.x509.PolicyQualifierInfo) UserNotice(org.mozilla.jss.netscape.security.x509.UserNotice) NoticeReference(org.mozilla.jss.netscape.security.x509.NoticeReference) IOException(java.io.IOException) CRLDistributionPoint(org.mozilla.jss.netscape.security.x509.CRLDistributionPoint) IssuingDistributionPoint(org.mozilla.jss.netscape.security.x509.IssuingDistributionPoint) DisplayText(org.mozilla.jss.netscape.security.x509.DisplayText) Qualifier(org.mozilla.jss.netscape.security.x509.Qualifier) CertificatePoliciesExtension(org.mozilla.jss.netscape.security.x509.CertificatePoliciesExtension) Vector(java.util.Vector) PolicyQualifiers(org.mozilla.jss.netscape.security.x509.PolicyQualifiers)

Aggregations

DisplayText (org.bouncycastle.asn1.x509.DisplayText)3 NoticeReference (org.bouncycastle.asn1.x509.NoticeReference)3 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)2 IOException (java.io.IOException)1 Vector (java.util.Vector)1 ASN1BMPString (org.bouncycastle.asn1.ASN1BMPString)1 ASN1BitString (org.bouncycastle.asn1.ASN1BitString)1 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)1 ASN1IA5String (org.bouncycastle.asn1.ASN1IA5String)1 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)1 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)1 ASN1PrintableString (org.bouncycastle.asn1.ASN1PrintableString)1 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)1 DERBitString (org.bouncycastle.asn1.DERBitString)1 DERGeneralString (org.bouncycastle.asn1.DERGeneralString)1 DERIA5String (org.bouncycastle.asn1.DERIA5String)1 DEROctetString (org.bouncycastle.asn1.DEROctetString)1 DirectoryString (org.bouncycastle.asn1.x500.DirectoryString)1 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)1 CertificatePolicies (org.bouncycastle.asn1.x509.CertificatePolicies)1