Example usage for org.bouncycastle.asn1 DERIA5String DERIA5String

List of usage examples for org.bouncycastle.asn1 DERIA5String DERIA5String

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 DERIA5String DERIA5String.

Prototype

public DERIA5String(String string) 

Source Link

Document

Basic constructor - without validation.

Usage

From source file:es.gob.afirma.signers.cades.CAdESUtils.java

License:Open Source License

/** Obtiene un <i>PolicyInformation</i> a partir de los datos de la pol&iacute;tica.
 * Sirve para los datos de SigningCertificate y SigningCertificateV2. Tiene que llevar algunos
 * datos de la pol&iacute;tica.//from w  ww  .ja v  a2  s . c  om
 *
 * <pre>
 * PolicyInformation ::= SEQUENCE {
 *       policyIdentifier   CertPolicyId,
 *       policyQualifiers   SEQUENCE SIZE (1..MAX) OF PolicyQualifierInfo OPTIONAL
 * }
 *
 * CertPolicyId ::= OBJECT IDENTIFIER
 *
 * PolicyQualifierInfo ::= SEQUENCE {
 *      policyQualifierId  PolicyQualifierId,
 *      qualifier          ANY DEFINED BY policyQualifierId
 * }
 *
 * -- policyQualifierIds for Internet policy qualifiers
 *
 * id-qt          OBJECT IDENTIFIER ::=  { id-pkix 2 }
 * id-qt-cps      OBJECT IDENTIFIER ::=  { id-qt 1 }
 * id-qt-unotice  OBJECT IDENTIFIER ::=  { id-qt 2 }
 *
 * PolicyQualifierId ::= OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice )
 *
 * Qualifier ::= CHOICE {
 *      cPSuri           CPSuri,
 *      userNotice       UserNotice
 * }
 *
 * CPSuri ::= IA5String
 *
 * UserNotice ::= SEQUENCE {
 *      noticeRef        NoticeReference OPTIONAL,
 *      explicitText     DisplayText OPTIONAL
 * }
 *
 * NoticeReference ::= SEQUENCE {
 *      organization     DisplayText,
 *      noticeNumbers    SEQUENCE OF INTEGER
 * }
 *
 * DisplayText ::= CHOICE {
 *      ia5String        IA5String      (SIZE (1..200)),
 *      visibleString    VisibleString  (SIZE (1..200)),
 *      bmpString        BMPString      (SIZE (1..200)),
 *      utf8String       UTF8String     (SIZE (1..200))
 * }
 * </pre>
 *
 * @param policy    Pol&iacute;tica de la firma.
 * @return          Estructura con la pol&iacute;tica preparada para insertarla en la firma. */
private static PolicyInformation[] getPolicyInformation(final AdESPolicy policy) {

    if (policy == null) {
        throw new IllegalArgumentException("La politica de firma no puede ser nula en este punto"); //$NON-NLS-1$
    }

    /** PolicyQualifierInfo ::= SEQUENCE {
     *          policyQualifierId  PolicyQualifierId,
     *          qualifier          ANY DEFINED BY policyQualifierId
     *  } */

    final PolicyQualifierId pqid = PolicyQualifierId.id_qt_cps;
    DERIA5String uri = null;

    if (policy.getPolicyQualifier() != null && !policy.getPolicyQualifier().equals("")) { //$NON-NLS-1$
        uri = new DERIA5String(policy.getPolicyQualifier().toString());
    }

    final ASN1EncodableVector v = new ASN1EncodableVector();
    PolicyQualifierInfo pqi = null;
    if (uri != null) {
        v.add(pqid);
        v.add(uri);
        pqi = PolicyQualifierInfo.getInstance(new DERSequence(v));
    }

    /** PolicyInformation ::= SEQUENCE {
     *     policyIdentifier   CertPolicyId,
     *     policyQualifiers   SEQUENCE SIZE (1..MAX) OF PolicyQualifierInfo OPTIONAL
     *  } */

    if (policy.getPolicyQualifier() == null || pqi == null) {
        return new PolicyInformation[] { new PolicyInformation(new ASN1ObjectIdentifier(
                policy.getPolicyIdentifier().toLowerCase(Locale.US).replace("urn:oid:", "") //$NON-NLS-1$ //$NON-NLS-2$
                )) };
    }

    return new PolicyInformation[] { new PolicyInformation(
            new ASN1ObjectIdentifier(policy.getPolicyIdentifier().toLowerCase(Locale.US).replace("urn:oid:", "") //$NON-NLS-1$ //$NON-NLS-2$
            ), new DERSequence(pqi)) };

}

From source file:mitm.common.security.crl.CRLDistributionPointsBuilder.java

License:Open Source License

public CRLDistPoint buildCRLDistPoint() {
    if (uris.size() == 0) {
        return null;
    }//w w w .  j  a va2  s.com

    CRLDistPoint crlDistPoint;

    ASN1EncodableVector names = new ASN1EncodableVector();

    for (String uri : uris) {
        GeneralName gn = new GeneralName(GeneralName.uniformResourceIdentifier, new DERIA5String(uri));

        names.add(gn);
    }

    GeneralNames gns = GeneralNames.getInstance(new DERSequence(names));

    DistributionPointName dpn = new DistributionPointName(DistributionPointName.FULL_NAME, gns);
    DistributionPoint distp = new DistributionPoint(dpn, null, null);

    crlDistPoint = CRLDistPoint.getInstance(new DERSequence(distp));

    return crlDistPoint;
}

From source file:net.java.bd.tools.security.SecurityUtil.java

License:Open Source License

GeneralNames getRfc822Name(String name) {
    GeneralName gn = new GeneralName(GeneralName.rfc822Name, new DERIA5String(name));
    DERConstructedSequence seq = new DERConstructedSequence();
    seq.addObject(gn);/*from w  ww  . ja va2s . com*/
    return new GeneralNames(seq);
}

From source file:net.java.bd.tools.security.X509BDJEntryConverter.java

License:Open Source License

public DERObject getConvertedValue(DERObjectIdentifier oid, String value) {

    if (value.length() != 0 && value.charAt(0) == '#') {
        try {//ww w .  java  2  s. c  o  m
            return convertHexEncoded(value, 1);
        } catch (IOException e) {
            throw new RuntimeException("can't recode value for oid " + oid.getId());
        }
    } else if (oid.equals(X509Name.EmailAddress) || oid.equals(X509Name.DC)) {
        return new DERIA5String(value);
    } else if (oid.equals(X509Name.DATE_OF_BIRTH)) {
        return new DERGeneralizedTime(value);
        //} else if (oid.equals(X509Name.C) || oid.equals(X509Name.SN) || oid.equals(X509Name.DN_QUALIFIER)){
        // Blu-ray Specific, require UTF8String.  MHP 12.5.6.
    } else if (oid.equals(X509Name.SN) || oid.equals(X509Name.DN_QUALIFIER)) {
        return new DERPrintableString(value);
    }

    return new DERUTF8String(value);
}

From source file:net.jsign.asn1.authenticode.SpcLink.java

License:Apache License

public SpcLink(String url) {
    this.url = new DERIA5String(url);
}

From source file:net.link.util.test.pkix.PkiTestUtils.java

License:Open Source License

public static X509Certificate generateCertificate(PublicKey subjectPublicKey, String subjectDn,
        PrivateKey issuerPrivateKey, @Nullable X509Certificate issuerCert, DateTime notBefore,
        DateTime notAfter, @Nullable String signatureAlgorithm, boolean includeAuthorityKeyIdentifier,
        boolean caCert, boolean timeStampingPurpose, @Nullable URI ocspUri)
        throws IOException, CertificateException, OperatorCreationException {

    String finalSignatureAlgorithm = signatureAlgorithm;
    if (null == signatureAlgorithm)
        finalSignatureAlgorithm = "SHA512WithRSAEncryption";

    X509Principal issuerDN;//  w  w w .  j av  a  2s.  c om
    if (null != issuerCert)
        issuerDN = new X509Principal(issuerCert.getSubjectX500Principal().toString());
    else
        issuerDN = new X509Principal(subjectDn);

    // new bc 2.0 API
    X509Principal subject = new X509Principal(subjectDn);
    SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo.getInstance(subjectPublicKey.getEncoded());
    BigInteger serialNumber = new BigInteger(SERIALNUMBER_NUM_BITS, new SecureRandom());

    X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(
            X500Name.getInstance(issuerDN.toASN1Primitive()), serialNumber, notBefore.toDate(),
            notAfter.toDate(), X500Name.getInstance(subject.toASN1Primitive()), publicKeyInfo);

    // prepare signer
    ContentSigner signer = new JcaContentSignerBuilder(finalSignatureAlgorithm).build(issuerPrivateKey);

    // add extensions
    certificateBuilder.addExtension(X509Extension.subjectKeyIdentifier, false,
            createSubjectKeyId(subjectPublicKey));
    PublicKey issuerPublicKey;
    if (null != issuerCert)
        issuerPublicKey = issuerCert.getPublicKey();
    else
        issuerPublicKey = subjectPublicKey;
    if (includeAuthorityKeyIdentifier)
        certificateBuilder.addExtension(X509Extension.authorityKeyIdentifier, false,
                createAuthorityKeyId(issuerPublicKey));

    certificateBuilder.addExtension(X509Extension.basicConstraints, false, new BasicConstraints(caCert));

    if (timeStampingPurpose)
        certificateBuilder.addExtension(X509Extension.extendedKeyUsage, true,
                new ExtendedKeyUsage(KeyPurposeId.id_kp_timeStamping));

    if (null != ocspUri) {
        GeneralName ocspName = new GeneralName(GeneralName.uniformResourceIdentifier,
                new DERIA5String(ocspUri.toString()));
        AuthorityInformationAccess authorityInformationAccess = new AuthorityInformationAccess(
                X509ObjectIdentifiers.ocspAccessMethod, ocspName);
        certificateBuilder.addExtension(X509Extension.authorityInfoAccess, false, authorityInformationAccess);
    }

    // build
    return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certificateBuilder.build(signer));
}

