Search in sources :

Example 46 with ASN1ObjectIdentifier

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

the class X509Ext method getSubjectDirectoryAttributesStringValue.

private String getSubjectDirectoryAttributesStringValue(byte[] value) throws IOException {
    // @formatter:off
    /*
		 * SubjectDirectoryAttributes ::= ASN1Sequence SIZE (1..MAX) OF Attribute
		 *
		 * Attribute ::= ASN1Sequence
		 * {
		 *      type AttributeType,
		 *      values SET OF AttributeValue
		 * }
		 */
    // @formatter:on
    StringBuilder sb = new StringBuilder();
    SubjectDirectoryAttributes subjectDirectoryAttributes = SubjectDirectoryAttributes.getInstance(value);
    for (Object attribute : subjectDirectoryAttributes.getAttributes()) {
        ASN1ObjectIdentifier attributeType = ((Attribute) attribute).getAttrType();
        String attributeTypeStr = attributeType.getId();
        ASN1Encodable[] attributeValues = ((Attribute) attribute).getAttributeValues();
        for (ASN1Encodable attributeValue : attributeValues) {
            String attributeValueStr = getAttributeValueString(attributeType, attributeValue);
            sb.append(MessageFormat.format("{0}={1}", attributeTypeStr, attributeValueStr));
            sb.append(NEWLINE);
        }
    }
    return sb.toString();
}
Also used : Attribute(org.bouncycastle.asn1.x509.Attribute) SubjectDirectoryAttributes(org.bouncycastle.asn1.x509.SubjectDirectoryAttributes) 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) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 47 with ASN1ObjectIdentifier

use of org.bouncycastle.asn1.ASN1ObjectIdentifier 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 48 with ASN1ObjectIdentifier

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

the class X509CertificateGenerator method generateVersion3.

private X509Certificate generateVersion3(X500Name subject, X500Name issuer, Date validityStart, Date validityEnd, PublicKey publicKey, PrivateKey privateKey, SignatureType signatureType, BigInteger serialNumber, X509Extension extensions, Provider provider) throws CryptoException, CertIOException {
    Date notBefore = validityStart == null ? new Date() : validityStart;
    Date notAfter = validityEnd == null ? new Date(notBefore.getTime() + TimeUnit.DAYS.toMillis(365)) : validityEnd;
    JcaX509v3CertificateBuilder certBuilder = new JcaX509v3CertificateBuilder(issuer, serialNumber, notBefore, notAfter, subject, publicKey);
    if (extensions != null) {
        for (String oid : extensions.getCriticalExtensionOIDs()) {
            certBuilder.addExtension(new ASN1ObjectIdentifier(oid), true, getExtensionValue(extensions, oid));
        }
        for (String oid : extensions.getNonCriticalExtensionOIDs()) {
            certBuilder.addExtension(new ASN1ObjectIdentifier(oid), false, getExtensionValue(extensions, oid));
        }
    }
    try {
        ContentSigner certSigner = null;
        if (provider == null) {
            certSigner = new JcaContentSignerBuilder(signatureType.jce()).setProvider("BC").build(privateKey);
        } else {
            certSigner = new JcaContentSignerBuilder(signatureType.jce()).setProvider(provider).build(privateKey);
        }
        return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certBuilder.build(certSigner));
    } catch (CertificateException | IllegalStateException | OperatorCreationException ex) {
        throw new CryptoException(res.getString("CertificateGenFailed.exception.message"), ex);
    }
}
Also used : JcaContentSignerBuilder(org.bouncycastle.operator.jcajce.JcaContentSignerBuilder) JcaX509CertificateConverter(org.bouncycastle.cert.jcajce.JcaX509CertificateConverter) JcaX509v3CertificateBuilder(org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder) ContentSigner(org.bouncycastle.operator.ContentSigner) CertificateException(java.security.cert.CertificateException) OperatorCreationException(org.bouncycastle.operator.OperatorCreationException) CryptoException(org.kse.crypto.CryptoException) Date(java.util.Date) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 49 with ASN1ObjectIdentifier

use of org.bouncycastle.asn1.ASN1ObjectIdentifier 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 50 with ASN1ObjectIdentifier

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

Aggregations

ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)331 IOException (java.io.IOException)85 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)80 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)61 DEROctetString (org.bouncycastle.asn1.DEROctetString)60 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)57 DERIA5String (org.bouncycastle.asn1.DERIA5String)57 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)52 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)50 DERSequence (org.bouncycastle.asn1.DERSequence)47 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)44 ASN1String (org.bouncycastle.asn1.ASN1String)41 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)38 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)37 Extension (org.bouncycastle.asn1.x509.Extension)36 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)35 ArrayList (java.util.ArrayList)34 BigInteger (java.math.BigInteger)33 X500Name (org.bouncycastle.asn1.x500.X500Name)33 HashSet (java.util.HashSet)31