Example usage for org.bouncycastle.asn1.pkcs PKCSObjectIdentifiers id_aa_ets_commitmentType

List of usage examples for org.bouncycastle.asn1.pkcs PKCSObjectIdentifiers id_aa_ets_commitmentType

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.pkcs PKCSObjectIdentifiers id_aa_ets_commitmentType.

Prototype

ASN1ObjectIdentifier id_aa_ets_commitmentType

To view the source code for org.bouncycastle.asn1.pkcs PKCSObjectIdentifiers id_aa_ets_commitmentType.

Click Source Link

Document

PKCS#9: 1.2.840.113549.1.9.16.2.16 - <a href="http://tools.ietf.org/html/rfc3126">RFC 3126</a>

Usage

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

License:Open Source License

/** Genera la parte que contiene la informaci&oacute;n del Usuario.
 * Se generan los atributos que se necesitan para generar la firma.
 *
 * <pre>/*  w  w w.  ja  v a2  s  .co  m*/
 * SignerInfo ::= SEQUENCE {
 *   version CMSVersion,
 *   sid SignerIdentifier,
 *   digestAlgorithm DigestAlgorithmIdentifier,
 *   signedAttrs [0] IMPLICIT SignedAttributes OPTIONAL,
 *   signatureAlgorithm SignatureAlgorithmIdentifier,
 *   signature SignatureValue,
 *   unsignedAttrs [1] IMPLICIT UnsignedAttributes OPTIONAL
 * }
 *
 * SignerIdentifier ::= CHOICE {
 *   issuerAndSerialNumber IssuerAndSerialNumber,
 *   subjectKeyIdentifier [0] SubjectKeyIdentifier
 * }
 *
 * SignedAttributes ::= SET SIZE (1..MAX) OF Attribute
 *
 * UnsignedAttributes ::= SET SIZE (1..MAX) OF Attribute
 *
 * Attribute ::= SEQUENCE {
 *   attrType OBJECT IDENTIFIER,
 *   attrValues SET OF AttributeValue
 * }
 *
 * AttributeValue ::= ANY
 *
 * SignatureValue ::= OCTET STRING
 * </pre>
 *
 * @param cert Certificado del firmante
 * @param digestAlgorithmName Nombre del algoritmo de huella digital a usar
 * @param data Datos firmados
 * @param policy Pol&iacute;tica de firma
 * @param signingCertificateV2 {@code true} para utilizar la versi&oacute;n 2 del campo
 *                             signingCertificate, {@code false} para utilizar la versi&oacute;n 1.
 * @param dataDigest Huella digital de los datos firmados
 * @param signDate Fecha de la firma (debe establecerse externamente para evitar desincronismos en la firma trif&aacute;sica)
 * @param padesMode <code>true</code> para generar una firma CAdES compatible PAdES, <code>false</code> para generar una firma CAdES normal
 * @param contentType Tipo de contenido definido por su OID.
 * @param contentDescription Descripci&oacute;n textual del tipo de contenido firmado.
 * @param ctis Lista de compromisos adquiridos con esta firma
 * @param csm Metadatos sobre el firmante
 * @return Los datos necesarios para generar la firma referente a los datos del usuario.
 * @throws java.security.NoSuchAlgorithmException Cuando se introduce un algoritmo no v&aacute;lido.
 * @throws java.io.IOException Cuando se produce un error de entrada/salida.
 * @throws CertificateEncodingException Error de codificaci&oacute;n en el certificado. */
public static ASN1EncodableVector generateSignerInfo(final Certificate cert, final String digestAlgorithmName,
        final byte[] data, final AdESPolicy policy, final boolean signingCertificateV2, final byte[] dataDigest,
        final Date signDate, final boolean padesMode, final String contentType, final String contentDescription,
        final List<CommitmentTypeIndicationBean> ctis, final CAdESSignerMetadata csm)
        throws NoSuchAlgorithmException, IOException, CertificateEncodingException {
    // // ATRIBUTOS

    // authenticatedAttributes (http://tools.ietf.org/html/rfc3852#section-11)
    final ASN1EncodableVector contexExpecific = initContexExpecific(digestAlgorithmName, data, dataDigest,
            signDate, padesMode);

    if (signingCertificateV2) {
        contexExpecific.add(getSigningCertificateV2((X509Certificate) cert, digestAlgorithmName, policy));
    } else {
        contexExpecific.add(getSigningCertificateV1((X509Certificate) cert, digestAlgorithmName, policy));
    }

    // SIGPOLICYID ATTRIBUTE

    if (policy != null && policy.getPolicyIdentifier() != null) {
        contexExpecific.add(getSigPolicyId(digestAlgorithmName, policy));
    }

    /** Secuencia con el tipo de contenido firmado. No se agrega en firmas PAdES.
     *
     * ContentHints ::= SEQUENCE {
     *     contentDescription UTF8String (SIZE (1..MAX)) OPTIONAL,
     *     contentType ContentType
     * } */

    if (contentType != null && !padesMode) {
        final ContentHints contentHints;
        if (contentDescription != null) {
            contentHints = new ContentHints(new ASN1ObjectIdentifier(contentType),
                    new DERUTF8String(contentDescription));
        } else {
            contentHints = new ContentHints(new ASN1ObjectIdentifier(contentType));
        }
        contexExpecific.add(new Attribute(PKCSObjectIdentifiers.id_aa_contentHint,
                new DERSet(contentHints.toASN1Primitive())));
    }

    // Atributos adicionales segun seccion 5.11 de RFC 5126

    // commitment-type-indication
    if (ctis != null && ctis.size() > 0) {
        for (final CommitmentTypeIndicationBean ctib : ctis) {
            contexExpecific.add(new Attribute(PKCSObjectIdentifiers.id_aa_ets_commitmentType, new DERSet(
                    CommitmentTypeIndicationsHelper.generateCommitmentTypeIndication(ctib).toASN1Primitive())));
        }
    }

    // id-aa-ets-signerLocation
    if (csm != null && CAdESSignerMetadataHelper.getSignerLocation(csm.getSignerLocation()) != null) {
        contexExpecific.add(new Attribute(PKCSObjectIdentifiers.id_aa_ets_signerLocation,
                new DERSet(CAdESSignerMetadataHelper.getSignerLocation(csm.getSignerLocation()))));
    }

    return contexExpecific;
}

