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

CPPKI: Do not double base64 encode #3549

Merged
merged 3 commits into from
Dec 23, 2019

Conversation

oncilla
Copy link
Contributor

@oncilla oncilla commented Dec 20, 2019

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

@oncilla oncilla added the bug Something isn't working label Dec 20, 2019
Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a 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.
@oncilla oncilla force-pushed the pub-cppki-double-base64 branch from e27ed64 to 442b142 Compare December 20, 2019 11:40
Copy link
Contributor Author

@oncilla oncilla left a 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.

Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 34 of 34 files at r2.
Reviewable status: :shipit: 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:

@oncilla oncilla merged commit f2b707d into scionproto:master Dec 23, 2019
@oncilla oncilla deleted the pub-cppki-double-base64 branch December 23, 2019 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants