Skip to content

Occasional errors when using nonces in CryptRetrieveTimeStamp #73

@DanielOstovary

Description

@DanielOstovary

Hi,

I have been using CryptRetrieveTimeStamp outside of OpenOpcSignTool and found that passing it a nonce with 32 bytes as you do in OpenOpcSignTool occasionally causes the error:

0x80096005 TRUST_E_TIME_STAMP
The timestamp signature and/or certificate could not be verified or is malformed.

CryptRetrieveTimeStamp uses the input nonce to generate a nonce itself (i.e. the nonce you pass to CryptRetrieveTimeStamp is not the same nonce that is sent to the TSA). Apparently depending on the size of the input nonce sometimes CryptRetrieveTimeStamp creates nonces out of a usual range. This doesn't cause a problem when CryptRetrieveTimeStamp sends the nonce (that it created from the input nonce) to the TSA. However when CryptRetrieveTimeStamp receives the nonce in the TSA's response it apparently sees it or the TSA's digests as invalid, leading CryptRetrieveTimeStamp to fail.

Im not sure why this happens, I have tested various input nonce sizes for this matter and got the following results (tested with Digicert TSA, Free TSA and an internal TSA):

  • For some nonce sizes CryptRetrieveTimeStamp always fails (e.g. 18-24 bytes size)
  • For some nonce sizes CryptRetrieveTimeStamp sometimes fails, probability of fails increase with the nonce size (e.g. 64 bytes size lead to a failures rate of ~50%)
  • For some nonce sizes CryptRetrieveTimeStamp doesn't fail, at least not in the 1000 requests I have tested (e.g. 16-17 bytes size)

I did some quick tests on the OpenOpcSignTool and discovered that this problem also occurs about 1% of the time out of 1000 tries. In that case OpenOpcSignTool silently (i.e. no error message) fails with exit code 2. Since CryptRetrieveTimeStamp creates its own nonce you might want to adjust the nonce size to circumvent this problem. However this might be a security problem depending on how CryptRetrieveTimestamp creates its own nonce.

Greets,
Daniel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions