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

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

Introduction

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

Prototype

ASN1ObjectIdentifier id_aa_contentIdentifier

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

Click Source Link

Document

PKCS#9: 1.2.840.113549.1.9.16.2.7 - See <a href="http://tools.ietf.org/html/rfc2634">RFC 2634</a>

Usage

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)/*from  w ww.  j  a  v  a 2  s. c o m*/
 * <p/>
 * 5.10.2 content-identifier Attribute
 * The content-identifier attribute provides an identifier for the signed content, for use when a reference may be
 * later required to that content; for example, in the content-reference attribute in other signed data sent later. The
 * content-identifier shall be a signed attribute. content-identifier attribute type values for the ES have an ASN.1 type ContentIdentifier, as defined in
 * ESS (RFC 2634 [5]).
 * <p/>
 * The minimal content-identifier attribute should contain a concatenation of user-specific identification
 * information (such as a user name or public keying material identification information), a GeneralizedTime string,
 * and a random number.
 *
 * @param parameters
 * @param signedAttributes
 */
private void addContentIdentifier(final SignatureParameters parameters,
        final ASN1EncodableVector signedAttributes) {

    /* this attribute is prohibited in PAdES B */
    if (!padesUsage) {

        final BLevelParameters bLevelParameters = parameters.bLevel();
        final String contentIdentifierPrefix = bLevelParameters.getContentIdentifierPrefix();
        if (DSSUtils.isNotBlank(contentIdentifierPrefix)) {

            final String contentIdentifierSuffix;
            if (DSSUtils.isBlank(bLevelParameters.getContentIdentifierSuffix())) {

                final Date now = new Date();
                final String asn1GeneralizedTimeString = new ASN1GeneralizedTime(now).getTimeString();
                final long randomNumber = new Random(now.getTime()).nextLong();
                contentIdentifierSuffix = asn1GeneralizedTimeString + randomNumber;
                bLevelParameters.setContentIdentifierSuffix(contentIdentifierSuffix);
            } else {
                contentIdentifierSuffix = bLevelParameters.getContentIdentifierSuffix();
            }
            final String contentIdentifierString = contentIdentifierPrefix + contentIdentifierSuffix;
            final ContentIdentifier contentIdentifier = new ContentIdentifier(
                    contentIdentifierString.getBytes());
            final DERSet attrValues = new DERSet(contentIdentifier);
            final Attribute attribute = new Attribute(PKCSObjectIdentifiers.id_aa_contentIdentifier,
                    attrValues);
            signedAttributes.add(attribute);
        }
    }
}

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

License:Open Source License

@Override
public String getContentIdentifier() {

    final AttributeTable signedAttributes = signerInformation.getSignedAttributes();
    if (signedAttributes == null) {
        return null;
    }//from   ww  w.j  a v  a  2s .co  m
    final Attribute contentIdentifierAttribute = signedAttributes
            .get(PKCSObjectIdentifiers.id_aa_contentIdentifier);
    if (contentIdentifierAttribute == null) {
        return null;
    }
    final ASN1Encodable asn1Encodable = contentIdentifierAttribute.getAttrValues().getObjectAt(0);
    final ContentIdentifier contentIdentifier = ContentIdentifier.getInstance(asn1Encodable);
    final String contentIdentifierString = DSSASN1Utils.toString(contentIdentifier.getValue());
    return contentIdentifierString;
}