Skip to content

Commit

Permalink
Merge pull request #2 from onrik/master
Browse files Browse the repository at this point in the history
Support classic merkle tree
  • Loading branch information
onrik authored Apr 24, 2017
2 parents 72c4623 + e0ca6d4 commit 5fa5eb4
Show file tree
Hide file tree
Showing 384 changed files with 155,024 additions and 349 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: go

go:
- 1.7
- tip

before_install:
- go get github.com/stretchr/testify
34 changes: 13 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Acronis Notary™ verifyhash CLI utility
## Overview
CLI for Acronis Notary created to verify that a key is included in Merkle Patricia Tree root and proof. It returns boolean and a value, stored inside the proof for given root and key. This operation is a part of a manual verification process for certificates generated by Acronis Notary™.
CLI for Acronis Notary created to verify Merkle Tree and Merkle Patricia Tree root and proof. This operation is a part of a manual verification process for certificates generated by Acronis Notary™.

[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/hyperium/hyper/master/LICENSE)

## Installation

1. Clone the repository `mkdir verifyhash && git clone [email protected]:acronis/notary-verifyhash.git && cd verify`
1. Clone the repository `mkdir verifyhash && git clone [email protected]:acronis/notary-verifyhash.git verifyhash && cd verifyhash`
2. Build and install dependencies `go get -d ./... && go install`

