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

fix: fix MessageImprint.HashAlgorithm.Parameters #24

Merged
merged 11 commits into from
Jul 2, 2024

Conversation

Two-Hearts
Copy link
Contributor

@Two-Hearts Two-Hearts commented Jul 1, 2024

This PR fixes MessageImprint.HashAlgorithm.Parameters and added corresponding validation in TSA response based on RFC 3161.

The issue that this PR is trying to fix is:
Golang's asn1.RawValue has zero value with Tag 0, which is actually not a valid asn1 tag (https://luca.ntop.org/Teaching/Appunti/asn1.html).
The correct zero value of the struct should be asn1.NullRawValue with Tag 5. However, asn1.NullRawValue is not a valid asn1 object either. The valid struct, as added by this PR, should be:

asn1.RawValue{
     Tag: 5,
     FullBytes: []bytes{5, 0}  // tag and length
}

If running the below piece of code:

v1 := asn1.NullRawValue
fmt.Println("v1:", v1)

b, _:= asn1.Marshal(v1)
var v2 asn1.RawValue
asn1.Unmarshal(b, &v2)
fmt.Println("v2:", v2)

The printouts will be:

v1: {0 5 false [] []}
v2: {0 5 false [] [5 0]}   --> unmarshal returns the correct struct

(This is a known issue of golang encoding/asn1 package: golang/go#30414. The issue was closed without any code update though)

Signed-off-by: Patrick Zheng <[email protected]>
Copy link

codecov bot commented Jul 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@0bcf659). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #24   +/-   ##
=======================================
  Coverage        ?   95.21%           
=======================================
  Files           ?       19           
  Lines           ?      732           
  Branches        ?        0           
=======================================
  Hits            ?      697           
  Misses          ?       18           
  Partials        ?       17           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
@Two-Hearts Two-Hearts changed the title fix: fix NewRequest fix: fix MessageImprint.HashAlgorithm.Parameters Jul 1, 2024
priteshbandi
priteshbandi previously approved these changes Jul 2, 2024
Copy link

@priteshbandi priteshbandi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JeyJeyGao
Copy link
Contributor

request.go Outdated Show resolved Hide resolved
@Two-Hearts
Copy link
Contributor Author

Two-Hearts commented Jul 2, 2024

https://cs.opensource.google/go/go/+/master:src/encoding/asn1/asn1_test.go;l=1045-1068?q=NullRawValue&ss=go%2Fgo

Could you have a look at this test? Is it by design?

Yes, it is by design by the golang library, but that's not by design of RFC 3161. When a TSA request contains asn1.NullRawValue, the TSA response may contain the correct null raw value struct instead. And this would fail tspclient-go's response validation. Therefore, we need to make sure we send out the correct asn1 object in the request. @JeyJeyGao

request.go Outdated Show resolved Hide resolved
request.go Outdated Show resolved Hide resolved
request.go Outdated Show resolved Hide resolved
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
internal/encoding/asn1/rawvalue/rawvalue.go Outdated Show resolved Hide resolved
request.go Outdated Show resolved Hide resolved
Signed-off-by: Patrick Zheng <[email protected]>
@Two-Hearts Two-Hearts requested a review from shizhMSFT July 2, 2024 03:42
shizhMSFT
shizhMSFT previously approved these changes Jul 2, 2024
Copy link

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with suggestions.

request.go Outdated Show resolved Hide resolved
Signed-off-by: Patrick Zheng <[email protected]>
Copy link

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Two-Hearts Two-Hearts merged commit d918484 into notaryproject:main Jul 2, 2024
9 checks passed
@Two-Hearts Two-Hearts deleted the fix branch July 2, 2024 05:07
@Two-Hearts Two-Hearts mentioned this pull request Jul 9, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants