Sample code for 30+ languages & platforms
SQL Server

Check for an S/MIME Signing Time

See more MIME Examples

Demonstrates the Chilkat Mime.HasSignatureSigningTime method, which returns whether the signer at a zero-based index included a CMS signingTime signed attribute. The only argument is the signer index; use NumSignerCerts for the count.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: A signing time records when the signer claims to have signed, which matters for auditing and for validating a certificate that has since expired. It is an optional signed attribute, so not every signature has one — this predicate lets you check before calling GetSignatureSigningTimeStr, avoiding an error for signers that omitted it. Being a signed attribute, it is covered by the signature and cannot be altered undetected.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    DECLARE @mime int
    EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @mime, 'LoadMimeFile', @success OUT, 'qa_data/signed.eml'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        RETURN
      END

    --  After verifying, check whether each signer included a CMS signingTime signed attribute.  The
    --  only argument is the zero-based signer index.
    EXEC sp_OAMethod @mime, 'Verify', @success OUT
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        RETURN
      END

    DECLARE @n int
    EXEC sp_OAGetProperty @mime, 'NumSignerCerts', @n OUT
    DECLARE @i int

    SELECT @i = 0
    WHILE @i <= @n - 1
      BEGIN
        EXEC sp_OAMethod @mime, 'HasSignatureSigningTime', @iTmp0 OUT, @i
        IF @iTmp0
          BEGIN


            PRINT 'Signer ' + @i + ' included a signing time.'
          END
        ELSE
          BEGIN


            PRINT 'Signer ' + @i + ' did not include a signing time.'
          END
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @mime


END
GO