Search in sources :

Example 6 with PolicyInformation

use of org.openecard.bouncycastle.asn1.x509.PolicyInformation 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 7 with PolicyInformation

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

the class DPolicyInformationChooser method okPressed.

private void okPressed() {
    ASN1ObjectIdentifier policyIdentifer = joiPolicyIdentifier.getObjectId();
    if (policyIdentifer == null) {
        JOptionPane.showMessageDialog(this, res.getString("DPolicyInformationChooser.PolicyIdentifierValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    List<PolicyQualifierInfo> policyQualifierInfo = jpqPolicyQualifiers.getPolicyQualifierInfo();
    if (policyQualifierInfo.size() > 0) {
        ASN1EncodableVector policyQualifiersVec = new ASN1EncodableVector();
        for (PolicyQualifierInfo policyQualInfo : policyQualifierInfo) {
            try {
                policyQualifiersVec.add(policyQualInfo);
            } catch (Exception ex) {
                DError dError = new DError(this, ex);
                dError.setLocationRelativeTo(this);
                dError.setVisible(true);
                return;
            }
        }
        DERSequence policyQualifiersSeq = new DERSequence(policyQualifiersVec);
        policyInformation = new PolicyInformation(policyIdentifer, policyQualifiersSeq);
    } else {
        policyInformation = new PolicyInformation(policyIdentifer);
    }
    closeDialog();
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) PolicyInformation(org.bouncycastle.asn1.x509.PolicyInformation) PolicyQualifierInfo(org.bouncycastle.asn1.x509.PolicyQualifierInfo) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) IOException(java.io.IOException) DError(org.kse.gui.error.DError)

Example 8 with PolicyInformation

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

the class JPolicyInformation method removeSelectedPolicyInformation.

private void removeSelectedPolicyInformation() {
    int selectedRow = jtPolicyInformation.getSelectedRow();
    if (selectedRow != -1) {
        PolicyInformation policyInfo = (PolicyInformation) jtPolicyInformation.getValueAt(selectedRow, 0);
        policyInformation.remove(policyInfo);
        reloadPolicyInformationTable();
        selectFirstPolicyInformationInTable();
        updateButtonControls();
    }
}
Also used : PolicyInformation(org.bouncycastle.asn1.x509.PolicyInformation) Point(java.awt.Point)

Example 9 with PolicyInformation

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

the class PolicyInformationTableModel method load.

/**
 * Load the PolicyInformationTableModel with policy information.
 *
 * @param policyInformation
 *            The policy information
 */
public void load(List<PolicyInformation> policyInformation) {
    PolicyInformation[] policyInformationArray = policyInformation.toArray(new PolicyInformation[policyInformation.size()]);
    Arrays.sort(policyInformationArray, new PolicyInformationComparator());
    data = new Object[policyInformation.size()][1];
    int i = 0;
    for (PolicyInformation policyInfo : policyInformationArray) {
        data[i][0] = policyInfo;
        i++;
    }
    fireTableDataChanged();
}
Also used : PolicyInformation(org.bouncycastle.asn1.x509.PolicyInformation)

Example 10 with PolicyInformation

use of org.openecard.bouncycastle.asn1.x509.PolicyInformation in project xipki by xipki.

the class XmlX509CertprofileUtil method createCertificatePolicies.

public static org.bouncycastle.asn1.x509.CertificatePolicies createCertificatePolicies(List<CertificatePolicyInformation> policyInfos) throws CertprofileException {
    ParamUtil.requireNonEmpty("policyInfos", policyInfos);
    int size = policyInfos.size();
    PolicyInformation[] infos = new PolicyInformation[size];
    int idx = 0;
    for (CertificatePolicyInformation policyInfo : policyInfos) {
        String policyId = policyInfo.getCertPolicyId();
        List<CertificatePolicyQualifier> qualifiers = policyInfo.getQualifiers();
        ASN1Sequence policyQualifiers = null;
        if (CollectionUtil.isNonEmpty(qualifiers)) {
            policyQualifiers = createPolicyQualifiers(qualifiers);
        }
        ASN1ObjectIdentifier policyOid = new ASN1ObjectIdentifier(policyId);
        infos[idx++] = (policyQualifiers == null) ? new PolicyInformation(policyOid) : new PolicyInformation(policyOid, policyQualifiers);
    }
    return new org.bouncycastle.asn1.x509.CertificatePolicies(infos);
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) PolicyInformation(org.bouncycastle.asn1.x509.PolicyInformation) CertificatePolicyInformation(org.xipki.ca.api.profile.x509.CertificatePolicyInformation) CertificatePolicyInformation(org.xipki.ca.api.profile.x509.CertificatePolicyInformation) CertificatePolicies(org.xipki.ca.certprofile.x509.jaxb.CertificatePolicies) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) CertificatePolicyQualifier(org.xipki.ca.api.profile.x509.CertificatePolicyQualifier) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Aggregations

PolicyInformation (org.bouncycastle.asn1.x509.PolicyInformation)20 IOException (java.io.IOException)16 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)13 ArrayList (java.util.ArrayList)12 CertPathValidatorException (java.security.cert.CertPathValidatorException)10 HashSet (java.util.HashSet)7 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)7 DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)7 Enumeration (java.util.Enumeration)6 Iterator (java.util.Iterator)6 List (java.util.List)6 Set (java.util.Set)6 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)6 ExtCertPathValidatorException (org.bouncycastle.jce.exception.ExtCertPathValidatorException)6 X509Certificate (java.security.cert.X509Certificate)5 PolicyInformation (sun.security.x509.PolicyInformation)5 GeneralSecurityException (java.security.GeneralSecurityException)4 IssuingDistributionPoint (org.bouncycastle.asn1.x509.IssuingDistributionPoint)4 PolicyQualifierInfo (org.bouncycastle.asn1.x509.PolicyQualifierInfo)4 DError (org.kse.gui.error.DError)4