From 3767e3b97b83706c1683c664b2a3f4c12c9a6750 Mon Sep 17 00:00:00 2001 From: Guillaume Louvigny Date: Mon, 7 Oct 2019 16:35:17 +0200 Subject: [PATCH] feat: network flow for handshake + removed testify --- api/entity.proto | 24 +- api/internal/crypto_sigchain.proto | 13 - api/internal/crypto_sigchain_entry.proto | 26 - api/internal/handshake.proto | 37 + docs/gen.sum | 5 +- go/gen.sum | 5 +- go/go.mod | 1 - go/go.sum | 42 +- go/internal/crypto/crypto_module.go | 4 +- .../cryptosigchain/crypto_sigchain.pb.go | 413 --------- .../crypto_sigchain_entry.pb.go | 753 ---------------- .../crypto_module.go} | 21 +- .../crypto_session.go} | 31 +- .../crypto_test.go} | 195 ++-- go/internal/handshake/errors.go | 15 + go/internal/handshake/handshake.pb.go | 843 ++++++++++++++++++ go/internal/handshake/net_flow.go | 144 +++ go/internal/handshake/net_flow_test.go | 292 ++++++ .../handshake/net_step_1_2_key_agreement.go | 48 + .../handshake/net_step_3_auth_challenge.go | 42 + .../net_step_4_5_sigchain_exchange.go | 77 ++ go/internal/handshake/net_utils.go | 50 ++ .../bertyprotocol}/crypto_sigchain.go | 4 +- .../bertyprotocol}/crypto_sigchain_entry.go | 2 +- go/pkg/bertyprotocol/entity.pb.go | 574 +++++++++++- go/pkg/iface/crypto.go | 20 - 26 files changed, 2263 insertions(+), 1418 deletions(-) delete mode 100644 api/internal/crypto_sigchain.proto delete mode 100644 api/internal/crypto_sigchain_entry.proto create mode 100644 api/internal/handshake.proto delete mode 100644 go/internal/cryptosigchain/crypto_sigchain.pb.go delete mode 100644 go/internal/cryptosigchain/crypto_sigchain_entry.pb.go rename go/internal/{cryptohandshake/handshake_module.go => handshake/crypto_module.go} (68%) rename go/internal/{cryptohandshake/handshake_session.go => handshake/crypto_session.go} (86%) rename go/internal/{cryptohandshake/handshake_test.go => handshake/crypto_test.go} (54%) create mode 100644 go/internal/handshake/errors.go create mode 100644 go/internal/handshake/handshake.pb.go create mode 100644 go/internal/handshake/net_flow.go create mode 100644 go/internal/handshake/net_flow_test.go create mode 100644 go/internal/handshake/net_step_1_2_key_agreement.go create mode 100644 go/internal/handshake/net_step_3_auth_challenge.go create mode 100644 go/internal/handshake/net_step_4_5_sigchain_exchange.go create mode 100644 go/internal/handshake/net_utils.go rename go/{internal/cryptosigchain => pkg/bertyprotocol}/crypto_sigchain.go (98%) rename go/{internal/cryptosigchain => pkg/bertyprotocol}/crypto_sigchain_entry.go (98%) diff --git a/api/entity.proto b/api/entity.proto index aad5a3a480..e10331cf74 100644 --- a/api/entity.proto +++ b/api/entity.proto @@ -3,14 +3,34 @@ syntax = "proto3"; option go_package = "berty.tech/go/pkg/bertyprotocol"; +import "google/protobuf/timestamp.proto"; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + message Device { bytes device_pub_key = 1; bytes account_pub_key = 2; } -message SigChainEntry {} +message SigChainEntry { + enum SigChainEntryType { + SigChainEntryTypeUndefined = 0; + SigChainEntryTypeInitChain = 1; + SigChainEntryTypeAddKey = 2; + SigChainEntryTypeRemoveKey = 3; + } + + bytes entry_hash = 1; + SigChainEntryType entry_type_code = 2; + bytes parent_entry_hash = 3; + google.protobuf.Timestamp created_at = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + google.protobuf.Timestamp expiring_at = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + bytes signer_public_key_bytes = 6; + bytes subject_public_key_bytes = 7; + bytes signature = 8; +} message SigChain { - repeated SigChainEntry entries = 1; + bytes id = 1 [(gogoproto.customname) = "ID"]; + repeated SigChainEntry entries = 2; } message Contact { diff --git a/api/internal/crypto_sigchain.proto b/api/internal/crypto_sigchain.proto deleted file mode 100644 index f022cb97fc..0000000000 --- a/api/internal/crypto_sigchain.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; - -package sigchain; - -option go_package = "berty.tech/go/internal/cryptosigchain"; - -import "internal/crypto_sigchain_entry.proto"; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; - -message SigChain { - bytes id = 1 [(gogoproto.customname) = "ID"]; - repeated SigChainEntry entries = 2; -} diff --git a/api/internal/crypto_sigchain_entry.proto b/api/internal/crypto_sigchain_entry.proto deleted file mode 100644 index 2292f65dcc..0000000000 --- a/api/internal/crypto_sigchain_entry.proto +++ /dev/null @@ -1,26 +0,0 @@ -syntax = "proto3"; - -package sigchain; - -option go_package = "berty.tech/go/internal/cryptosigchain"; - -import "google/protobuf/timestamp.proto"; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; - -message SigChainEntry { - enum SigChainEntryType { - SigChainEntryTypeUndefined = 0; - SigChainEntryTypeInitChain = 1; - SigChainEntryTypeAddKey = 2; - SigChainEntryTypeRemoveKey = 3; - } - - bytes entry_hash = 1; - SigChainEntryType entry_type_code = 2; - bytes parent_entry_hash = 3; - google.protobuf.Timestamp created_at = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; - google.protobuf.Timestamp expiring_at = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; - bytes signer_public_key_bytes = 6; - bytes subject_public_key_bytes = 7; - bytes signature = 8; -} diff --git a/api/internal/handshake.proto b/api/internal/handshake.proto new file mode 100644 index 0000000000..6869c52ad6 --- /dev/null +++ b/api/internal/handshake.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +package handshake; + +option go_package = "berty.tech/go/internal/handshake"; + +import "entity.proto"; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message HandshakeFrame { + enum HandshakeStep { + STEP_1_KEY_AGREEMENT = 0; + STEP_2_KEY_AGREEMENT = 1; + + STEP_3_DISPATCH = 10; // Should not be used directly + + STEP_3A_KNOWN_IDENTITY_PROOF = 20; + STEP_4A_KNOWN_IDENTITY_DISCLOSURE = 21; + STEP_5A_KNOWN_IDENTITY_DISCLOSURE = 22; + + STEP_3B_KNOWN_DEVICE_PROOF = 30; + STEP_4B_KNOWN_DEVICE_DISCLOSURE = 31; + + STEP_9_DONE = 999; // Should not be used directly + } + + HandshakeStep step = 1; + bytes signatureKey = 2; + bytes encryptionKey = 3; + bytes encryptedPayload = 4; +} + +message HandshakePayload { + bytes signature = 1; + SigChain sigChain = 2; + bytes deviceKey = 3; +} diff --git a/docs/gen.sum b/docs/gen.sum index d71df4a5c5..1b85229d58 100644 --- a/docs/gen.sum +++ b/docs/gen.sum @@ -2,10 +2,9 @@ b139403f729a7cf26f2d2ecbde2d9b6524b5efe2 ../api/baz.proto ff391d728348f29cc5717259c34c3e5ac09d111c ../api/bertychat.proto 72ed3ae8d0d04176da21eb7f4c4cd6ce24207c37 ../api/bertyprotocol.proto 5ab0b787232df7924763ee81368185385bdf340d ../api/chatmodel.proto -961a4952e56eb176d8239981794e0bff5ebe9238 ../api/entity.proto +66a1baee88ad13dbab569a449235046ab061b5de ../api/entity.proto bb0d4bdd5e638b97f5dd350eb3505645de48eda5 ../api/internal/bar.proto -ae05d50ce77bd7f8d80555112b6ebf3a77053992 ../api/internal/crypto_sigchain.proto -8415f8071ae068eb5cb4c31adcd1a6513473588f ../api/internal/crypto_sigchain_entry.proto 85030963b9dd2a9e133da98c6d6dbc1ce73993b0 ../api/internal/foo.proto +e63e8e917c3ea5559a2f55629d1b633415920d21 ../api/internal/handshake.proto 2d16fa7cd2c7dd30a9480df3d1aac433c120ce32 ../api/protocolmodel.proto d410cf3ad81cac7fc0ead9ea91ca0f592d86b4e8 Makefile diff --git a/go/gen.sum b/go/gen.sum index 717d7e9bad..58a2d0fe1d 100644 --- a/go/gen.sum +++ b/go/gen.sum @@ -2,10 +2,9 @@ b139403f729a7cf26f2d2ecbde2d9b6524b5efe2 ../api/baz.proto ff391d728348f29cc5717259c34c3e5ac09d111c ../api/bertychat.proto 72ed3ae8d0d04176da21eb7f4c4cd6ce24207c37 ../api/bertyprotocol.proto 5ab0b787232df7924763ee81368185385bdf340d ../api/chatmodel.proto -961a4952e56eb176d8239981794e0bff5ebe9238 ../api/entity.proto +66a1baee88ad13dbab569a449235046ab061b5de ../api/entity.proto bb0d4bdd5e638b97f5dd350eb3505645de48eda5 ../api/internal/bar.proto -ae05d50ce77bd7f8d80555112b6ebf3a77053992 ../api/internal/crypto_sigchain.proto -8415f8071ae068eb5cb4c31adcd1a6513473588f ../api/internal/crypto_sigchain_entry.proto 85030963b9dd2a9e133da98c6d6dbc1ce73993b0 ../api/internal/foo.proto +e63e8e917c3ea5559a2f55629d1b633415920d21 ../api/internal/handshake.proto 2d16fa7cd2c7dd30a9480df3d1aac433c120ce32 ../api/protocolmodel.proto 9b18781a092873f9e0fdd4841e02ce692e08191d Makefile diff --git a/go/go.mod b/go/go.mod index e9c21f909e..292c4600f4 100644 --- a/go/go.mod +++ b/go/go.mod @@ -19,7 +19,6 @@ require ( github.com/peterbourgon/ff v1.6.0 github.com/pkg/errors v0.8.1 github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect - github.com/stretchr/testify v1.3.0 go.uber.org/multierr v1.2.0 // indirect go.uber.org/zap v1.10.0 golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 diff --git a/go/go.sum b/go/go.sum index 87a4197f31..166aa5dec7 100644 --- a/go/go.sum +++ b/go/go.sum @@ -33,13 +33,14 @@ github.com/bifurcation/mint v0.0.0-20181105073638-824af6541065/go.mod h1:zVt7zX3 github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bren2010/proquint v0.0.0-20160323162903-38337c27106d h1:QgeLLoPD3kRVmeu/1al9iIpIANMi9O1zXFm8BnYGCJg= github.com/bren2010/proquint v0.0.0-20160323162903-38337c27106d/go.mod h1:Jbj8eKecMNwf0KFI75skSUZqMB4UCRcndUScVBTWyUI= +github.com/brianvoe/gofakeit v3.18.0+incompatible h1:wDOmHc9DLG4nRjUVVaxA+CEglKOW72Y5+4WNxUIkjM8= +github.com/brianvoe/gofakeit v3.18.0+incompatible/go.mod h1:kfwdRA90vvNhPutZWfH7WPaDzUjz+CZFqG+rPkOjGOc= github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= github.com/btcsuite/btcd v0.0.0-20190427004231-96897255fd17 h1:m0N5Vg5nP3zEz8TREZpwX3gt4Biw3/8fbIf4A3hO96g= github.com/btcsuite/btcd v0.0.0-20190427004231-96897255fd17/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0= github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= -github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= @@ -52,9 +53,6 @@ github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QH github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= -github.com/brianvoe/gofakeit v3.18.0+incompatible h1:wDOmHc9DLG4nRjUVVaxA+CEglKOW72Y5+4WNxUIkjM8= -github.com/brianvoe/gofakeit v3.18.0+incompatible/go.mod h1:kfwdRA90vvNhPutZWfH7WPaDzUjz+CZFqG+rPkOjGOc= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= @@ -62,7 +60,6 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-semver v0.2.1-0.20180108230905-e214231b295a/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cskr/pubsub v1.0.2 h1:vlOzMhl6PFn60gRlTQQsIfVwaPB/B/8MziK8FhEPt/0= github.com/cskr/pubsub v1.0.2/go.mod h1:/8MzYXk/NJAz782G8RPkFzXTZVu63VotefPnR9TIRis= @@ -175,8 +172,6 @@ github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gxed/go-shellwords v1.0.3/go.mod h1:N7paucT91ByIjmVJHhvoarjoQnmsi3Jd3vH7VqgtMxQ= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= -github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= -github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= github.com/gxed/pubsub v0.0.0-20180201040156-26ebdf44f824/go.mod h1:OiEWyHgK+CWrmOlVquHaIK1vhpUJydC9m0Je6mhaiNE= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= @@ -314,7 +309,6 @@ github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+ github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs= github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= -github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jbenet/go-is-domain v1.0.2 h1:11r5MSptcNFZyBoqubBQnVMUKRWLuRjL1banaIk+iYo= @@ -326,8 +320,6 @@ github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2/go.mod github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY= github.com/jbenet/goprocess v0.1.3 h1:YKyIEECS/XvcfHtBzxtjBBbWK+MbvA6dG8ASiqwvr10= github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= -github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= -github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jinzhu/gorm v1.9.2/go.mod h1:Vla75njaFJ8clLU1W44h34PjIkijhjHIYnZxMqCdxqo= @@ -360,8 +352,6 @@ github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b/go.mod h1:5Ky9EC2xfo github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -371,7 +361,6 @@ github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/libp2p/go-addr-util v0.0.1 h1:TpTQm9cXVRVSKsYbgQ7GKc3KbbHVTnbostgGaDEP+88= github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ= github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ= -github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ= github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOSqcmlfs= github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= github.com/libp2p/go-conn-security v0.0.1 h1:4kMMrqrt9EUNCNjX1xagSJC+bq16uqjMe9lk1KBMVNs= @@ -381,7 +370,6 @@ github.com/libp2p/go-conn-security-multistream v0.0.2 h1:Ykz0lnNjxk+0SdslUmlLNyr github.com/libp2p/go-conn-security-multistream v0.0.2/go.mod h1:nc9vud7inQ+d6SO0I/6dSWrdMnHnzZNHeyUQqrAJulE= github.com/libp2p/go-flow-metrics v0.0.1 h1:0gxuFd2GuK7IIP5pKljLwps6TvcuYgvG7Atqi3INF5s= github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= -github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= github.com/libp2p/go-libp2p v0.0.2/go.mod h1:Qu8bWqFXiocPloabFGUcVG4kk94fLvfC8mWTDdFC9wE= github.com/libp2p/go-libp2p v0.0.27/go.mod h1:kjeVlESxQisK2DvyKp38/UMHYd9gAMTj3C3XOB/DEZo= github.com/libp2p/go-libp2p v0.0.28 h1:tkDnM7iwrz9OSRRb8YAV4HYjv8TKsAxyxrV2sES9/Aw= @@ -543,7 +531,6 @@ github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN github.com/marten-seemann/qtls v0.2.3 h1:0yWJ43C62LsZt08vuQJDK1uC1czUc3FJeCLPoNAI4vA= github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -562,11 +549,8 @@ github.com/miekg/dns v1.1.4/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nr github.com/miekg/dns v1.1.12 h1:WMhc1ik4LNkTg8U9l3hI1LvxKmIL+f1+WV/SZtCbDDA= github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= -github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= -github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= -github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5 h1:l16XLUUJ34wIz+RIvLhSwGvLvKyy+W598b135bJN6mg= github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= @@ -577,20 +561,15 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= -github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mozilla/tls-observatory v0.0.0-20180409132520-8791a200eb40/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= -github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= -github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= -github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI= github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= -github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= github.com/multiformats/go-multiaddr v0.0.1/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= github.com/multiformats/go-multiaddr v0.0.2/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= github.com/multiformats/go-multiaddr v0.0.4 h1:WgMSI84/eRLdbptXMkMWDXPjPq7SPLIgGUVm2eroyU4= @@ -605,11 +584,9 @@ github.com/multiformats/go-multiaddr-net v0.0.1 h1:76O59E3FavvHqNg7jvzWzsPSW5JSi github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d1tnvM7ihcFwHMSstNAVUU= github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmrJR+ubhT9qA= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= -github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multicodec v0.1.6 h1:4u6lcjbE4VVVoigU4QJSSVYsGVP4j2jtDkR8lPwOrLE= github.com/multiformats/go-multicodec v0.1.6/go.mod h1:lliaRHbcG8q33yf4Ot9BGD7JqR/Za9HE7HTyVyKwrUQ= github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= -github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= github.com/multiformats/go-multihash v0.0.5 h1:1wxmCvTXAifAepIMyF39vZinRw5sbqjPs/UIi93+uik= github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po= github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg= @@ -680,21 +657,15 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2RVY1rIf+2J2o/IM9+vPq9RzmHDSseB7FoXiSNIUsoU= github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8= -github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8= -github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY= github.com/sourcegraph/go-diff v0.5.1/go.mod h1:j2dHj3m8aZgQO8lMTcTnBcXkRRRqi34cd2MNlA9u1mE= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a h1:/eS3yfGjQKG+9kayBkj0ip1BGhq6zJ3eaVksphxAaek= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= -github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= -github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= -github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= -github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.0/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= @@ -756,7 +727,6 @@ github.com/whyrusleeping/yamux v1.2.0/go.mod h1:Cgw3gpb4DrDZ1FrP/5pxg/cpiY54Gr5u github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= -go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.21.0 h1:mU6zScU4U1YAFPHEHYk+3JC4SY7JxgkqS10ZOSyksNg= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.1 h1:8dP3SGL7MPB94crU3bEPplMPe83FI4EouesJUeFHv50= @@ -778,15 +748,11 @@ go4.org v0.0.0-20190218023631-ce4c26f7be8e/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1 go4.org v0.0.0-20190313082347-94abd6928b1d h1:JkRdGP3zvTtTbabWSAC6n67ka30y7gOzWAah4XYJSfw= go4.org v0.0.0-20190313082347-94abd6928b1d/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180426230345-b49d69b5da94/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -820,7 +786,6 @@ golang.org/x/net v0.0.0-20190310074541-c10a0554eabf/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522135303-fa69b94a3b58/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -848,12 +813,10 @@ golang.org/x/sys v0.0.0-20190302025703-b6889370fb10/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190310054646-10058d7d4faa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190522044717-8097e1b27ff5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 h1:rOhMmluY6kLMhdnrivzec6lLgaVbMHMn2ISQXJeJ5EM= golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.0.0-20170915090833-1cbadb444a80/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -868,7 +831,6 @@ golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181024171208-a2dc47679d30/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181117154741-2ddaf7f79a09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181130052023-1c3d964395ce/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181205014116-22934f0fdb62/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/go/internal/crypto/crypto_module.go b/go/internal/crypto/crypto_module.go index a9ce0b67cb..09e4bd83e4 100644 --- a/go/internal/crypto/crypto_module.go +++ b/go/internal/crypto/crypto_module.go @@ -9,7 +9,7 @@ import ( "errors" "time" - sigchain "berty.tech/go/internal/cryptosigchain" + "berty.tech/go/pkg/bertyprotocol" "berty.tech/go/pkg/iface" sign "github.com/libp2p/go-libp2p-core/crypto" ) @@ -47,7 +47,7 @@ func InitSigChain(key sign.PrivKey) (iface.SigChain, error) { return nil, err } - sigChain := sigchain.NewSigChain() + sigChain := bertyprotocol.NewSigChain() _, err = sigChain.Init(accountKey) if err != nil { diff --git a/go/internal/cryptosigchain/crypto_sigchain.pb.go b/go/internal/cryptosigchain/crypto_sigchain.pb.go deleted file mode 100644 index f44528ccb1..0000000000 --- a/go/internal/cryptosigchain/crypto_sigchain.pb.go +++ /dev/null @@ -1,413 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: internal/crypto_sigchain.proto - -package cryptosigchain - -import ( - fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -type SigChain struct { - ID []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Entries []*SigChainEntry `protobuf:"bytes,2,rep,name=entries,proto3" json:"entries,omitempty"` -} - -func (m *SigChain) Reset() { *m = SigChain{} } -func (m *SigChain) String() string { return proto.CompactTextString(m) } -func (*SigChain) ProtoMessage() {} -func (*SigChain) Descriptor() ([]byte, []int) { - return fileDescriptor_c084a4931fd44deb, []int{0} -} -func (m *SigChain) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SigChain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SigChain.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *SigChain) XXX_Merge(src proto.Message) { - xxx_messageInfo_SigChain.Merge(m, src) -} -func (m *SigChain) XXX_Size() int { - return m.Size() -} -func (m *SigChain) XXX_DiscardUnknown() { - xxx_messageInfo_SigChain.DiscardUnknown(m) -} - -var xxx_messageInfo_SigChain proto.InternalMessageInfo - -func (m *SigChain) GetID() []byte { - if m != nil { - return m.ID - } - return nil -} - -func (m *SigChain) GetEntries() []*SigChainEntry { - if m != nil { - return m.Entries - } - return nil -} - -func init() { - proto.RegisterType((*SigChain)(nil), "sigchain.SigChain") -} - -func init() { proto.RegisterFile("internal/crypto_sigchain.proto", fileDescriptor_c084a4931fd44deb) } - -var fileDescriptor_c084a4931fd44deb = []byte{ - // 218 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcb, 0xcc, 0x2b, 0x49, - 0x2d, 0xca, 0x4b, 0xcc, 0xd1, 0x4f, 0x2e, 0xaa, 0x2c, 0x28, 0xc9, 0x8f, 0x2f, 0xce, 0x4c, 0x4f, - 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x80, 0xf1, 0xa5, 0x54, - 0x70, 0xa9, 0x8c, 0x4f, 0xcd, 0x2b, 0x29, 0xaa, 0x84, 0xa8, 0x97, 0xd2, 0x4d, 0xcf, 0x2c, 0xc9, - 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0x4f, 0xcf, 0xd7, 0x07, 0x0b, 0x27, 0x95, - 0xa6, 0x81, 0x79, 0x60, 0x0e, 0x98, 0x05, 0x51, 0xae, 0x14, 0xca, 0xc5, 0x11, 0x9c, 0x99, 0xee, - 0x0c, 0x32, 0x46, 0x48, 0x8c, 0x8b, 0x29, 0x33, 0x45, 0x82, 0x51, 0x81, 0x51, 0x83, 0xc7, 0x89, - 0xed, 0xd1, 0x3d, 0x79, 0x26, 0x4f, 0x97, 0x20, 0xa6, 0xcc, 0x14, 0x21, 0x43, 0x2e, 0x76, 0x90, - 0x0d, 0x99, 0xa9, 0xc5, 0x12, 0x4c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0xe2, 0x7a, 0x70, 0x47, 0xc2, - 0x34, 0xbb, 0x82, 0x9c, 0x10, 0x04, 0x53, 0xe7, 0x64, 0x7f, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, - 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, - 0xc7, 0x72, 0x0c, 0x51, 0xaa, 0x49, 0xa9, 0x45, 0x25, 0x95, 0x7a, 0x25, 0xa9, 0xc9, 0x19, 0xfa, - 0xe9, 0xf9, 0xfa, 0x68, 0x7e, 0x82, 0x99, 0x9b, 0xc4, 0x06, 0x76, 0x9e, 0x31, 0x20, 0x00, 0x00, - 0xff, 0xff, 0x80, 0x11, 0x6d, 0x9e, 0x1f, 0x01, 0x00, 0x00, -} - -func (m *SigChain) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SigChain) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SigChain) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Entries) > 0 { - for iNdEx := len(m.Entries) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Entries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCryptoSigchain(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - if len(m.ID) > 0 { - i -= len(m.ID) - copy(dAtA[i:], m.ID) - i = encodeVarintCryptoSigchain(dAtA, i, uint64(len(m.ID))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintCryptoSigchain(dAtA []byte, offset int, v uint64) int { - offset -= sovCryptoSigchain(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *SigChain) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ID) - if l > 0 { - n += 1 + l + sovCryptoSigchain(uint64(l)) - } - if len(m.Entries) > 0 { - for _, e := range m.Entries { - l = e.Size() - n += 1 + l + sovCryptoSigchain(uint64(l)) - } - } - return n -} - -func sovCryptoSigchain(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozCryptoSigchain(x uint64) (n int) { - return sovCryptoSigchain(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *SigChain) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchain - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SigChain: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SigChain: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchain - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthCryptoSigchain - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthCryptoSigchain - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ID = append(m.ID[:0], dAtA[iNdEx:postIndex]...) - if m.ID == nil { - m.ID = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Entries", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchain - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCryptoSigchain - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCryptoSigchain - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Entries = append(m.Entries, &SigChainEntry{}) - if err := m.Entries[len(m.Entries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCryptoSigchain(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthCryptoSigchain - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthCryptoSigchain - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipCryptoSigchain(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowCryptoSigchain - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowCryptoSigchain - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowCryptoSigchain - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthCryptoSigchain - } - iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthCryptoSigchain - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowCryptoSigchain - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipCryptoSigchain(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthCryptoSigchain - } - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthCryptoSigchain = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowCryptoSigchain = fmt.Errorf("proto: integer overflow") -) diff --git a/go/internal/cryptosigchain/crypto_sigchain_entry.pb.go b/go/internal/cryptosigchain/crypto_sigchain_entry.pb.go deleted file mode 100644 index cd3dff337a..0000000000 --- a/go/internal/cryptosigchain/crypto_sigchain_entry.pb.go +++ /dev/null @@ -1,753 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: internal/crypto_sigchain_entry.proto - -package cryptosigchain - -import ( - fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - time "time" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "github.com/golang/protobuf/ptypes/timestamp" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf -var _ = time.Kitchen - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -type SigChainEntry_SigChainEntryType int32 - -const ( - SigChainEntry_SigChainEntryTypeUndefined SigChainEntry_SigChainEntryType = 0 - SigChainEntry_SigChainEntryTypeInitChain SigChainEntry_SigChainEntryType = 1 - SigChainEntry_SigChainEntryTypeAddKey SigChainEntry_SigChainEntryType = 2 - SigChainEntry_SigChainEntryTypeRemoveKey SigChainEntry_SigChainEntryType = 3 -) - -var SigChainEntry_SigChainEntryType_name = map[int32]string{ - 0: "SigChainEntryTypeUndefined", - 1: "SigChainEntryTypeInitChain", - 2: "SigChainEntryTypeAddKey", - 3: "SigChainEntryTypeRemoveKey", -} - -var SigChainEntry_SigChainEntryType_value = map[string]int32{ - "SigChainEntryTypeUndefined": 0, - "SigChainEntryTypeInitChain": 1, - "SigChainEntryTypeAddKey": 2, - "SigChainEntryTypeRemoveKey": 3, -} - -func (x SigChainEntry_SigChainEntryType) String() string { - return proto.EnumName(SigChainEntry_SigChainEntryType_name, int32(x)) -} - -func (SigChainEntry_SigChainEntryType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_10e430be580c9ede, []int{0, 0} -} - -type SigChainEntry struct { - EntryHash []byte `protobuf:"bytes,1,opt,name=entry_hash,json=entryHash,proto3" json:"entry_hash,omitempty"` - EntryTypeCode SigChainEntry_SigChainEntryType `protobuf:"varint,2,opt,name=entry_type_code,json=entryTypeCode,proto3,enum=sigchain.SigChainEntry_SigChainEntryType" json:"entry_type_code,omitempty"` - ParentEntryHash []byte `protobuf:"bytes,3,opt,name=parent_entry_hash,json=parentEntryHash,proto3" json:"parent_entry_hash,omitempty"` - CreatedAt time.Time `protobuf:"bytes,4,opt,name=created_at,json=createdAt,proto3,stdtime" json:"created_at"` - ExpiringAt time.Time `protobuf:"bytes,5,opt,name=expiring_at,json=expiringAt,proto3,stdtime" json:"expiring_at"` - SignerPublicKeyBytes []byte `protobuf:"bytes,6,opt,name=signer_public_key_bytes,json=signerPublicKeyBytes,proto3" json:"signer_public_key_bytes,omitempty"` - SubjectPublicKeyBytes []byte `protobuf:"bytes,7,opt,name=subject_public_key_bytes,json=subjectPublicKeyBytes,proto3" json:"subject_public_key_bytes,omitempty"` - Signature []byte `protobuf:"bytes,8,opt,name=signature,proto3" json:"signature,omitempty"` -} - -func (m *SigChainEntry) Reset() { *m = SigChainEntry{} } -func (m *SigChainEntry) String() string { return proto.CompactTextString(m) } -func (*SigChainEntry) ProtoMessage() {} -func (*SigChainEntry) Descriptor() ([]byte, []int) { - return fileDescriptor_10e430be580c9ede, []int{0} -} -func (m *SigChainEntry) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SigChainEntry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SigChainEntry.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *SigChainEntry) XXX_Merge(src proto.Message) { - xxx_messageInfo_SigChainEntry.Merge(m, src) -} -func (m *SigChainEntry) XXX_Size() int { - return m.Size() -} -func (m *SigChainEntry) XXX_DiscardUnknown() { - xxx_messageInfo_SigChainEntry.DiscardUnknown(m) -} - -var xxx_messageInfo_SigChainEntry proto.InternalMessageInfo - -func (m *SigChainEntry) GetEntryHash() []byte { - if m != nil { - return m.EntryHash - } - return nil -} - -func (m *SigChainEntry) GetEntryTypeCode() SigChainEntry_SigChainEntryType { - if m != nil { - return m.EntryTypeCode - } - return SigChainEntry_SigChainEntryTypeUndefined -} - -func (m *SigChainEntry) GetParentEntryHash() []byte { - if m != nil { - return m.ParentEntryHash - } - return nil -} - -func (m *SigChainEntry) GetCreatedAt() time.Time { - if m != nil { - return m.CreatedAt - } - return time.Time{} -} - -func (m *SigChainEntry) GetExpiringAt() time.Time { - if m != nil { - return m.ExpiringAt - } - return time.Time{} -} - -func (m *SigChainEntry) GetSignerPublicKeyBytes() []byte { - if m != nil { - return m.SignerPublicKeyBytes - } - return nil -} - -func (m *SigChainEntry) GetSubjectPublicKeyBytes() []byte { - if m != nil { - return m.SubjectPublicKeyBytes - } - return nil -} - -func (m *SigChainEntry) GetSignature() []byte { - if m != nil { - return m.Signature - } - return nil -} - -func init() { - proto.RegisterEnum("sigchain.SigChainEntry_SigChainEntryType", SigChainEntry_SigChainEntryType_name, SigChainEntry_SigChainEntryType_value) - proto.RegisterType((*SigChainEntry)(nil), "sigchain.SigChainEntry") -} - -func init() { - proto.RegisterFile("internal/crypto_sigchain_entry.proto", fileDescriptor_10e430be580c9ede) -} - -var fileDescriptor_10e430be580c9ede = []byte{ - // 461 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0xf5, 0xb6, 0xa5, 0x24, 0x5b, 0x4a, 0x53, 0x0b, 0x54, 0x2b, 0x80, 0x13, 0x55, 0x20, 0x05, - 0x24, 0x6c, 0xa9, 0x08, 0x71, 0x44, 0x49, 0x14, 0x09, 0xd4, 0x0b, 0x84, 0x72, 0xe1, 0x62, 0xad, - 0xed, 0xe9, 0x7a, 0x21, 0xd9, 0xb5, 0xd6, 0x63, 0xc4, 0xfe, 0x45, 0x3e, 0xab, 0xc7, 0x1e, 0x11, - 0x07, 0x40, 0xc9, 0x8f, 0x20, 0xaf, 0xeb, 0x42, 0x9b, 0x5e, 0xb8, 0xed, 0xbc, 0x37, 0xef, 0xbd, - 0xf5, 0x8c, 0x97, 0x3e, 0x16, 0x12, 0x41, 0x4b, 0x36, 0x0b, 0x13, 0x6d, 0x72, 0x54, 0x51, 0x21, - 0x78, 0x92, 0x31, 0x21, 0x23, 0x90, 0xa8, 0x4d, 0x90, 0x6b, 0x85, 0xca, 0x6d, 0x35, 0x68, 0xb7, - 0xc7, 0x95, 0xe2, 0x33, 0x08, 0x2d, 0x1e, 0x97, 0xa7, 0x21, 0x8a, 0x39, 0x14, 0xc8, 0xe6, 0x79, - 0xdd, 0xda, 0x7d, 0xce, 0x05, 0x66, 0x65, 0x1c, 0x24, 0x6a, 0x1e, 0x72, 0xc5, 0xd5, 0xdf, 0xce, - 0xaa, 0xb2, 0x85, 0x3d, 0xd5, 0xed, 0x87, 0x3f, 0xb6, 0xe8, 0xee, 0x07, 0xc1, 0xc7, 0x95, 0xf9, - 0xa4, 0x4a, 0x74, 0x1f, 0x51, 0x6a, 0xa3, 0xa3, 0x8c, 0x15, 0x99, 0x47, 0xfa, 0x64, 0x70, 0x67, - 0xda, 0xb6, 0xc8, 0x1b, 0x56, 0x64, 0xee, 0x7b, 0xba, 0x57, 0xd3, 0x68, 0x72, 0x88, 0x12, 0x95, - 0x82, 0xb7, 0xd1, 0x27, 0x83, 0xbb, 0x47, 0x4f, 0x83, 0xe6, 0x92, 0xc1, 0x15, 0xc3, 0xab, 0xd5, - 0x89, 0xc9, 0x61, 0xba, 0x0b, 0xcd, 0x71, 0xac, 0x52, 0x70, 0x9f, 0xd1, 0xfd, 0x9c, 0x69, 0x90, - 0x18, 0xfd, 0x13, 0xbc, 0x69, 0x83, 0xf7, 0x6a, 0x62, 0x72, 0x19, 0x3f, 0xa6, 0x34, 0xd1, 0xc0, - 0x10, 0xd2, 0x88, 0xa1, 0xb7, 0xd5, 0x27, 0x83, 0x9d, 0xa3, 0x6e, 0x50, 0x0f, 0x25, 0x68, 0x3e, - 0x35, 0x38, 0x69, 0x86, 0x32, 0x6a, 0x9d, 0xfd, 0xec, 0x39, 0x8b, 0x5f, 0x3d, 0x32, 0x6d, 0x5f, - 0xe8, 0x86, 0xe8, 0x4e, 0xe8, 0x0e, 0x7c, 0xcb, 0x85, 0x16, 0x92, 0x57, 0x2e, 0xb7, 0xfe, 0xc3, - 0x85, 0x36, 0xc2, 0x21, 0xba, 0x2f, 0xe9, 0x41, 0x21, 0xb8, 0x04, 0x1d, 0xe5, 0x65, 0x3c, 0x13, - 0x49, 0xf4, 0x05, 0x4c, 0x14, 0x1b, 0x84, 0xc2, 0xdb, 0xb6, 0xb7, 0xbf, 0x57, 0xd3, 0xef, 0x2c, - 0x7b, 0x0c, 0x66, 0x54, 0x71, 0xee, 0x2b, 0xea, 0x15, 0x65, 0xfc, 0x19, 0x12, 0x5c, 0xd7, 0xdd, - 0xb6, 0xba, 0xfb, 0x17, 0xfc, 0x35, 0xe1, 0x43, 0xda, 0xae, 0x0c, 0x19, 0x96, 0x1a, 0xbc, 0x56, - 0xbd, 0x98, 0x4b, 0xe0, 0x70, 0x41, 0xe8, 0xfe, 0xda, 0xa8, 0x5d, 0x9f, 0x76, 0xd7, 0xc0, 0x8f, - 0x32, 0x85, 0x53, 0x21, 0x21, 0xed, 0x38, 0x37, 0xf2, 0x6f, 0xa5, 0x40, 0x8b, 0x74, 0x88, 0xfb, - 0x80, 0x1e, 0xac, 0xf1, 0xc3, 0x34, 0x3d, 0x06, 0xd3, 0xd9, 0xb8, 0x51, 0x3c, 0x85, 0xb9, 0xfa, - 0x0a, 0x15, 0xbf, 0x39, 0x7a, 0x7d, 0xb6, 0xf4, 0xc9, 0xf9, 0xd2, 0x27, 0xbf, 0x97, 0x3e, 0x59, - 0xac, 0x7c, 0xe7, 0x7c, 0xe5, 0x3b, 0xdf, 0x57, 0xbe, 0xf3, 0xe9, 0x49, 0x0c, 0x1a, 0x4d, 0x80, - 0x90, 0x64, 0x21, 0x57, 0xe1, 0xb5, 0x47, 0xd0, 0xfc, 0x48, 0xf1, 0xb6, 0xdd, 0xc5, 0x8b, 0x3f, - 0x01, 0x00, 0x00, 0xff, 0xff, 0x6c, 0xc4, 0x5e, 0x91, 0x26, 0x03, 0x00, 0x00, -} - -func (m *SigChainEntry) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SigChainEntry) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SigChainEntry) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Signature) > 0 { - i -= len(m.Signature) - copy(dAtA[i:], m.Signature) - i = encodeVarintCryptoSigchainEntry(dAtA, i, uint64(len(m.Signature))) - i-- - dAtA[i] = 0x42 - } - if len(m.SubjectPublicKeyBytes) > 0 { - i -= len(m.SubjectPublicKeyBytes) - copy(dAtA[i:], m.SubjectPublicKeyBytes) - i = encodeVarintCryptoSigchainEntry(dAtA, i, uint64(len(m.SubjectPublicKeyBytes))) - i-- - dAtA[i] = 0x3a - } - if len(m.SignerPublicKeyBytes) > 0 { - i -= len(m.SignerPublicKeyBytes) - copy(dAtA[i:], m.SignerPublicKeyBytes) - i = encodeVarintCryptoSigchainEntry(dAtA, i, uint64(len(m.SignerPublicKeyBytes))) - i-- - dAtA[i] = 0x32 - } - n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.ExpiringAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.ExpiringAt):]) - if err1 != nil { - return 0, err1 - } - i -= n1 - i = encodeVarintCryptoSigchainEntry(dAtA, i, uint64(n1)) - i-- - dAtA[i] = 0x2a - n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.CreatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt):]) - if err2 != nil { - return 0, err2 - } - i -= n2 - i = encodeVarintCryptoSigchainEntry(dAtA, i, uint64(n2)) - i-- - dAtA[i] = 0x22 - if len(m.ParentEntryHash) > 0 { - i -= len(m.ParentEntryHash) - copy(dAtA[i:], m.ParentEntryHash) - i = encodeVarintCryptoSigchainEntry(dAtA, i, uint64(len(m.ParentEntryHash))) - i-- - dAtA[i] = 0x1a - } - if m.EntryTypeCode != 0 { - i = encodeVarintCryptoSigchainEntry(dAtA, i, uint64(m.EntryTypeCode)) - i-- - dAtA[i] = 0x10 - } - if len(m.EntryHash) > 0 { - i -= len(m.EntryHash) - copy(dAtA[i:], m.EntryHash) - i = encodeVarintCryptoSigchainEntry(dAtA, i, uint64(len(m.EntryHash))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintCryptoSigchainEntry(dAtA []byte, offset int, v uint64) int { - offset -= sovCryptoSigchainEntry(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *SigChainEntry) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.EntryHash) - if l > 0 { - n += 1 + l + sovCryptoSigchainEntry(uint64(l)) - } - if m.EntryTypeCode != 0 { - n += 1 + sovCryptoSigchainEntry(uint64(m.EntryTypeCode)) - } - l = len(m.ParentEntryHash) - if l > 0 { - n += 1 + l + sovCryptoSigchainEntry(uint64(l)) - } - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt) - n += 1 + l + sovCryptoSigchainEntry(uint64(l)) - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.ExpiringAt) - n += 1 + l + sovCryptoSigchainEntry(uint64(l)) - l = len(m.SignerPublicKeyBytes) - if l > 0 { - n += 1 + l + sovCryptoSigchainEntry(uint64(l)) - } - l = len(m.SubjectPublicKeyBytes) - if l > 0 { - n += 1 + l + sovCryptoSigchainEntry(uint64(l)) - } - l = len(m.Signature) - if l > 0 { - n += 1 + l + sovCryptoSigchainEntry(uint64(l)) - } - return n -} - -func sovCryptoSigchainEntry(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozCryptoSigchainEntry(x uint64) (n int) { - return sovCryptoSigchainEntry(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *SigChainEntry) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SigChainEntry: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SigChainEntry: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EntryHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.EntryHash = append(m.EntryHash[:0], dAtA[iNdEx:postIndex]...) - if m.EntryHash == nil { - m.EntryHash = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EntryTypeCode", wireType) - } - m.EntryTypeCode = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.EntryTypeCode |= SigChainEntry_SigChainEntryType(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ParentEntryHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ParentEntryHash = append(m.ParentEntryHash[:0], dAtA[iNdEx:postIndex]...) - if m.ParentEntryHash == nil { - m.ParentEntryHash = []byte{} - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CreatedAt", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.CreatedAt, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ExpiringAt", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.ExpiringAt, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SignerPublicKeyBytes", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SignerPublicKeyBytes = append(m.SignerPublicKeyBytes[:0], dAtA[iNdEx:postIndex]...) - if m.SignerPublicKeyBytes == nil { - m.SignerPublicKeyBytes = []byte{} - } - iNdEx = postIndex - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SubjectPublicKeyBytes", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SubjectPublicKeyBytes = append(m.SubjectPublicKeyBytes[:0], dAtA[iNdEx:postIndex]...) - if m.SubjectPublicKeyBytes == nil { - m.SubjectPublicKeyBytes = []byte{} - } - iNdEx = postIndex - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) - if m.Signature == nil { - m.Signature = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCryptoSigchainEntry(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthCryptoSigchainEntry - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipCryptoSigchainEntry(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthCryptoSigchainEntry - } - iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthCryptoSigchainEntry - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowCryptoSigchainEntry - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipCryptoSigchainEntry(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthCryptoSigchainEntry - } - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthCryptoSigchainEntry = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowCryptoSigchainEntry = fmt.Errorf("proto: integer overflow") -) diff --git a/go/internal/cryptohandshake/handshake_module.go b/go/internal/handshake/crypto_module.go similarity index 68% rename from go/internal/cryptohandshake/handshake_module.go rename to go/internal/handshake/crypto_module.go index 23dfc47dae..a0880754fd 100644 --- a/go/internal/cryptohandshake/handshake_module.go +++ b/go/internal/handshake/crypto_module.go @@ -1,4 +1,4 @@ -package cryptohandshake +package handshake import ( "crypto/rand" @@ -58,7 +58,7 @@ func initHandshake(ownDevicePrivateKey sign.PrivKey, ownSigChain iface.SigChain) }, nil } -func NewRequest(ownDevicePrivateKey crypto.PrivKey, ownSigChain iface.SigChain, accountToReach crypto.PubKey) (iface.HandshakeSession, error) { +func newCryptoRequest(ownDevicePrivateKey crypto.PrivKey, ownSigChain iface.SigChain, accountToReach crypto.PubKey) (*handshakeSession, error) { session, err := initHandshake(ownDevicePrivateKey, ownSigChain) if err != nil { return nil, err @@ -69,26 +69,11 @@ func NewRequest(ownDevicePrivateKey crypto.PrivKey, ownSigChain iface.SigChain, return session, nil } -func NewResponse(ownDevicePrivateKey crypto.PrivKey, ownSigChain iface.SigChain, marshaledSigKey []byte, boxKey []byte) (iface.HandshakeSession, error) { - // TODO: include cipher suite to allow protocol updates? - sigKey, err := sign.UnmarshalPublicKey(marshaledSigKey) - if err != nil { - return nil, err - } - - if sigKey.Type() != SupportedKeyType { - return nil, errors.New("unsupported key type") - } - +func newCryptoResponse(ownDevicePrivateKey crypto.PrivKey, ownSigChain iface.SigChain) (*handshakeSession, error) { session, err := initHandshake(ownDevicePrivateKey, ownSigChain) if err != nil { return nil, err } - err = session.SetOtherKeys(sigKey, boxKey) - if err != nil { - return nil, err - } - return session, nil } diff --git a/go/internal/cryptohandshake/handshake_session.go b/go/internal/handshake/crypto_session.go similarity index 86% rename from go/internal/cryptohandshake/handshake_session.go rename to go/internal/handshake/crypto_session.go index ab19ef9062..0784ae62cf 100644 --- a/go/internal/cryptohandshake/handshake_session.go +++ b/go/internal/handshake/crypto_session.go @@ -1,8 +1,7 @@ -package cryptohandshake +package handshake import ( "encoding/binary" - "errors" "github.com/libp2p/go-libp2p-core/crypto" @@ -31,7 +30,7 @@ func (h *handshakeSession) SetOtherKeys(sign crypto.PubKey, box []byte) error { } if sign.Type() != SupportedKeyType { - return errors.New("invalid key type") + return ErrInvalidKeyType } h.otherSigningPublicKey = sign @@ -48,13 +47,9 @@ func (h *handshakeSession) GetPublicKeys() (sign crypto.PubKey, box []byte) { return h.selfSigningPrivateKey.GetPublic(), b32Slice(h.selfBoxPublicKey) } -//func (h *handshakeSession) Crypto() iface.Crypto { -// return h.crypto -//} - func computeValueToProvePubKey(keyToProve crypto.PubKey, receiverSigKey *[32]byte) ([]byte, error) { if keyToProve == nil || receiverSigKey == nil { - return nil, errors.New("missing a key") + return nil, ErrParams } keyToProveBytes, err := keyToProve.Raw() @@ -69,7 +64,7 @@ func computeValueToProvePubKey(keyToProve crypto.PubKey, receiverSigKey *[32]byt func computeValueToProveDevicePubKeyAndSigChain(keyToProve *[32]byte, chain iface.SigChain) ([]byte, error) { if keyToProve == nil || chain == nil { - return nil, errors.New("missing a key or sig chain") + return nil, ErrParams } sigChainBytes, err := chain.Marshal() @@ -85,7 +80,7 @@ func computeValueToProveDevicePubKeyAndSigChain(keyToProve *[32]byte, chain ifac func (h *handshakeSession) ProveOtherKey() ([]byte, error) { // Step 3a (out) : sig_a1(B·b1) if h.accountKeyToProve == nil { - return nil, errors.New("missing a key to prove") + return nil, ErrSessionInvalid } signedValue, err := computeValueToProvePubKey(h.accountKeyToProve, h.otherBoxPublicKey) @@ -125,7 +120,7 @@ func (h *handshakeSession) CheckOwnKeyProof(sig []byte) error { } if !ok { - return errors.New("signature is not valid") + return ErrInvalidSignature } return nil @@ -160,7 +155,7 @@ func (h *handshakeSession) CheckOtherKeyProof(sig []byte, chain iface.SigChain, } if !ok { - return errors.New("signature is not valid") + return ErrInvalidSignature } entries := chain.ListCurrentPubKeys() @@ -170,7 +165,7 @@ func (h *handshakeSession) CheckOtherKeyProof(sig []byte, chain iface.SigChain, } } - return errors.New("key not found in sig chain") + return ErrKeyNotInSigChain } func (h *handshakeSession) ProveOtherKnownAccount() ([]byte, error) { @@ -201,7 +196,7 @@ func (h *handshakeSession) CheckOwnKnownAccountProof(attemptedDeviceKey crypto.P } if !ok { - return errors.New("signature is not valid") + return ErrInvalidSignature } return nil @@ -209,7 +204,7 @@ func (h *handshakeSession) CheckOwnKnownAccountProof(attemptedDeviceKey crypto.P func (h *handshakeSession) Encrypt(data []byte) ([]byte, error) { if h.otherBoxPublicKey == nil || h.selfBoxPrivateKey == nil { - return nil, errors.New("handshake session has not been properly initialized") + return nil, ErrSessionInvalid } nonce := h.getNonce() @@ -223,14 +218,14 @@ func (h *handshakeSession) Encrypt(data []byte) ([]byte, error) { func (h *handshakeSession) Decrypt(data []byte) ([]byte, error) { if h.otherBoxPublicKey == nil || h.selfBoxPrivateKey == nil { - return nil, errors.New("handshake session has not been properly initialized") + return nil, ErrSessionInvalid } nonce := h.getNonce() out, ok := box.Open(nil, data, &nonce, h.otherBoxPublicKey, h.selfBoxPrivateKey) if !ok { - return nil, errors.New("unable to decrypt data") + return nil, ErrDecrypt } h.incrementNonce() @@ -258,5 +253,3 @@ func (h *handshakeSession) getNonce() [24]byte { func (h *handshakeSession) Close() error { return nil } - -var _ iface.HandshakeSession = (*handshakeSession)(nil) diff --git a/go/internal/cryptohandshake/handshake_test.go b/go/internal/handshake/crypto_test.go similarity index 54% rename from go/internal/cryptohandshake/handshake_test.go rename to go/internal/handshake/crypto_test.go index f75630417f..a932563563 100644 --- a/go/internal/cryptohandshake/handshake_test.go +++ b/go/internal/handshake/crypto_test.go @@ -1,18 +1,14 @@ -package cryptohandshake_test +package handshake import ( "context" "crypto/rand" "testing" - "berty.tech/go/internal/cryptohandshake" - "berty.tech/go/pkg/iface" p2pCrypto "github.com/libp2p/go-libp2p-core/crypto" - "github.com/stretchr/testify/assert" - "berty.tech/go/internal/crypto" ) @@ -21,33 +17,44 @@ func createNewIdentity(t *testing.T, ctx context.Context) (iface.Crypto, p2pCryp ds := &struct{ TODO int }{} c, privateKey, err := crypto.InitNewIdentity(ctx, ds) - assert.Nil(t, err) + if err != nil { + t.Fatalf("can't create new identity") + } return c, privateKey } -func createTwoDevices(t *testing.T, ctx context.Context) (iface.HandshakeSession, iface.Crypto, iface.HandshakeSession, iface.Crypto) { +func createTwoDevices(t *testing.T, ctx context.Context) (*handshakeSession, iface.Crypto, *handshakeSession, iface.Crypto) { c1, pk1 := createNewIdentity(t, ctx) c2, pk2 := createNewIdentity(t, ctx) accountPublicKey, err := c2.GetAccountPublicKey() - assert.Nil(t, err) + if err != nil { + t.Fatalf("can't get public key for account") + } - hss1, err := cryptohandshake.NewRequest(pk1, c1.GetSigChain(), accountPublicKey) - assert.Nil(t, err) - assert.NotNil(t, hss1) + hss1, err := newCryptoRequest(pk1, c1.GetSigChain(), accountPublicKey) + if err != nil || hss1 == nil { + t.Fatalf("can't get crypto request for c1") + } sign, box := hss1.GetPublicKeys() - signBytes, err := sign.Bytes() - assert.Nil(t, err) - hss2, err := cryptohandshake.NewResponse(pk2, c2.GetSigChain(), signBytes, box) - assert.Nil(t, err) - assert.NotNil(t, hss2) + hss2, err := newCryptoResponse(pk2, c2.GetSigChain()) + if err != nil || hss2 == nil { + t.Fatalf("can't get crypto request for c2") + } + + err = hss2.SetOtherKeys(sign, box) + if err != nil { + t.Fatalf("can't set other keys on hss2") + } sign, box = hss2.GetPublicKeys() err = hss1.SetOtherKeys(sign, box) - assert.Nil(t, err) + if err != nil { + t.Fatalf("can't set other keys on hss1") + } return hss1, c1, hss2, c2 } @@ -67,11 +74,14 @@ func TestModule_NewRequest(t *testing.T) { c2, _ := createNewIdentity(t, ctx) accountPubKey, err := c2.GetAccountPublicKey() - assert.Nil(t, err) - - hss, err := cryptohandshake.NewRequest(pk1, c1.GetSigChain(), accountPubKey) - assert.Nil(t, err) - assert.NotNil(t, hss) + if err != nil { + t.Fatalf("can't get account public key for c2") + } + + hss, err := newCryptoRequest(pk1, c1.GetSigChain(), accountPubKey) + if err != nil || hss == nil { + t.Fatalf("can't get initiate crypto handshake request") + } } func TestModule_NewResponse(t *testing.T) { @@ -82,19 +92,26 @@ func TestModule_NewResponse(t *testing.T) { c2, pk2 := createNewIdentity(t, ctx) accountPubKey, err := c2.GetAccountPublicKey() - assert.Nil(t, err) + if err != nil { + t.Fatalf("err should be nil") + } - hss1, err := cryptohandshake.NewRequest(pk1, c1.GetSigChain(), accountPubKey) - assert.Nil(t, err) - assert.NotNil(t, hss1) + hss1, err := newCryptoRequest(pk1, c1.GetSigChain(), accountPubKey) + if err != nil || hss1 == nil { + t.Fatalf("err should be nil") + } sign, box := hss1.GetPublicKeys() - signBytes, err := sign.Bytes() - assert.Nil(t, err) - hss2, err := cryptohandshake.NewResponse(pk2, c2.GetSigChain(), signBytes, box) - assert.Nil(t, err) - assert.NotNil(t, hss2) + hss2, err := newCryptoResponse(pk2, c2.GetSigChain()) + if err != nil || hss2 == nil { + t.Fatalf("err should be nil") + } + + err = hss2.SetOtherKeys(sign, box) + if err != nil { + t.Fatalf("err should be nil") + } } func TestHandshakeSession_SetOtherKeys(t *testing.T) { @@ -104,16 +121,24 @@ func TestHandshakeSession_SetOtherKeys(t *testing.T) { hss1, _, hss2, _ := createTwoDevices(t, ctx) sign, box := hss2.GetPublicKeys() err := hss1.SetOtherKeys(sign, box) - assert.Nil(t, err) + if err != nil { + t.Fatalf("err should be nil") + } err = hss1.SetOtherKeys(sign, box[0:3]) - assert.NotNil(t, err) + if err == nil { + t.Fatalf("err should not be nil") + } _, badSigningPubKey, err := p2pCrypto.GenerateSecp256k1Key(rand.Reader) - assert.Nil(t, err) + if err != nil { + t.Fatalf("err should be nil") + } err = hss1.SetOtherKeys(badSigningPubKey, box) - assert.NotNil(t, err) + if err == nil { + t.Fatalf("err should not be nil") + } } func TestHandshakeSession_GetPublicKeys(t *testing.T) { @@ -123,8 +148,9 @@ func TestHandshakeSession_GetPublicKeys(t *testing.T) { hss1, _, _, _ := createTwoDevices(t, ctx) sign, box := hss1.GetPublicKeys() - assert.Equal(t, int(sign.Type()), cryptohandshake.SupportedKeyType) - assert.Len(t, box, 32) + if int(sign.Type()) != SupportedKeyType || len(box) != 32 { + t.Fatalf("public keys seems improperly returned") + } } func TestHandshakeSession_ProveOtherKey_CheckOwnKeyProof(t *testing.T) { @@ -134,15 +160,21 @@ func TestHandshakeSession_ProveOtherKey_CheckOwnKeyProof(t *testing.T) { hss1, _, hss2, _ := createTwoDevices(t, ctx) proof, err := hss1.ProveOtherKey() - assert.Nil(t, err) + if err != nil { + t.Fatalf("err should be nil") + } err = hss2.CheckOwnKeyProof(proof) - assert.Nil(t, err) + if err != nil { + t.Fatalf("err should be nil") + } err = hss2.CheckOwnKeyProof([]byte("oops")) - assert.NotNil(t, err) + if err == nil { + t.Fatalf("err should not be nil") + } } func TestHandshakeSession_ProveOwnDeviceKey_CheckOtherKeyProof(t *testing.T) { @@ -152,23 +184,33 @@ func TestHandshakeSession_ProveOwnDeviceKey_CheckOtherKeyProof(t *testing.T) { hss1, c1, hss2, c2 := createTwoDevices(t, ctx) proof, err := hss1.ProveOwnDeviceKey() - assert.Nil(t, err) + if err != nil { + t.Fatalf("err should be nil") + } // Correct err = hss2.CheckOtherKeyProof(proof, c1.GetSigChain(), c1.GetDevicePublicKey()) - assert.Nil(t, err) + if err != nil { + t.Fatalf("err should be nil") + } // Wrong signature err = hss2.CheckOtherKeyProof([]byte("oops"), c1.GetSigChain(), c1.GetDevicePublicKey()) - assert.NotNil(t, err) + if err == nil { + t.Fatalf("err should not be nil") + } // Wrong sig chain err = hss2.CheckOtherKeyProof(proof, c2.GetSigChain(), c1.GetDevicePublicKey()) - assert.NotNil(t, err) + if err == nil { + t.Fatalf("err should not be nil") + } // Key not found in sig chain err = hss1.CheckOtherKeyProof(proof, c1.GetSigChain(), c1.GetDevicePublicKey()) - assert.NotNil(t, err) + if err == nil { + t.Fatalf("err should not be nil") + } } func TestHandshakeSession_ProveOtherKnownAccount_CheckOwnKnownAccountProof(t *testing.T) { @@ -178,10 +220,14 @@ func TestHandshakeSession_ProveOtherKnownAccount_CheckOwnKnownAccountProof(t *te hss1, c1, hss2, _ := createTwoDevices(t, ctx) proof, err := hss1.ProveOtherKnownAccount() - assert.Nil(t, err) + if err != nil { + t.Fatalf("can't prove other known account") + } err = hss2.CheckOwnKnownAccountProof(c1.GetDevicePublicKey(), proof) - assert.Nil(t, err) + if err != nil { + t.Fatalf("can't check self account proof") + } } func TestHandshakeSession_Encrypt_Decrypt(t *testing.T) { @@ -196,49 +242,51 @@ func TestHandshakeSession_Encrypt_Decrypt(t *testing.T) { // Should be able to encode the message encrypted, err := hss1.Encrypt(testData1) - assert.Nil(t, err) - assert.NotNil(t, encrypted) - assert.NotEmpty(t, encrypted) + if err != nil || len(encrypted) == 0 || string(testData1) == string(encrypted) { + t.Fatalf("err should be nil and encrypted should not be empty, encrypted value should not be clear text") + } // Should decode the message properly decrypted, err := hss2.Decrypt(encrypted) - assert.Nil(t, err) - assert.Equal(t, string(testData1), string(decrypted)) + if err != nil || string(testData1) != string(decrypted) { + t.Fatalf("err should be nil and decrypted should equal testData1") + } // Should not decode the message twice decrypted, err = hss2.Decrypt(encrypted) - assert.NotNil(t, err) - assert.NotEqual(t, string(testData1), string(decrypted)) + if err != ErrDecrypt || string(decrypted) != "" { + t.Fatalf("err should be ErrDecrypt and decrypted should be empty") + } // Should not decode a random string decrypted, err = hss2.Decrypt([]byte("blahblah")) - assert.NotNil(t, err) - assert.NotEqual(t, string(testData1), string(decrypted)) + if err != ErrDecrypt || string(decrypted) != "" { + t.Fatalf("err should be ErrDecrypt and decrypted should be empty") + } // Should be able to encode a second message encrypted2, err := hss1.Encrypt(testData2) - assert.Nil(t, err) - assert.NotNil(t, encrypted) - assert.NotEmpty(t, encrypted) - assert.NotEqual(t, string(encrypted), string(encrypted2)) + if err != nil || len(encrypted2) == 0 || string(testData2) == string(encrypted2) { + t.Fatalf("err should be nil and encrypted2 should not be empty, encrypted2 value should not be clear text") + } // Should decode the second message properly decrypted, err = hss2.Decrypt(encrypted2) - assert.Nil(t, err) - assert.Equal(t, string(testData2), string(decrypted)) + if err != nil || string(testData2) != string(decrypted) { + t.Fatalf("err should be nil and decrypted should equal testData2") + } // Should be able to encode a message from second peer encrypted3, err := hss2.Encrypt(testData3) - assert.Nil(t, err) - assert.NotNil(t, encrypted2) - assert.NotEmpty(t, encrypted2) - assert.NotEqual(t, string(encrypted2), string(encrypted3)) + if err != nil || len(encrypted3) == 0 || string(testData3) == string(encrypted3) { + t.Fatalf("err should be nil and encrypted3 should not be empty, encrypted3 value should not be clear text") + } // Should decode the third message properly decrypted, err = hss1.Decrypt(encrypted3) - assert.Nil(t, err) - assert.Equal(t, string(testData3), string(decrypted)) - + if err != nil || string(testData3) != string(decrypted) { + t.Fatalf("err should be nil and decrypted should equal testData3") + } } func TestHandshakeSession_Close(t *testing.T) { @@ -246,6 +294,11 @@ func TestHandshakeSession_Close(t *testing.T) { defer cancel() hss1, _, hss2, _ := createTwoDevices(t, ctx) - assert.Nil(t, hss1.Close()) - assert.Nil(t, hss2.Close()) + if err := hss1.Close(); err != nil { + t.Fatalf("can't close hss1 properly") + } + + if err := hss2.Close(); err != nil { + t.Fatalf("can't close hss2 properly") + } } diff --git a/go/internal/handshake/errors.go b/go/internal/handshake/errors.go new file mode 100644 index 0000000000..3f3f7f6666 --- /dev/null +++ b/go/internal/handshake/errors.go @@ -0,0 +1,15 @@ +package handshake + +import "errors" + +var ErrNoPayload = errors.New("handshake: no payload specified") +var ErrInvalidFlow = errors.New("handshake: invalid flow") +var ErrInvalidFlowStepNotFound = errors.New("handshake: invalid flow, step not found") +var ErrParams = errors.New("handshake: can't init with supplied parameters") +var ErrSigChainCast = errors.New("handshake: can't cast sig chain") +var ErrNoAuthReturned = errors.New("handshake: no authenticated sig chain or device key returned") +var ErrInvalidKeyType = errors.New("handshake: invalid key type") +var ErrInvalidSignature = errors.New("handshake: signature is not valid") +var ErrSessionInvalid = errors.New("handshake: session has not been properly initialized") +var ErrKeyNotInSigChain = errors.New("handshake: key not found in sig chain") +var ErrDecrypt = errors.New("handshake: unable to decrypt data") diff --git a/go/internal/handshake/handshake.pb.go b/go/internal/handshake/handshake.pb.go new file mode 100644 index 0000000000..c39ed0109c --- /dev/null +++ b/go/internal/handshake/handshake.pb.go @@ -0,0 +1,843 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: internal/handshake.proto + +package handshake + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + bertyprotocol "berty.tech/go/pkg/bertyprotocol" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type HandshakeFrame_HandshakeStep int32 + +const ( + HandshakeFrame_STEP_1_KEY_AGREEMENT HandshakeFrame_HandshakeStep = 0 + HandshakeFrame_STEP_2_KEY_AGREEMENT HandshakeFrame_HandshakeStep = 1 + HandshakeFrame_STEP_3_DISPATCH HandshakeFrame_HandshakeStep = 10 + HandshakeFrame_STEP_3A_KNOWN_IDENTITY_PROOF HandshakeFrame_HandshakeStep = 20 + HandshakeFrame_STEP_4A_KNOWN_IDENTITY_DISCLOSURE HandshakeFrame_HandshakeStep = 21 + HandshakeFrame_STEP_5A_KNOWN_IDENTITY_DISCLOSURE HandshakeFrame_HandshakeStep = 22 + HandshakeFrame_STEP_3B_KNOWN_DEVICE_PROOF HandshakeFrame_HandshakeStep = 30 + HandshakeFrame_STEP_4B_KNOWN_DEVICE_DISCLOSURE HandshakeFrame_HandshakeStep = 31 + HandshakeFrame_STEP_9_DONE HandshakeFrame_HandshakeStep = 999 +) + +var HandshakeFrame_HandshakeStep_name = map[int32]string{ + 0: "STEP_1_KEY_AGREEMENT", + 1: "STEP_2_KEY_AGREEMENT", + 10: "STEP_3_DISPATCH", + 20: "STEP_3A_KNOWN_IDENTITY_PROOF", + 21: "STEP_4A_KNOWN_IDENTITY_DISCLOSURE", + 22: "STEP_5A_KNOWN_IDENTITY_DISCLOSURE", + 30: "STEP_3B_KNOWN_DEVICE_PROOF", + 31: "STEP_4B_KNOWN_DEVICE_DISCLOSURE", + 999: "STEP_9_DONE", +} + +var HandshakeFrame_HandshakeStep_value = map[string]int32{ + "STEP_1_KEY_AGREEMENT": 0, + "STEP_2_KEY_AGREEMENT": 1, + "STEP_3_DISPATCH": 10, + "STEP_3A_KNOWN_IDENTITY_PROOF": 20, + "STEP_4A_KNOWN_IDENTITY_DISCLOSURE": 21, + "STEP_5A_KNOWN_IDENTITY_DISCLOSURE": 22, + "STEP_3B_KNOWN_DEVICE_PROOF": 30, + "STEP_4B_KNOWN_DEVICE_DISCLOSURE": 31, + "STEP_9_DONE": 999, +} + +func (x HandshakeFrame_HandshakeStep) String() string { + return proto.EnumName(HandshakeFrame_HandshakeStep_name, int32(x)) +} + +func (HandshakeFrame_HandshakeStep) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_15a58250da931098, []int{0, 0} +} + +type HandshakeFrame struct { + Step HandshakeFrame_HandshakeStep `protobuf:"varint,1,opt,name=step,proto3,enum=handshake.HandshakeFrame_HandshakeStep" json:"step,omitempty"` + SignatureKey []byte `protobuf:"bytes,2,opt,name=signatureKey,proto3" json:"signatureKey,omitempty"` + EncryptionKey []byte `protobuf:"bytes,3,opt,name=encryptionKey,proto3" json:"encryptionKey,omitempty"` + EncryptedPayload []byte `protobuf:"bytes,4,opt,name=encryptedPayload,proto3" json:"encryptedPayload,omitempty"` +} + +func (m *HandshakeFrame) Reset() { *m = HandshakeFrame{} } +func (m *HandshakeFrame) String() string { return proto.CompactTextString(m) } +func (*HandshakeFrame) ProtoMessage() {} +func (*HandshakeFrame) Descriptor() ([]byte, []int) { + return fileDescriptor_15a58250da931098, []int{0} +} +func (m *HandshakeFrame) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HandshakeFrame) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_HandshakeFrame.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *HandshakeFrame) XXX_Merge(src proto.Message) { + xxx_messageInfo_HandshakeFrame.Merge(m, src) +} +func (m *HandshakeFrame) XXX_Size() int { + return m.Size() +} +func (m *HandshakeFrame) XXX_DiscardUnknown() { + xxx_messageInfo_HandshakeFrame.DiscardUnknown(m) +} + +var xxx_messageInfo_HandshakeFrame proto.InternalMessageInfo + +func (m *HandshakeFrame) GetStep() HandshakeFrame_HandshakeStep { + if m != nil { + return m.Step + } + return HandshakeFrame_STEP_1_KEY_AGREEMENT +} + +func (m *HandshakeFrame) GetSignatureKey() []byte { + if m != nil { + return m.SignatureKey + } + return nil +} + +func (m *HandshakeFrame) GetEncryptionKey() []byte { + if m != nil { + return m.EncryptionKey + } + return nil +} + +func (m *HandshakeFrame) GetEncryptedPayload() []byte { + if m != nil { + return m.EncryptedPayload + } + return nil +} + +type HandshakePayload struct { + Signature []byte `protobuf:"bytes,1,opt,name=signature,proto3" json:"signature,omitempty"` + SigChain *bertyprotocol.SigChain `protobuf:"bytes,2,opt,name=sigChain,proto3" json:"sigChain,omitempty"` + DeviceKey []byte `protobuf:"bytes,3,opt,name=deviceKey,proto3" json:"deviceKey,omitempty"` +} + +func (m *HandshakePayload) Reset() { *m = HandshakePayload{} } +func (m *HandshakePayload) String() string { return proto.CompactTextString(m) } +func (*HandshakePayload) ProtoMessage() {} +func (*HandshakePayload) Descriptor() ([]byte, []int) { + return fileDescriptor_15a58250da931098, []int{1} +} +func (m *HandshakePayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HandshakePayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_HandshakePayload.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *HandshakePayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_HandshakePayload.Merge(m, src) +} +func (m *HandshakePayload) XXX_Size() int { + return m.Size() +} +func (m *HandshakePayload) XXX_DiscardUnknown() { + xxx_messageInfo_HandshakePayload.DiscardUnknown(m) +} + +var xxx_messageInfo_HandshakePayload proto.InternalMessageInfo + +func (m *HandshakePayload) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + +func (m *HandshakePayload) GetSigChain() *bertyprotocol.SigChain { + if m != nil { + return m.SigChain + } + return nil +} + +func (m *HandshakePayload) GetDeviceKey() []byte { + if m != nil { + return m.DeviceKey + } + return nil +} + +func init() { + proto.RegisterEnum("handshake.HandshakeFrame_HandshakeStep", HandshakeFrame_HandshakeStep_name, HandshakeFrame_HandshakeStep_value) + proto.RegisterType((*HandshakeFrame)(nil), "handshake.HandshakeFrame") + proto.RegisterType((*HandshakePayload)(nil), "handshake.HandshakePayload") +} + +func init() { proto.RegisterFile("internal/handshake.proto", fileDescriptor_15a58250da931098) } + +var fileDescriptor_15a58250da931098 = []byte{ + // 461 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0x86, 0xe3, 0xb6, 0x02, 0x32, 0x4d, 0x8b, 0xb5, 0x14, 0x64, 0x45, 0x95, 0x1b, 0x02, 0x15, + 0x15, 0x12, 0xb6, 0x48, 0xe1, 0x00, 0x9c, 0xd2, 0x78, 0x4b, 0xad, 0x80, 0x1d, 0xd9, 0x06, 0x54, + 0x2e, 0x96, 0x93, 0x2c, 0xf6, 0x8a, 0x76, 0x37, 0x72, 0x36, 0x48, 0x7e, 0x0b, 0xde, 0x80, 0xd7, + 0xe1, 0xd8, 0x23, 0x47, 0x94, 0x08, 0xf1, 0x1a, 0xa8, 0x6b, 0x63, 0x93, 0x44, 0xe2, 0xe6, 0xf9, + 0xfe, 0xcf, 0x33, 0xab, 0x9d, 0x05, 0x8d, 0x32, 0x41, 0x52, 0x16, 0x5d, 0x98, 0x49, 0xc4, 0xc6, + 0xd3, 0x24, 0xfa, 0x4c, 0x8c, 0x49, 0xca, 0x05, 0x47, 0xf5, 0x12, 0x34, 0x1b, 0x84, 0x09, 0x2a, + 0xb2, 0x3c, 0x68, 0x3e, 0x89, 0xa9, 0x48, 0x66, 0x43, 0x63, 0xc4, 0x2f, 0xcd, 0x98, 0xc7, 0xdc, + 0x94, 0x78, 0x38, 0xfb, 0x24, 0x2b, 0x59, 0xc8, 0xaf, 0x5c, 0x6f, 0xff, 0xda, 0x84, 0xdd, 0xb3, + 0xbf, 0xad, 0x4e, 0xd3, 0xe8, 0x92, 0xa0, 0x57, 0xb0, 0x35, 0x15, 0x64, 0xa2, 0x29, 0x2d, 0xe5, + 0x68, 0xb7, 0xf3, 0xc8, 0xa8, 0x46, 0x2f, 0x8b, 0x55, 0xe9, 0x0b, 0x32, 0xf1, 0xe4, 0x4f, 0xa8, + 0x0d, 0x8d, 0x29, 0x8d, 0x59, 0x24, 0x66, 0x29, 0xe9, 0x93, 0x4c, 0xdb, 0x68, 0x29, 0x47, 0x0d, + 0x6f, 0x89, 0xa1, 0x87, 0xb0, 0x43, 0xd8, 0x28, 0xcd, 0x26, 0x82, 0x72, 0x76, 0x2d, 0x6d, 0x4a, + 0x69, 0x19, 0xa2, 0xc7, 0xa0, 0x16, 0x80, 0x8c, 0x07, 0x51, 0x76, 0xc1, 0xa3, 0xb1, 0xb6, 0x25, + 0xc5, 0x35, 0xde, 0xfe, 0xb6, 0x01, 0x3b, 0x4b, 0xa7, 0x41, 0x1a, 0xec, 0xf9, 0x01, 0x1e, 0x84, + 0x4f, 0xc3, 0x3e, 0x3e, 0x0f, 0xbb, 0xaf, 0x3d, 0x8c, 0xdf, 0x62, 0x27, 0x50, 0x6b, 0x65, 0xd2, + 0x59, 0x49, 0x14, 0x74, 0x07, 0x6e, 0xcb, 0xe4, 0x38, 0xb4, 0x6c, 0x7f, 0xd0, 0x0d, 0x7a, 0x67, + 0x2a, 0xa0, 0x16, 0xec, 0xe7, 0xb0, 0x1b, 0xf6, 0x1d, 0xf7, 0x83, 0x13, 0xda, 0x16, 0x76, 0x02, + 0x3b, 0x38, 0x0f, 0x07, 0x9e, 0xeb, 0x9e, 0xaa, 0x7b, 0xe8, 0x10, 0xee, 0x4b, 0xe3, 0xd9, 0x9a, + 0x61, 0xd9, 0x7e, 0xef, 0x8d, 0xeb, 0xbf, 0xf3, 0xb0, 0x7a, 0xb7, 0xd4, 0x9e, 0xff, 0x4f, 0xbb, + 0x87, 0x74, 0x68, 0xe6, 0xf3, 0x4e, 0x0a, 0xcd, 0xc2, 0xef, 0xed, 0x1e, 0x2e, 0xa6, 0xe9, 0xe8, + 0x01, 0x1c, 0xe4, 0xd3, 0x56, 0xf2, 0x7f, 0x9a, 0x1c, 0x20, 0x15, 0xb6, 0xa5, 0xf4, 0x22, 0xb4, + 0x5c, 0x07, 0xab, 0xbf, 0x6f, 0xb6, 0x67, 0xa0, 0x96, 0x17, 0x54, 0xdc, 0x1a, 0xda, 0x87, 0x7a, + 0xb9, 0x17, 0xb9, 0xed, 0x86, 0x57, 0x01, 0x74, 0x08, 0xb7, 0xa6, 0x34, 0xee, 0x25, 0x11, 0x65, + 0x72, 0x8b, 0xdb, 0x9d, 0xba, 0xe1, 0x17, 0xc0, 0x2b, 0xa3, 0xeb, 0x26, 0x63, 0xf2, 0x85, 0x8e, + 0x48, 0xb5, 0xc8, 0x0a, 0x9c, 0xbc, 0xfc, 0x3e, 0xd7, 0x95, 0xab, 0xb9, 0xae, 0xfc, 0x9c, 0xeb, + 0xca, 0xd7, 0x85, 0x5e, 0xbb, 0x5a, 0xe8, 0xb5, 0x1f, 0x0b, 0xbd, 0xf6, 0xb1, 0x35, 0x24, 0xa9, + 0xc8, 0x0c, 0x41, 0x46, 0x89, 0x19, 0x73, 0x73, 0xfd, 0xa1, 0x0f, 0x6f, 0xc8, 0x17, 0x7a, 0xfc, + 0x27, 0x00, 0x00, 0xff, 0xff, 0xe7, 0x5e, 0xe7, 0x24, 0x05, 0x03, 0x00, 0x00, +} + +func (m *HandshakeFrame) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *HandshakeFrame) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HandshakeFrame) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.EncryptedPayload) > 0 { + i -= len(m.EncryptedPayload) + copy(dAtA[i:], m.EncryptedPayload) + i = encodeVarintHandshake(dAtA, i, uint64(len(m.EncryptedPayload))) + i-- + dAtA[i] = 0x22 + } + if len(m.EncryptionKey) > 0 { + i -= len(m.EncryptionKey) + copy(dAtA[i:], m.EncryptionKey) + i = encodeVarintHandshake(dAtA, i, uint64(len(m.EncryptionKey))) + i-- + dAtA[i] = 0x1a + } + if len(m.SignatureKey) > 0 { + i -= len(m.SignatureKey) + copy(dAtA[i:], m.SignatureKey) + i = encodeVarintHandshake(dAtA, i, uint64(len(m.SignatureKey))) + i-- + dAtA[i] = 0x12 + } + if m.Step != 0 { + i = encodeVarintHandshake(dAtA, i, uint64(m.Step)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *HandshakePayload) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *HandshakePayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HandshakePayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DeviceKey) > 0 { + i -= len(m.DeviceKey) + copy(dAtA[i:], m.DeviceKey) + i = encodeVarintHandshake(dAtA, i, uint64(len(m.DeviceKey))) + i-- + dAtA[i] = 0x1a + } + if m.SigChain != nil { + { + size, err := m.SigChain.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintHandshake(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintHandshake(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintHandshake(dAtA []byte, offset int, v uint64) int { + offset -= sovHandshake(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *HandshakeFrame) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Step != 0 { + n += 1 + sovHandshake(uint64(m.Step)) + } + l = len(m.SignatureKey) + if l > 0 { + n += 1 + l + sovHandshake(uint64(l)) + } + l = len(m.EncryptionKey) + if l > 0 { + n += 1 + l + sovHandshake(uint64(l)) + } + l = len(m.EncryptedPayload) + if l > 0 { + n += 1 + l + sovHandshake(uint64(l)) + } + return n +} + +func (m *HandshakePayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Signature) + if l > 0 { + n += 1 + l + sovHandshake(uint64(l)) + } + if m.SigChain != nil { + l = m.SigChain.Size() + n += 1 + l + sovHandshake(uint64(l)) + } + l = len(m.DeviceKey) + if l > 0 { + n += 1 + l + sovHandshake(uint64(l)) + } + return n +} + +func sovHandshake(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozHandshake(x uint64) (n int) { + return sovHandshake(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *HandshakeFrame) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHandshake + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: HandshakeFrame: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HandshakeFrame: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Step", wireType) + } + m.Step = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHandshake + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Step |= HandshakeFrame_HandshakeStep(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SignatureKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHandshake + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthHandshake + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthHandshake + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SignatureKey = append(m.SignatureKey[:0], dAtA[iNdEx:postIndex]...) + if m.SignatureKey == nil { + m.SignatureKey = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EncryptionKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHandshake + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthHandshake + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthHandshake + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EncryptionKey = append(m.EncryptionKey[:0], dAtA[iNdEx:postIndex]...) + if m.EncryptionKey == nil { + m.EncryptionKey = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EncryptedPayload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHandshake + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthHandshake + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthHandshake + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EncryptedPayload = append(m.EncryptedPayload[:0], dAtA[iNdEx:postIndex]...) + if m.EncryptedPayload == nil { + m.EncryptedPayload = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipHandshake(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthHandshake + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthHandshake + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *HandshakePayload) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHandshake + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: HandshakePayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HandshakePayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHandshake + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthHandshake + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthHandshake + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) + if m.Signature == nil { + m.Signature = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SigChain", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHandshake + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthHandshake + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthHandshake + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.SigChain == nil { + m.SigChain = &bertyprotocol.SigChain{} + } + if err := m.SigChain.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DeviceKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHandshake + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthHandshake + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthHandshake + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DeviceKey = append(m.DeviceKey[:0], dAtA[iNdEx:postIndex]...) + if m.DeviceKey == nil { + m.DeviceKey = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipHandshake(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthHandshake + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthHandshake + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipHandshake(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowHandshake + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowHandshake + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + return iNdEx, nil + case 1: + iNdEx += 8 + return iNdEx, nil + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowHandshake + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthHandshake + } + iNdEx += length + if iNdEx < 0 { + return 0, ErrInvalidLengthHandshake + } + return iNdEx, nil + case 3: + for { + var innerWire uint64 + var start int = iNdEx + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowHandshake + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + innerWire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + innerWireType := int(innerWire & 0x7) + if innerWireType == 4 { + break + } + next, err := skipHandshake(dAtA[start:]) + if err != nil { + return 0, err + } + iNdEx = start + next + if iNdEx < 0 { + return 0, ErrInvalidLengthHandshake + } + } + return iNdEx, nil + case 4: + return iNdEx, nil + case 5: + iNdEx += 4 + return iNdEx, nil + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + } + panic("unreachable") +} + +var ( + ErrInvalidLengthHandshake = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowHandshake = fmt.Errorf("proto: integer overflow") +) diff --git a/go/internal/handshake/net_flow.go b/go/internal/handshake/net_flow.go new file mode 100644 index 0000000000..1522449582 --- /dev/null +++ b/go/internal/handshake/net_flow.go @@ -0,0 +1,144 @@ +package handshake + +import ( + "context" + "net" + + "berty.tech/go/pkg/iface" + ggio "github.com/gogo/protobuf/io" + "github.com/libp2p/go-libp2p-core/crypto" + inet "github.com/libp2p/go-libp2p-core/network" +) + +type flowStep interface { + action(ctx context.Context, f *flow, step HandshakeFrame_HandshakeStep, readMsg *HandshakeFrame) (nextStep *HandshakeFrame_HandshakeStep, err error) + isReadAction() bool +} + +type flow struct { + reader ggio.ReadCloser + writer ggio.WriteCloser + session *handshakeSession + steps map[HandshakeFrame_HandshakeStep]flowStep + ownSigChain iface.SigChain + ownDevicePubKey crypto.PubKey + provedSigChain iface.SigChain + provedDevicePubKey crypto.PubKey +} + +func newHandshakeFlow(ctx context.Context, conn net.Conn, devPubKey crypto.PubKey, ownSigChain iface.SigChain, session *handshakeSession, steps map[HandshakeFrame_HandshakeStep]flowStep) (iface.SigChain, crypto.PubKey, error) { + if conn == nil || session == nil || steps == nil { + return nil, nil, ErrParams + } + + writer := ggio.NewDelimitedWriter(conn) + reader := ggio.NewDelimitedReader(conn, inet.MessageSizeMax) + + f := flow{ + reader: reader, + writer: writer, + session: session, + steps: steps, + ownDevicePubKey: devPubKey, + ownSigChain: ownSigChain, + } + + return f.performFlow(ctx) +} + +func (f *flow) close() error { + if f.writer != nil { + if err := f.writer.Close(); err != nil { + return err + } + } + + if f.reader != nil { + if err := f.reader.Close(); err != nil { + return err + } + } + + if f.session != nil { + if err := f.session.Close(); err != nil { + return err + } + } + + return nil +} + +func (f *flow) performFlow(ctx context.Context) (iface.SigChain, crypto.PubKey, error) { + var err error + defer func() { _ = f.close() }() + + initialStep := HandshakeFrame_STEP_1_KEY_AGREEMENT + nextStep := &initialStep + + for nextStep != nil { + if *nextStep == HandshakeFrame_STEP_9_DONE { + if f.provedSigChain == nil || f.provedDevicePubKey == nil { + return nil, nil, ErrNoAuthReturned + } + + return f.provedSigChain, f.provedDevicePubKey, nil + } + + currentStep := *nextStep + + step, ok := f.steps[*nextStep] + if !ok { + return nil, nil, ErrInvalidFlowStepNotFound + } + + var readMsg = &HandshakeFrame{} + if step.isReadAction() { + // TODO: time out + + if err := f.reader.ReadMsg(readMsg); err != nil { + return nil, nil, err + } + + } + + if nextStep, err = step.action(ctx, f, *nextStep, readMsg); err != nil { + return nil, nil, err + } + + if *nextStep == currentStep { + return nil, nil, ErrInvalidFlow + } + } + + return nil, nil, ErrInvalidFlow +} + +func Request(ctx context.Context, conn net.Conn, devicePrivateKey crypto.PrivKey, sigChain iface.SigChain, accountToReach crypto.PubKey) (iface.SigChain, crypto.PubKey, error) { + session, err := newCryptoRequest(devicePrivateKey, sigChain, accountToReach) + if err != nil { + return nil, nil, err + } + + return newHandshakeFlow(ctx, conn, devicePrivateKey.GetPublic(), sigChain, session, map[HandshakeFrame_HandshakeStep]flowStep{ + HandshakeFrame_STEP_1_KEY_AGREEMENT: &step1or2SendKeys{next: HandshakeFrame_STEP_2_KEY_AGREEMENT}, + HandshakeFrame_STEP_2_KEY_AGREEMENT: &step1or2ReceiveKey{next: HandshakeFrame_STEP_3A_KNOWN_IDENTITY_PROOF}, + HandshakeFrame_STEP_3A_KNOWN_IDENTITY_PROOF: &step3ProveOtherKey{next: HandshakeFrame_STEP_4A_KNOWN_IDENTITY_DISCLOSURE}, + HandshakeFrame_STEP_4A_KNOWN_IDENTITY_DISCLOSURE: &step4or5CheckSigChainProof{next: HandshakeFrame_STEP_5A_KNOWN_IDENTITY_DISCLOSURE}, + HandshakeFrame_STEP_5A_KNOWN_IDENTITY_DISCLOSURE: &step4or5SendSigChainProof{next: HandshakeFrame_STEP_9_DONE}, + }) +} + +func Response(ctx context.Context, conn net.Conn, devicePrivateKey crypto.PrivKey, sigChain iface.SigChain) (iface.SigChain, crypto.PubKey, error) { + session, err := newCryptoResponse(devicePrivateKey, sigChain) + if err != nil { + return nil, nil, err + } + + return newHandshakeFlow(ctx, conn, devicePrivateKey.GetPublic(), sigChain, session, map[HandshakeFrame_HandshakeStep]flowStep{ + HandshakeFrame_STEP_1_KEY_AGREEMENT: &step1or2ReceiveKey{next: HandshakeFrame_STEP_2_KEY_AGREEMENT}, + HandshakeFrame_STEP_2_KEY_AGREEMENT: &step1or2SendKeys{next: HandshakeFrame_STEP_3A_KNOWN_IDENTITY_PROOF}, + HandshakeFrame_STEP_3A_KNOWN_IDENTITY_PROOF: &step3CheckOwnKey{next: HandshakeFrame_STEP_4A_KNOWN_IDENTITY_DISCLOSURE}, + HandshakeFrame_STEP_4A_KNOWN_IDENTITY_DISCLOSURE: &step4or5SendSigChainProof{next: HandshakeFrame_STEP_5A_KNOWN_IDENTITY_DISCLOSURE}, + HandshakeFrame_STEP_5A_KNOWN_IDENTITY_DISCLOSURE: &step4or5CheckSigChainProof{next: HandshakeFrame_STEP_9_DONE}, + }) +} diff --git a/go/internal/handshake/net_flow_test.go b/go/internal/handshake/net_flow_test.go new file mode 100644 index 0000000000..c6ea11363a --- /dev/null +++ b/go/internal/handshake/net_flow_test.go @@ -0,0 +1,292 @@ +package handshake + +import ( + "bytes" + "context" + "crypto/rand" + "errors" + "net" + "sync" + "testing" + "time" + + "berty.tech/go/pkg/bertyprotocol" + "berty.tech/go/pkg/iface" + "github.com/libp2p/go-libp2p-core/crypto" + + "github.com/gogo/protobuf/proto" + + internalCrypto "berty.tech/go/internal/crypto" + ggio "github.com/gogo/protobuf/io" +) + +var ErrDummy = errors.New("handshake: dummy") +var ErrNoIncomingMessage = errors.New("handshake: missing incoming message") +var ErrNotExpectedMsg = errors.New("handshake: not expected message") + +type dummyReader struct { + msg *HandshakeFrame +} + +func (d *dummyReader) ReadMsg(msg proto.Message) error { + data, err := d.msg.Marshal() + if err != nil { + return err + } + + return proto.Unmarshal(data[:], msg) +} + +func (d *dummyReader) Close() error { + return nil +} + +var _ ggio.ReadCloser = (*dummyReader)(nil) + +type dummyStep struct { + next HandshakeFrame_HandshakeStep + err error + read bool + expectedMsg *HandshakeFrame +} + +func (s *dummyStep) isReadAction() bool { return s.read } +func (s *dummyStep) action(ctx context.Context, f *flow, step HandshakeFrame_HandshakeStep, readMsg *HandshakeFrame) (*HandshakeFrame_HandshakeStep, error) { + if s.read { + if readMsg == nil { + return nil, ErrNoIncomingMessage + } + + if readMsg.Step != s.expectedMsg.Step || bytes.Compare(readMsg.EncryptedPayload, s.expectedMsg.EncryptedPayload) != 0 { + return nil, ErrNotExpectedMsg + } + } + + return &s.next, s.err +} + +type dummySetCredsStep struct { + next HandshakeFrame_HandshakeStep + sigChain iface.SigChain + devicePubKey crypto.PubKey +} + +func (s *dummySetCredsStep) isReadAction() bool { return false } +func (s *dummySetCredsStep) action(ctx context.Context, f *flow, step HandshakeFrame_HandshakeStep, readMsg *HandshakeFrame) (*HandshakeFrame_HandshakeStep, error) { + _, provedDevicePubKey, err := crypto.GenerateEd25519Key(rand.Reader) + if err != nil { + return nil, err + } + + f.provedDevicePubKey = provedDevicePubKey + f.provedSigChain = &bertyprotocol.SigChain{} + + return &s.next, nil +} + +func Test_flow_performFlow(t *testing.T) { + ctx := context.Background() + + expectedMsg := &HandshakeFrame{ + Step: HandshakeFrame_STEP_1_KEY_AGREEMENT, + EncryptedPayload: []byte("dummy"), + } + + cases := []struct { + name string + steps map[HandshakeFrame_HandshakeStep]flowStep + expected error + reader ggio.ReadCloser + }{ + { + name: "no steps", + steps: map[HandshakeFrame_HandshakeStep]flowStep{}, + expected: ErrInvalidFlowStepNotFound, + }, + { + name: "single valid, no authenticated returned", + steps: map[HandshakeFrame_HandshakeStep]flowStep{ + HandshakeFrame_STEP_1_KEY_AGREEMENT: &dummyStep{ + next: HandshakeFrame_STEP_9_DONE, + }, + }, + expected: ErrNoAuthReturned, + }, + { + name: "single valid, read, no authenticated returned", + steps: map[HandshakeFrame_HandshakeStep]flowStep{ + HandshakeFrame_STEP_1_KEY_AGREEMENT: &dummyStep{ + next: HandshakeFrame_STEP_9_DONE, + read: true, + expectedMsg: expectedMsg, + }, + }, + reader: &dummyReader{msg: expectedMsg}, + expected: ErrNoAuthReturned, + }, + { + name: "single invalid looping", + steps: map[HandshakeFrame_HandshakeStep]flowStep{ + HandshakeFrame_STEP_1_KEY_AGREEMENT: &dummyStep{ + next: HandshakeFrame_STEP_1_KEY_AGREEMENT, + }, + }, + expected: ErrInvalidFlow, + }, + { + name: "single invalid end", + steps: map[HandshakeFrame_HandshakeStep]flowStep{ + HandshakeFrame_STEP_1_KEY_AGREEMENT: &dummyStep{ + next: HandshakeFrame_STEP_2_KEY_AGREEMENT, + }, + }, + expected: ErrInvalidFlowStepNotFound, + }, + { + name: "single invalid start", + steps: map[HandshakeFrame_HandshakeStep]flowStep{ + HandshakeFrame_STEP_2_KEY_AGREEMENT: &dummyStep{ + next: HandshakeFrame_STEP_9_DONE, + }, + }, + expected: ErrInvalidFlowStepNotFound, + }, + { + name: "multiple valid, no authenticated returned", + steps: map[HandshakeFrame_HandshakeStep]flowStep{ + HandshakeFrame_STEP_1_KEY_AGREEMENT: &dummyStep{ + next: HandshakeFrame_STEP_2_KEY_AGREEMENT, + }, + HandshakeFrame_STEP_2_KEY_AGREEMENT: &dummyStep{ + next: HandshakeFrame_STEP_9_DONE, + }, + }, + expected: ErrNoAuthReturned, + }, + { + name: "multiple valid, authenticated returned", + steps: map[HandshakeFrame_HandshakeStep]flowStep{ + HandshakeFrame_STEP_1_KEY_AGREEMENT: &dummyStep{ + next: HandshakeFrame_STEP_2_KEY_AGREEMENT, + }, + HandshakeFrame_STEP_2_KEY_AGREEMENT: &dummyStep{ + next: HandshakeFrame_STEP_3A_KNOWN_IDENTITY_PROOF, + }, + HandshakeFrame_STEP_3A_KNOWN_IDENTITY_PROOF: &dummySetCredsStep{ + next: HandshakeFrame_STEP_9_DONE, + }, + }, + expected: nil, + }, + { + name: "multiple erroring", + steps: map[HandshakeFrame_HandshakeStep]flowStep{ + HandshakeFrame_STEP_1_KEY_AGREEMENT: &dummyStep{ + next: HandshakeFrame_STEP_2_KEY_AGREEMENT, + err: ErrDummy, + }, + HandshakeFrame_STEP_2_KEY_AGREEMENT: &dummyStep{ + next: HandshakeFrame_STEP_9_DONE, + }, + }, + expected: ErrDummy, + }, + } + + for _, c := range cases { + f := flow{ + steps: c.steps, + reader: c.reader, + } + + _, _, err := f.performFlow(ctx) + if err != c.expected { + t.Fatalf("invalid flow for case %s (got error %v, expected %v)", c.name, err, c.expected) + } + } +} + +func Test_Request_Response(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), time.Second*2) + defer cancel() + + ds := &struct{ TODO int }{} + + reqCrypto, reqPrivateKey, err := internalCrypto.InitNewIdentity(ctx, ds) + if err != nil { + t.Fatalf("unable to create an identity") + return + } + + resCrypto, resPrivateKey, err := internalCrypto.InitNewIdentity(ctx, ds) + if err != nil { + t.Fatalf("unable to create an identity") + return + } + + wg := sync.WaitGroup{} + wg.Add(2) + + reqConn, resConn := net.Pipe() + + go func() { + defer wg.Done() + + initialEntry, err := resCrypto.GetSigChain().GetInitialEntry() + if err != nil { + t.Fatalf("unable to get initial sigchain entry of requestee on requester side: %v", err) + return + } + + accountPk, err := initialEntry.GetSubject() + if err != nil { + t.Fatalf("unable to get initial sigchain entry of requestee on requester side: %v", err) + return + } + + reqProvedSigChain, reqProvedKey, err := Request(ctx, reqConn, reqPrivateKey, reqCrypto.GetSigChain(), accountPk) + if err != nil { + t.Fatalf("unable to perform handshake on requester side: %v", err) + return + } + + if !reqProvedKey.Equals(resPrivateKey.GetPublic()) { + t.Fatalf("sig chain found on requester side is invalid") + return + } + + _ = reqProvedSigChain + + }() + + go func() { + defer wg.Done() + + resProvedSigChain, resProvedKey, err := Response(ctx, resConn, resPrivateKey, resCrypto.GetSigChain()) + if err != nil { + t.Fatalf("unable to perform handshake on requestee side: %v", err) + return + } + + if !resProvedKey.Equals(reqPrivateKey.GetPublic()) { + t.Fatalf("sig chain found on requestee side is invalid") + return + } + + _ = resProvedSigChain + }() + + go func() { + select { + case <-time.After(time.Second * 2): + // TODO: find something cleaner + wg.Done() + wg.Done() + t.Fail() + case <-ctx.Done(): + return + } + }() + + wg.Wait() +} diff --git a/go/internal/handshake/net_step_1_2_key_agreement.go b/go/internal/handshake/net_step_1_2_key_agreement.go new file mode 100644 index 0000000000..ae79c31b85 --- /dev/null +++ b/go/internal/handshake/net_step_1_2_key_agreement.go @@ -0,0 +1,48 @@ +package handshake + +import ( + "context" + + "github.com/libp2p/go-libp2p-core/crypto" +) + +type step1or2SendKeys struct { + next HandshakeFrame_HandshakeStep +} + +func (s *step1or2SendKeys) isReadAction() bool { return false } +func (s *step1or2SendKeys) action(ctx context.Context, f *flow, step HandshakeFrame_HandshakeStep, readMsg *HandshakeFrame) (*HandshakeFrame_HandshakeStep, error) { + signKey, encryptKey := f.session.GetPublicKeys() + signKeyProto, err := crypto.MarshalPublicKey(signKey) + if err != nil { + return nil, err + } + + if err = f.writer.WriteMsg(&HandshakeFrame{ + Step: step, + SignatureKey: signKeyProto, + EncryptionKey: encryptKey, + }); err != nil { + return nil, err + } + + return &s.next, nil +} + +type step1or2ReceiveKey struct { + next HandshakeFrame_HandshakeStep +} + +func (s *step1or2ReceiveKey) isReadAction() bool { return true } +func (s *step1or2ReceiveKey) action(ctx context.Context, f *flow, step HandshakeFrame_HandshakeStep, readMsg *HandshakeFrame) (*HandshakeFrame_HandshakeStep, error) { + signKey, err := crypto.UnmarshalPublicKey(readMsg.SignatureKey) + if err != nil { + return nil, err + } + + if err := f.session.SetOtherKeys(signKey, readMsg.EncryptionKey); err != nil { + return nil, err + } + + return &s.next, nil +} diff --git a/go/internal/handshake/net_step_3_auth_challenge.go b/go/internal/handshake/net_step_3_auth_challenge.go new file mode 100644 index 0000000000..6e57b9a8e0 --- /dev/null +++ b/go/internal/handshake/net_step_3_auth_challenge.go @@ -0,0 +1,42 @@ +package handshake + +import "context" + +type step3ProveOtherKey struct { + next HandshakeFrame_HandshakeStep +} + +func (s *step3ProveOtherKey) isReadAction() bool { return false } +func (s *step3ProveOtherKey) action(ctx context.Context, f *flow, step HandshakeFrame_HandshakeStep, readMsg *HandshakeFrame) (*HandshakeFrame_HandshakeStep, error) { + sig, err := f.session.ProveOtherKey() + if err != nil { + return nil, err + } + + err = writeEncryptedPayload(f.session, f.writer, step, &HandshakePayload{ + Signature: sig, + }) + if err != nil { + return nil, err + } + + return &s.next, nil +} + +type step3CheckOwnKey struct { + next HandshakeFrame_HandshakeStep +} + +func (s *step3CheckOwnKey) isReadAction() bool { return true } +func (s *step3CheckOwnKey) action(ctx context.Context, f *flow, step HandshakeFrame_HandshakeStep, readMsg *HandshakeFrame) (*HandshakeFrame_HandshakeStep, error) { + payload, err := decryptPayload(f.session, readMsg.EncryptedPayload) + if err != nil { + return nil, err + } + + if err := f.session.CheckOwnKeyProof(payload.Signature); err != nil { + return nil, err + } + + return &s.next, nil +} diff --git a/go/internal/handshake/net_step_4_5_sigchain_exchange.go b/go/internal/handshake/net_step_4_5_sigchain_exchange.go new file mode 100644 index 0000000000..f7f2cb570a --- /dev/null +++ b/go/internal/handshake/net_step_4_5_sigchain_exchange.go @@ -0,0 +1,77 @@ +package handshake + +import ( + "context" + + "berty.tech/go/pkg/bertyprotocol" + "berty.tech/go/pkg/iface" + + "github.com/libp2p/go-libp2p-core/crypto" +) + +type step4or5CheckSigChainProof struct { + next HandshakeFrame_HandshakeStep +} + +func sigChainAsProto(chain iface.SigChain) (*bertyprotocol.SigChain, error) { + p, ok := chain.(*bertyprotocol.SigChain) + if !ok { + return nil, ErrSigChainCast + } + + return p, nil +} + +func (s *step4or5CheckSigChainProof) isReadAction() bool { return true } +func (s *step4or5CheckSigChainProof) action(ctx context.Context, f *flow, step HandshakeFrame_HandshakeStep, readMsg *HandshakeFrame) (*HandshakeFrame_HandshakeStep, error) { + payload, err := decryptPayload(f.session, readMsg.EncryptedPayload) + if err != nil { + return nil, err + } + + signKey, err := crypto.UnmarshalPublicKey(payload.DeviceKey) + if err != nil { + return nil, err + } + + if err = f.session.CheckOtherKeyProof(payload.Signature, payload.SigChain, signKey); err != nil { + return nil, err + } + + f.provedDevicePubKey = signKey + f.provedSigChain = payload.SigChain + + return &s.next, nil +} + +type step4or5SendSigChainProof struct { + next HandshakeFrame_HandshakeStep +} + +func (s *step4or5SendSigChainProof) isReadAction() bool { return false } +func (s *step4or5SendSigChainProof) action(ctx context.Context, f *flow, step HandshakeFrame_HandshakeStep, readMsg *HandshakeFrame) (*HandshakeFrame_HandshakeStep, error) { + proof, err := f.session.ProveOwnDeviceKey() + if err != nil { + return nil, err + } + + devicePubKey, err := crypto.MarshalPublicKey(f.ownDevicePubKey) + if err != nil { + return nil, err + } + + sigChain, err := sigChainAsProto(f.ownSigChain) + if err != nil { + return nil, err + } + + if err := writeEncryptedPayload(f.session, f.writer, step, &HandshakePayload{ + Signature: proof, + SigChain: sigChain, + DeviceKey: devicePubKey, + }); err != nil { + return nil, err + } + + return &s.next, nil +} diff --git a/go/internal/handshake/net_utils.go b/go/internal/handshake/net_utils.go new file mode 100644 index 0000000000..75748947d3 --- /dev/null +++ b/go/internal/handshake/net_utils.go @@ -0,0 +1,50 @@ +package handshake + +import ( + ggio "github.com/gogo/protobuf/io" +) + +func encryptPayload(session *handshakeSession, payload *HandshakePayload) ([]byte, error) { + data, err := payload.Marshal() + if err != nil { + return nil, err + } + + return session.Encrypt(data) +} + +func writeEncryptedPayload(session *handshakeSession, writer ggio.WriteCloser, step HandshakeFrame_HandshakeStep, payload *HandshakePayload) error { + var ( + data []byte + err error + ) + + if payload == nil { + return ErrNoPayload + } + + data, err = encryptPayload(session, payload) + if err != nil { + return err + } + + return writer.WriteMsg(&HandshakeFrame{ + Step: step, + EncryptedPayload: data, + }) +} + +func decryptPayload(session *handshakeSession, payload []byte) (*HandshakePayload, error) { + instance := &HandshakePayload{} + + clear, err := session.Decrypt(payload) + if err != nil { + return nil, err + } + + if err = instance.Unmarshal(clear); err != nil { + return nil, err + } + + return instance, nil +} diff --git a/go/internal/cryptosigchain/crypto_sigchain.go b/go/pkg/bertyprotocol/crypto_sigchain.go similarity index 98% rename from go/internal/cryptosigchain/crypto_sigchain.go rename to go/pkg/bertyprotocol/crypto_sigchain.go index f9105e5ba7..c7c5709df0 100644 --- a/go/internal/cryptosigchain/crypto_sigchain.go +++ b/go/pkg/bertyprotocol/crypto_sigchain.go @@ -1,4 +1,4 @@ -package cryptosigchain +package bertyprotocol import ( "errors" @@ -181,3 +181,5 @@ func (m *SigChain) Check() error { func NewSigChain() iface.SigChain { return &SigChain{} } + +var _ iface.SigChain = (*SigChain)(nil) diff --git a/go/internal/cryptosigchain/crypto_sigchain_entry.go b/go/pkg/bertyprotocol/crypto_sigchain_entry.go similarity index 98% rename from go/internal/cryptosigchain/crypto_sigchain_entry.go rename to go/pkg/bertyprotocol/crypto_sigchain_entry.go index 285d859e86..7efde87730 100644 --- a/go/internal/cryptosigchain/crypto_sigchain_entry.go +++ b/go/pkg/bertyprotocol/crypto_sigchain_entry.go @@ -1,4 +1,4 @@ -package cryptosigchain +package bertyprotocol import ( "berty.tech/go/pkg/iface" diff --git a/go/pkg/bertyprotocol/entity.pb.go b/go/pkg/bertyprotocol/entity.pb.go index 58b0fe6df0..e7a8eb94ce 100644 --- a/go/pkg/bertyprotocol/entity.pb.go +++ b/go/pkg/bertyprotocol/entity.pb.go @@ -8,14 +8,19 @@ import ( io "io" math "math" math_bits "math/bits" + time "time" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "github.com/golang/protobuf/ptypes/timestamp" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf +var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -23,6 +28,37 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type SigChainEntry_SigChainEntryType int32 + +const ( + SigChainEntry_SigChainEntryTypeUndefined SigChainEntry_SigChainEntryType = 0 + SigChainEntry_SigChainEntryTypeInitChain SigChainEntry_SigChainEntryType = 1 + SigChainEntry_SigChainEntryTypeAddKey SigChainEntry_SigChainEntryType = 2 + SigChainEntry_SigChainEntryTypeRemoveKey SigChainEntry_SigChainEntryType = 3 +) + +var SigChainEntry_SigChainEntryType_name = map[int32]string{ + 0: "SigChainEntryTypeUndefined", + 1: "SigChainEntryTypeInitChain", + 2: "SigChainEntryTypeAddKey", + 3: "SigChainEntryTypeRemoveKey", +} + +var SigChainEntry_SigChainEntryType_value = map[string]int32{ + "SigChainEntryTypeUndefined": 0, + "SigChainEntryTypeInitChain": 1, + "SigChainEntryTypeAddKey": 2, + "SigChainEntryTypeRemoveKey": 3, +} + +func (x SigChainEntry_SigChainEntryType) String() string { + return proto.EnumName(SigChainEntry_SigChainEntryType_name, int32(x)) +} + +func (SigChainEntry_SigChainEntryType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_cf50d946d740d100, []int{1, 0} +} + type Contact_ContactStatus int32 const ( @@ -116,6 +152,14 @@ func (m *Device) GetAccountPubKey() []byte { } type SigChainEntry struct { + EntryHash []byte `protobuf:"bytes,1,opt,name=entry_hash,json=entryHash,proto3" json:"entry_hash,omitempty"` + EntryTypeCode SigChainEntry_SigChainEntryType `protobuf:"varint,2,opt,name=entry_type_code,json=entryTypeCode,proto3,enum=SigChainEntry_SigChainEntryType" json:"entry_type_code,omitempty"` + ParentEntryHash []byte `protobuf:"bytes,3,opt,name=parent_entry_hash,json=parentEntryHash,proto3" json:"parent_entry_hash,omitempty"` + CreatedAt time.Time `protobuf:"bytes,4,opt,name=created_at,json=createdAt,proto3,stdtime" json:"created_at"` + ExpiringAt time.Time `protobuf:"bytes,5,opt,name=expiring_at,json=expiringAt,proto3,stdtime" json:"expiring_at"` + SignerPublicKeyBytes []byte `protobuf:"bytes,6,opt,name=signer_public_key_bytes,json=signerPublicKeyBytes,proto3" json:"signer_public_key_bytes,omitempty"` + SubjectPublicKeyBytes []byte `protobuf:"bytes,7,opt,name=subject_public_key_bytes,json=subjectPublicKeyBytes,proto3" json:"subject_public_key_bytes,omitempty"` + Signature []byte `protobuf:"bytes,8,opt,name=signature,proto3" json:"signature,omitempty"` } func (m *SigChainEntry) Reset() { *m = SigChainEntry{} } @@ -151,8 +195,65 @@ func (m *SigChainEntry) XXX_DiscardUnknown() { var xxx_messageInfo_SigChainEntry proto.InternalMessageInfo +func (m *SigChainEntry) GetEntryHash() []byte { + if m != nil { + return m.EntryHash + } + return nil +} + +func (m *SigChainEntry) GetEntryTypeCode() SigChainEntry_SigChainEntryType { + if m != nil { + return m.EntryTypeCode + } + return SigChainEntry_SigChainEntryTypeUndefined +} + +func (m *SigChainEntry) GetParentEntryHash() []byte { + if m != nil { + return m.ParentEntryHash + } + return nil +} + +func (m *SigChainEntry) GetCreatedAt() time.Time { + if m != nil { + return m.CreatedAt + } + return time.Time{} +} + +func (m *SigChainEntry) GetExpiringAt() time.Time { + if m != nil { + return m.ExpiringAt + } + return time.Time{} +} + +func (m *SigChainEntry) GetSignerPublicKeyBytes() []byte { + if m != nil { + return m.SignerPublicKeyBytes + } + return nil +} + +func (m *SigChainEntry) GetSubjectPublicKeyBytes() []byte { + if m != nil { + return m.SubjectPublicKeyBytes + } + return nil +} + +func (m *SigChainEntry) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + type SigChain struct { - Entries []*SigChainEntry `protobuf:"bytes,1,rep,name=entries,proto3" json:"entries,omitempty"` + ID []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Entries []*SigChainEntry `protobuf:"bytes,2,rep,name=entries,proto3" json:"entries,omitempty"` } func (m *SigChain) Reset() { *m = SigChain{} } @@ -188,6 +289,13 @@ func (m *SigChain) XXX_DiscardUnknown() { var xxx_messageInfo_SigChain proto.InternalMessageInfo +func (m *SigChain) GetID() []byte { + if m != nil { + return m.ID + } + return nil +} + func (m *SigChain) GetEntries() []*SigChainEntry { if m != nil { return m.Entries @@ -353,6 +461,7 @@ func (m *DeviceConfig) XXX_DiscardUnknown() { var xxx_messageInfo_DeviceConfig proto.InternalMessageInfo func init() { + proto.RegisterEnum("SigChainEntry_SigChainEntryType", SigChainEntry_SigChainEntryType_name, SigChainEntry_SigChainEntryType_value) proto.RegisterEnum("Contact_ContactStatus", Contact_ContactStatus_name, Contact_ContactStatus_value) proto.RegisterType((*Device)(nil), "Device") proto.RegisterType((*SigChainEntry)(nil), "SigChainEntry") @@ -365,36 +474,54 @@ func init() { func init() { proto.RegisterFile("entity.proto", fileDescriptor_cf50d946d740d100) } var fileDescriptor_cf50d946d740d100 = []byte{ - // 452 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x52, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0x8e, 0x93, 0x36, 0x3f, 0x93, 0xd8, 0xb5, 0x16, 0x51, 0x59, 0x1c, 0x4c, 0x64, 0x50, 0x95, - 0x53, 0x22, 0x05, 0x0e, 0x70, 0xe0, 0x40, 0x43, 0x0f, 0x15, 0x42, 0x54, 0x0e, 0x70, 0xe0, 0x62, - 0x39, 0xeb, 0xa9, 0x63, 0x25, 0xec, 0x06, 0xef, 0xb8, 0xc8, 0x3c, 0x05, 0x8f, 0xc5, 0xb1, 0x17, - 0x24, 0x8e, 0x28, 0x79, 0x11, 0xe4, 0x5d, 0x27, 0x50, 0x38, 0x79, 0xbe, 0x1f, 0x8f, 0x3e, 0x7d, - 0x3b, 0x30, 0x40, 0x41, 0x19, 0x95, 0xe3, 0x4d, 0x2e, 0x49, 0x06, 0x1f, 0xa0, 0xfd, 0x0a, 0x6f, - 0x32, 0x8e, 0xec, 0x31, 0x38, 0x89, 0x9e, 0xa2, 0x4d, 0xb1, 0x88, 0x56, 0x58, 0x7a, 0xd6, 0xd0, - 0x1a, 0x0d, 0xc2, 0x81, 0x61, 0xaf, 0x8a, 0xc5, 0x6b, 0x2c, 0xd9, 0x19, 0x9c, 0xc4, 0x9c, 0xcb, - 0x42, 0xd0, 0xc1, 0xd6, 0xd4, 0x36, 0xbb, 0xa6, 0x8d, 0x2f, 0x38, 0x01, 0x7b, 0x9e, 0xa5, 0xb3, - 0x65, 0x9c, 0x89, 0x0b, 0x41, 0x79, 0x19, 0x3c, 0x85, 0xee, 0x9e, 0x60, 0x23, 0xe8, 0xa0, 0xa0, - 0x3c, 0x43, 0xe5, 0x59, 0xc3, 0xd6, 0xa8, 0x3f, 0x75, 0xc6, 0x77, 0xcc, 0xe1, 0x5e, 0x0e, 0x7e, - 0x34, 0xa1, 0x33, 0x93, 0x82, 0x62, 0x4e, 0xec, 0x0c, 0x7a, 0x2a, 0x4b, 0x23, 0x5e, 0xd9, 0x74, - 0xb6, 0xfe, 0xb4, 0x77, 0xf8, 0x2f, 0xec, 0xaa, 0xfd, 0xf6, 0x07, 0xd0, 0xfd, 0x84, 0x14, 0x27, - 0x31, 0xc5, 0x75, 0xb6, 0x03, 0x66, 0x53, 0xb8, 0x9f, 0xa3, 0x48, 0xf0, 0xeb, 0x8d, 0x2c, 0x54, - 0xb4, 0x91, 0x99, 0xa0, 0x48, 0x21, 0x26, 0x5e, 0x4b, 0x1b, 0xef, 0xfd, 0x11, 0xaf, 0x2a, 0x6d, - 0x8e, 0x98, 0xb0, 0x47, 0x60, 0xab, 0x65, 0x9c, 0x63, 0x12, 0x29, 0xe4, 0x39, 0x92, 0x77, 0x64, - 0x7a, 0x31, 0xe4, 0x5c, 0x73, 0xec, 0x05, 0x38, 0xdc, 0xe4, 0x8c, 0x14, 0xc5, 0x54, 0x28, 0xef, - 0x78, 0x68, 0x8d, 0x9c, 0xe9, 0xe9, 0xb8, 0x8e, 0xbf, 0xff, 0xce, 0xb5, 0x1a, 0xda, 0xfc, 0x6f, - 0x18, 0x08, 0xb0, 0xef, 0xe8, 0xac, 0x0f, 0x9d, 0xf7, 0x62, 0x25, 0xe4, 0x17, 0xe1, 0x36, 0x18, - 0x40, 0xfb, 0x4d, 0xa9, 0x70, 0x7d, 0xed, 0x5a, 0x95, 0x50, 0x3b, 0xdd, 0x66, 0x05, 0xde, 0xe5, - 0x85, 0x22, 0x4c, 0xdc, 0x56, 0x05, 0xce, 0xd7, 0x92, 0xaf, 0x30, 0x71, 0x8f, 0x98, 0x0d, 0xbd, - 0x10, 0x3f, 0x17, 0xa8, 0xe8, 0x52, 0xb8, 0xc7, 0xcc, 0x01, 0xa8, 0xe1, 0xdb, 0x82, 0xdc, 0x76, - 0x70, 0x09, 0xf6, 0x4b, 0xf3, 0x5e, 0x33, 0x29, 0xae, 0xb3, 0x94, 0x3d, 0x03, 0xef, 0xbf, 0x62, - 0x50, 0xc4, 0x8b, 0x35, 0x26, 0xba, 0xeb, 0x6e, 0x78, 0xfa, 0x4f, 0x37, 0x17, 0x46, 0x0d, 0x1c, - 0x18, 0x98, 0x0b, 0x32, 0x9b, 0xce, 0x9f, 0x7f, 0xdf, 0xfa, 0xd6, 0xed, 0xd6, 0xb7, 0x7e, 0x6d, - 0x7d, 0xeb, 0xdb, 0xce, 0x6f, 0xdc, 0xee, 0xfc, 0xc6, 0xcf, 0x9d, 0xdf, 0xf8, 0xf8, 0x70, 0x81, - 0x39, 0x95, 0x63, 0x42, 0xbe, 0x9c, 0xa4, 0x72, 0xb2, 0x59, 0xa5, 0x13, 0xcd, 0xe8, 0x4b, 0xe4, - 0x72, 0xbd, 0x68, 0xeb, 0xe9, 0xc9, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x1e, 0x20, 0x30, - 0xa3, 0x02, 0x00, 0x00, + // 752 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x6f, 0xe3, 0x44, + 0x14, 0x8e, 0xd3, 0x6e, 0x9a, 0xbc, 0xfc, 0xa8, 0x77, 0x60, 0xbb, 0x51, 0x81, 0xa4, 0x0a, 0x68, + 0x55, 0x21, 0x91, 0x48, 0x41, 0x08, 0x38, 0x70, 0x68, 0xb2, 0x95, 0xb6, 0x2a, 0x88, 0xca, 0xed, + 0x72, 0xe0, 0x62, 0x8d, 0x67, 0x5e, 0x9d, 0xa1, 0xc9, 0x8c, 0xf1, 0x8c, 0x0b, 0xe6, 0xaf, 0xe8, + 0x9f, 0xb5, 0xc7, 0xe5, 0x80, 0xc4, 0x69, 0x41, 0xed, 0x3f, 0x82, 0x3c, 0x63, 0x67, 0xb7, 0x9b, + 0x5e, 0x38, 0xf9, 0x7d, 0xdf, 0xf7, 0x7e, 0x8c, 0xbe, 0x79, 0x1e, 0xe8, 0xa0, 0x34, 0xc2, 0xe4, + 0xe3, 0x24, 0x55, 0x46, 0xed, 0x0f, 0x63, 0xa5, 0xe2, 0x25, 0x4e, 0x2c, 0x8a, 0xb2, 0xcb, 0x89, + 0x11, 0x2b, 0xd4, 0x86, 0xae, 0x92, 0x32, 0xe1, 0x8b, 0x58, 0x98, 0x45, 0x16, 0x8d, 0x99, 0x5a, + 0x4d, 0x62, 0x15, 0xab, 0xb7, 0x99, 0x05, 0xb2, 0xc0, 0x46, 0x2e, 0x7d, 0xf4, 0x13, 0x34, 0x9e, + 0xe3, 0xb5, 0x60, 0x48, 0x3e, 0x83, 0x1e, 0xb7, 0x51, 0x98, 0x64, 0x51, 0x78, 0x85, 0x79, 0xdf, + 0x3b, 0xf0, 0x0e, 0x3b, 0x41, 0xc7, 0xb1, 0x67, 0x59, 0x74, 0x8a, 0x39, 0x79, 0x06, 0xbb, 0x94, + 0x31, 0x95, 0x49, 0xb3, 0x4e, 0xab, 0xdb, 0xb4, 0x6e, 0x49, 0xbb, 0xbc, 0xd1, 0x9f, 0xdb, 0xd0, + 0x3d, 0x17, 0xf1, 0x7c, 0x41, 0x85, 0x3c, 0x96, 0x26, 0xcd, 0xc9, 0x27, 0x00, 0x58, 0x04, 0xe1, + 0x82, 0xea, 0x45, 0xd9, 0xbb, 0x65, 0x99, 0x17, 0x54, 0x2f, 0xc8, 0x0b, 0xd8, 0x75, 0xb2, 0xc9, + 0x13, 0x0c, 0x99, 0xe2, 0x68, 0x1b, 0xf7, 0xa6, 0x07, 0xe3, 0x7b, 0x7d, 0xee, 0xa3, 0x8b, 0x3c, + 0xc1, 0xa0, 0x8b, 0x55, 0x38, 0x57, 0x1c, 0xc9, 0xe7, 0xf0, 0x38, 0xa1, 0x29, 0x4a, 0x13, 0xbe, + 0x33, 0x6f, 0xcb, 0xce, 0xdb, 0x75, 0xc2, 0xf1, 0x7a, 0xea, 0x1c, 0x80, 0xa5, 0x48, 0x0d, 0xf2, + 0x90, 0x9a, 0xfe, 0xf6, 0x81, 0x77, 0xd8, 0x9e, 0xee, 0x8f, 0x9d, 0xc7, 0xe3, 0xca, 0xb9, 0xf1, + 0x45, 0xe5, 0xf1, 0xac, 0xf9, 0xea, 0xcd, 0xb0, 0x76, 0xf3, 0xcf, 0xd0, 0x0b, 0x5a, 0x65, 0xdd, + 0x91, 0x21, 0xc7, 0xd0, 0xc6, 0xdf, 0x13, 0x91, 0x0a, 0x19, 0x17, 0x5d, 0x1e, 0xfd, 0x8f, 0x2e, + 0x50, 0x15, 0x1e, 0x19, 0xf2, 0x15, 0x3c, 0xd5, 0x22, 0x96, 0x98, 0x16, 0xce, 0x2e, 0x05, 0x2b, + 0xcc, 0x0d, 0xa3, 0xdc, 0xa0, 0xee, 0x37, 0xec, 0xe9, 0x3f, 0x74, 0xf2, 0x99, 0x55, 0x4f, 0x31, + 0x9f, 0x15, 0x1a, 0xf9, 0x1a, 0xfa, 0x3a, 0x8b, 0x7e, 0x41, 0x66, 0x36, 0xeb, 0x76, 0x6c, 0xdd, + 0x93, 0x52, 0x7f, 0xaf, 0xf0, 0x63, 0x68, 0x15, 0x0d, 0xa9, 0xc9, 0x52, 0xec, 0x37, 0xdd, 0x7d, + 0xac, 0x89, 0xd1, 0x8d, 0x07, 0x8f, 0x37, 0xac, 0x26, 0x03, 0xd8, 0xdf, 0x20, 0x5f, 0x4a, 0x8e, + 0x97, 0x42, 0x22, 0xf7, 0x6b, 0x0f, 0xea, 0x27, 0x52, 0x18, 0xcb, 0xf8, 0x1e, 0xf9, 0x08, 0x9e, + 0x6e, 0xe8, 0x47, 0x9c, 0x9f, 0x62, 0xee, 0xd7, 0x1f, 0x2c, 0x0e, 0x70, 0xa5, 0xae, 0xb1, 0xd0, + 0xb7, 0x46, 0xdf, 0x43, 0xb3, 0xd2, 0xc9, 0x1e, 0xd4, 0x05, 0x77, 0x5b, 0x34, 0x6b, 0xdc, 0xbe, + 0x19, 0xd6, 0x4f, 0x9e, 0x07, 0x75, 0xc1, 0xc9, 0x21, 0xec, 0x14, 0xb7, 0x2e, 0x50, 0xf7, 0xeb, + 0x07, 0x5b, 0x87, 0xed, 0x69, 0xef, 0xfe, 0xc2, 0x04, 0x95, 0x3c, 0xfa, 0xab, 0x0e, 0x3b, 0x73, + 0x25, 0x0d, 0x65, 0x86, 0x3c, 0xb3, 0x56, 0x84, 0xac, 0x48, 0xb3, 0x4d, 0xdb, 0xd3, 0xd6, 0xba, + 0x2e, 0x68, 0xea, 0x6a, 0xea, 0x3e, 0x34, 0x57, 0x68, 0x28, 0xa7, 0x86, 0x96, 0x6b, 0xbf, 0xc6, + 0x64, 0x0a, 0x4f, 0x52, 0x94, 0x1c, 0xff, 0xb8, 0x56, 0x99, 0x0e, 0x13, 0x25, 0xa4, 0x09, 0x35, + 0x22, 0x2f, 0x57, 0xef, 0x83, 0xb7, 0xe2, 0x59, 0xa1, 0x9d, 0x23, 0x72, 0xf2, 0x29, 0x74, 0xf5, + 0x82, 0xa6, 0xc8, 0x43, 0x8d, 0x2c, 0x45, 0xb7, 0x81, 0x9d, 0xa0, 0xe3, 0xc8, 0x73, 0xcb, 0x91, + 0xef, 0xa0, 0xc7, 0xdc, 0x39, 0x43, 0x6d, 0xa8, 0xc9, 0xb4, 0xdd, 0xb0, 0xde, 0x74, 0x6f, 0x5c, + 0x1e, 0xbf, 0xfa, 0x9e, 0x5b, 0x35, 0xe8, 0xb2, 0x77, 0xe1, 0x48, 0x42, 0xf7, 0x9e, 0x4e, 0xda, + 0xb0, 0xf3, 0x52, 0x5e, 0x49, 0xf5, 0x9b, 0xf4, 0x6b, 0x04, 0xa0, 0xf1, 0x43, 0xae, 0x71, 0x79, + 0xe9, 0x7b, 0x85, 0x50, 0x66, 0xfa, 0xf5, 0x02, 0x5c, 0xa4, 0x99, 0x36, 0xc8, 0xfd, 0xad, 0x02, + 0xcc, 0x96, 0x8a, 0x5d, 0x21, 0xf7, 0xb7, 0x49, 0x17, 0x5a, 0x01, 0xfe, 0x9a, 0xa1, 0x36, 0x27, + 0xd2, 0x7f, 0x44, 0x7a, 0x00, 0x25, 0xfc, 0x31, 0x33, 0x7e, 0x63, 0x74, 0x02, 0xdd, 0x23, 0xf7, + 0x14, 0xcc, 0x95, 0xbc, 0x14, 0x31, 0xf9, 0x06, 0xfa, 0x1b, 0xc6, 0xa0, 0xa4, 0xd1, 0x12, 0xdd, + 0x05, 0x36, 0x83, 0xbd, 0xf7, 0xbc, 0x39, 0x76, 0xea, 0xa8, 0x07, 0x1d, 0xf7, 0x38, 0xb9, 0x4e, + 0xb3, 0x6f, 0x5f, 0xdd, 0x0e, 0xbc, 0xd7, 0xb7, 0x03, 0xef, 0xdf, 0xdb, 0x81, 0x77, 0x73, 0x37, + 0xa8, 0xbd, 0xbe, 0x1b, 0xd4, 0xfe, 0xbe, 0x1b, 0xd4, 0x7e, 0x1e, 0x46, 0x98, 0x9a, 0x7c, 0x6c, + 0x90, 0x2d, 0x26, 0xc5, 0x9b, 0x77, 0x15, 0x4f, 0x2c, 0x63, 0x7f, 0x3e, 0xa6, 0x96, 0x51, 0xc3, + 0x46, 0x5f, 0xfe, 0x17, 0x00, 0x00, 0xff, 0xff, 0x7a, 0x53, 0xfd, 0x71, 0x4e, 0x05, 0x00, 0x00, } func (m *Device) Marshal() (dAtA []byte, err error) { @@ -454,6 +581,62 @@ func (m *SigChainEntry) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintEntity(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0x42 + } + if len(m.SubjectPublicKeyBytes) > 0 { + i -= len(m.SubjectPublicKeyBytes) + copy(dAtA[i:], m.SubjectPublicKeyBytes) + i = encodeVarintEntity(dAtA, i, uint64(len(m.SubjectPublicKeyBytes))) + i-- + dAtA[i] = 0x3a + } + if len(m.SignerPublicKeyBytes) > 0 { + i -= len(m.SignerPublicKeyBytes) + copy(dAtA[i:], m.SignerPublicKeyBytes) + i = encodeVarintEntity(dAtA, i, uint64(len(m.SignerPublicKeyBytes))) + i-- + dAtA[i] = 0x32 + } + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.ExpiringAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.ExpiringAt):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintEntity(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x2a + n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.CreatedAt, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintEntity(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x22 + if len(m.ParentEntryHash) > 0 { + i -= len(m.ParentEntryHash) + copy(dAtA[i:], m.ParentEntryHash) + i = encodeVarintEntity(dAtA, i, uint64(len(m.ParentEntryHash))) + i-- + dAtA[i] = 0x1a + } + if m.EntryTypeCode != 0 { + i = encodeVarintEntity(dAtA, i, uint64(m.EntryTypeCode)) + i-- + dAtA[i] = 0x10 + } + if len(m.EntryHash) > 0 { + i -= len(m.EntryHash) + copy(dAtA[i:], m.EntryHash) + i = encodeVarintEntity(dAtA, i, uint64(len(m.EntryHash))) + i-- + dAtA[i] = 0xa + } return len(dAtA) - i, nil } @@ -488,9 +671,16 @@ func (m *SigChain) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintEntity(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0xa + dAtA[i] = 0x12 } } + if len(m.ID) > 0 { + i -= len(m.ID) + copy(dAtA[i:], m.ID) + i = encodeVarintEntity(dAtA, i, uint64(len(m.ID))) + i-- + dAtA[i] = 0xa + } return len(dAtA) - i, nil } @@ -645,6 +835,33 @@ func (m *SigChainEntry) Size() (n int) { } var l int _ = l + l = len(m.EntryHash) + if l > 0 { + n += 1 + l + sovEntity(uint64(l)) + } + if m.EntryTypeCode != 0 { + n += 1 + sovEntity(uint64(m.EntryTypeCode)) + } + l = len(m.ParentEntryHash) + if l > 0 { + n += 1 + l + sovEntity(uint64(l)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt) + n += 1 + l + sovEntity(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.ExpiringAt) + n += 1 + l + sovEntity(uint64(l)) + l = len(m.SignerPublicKeyBytes) + if l > 0 { + n += 1 + l + sovEntity(uint64(l)) + } + l = len(m.SubjectPublicKeyBytes) + if l > 0 { + n += 1 + l + sovEntity(uint64(l)) + } + l = len(m.Signature) + if l > 0 { + n += 1 + l + sovEntity(uint64(l)) + } return n } @@ -654,6 +871,10 @@ func (m *SigChain) Size() (n int) { } var l int _ = l + l = len(m.ID) + if l > 0 { + n += 1 + l + sovEntity(uint64(l)) + } if len(m.Entries) > 0 { for _, e := range m.Entries { l = e.Size() @@ -868,6 +1089,261 @@ func (m *SigChainEntry) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: SigChainEntry: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EntryHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntity + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthEntity + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthEntity + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EntryHash = append(m.EntryHash[:0], dAtA[iNdEx:postIndex]...) + if m.EntryHash == nil { + m.EntryHash = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EntryTypeCode", wireType) + } + m.EntryTypeCode = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntity + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EntryTypeCode |= SigChainEntry_SigChainEntryType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ParentEntryHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntity + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthEntity + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthEntity + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ParentEntryHash = append(m.ParentEntryHash[:0], dAtA[iNdEx:postIndex]...) + if m.ParentEntryHash == nil { + m.ParentEntryHash = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntity + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEntity + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEntity + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.CreatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExpiringAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntity + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEntity + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEntity + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.ExpiringAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SignerPublicKeyBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntity + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthEntity + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthEntity + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SignerPublicKeyBytes = append(m.SignerPublicKeyBytes[:0], dAtA[iNdEx:postIndex]...) + if m.SignerPublicKeyBytes == nil { + m.SignerPublicKeyBytes = []byte{} + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubjectPublicKeyBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntity + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthEntity + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthEntity + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SubjectPublicKeyBytes = append(m.SubjectPublicKeyBytes[:0], dAtA[iNdEx:postIndex]...) + if m.SubjectPublicKeyBytes == nil { + m.SubjectPublicKeyBytes = []byte{} + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntity + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthEntity + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthEntity + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) + if m.Signature == nil { + m.Signature = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipEntity(dAtA[iNdEx:]) @@ -922,6 +1398,40 @@ func (m *SigChain) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntity + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthEntity + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthEntity + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ID = append(m.ID[:0], dAtA[iNdEx:postIndex]...) + if m.ID == nil { + m.ID = []byte{} + } + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Entries", wireType) } diff --git a/go/pkg/iface/crypto.go b/go/pkg/iface/crypto.go index 32d766d576..859a843d73 100644 --- a/go/pkg/iface/crypto.go +++ b/go/pkg/iface/crypto.go @@ -71,26 +71,6 @@ type Crypto interface { Close() error } -type HandshakeSession interface { - // Getters/Setters - SetOtherKeys(sign crypto.PubKey, box []byte) error - GetPublicKeys() (sign crypto.PubKey, box []byte) - - // Actions - ProveOtherKey() ([]byte, error) - CheckOwnKeyProof(sig []byte) error - ProveOwnDeviceKey() ([]byte, error) - CheckOtherKeyProof(sig []byte, chain SigChain, deviceKey crypto.PubKey) error - ProveOtherKnownAccount() ([]byte, error) - CheckOwnKnownAccountProof(attemptedDeviceKey crypto.PubKey, proof []byte) error - - // Utils - Encrypt(data []byte) ([]byte, error) - Decrypt(data []byte) ([]byte, error) - - Close() error -} - //type CryptoEnvelope interface { // // Getters // GetGroupID() []byte