Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ClickOnce] Fix nonce generation in timestamping of signed manifest. #9579

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Tasks/ManifestUtil/mansign2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -814,13 +814,28 @@ private static string ObtainRFC3161Timestamp(string timeStampUrl, string signatu

try
{
byte[] nonce = new byte[24];
byte[] nonce = new byte[32];

using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
rng.GetBytes(nonce);
}

// Eventually, CryptEncodeObjectEx(...) is called on a CRYPT_TIMESTAMP_REQUEST with this nonce,
// and CryptEncodeObjectEx(...) interprets the nonce as a little endian, DER-encoded integer value
// (without tag and length), and may even strip leading bytes from the big endian representation
// of the byte sequence to achieve proper integer DER encoding.
//
// If the nonce is changed after the client generates it, the timestamp server would receive
// and return a nonce that does not agree with the client's original nonce.
//
// To ensure this does not happen, ensure that the most significant byte in the little
// endian byte sequence is in the 0x01-0x7F range; clear that byte's most significant bit
// and set that byte's least significant bit.

nonce[nonce.Length - 1] &= 0x7f;
nonce[nonce.Length - 1] |= 0x01;

Win32.CRYPT_TIMESTAMP_PARA para = new Win32.CRYPT_TIMESTAMP_PARA()
{
fRequestCerts = true,
Expand Down