Class PKCS9Attribute

  • All Implemented Interfaces:
    DerEncoder

    public class PKCS9Attribute
    extends java.lang.Object
    implements DerEncoder
    Class supporting any PKCS9 attribute except ExtendedCertificateAttribute. Supports DER decoding and access to attribute values, but not DER encoding or setting of values.
    • Field Detail

      • UNSTRUCTURED_NAME_OID

        public static final ObjectIdentifier UNSTRUCTURED_NAME_OID
      • COUNTERSIGNATURE_OID

        public static final ObjectIdentifier COUNTERSIGNATURE_OID
      • CHALLENGE_PASSWORD_OID

        public static final ObjectIdentifier CHALLENGE_PASSWORD_OID
      • UNSTRUCTURED_ADDRESS_OID

        public static final ObjectIdentifier UNSTRUCTURED_ADDRESS_OID
      • EXTENDED_CERTIFICATE_ATTRIBUTES_OID

        public static final ObjectIdentifier EXTENDED_CERTIFICATE_ATTRIBUTES_OID
      • ISSUER_AND_SERIALNUMBER_OID

        public static final ObjectIdentifier ISSUER_AND_SERIALNUMBER_OID
      • SIGNING_DESCRIPTION_OID

        public static final ObjectIdentifier SIGNING_DESCRIPTION_OID
      • EXTENSION_REQUEST_OID

        public static final ObjectIdentifier EXTENSION_REQUEST_OID
      • EMAIL_ADDRESS_STR

        public static final java.lang.String EMAIL_ADDRESS_STR
        See Also:
        Constant Field Values
      • UNSTRUCTURED_NAME_STR

        public static final java.lang.String UNSTRUCTURED_NAME_STR
        See Also:
        Constant Field Values
      • CONTENT_TYPE_STR

        public static final java.lang.String CONTENT_TYPE_STR
        See Also:
        Constant Field Values
      • MESSAGE_DIGEST_STR

        public static final java.lang.String MESSAGE_DIGEST_STR
        See Also:
        Constant Field Values
      • SIGNING_TIME_STR

        public static final java.lang.String SIGNING_TIME_STR
        See Also:
        Constant Field Values
      • COUNTERSIGNATURE_STR

        public static final java.lang.String COUNTERSIGNATURE_STR
        See Also:
        Constant Field Values
      • CHALLENGE_PASSWORD_STR

        public static final java.lang.String CHALLENGE_PASSWORD_STR
        See Also:
        Constant Field Values
      • UNSTRUCTURED_ADDRESS_STR

        public static final java.lang.String UNSTRUCTURED_ADDRESS_STR
        See Also:
        Constant Field Values
      • EXTENDED_CERTIFICATE_ATTRIBUTES_STR

        public static final java.lang.String EXTENDED_CERTIFICATE_ATTRIBUTES_STR
        See Also:
        Constant Field Values
      • ISSUER_AND_SERIALNUMBER_STR

        public static final java.lang.String ISSUER_AND_SERIALNUMBER_STR
        See Also:
        Constant Field Values
      • PASSWORD_CHECK_STR

        public static final java.lang.String PASSWORD_CHECK_STR
        See Also:
        Constant Field Values
      • SIGNING_DESCRIPTION_STR

        public static final java.lang.String SIGNING_DESCRIPTION_STR
        See Also:
        Constant Field Values
      • EXTENSION_REQUEST_STR

        public static final java.lang.String EXTENSION_REQUEST_STR
        See Also:
        Constant Field Values
    • Constructor Detail

      • PKCS9Attribute

        public PKCS9Attribute​(ObjectIdentifier oid,
                              java.lang.Object value)
                       throws java.lang.IllegalArgumentException
        Construct an attribute object from the attribute's OID and value. If the attribute is single-valued, provide only one value. If the attribute is multiple-valued, provide an array containing all the values. Arrays of length zero are accepted, though probably useless.

        The following table gives the class that value must have for a given attribute.

        OID Attribute Type Name Kind Value Class
        1.2.840.113549.1.9.1 EmailAddress Multiple-valued String[]
        1.2.840.113549.1.9.2 UnstructuredName Multiple-valued String[]
        1.2.840.113549.1.9.3 ContentType Single-valued ObjectIdentifier
        1.2.840.113549.1.9.4 MessageDigest Single-valued byte[]
        1.2.840.113549.1.9.5 SigningTime Single-valued Date
        1.2.840.113549.1.9.6 Countersignature Multiple-valued SignerInfo[]
        1.2.840.113549.1.9.7 ChallengePassword Single-valued String
        1.2.840.113549.1.9.8 UnstructuredAddress Single-valued String[]
        1.2.840.113549.1.9.9 ExtendedCertificateAttributes Multiple-valued (not supported)
        1.2.840.113549.1.9.10 IssuerAndSerialNumber Single-valued (not supported)
        1.2.840.113549.1.9.11 PasswordCheck Single-valued (not supported)
        1.2.840.113549.1.9.12 PublicKey Single-valued (not supported)
        1.2.840.113549.1.9.13 SigningDescription Single-valued (not supported)
        1.2.840.113549.1.9.14 ExtensionRequest Single-valued Sequence
        Throws:
        java.lang.IllegalArgumentException
      • PKCS9Attribute

        public PKCS9Attribute​(java.lang.String name,
                              java.lang.Object value)
                       throws java.lang.IllegalArgumentException
        Construct an attribute object from the attribute's name and value. If the attribute is single-valued, provide only one value. If the attribute is multiple-valued, provide an array containing all the values. Arrays of length zero are accepted, though probably useless.

        The following table gives the class that value must have for a given attribute. Reasonable variants of these attributes are accepted; in particular, case does not matter.

        OID Attribute Type Name Kind Value Class
        1.2.840.113549.1.9.1 EmailAddress Multiple-valued String[]
        1.2.840.113549.1.9.2 UnstructuredName Multiple-valued String[]
        1.2.840.113549.1.9.3 ContentType Single-valued ObjectIdentifier
        1.2.840.113549.1.9.4 MessageDigest Single-valued byte[]
        1.2.840.113549.1.9.5 SigningTime Single-valued Date
        1.2.840.113549.1.9.6 Countersignature Multiple-valued SignerInfo[]
        1.2.840.113549.1.9.7 ChallengePassword Single-valued String
        1.2.840.113549.1.9.8 UnstructuredAddress Single-valued String[]
        1.2.840.113549.1.9.9 ExtendedCertificateAttributes Multiple-valued (not supported)
        1.2.840.113549.1.9.10 IssuerAndSerialNumber Single-valued (not supported)
        1.2.840.113549.1.9.11 PasswordCheck Single-valued (not supported)
        1.2.840.113549.1.9.12 PublicKey Single-valued (not supported)
        1.2.840.113549.1.9.13 SigningDescription Single-valued (not supported)
        1.2.840.113549.1.9.14 ExtensionRequest Single-valued Sequence
        Throws:
        java.lang.IllegalArgumentException - if the name is not recognized of the value has the wrong type.
      • PKCS9Attribute

        public PKCS9Attribute​(DerValue derVal)
                       throws java.io.IOException
        Construct a PKCS9Attribute from its encoding on an input stream.
        Throws:
        java.io.IOException - on parsing error.
    • Method Detail

      • derEncode

        public void derEncode​(java.io.OutputStream out)
                       throws java.io.IOException
        Write the DER encoding of this attribute to an output stream.

        N.B.: This method always encodes values of ChallengePassword and UnstructuredAddress attributes as ASN.1 PrintableStrings, without checking whether they should be encoded as T61Strings.

        Specified by:
        derEncode in interface DerEncoder
        Parameters:
        out - the stream on which the DER encoding is written.
        Throws:
        java.io.IOException
      • getValue

        public java.lang.Object getValue()
        Get the value of this attribute. If the attribute is single-valued, return just the one value. If the attribute is multiple-valued, return an array containing all the values. It is possible for this array to be of length 0.

        The following table gives the class of the value returned, depending on the type of this attribute.

        OID Attribute Type Name Kind Value Class
        1.2.840.113549.1.9.1 EmailAddress Multiple-valued String[]
        1.2.840.113549.1.9.2 UnstructuredName Multiple-valued String[]
        1.2.840.113549.1.9.3 ContentType Single-valued ObjectIdentifier
        1.2.840.113549.1.9.4 MessageDigest Single-valued byte[]
        1.2.840.113549.1.9.5 SigningTime Single-valued Date
        1.2.840.113549.1.9.6 Countersignature Multiple-valued SignerInfo[]
        1.2.840.113549.1.9.7 ChallengePassword Single-valued String
        1.2.840.113549.1.9.8 UnstructuredAddress Single-valued String[]
        1.2.840.113549.1.9.9 ExtendedCertificateAttributes Multiple-valued (not supported)
        1.2.840.113549.1.9.10 IssuerAndSerialNumber Single-valued (not supported)
        1.2.840.113549.1.9.11 PasswordCheck Single-valued (not supported)
        1.2.840.113549.1.9.12 PublicKey Single-valued (not supported)
        1.2.840.113549.1.9.13 SigningDescription Single-valued (not supported)
        1.2.840.113549.1.9.14 ExtensionRequest Single-valued Sequence
      • isSingleValued

        public boolean isSingleValued()
        Show whether this attribute is single-valued.
      • getName

        public java.lang.String getName()
        Return the name of this attribute.
      • getOID

        public static ObjectIdentifier getOID​(java.lang.String name)
        Return the OID for a given attribute name or null if we don't recognize the name.
      • getName

        public static java.lang.String getName​(ObjectIdentifier oid)
        Return the attribute name for a given OID or null if we don't recognize the oid.
      • toString

        public java.lang.String toString()
        Returns a string representation of this attribute.
        Overrides:
        toString in class java.lang.Object