-
Notifications
You must be signed in to change notification settings - Fork 163
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
CPPKI: Do not double base64 encode #3549
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 40 of 40 files at r1.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @oncilla)
go/lib/infra/modules/trust/v2/trustdbsqlite/db.go, line 222 at r1 (raw file):
defer e.Unlock() h := hash([]byte(d.Signed.EncodedTRC))
I think it would be cleaner if the conversion to the byte slice happens in the hash function itself.
go/lib/scrypto/cert/v2/as_signed_test.go, line 78 at r1 (raw file):
valid[:len(valid)/2]
just that should be enough
go/lib/scrypto/cert/v2/as_signed_test.go, line 143 at r1 (raw file):
valid[:len(valid)/2]
just that should be enough
go/lib/scrypto/cert/v2/issuer_signed_test.go, line 78 at r1 (raw file):
valid[:len(valid)/2]
just that should be enough
go/lib/scrypto/cert/v2/issuer_signed_test.go, line 144 at r1 (raw file):
valid[:len(valid)/2]
just that should be enough
go/lib/scrypto/trc/v2/signed_test.go, line 79 at r1 (raw file):
valid[:len(valid)/2]
just that should be enough
go/lib/scrypto/trc/v2/signed_test.go, line 144 at r1 (raw file):
valid[:len(valid)/2]
just that should be enough
We use the JWS standard that prescribes that the payload and protected metadata must be encoded as base 64 raw url safe encoding. In the go code, we have typed byte slices with respective encode and decode functions because the json library only allows using the standard base64 encoding. Helpfully, when calling json.{Unm,M}arshal, byte slices are encoded in base64 automatically. Which results in double encoding in our case. This PR changes the encoded types to string types to prevent the json library from encoding the data.
e27ed64
to
442b142
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 14 of 48 files reviewed, 7 unresolved discussions (waiting on @lukedirtwalker)
go/lib/infra/modules/trust/v2/trustdbsqlite/db.go, line 222 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
I think it would be cleaner if the conversion to the byte slice happens in the hash function itself.
In that case I need to cast everything to string first, as typed strings cannot be passed to string argument.
go/lib/scrypto/cert/v2/as_signed_test.go, line 78 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
valid[:len(valid)/2]
just that should be enough
valid[:len(valid)/2]
is not guaranteed to be valid base64, so we might not even get to the branch we try to cover.
if you look at the coverage report, it will shrink with the proposed change.
Made it a bit prettier
go/lib/scrypto/cert/v2/as_signed_test.go, line 143 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
valid[:len(valid)/2]
just that should be enough
Done.
go/lib/scrypto/cert/v2/issuer_signed_test.go, line 78 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
valid[:len(valid)/2]
just that should be enough
Done.
go/lib/scrypto/cert/v2/issuer_signed_test.go, line 144 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
valid[:len(valid)/2]
just that should be enough
Done.
go/lib/scrypto/trc/v2/signed_test.go, line 79 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
valid[:len(valid)/2]
just that should be enough
Done.
go/lib/scrypto/trc/v2/signed_test.go, line 144 at r1 (raw file):
Previously, lukedirtwalker (Lukas Vogel) wrote…
valid[:len(valid)/2]
just that should be enough
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 34 of 34 files at r2.
Reviewable status:complete! all files reviewed, all discussions resolved
go/lib/infra/modules/trust/v2/trustdbsqlite/db.go, line 222 at r1 (raw file):
Previously, Oncilla wrote…
In that case I need to cast everything to string first, as typed strings cannot be passed to string argument.
:sad_panda:
We use the JWS standard that prescribes that the payload and protected
metadata must be encoded as base 64 raw url safe encoding.
In the go code, we have typed byte slices with respective encode and
decode functions because the json library only allows using the standard
base64 encoding.
Helpfully, when calling json.{Unm,M}arshal, byte slices are encoded in
base64 automatically. Which results in double encoding in our case.
This PR changes the encoded types to string types to prevent the
json library from encoding the data.
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)