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

Remove opencontainer dependency for timestamping code #11

Merged
merged 4 commits into from
Jun 29, 2022

Conversation

priteshbandi
Copy link
Contributor

  • timestamping shouldn't depend on opencontainers.
  • Also, rephrased some of the error message for certificate chain validation.

Pritesh Bandi added 2 commits June 21, 2022 10:55
Signed-off-by: Pritesh Bandi <pritesb@amazon.com>
Signed-off-by: Pritesh Bandi <pritesb@amazon.com>
Copy link
Contributor

@rgnote rgnote left a comment

Choose a reason for hiding this comment

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

LGTM

@gokarnm gokarnm requested a review from a team June 24, 2022 23:25
timestamp/request.go Outdated Show resolved Hide resolved
timestamp/http_test.go Outdated Show resolved Hide resolved
timestamp/request.go Outdated Show resolved Hide resolved
timestamp/request.go Show resolved Hide resolved
Comment on lines +3 to +4
// MalformedRequestError is used when timestamping request is malformed.
type MalformedRequestError struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is better to name it ErrorMalformedRequest. It's a convention to put Error as a prefix.

timestamp/request.go Outdated Show resolved Hide resolved
timestamp/token.go Outdated Show resolved Hide resolved
timestamp/token.go Outdated Show resolved Hide resolved
timestamp/request.go Outdated Show resolved Hide resolved
Signed-off-by: Pritesh Bandi <pritesb@amazon.com>
return NewRequest(digest.FromBytes(content))
}
// NewRequestWithContent creates a request based on the given data and hash algorithm.
func NewRequestWithContent(content []byte, alg crypto.Hash) (*Request, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
func NewRequestWithContent(content []byte, alg crypto.Hash) (*Request, error) {
func NewRequestFromContent(content []byte, alg crypto.Hash) (*Request, error) {

// Verify verifies the message against the timestamp token information.
func (tst *TSTInfo) Verify(message []byte) error {
// VerifyWithContent verifies the message against the timestamp token information.
func (tst *TSTInfo) VerifyWithContent(message []byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
func (tst *TSTInfo) VerifyWithContent(message []byte) error {
func (tst *TSTInfo) VerifyContent(message []byte) error {

Comment on lines 103 to 120
func validate(digest []byte, alg crypto.Hash) error {
l := len(digest)
var validContent bool
switch alg {
case crypto.SHA256:
validContent = l == crypto.SHA256.Size()
case crypto.SHA384:
validContent = l == crypto.SHA384.Size()
case crypto.SHA512:
validContent = l == crypto.SHA512.Size()
default:
return MalformedRequestError{msg: fmt.Sprintf("unsupported hashing algorithm: %s", alg)}
}
if !validContent {
return MalformedRequestError{msg: fmt.Sprintf("digest is of incorrect size: %d", l)}
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func validate(digest []byte, alg crypto.Hash) error {
l := len(digest)
var validContent bool
switch alg {
case crypto.SHA256:
validContent = l == crypto.SHA256.Size()
case crypto.SHA384:
validContent = l == crypto.SHA384.Size()
case crypto.SHA512:
validContent = l == crypto.SHA512.Size()
default:
return MalformedRequestError{msg: fmt.Sprintf("unsupported hashing algorithm: %s", alg)}
}
if !validContent {
return MalformedRequestError{msg: fmt.Sprintf("digest is of incorrect size: %d", l)}
}
return nil
}
func validate(digest []byte, alg crypto.Hash) error {
switch alg {
case crypto.SHA256, crypto.SHA384, crypto.SHA512:
// no-op
default:
return MalformedRequestError{msg: fmt.Sprintf("unsupported hashing algorithm: %s", alg)}
}
if len(digest) != alg.Size() {
return MalformedRequestError{msg: fmt.Sprintf("digest is of incorrect size: %d", l)}
}
return nil
}

Signed-off-by: Pritesh Bandi <pritesb@amazon.com>
Copy link
Contributor

@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

@gokarnm
Copy link

gokarnm commented Jun 29, 2022

LGTM!

@gokarnm gokarnm merged commit e32e65c into notaryproject:main Jun 29, 2022
@priteshbandi priteshbandi deleted the e2e branch July 12, 2022 22:06
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.

5 participants