Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rekor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SafSec
rekor
Commits
64b7838c
Unverified
Commit
64b7838c
authored
4 years ago
by
Luke Hinds
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve Status Handling (#23)
parent
1f1146ef
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/add.go
+10
-36
10 additions, 36 deletions
cmd/add.go
cmd/get.go
+19
-17
19 additions, 17 deletions
cmd/get.go
cmd/getleaf.go
+8
-5
8 additions, 5 deletions
cmd/getleaf.go
cmd/update.go
+9
-4
9 additions, 4 deletions
cmd/update.go
with
46 additions
and
62 deletions
cmd/add.go
+
10
−
36
View file @
64b7838c
...
...
@@ -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
)
},
}
...
...
This diff is collapsed.
Click to expand it.
cmd/get.go
+
19
−
17
View file @
64b7838c
...
...
@@ -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!"
)
},
}
...
...
This diff is collapsed.
Click to expand it.
cmd/getleaf.go
+
8
−
5
View file @
64b7838c
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
cmd/update.go
+
9
−
4
View file @
64b7838c
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment