extract timestamp from p7s(signature file)

Solution 1:

You can use OpenSSL's cms command to view the contents of a signed PKCS#7 file. Assuming you haven't got the signer's certificate, and therefore aren't verifying the signature and are only viewing the structure, you can use:

openssl cms -verify -noverify -cmsout -print -inform DER -in file.p7s

This will dump details of the structure, which includes the following extract:

    signedAttrs:
        object: contentType (1.2.840.113549.1.9.3)
        set:
          OBJECT:pkcs7-data (1.2.840.113549.1.7.1)

        object: signingTime (1.2.840.113549.1.9.5)
        set:
          GENERALIZEDTIME:Aug  3 23:50:00 2020 GMT

You could filter this with awk or grep for the required signingTime field.

If filtering the text output of OpenSSL doesn't sit well with you, there are other tools better suited to inspecting the contents of any ASN.1 structure. If you're competent in Python for example, you could use pyasn1crypto.