From source file:eu.europa.ec.markt.dss.signature.cades.CAdESLevelBaselineB.java

License:Open Source License

/**
 * ETSI TS 101 733 V2.2.1 (2013-04)//  www . j  a va  2s  .c om
 * <p/>
 * 5.11.1 commitment-type-indication Attribute
 * There may be situations where a signer wants to explicitly indicate to a verifier that by signing the data, it illustrates a
 * type of commitment on behalf of the signer. The commitment-type-indication attribute conveys such
 * information.
 *
 * @param parameters
 * @param signedAttributes
 */
private void addCommitmentType(final SignatureParameters parameters,
        final ASN1EncodableVector signedAttributes) {

    // TODO (19/08/2014): commitmentTypeQualifier is not implemented
    final BLevelParameters bLevelParameters = parameters.bLevel();

    final List<String> commitmentTypeIndications = bLevelParameters.getCommitmentTypeIndications();
    if (commitmentTypeIndications != null && !commitmentTypeIndications.isEmpty()) {

        final int size = commitmentTypeIndications.size();
        ASN1Encodable[] asn1Encodables = new ASN1Encodable[size];
        for (int ii = 0; ii < size; ii++) {

            final String commitmentTypeId = commitmentTypeIndications.get(ii);
            final ASN1ObjectIdentifier objectIdentifier = new ASN1ObjectIdentifier(commitmentTypeId);
            // final CommitmentTypeIndication commitmentTypeIndication = new CommitmentTypeIndication(objectIdentifier);
            //            final ASN1Primitive asn1Primitive = commitmentTypeIndication.toASN1Primitive();
            asn1Encodables[ii] = new DERSequence(objectIdentifier);
        }
        final DERSet attrValues = new DERSet(asn1Encodables);
        final Attribute attribute = new Attribute(PKCSObjectIdentifiers.id_aa_ets_commitmentType, attrValues);
        signedAttributes.add(attribute);
    }
}

From source file:eu.europa.ec.markt.dss.validation102853.cades.CAdESSignature.java

License:Open Source License

@Override
public CommitmentType getCommitmentTypeIndication() {

    final AttributeTable attributes = signerInformation.getSignedAttributes();
    if (attributes == null) {

        return null;
    }//from  www  . j a  v a 2s  .c  o  m
    final Attribute commitmentTypeIndicationAttribute = attributes
            .get(PKCSObjectIdentifiers.id_aa_ets_commitmentType);
    if (commitmentTypeIndicationAttribute != null) {

        try {

            final ASN1Set attrValues = commitmentTypeIndicationAttribute.getAttrValues();
            final int size = attrValues.size();
            if (size > 0) {

                final CommitmentType commitmentType = new CommitmentType();
                for (int ii = 0; ii < size; ii++) {

                    final DERSequence derSequence = (DERSequence) attrValues.getObjectAt(ii);
                    final CommitmentTypeIndication commitmentTypeIndication = CommitmentTypeIndication
                            .getInstance(derSequence);
                    final ASN1ObjectIdentifier commitmentTypeId = commitmentTypeIndication
                            .getCommitmentTypeId();
                    commitmentType.addIdentifier(commitmentTypeId.getId());
                }
                return commitmentType;
            }
        } catch (Exception e) {
            throw new DSSException("Error when dealing with CommitmentTypeIndication!", e);
        }
    }
    return null;
}

From source file:eu.europa.esig.dss.cades.validation.CAdESSignature.java

License:Open Source License

@Override
public CommitmentType getCommitmentTypeIndication() {

    final AttributeTable attributes = signerInformation.getSignedAttributes();
    if (attributes == null) {

        return null;
    }//from   w w w  . j a va  2  s.c o  m
    final Attribute commitmentTypeIndicationAttribute = attributes
            .get(PKCSObjectIdentifiers.id_aa_ets_commitmentType);
    if (commitmentTypeIndicationAttribute != null) {

        try {

            final ASN1Set attrValues = commitmentTypeIndicationAttribute.getAttrValues();
            final int size = attrValues.size();
            if (size > 0) {

                final CommitmentType commitmentType = new CommitmentType();
                for (int ii = 0; ii < size; ii++) {
                    if (attrValues.getObjectAt(ii) instanceof DERSequence) {
                        final DERSequence derSequence = (DERSequence) attrValues.getObjectAt(ii);
                        final CommitmentTypeIndication commitmentTypeIndication = CommitmentTypeIndication
                                .getInstance(derSequence);
                        final ASN1ObjectIdentifier commitmentTypeId = commitmentTypeIndication
                                .getCommitmentTypeId();
                        commitmentType.addIdentifier(commitmentTypeId.getId());
                    } else {
                        LOG.warn("Unsupported type for CommitmentType : "
                                + attrValues.getObjectAt(ii).getClass());
                    }
                }
                return commitmentType;
            }
        } catch (Exception e) {
            throw new DSSException("Error when dealing with CommitmentTypeIndication!", e);
        }
    }
    return null;
}