cryptographic_message_syntax

Struct SignerInfo

Source
pub struct SignerInfo { /* private fields */ }
Expand description

Represents a CMS SignerInfo structure.

This is a high-level interface to the SignerInfo ASN.1 type. It supports performing common operations against that type.

Instances of this type are logically equivalent to a single signed assertion within a SignedData payload. There can be multiple signers per SignedData, which is why this type exists on its own.

Implementations§

Source§

impl SignerInfo

Source

pub fn certificate_issuer_and_serial(&self) -> Option<(&Name, &Integer)>

Obtain the signing X.509 certificate’s issuer name and its serial number.

The returned value can be used to locate the certificate so verification can be performed.

Source

pub fn digest_algorithm(&self) -> DigestAlgorithm

Obtain the message digest algorithm used by this signer.

Source

pub fn signature_algorithm(&self) -> SignatureAlgorithm

Obtain the cryptographic signing algorithm used by this signer.

Source

pub fn signature(&self) -> &[u8]

Obtain the raw bytes constituting the cryptographic signature.

This is the signature that should be verified.

Source

pub fn signed_attributes(&self) -> Option<&SignedAttributes>

Obtain the SignedAttributes attached to this instance.

Source

pub fn unsigned_attributes(&self) -> Option<&UnsignedAttributes>

Obtain the UnsignedAttributes attached to this instance.

Source

pub fn verify_signature_with_signed_data( &self, signed_data: &SignedData, ) -> Result<(), CmsError>

Verifies the signature defined by this signer given a SignedData instance.

This function will perform cryptographic verification that the signature contained within this SignerInfo instance is valid for the content that was signed. The content that was signed is the encapsulated content from the SignedData instance (its .signed_data() value) combined with the SignedAttributes attached to this instance.

§IMPORTANT SECURITY LIMITATIONS

This method only performs signature verification. It:

  • DOES NOT verify the digest hash embedded within SignedAttributes (if present).
  • DOES NOT validate the signing certificate in any way.
  • DOES NOT validate that the cryptography used is appropriate.
  • DOES NOT verify the time stamp token, if present.

See the crate’s documentation for more on the security implications.

Source

pub fn verify_signature_with_signed_data_and_content( &self, signed_data: &SignedData, signed_content: &[u8], ) -> Result<(), CmsError>

Verifies the signature defined by this signer given a SignedData and signed content.

This function will perform cryptographic verification that the signature contained within this SignerInfo is valid for signed_content. Unlike Self::verify_signature_with_signed_data(), the content that was signed is passed in explicitly instead of derived from SignedData.

This is a low-level API that bypasses the normal rules for deriving the raw content a cryptographic signature was made over. You probably want to use Self::verify_signature_with_signed_data() instead. Also note that signed_content here may or may not be the encapsulated content which is ultimately signed.

This method only performs cryptographic signature verification. It is therefore subject to the same limitations as Self::verify_signature_with_signed_data().

Source

pub fn verify_message_digest_with_signed_data( &self, signed_data: &SignedData, ) -> Result<(), CmsError>

Verifies the digest stored in signed attributes matches that of content in a SignedData.

If signed attributes are present on this instance, they must contain a message-digest attribute defining the digest of data that was signed. The specification says this digested data should come from the encapsulated content within SignedData (SignedData.signed_content()).

Note that some utilities of CMS will not store a computed digest in message-digest that came from SignedData or is using the digest algorithm indicated by this SignerInfo. This is strictly in violation of the specification but it does occur.

§IMPORTANT SECURITY LIMITATIONS

This method only performs message digest verification. It:

  • DOES NOT verify the signature over the signed data or anything about the signer.
  • DOES NOT validate that the digest algorithm is strong/appropriate.
  • DOES NOT compare the digests in a manner that is immune to timing side-channels.

See the crate’s documentation for more on the security implications.

Source

pub fn verify_message_digest_with_content( &self, data: &[u8], ) -> Result<(), CmsError>

Verifies the message digest stored in signed attributes using explicit encapsulated content.

Typically, the digest is computed over content stored in the SignedData instance. However, it is possible for the signed content to be external. This function allows you to define the source of that external content.

Behavior is very similar to SignerInfo::verify_message_digest_with_signed_data except the original content that was digested is explicitly passed in. This content is appended with the signed attributes data on this SignerInfo.

The security limitations from SignerInfo::verify_message_digest_with_signed_data apply to this function as well.

Source

pub fn signature_verifier<'a, C>( &self, certs: C, ) -> Result<UnparsedPublicKey<Vec<u8>>, CmsError>
where C: Iterator<Item = &'a CapturedX509Certificate>,

Obtain an entity for validating the signature described by this instance.

This will attempt to locate the certificate used by this signing info structure in the passed iterable of certificates and then construct a signature verifier that can be used to verify content integrity.

If the certificate referenced by this signing info could not be found, an error occurs.

If the signing key’s algorithm or signature algorithm aren’t supported, an error occurs.

Source

pub fn time_stamp_token_signed_data( &self, ) -> Result<Option<SignedData>, CmsError>

Resolve the time-stamp token SignedData for this signer.

The time-stamp token is a SignedData ASN.1 structure embedded as an unsigned attribute. This is a convenience method to extract it and turn it into a SignedData.

Returns Ok(Some) on success, Ok(None) if there is no time-stamp token, and Err if there is a parsing error.

Source

pub fn verify_time_stamp_token(&self) -> Result<Option<()>, CmsError>

Verify the time-stamp token in this instance.

The time-stamp token is a SignedData ASN.1 structure embedded as an unsigned attribute. So this method reconstructs that data structure and effectively calls SignerInfo::verify_signature_with_signed_data and SignerInfo::verify_message_digest_with_signed_data.

Returns Ok(None) if there is no time-stamp token and Ok(Some(())) if there is and the token validates. Err occurs on any parse or verification error.

Source

pub fn signed_content_with_signed_data( &self, signed_data: &SignedData, ) -> Vec<u8>

Obtain the raw bytes of content that was signed given a SignedData.

This joins the encapsulated content from SignedData with SignedAttributes on this instance to produce a new blob. This new blob is the message that is signed and whose signature is embedded in SignerInfo instances.

Source

pub fn signed_content(&self, content: Option<&[u8]>) -> Vec<u8>

Obtain the raw bytes of content that were digested and signed.

The returned value is the message that was signed and whose signature of which needs to be verified.

The optional content argument is the encapContentInfo eContent field, typically the value of SignedData.signed_content().

Source

pub fn signed_attributes_data(&self) -> Option<&[u8]>

Obtain the raw bytes constituting SignerInfo.signedAttrs as encoded for signatures.

Cryptographic signatures in the SignerInfo ASN.1 type are made from the digest of the EXPLICIT SET OF DER encoding of SignerInfo.signedAttrs, if signed attributes are present. This function resolves the raw bytes that are used for digest computation and later signing.

This should always be Some if the instance was constructed from an ASN.1 value that had signed attributes.

Source

pub fn compute_digest_with_signed_data( &self, signed_data: &SignedData, ) -> Digest

Compute a message digest using a SignedData instance.

This will obtain the encapsulated content blob from a SignedData and digest it using the algorithm configured on this instance.

The resulting digest is typically stored in the message-digest attribute of SignedData.

Source

pub fn compute_digest(&self, content: Option<&[u8]>) -> Digest

Compute a message digest using the configured algorithm.

This method calls into compute_digest_with_algorithm() using the digest algorithm stored in this instance.

Source

pub fn compute_digest_with_algorithm( &self, content: Option<&[u8]>, alg: DigestAlgorithm, ) -> Digest

Compute a message digest using an explicit digest algorithm.

This will compute the hash/digest of the passed in content.

Trait Implementations§

Source§

impl Clone for SignerInfo

Source§

fn clone(&self) -> SignerInfo

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SignerInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TryFrom<&SignerInfo> for SignerInfo

Source§

type Error = CmsError

The type returned in the event of a conversion error.
Source§

fn try_from(signer_info: &SignerInfo) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more