## How to use
Expand All @@ -19,41 +19,33 @@ $ verifyhash --help
USAGE:
verifyhash [global options]
Required flags: -c|-o|-fo, -p|-fp, -r
Required flags: -c, -r, -p, -e
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--cert value, -c value ID of certificate
--object value, -o value "Object" from certificate
--fobject value, --fo value Path to the file with the "object" from certificate
--root value, -r value Merkle root
--proof value, -p value Merkle proof
--fproof value, --fp value Path to the file with merkle proof
--help, -h show help
--version, -v print the version
--cert value, -c value ID of certificate
--root value, -r value Merkle root
--proof value, -p value Merkle proof
--etag value, -e value File eTag
--help, -h show help
--version, -v print the version
```


#### Example usage

In a basic scenario the utility accepts certificate id, merkle patricia root, and merkle patricia proof
Verify Merkle Patricia Tree

`
$ verifyhash -c 7f420817b35d23a9e6f52fa715bffee975c009340419d82d596b700ef03222e9 -r b829f2d554623b22b6ee431dff294e71f24eab79ddc1f83435a2cc606ca53623 -p [\"f843a1207f420817b35d23a9e6f52fa715bffee975c009340419d82d596b700ef03222e9a03131656533626565393065666433383237323465376135643631666531376430\"]
$ ./verifyhash --cert=a8deb1a8ecd60007699d0f9108434c316a1e74f3e69f32fdc7ee3875b47e6f65 --root=48b545fc340bbb5443e1ea59ad7031231fd5997baf738583cf1b02ff32b934bb --proof="[\"f90111a04859bd25820e591e8d48c850f5f3ed9857a4477ea69921e57143a6e85a2ba1398080a0c736c0a016de219c26519ef4db17e04dbded88b9e6a522c6ffed82a55001ab31a080323e8f701e3042c688415a44e55bd36d2fa41cba8df14aea0eede6e0592b938080808080a0e6dadefefb174be9ce76a350f7890ab604bf2aad660dbf47fc2c601db7973e35a0a2da8847b294dbecb823dfea26f9dc1303f9fca39d754623f8769ebfa71add44a01e88e5f64778fb794a5b004740a0278f7fb76256b3b3acbdb0f02ec86eb6af6e80a0965de56d9818e1e65485d67c9739d7b60832eca6c21d5552f48a16fcb02b11cda099a958d2d407f267559027f528ac78b6a2fd173479356b057d12837c6fdc62fd80\",\"f842a038deb1a8ecd60007699d0f9108434c316a1e74f3e69f32fdc7ee3875b47e6f65a03665383038653465383263663830333139323830396661343135326265333231\"]" --etag=6e808e4e82cf803192809fa4152be321
`

In the alternative way, the utility accepts `object`, merkle patricia root, and merkle patricia proof
Verify Merkle Tree

`
$ verifyhash -o {\"eTag\": \"11ee3bee90efd382724e7a5d61fe17d0\", \"key\":\"init.sql\",\"sequencer\": \"24EA5D176F5F21959E\",\"size\": 5391} -r b829f2d554623b22b6ee431dff294e71f24eab79ddc1f83435a2cc606ca53623 -p [\"f843a1207f420817b35d23a9e6f52fa715bffee975c009340419d82d596b700ef03222e9a03131656533626565393065666433383237323465376135643631666531376430\"]
`

The utility could also read an object or proof from files. There is no need to escape characters in files.

`
$ verifyhash -fo "path/to/objectfile" -r b829f2d554623b22b6ee431dff294e71f24eab79ddc1f83435a2cc606ca53623 -fp "path/to/prooffile"
$ ./verifyhash --root=543a5b1d24df27386fd138a84fe02badf2ca98603cabd06267e4b56e2c0a7c79 --proof="[{\"right\":\"8fbda2c989ea391cc5afdd2270cbd3802132a0a25b03db0d40d9473887881c7e\"},{\"left\":\"e1122abf373076abb65af59b8e1492f7d026774cb9225fac377df55611f1d6e6\"},{\"left\":\"35246b8c8713282bce735db1ca4c6c054e4b6b51b0c1e5bd1857feef5c86554f\"},{\"right\":\"d3a22c30a455ca220b5e45cbc4f5279a6144d6288c00557d269455f44cf53bd5\"}]" --etag=7b2febf73e033aec3270d4b5ba7ee1f666f2b01944d011c8ce5f02b86f0c5c0f
`

## License
Expand Down
53 changes: 0 additions & 53 deletions common.go

This file was deleted.

123 changes: 0 additions & 123 deletions common_test.go

This file was deleted.

73 changes: 12 additions & 61 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"time"

Expand All @@ -12,41 +11,27 @@ import (
func main() {
var (
certificate,
object,
root,
proof,
fobject,
fproof string
eTag string
)

app := cli.NewApp()
app.Name = "Verifyhash"
app.Version = "1.0"
app.Version = "2.0"
app.Compiled = time.Now()
app.Copyright = "(c) 2016 Acronis International GmbH"
app.Usage = "Acronis Notary verify hash CLI utility"
app.UsageText = `verifyhash [global options]
Required flags: -c|-o|-fo, -p|-fp, -r`
Required flags: -c, -r, -p, -e`
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "cert, c",
Value: "",
Usage: "ID of certificate",
Destination: &certificate,
},
cli.StringFlag{
Name: "object, o",
Value: "",
Usage: "\"Object\" from certificate",
Destination: &object,
},
cli.StringFlag{
Name: "fobject, fo",
Value: "",
Usage: "Path to the file with the \"object\" from certificate",
Destination: &fobject,
},
cli.StringFlag{
Name: "root, r",
Value: "",
Expand All @@ -60,54 +45,20 @@ func main() {
Destination: &proof,
},
cli.StringFlag{
Name: "fproof, fp",
Name: "etag, e",
Value: "",
Usage: "Path to the file with merkle proof",
Destination: &fproof,
Usage: "File eTag",
Destination: &eTag,
},
}

app.Action = func(c *cli.Context) (err error) {
var val, b []byte
var data dataVerification

if len(object) != 0 && len(fobject) == 0 {
if certificate, err = hashObject([]byte(object)); err != nil {
color.Yellow("\n%v", err)
return nil
}
app.Action = func(c *cli.Context) error {
err := verifyProof([]byte(proof), root, certificate, eTag)
if err != nil {
color.Red("Error: %s", err.Error())
} else {
color.Green("Verification successful")
}
if len(fobject) != 0 {
b, err = ioutil.ReadFile(fobject)
if err != nil {
color.Yellow("\n%v", err)
return nil
}
if certificate, err = hashObject(b); err != nil {
color.Yellow("\n%v", err)
return nil
}
}
if len(fproof) != 0 {
b, err = ioutil.ReadFile(fproof)
if err != nil {
color.Yellow("\n%v", err)
return nil
}
proof = string(b)
}

if err = data.setData(certificate, root, proof); err != nil {
color.Yellow("\n%v", err)
return nil
}

if val, err = data.getValFromTree(); err != nil || len(val) == 0 {
color.Red("\n%v", err)
return nil
}

color.Green("\nVerification successful\nValue: %s\n", string(val))

return nil
}
Expand Down
16 changes: 16 additions & 0 deletions vendor/github.com/btcsuite/btcd/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5fa5eb4

Please sign in to comment.