-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ade17a7
commit 91d36ea
Showing
10 changed files
with
215 additions
and
41 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,6 @@ The `.env` file required for the Docker service is a key-value format with this | |
|
||
``` | ||
WITNESS_PRIVATE_KEY=PRIVATE+KEY+YourTokenHere+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
WITNESS_PUBLIC_KEY=YourTokenHere+01234567+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | ||
GITHUB_AUTH_TOKEN=ghp_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
GIT_USERNAME=johndoe | ||
|
@@ -67,7 +66,7 @@ [email protected] | |
WITNESS_VERSION=latest | ||
``` | ||
|
||
`WITNESS_PRIVATE_KEY` and `WITNESS_PUBLIC_KEY` should be generated as documented in [Witness Key Generation](#witness-key-generation). | ||
`WITNESS_PRIVATE_KEY` should be generated as documented in [Witness Key Generation](#witness-key-generation). | ||
|
||
If you wish to use the distributors to push to GitHub, follow the steps in [GitHub Credentials](#github-credentials) and then: | ||
* The token should be set as `GITHUB_AUTH_TOKEN` | ||
|
@@ -81,14 +80,13 @@ If you have some reason to run the OmniWitness outside of Docker, then you can r | |
### Simple | ||
|
||
The simplest possible configuration brings up the OmniWitness to follow all of the logs, | ||
but the witnessed checkpoints will not be distributed and can only be disovered via the | ||
but the witnessed checkpoints will not be distributed and can only be discovered via the | ||
witness HTTP endpoints. | ||
You will need to have followed the steps in [Witness Key Generation](#witness-key-generation). | ||
|
||
``` | ||
go run github.com/transparency-dev/witness/cmd/omniwitness@master --alsologtostderr --v=1 \ | ||
--private_key PRIVATE+KEY+my.witness+67890abc+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \ | ||
--public_key my.witness+67890abc+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \ | ||
--db_file ~/witness.db | ||
``` | ||
|
||
|
@@ -103,7 +101,6 @@ This is described in [GitHub Credentials](#github-credentials). | |
``` | ||
go run github.com/transparency-dev/witness/cmd/omniwitness@master --alsologtostderr --v=1 \ | ||
--private_key PRIVATE+KEY+my.witness+67890abc+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \ | ||
--public_key my.witness+67890abc+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \ | ||
--gh_user my-github-user \ | ||
--gh_email [email protected] \ | ||
--gh_token ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \ | ||
|
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
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,147 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package note | ||
|
||
import ( | ||
"bytes" | ||
"crypto/ed25519" | ||
"crypto/sha256" | ||
"encoding/base64" | ||
"encoding/binary" | ||
"errors" | ||
"fmt" | ||
"strings" | ||
"time" | ||
"unicode" | ||
"unicode/utf8" | ||
|
||
"golang.org/x/mod/sumdb/note" | ||
) | ||
|
||
const ( | ||
algEd25519 = 1 | ||
algEd25519CosignatureV1 = 4 | ||
) | ||
|
||
// NewSignerForCosignatureV1 constructs a new Signer that produces timestamped | ||
// cosignature/v1 signatures from a standard Ed25519 encoded signer key. | ||
// | ||
// (The returned Signer has a different key hash from a non-timestamped one, | ||
// meaning it will differ from the key hash in the input encoding.) | ||
func NewSignerForCosignatureV1(skey string) (*Signer, error) { | ||
priv1, skey, _ := strings.Cut(skey, "+") | ||
priv2, skey, _ := strings.Cut(skey, "+") | ||
name, skey, _ := strings.Cut(skey, "+") | ||
hash16, key64, _ := strings.Cut(skey, "+") | ||
key, err := base64.StdEncoding.DecodeString(key64) | ||
if priv1 != "PRIVATE" || priv2 != "KEY" || len(hash16) != 8 || err != nil || !isValidName(name) || len(key) == 0 { | ||
return nil, errSignerID | ||
} | ||
|
||
s := &Signer{name: name} | ||
|
||
alg, key := key[0], key[1:] | ||
switch alg { | ||
default: | ||
return nil, errSignerAlg | ||
|
||
case algEd25519: | ||
if len(key) != ed25519.SeedSize { | ||
return nil, errSignerID | ||
} | ||
key := ed25519.NewKeyFromSeed(key) | ||
pubkey := append([]byte{algEd25519CosignatureV1}, key.Public().(ed25519.PublicKey)...) | ||
s.hash = keyHashEd25519(name, pubkey) | ||
s.sign = func(msg []byte) ([]byte, error) { | ||
t := uint64(time.Now().Unix()) | ||
m, err := formatCosignatureV1(t, msg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// The signature itself is encoded as timestamp || signature. | ||
sig := make([]byte, 0, 8+ed25519.SignatureSize) | ||
sig = binary.LittleEndian.AppendUint64(sig, t) | ||
sig = append(sig, ed25519.Sign(key, m)...) | ||
return sig, nil | ||
} | ||
s.verify = func(msg, sig []byte) bool { | ||
if len(sig) != 8+ed25519.SignatureSize { | ||
return false | ||
} | ||
t := binary.LittleEndian.Uint64(sig) | ||
sig = sig[8:] | ||
m, err := formatCosignatureV1(t, msg) | ||
if err != nil { | ||
return false | ||
} | ||
return ed25519.Verify(key.Public().(ed25519.PublicKey), m, sig) | ||
} | ||
} | ||
|
||
return s, nil | ||
} | ||
|
||
func formatCosignatureV1(t uint64, msg []byte) ([]byte, error) { | ||
// The signed message is in the following format | ||
// | ||
// cosignature/v1 | ||
// time TTTTTTTTTT | ||
// origin line | ||
// NNNNNNNNN | ||
// tree hash | ||
// | ||
// where TTTTTTTTTT is the current UNIX timestamp, and the following | ||
// three lines are the first three lines of the note. All other | ||
// lines are not processed by the witness, so are not signed. | ||
|
||
lines := bytes.Split(msg, []byte("\n")) | ||
if len(lines) < 3 { | ||
return nil, errors.New("cosigned note format invalid") | ||
} | ||
return []byte(fmt.Sprintf( | ||
"cosignature/v1\ntime %d\n%s\n%s\n%s\n", | ||
t, lines[0], lines[1], lines[2])), nil | ||
} | ||
|
||
var ( | ||
errSignerID = errors.New("malformed verifier id") | ||
errSignerAlg = errors.New("unknown verifier algorithm") | ||
errSignerHash = errors.New("invalid verifier hash") | ||
) | ||
|
||
type Signer struct { | ||
name string | ||
hash uint32 | ||
sign func([]byte) ([]byte, error) | ||
verify func(msg, sig []byte) bool | ||
} | ||
|
||
func (s *Signer) Name() string { return s.name } | ||
func (s *Signer) KeyHash() uint32 { return s.hash } | ||
func (s *Signer) Sign(msg []byte) ([]byte, error) { return s.sign(msg) } | ||
|
||
func (s *Signer) Verifier() note.Verifier { | ||
return &verifier{ | ||
name: s.name, | ||
keyHash: s.hash, | ||
v: s.verify, | ||
} | ||
} | ||
|
||
// isValidName reports whether name is valid. | ||
// It must be non-empty and not have any Unicode spaces or pluses. | ||
func isValidName(name string) bool { | ||
return name != "" && utf8.ValidString(name) && strings.IndexFunc(name, unicode.IsSpace) < 0 && !strings.Contains(name, "+") | ||
} | ||
|
||
func keyHashEd25519(name string, key []byte) uint32 { | ||
h := sha256.New() | ||
h.Write([]byte(name)) | ||
h.Write([]byte("\n")) | ||
h.Write(key) | ||
sum := h.Sum(nil) | ||
return binary.BigEndian.Uint32(sum) | ||
} |
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,34 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package note | ||
|
||
import ( | ||
"crypto/rand" | ||
"testing" | ||
|
||
"golang.org/x/mod/sumdb/note" | ||
) | ||
|
||
func TestSignerRoundtrip(t *testing.T) { | ||
skey, _, err := note.GenerateKey(rand.Reader, "test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
s, err := NewSignerForCosignatureV1(skey) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
msg := "test\n123\nf+7CoKgXKE/tNys9TTXcr/ad6U/K3xvznmzew9y6SP0=\n" | ||
n, err := note.Sign(¬e.Note{Text: msg}, s) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if _, err := note.Open(n, note.VerifierList(s.Verifier())); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
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
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
Oops, something went wrong.