diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..7b1d454 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,29 @@ +name: Go +on: [push] +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-go@v1 + with: + go-version: 1.12 + + - name: Install dependencies + run: | + go get honnef.co/go/tools/cmd/staticcheck + go get golang.org/x/lint/golint + + - name: Lint + run: /home/runner/go/bin/golint -set_exit_status ./... + + - name: Static check + run: /home/runner/go/bin/staticcheck ./... + + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: teserakt-io/gh-actions/go-test@master diff --git a/.gitignore b/.gitignore index 13ec187..61fb0d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -cover.out.tmp cover.out test/data diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c3f992b..a38d1ec 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,11 +4,11 @@ Although E4 is an in-house-developed product by Teserakt.io, it is still open-so ## Bugs, issues, feature requests -Please let us know by creating a [Github issues](https://github.com/Teserakt-io/e4common/issues) if you stumble upon a bug, have an issue or a feature request. +Please let us know by creating a [Github issues](https://github.com/Teserakt-io/e4go/issues) if you stumble upon a bug, have an issue or a feature request. ## Development -* We use golang version >= 1.12 for developing e4common. +* We use golang version >= 1.12 for developing e4go. * Makes sure to create new unit tests covering your code additions. * Please create pull requests targeting the `develop` branch diff --git a/README.md b/README.md index 23b9842..06dfc4b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ -# e4common - -Copyright (C) Teserakt AG 2018-2019. All Rights Reserved. +# e4go This repository implements E4 in Go, Teserakt's Secure machine-to-machine communication protocol. @@ -15,7 +13,7 @@ communication protocol. Client instances can be created with either the `NewSymKeyClient` or `NewSymKeyClientPretty` commands, for example you might call: ```go - import e4 "gitlab.com/teserakt/e4common" + import e4 "github.com/teserakt-io/e4go" var id []byte var key []byte @@ -25,7 +23,7 @@ Client instances can be created with either the `NewSymKeyClient` or If you know your id and key already; alternatively you might do: ```go - import e4 "gitlab.com/teserakt/e4common" + import e4 "github.com/teserakt-io/e4go" name := "some client name" pwd := "some random password" diff --git a/client.go b/client.go index ade635a..1a2f1aa 100644 --- a/client.go +++ b/client.go @@ -1,5 +1,5 @@ // -// Package e4common provides a e4 client implementation and libraries. +// Package e4go provides a e4 client implementation and libraries. // // It aims to be quick and easy to integrate in IoT devices applications // enabling to secure their communications, as well as exposing a way to manage the various keys required. @@ -28,7 +28,7 @@ // There is nothing particular to be done when receiving a command, just passing its protected form to the Unprotect() method // and the client will automatically unprotect and process it (thus returning no unprotected message). // See commands.go for the list of available commands and their respective parameters. -package e4common +package e4go import ( "encoding/hex" @@ -41,8 +41,8 @@ import ( "golang.org/x/crypto/ed25519" - e4crypto "gitlab.com/teserakt/e4common/crypto" - "gitlab.com/teserakt/e4common/keys" + e4crypto "github.com/teserakt-io/e4go/crypto" + "github.com/teserakt-io/e4go/keys" ) const ( diff --git a/client_test.go b/client_test.go index b6594f8..3f44879 100644 --- a/client_test.go +++ b/client_test.go @@ -1,4 +1,4 @@ -package e4common +package e4go import ( "bytes" @@ -10,8 +10,8 @@ import ( "time" "github.com/agl/ed25519/extra25519" - e4crypto "gitlab.com/teserakt/e4common/crypto" - "gitlab.com/teserakt/e4common/keys" + e4crypto "github.com/teserakt-io/e4go/crypto" + "github.com/teserakt-io/e4go/keys" "golang.org/x/crypto/ed25519" ) diff --git a/commands.go b/commands.go index d50ebd2..b3a4b32 100644 --- a/commands.go +++ b/commands.go @@ -1,10 +1,11 @@ -package e4common +package e4go import ( "errors" - e4crypto "gitlab.com/teserakt/e4common/crypto" "golang.org/x/crypto/ed25519" + + e4crypto "github.com/teserakt-io/e4go/crypto" ) // Command is a command sent by C2 to a client. This is a sequence of bytes, starting from a Command, followed by the command arguments. diff --git a/crypto/crypto.go b/crypto/crypto.go index fb3f288..2c50255 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -13,7 +13,7 @@ import ( "golang.org/x/crypto/argon2" "golang.org/x/crypto/curve25519" - miscreant "github.com/miscreant/miscreant/go" + miscreant "github.com/miscreant/miscreant.go" ) var ( diff --git a/example_test.go b/example_test.go index 7cd4e1c..563d373 100644 --- a/example_test.go +++ b/example_test.go @@ -1,4 +1,4 @@ -package e4common +package e4go import ( "log" @@ -6,7 +6,7 @@ import ( "github.com/agl/ed25519/extra25519" "golang.org/x/crypto/ed25519" - "gitlab.com/teserakt/e4common/crypto" + "github.com/teserakt-io/e4go/crypto" ) func ExampleNewSymKeyClient() { diff --git a/go.mod b/go.mod index 82ed8ee..b463e65 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,9 @@ -module gitlab.com/teserakt/e4common +module github.com/teserakt-io/e4go go 1.12 require ( github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 - github.com/golang/protobuf v1.3.1 - github.com/miscreant/miscreant v0.3.0 + github.com/miscreant/miscreant.go v0.0.0-20190903041724-6bebe170cbaf golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5 - golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 - google.golang.org/grpc v1.21.1 ) diff --git a/go.sum b/go.sum index 7c56366..f1d3e0a 100644 --- a/go.sum +++ b/go.sum @@ -1,38 +1,14 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI= github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/miscreant/miscreant v0.3.0 h1:bCn4zQMvNeeFBE3PWrG9ePFLPZyttBPhJ/WDqyqWrLQ= -github.com/miscreant/miscreant v0.3.0/go.mod h1:ZKWeIKfbJej2zjb1OUXJaaP1DnCb4yoTtcR90O7BOD4= +github.com/miscreant/miscreant.go v0.0.0-20190903041724-6bebe170cbaf h1:WHuYoA2VHEGYtfIaV2oBwa8csNWuUpCKAnDf3Jz2D1o= +github.com/miscreant/miscreant.go v0.0.0-20190903041724-6bebe170cbaf/go.mod h1:pBbZyGwC5i16IBkjVKoy/sznA8jPD/K9iedwe1ESE6w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5 h1:8dUaAV7K4uHsF56JQWkprecIQKdPHtR9jCHF5nB8uzc= golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/grpc v1.21.1 h1:j6XxA85m/6txkUCHvzlV5f+HBNl/1r5cZ2A/3IEFOO8= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/keys/publickey.go b/keys/publickey.go index 4e42bed..d53af6c 100644 --- a/keys/publickey.go +++ b/keys/publickey.go @@ -8,7 +8,7 @@ import ( "sync" "time" - e4crypto "gitlab.com/teserakt/e4common/crypto" + e4crypto "github.com/teserakt-io/e4go/crypto" "github.com/agl/ed25519/extra25519" "golang.org/x/crypto/curve25519" diff --git a/keys/publickey_test.go b/keys/publickey_test.go index fe286ff..2d66118 100644 --- a/keys/publickey_test.go +++ b/keys/publickey_test.go @@ -10,7 +10,7 @@ import ( "github.com/agl/ed25519/extra25519" - e4crypto "gitlab.com/teserakt/e4common/crypto" + e4crypto "github.com/teserakt-io/e4go/crypto" "golang.org/x/crypto/ed25519" ) @@ -352,6 +352,10 @@ func TestPubKeyMaterialPubKeys(t *testing.T) { func TestPubKeyMaterialSetKey(t *testing.T) { _, privateKey, err := ed25519.GenerateKey(nil) + if err != nil { + t.Fatalf("Failed to generate key: %v", err) + } + clientID := e4crypto.HashIDAlias("test") k, err := NewPubKeyMaterial(clientID, privateKey, getTestC2PubKey(t)) @@ -369,6 +373,10 @@ func TestPubKeyMaterialSetKey(t *testing.T) { } _, privateKey2, err := ed25519.GenerateKey(nil) + if err != nil { + t.Fatalf("Failed to generate key: %v", err) + } + if err := typedKey.SetKey(privateKey2); err != nil { t.Fatalf("Failed to set key: %v", err) } @@ -389,6 +397,10 @@ func TestPubKeyMaterialSetKey(t *testing.T) { func TestPubKeyMaterialMarshalJSON(t *testing.T) { _, privateKey, err := ed25519.GenerateKey(nil) + if err != nil { + t.Fatalf("Failed to generate key: %v", err) + } + clientID := e4crypto.HashIDAlias("test") c2Pk := getTestC2PubKey(t) diff --git a/keys/symmetric.go b/keys/symmetric.go index a4cbe70..dc0af54 100644 --- a/keys/symmetric.go +++ b/keys/symmetric.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" - e4crypto "gitlab.com/teserakt/e4common/crypto" + e4crypto "github.com/teserakt-io/e4go/crypto" ) // SymKeyMaterial extends the KeyMaterial interface for symmetric key implementations diff --git a/keys/symmetric_test.go b/keys/symmetric_test.go index cdb49d6..0dfeedf 100644 --- a/keys/symmetric_test.go +++ b/keys/symmetric_test.go @@ -7,7 +7,7 @@ import ( "reflect" "testing" - e4crypto "gitlab.com/teserakt/e4common/crypto" + e4crypto "github.com/teserakt-io/e4go/crypto" ) func TestNewSymKeyFromPassword(t *testing.T) {