Skip to content
Snippets Groups Projects
Unverified Commit 64b7838c authored by Luke Hinds's avatar Luke Hinds Committed by GitHub
Browse files

Improve Status Handling (#23)

parent 1f1146ef
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ package cmd
import (
"context"
"fmt"
"encoding/json"
"io/ioutil"
"net/http"
"time"
......@@ -27,40 +27,6 @@ import (
"github.com/spf13/viper"
)
//type LeafData struct {
// File string `json:"file"`
// Hash string `json:"hash"`
//}
//type LeafData struct {
// Signatures []struct {
// Keyid string `json:"keyid"`
// Sig string `json:"sig"`
// } `json:"signatures"`
// Signed struct {
// Type string `json:"_type"`
// Byproducts struct {
// ReturnValue int `json:"return-value"`
// Stderr string `json:"stderr"`
// Stdout string `json:"stdout"`
// } `json:"byproducts"`
// Command []string `json:"command"`
// Environment struct {
// } `json:"environment"`
// Materials struct {
// FooPy struct {
// Sha256 string `json:"sha256"`
// } `json:"foo.py"`
// } `json:"materials"`
// Name string `json:"name"`
// Products struct {
// FooTarGz struct {
// Sha256 string `json:"sha256"`
// } `json:"foo.tar.gz"`
// } `json:"products"`
// } `json:"signed"`
//}
// addCmd represents the add command
var addCmd = &cobra.Command{
Use: "add",
......@@ -98,7 +64,15 @@ then hash the file into the transparency log`,
if err != nil {
log.Fatal(err)
}
fmt.Println(string(content))
resp := getLeafResponse{}
if err := json.Unmarshal(content, &resp); err != nil {
log.Fatal(err)
}
log.Info("Status: ", resp.Status)
},
}
......
......@@ -20,7 +20,6 @@ import (
"crypto"
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
......@@ -39,8 +38,9 @@ import (
)
type getProofResponse struct {
Proof *trillian.GetInclusionProofByHashResponse
Key []byte
Status string
Proof *trillian.GetInclusionProofByHashResponse
Key []byte
}
// getCmd represents the get command
......@@ -82,8 +82,6 @@ exists within the transparency log`,
log.Fatal(err)
}
fmt.Println(string(content))
resp := getProofResponse{}
if err := json.Unmarshal(content, &resp); err != nil {
log.Fatal(err)
......@@ -99,19 +97,23 @@ exists within the transparency log`,
log.Fatal(err)
}
leafHash := rfc6962.DefaultHasher.HashLeaf(f)
verifier := tclient.NewLogVerifier(rfc6962.DefaultHasher, pub, crypto.SHA256)
root, err := tcrypto.VerifySignedLogRoot(verifier.PubKey, verifier.SigHash, resp.Proof.SignedLogRoot)
if err != nil {
log.Fatal(err)
}
v := merkle.NewLogVerifier(rfc6962.DefaultHasher)
proof := resp.Proof.Proof[0]
if err := v.VerifyInclusionProof(proof.LeafIndex, int64(root.TreeSize), proof.Hashes, root.RootHash, leafHash); err != nil {
log.Fatal(err)
if resp.Proof != nil {
leafHash := rfc6962.DefaultHasher.HashLeaf(f)
verifier := tclient.NewLogVerifier(rfc6962.DefaultHasher, pub, crypto.SHA256)
root, err := tcrypto.VerifySignedLogRoot(verifier.PubKey, verifier.SigHash, resp.Proof.SignedLogRoot)
if err != nil {
log.Fatal(err)
}
v := merkle.NewLogVerifier(rfc6962.DefaultHasher)
proof := resp.Proof.Proof[0]
if err := v.VerifyInclusionProof(proof.LeafIndex, int64(root.TreeSize), proof.Hashes, root.RootHash, leafHash); err != nil {
log.Fatal(err)
}
log.Info("Proof correct!")
} else {
log.Info(resp.Status)
}
log.Info("proof correct!")
},
}
......
......@@ -36,6 +36,12 @@ import (
"github.com/spf13/viper"
)
type getLeafResponse struct {
Status RespStatusCode
Leaf *trillian.GetLeavesByIndexResponse
Key []byte
}
func GenerateRand(length int) string {
b := make([]byte, length)
if _, err := rand.Read(b); err != nil {
......@@ -44,11 +50,6 @@ func GenerateRand(length int) string {
return hex.EncodeToString(b)
}
type getLeafResponse struct {
Leaf *trillian.GetLeavesByIndexResponse
Key []byte
}
var getleafCmd = &cobra.Command{
Use: "getleaf",
Short: "Rekor Get Leaf Command",
......@@ -88,6 +89,8 @@ var getleafCmd = &cobra.Command{
log.Fatal(err)
}
log.Info("Status: ", resp.Status)
pub, err := x509.ParsePKIXPublicKey(resp.Key)
if err != nil {
log.Fatal(err)
......
......@@ -43,9 +43,14 @@ import (
"github.com/spf13/cobra"
)
type RespStatusCode struct {
Code string `json:"file_recieved"`
}
type latestResponse struct {
Proof *trillian.GetLatestSignedLogRootResponse
Key []byte
Status RespStatusCode
Proof *trillian.GetLatestSignedLogRootResponse
Key []byte
}
type state struct {
......@@ -150,13 +155,13 @@ var updateCmd = &cobra.Command{
log.Fatal(err)
}
fmt.Println(string(content))
resp := latestResponse{}
if err := json.Unmarshal(content, &resp); err != nil {
log.Fatal(err)
}
log.Info("Status: ", resp.Status)
pub, err := x509.ParsePKIXPublicKey(resp.Key)
if err != nil {
log.Fatal(err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment