-
Notifications
You must be signed in to change notification settings - Fork 381
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
TLS LogRootV1 Format #1037
Merged
Merged
TLS LogRootV1 Format #1037
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0e80915
Define enums for signature formats
gdbelvin 427b7d4
LogRoot format
gdbelvin 1843670
Use TLS variants
gdbelvin 5b8786b
Move LogRoot and MapRoot to types package
gdbelvin a50a47e
add glog so ci tests pass
gdbelvin e8cf97c
Add nil checks to types package
gdbelvin 42bf9b0
Add documentation and tests
gdbelvin 65c2eb5
Use MarshalBinary interface
gdbelvin e073651
Use marshler interfaces in tests
gdbelvin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2018 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package types defines serialization and parsing functions for SignedLogRoot | ||
// and SignedMapRoot fields. | ||
package types | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
|
||
"github.com/google/certificate-transparency-go/tls" | ||
|
||
"github.com/google/trillian" | ||
) | ||
|
||
// LogRootV1 holds the TLS-deserialization of the following structure | ||
// (described in RFC5246 section 4 notation): | ||
// struct { | ||
// uint64 tree_size; | ||
// opaque root_hash<0..128>; | ||
// uint64 timestamp_nanos; | ||
// uint64 revision; | ||
// opaque metadata<0..65535>; | ||
// } LogRootV1; | ||
type LogRootV1 struct { | ||
TreeSize uint64 | ||
RootHash []byte `tls:"minlen:0,maxlen:128"` | ||
TimestampNanos uint64 | ||
Revision uint64 | ||
Metadata []byte `tls:"minlen:0,maxlen:65535"` | ||
} | ||
|
||
// LogRoot holds the TLS-deserialization of the following structure | ||
// (described in RFC5246 section 4 notation): | ||
// enum { v1(1), (65535)} Version; | ||
// struct { | ||
// Version version; | ||
// select(version) { | ||
// case v1: LogRootV1; | ||
// } | ||
// } LogRoot; | ||
type LogRoot struct { | ||
Version tls.Enum `tls:"size:2"` | ||
V1 *LogRootV1 `tls:"selector:Version,val:1"` | ||
} | ||
|
||
// UnmarshalBinary verifies that logRootBytes is a TLS serialized LogRoot, has | ||
// the LOG_ROOT_FORMAT_V1 tag, and populates the caller with the deserialized | ||
// *LogRootV1. | ||
func (l *LogRootV1) UnmarshalBinary(logRootBytes []byte) error { | ||
if logRootBytes == nil { | ||
return fmt.Errorf("nil log root") | ||
} | ||
version := binary.BigEndian.Uint16(logRootBytes) | ||
if version != uint16(trillian.LogRootFormat_LOG_ROOT_FORMAT_V1) { | ||
return fmt.Errorf("invalid LogRoot.Version: %v, want %v", | ||
version, trillian.LogRootFormat_LOG_ROOT_FORMAT_V1) | ||
} | ||
|
||
var logRoot LogRoot | ||
if _, err := tls.Unmarshal(logRootBytes, &logRoot); err != nil { | ||
return err | ||
} | ||
|
||
*l = *logRoot.V1 | ||
return nil | ||
} | ||
|
||
// MarshalBinary returns a canonical TLS serialization of LogRoot. | ||
func (l *LogRootV1) MarshalBinary() ([]byte, error) { | ||
return tls.Marshal(LogRoot{ | ||
Version: tls.Enum(trillian.LogRootFormat_LOG_ROOT_FORMAT_V1), | ||
V1: l, | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we have a package comment in exactly one of the files in
types
? (Some stricter linters check for this.)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.
Added.