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

crypto: TRC update validation #2860

Merged
merged 3 commits into from
Jul 22, 2019
Merged

Conversation

oncilla
Copy link
Contributor

@oncilla oncilla commented Jul 17, 2019

This PR introduces TRC update validation.
The UpdateValidator checks that the new TRC contains valid contents
and the update is valid according to the regular/sensitive rules.

The caller has to verify the signatures itself. It must ensure that
all signatures mentioned in TRC.Votes are present and verifiable.

fixes #2849


This change is Reviewable

@oncilla oncilla added the c/CPPKI SCION Control-plane PKI label Jul 17, 2019
@oncilla oncilla added this to the Q3S1 milestone Jul 17, 2019
@oncilla oncilla requested a review from lukedirtwalker July 17, 2019 13:08
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 4 of 5 files at r1.
Reviewable status: 4 of 5 files reviewed, 7 unresolved discussions (waiting on @lukedirtwalker and @oncilla)


go/lib/scrypto/trc/v2/keychanges.go, line 28 at r1 (raw file):

	InvalidKeyMeta = "invalid key meta"
	// InvalidKeyVersion indicates an invalid key version.
	InvalidKeyVersion = "invalid key version"

This error is always nested in InvalidKeyMeta not sure if that is intended?


go/lib/scrypto/trc/v2/keychanges.go, line 62 at r1 (raw file):

}

func (c *KeyChanges) insertAllFresh(as addr.AS, next PrimaryAS) {

I think this is not needed see comment in update.go.


go/lib/scrypto/trc/v2/keychanges.go, line 93 at r1 (raw file):

	modified := next.Algorithm != prev.Algorithm || !bytes.Equal(next.Key, prev.Key)
	// If the meta data has changed, expect a key version change.
	expectedVersion := prev.KeyVersion

possible alternative, not sure what is better:

	switch {
	case modified && next.KeyVersion != prev.KeyVersion+1:
		return modified, common.NewBasicError(InvalidKeyVersion, nil, "modified", modified,
			"expected", prev.KeyVersion+1, "actual", next.KeyVersion)
	case !modified && next.KeyVersion != prev.KeyVersion:
		return modified, common.NewBasicError(InvalidKeyVersion, nil, "modified", modified,
			"expected", prev.KeyVersion, "actual", next.KeyVersion)
	default:
		return modified, nil
	}

feel free to leave as is.


go/lib/scrypto/trc/v2/update.go, line 141 at r1 (raw file):

	for as, primary := range v.Next.PrimaryASes {
		prev, ok := v.Prev.PrimaryASes[as]
		if !ok {

This is not really needed:

		prev := v.Prev.PrimaryASes[as]
		if err := c.insertModifications(as, prev, primary); err != nil {
			return nil, err
		}

is good enough since prev will be the empty value and prev.Keys[...] will always return !ok and inserModifications checks this.


go/lib/scrypto/trc/v2/update.go, line 157 at r1 (raw file):

	for as, primary := range v.Next.PrimaryASes {
		prev, ok := v.Prev.PrimaryASes[as]
		if !ok {

can also be simplified to:

	for as, primary := range v.Next.PrimaryASes {
		prev := v.Prev.PrimaryASes[as]
		c.insertModifications(as, prev, primary)
	}

insertAll is not needed.

That's the cool thing that we work with values here 💯


go/lib/scrypto/trc/v2/update.go, line 188 at r1 (raw file):

func (v *UpdateValidator) checkVotes(info UpdateInfo) error {
	check := v.checkVotesSensitive

alternative

	var err error
	switch info.Type {
	case RegularUpdate:
		err = v.checkVotesRegular(info)
	default:
		err = v.checkVotesSensitive(info)
	}
	if err != nil {
		return err
	}

I feel this might be slightly clearer. But I'm also fine with the current version


go/lib/scrypto/trc/v2/update.go, line 269 at r1 (raw file):

}

func (c AttributeChanges) insertAll(as addr.AS, attrs Attributes, change AttributeChange) {

not needed see comment above

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 1 of 5 files at r1.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @oncilla)


go/lib/scrypto/trc/v2/update_test.go, line 30 at r1 (raw file):

// TestCommonUpdate tests shared error cases between regular and sensitive updates.
func TestCommonUpdate(t *testing.T) {

I think somewhere you should also test that the TRCs as created are indeed a valid update pair, as that is kind of the base assumption for the other tests.


go/lib/scrypto/trc/v2/update_test.go, line 39 at r1 (raw file):

				*updated = *newBaseTRC()
				updated.Version = 2
				updated.BaseVersion = 2

Just setting updated.BaseVersion = updated.Version would be a bit simpler.


go/lib/scrypto/trc/v2/update_test.go, line 51 at r1 (raw file):

		"Wrong ISD": {
			Modify: func(updated, _ *trc.TRC) {
				updated.ISD = 2

instead of 2 you could use prev.ISD + 1 it makes it a bit more flexible.

oncilla added 3 commits July 22, 2019 10:14
This PR introduces TRC update validation.
The `UpdateValidator` checks that the new TRC contains valid contents
and the update is valid according to the regular/sensitive rules.

The caller has to verify the signatures itself. It must ensure that
all signatures mentioned in TRC.Votes are present and verifiable.
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: 2 of 5 files reviewed, 6 unresolved discussions (waiting on @lukedirtwalker)


go/lib/scrypto/trc/v2/keychanges.go, line 28 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

This error is always nested in InvalidKeyMeta not sure if that is intended?

That is intended yes. The wrapping call attaches additional information that cannot be known by ValidateKeyUpdate


go/lib/scrypto/trc/v2/keychanges.go, line 62 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

I think this is not needed see comment in update.go.

Done.


go/lib/scrypto/trc/v2/update.go, line 141 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

This is not really needed:

		prev := v.Prev.PrimaryASes[as]
		if err := c.insertModifications(as, prev, primary); err != nil {
			return nil, err
		}

is good enough since prev will be the empty value and prev.Keys[...] will always return !ok and inserModifications checks this.

Nice!
Done.


go/lib/scrypto/trc/v2/update.go, line 157 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

can also be simplified to:

	for as, primary := range v.Next.PrimaryASes {
		prev := v.Prev.PrimaryASes[as]
		c.insertModifications(as, prev, primary)
	}

insertAll is not needed.

That's the cool thing that we work with values here 💯

Done.


go/lib/scrypto/trc/v2/update.go, line 188 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

alternative

	var err error
	switch info.Type {
	case RegularUpdate:
		err = v.checkVotesRegular(info)
	default:
		err = v.checkVotesSensitive(info)
	}
	if err != nil {
		return err
	}

I feel this might be slightly clearer. But I'm also fine with the current version

Done.


go/lib/scrypto/trc/v2/update.go, line 269 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

not needed see comment above

Done.


go/lib/scrypto/trc/v2/update_test.go, line 30 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

I think somewhere you should also test that the TRCs as created are indeed a valid update pair, as that is kind of the base assumption for the other tests.

That is only possible for the regular update, which is done in TestRegularUpdate


go/lib/scrypto/trc/v2/update_test.go, line 39 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

Just setting updated.BaseVersion = updated.Version would be a bit simpler.

Done.


go/lib/scrypto/trc/v2/update_test.go, line 51 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

instead of 2 you could use prev.ISD + 1 it makes it a bit more flexible.

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 3 of 3 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@oncilla oncilla merged commit 06e3d4d into scionproto:master Jul 22, 2019
@oncilla oncilla deleted the pub-trc-update branch July 22, 2019 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/CPPKI SCION Control-plane PKI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CPPKI: Implement TRC update validation
2 participants