From source file:net.sf.keystore_explorer.crypto.csr.spkac.Spkac.java

License:Open Source License

private ASN1Sequence createPublicKeyAndChallenge() throws SpkacException {
    ASN1EncodableVector publicKeyAlgorithm = new ASN1EncodableVector();
    publicKeyAlgorithm.add(new ASN1ObjectIdentifier(getPublicKeyAlg().oid()));

    if (getPublicKey() instanceof RSAPublicKey) {
        publicKeyAlgorithm.add(DERNull.INSTANCE);
    } else {/* www .  jav a2 s  .  c  o m*/
        DSAParams dsaParams = ((DSAPublicKey) getPublicKey()).getParams();

        ASN1EncodableVector dssParams = new ASN1EncodableVector();
        dssParams.add(new ASN1Integer(dsaParams.getP()));
        dssParams.add(new ASN1Integer(dsaParams.getQ()));
        dssParams.add(new ASN1Integer(dsaParams.getG()));

        publicKeyAlgorithm.add(new DERSequence(dssParams));
    }

    ASN1EncodableVector spki = new ASN1EncodableVector();
    spki.add(new DERSequence(publicKeyAlgorithm));
    spki.add(encodePublicKeyAsBitString(getPublicKey()));

    ASN1EncodableVector publicKeyAndChallenge = new ASN1EncodableVector();
    publicKeyAndChallenge.add(new DERSequence(spki));
    publicKeyAndChallenge.add(new DERIA5String(getChallenge()));
    return new DERSequence(publicKeyAndChallenge);
}

From source file:net.sf.keystore_explorer.gui.crypto.generalname.DGeneralNameChooser.java

License:Open Source License

private void okPressed() {
    try {//from   w w w.  jav a  2  s  . c o  m
        GeneralName newGeneralName = null;

        if (jrbDirectoryName.isSelected()) {
            X500Name directoryName = jdnDirectoryName.getDistinguishedName();

            if (directoryName == null) {
                JOptionPane.showMessageDialog(this,
                        res.getString("DGeneralNameChooser.DirectoryNameValueReq.message"), getTitle(),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }

            newGeneralName = new GeneralName(GeneralName.directoryName, directoryName);
        } else if (jrbDnsName.isSelected()) {
            String dnsName = jtfDnsName.getText().trim();

            if (dnsName.length() == 0) {
                JOptionPane.showMessageDialog(this,
                        res.getString("DGeneralNameChooser.DnsNameValueReq.message"), getTitle(),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }

            newGeneralName = new GeneralName(GeneralName.dNSName, new DERIA5String(dnsName));
        } else if (jrbIpAddress.isSelected()) {

            String ipAddress = jtfIpAddress.getText().trim();

            if (ipAddress.length() == 0) {
                JOptionPane.showMessageDialog(this,
                        res.getString("DGeneralNameChooser.IpAddressValueReq.message"), getTitle(),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }

            if (!IPAddress.isValid(ipAddress)) {
                JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.NotAValidIP.message"),
                        getTitle(), JOptionPane.WARNING_MESSAGE);
                return;
            }

            newGeneralName = new GeneralName(GeneralName.iPAddress, ipAddress);
        } else if (jrbRegisteredId.isSelected()) {
            ASN1ObjectIdentifier registeredId = joiRegisteredId.getObjectId();

            if (registeredId == null) {
                JOptionPane.showMessageDialog(this,
                        res.getString("DGeneralNameChooser.RegisteredIdValueReq.message"), getTitle(),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }

            newGeneralName = new GeneralName(GeneralName.registeredID, registeredId);
        } else if (jrbRfc822Name.isSelected()) {
            String rfc822Name = jtfRfc822Name.getText().trim();

            if (rfc822Name.length() == 0) {
                JOptionPane.showMessageDialog(this,
                        res.getString("DGeneralNameChooser.Rfc822NameValueReq.message"), getTitle(),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }

            newGeneralName = new GeneralName(GeneralName.rfc822Name, new DERIA5String(rfc822Name));
        } else if (jrbUniformResourceIdentifier.isSelected()) {
            String uniformResourceIdentifier = jtfUniformResourceIdentifier.getText().trim();

            if (uniformResourceIdentifier.length() == 0) {
                JOptionPane.showMessageDialog(this,
                        res.getString("DGeneralNameChooser.UniformResourceIdentifierValueReq.message"),
                        getTitle(), JOptionPane.WARNING_MESSAGE);
                return;
            }

            newGeneralName = new GeneralName(GeneralName.uniformResourceIdentifier,
                    new DERIA5String(uniformResourceIdentifier));
        } else if (jrbPrincipalName.isSelected()) {
            String upnString = jtfPrincipalName.getText().trim();

            if (upnString.length() == 0) {
                JOptionPane.showMessageDialog(this,
                        res.getString("DGeneralNameChooser.PrincipalNameValueReq.message"), getTitle(),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }

            ASN1EncodableVector asn1Vector = new ASN1EncodableVector();
            asn1Vector.add(new ASN1ObjectIdentifier(GeneralNameUtil.UPN_OID));
            asn1Vector.add(new DERTaggedObject(true, 0, new DERUTF8String(upnString)));

            newGeneralName = new GeneralName(GeneralName.otherName, new DERSequence(asn1Vector));
        }

        generalName = newGeneralName;
    } catch (Exception ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
        return;
    }

    closeDialog();
}

From source file:net.sf.keystore_explorer.gui.crypto.policyinformation.DPolicyQualifierInfoChooser.java

License:Open Source License

private void okPressed() {

    PolicyQualifierInfo newPolicyQualifierInfo = null;
    try {/*  w  w w .j a va 2  s. c  o m*/

        if (jrbCps.isSelected()) {
            String cps = jtfCps.getText().trim();

            if (cps.length() == 0) {
                JOptionPane.showMessageDialog(this,
                        res.getString("DPolicyQualifierInfoChooser.CpsValueReq.message"), getTitle(),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }

            newPolicyQualifierInfo = new PolicyQualifierInfo(
                    new ASN1ObjectIdentifier(PKIX_CPS_POINTER_QUALIFIER.oid()),
                    (new DERIA5String(cps)).toASN1Primitive());
        } else {
            UserNotice userNotice = junUserNotice.getUserNotice();

            if (userNotice == null) {
                JOptionPane.showMessageDialog(this,
                        res.getString("DPolicyQualifierInfoChooser.UserNoticeValueReq.message"), getTitle(),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }

            newPolicyQualifierInfo = new PolicyQualifierInfo(
                    new ASN1ObjectIdentifier(PKIX_USER_NOTICE_QUALIFIER.oid()), userNotice);
        }
    } catch (Exception ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
        return;
    }

    policyQualifierInfo = newPolicyQualifierInfo;

    closeDialog();
}

From source file:net.sf.keystore_explorer.gui.dialogs.extensions.DNetscapeBaseUrl.java

License:Open Source License

private void okPressed() {
    String netscapeBaseUrlStr = jtfNetscapeBaseUrl.getText().trim();

    if (netscapeBaseUrlStr.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DNetscapeBaseUrl.ValueReq.message"), getTitle(),
                JOptionPane.WARNING_MESSAGE);
        return;//from w  w w. j a  va 2s  . com
    }

    DERIA5String netscapeBaseUrl = new DERIA5String(netscapeBaseUrlStr);

    try {
        value = netscapeBaseUrl.getEncoded(ASN1Encoding.DER);
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
        return;
    }

    closeDialog();
}