-
Notifications
You must be signed in to change notification settings - Fork 116
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
gen-certurl: Read SCT files from directory specified with -sctDir #259
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,38 @@ | ||
package certurl | ||
|
||
import ( | ||
"bytes" | ||
"encoding/binary" | ||
"fmt" | ||
) | ||
|
||
const maxSerializedSCTLength = 0xffff | ||
|
||
// Serializes a list of SignedCertificateTimestamps into a | ||
// SignedCertificateTimestampList (RFC6962 Section 3.3). | ||
func SerializeSCTList(scts [][]byte) ([]byte, error) { | ||
total_length := 0 | ||
for _, sct := range scts { | ||
if len(sct) > maxSerializedSCTLength { | ||
return nil, fmt.Errorf("SCT too large") | ||
} | ||
total_length += len(sct) + 2 // +2 for length | ||
} | ||
if total_length > maxSerializedSCTLength { | ||
return nil, fmt.Errorf("SCT list too large") | ||
} | ||
|
||
var buf bytes.Buffer | ||
if err := binary.Write(&buf, binary.BigEndian, uint16(total_length)); err != nil { | ||
return nil, err | ||
} | ||
for _, sct := range scts { | ||
if err := binary.Write(&buf, binary.BigEndian, uint16(len(sct))); err != nil { | ||
return nil, err | ||
} | ||
if _, err := buf.Write(sct); err != nil { | ||
return nil, err | ||
} | ||
} | ||
return buf.Bytes(), nil | ||
} |
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,37 @@ | ||
package certurl_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
. "github.com/WICG/webpackage/go/signedexchange/certurl" | ||
) | ||
|
||
func TestCreateOCSPRequest(t *testing.T) { | ||
expected := []byte{ | ||
0x00, 0x0a, // length | ||
0x00, 0x03, 0x01, 0x02, 0x03, // length + first SCT | ||
0x00, 0x03, 0x04, 0x05, 0x06, // length + second SCT | ||
} | ||
serialized, err := SerializeSCTList([][]byte{{1, 2, 3}, {4, 5, 6}}) | ||
if err != nil { | ||
t.Errorf("SerializeSCTList failed: %v", err) | ||
return | ||
} | ||
if !bytes.Equal(expected, serialized) { | ||
t.Errorf("The SCTs expected to serialize to %v, actual %v", expected, serialized) | ||
} | ||
} | ||
|
||
func TestCreateOCSPRequestTooLarge(t *testing.T) { | ||
_, err := SerializeSCTList([][]byte{make([]byte, 65536)}) | ||
if err == nil { | ||
t.Errorf("SerializeSCTList didn't fail with too large SCT") | ||
} | ||
|
||
// (32766 + 2) * 2 = 65536 | ||
_, err = SerializeSCTList([][]byte{make([]byte, 32766), make([]byte, 32766)}) | ||
if err == nil { | ||
t.Errorf("SerializeSCTList didn't fail with too large SCT list") | ||
} | ||
} |
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
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.
I removed
-sct
here since SCT is not necessary for self-signed certs.I plan to add a separate section for instructions to create signed exchanges with trusted certificates, and will explain the usage of
-sctDir
there.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.
sgtm