pax_global_header00006660000000000000000000000064141365614710014522gustar00rootroot0000000000000052 comment=1c139d1cc84b1320feb9d603a6e3962e54b8743f go-minisign-0.2.1/000077500000000000000000000000001413656147100137425ustar00rootroot00000000000000go-minisign-0.2.1/.github/000077500000000000000000000000001413656147100153025ustar00rootroot00000000000000go-minisign-0.2.1/.github/dependabot.yml000066400000000000000000000002211413656147100201250ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: gomod directory: "/" schedule: interval: daily time: "04:00" open-pull-requests-limit: 10 go-minisign-0.2.1/.github/workflows/000077500000000000000000000000001413656147100173375ustar00rootroot00000000000000go-minisign-0.2.1/.github/workflows/go.yml000066400000000000000000000005511413656147100204700ustar00rootroot00000000000000name: Go on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Go uses: actions/setup-go@v2 with: go-version: 1.15 - name: Build run: go build -v ./... - name: Test run: go test -v ./... go-minisign-0.2.1/.gitignore000066400000000000000000000004231413656147100157310ustar00rootroot00000000000000# Binaries for programs and plugins *.exe *.dll *.so *.dylib # Test binary, build with `go test -c` *.test # Output of the go coverage tool, specifically when used with LiteIDE *.out # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 .glide/ go-minisign-0.2.1/LICENSE000066400000000000000000000020611413656147100147460ustar00rootroot00000000000000MIT License Copyright (c) 2018-2021 Frank Denis Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. go-minisign-0.2.1/README.md000066400000000000000000000001501413656147100152150ustar00rootroot00000000000000# go-minisign A Golang library to verify [Minisign](https://jedisct1.github.io/minisign/) signatures. go-minisign-0.2.1/go.mod000066400000000000000000000002711413656147100150500ustar00rootroot00000000000000module github.com/jedisct1/go-minisign go 1.17 require golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 require golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect go-minisign-0.2.1/go.sum000066400000000000000000000016431413656147100151010ustar00rootroot00000000000000golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= go-minisign-0.2.1/minisign.go000066400000000000000000000074441413656147100161170ustar00rootroot00000000000000package minisign import ( "encoding/base64" "errors" "io/ioutil" "strings" "golang.org/x/crypto/blake2b" "golang.org/x/crypto/ed25519" ) type PublicKey struct { SignatureAlgorithm [2]byte KeyId [8]byte PublicKey [32]byte } type Signature struct { UntrustedComment string SignatureAlgorithm [2]byte KeyId [8]byte Signature [64]byte TrustedComment string GlobalSignature [64]byte } func NewPublicKey(publicKeyStr string) (PublicKey, error) { var publicKey PublicKey bin, err := base64.StdEncoding.DecodeString(publicKeyStr) if err != nil || len(bin) != 42 { return publicKey, errors.New("Invalid encoded public key") } copy(publicKey.SignatureAlgorithm[:], bin[0:2]) copy(publicKey.KeyId[:], bin[2:10]) copy(publicKey.PublicKey[:], bin[10:42]) return publicKey, nil } func DecodePublicKey(in string) (PublicKey, error) { var publicKey PublicKey lines := strings.SplitN(in, "\n", 2) if len(lines) < 2 { return publicKey, errors.New("Incomplete encoded public key") } return NewPublicKey(lines[1]) } func trimCarriageReturn(input string) string { return strings.TrimRight(input, "\r") } func DecodeSignature(in string) (Signature, error) { var signature Signature lines := strings.SplitN(in, "\n", 4) if len(lines) < 4 { return signature, errors.New("Incomplete encoded signature") } signature.UntrustedComment = trimCarriageReturn(lines[0]) bin1, err := base64.StdEncoding.DecodeString(lines[1]) if err != nil || len(bin1) != 74 { return signature, errors.New("Invalid encoded signature") } signature.TrustedComment = trimCarriageReturn(lines[2]) bin2, err := base64.StdEncoding.DecodeString(lines[3]) if err != nil || len(bin2) != 64 { return signature, errors.New("Invalid encoded signature") } copy(signature.SignatureAlgorithm[:], bin1[0:2]) copy(signature.KeyId[:], bin1[2:10]) copy(signature.Signature[:], bin1[10:74]) copy(signature.GlobalSignature[:], bin2) return signature, nil } func NewPublicKeyFromFile(file string) (PublicKey, error) { var publicKey PublicKey bin, err := ioutil.ReadFile(file) if err != nil { return publicKey, err } return DecodePublicKey(string(bin)) } func NewSignatureFromFile(file string) (Signature, error) { var signature Signature bin, err := ioutil.ReadFile(file) if err != nil { return signature, err } return DecodeSignature(string(bin)) } func (publicKey *PublicKey) Verify(bin []byte, signature Signature) (bool, error) { if publicKey.SignatureAlgorithm != [2]byte{'E', 'd'} { return false, errors.New("Incompatible signature algorithm") } prehashed := false if signature.SignatureAlgorithm[0] == 0x45 && signature.SignatureAlgorithm[1] == 0x64 { prehashed = false } else if signature.SignatureAlgorithm[0] == 0x45 && signature.SignatureAlgorithm[1] == 0x44 { prehashed = true } else { return false, errors.New("Unsupported signature algorithm") } if publicKey.KeyId != signature.KeyId { return false, errors.New("Incompatible key identifiers") } if !strings.HasPrefix(signature.TrustedComment, "trusted comment: ") { return false, errors.New("Unexpected format for the trusted comment") } if prehashed { h, _ := blake2b.New512(nil) h.Write(bin) bin = h.Sum(nil) } if !ed25519.Verify(ed25519.PublicKey(publicKey.PublicKey[:]), bin, signature.Signature[:]) { return false, errors.New("Invalid signature") } if !ed25519.Verify(ed25519.PublicKey(publicKey.PublicKey[:]), append(signature.Signature[:], []byte(signature.TrustedComment)[17:]...), signature.GlobalSignature[:]) { return false, errors.New("Invalid global signature") } return true, nil } func (publicKey *PublicKey) VerifyFromFile(file string, signature Signature) (bool, error) { bin, err := ioutil.ReadFile(file) if err != nil { return false, err } return publicKey.Verify(bin, signature) } go-minisign-0.2.1/minisign_test.go000066400000000000000000000025521413656147100171510ustar00rootroot00000000000000package minisign import "testing" func TestLegacy(t *testing.T) { pk, err := NewPublicKey("RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3") if err != nil { t.Fatal(err) } sigStr := "untrusted comment: signature from minisign secret key\nRWQf6LRCGA9i59SLOFxz6NxvASXDJeRtuZykwQepbDEGt87ig1BNpWaVWuNrm73YiIiJbq71Wi+dP9eKL8OC351vwIasSSbXxwA=\ntrusted comment: timestamp:1635442742\tfile:test\n0YteLgV960ia80vnA/fHbvkyjl/IoP/HNOCaZfrF0CdhAlp7ok+Tpkya+VpWPX5C/Is3q8a/kEDSY7fBmmgJCg==\n" sig, err := DecodeSignature(sigStr) if err != nil { t.Fatal(err) } v, err := pk.Verify([]byte("test"), sig) if err != nil { t.Fatal(err) } if !v { t.Fatal("signature verification failed") } } func TestPrehashed(t *testing.T) { pk, err := NewPublicKey("RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3") if err != nil { t.Fatal(err) } sigStr := "untrusted comment: signature from minisign secret key\nRUQf6LRCGA9i559r3g7V1qNyJDApGip8MfqcadIgT9CuhV3EMhHoN1mGTkUidF/z7SrlQgXdy8ofjb7bNJJylDOocrCo8KLzZwo=\ntrusted comment: timestamp:1635443258\tfile:test\thashed\n/cj37GK60vryibFn+ftOgbCvW9NKhKYgjVpFFQUcWPAnjO23wrvVDTt7cloNC06maoBli9q6qwZDXXoaxweICQ==\n" sig, err := DecodeSignature(sigStr) if err != nil { t.Fatal(err) } v, err := pk.Verify([]byte("test"), sig) if err != nil { t.Fatal(err) } if !v { t.Fatal("signature verification failed") } }