aboutsummaryrefslogtreecommitdiff
path: root/client/add-entry/main.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-01-29 17:29:34 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-01-29 17:29:34 +0100
commit7dfa743dce780659bd2e71130d91d51e93b1f68e (patch)
treea05f44a93ae28f6cdf3c4b19817a2d53c2370f61 /client/add-entry/main.go
parent20903a5fb26e90ef4b94d157927c3e82bb1893c2 (diff)
replaced x509 with namespace on the client-side
Diffstat (limited to 'client/add-entry/main.go')
-rw-r--r--client/add-entry/main.go44
1 files changed, 33 insertions, 11 deletions
diff --git a/client/add-entry/main.go b/client/add-entry/main.go
index 0f494aa..52861ef 100644
--- a/client/add-entry/main.go
+++ b/client/add-entry/main.go
@@ -5,18 +5,19 @@ import (
"flag"
"fmt"
+ "crypto/ed25519"
"encoding/base64"
"net/http"
"github.com/golang/glog"
"github.com/system-transparency/stfe/client"
+ "github.com/system-transparency/stfe/descriptor"
)
var (
operators = flag.String("operators", "../../descriptor/stfe.json", "path to json-encoded list of log operators")
- logId = flag.String("log_id", "B9oCJk4XIOMXba8dBM5yUj+NLtqTE6xHwbvR9dYkHPM=", "base64-encoded log identifier")
- chain = flag.String("chain", "../../x509util/testdata/chain.pem", "path to pem-encoded certificate chain that the log accepts")
- key = flag.String("key", "../../x509util/testdata/end-entity.key", "path to ed25519 private key that corresponds to the chain's end-entity certificate")
+ logId = flag.String("log_id", "AAEgFKl1V+J3ib3Aav86UgGD7GRRtcKIdDhgc0G4vVD/TGc=", "base64-encoded log identifier")
+ key = flag.String("key", "Zaajc50Xt1tNpTj6WYkljzcVjLXL2CcQcHFT/xZqYEcc5AVSQo1amNgCE0pPJYLNqGUjtEO1/nXbeQcPYsAKPQ==", "base64-encoded ed25519 signing key")
name = flag.String("name", "foobar-1.2.3", "package name")
checksum = flag.String("checksum", "50e7967bce266a506f8f614bb5096beba580d205046b918f47d23b2ec626d75e", "base64-encoded package checksum")
)
@@ -24,17 +25,13 @@ var (
func main() {
flag.Parse()
- pname := []byte(*name)
- psum, err := base64.StdEncoding.DecodeString(*checksum)
- if err != nil {
- glog.Fatalf("failed decoding checksum: %v", err)
- }
-
- client, err := client.NewClientFromPath(*logId, *chain, *key, *operators, &http.Client{}, true)
+ log, sk, sum := mustLoad(*operators, *logId, *key, *checksum)
+ client, err := client.NewClient(log, &http.Client{}, true, sk)
if err != nil {
glog.Fatal(err)
}
- sdi, err := client.AddEntry(context.Background(), pname, psum)
+
+ sdi, err := client.AddEntry(context.Background(), []byte(*name), sum)
if err != nil {
glog.Fatalf("add-entry failed: %v", err)
}
@@ -47,3 +44,28 @@ func main() {
glog.Flush()
}
+
+func mustLoad(operators, logId, key, checksum string) (*descriptor.Log, *ed25519.PrivateKey, []byte) {
+ ops, err := descriptor.LoadOperators(operators)
+ if err != nil {
+ glog.Fatalf("failed loading log operators: %v")
+ }
+ id, err := base64.StdEncoding.DecodeString(logId)
+ if err != nil {
+ glog.Fatalf("invalid base64 log id: %v", err)
+ }
+ log, err := descriptor.FindLog(ops, id)
+ if err != nil {
+ glog.Fatalf("unknown log id: %v", err)
+ }
+ b, err := base64.StdEncoding.DecodeString(key)
+ if err != nil {
+ glog.Fatalf("invalid base64 key: %v", err)
+ }
+ sk := ed25519.PrivateKey(b)
+ b, err = base64.StdEncoding.DecodeString(checksum)
+ if err != nil {
+ glog.Fatalf("failed decoding checksum: %v", err)
+ }
+ return log, &sk, b
+}