├── .gitignore ├── CHANGELOG.md ├── LICENSE.txt ├── README.md ├── auth └── auth.go ├── config └── config.go ├── main.go ├── release.py ├── revproxyry_component_test └── main.go ├── sigterm └── sigterm.go ├── vendor.yml └── vendor ├── github.com ├── jimstudt │ └── http-authentication │ │ ├── LICENSE │ │ ├── README.md │ │ ├── basic │ │ ├── README.md │ │ ├── bcrypt.go │ │ ├── bcrypt_test.go │ │ ├── htpasswd.go │ │ ├── htpasswd_test.go │ │ ├── md5.go │ │ ├── md5_test.go │ │ ├── plain.go │ │ ├── plain_test.go │ │ ├── sha.go │ │ ├── sha_test.go │ │ ├── util.go │ │ └── util_test.go │ │ └── digest │ │ ├── README.md │ │ ├── digest.go │ │ ├── digest_test.go │ │ ├── htdigest-user-store.go │ │ ├── parse.go │ │ ├── simple-nonce-store.go │ │ ├── simple-nonce.go │ │ └── simple-user-store.go └── phayes │ └── freeport │ ├── .goreleaser.yml │ ├── LICENSE.md │ ├── README.md │ ├── cmd │ └── freeport │ │ └── main.go │ ├── freeport.go │ └── freeport_test.go └── golang.org └── x └── crypto ├── .gitattributes ├── AUTHORS ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── LICENSE ├── PATENTS ├── README.md ├── acme ├── acme.go ├── acme_test.go ├── autocert │ ├── autocert.go │ ├── autocert_test.go │ ├── cache.go │ ├── cache_test.go │ ├── example_test.go │ ├── internal │ │ └── acmetest │ │ │ └── ca.go │ ├── listener.go │ ├── renewal.go │ └── renewal_test.go ├── http.go ├── http_test.go ├── internal │ └── acmeprobe │ │ └── prober.go ├── jws.go ├── jws_test.go ├── rfc8555.go ├── rfc8555_test.go ├── types.go ├── types_test.go └── version_go112.go ├── argon2 ├── argon2.go ├── argon2_test.go ├── blake2b.go ├── blamka_amd64.go ├── blamka_amd64.s ├── blamka_generic.go └── blamka_ref.go ├── bcrypt ├── base64.go ├── bcrypt.go └── bcrypt_test.go ├── blake2b ├── blake2b.go ├── blake2bAVX2_amd64.go ├── blake2bAVX2_amd64.s ├── blake2b_amd64.go ├── blake2b_amd64.s ├── blake2b_generic.go ├── blake2b_ref.go ├── blake2b_test.go ├── blake2x.go └── register.go ├── blake2s ├── blake2s.go ├── blake2s_386.go ├── blake2s_386.s ├── blake2s_amd64.go ├── blake2s_amd64.s ├── blake2s_generic.go ├── blake2s_ref.go ├── blake2s_test.go ├── blake2x.go └── register.go ├── blowfish ├── block.go ├── blowfish_test.go ├── cipher.go └── const.go ├── bn256 ├── bn256.go ├── bn256_test.go ├── constants.go ├── curve.go ├── example_test.go ├── gfp12.go ├── gfp2.go ├── gfp6.go ├── optate.go └── twist.go ├── cast5 ├── cast5.go └── cast5_test.go ├── chacha20 ├── chacha_arm64.go ├── chacha_arm64.s ├── chacha_generic.go ├── chacha_noasm.go ├── chacha_ppc64le.go ├── chacha_ppc64le.s ├── chacha_s390x.go ├── chacha_s390x.s ├── chacha_test.go ├── vectors_test.go └── xor.go ├── chacha20poly1305 ├── chacha20poly1305.go ├── chacha20poly1305_amd64.go ├── chacha20poly1305_amd64.s ├── chacha20poly1305_generic.go ├── chacha20poly1305_noasm.go ├── chacha20poly1305_test.go ├── chacha20poly1305_vectors_test.go └── xchacha20poly1305.go ├── codereview.cfg ├── cryptobyte ├── asn1.go ├── asn1 │ └── asn1.go ├── asn1_test.go ├── builder.go ├── cryptobyte_test.go ├── example_test.go └── string.go ├── curve25519 ├── curve25519.go ├── curve25519_amd64.go ├── curve25519_amd64.s ├── curve25519_generic.go ├── curve25519_noasm.go ├── curve25519_test.go └── vectors_test.go ├── ed25519 ├── ed25519.go ├── ed25519_go113.go ├── ed25519_test.go ├── go113_test.go ├── internal │ └── edwards25519 │ │ ├── const.go │ │ └── edwards25519.go └── testdata │ └── sign.input.gz ├── go.mod ├── go.sum ├── hkdf ├── example_test.go ├── hkdf.go └── hkdf_test.go ├── internal ├── subtle │ ├── aliasing.go │ ├── aliasing_appengine.go │ └── aliasing_test.go └── wycheproof │ ├── README.md │ ├── dsa_test.go │ ├── ecdsa_test.go │ ├── eddsa_test.go │ ├── internal │ ├── dsa │ │ └── dsa.go │ └── ecdsa │ │ └── ecdsa.go │ ├── rsa_pss_test.go │ ├── rsa_signature_test.go │ └── wycheproof_test.go ├── md4 ├── example_test.go ├── md4.go ├── md4_test.go └── md4block.go ├── nacl ├── auth │ ├── auth.go │ ├── auth_test.go │ └── example_test.go ├── box │ ├── box.go │ ├── box_test.go │ └── example_test.go ├── secretbox │ ├── example_test.go │ ├── secretbox.go │ └── secretbox_test.go └── sign │ ├── sign.go │ └── sign_test.go ├── ocsp ├── ocsp.go └── ocsp_test.go ├── openpgp ├── armor │ ├── armor.go │ ├── armor_test.go │ └── encode.go ├── canonical_text.go ├── canonical_text_test.go ├── clearsign │ ├── clearsign.go │ └── clearsign_test.go ├── elgamal │ ├── elgamal.go │ └── elgamal_test.go ├── errors │ └── errors.go ├── keys.go ├── keys_data_test.go ├── keys_test.go ├── packet │ ├── compressed.go │ ├── compressed_test.go │ ├── config.go │ ├── encrypted_key.go │ ├── encrypted_key_test.go │ ├── literal.go │ ├── ocfb.go │ ├── ocfb_test.go │ ├── one_pass_signature.go │ ├── opaque.go │ ├── opaque_test.go │ ├── packet.go │ ├── packet_test.go │ ├── private_key.go │ ├── private_key_test.go │ ├── public_key.go │ ├── public_key_test.go │ ├── public_key_v3.go │ ├── public_key_v3_test.go │ ├── reader.go │ ├── signature.go │ ├── signature_test.go │ ├── signature_v3.go │ ├── signature_v3_test.go │ ├── symmetric_key_encrypted.go │ ├── symmetric_key_encrypted_test.go │ ├── symmetrically_encrypted.go │ ├── symmetrically_encrypted_test.go │ ├── userattribute.go │ ├── userattribute_test.go │ ├── userid.go │ └── userid_test.go ├── read.go ├── read_test.go ├── s2k │ ├── s2k.go │ └── s2k_test.go ├── write.go └── write_test.go ├── otr ├── libotr_test_helper.c ├── otr.go ├── otr_test.go └── smp.go ├── pbkdf2 ├── pbkdf2.go └── pbkdf2_test.go ├── pkcs12 ├── bmp-string.go ├── bmp-string_test.go ├── crypto.go ├── crypto_test.go ├── errors.go ├── internal │ └── rc2 │ │ ├── bench_test.go │ │ ├── rc2.go │ │ └── rc2_test.go ├── mac.go ├── mac_test.go ├── pbkdf.go ├── pbkdf_test.go ├── pkcs12.go ├── pkcs12_test.go └── safebags.go ├── poly1305 ├── bits_compat.go ├── bits_go1.13.go ├── mac_noasm.go ├── poly1305.go ├── poly1305_test.go ├── sum_amd64.go ├── sum_amd64.s ├── sum_generic.go ├── sum_noasm.go ├── sum_ppc64le.go ├── sum_ppc64le.s ├── sum_s390x.go ├── sum_s390x.s ├── sum_vmsl_s390x.s └── vectors_test.go ├── ripemd160 ├── ripemd160.go ├── ripemd160_test.go └── ripemd160block.go ├── salsa20 ├── salsa │ ├── hsalsa20.go │ ├── salsa208.go │ ├── salsa20_amd64.go │ ├── salsa20_amd64.s │ ├── salsa20_amd64_test.go │ ├── salsa20_noasm.go │ ├── salsa20_ref.go │ └── salsa_test.go ├── salsa20.go └── salsa20_test.go ├── scrypt ├── example_test.go ├── scrypt.go └── scrypt_test.go ├── sha3 ├── doc.go ├── hashes.go ├── hashes_generic.go ├── keccakf.go ├── keccakf_amd64.go ├── keccakf_amd64.s ├── register.go ├── sha3.go ├── sha3_s390x.go ├── sha3_s390x.s ├── sha3_test.go ├── shake.go ├── shake_generic.go ├── testdata │ └── keccakKats.json.deflate ├── xor.go ├── xor_generic.go └── xor_unaligned.go ├── ssh ├── agent │ ├── client.go │ ├── client_test.go │ ├── example_test.go │ ├── forward.go │ ├── keyring.go │ ├── keyring_test.go │ ├── server.go │ ├── server_test.go │ └── testdata_test.go ├── benchmark_test.go ├── buffer.go ├── buffer_test.go ├── certs.go ├── certs_test.go ├── channel.go ├── cipher.go ├── cipher_test.go ├── client.go ├── client_auth.go ├── client_auth_test.go ├── client_test.go ├── common.go ├── common_test.go ├── connection.go ├── doc.go ├── example_test.go ├── handshake.go ├── handshake_test.go ├── kex.go ├── kex_test.go ├── keys.go ├── keys_test.go ├── knownhosts │ ├── knownhosts.go │ └── knownhosts_test.go ├── mac.go ├── mempipe_test.go ├── messages.go ├── messages_test.go ├── mux.go ├── mux_test.go ├── server.go ├── session.go ├── session_test.go ├── ssh_gss.go ├── ssh_gss_test.go ├── streamlocal.go ├── tcpip.go ├── tcpip_test.go ├── terminal │ ├── terminal.go │ ├── terminal_test.go │ ├── util.go │ ├── util_aix.go │ ├── util_bsd.go │ ├── util_linux.go │ ├── util_plan9.go │ ├── util_solaris.go │ └── util_windows.go ├── test │ ├── agent_unix_test.go │ ├── banner_test.go │ ├── cert_test.go │ ├── dial_unix_test.go │ ├── doc.go │ ├── forward_unix_test.go │ ├── multi_auth_test.go │ ├── session_test.go │ ├── sshd_test_pw.c │ ├── test_unix_test.go │ └── testdata_test.go ├── testdata │ ├── doc.go │ └── keys.go ├── testdata_test.go ├── transport.go └── transport_test.go ├── tea ├── cipher.go └── tea_test.go ├── twofish ├── twofish.go └── twofish_test.go ├── xtea ├── block.go ├── cipher.go └── xtea_test.go └── xts ├── xts.go └── xts_test.go /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changlog 2 | 3 | ## 1.0.7 4 | * Vendored the dependencies and updated them to the latest ones. 5 | 6 | ## 1.0.6 7 | * Vendored the dependencies and updated them to the latest ones. 8 | 9 | ## 1.0.5 10 | * Root ("/") prefix is handled by revproxyry only if not specified in the configuration. 11 | 12 | ## 1.0.4 13 | * Added the path to the config in the config error message 14 | 15 | ## 1.0.3 16 | * Moved to github.com 17 | 18 | ## 1.0.2 19 | * Authentication registry maps authentications by user name instead of authentication ID. 20 | 21 | ## 1.0.1 22 | * Refactored revproxyhashry to a [separate repository](https://bitbucket.org/parqueryopen/revproxyhashry). 23 | 24 | Since this change did not affect the interface of the _revproxyry_, we decided not to bump the major 25 | version. 26 | 27 | * Refactored authentication, config and sigterm to a separate package 28 | * Added component test 29 | 30 | 31 | ## 1.0.0 32 | * Initial version 33 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Parquery AG 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /sigterm/sigterm.go: -------------------------------------------------------------------------------- 1 | package sigterm 2 | 3 | import ( 4 | "os" 5 | "os/signal" 6 | "syscall" 7 | "sync/atomic" 8 | ) 9 | 10 | var receivedSIGTERM = int32(0) 11 | 12 | // RegisterHandler registers the handler for the SIGTERM signal. 13 | func RegisterSIGTERMHandler() { 14 | c := make(chan os.Signal, 1) 15 | signal.Notify(c, os.Interrupt, syscall.SIGTERM) 16 | go func() { 17 | <-c 18 | atomic.AddInt32(&receivedSIGTERM, 1) 19 | }() 20 | } 21 | 22 | // Done returns true when a SIGTERM signal has been received. 23 | func ReceivedSIGTERM() bool { 24 | return atomic.LoadInt32(&receivedSIGTERM) > 0 25 | } 26 | -------------------------------------------------------------------------------- /vendor.yml: -------------------------------------------------------------------------------- 1 | vendors: 2 | - path: github.com/jimstudt/http-authentication 3 | rev: 3eca13d6893afd7ecabe15f4445f5d2872a1b012 4 | - path: github.com/phayes/freeport 5 | rev: 95f893ade6f232a5f1511d61735d89b1ae2df543 6 | - path: golang.org/x/crypto 7 | rev: 61a87790db17894570dfb32dbaa0a4af9ce60cb4 8 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jim Studt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/README.md: -------------------------------------------------------------------------------- 1 | http-authentication 2 | =================== 3 | 4 | Go implementation of RFC 2617 HTTP Authentication: Basic and Digest Access Authentication 5 | 6 | You will want to include one or both of the packages depending on your requirements. 7 | 8 | ~~~~ go 9 | import "github/jimstudt/http-authentication/basic" 10 | import "github/jimstudt/http-authentication/digest" 11 | ~~~~ 12 | 13 | The packages are documented in their own directories. -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/basic/README.md: -------------------------------------------------------------------------------- 1 | # auth/htpasswd [![GoDoc](https://godoc.org/github.com/jimstudt/http-authentication/basic?status.png)](http://godoc.org/github.com/jimstudt/http-authentication/basic) 2 | 3 | Authenticate using Apache-style htpasswd files and HTTP Basic Authentication. 4 | 5 | `htpasswd` has supported a number of different password hashing schemes over the 6 | decades. Most common and sane ones are supported directly. For some you will need 7 | to add another package. 8 | 9 | | Style | Status | 10 | |-------|--------| 11 | | plain | yes+ | 12 | | md5 | yes | 13 | | sha | yes | 14 | | crypt | no (conflicts with plain) | 15 | | bcrypt | no (can add with another package) | 16 | 17 | The standard set of systems will use *Plain*, *Sha*, and *MD5* systems while filtering out *bcrypt*. 18 | Because of its complexity, *bcrypt* will be in another package which you can import and 19 | add if you need it. *Plain* accepts both Apache style plain text and nginx style where the 20 | password is preceded by {PLAIN}. 21 | 22 | ## Usage 23 | 24 | ~~~ go 25 | import ( 26 | "github.com/codegangsta/martini" 27 | "github.com/jimstudt/http-authentication/basic" 28 | "log" 29 | ) 30 | 31 | func main() { 32 | m := martini.Classic() 33 | 34 | pw,err := basic.New("My Realm", "./my-htpasswd-file", htpasswd.DefaultSystems, nil) 35 | if ( err != nil) { 36 | log.Fatalf("Unable to read my htpassword file: %s", err.Error()) 37 | } 38 | 39 | // authenticate every request 40 | m.Use( pw.ServeHTTP) 41 | 42 | // You will also want to call pw.Reload(nil) to reprocess the password file when it changes. 43 | 44 | // You can use pw.ReloadOn( syscall.SIGHUP, nil ) to make it automatically 45 | // reload on a HUP signal. 46 | 47 | // And those 'nil' arguments are where you pass a function to be notified about illegally 48 | // formatted entries, or unsupported hash systems. See the API documents. 49 | 50 | // If you only want to authenticate some requests, then it goes like this... 51 | // m.Get("/secure/thing", pw.ServeHTTP, myRealHandler) 52 | // ... if pw.ServeHTTP does the 401 then your handler will not be called 53 | 54 | m.Run() 55 | 56 | } 57 | ~~~ 58 | 59 | ## API Documentation 60 | 61 | The API is documented using godoc and also available at [godoc.org](http://godoc.org/github.com/jimstudt/http-authentication/basic) 62 | ~~~ 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/basic/bcrypt.go: -------------------------------------------------------------------------------- 1 | package basic 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | // Reject any password encoded using bcrypt. 9 | func RejectBcrypt(src string) (EncodedPasswd, error) { 10 | if strings.HasPrefix(src, "$2y$") { 11 | return nil, fmt.Errorf("bcrypt passwords are not accepted: %s", src) 12 | } 13 | 14 | return nil, nil 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/basic/bcrypt_test.go: -------------------------------------------------------------------------------- 1 | package basic 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func Test_Bcrypt(t *testing.T) { 8 | testParserGood(t, "bcrypt", nil, RejectBcrypt, "$2y$05$NqR6p/K60C40W08.LDCTNeLpSC.gVVkadaLXysS5Y.nGNPltVacSi", "bar") 9 | testParserBad(t, "bcrypt", nil, RejectBcrypt, "$2y$0") 10 | testParserNot(t, "bcrypt", nil, RejectBcrypt, "plaintext") 11 | } 12 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/basic/plain.go: -------------------------------------------------------------------------------- 1 | package basic 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type plainPassword struct { 8 | password string 9 | } 10 | 11 | // Accept any password in the plain text encoding. 12 | // Be careful: This matches any line, so it *must* be the last parser in you list. 13 | func AcceptPlain(pw string) (EncodedPasswd, error) { 14 | return &plainPassword{pw}, nil 15 | } 16 | 17 | // Reject any plain text encoded passoword. 18 | // Be careful: This matches any line, so it *must* be the last parser in you list. 19 | func RejectPlain(pw string) (EncodedPasswd, error) { 20 | return nil, fmt.Errorf("plain password rejected: %s", pw) 21 | } 22 | 23 | func (p *plainPassword) MatchesPassword(pw string) bool { 24 | // Notice: nginx prefixes plain passwords with {PLAIN}, so we see if that would 25 | // let us match too. I'd split {PLAIN} off, but someone probably uses that 26 | // in their password. It's a big planet. 27 | return constantTimeEquals(pw, p.password) || constantTimeEquals("{PLAIN}"+pw, p.password) 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/basic/plain_test.go: -------------------------------------------------------------------------------- 1 | package basic 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func Test_Plain(t *testing.T) { 8 | testParserGood(t, "plain", AcceptPlain, RejectPlain, "bar", "bar") 9 | //testParserBad() plain takes anything 10 | // testParserNot() plain takes anything 11 | } 12 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/basic/sha.go: -------------------------------------------------------------------------------- 1 | package basic 2 | 3 | import ( 4 | "crypto/sha1" 5 | "crypto/subtle" 6 | "encoding/base64" 7 | "fmt" 8 | "strings" 9 | ) 10 | 11 | type shaPassword struct { 12 | hashed []byte 13 | } 14 | 15 | // Accept valid SHA encoded passwords. 16 | func AcceptSha(src string) (EncodedPasswd, error) { 17 | if !strings.HasPrefix(src, "{SHA}") { 18 | return nil, nil 19 | } 20 | 21 | b64 := strings.TrimPrefix(src, "{SHA}") 22 | hashed, err := base64.StdEncoding.DecodeString(b64) 23 | if err != nil { 24 | return nil, fmt.Errorf("Malformed sha1(%s): %s", src, err.Error()) 25 | } 26 | if len(hashed) != sha1.Size { 27 | return nil, fmt.Errorf("Malformed sha1(%s): wrong length", src) 28 | } 29 | return &shaPassword{hashed}, nil 30 | } 31 | 32 | // Reject any password encoded as SHA. 33 | func RejectSha(src string) (EncodedPasswd, error) { 34 | if !strings.HasPrefix(src, "{SHA}") { 35 | return nil, nil 36 | } 37 | return nil, fmt.Errorf("sha password rejected: %s", src) 38 | } 39 | 40 | func (s *shaPassword) MatchesPassword(pw string) bool { 41 | h := sha1.Sum([]byte(pw)) 42 | return subtle.ConstantTimeCompare(h[:], s.hashed) == 1 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/basic/util.go: -------------------------------------------------------------------------------- 1 | package basic 2 | 3 | import ( 4 | "crypto/sha1" 5 | "crypto/subtle" 6 | ) 7 | 8 | func constantTimeEquals(a string, b string) bool { 9 | // compare SHA-1 as a gatekeeper in constant time 10 | // then check that we didn't get by because of a collision 11 | aSha := sha1.Sum([]byte(a)) 12 | bSha := sha1.Sum([]byte(b)) 13 | if subtle.ConstantTimeCompare(aSha[:], bSha[:]) == 1 { 14 | // yes, this bit isn't constant, but you had to make a Sha1 collision to get here 15 | return a == b 16 | } 17 | return false 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/basic/util_test.go: -------------------------------------------------------------------------------- 1 | package basic 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func testParserGood(t *testing.T, name string, accept PasswdParser, reject PasswdParser, hashed string, passwd string) { 8 | if accept != nil { 9 | ep, err := accept(hashed) 10 | if err != nil { 11 | t.Errorf("%s accept (%s) failed to parse: %s", name, hashed, err.Error()) 12 | } else if ep == nil { 13 | t.Errorf("%s accept (%s) failed to yield an EncodedPasswd", name, hashed) 14 | } else { 15 | if !ep.MatchesPassword(passwd) { 16 | t.Errorf("%s accept (%s) failed to match password (%s)", name, hashed, passwd) 17 | } 18 | if ep.MatchesPassword(passwd + "not") { 19 | t.Errorf("%s accept (%s) failed by matching password (%s)", name, hashed, passwd+"not") 20 | } 21 | } 22 | } 23 | 24 | if reject != nil { 25 | ep, err := reject(hashed) 26 | if ep != nil { 27 | t.Errorf("%s reject (%s) yielded an EncodedPasswd", name, hashed) 28 | } else if err == nil { 29 | t.Errorf("%s reject (%s) did not return an error", name, hashed) 30 | } 31 | } 32 | } 33 | 34 | func testParserBad(t *testing.T, name string, accept PasswdParser, reject PasswdParser, hashed string) { 35 | if accept != nil { 36 | ep, err := accept(hashed) 37 | if ep != nil { 38 | t.Errorf("%s accept (%s) yielded a EncodedPasswd", name, hashed) 39 | } else if err == nil { 40 | t.Errorf("%s accept (%s) did not return an error", name, hashed) 41 | } 42 | } 43 | if reject != nil { 44 | ep, err := reject(hashed) 45 | if ep != nil { 46 | t.Errorf("%s reject (%s) yielded a EncodedPasswd", name, hashed) 47 | } else if err == nil { 48 | t.Errorf("%s reject (%s) did not return an error", name, hashed) 49 | } 50 | } 51 | } 52 | 53 | func testParserNot(t *testing.T, name string, accept PasswdParser, reject PasswdParser, hashed string) { 54 | if accept != nil { 55 | ep, err := accept(hashed) 56 | if ep != nil { 57 | t.Errorf("%s accept (%s) yielded a EncodedPasswd", name, hashed) 58 | } else if err != nil { 59 | t.Errorf("%s accept (%s) errored instead of ignoring", name, hashed) 60 | } 61 | } 62 | if reject != nil { 63 | ep, err := reject(hashed) 64 | if ep != nil { 65 | t.Errorf("%s reject (%s) yielded a EncodedPasswd", name, hashed) 66 | } else if err != nil { 67 | t.Errorf("%s reject (%s) errored instead of ignoring", name, hashed) 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/digest/htdigest-user-store.go: -------------------------------------------------------------------------------- 1 | package digest 2 | 3 | import ( 4 | "encoding/csv" 5 | "fmt" 6 | "io" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "strings" 11 | "sync" 12 | ) 13 | 14 | var _ = log.Print 15 | 16 | // Use an htdigest file from apache's htdigest command as a source of user authentication 17 | // As provided it will read the file once. You may invoke .Reload() if you wish to track changes, 18 | // perhaps in response to fsnotify. 19 | type HtdigestUserStore struct { 20 | simpleUserStore 21 | mutex sync.Mutex 22 | filename string 23 | } 24 | 25 | // Reload the htdigest's file. If there is an error, the old data will be kept instead. 26 | // This function is thread safe. 27 | func (us *HtdigestUserStore) Reload(onbad BadLineHandler) error { 28 | f, err := os.Open(us.filename) 29 | if err != nil { 30 | return err 31 | } 32 | defer f.Close() 33 | 34 | c := csv.NewReader(f) 35 | c.Comma = ':' 36 | c.Comment = '#' 37 | c.TrimLeadingSpace = true 38 | c.FieldsPerRecord = -1 // don't check 39 | 40 | n := map[string]string{} 41 | for { 42 | r, err := c.Read() 43 | if err == io.EOF { 44 | break 45 | } 46 | if err != nil { 47 | return err 48 | } 49 | 50 | if len(r) != 3 { 51 | if onbad != nil { 52 | // sad error message, there is some wreckage of better errors in encoding/csv, but 53 | // I'm not sure it is in use anymore. 54 | onbad(fmt.Errorf("line is not three fields: %v", r)) 55 | } 56 | // skip this line, it isn't three fields 57 | continue 58 | } 59 | 60 | n[r[0]+":"+r[1]] = strings.TrimSpace(r[2]) // might have trailing space 61 | } 62 | 63 | us.mutex.Lock() 64 | defer us.mutex.Unlock() 65 | 66 | us.userToHA1 = n 67 | return nil 68 | } 69 | 70 | // Reload the htdigest's file on a signal. If there is an error, the old data will be kept instead. 71 | // Typically you would use syscall.SIGHUP for the value of "when" 72 | func (us *HtdigestUserStore) ReloadOn(when os.Signal, onbad BadLineHandler) { 73 | // this is rather common with code in htpasswd, but I don't have a common area... 74 | c := make(chan os.Signal, 1) 75 | signal.Notify(c, when) 76 | 77 | go func() { 78 | for { 79 | _ = <-c 80 | log.Printf("Reloading!") 81 | us.Reload(onbad) 82 | } 83 | }() 84 | } 85 | 86 | // Create a new UserStore loaded from an Apache style htdigest file. 87 | func NewHtdigestUserStore(filename string, onbad BadLineHandler) (*HtdigestUserStore, error) { 88 | us := HtdigestUserStore{ 89 | simpleUserStore: simpleUserStore{userToHA1: map[string]string{}}, 90 | filename: filename, 91 | } 92 | if err := us.Reload(onbad); err != nil { 93 | return nil, err 94 | } else { 95 | return &us, nil 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/digest/simple-nonce-store.go: -------------------------------------------------------------------------------- 1 | package digest 2 | 3 | import ( 4 | "log" 5 | "sync" 6 | "testing" 7 | "time" 8 | ) 9 | 10 | type simpleNonceStore struct { 11 | mutex sync.Mutex 12 | nonces map[string]Nonce 13 | elderlyNonces map[string]Nonce 14 | expirationInterval time.Duration 15 | nextExpiration time.Time 16 | } 17 | 18 | func newSimpleNonceStore() *simpleNonceStore { 19 | interval, _ := time.ParseDuration("5s") 20 | if interval == 0 { 21 | panic("Unable to parse duration") 22 | } 23 | 24 | return &simpleNonceStore{ 25 | nonces: map[string]Nonce{}, 26 | elderlyNonces: map[string]Nonce{}, 27 | expirationInterval: interval, 28 | nextExpiration: time.Now().Add(interval), 29 | } 30 | } 31 | 32 | func (s *simpleNonceStore) Add(nonce Nonce) error { 33 | s.mutex.Lock() 34 | defer s.mutex.Unlock() 35 | 36 | s.nonces[nonce.Value()] = nonce 37 | 38 | return nil 39 | } 40 | 41 | func (s *simpleNonceStore) Lookup(value string) (Nonce, bool, error) { 42 | s.mutex.Lock() 43 | defer s.mutex.Unlock() 44 | 45 | now := time.Now() 46 | 47 | // that second || part catches that the system clock has moved more than an interval into the past 48 | // we are going to need a new expiration time or we'd wait for a potentially very long time 49 | togo := s.nextExpiration.Sub(now).Seconds() 50 | if togo < 0 || togo > s.expirationInterval.Seconds() { 51 | if testing.Verbose() { 52 | log.Printf("expiring nonces, interval=%#v:", s.expirationInterval) 53 | for k, _ := range s.elderlyNonces { 54 | log.Printf(" %#v", k) 55 | } 56 | } 57 | s.elderlyNonces = s.nonces 58 | s.nonces = map[string]Nonce{} 59 | s.nextExpiration = now.Add(s.expirationInterval) 60 | } 61 | 62 | // look in the current ones 63 | if n, found := s.nonces[value]; found { 64 | return n, true, nil 65 | } 66 | 67 | // look in the elderly ones 68 | if en, found := s.elderlyNonces[value]; found { 69 | // still in use, move it to the current nonces 70 | s.nonces[value] = en 71 | 72 | // don't bother to purge it from elderly, just makes memory load and it 73 | // is about to go away. 74 | return en, true, nil 75 | } 76 | 77 | // not found 78 | return nil, false, nil 79 | } 80 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/digest/simple-nonce.go: -------------------------------------------------------------------------------- 1 | package digest 2 | 3 | import ( 4 | "crypto/rand" 5 | "encoding/hex" 6 | "sync" 7 | ) 8 | 9 | type simpleNonce struct { 10 | mutex sync.Mutex 11 | value string 12 | next Nonce 13 | expired bool 14 | graceUses int // after expired, decremented on each expire() called from AcceptCounter() 15 | countersSeen map[uint]bool 16 | } 17 | 18 | func newSimpleNonce() (Nonce, error) { 19 | size := 8 // 64 bits sounds good 20 | b := make([]byte, size) 21 | count, err := rand.Read(b) 22 | if count < size || err != nil { 23 | panic("rand.Read failed") 24 | } 25 | 26 | return &simpleNonce{value: hex.EncodeToString(b), countersSeen: map[uint]bool{}}, nil 27 | } 28 | 29 | func (n *simpleNonce) Value() string { 30 | // no lock, never changes 31 | return n.value 32 | } 33 | 34 | func (n *simpleNonce) Next() Nonce { 35 | n.mutex.Lock() 36 | defer n.mutex.Unlock() 37 | 38 | return n.next 39 | } 40 | 41 | func (n *simpleNonce) Stale() bool { 42 | n.mutex.Lock() 43 | defer n.mutex.Unlock() 44 | 45 | return n.expired && n.graceUses <= 0 46 | } 47 | 48 | func (n *simpleNonce) AcceptCounter(c uint) bool { 49 | n.mutex.Lock() 50 | defer n.mutex.Unlock() 51 | 52 | if n.countersSeen[c] { 53 | return false 54 | } 55 | n.countersSeen[c] = true 56 | 57 | // Don't let our map get too big. 58 | if len(n.countersSeen) > 100 { 59 | n.Expire() 60 | } 61 | return true 62 | } 63 | 64 | func (n *simpleNonce) Expire() { 65 | if !n.expired { 66 | n.expired = true 67 | n.graceUses = 10 68 | } else { 69 | n.graceUses -= 1 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /vendor/github.com/jimstudt/http-authentication/digest/simple-user-store.go: -------------------------------------------------------------------------------- 1 | package digest 2 | 3 | import () 4 | 5 | // A simpleUserStore uses a map to lookup strings of "user:realm" into "ha1" 6 | type simpleUserStore struct { 7 | userToHA1 map[string]string 8 | } 9 | 10 | // Create a simple UserStore. You will pass in a map of the form { "username:realm": "md5(username:realm:password)", ... } 11 | // It will be used to answer .Lookup() queries. The map is NOT copied. You could alter it if you wished to track new 12 | // accounts or password changes, though I suggest you make your own implementation of UserStore instead of going that route. 13 | // Spare your code readers. 14 | func NewSimpleUserStore(users map[string]string) UserStore { 15 | us := simpleUserStore{userToHA1: users} 16 | return &us 17 | } 18 | func (us *simpleUserStore) Lookup(user string, realm string) (string, bool, error) { 19 | ha1, ok := us.userToHA1[user+":"+realm] 20 | if ok { 21 | return ha1, true, nil 22 | } else { 23 | return "", false, nil 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/phayes/freeport/LICENSE.md: -------------------------------------------------------------------------------- 1 | Open Source License (BSD 3-Clause) 2 | ---------------------------------- 3 | 4 | Copyright (c) 2014, Patrick Hayes / HighWire Press 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 12 | 13 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 | -------------------------------------------------------------------------------- /vendor/github.com/phayes/freeport/README.md: -------------------------------------------------------------------------------- 1 | FreePort 2 | ======== 3 | 4 | Get a free open TCP port that is ready to use. 5 | 6 | ## Command Line Example: 7 | ```bash 8 | # Ask the kernel to give us an open port. 9 | export port=$(freeport) 10 | 11 | # Start standalone httpd server for testing 12 | httpd -X -c "Listen $port" & 13 | 14 | # Curl local server on the selected port 15 | curl localhost:$port 16 | ``` 17 | 18 | ## Golang example: 19 | ```go 20 | package main 21 | 22 | import "github.com/phayes/freeport" 23 | 24 | func main() { 25 | port, err := freeport.GetFreePort() 26 | if err != nil { 27 | log.Fatal(err) 28 | } 29 | // port is ready to listen on 30 | } 31 | 32 | ``` 33 | 34 | ## Installation 35 | 36 | #### Mac OSX 37 | ```bash 38 | brew install phayes/repo/freeport 39 | ``` 40 | 41 | 42 | #### CentOS and other RPM based systems 43 | ```bash 44 | wget https://github.com/phayes/freeport/releases/download/1.0.2/freeport_1.0.2_linux_386.rpm 45 | rpm -Uvh freeport_1.0.2_linux_386.rpm 46 | ``` 47 | 48 | #### Ubuntu and other DEB based systems 49 | ```bash 50 | wget wget https://github.com/phayes/freeport/releases/download/1.0.2/freeport_1.0.2_linux_amd64.deb 51 | dpkg -i freeport_1.0.2_linux_amd64.deb 52 | ``` 53 | 54 | #### Building From Source 55 | ```bash 56 | sudo apt-get install golang # Download go. Alternativly build from source: https://golang.org/doc/install/source 57 | go get github.com/phayes/freeport 58 | ``` 59 | -------------------------------------------------------------------------------- /vendor/github.com/phayes/freeport/cmd/freeport/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "strconv" 7 | 8 | "github.com/phayes/freeport" 9 | ) 10 | 11 | func main() { 12 | port, err := freeport.GetFreePort() 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | fmt.Println(strconv.Itoa(port)) 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/phayes/freeport/freeport.go: -------------------------------------------------------------------------------- 1 | package freeport 2 | 3 | import ( 4 | "net" 5 | ) 6 | 7 | // GetFreePort asks the kernel for a free open port that is ready to use. 8 | func GetFreePort() (int, error) { 9 | addr, err := net.ResolveTCPAddr("tcp", "localhost:0") 10 | if err != nil { 11 | return 0, err 12 | } 13 | 14 | l, err := net.ListenTCP("tcp", addr) 15 | if err != nil { 16 | return 0, err 17 | } 18 | defer l.Close() 19 | return l.Addr().(*net.TCPAddr).Port, nil 20 | } 21 | 22 | // GetPort is deprecated, use GetFreePort instead 23 | // Ask the kernel for a free open port that is ready to use 24 | func GetPort() int { 25 | port, err := GetFreePort() 26 | if err != nil { 27 | panic(err) 28 | } 29 | return port 30 | } 31 | 32 | // GetFreePort asks the kernel for free open ports that are ready to use. 33 | func GetFreePorts(count int) ([]int, error) { 34 | var ports []int 35 | for i := 0; i < count; i++ { 36 | addr, err := net.ResolveTCPAddr("tcp", "localhost:0") 37 | if err != nil { 38 | return nil, err 39 | } 40 | 41 | l, err := net.ListenTCP("tcp", addr) 42 | if err != nil { 43 | return nil, err 44 | } 45 | defer l.Close() 46 | ports = append(ports, l.Addr().(*net.TCPAddr).Port) 47 | } 48 | return ports, nil 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/phayes/freeport/freeport_test.go: -------------------------------------------------------------------------------- 1 | package freeport 2 | 3 | import ( 4 | "net" 5 | "strconv" 6 | "testing" 7 | ) 8 | 9 | func TestGetFreePort(t *testing.T) { 10 | port, err := GetFreePort() 11 | if err != nil { 12 | t.Error(err) 13 | } 14 | if port == 0 { 15 | t.Error("port == 0") 16 | } 17 | 18 | // Try to listen on the port 19 | l, err := net.Listen("tcp", "localhost"+":"+strconv.Itoa(port)) 20 | if err != nil { 21 | t.Error(err) 22 | } 23 | defer l.Close() 24 | } 25 | 26 | func TestGetFreePorts(t *testing.T) { 27 | count := 3 28 | ports, err := GetFreePorts(count) 29 | if err != nil { 30 | t.Error(err) 31 | } 32 | if len(ports) == 0 { 33 | t.Error("len(ports) == 0") 34 | } 35 | for _, port := range ports { 36 | if port == 0 { 37 | t.Error("port == 0") 38 | } 39 | 40 | // Try to listen on the port 41 | l, err := net.Listen("tcp", "localhost"+":"+strconv.Itoa(port)) 42 | if err != nil { 43 | t.Error(err) 44 | } 45 | defer l.Close() 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/.gitattributes: -------------------------------------------------------------------------------- 1 | # Treat all files in this repo as binary, with no git magic updating 2 | # line endings. Windows users contributing to Go will need to use a 3 | # modern version of git and editors capable of LF line endings. 4 | # 5 | # We'll prevent accidental CRLF line endings from entering the repo 6 | # via the git-review gofmt checks. 7 | # 8 | # See golang.org/issue/9281 9 | 10 | * -text 11 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at https://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Go 2 | 3 | Go is an open source project. 4 | 5 | It is the work of hundreds of contributors. We appreciate your help! 6 | 7 | ## Filing issues 8 | 9 | When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions: 10 | 11 | 1. What version of Go are you using (`go version`)? 12 | 2. What operating system and processor architecture are you using? 13 | 3. What did you do? 14 | 4. What did you expect to see? 15 | 5. What did you see instead? 16 | 17 | General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker. 18 | The gophers there will answer or ask you to file an issue if you've tripped over a bug. 19 | 20 | ## Contributing code 21 | 22 | Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html) 23 | before sending patches. 24 | 25 | Unless otherwise noted, the Go source files are distributed under 26 | the BSD-style license found in the LICENSE file. 27 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at https://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/README.md: -------------------------------------------------------------------------------- 1 | # Go Cryptography 2 | 3 | This repository holds supplementary Go cryptography libraries. 4 | 5 | ## Download/Install 6 | 7 | The easiest way to install is to run `go get -u golang.org/x/crypto/...`. You 8 | can also manually git clone the repository to `$GOPATH/src/golang.org/x/crypto`. 9 | 10 | ## Report Issues / Send Patches 11 | 12 | This repository uses Gerrit for code changes. To learn how to submit changes to 13 | this repository, see https://golang.org/doc/contribute.html. 14 | 15 | The main issue tracker for the crypto repository is located at 16 | https://github.com/golang/go/issues. Prefix your issue with "x/crypto:" in the 17 | subject line, so it is easy to find. 18 | 19 | Note that contributions to the cryptography package receive additional scrutiny 20 | due to their sensitive nature. Patches may take longer than normal to receive 21 | feedback. 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/acme/autocert/cache_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package autocert 6 | 7 | import ( 8 | "context" 9 | "io/ioutil" 10 | "os" 11 | "path/filepath" 12 | "reflect" 13 | "testing" 14 | ) 15 | 16 | // make sure DirCache satisfies Cache interface 17 | var _ Cache = DirCache("/") 18 | 19 | func TestDirCache(t *testing.T) { 20 | dir, err := ioutil.TempDir("", "autocert") 21 | if err != nil { 22 | t.Fatal(err) 23 | } 24 | defer os.RemoveAll(dir) 25 | dir = filepath.Join(dir, "certs") // a nonexistent dir 26 | cache := DirCache(dir) 27 | ctx := context.Background() 28 | 29 | // test cache miss 30 | if _, err := cache.Get(ctx, "nonexistent"); err != ErrCacheMiss { 31 | t.Errorf("get: %v; want ErrCacheMiss", err) 32 | } 33 | 34 | // test put/get 35 | b1 := []byte{1} 36 | if err := cache.Put(ctx, "dummy", b1); err != nil { 37 | t.Fatalf("put: %v", err) 38 | } 39 | b2, err := cache.Get(ctx, "dummy") 40 | if err != nil { 41 | t.Fatalf("get: %v", err) 42 | } 43 | if !reflect.DeepEqual(b1, b2) { 44 | t.Errorf("b1 = %v; want %v", b1, b2) 45 | } 46 | name := filepath.Join(dir, "dummy") 47 | if _, err := os.Stat(name); err != nil { 48 | t.Error(err) 49 | } 50 | 51 | // test put deletes temp file 52 | tmp, err := filepath.Glob(name + "?*") 53 | if err != nil { 54 | t.Error(err) 55 | } 56 | if tmp != nil { 57 | t.Errorf("temp file exists: %s", tmp) 58 | } 59 | 60 | // test delete 61 | if err := cache.Delete(ctx, "dummy"); err != nil { 62 | t.Fatalf("delete: %v", err) 63 | } 64 | if _, err := cache.Get(ctx, "dummy"); err != ErrCacheMiss { 65 | t.Errorf("get: %v; want ErrCacheMiss", err) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/acme/autocert/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package autocert_test 6 | 7 | import ( 8 | "fmt" 9 | "log" 10 | "net/http" 11 | 12 | "golang.org/x/crypto/acme/autocert" 13 | ) 14 | 15 | func ExampleNewListener() { 16 | mux := http.NewServeMux() 17 | mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 18 | fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS) 19 | }) 20 | log.Fatal(http.Serve(autocert.NewListener("example.com"), mux)) 21 | } 22 | 23 | func ExampleManager() { 24 | m := &autocert.Manager{ 25 | Cache: autocert.DirCache("secret-dir"), 26 | Prompt: autocert.AcceptTOS, 27 | HostPolicy: autocert.HostWhitelist("example.org", "www.example.org"), 28 | } 29 | s := &http.Server{ 30 | Addr: ":https", 31 | TLSConfig: m.TLSConfig(), 32 | } 33 | s.ListenAndServeTLS("", "") 34 | } 35 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/acme/types_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package acme 6 | 7 | import ( 8 | "errors" 9 | "net/http" 10 | "testing" 11 | "time" 12 | ) 13 | 14 | func TestRateLimit(t *testing.T) { 15 | now := time.Date(2017, 04, 27, 10, 0, 0, 0, time.UTC) 16 | f := timeNow 17 | defer func() { timeNow = f }() 18 | timeNow = func() time.Time { return now } 19 | 20 | h120, hTime := http.Header{}, http.Header{} 21 | h120.Set("Retry-After", "120") 22 | hTime.Set("Retry-After", "Tue Apr 27 11:00:00 2017") 23 | 24 | err1 := &Error{ 25 | ProblemType: "urn:ietf:params:acme:error:nolimit", 26 | Header: h120, 27 | } 28 | err2 := &Error{ 29 | ProblemType: "urn:ietf:params:acme:error:rateLimited", 30 | Header: h120, 31 | } 32 | err3 := &Error{ 33 | ProblemType: "urn:ietf:params:acme:error:rateLimited", 34 | Header: nil, 35 | } 36 | err4 := &Error{ 37 | ProblemType: "urn:ietf:params:acme:error:rateLimited", 38 | Header: hTime, 39 | } 40 | 41 | tt := []struct { 42 | err error 43 | res time.Duration 44 | ok bool 45 | }{ 46 | {nil, 0, false}, 47 | {errors.New("dummy"), 0, false}, 48 | {err1, 0, false}, 49 | {err2, 2 * time.Minute, true}, 50 | {err3, 0, true}, 51 | {err4, time.Hour, true}, 52 | } 53 | for i, test := range tt { 54 | res, ok := RateLimit(test.err) 55 | if ok != test.ok { 56 | t.Errorf("%d: RateLimit(%+v): ok = %v; want %v", i, test.err, ok, test.ok) 57 | continue 58 | } 59 | if res != test.res { 60 | t.Errorf("%d: RateLimit(%+v) = %v; want %v", i, test.err, res, test.res) 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/acme/version_go112.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.12 6 | 7 | package acme 8 | 9 | import "runtime/debug" 10 | 11 | func init() { 12 | // Set packageVersion if the binary was built in modules mode and x/crypto 13 | // was not replaced with a different module. 14 | info, ok := debug.ReadBuildInfo() 15 | if !ok { 16 | return 17 | } 18 | for _, m := range info.Deps { 19 | if m.Path != "golang.org/x/crypto" { 20 | continue 21 | } 22 | if m.Replace == nil { 23 | packageVersion = m.Version 24 | } 25 | break 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/argon2/blake2b.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package argon2 6 | 7 | import ( 8 | "encoding/binary" 9 | "hash" 10 | 11 | "golang.org/x/crypto/blake2b" 12 | ) 13 | 14 | // blake2bHash computes an arbitrary long hash value of in 15 | // and writes the hash to out. 16 | func blake2bHash(out []byte, in []byte) { 17 | var b2 hash.Hash 18 | if n := len(out); n < blake2b.Size { 19 | b2, _ = blake2b.New(n, nil) 20 | } else { 21 | b2, _ = blake2b.New512(nil) 22 | } 23 | 24 | var buffer [blake2b.Size]byte 25 | binary.LittleEndian.PutUint32(buffer[:4], uint32(len(out))) 26 | b2.Write(buffer[:4]) 27 | b2.Write(in) 28 | 29 | if len(out) <= blake2b.Size { 30 | b2.Sum(out[:0]) 31 | return 32 | } 33 | 34 | outLen := len(out) 35 | b2.Sum(buffer[:0]) 36 | b2.Reset() 37 | copy(out, buffer[:32]) 38 | out = out[32:] 39 | for len(out) > blake2b.Size { 40 | b2.Write(buffer[:]) 41 | b2.Sum(buffer[:0]) 42 | copy(out, buffer[:32]) 43 | out = out[32:] 44 | b2.Reset() 45 | } 46 | 47 | if outLen%blake2b.Size > 0 { // outLen > 64 48 | r := ((outLen + 31) / 32) - 2 // ⌈τ /32⌉-2 49 | b2, _ = blake2b.New(outLen-32*r, nil) 50 | } 51 | b2.Write(buffer[:]) 52 | b2.Sum(out[:0]) 53 | } 54 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/argon2/blamka_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,!gccgo,!appengine 6 | 7 | package argon2 8 | 9 | import "golang.org/x/sys/cpu" 10 | 11 | func init() { 12 | useSSE4 = cpu.X86.HasSSE41 13 | } 14 | 15 | //go:noescape 16 | func mixBlocksSSE2(out, a, b, c *block) 17 | 18 | //go:noescape 19 | func xorBlocksSSE2(out, a, b, c *block) 20 | 21 | //go:noescape 22 | func blamkaSSE4(b *block) 23 | 24 | func processBlockSSE(out, in1, in2 *block, xor bool) { 25 | var t block 26 | mixBlocksSSE2(&t, in1, in2, &t) 27 | if useSSE4 { 28 | blamkaSSE4(&t) 29 | } else { 30 | for i := 0; i < blockLength; i += 16 { 31 | blamkaGeneric( 32 | &t[i+0], &t[i+1], &t[i+2], &t[i+3], 33 | &t[i+4], &t[i+5], &t[i+6], &t[i+7], 34 | &t[i+8], &t[i+9], &t[i+10], &t[i+11], 35 | &t[i+12], &t[i+13], &t[i+14], &t[i+15], 36 | ) 37 | } 38 | for i := 0; i < blockLength/8; i += 2 { 39 | blamkaGeneric( 40 | &t[i], &t[i+1], &t[16+i], &t[16+i+1], 41 | &t[32+i], &t[32+i+1], &t[48+i], &t[48+i+1], 42 | &t[64+i], &t[64+i+1], &t[80+i], &t[80+i+1], 43 | &t[96+i], &t[96+i+1], &t[112+i], &t[112+i+1], 44 | ) 45 | } 46 | } 47 | if xor { 48 | xorBlocksSSE2(out, in1, in2, &t) 49 | } else { 50 | mixBlocksSSE2(out, in1, in2, &t) 51 | } 52 | } 53 | 54 | func processBlock(out, in1, in2 *block) { 55 | processBlockSSE(out, in1, in2, false) 56 | } 57 | 58 | func processBlockXOR(out, in1, in2 *block) { 59 | processBlockSSE(out, in1, in2, true) 60 | } 61 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/argon2/blamka_ref.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !amd64 appengine gccgo 6 | 7 | package argon2 8 | 9 | func processBlock(out, in1, in2 *block) { 10 | processBlockGeneric(out, in1, in2, false) 11 | } 12 | 13 | func processBlockXOR(out, in1, in2 *block) { 14 | processBlockGeneric(out, in1, in2, true) 15 | } 16 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/bcrypt/base64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bcrypt 6 | 7 | import "encoding/base64" 8 | 9 | const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" 10 | 11 | var bcEncoding = base64.NewEncoding(alphabet) 12 | 13 | func base64Encode(src []byte) []byte { 14 | n := bcEncoding.EncodedLen(len(src)) 15 | dst := make([]byte, n) 16 | bcEncoding.Encode(dst, src) 17 | for dst[n-1] == '=' { 18 | n-- 19 | } 20 | return dst[:n] 21 | } 22 | 23 | func base64Decode(src []byte) ([]byte, error) { 24 | numOfEquals := 4 - (len(src) % 4) 25 | for i := 0; i < numOfEquals; i++ { 26 | src = append(src, '=') 27 | } 28 | 29 | dst := make([]byte, bcEncoding.DecodedLen(len(src))) 30 | n, err := bcEncoding.Decode(dst, src) 31 | if err != nil { 32 | return nil, err 33 | } 34 | return dst[:n], nil 35 | } 36 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.7,amd64,!gccgo,!appengine 6 | 7 | package blake2b 8 | 9 | import "golang.org/x/sys/cpu" 10 | 11 | func init() { 12 | useAVX2 = cpu.X86.HasAVX2 13 | useAVX = cpu.X86.HasAVX 14 | useSSE4 = cpu.X86.HasSSE41 15 | } 16 | 17 | //go:noescape 18 | func hashBlocksAVX2(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) 19 | 20 | //go:noescape 21 | func hashBlocksAVX(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) 22 | 23 | //go:noescape 24 | func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) 25 | 26 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) { 27 | switch { 28 | case useAVX2: 29 | hashBlocksAVX2(h, c, flag, blocks) 30 | case useAVX: 31 | hashBlocksAVX(h, c, flag, blocks) 32 | case useSSE4: 33 | hashBlocksSSE4(h, c, flag, blocks) 34 | default: 35 | hashBlocksGeneric(h, c, flag, blocks) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2b/blake2b_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.7,amd64,!gccgo,!appengine 6 | 7 | package blake2b 8 | 9 | import "golang.org/x/sys/cpu" 10 | 11 | func init() { 12 | useSSE4 = cpu.X86.HasSSE41 13 | } 14 | 15 | //go:noescape 16 | func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) 17 | 18 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) { 19 | if useSSE4 { 20 | hashBlocksSSE4(h, c, flag, blocks) 21 | } else { 22 | hashBlocksGeneric(h, c, flag, blocks) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2b/blake2b_ref.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !amd64 appengine gccgo 6 | 7 | package blake2b 8 | 9 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) { 10 | hashBlocksGeneric(h, c, flag, blocks) 11 | } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2b/register.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.9 6 | 7 | package blake2b 8 | 9 | import ( 10 | "crypto" 11 | "hash" 12 | ) 13 | 14 | func init() { 15 | newHash256 := func() hash.Hash { 16 | h, _ := New256(nil) 17 | return h 18 | } 19 | newHash384 := func() hash.Hash { 20 | h, _ := New384(nil) 21 | return h 22 | } 23 | 24 | newHash512 := func() hash.Hash { 25 | h, _ := New512(nil) 26 | return h 27 | } 28 | 29 | crypto.RegisterHash(crypto.BLAKE2b_256, newHash256) 30 | crypto.RegisterHash(crypto.BLAKE2b_384, newHash384) 31 | crypto.RegisterHash(crypto.BLAKE2b_512, newHash512) 32 | } 33 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2s/blake2s_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build 386,!gccgo,!appengine 6 | 7 | package blake2s 8 | 9 | import "golang.org/x/sys/cpu" 10 | 11 | var ( 12 | useSSE4 = false 13 | useSSSE3 = cpu.X86.HasSSSE3 14 | useSSE2 = cpu.X86.HasSSE2 15 | ) 16 | 17 | //go:noescape 18 | func hashBlocksSSE2(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) 19 | 20 | //go:noescape 21 | func hashBlocksSSSE3(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) 22 | 23 | func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) { 24 | switch { 25 | case useSSSE3: 26 | hashBlocksSSSE3(h, c, flag, blocks) 27 | case useSSE2: 28 | hashBlocksSSE2(h, c, flag, blocks) 29 | default: 30 | hashBlocksGeneric(h, c, flag, blocks) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2s/blake2s_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,!gccgo,!appengine 6 | 7 | package blake2s 8 | 9 | import "golang.org/x/sys/cpu" 10 | 11 | var ( 12 | useSSE4 = cpu.X86.HasSSE41 13 | useSSSE3 = cpu.X86.HasSSSE3 14 | useSSE2 = cpu.X86.HasSSE2 15 | ) 16 | 17 | //go:noescape 18 | func hashBlocksSSE2(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) 19 | 20 | //go:noescape 21 | func hashBlocksSSSE3(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) 22 | 23 | //go:noescape 24 | func hashBlocksSSE4(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) 25 | 26 | func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) { 27 | switch { 28 | case useSSE4: 29 | hashBlocksSSE4(h, c, flag, blocks) 30 | case useSSSE3: 31 | hashBlocksSSSE3(h, c, flag, blocks) 32 | case useSSE2: 33 | hashBlocksSSE2(h, c, flag, blocks) 34 | default: 35 | hashBlocksGeneric(h, c, flag, blocks) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2s/blake2s_ref.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !amd64,!386 gccgo appengine 6 | 7 | package blake2s 8 | 9 | var ( 10 | useSSE4 = false 11 | useSSSE3 = false 12 | useSSE2 = false 13 | ) 14 | 15 | func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) { 16 | hashBlocksGeneric(h, c, flag, blocks) 17 | } 18 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2s/register.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.9 6 | 7 | package blake2s 8 | 9 | import ( 10 | "crypto" 11 | "hash" 12 | ) 13 | 14 | func init() { 15 | newHash256 := func() hash.Hash { 16 | h, _ := New256(nil) 17 | return h 18 | } 19 | 20 | crypto.RegisterHash(crypto.BLAKE2s_256, newHash256) 21 | } 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/bn256/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bn256 6 | 7 | import ( 8 | "math/big" 9 | ) 10 | 11 | func bigFromBase10(s string) *big.Int { 12 | n, _ := new(big.Int).SetString(s, 10) 13 | return n 14 | } 15 | 16 | // u is the BN parameter that determines the prime: 1868033³. 17 | var u = bigFromBase10("6518589491078791937") 18 | 19 | // p is a prime over which we form a basic field: 36u⁴+36u³+24u²+6u+1. 20 | var p = bigFromBase10("65000549695646603732796438742359905742825358107623003571877145026864184071783") 21 | 22 | // Order is the number of elements in both G₁ and G₂: 36u⁴+36u³+18u²+6u+1. 23 | var Order = bigFromBase10("65000549695646603732796438742359905742570406053903786389881062969044166799969") 24 | 25 | // xiToPMinus1Over6 is ξ^((p-1)/6) where ξ = i+3. 26 | var xiToPMinus1Over6 = &gfP2{bigFromBase10("8669379979083712429711189836753509758585994370025260553045152614783263110636"), bigFromBase10("19998038925833620163537568958541907098007303196759855091367510456613536016040")} 27 | 28 | // xiToPMinus1Over3 is ξ^((p-1)/3) where ξ = i+3. 29 | var xiToPMinus1Over3 = &gfP2{bigFromBase10("26098034838977895781559542626833399156321265654106457577426020397262786167059"), bigFromBase10("15931493369629630809226283458085260090334794394361662678240713231519278691715")} 30 | 31 | // xiToPMinus1Over2 is ξ^((p-1)/2) where ξ = i+3. 32 | var xiToPMinus1Over2 = &gfP2{bigFromBase10("50997318142241922852281555961173165965672272825141804376761836765206060036244"), bigFromBase10("38665955945962842195025998234511023902832543644254935982879660597356748036009")} 33 | 34 | // xiToPSquaredMinus1Over3 is ξ^((p²-1)/3) where ξ = i+3. 35 | var xiToPSquaredMinus1Over3 = bigFromBase10("65000549695646603727810655408050771481677621702948236658134783353303381437752") 36 | 37 | // xiTo2PSquaredMinus2Over3 is ξ^((2p²-2)/3) where ξ = i+3 (a cubic root of unity, mod p). 38 | var xiTo2PSquaredMinus2Over3 = bigFromBase10("4985783334309134261147736404674766913742361673560802634030") 39 | 40 | // xiToPSquaredMinus1Over6 is ξ^((1p²-1)/6) where ξ = i+3 (a cubic root of -1, mod p). 41 | var xiToPSquaredMinus1Over6 = bigFromBase10("65000549695646603727810655408050771481677621702948236658134783353303381437753") 42 | 43 | // xiTo2PMinus2Over3 is ξ^((2p-2)/3) where ξ = i+3. 44 | var xiTo2PMinus2Over3 = &gfP2{bigFromBase10("19885131339612776214803633203834694332692106372356013117629940868870585019582"), bigFromBase10("21645619881471562101905880913352894726728173167203616652430647841922248593627")} 45 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/bn256/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bn256 6 | 7 | import ( 8 | "crypto/rand" 9 | ) 10 | 11 | func ExamplePair() { 12 | // This implements the tripartite Diffie-Hellman algorithm from "A One 13 | // Round Protocol for Tripartite Diffie-Hellman", A. Joux. 14 | // http://www.springerlink.com/content/cddc57yyva0hburb/fulltext.pdf 15 | 16 | // Each of three parties, a, b and c, generate a private value. 17 | a, _ := rand.Int(rand.Reader, Order) 18 | b, _ := rand.Int(rand.Reader, Order) 19 | c, _ := rand.Int(rand.Reader, Order) 20 | 21 | // Then each party calculates g₁ and g₂ times their private value. 22 | pa := new(G1).ScalarBaseMult(a) 23 | qa := new(G2).ScalarBaseMult(a) 24 | 25 | pb := new(G1).ScalarBaseMult(b) 26 | qb := new(G2).ScalarBaseMult(b) 27 | 28 | pc := new(G1).ScalarBaseMult(c) 29 | qc := new(G2).ScalarBaseMult(c) 30 | 31 | // Now each party exchanges its public values with the other two and 32 | // all parties can calculate the shared key. 33 | k1 := Pair(pb, qc) 34 | k1.ScalarMult(k1, a) 35 | 36 | k2 := Pair(pc, qa) 37 | k2.ScalarMult(k2, b) 38 | 39 | k3 := Pair(pa, qb) 40 | k3.ScalarMult(k3, c) 41 | 42 | // k1, k2 and k3 will all be equal. 43 | } 44 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20/chacha_arm64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.11 6 | // +build !gccgo,!appengine 7 | 8 | package chacha20 9 | 10 | const bufSize = 256 11 | 12 | //go:noescape 13 | func xorKeyStreamVX(dst, src []byte, key *[8]uint32, nonce *[3]uint32, counter *uint32) 14 | 15 | func (c *Cipher) xorKeyStreamBlocks(dst, src []byte) { 16 | xorKeyStreamVX(dst, src, &c.key, &c.nonce, &c.counter) 17 | } 18 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20/chacha_noasm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !arm64,!s390x,!ppc64le arm64,!go1.11 gccgo appengine 6 | 7 | package chacha20 8 | 9 | const bufSize = blockSize 10 | 11 | func (s *Cipher) xorKeyStreamBlocks(dst, src []byte) { 12 | s.xorKeyStreamBlocksGeneric(dst, src) 13 | } 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20/chacha_ppc64le.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo,!appengine 6 | 7 | package chacha20 8 | 9 | const bufSize = 256 10 | 11 | //go:noescape 12 | func chaCha20_ctr32_vsx(out, inp *byte, len int, key *[8]uint32, counter *uint32) 13 | 14 | func (c *Cipher) xorKeyStreamBlocks(dst, src []byte) { 15 | chaCha20_ctr32_vsx(&dst[0], &src[0], len(src), &c.key, &c.counter) 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20/chacha_s390x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo,!appengine 6 | 7 | package chacha20 8 | 9 | import "golang.org/x/sys/cpu" 10 | 11 | var haveAsm = cpu.S390X.HasVX 12 | 13 | const bufSize = 256 14 | 15 | // xorKeyStreamVX is an assembly implementation of XORKeyStream. It must only 16 | // be called when the vector facility is available. Implementation in asm_s390x.s. 17 | //go:noescape 18 | func xorKeyStreamVX(dst, src []byte, key *[8]uint32, nonce *[3]uint32, counter *uint32) 19 | 20 | func (c *Cipher) xorKeyStreamBlocks(dst, src []byte) { 21 | if cpu.S390X.HasVX { 22 | xorKeyStreamVX(dst, src, &c.key, &c.nonce, &c.counter) 23 | } else { 24 | c.xorKeyStreamBlocksGeneric(dst, src) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20/xor.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found src the LICENSE file. 4 | 5 | package chacha20 6 | 7 | import "runtime" 8 | 9 | // Platforms that have fast unaligned 32-bit little endian accesses. 10 | const unaligned = runtime.GOARCH == "386" || 11 | runtime.GOARCH == "amd64" || 12 | runtime.GOARCH == "arm64" || 13 | runtime.GOARCH == "ppc64le" || 14 | runtime.GOARCH == "s390x" 15 | 16 | // xor reads a little endian uint32 from src, XORs it with u and 17 | // places the result in little endian byte order in dst. 18 | func xor(dst, src []byte, u uint32) { 19 | _, _ = src[3], dst[3] // eliminate bounds checks 20 | if unaligned { 21 | // The compiler should optimize this code into 22 | // 32-bit unaligned little endian loads and stores. 23 | // TODO: delete once the compiler does a reliably 24 | // good job with the generic code below. 25 | // See issue #25111 for more details. 26 | v := uint32(src[0]) 27 | v |= uint32(src[1]) << 8 28 | v |= uint32(src[2]) << 16 29 | v |= uint32(src[3]) << 24 30 | v ^= u 31 | dst[0] = byte(v) 32 | dst[1] = byte(v >> 8) 33 | dst[2] = byte(v >> 16) 34 | dst[3] = byte(v >> 24) 35 | } else { 36 | dst[0] = src[0] ^ byte(u) 37 | dst[1] = src[1] ^ byte(u>>8) 38 | dst[2] = src[2] ^ byte(u>>16) 39 | dst[3] = src[3] ^ byte(u>>24) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.7,amd64,!gccgo,!appengine 6 | 7 | package chacha20poly1305 8 | 9 | import ( 10 | "encoding/binary" 11 | 12 | "golang.org/x/crypto/internal/subtle" 13 | "golang.org/x/sys/cpu" 14 | ) 15 | 16 | //go:noescape 17 | func chacha20Poly1305Open(dst []byte, key []uint32, src, ad []byte) bool 18 | 19 | //go:noescape 20 | func chacha20Poly1305Seal(dst []byte, key []uint32, src, ad []byte) 21 | 22 | var ( 23 | useAVX2 = cpu.X86.HasAVX2 && cpu.X86.HasBMI2 24 | ) 25 | 26 | // setupState writes a ChaCha20 input matrix to state. See 27 | // https://tools.ietf.org/html/rfc7539#section-2.3. 28 | func setupState(state *[16]uint32, key *[32]byte, nonce []byte) { 29 | state[0] = 0x61707865 30 | state[1] = 0x3320646e 31 | state[2] = 0x79622d32 32 | state[3] = 0x6b206574 33 | 34 | state[4] = binary.LittleEndian.Uint32(key[0:4]) 35 | state[5] = binary.LittleEndian.Uint32(key[4:8]) 36 | state[6] = binary.LittleEndian.Uint32(key[8:12]) 37 | state[7] = binary.LittleEndian.Uint32(key[12:16]) 38 | state[8] = binary.LittleEndian.Uint32(key[16:20]) 39 | state[9] = binary.LittleEndian.Uint32(key[20:24]) 40 | state[10] = binary.LittleEndian.Uint32(key[24:28]) 41 | state[11] = binary.LittleEndian.Uint32(key[28:32]) 42 | 43 | state[12] = 0 44 | state[13] = binary.LittleEndian.Uint32(nonce[0:4]) 45 | state[14] = binary.LittleEndian.Uint32(nonce[4:8]) 46 | state[15] = binary.LittleEndian.Uint32(nonce[8:12]) 47 | } 48 | 49 | func (c *chacha20poly1305) seal(dst, nonce, plaintext, additionalData []byte) []byte { 50 | if !cpu.X86.HasSSSE3 { 51 | return c.sealGeneric(dst, nonce, plaintext, additionalData) 52 | } 53 | 54 | var state [16]uint32 55 | setupState(&state, &c.key, nonce) 56 | 57 | ret, out := sliceForAppend(dst, len(plaintext)+16) 58 | if subtle.InexactOverlap(out, plaintext) { 59 | panic("chacha20poly1305: invalid buffer overlap") 60 | } 61 | chacha20Poly1305Seal(out[:], state[:], plaintext, additionalData) 62 | return ret 63 | } 64 | 65 | func (c *chacha20poly1305) open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) { 66 | if !cpu.X86.HasSSSE3 { 67 | return c.openGeneric(dst, nonce, ciphertext, additionalData) 68 | } 69 | 70 | var state [16]uint32 71 | setupState(&state, &c.key, nonce) 72 | 73 | ciphertext = ciphertext[:len(ciphertext)-16] 74 | ret, out := sliceForAppend(dst, len(ciphertext)) 75 | if subtle.InexactOverlap(out, ciphertext) { 76 | panic("chacha20poly1305: invalid buffer overlap") 77 | } 78 | if !chacha20Poly1305Open(out, state[:], ciphertext, additionalData) { 79 | for i := range out { 80 | out[i] = 0 81 | } 82 | return nil, errOpen 83 | } 84 | 85 | return ret, nil 86 | } 87 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20poly1305/chacha20poly1305_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package chacha20poly1305 6 | 7 | import ( 8 | "encoding/binary" 9 | 10 | "golang.org/x/crypto/chacha20" 11 | "golang.org/x/crypto/internal/subtle" 12 | "golang.org/x/crypto/poly1305" 13 | ) 14 | 15 | func roundTo16(n int) int { 16 | return 16 * ((n + 15) / 16) 17 | } 18 | 19 | func (c *chacha20poly1305) sealGeneric(dst, nonce, plaintext, additionalData []byte) []byte { 20 | ret, out := sliceForAppend(dst, len(plaintext)+poly1305.TagSize) 21 | if subtle.InexactOverlap(out, plaintext) { 22 | panic("chacha20poly1305: invalid buffer overlap") 23 | } 24 | 25 | var polyKey, discardBuf [32]byte 26 | s, _ := chacha20.NewUnauthenticatedCipher(c.key[:], nonce) 27 | s.XORKeyStream(polyKey[:], polyKey[:]) 28 | s.XORKeyStream(discardBuf[:], discardBuf[:]) // skip the next 32 bytes 29 | s.XORKeyStream(out, plaintext) 30 | 31 | polyInput := make([]byte, roundTo16(len(additionalData))+roundTo16(len(plaintext))+8+8) 32 | copy(polyInput, additionalData) 33 | copy(polyInput[roundTo16(len(additionalData)):], out[:len(plaintext)]) 34 | binary.LittleEndian.PutUint64(polyInput[len(polyInput)-16:], uint64(len(additionalData))) 35 | binary.LittleEndian.PutUint64(polyInput[len(polyInput)-8:], uint64(len(plaintext))) 36 | 37 | var tag [poly1305.TagSize]byte 38 | poly1305.Sum(&tag, polyInput, &polyKey) 39 | copy(out[len(plaintext):], tag[:]) 40 | 41 | return ret 42 | } 43 | 44 | func (c *chacha20poly1305) openGeneric(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) { 45 | var tag [poly1305.TagSize]byte 46 | copy(tag[:], ciphertext[len(ciphertext)-16:]) 47 | ciphertext = ciphertext[:len(ciphertext)-16] 48 | 49 | var polyKey, discardBuf [32]byte 50 | s, _ := chacha20.NewUnauthenticatedCipher(c.key[:], nonce) 51 | s.XORKeyStream(polyKey[:], polyKey[:]) 52 | s.XORKeyStream(discardBuf[:], discardBuf[:]) // skip the next 32 bytes 53 | 54 | polyInput := make([]byte, roundTo16(len(additionalData))+roundTo16(len(ciphertext))+8+8) 55 | copy(polyInput, additionalData) 56 | copy(polyInput[roundTo16(len(additionalData)):], ciphertext) 57 | binary.LittleEndian.PutUint64(polyInput[len(polyInput)-16:], uint64(len(additionalData))) 58 | binary.LittleEndian.PutUint64(polyInput[len(polyInput)-8:], uint64(len(ciphertext))) 59 | 60 | ret, out := sliceForAppend(dst, len(ciphertext)) 61 | if subtle.InexactOverlap(out, ciphertext) { 62 | panic("chacha20poly1305: invalid buffer overlap") 63 | } 64 | if !poly1305.Verify(&tag, polyInput, &polyKey) { 65 | for i := range out { 66 | out[i] = 0 67 | } 68 | return nil, errOpen 69 | } 70 | 71 | s.XORKeyStream(out, ciphertext) 72 | return ret, nil 73 | } 74 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20poly1305/chacha20poly1305_noasm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !amd64 !go1.7 gccgo appengine 6 | 7 | package chacha20poly1305 8 | 9 | func (c *chacha20poly1305) seal(dst, nonce, plaintext, additionalData []byte) []byte { 10 | return c.sealGeneric(dst, nonce, plaintext, additionalData) 11 | } 12 | 13 | func (c *chacha20poly1305) open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) { 14 | return c.openGeneric(dst, nonce, ciphertext, additionalData) 15 | } 16 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20poly1305/xchacha20poly1305.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package chacha20poly1305 6 | 7 | import ( 8 | "crypto/cipher" 9 | "errors" 10 | 11 | "golang.org/x/crypto/chacha20" 12 | ) 13 | 14 | type xchacha20poly1305 struct { 15 | key [KeySize]byte 16 | } 17 | 18 | // NewX returns a XChaCha20-Poly1305 AEAD that uses the given 256-bit key. 19 | // 20 | // XChaCha20-Poly1305 is a ChaCha20-Poly1305 variant that takes a longer nonce, 21 | // suitable to be generated randomly without risk of collisions. It should be 22 | // preferred when nonce uniqueness cannot be trivially ensured, or whenever 23 | // nonces are randomly generated. 24 | func NewX(key []byte) (cipher.AEAD, error) { 25 | if len(key) != KeySize { 26 | return nil, errors.New("chacha20poly1305: bad key length") 27 | } 28 | ret := new(xchacha20poly1305) 29 | copy(ret.key[:], key) 30 | return ret, nil 31 | } 32 | 33 | func (*xchacha20poly1305) NonceSize() int { 34 | return NonceSizeX 35 | } 36 | 37 | func (*xchacha20poly1305) Overhead() int { 38 | return 16 39 | } 40 | 41 | func (x *xchacha20poly1305) Seal(dst, nonce, plaintext, additionalData []byte) []byte { 42 | if len(nonce) != NonceSizeX { 43 | panic("chacha20poly1305: bad nonce length passed to Seal") 44 | } 45 | 46 | // XChaCha20-Poly1305 technically supports a 64-bit counter, so there is no 47 | // size limit. However, since we reuse the ChaCha20-Poly1305 implementation, 48 | // the second half of the counter is not available. This is unlikely to be 49 | // an issue because the cipher.AEAD API requires the entire message to be in 50 | // memory, and the counter overflows at 256 GB. 51 | if uint64(len(plaintext)) > (1<<38)-64 { 52 | panic("chacha20poly1305: plaintext too large") 53 | } 54 | 55 | c := new(chacha20poly1305) 56 | hKey, _ := chacha20.HChaCha20(x.key[:], nonce[0:16]) 57 | copy(c.key[:], hKey) 58 | 59 | // The first 4 bytes of the final nonce are unused counter space. 60 | cNonce := make([]byte, NonceSize) 61 | copy(cNonce[4:12], nonce[16:24]) 62 | 63 | return c.seal(dst, cNonce[:], plaintext, additionalData) 64 | } 65 | 66 | func (x *xchacha20poly1305) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) { 67 | if len(nonce) != NonceSizeX { 68 | panic("chacha20poly1305: bad nonce length passed to Open") 69 | } 70 | if len(ciphertext) < 16 { 71 | return nil, errOpen 72 | } 73 | if uint64(len(ciphertext)) > (1<<38)-48 { 74 | panic("chacha20poly1305: ciphertext too large") 75 | } 76 | 77 | c := new(chacha20poly1305) 78 | hKey, _ := chacha20.HChaCha20(x.key[:], nonce[0:16]) 79 | copy(c.key[:], hKey) 80 | 81 | // The first 4 bytes of the final nonce are unused counter space. 82 | cNonce := make([]byte, NonceSize) 83 | copy(cNonce[4:12], nonce[16:24]) 84 | 85 | return c.open(dst, cNonce[:], ciphertext, additionalData) 86 | } 87 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/codereview.cfg: -------------------------------------------------------------------------------- 1 | issuerepo: golang/go 2 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/cryptobyte/asn1/asn1.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package asn1 contains supporting types for parsing and building ASN.1 6 | // messages with the cryptobyte package. 7 | package asn1 // import "golang.org/x/crypto/cryptobyte/asn1" 8 | 9 | // Tag represents an ASN.1 identifier octet, consisting of a tag number 10 | // (indicating a type) and class (such as context-specific or constructed). 11 | // 12 | // Methods in the cryptobyte package only support the low-tag-number form, i.e. 13 | // a single identifier octet with bits 7-8 encoding the class and bits 1-6 14 | // encoding the tag number. 15 | type Tag uint8 16 | 17 | const ( 18 | classConstructed = 0x20 19 | classContextSpecific = 0x80 20 | ) 21 | 22 | // Constructed returns t with the constructed class bit set. 23 | func (t Tag) Constructed() Tag { return t | classConstructed } 24 | 25 | // ContextSpecific returns t with the context-specific class bit set. 26 | func (t Tag) ContextSpecific() Tag { return t | classContextSpecific } 27 | 28 | // The following is a list of standard tag and class combinations. 29 | const ( 30 | BOOLEAN = Tag(1) 31 | INTEGER = Tag(2) 32 | BIT_STRING = Tag(3) 33 | OCTET_STRING = Tag(4) 34 | NULL = Tag(5) 35 | OBJECT_IDENTIFIER = Tag(6) 36 | ENUM = Tag(10) 37 | UTF8String = Tag(12) 38 | SEQUENCE = Tag(16 | classConstructed) 39 | SET = Tag(17 | classConstructed) 40 | PrintableString = Tag(19) 41 | T61String = Tag(20) 42 | IA5String = Tag(22) 43 | UTCTime = Tag(23) 44 | GeneralizedTime = Tag(24) 45 | GeneralString = Tag(27) 46 | ) 47 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/curve25519_noasm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !amd64 gccgo appengine purego 6 | 7 | package curve25519 8 | 9 | func scalarMult(out, in, base *[32]byte) { 10 | scalarMultGeneric(out, in, base) 11 | } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/curve25519_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package curve25519 6 | 7 | import ( 8 | "bytes" 9 | "crypto/rand" 10 | "fmt" 11 | "testing" 12 | ) 13 | 14 | const expectedHex = "89161fde887b2b53de549af483940106ecc114d6982daa98256de23bdf77661a" 15 | 16 | func TestX25519Basepoint(t *testing.T) { 17 | x := make([]byte, 32) 18 | x[0] = 1 19 | 20 | for i := 0; i < 200; i++ { 21 | var err error 22 | x, err = X25519(x, Basepoint) 23 | if err != nil { 24 | t.Fatal(err) 25 | } 26 | } 27 | 28 | result := fmt.Sprintf("%x", x) 29 | if result != expectedHex { 30 | t.Errorf("incorrect result: got %s, want %s", result, expectedHex) 31 | } 32 | } 33 | 34 | func TestLowOrderPoints(t *testing.T) { 35 | scalar := make([]byte, ScalarSize) 36 | if _, err := rand.Read(scalar); err != nil { 37 | t.Fatal(err) 38 | } 39 | for i, p := range lowOrderPoints { 40 | out, err := X25519(scalar, p) 41 | if err == nil { 42 | t.Errorf("%d: expected error, got nil", i) 43 | } 44 | if out != nil { 45 | t.Errorf("%d: expected nil output, got %x", i, out) 46 | } 47 | } 48 | } 49 | 50 | func TestTestVectors(t *testing.T) { 51 | t.Run("Generic", func(t *testing.T) { testTestVectors(t, scalarMultGeneric) }) 52 | t.Run("Native", func(t *testing.T) { testTestVectors(t, ScalarMult) }) 53 | t.Run("X25519", func(t *testing.T) { 54 | testTestVectors(t, func(dst, scalar, point *[32]byte) { 55 | out, err := X25519(scalar[:], point[:]) 56 | if err != nil { 57 | t.Fatal(err) 58 | } 59 | copy(dst[:], out) 60 | }) 61 | }) 62 | } 63 | 64 | func testTestVectors(t *testing.T, scalarMult func(dst, scalar, point *[32]byte)) { 65 | for _, tv := range testVectors { 66 | var got [32]byte 67 | scalarMult(&got, &tv.In, &tv.Base) 68 | if !bytes.Equal(got[:], tv.Expect[:]) { 69 | t.Logf(" in = %x", tv.In) 70 | t.Logf(" base = %x", tv.Base) 71 | t.Logf(" got = %x", got) 72 | t.Logf("expect = %x", tv.Expect) 73 | t.Fail() 74 | } 75 | } 76 | } 77 | 78 | // TestHighBitIgnored tests the following requirement in RFC 7748: 79 | // 80 | // When receiving such an array, implementations of X25519 (but not X448) MUST 81 | // mask the most significant bit in the final byte. 82 | // 83 | // Regression test for issue #30095. 84 | func TestHighBitIgnored(t *testing.T) { 85 | var s, u [32]byte 86 | rand.Read(s[:]) 87 | rand.Read(u[:]) 88 | 89 | var hi0, hi1 [32]byte 90 | 91 | u[31] &= 0x7f 92 | ScalarMult(&hi0, &s, &u) 93 | 94 | u[31] |= 0x80 95 | ScalarMult(&hi1, &s, &u) 96 | 97 | if !bytes.Equal(hi0[:], hi1[:]) { 98 | t.Errorf("high bit of group point should not affect result") 99 | } 100 | } 101 | 102 | func BenchmarkScalarBaseMult(b *testing.B) { 103 | var in, out [32]byte 104 | in[0] = 1 105 | 106 | b.SetBytes(32) 107 | for i := 0; i < b.N; i++ { 108 | ScalarBaseMult(&out, &in) 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ed25519/go113_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.13 6 | 7 | package ed25519_test 8 | 9 | import ( 10 | ed25519std "crypto/ed25519" 11 | "golang.org/x/crypto/ed25519" 12 | "testing" 13 | ) 14 | 15 | func TestTypeAlias(t *testing.T) { 16 | var zero zeroReader 17 | public, private, _ := ed25519std.GenerateKey(zero) 18 | 19 | message := []byte("test message") 20 | sig := ed25519.Sign(private, message) 21 | if !ed25519.Verify(public, message, sig) { 22 | t.Errorf("valid signature rejected") 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ed25519/testdata/sign.input.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parquery/revproxyry/54edc9726d86d5f1bdc5c09004898a3b9956d8ba/vendor/golang.org/x/crypto/ed25519/testdata/sign.input.gz -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/go.mod: -------------------------------------------------------------------------------- 1 | module golang.org/x/crypto 2 | 3 | go 1.11 4 | 5 | require ( 6 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 7 | golang.org/x/sys v0.0.0-20190412213103-97732733099d 8 | ) 9 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 2 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= 3 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 4 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 5 | golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= 6 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 7 | golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= 8 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 9 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/hkdf/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package hkdf_test 6 | 7 | import ( 8 | "bytes" 9 | "crypto/rand" 10 | "crypto/sha256" 11 | "fmt" 12 | "io" 13 | 14 | "golang.org/x/crypto/hkdf" 15 | ) 16 | 17 | // Usage example that expands one master secret into three other 18 | // cryptographically secure keys. 19 | func Example_usage() { 20 | // Underlying hash function for HMAC. 21 | hash := sha256.New 22 | 23 | // Cryptographically secure master secret. 24 | secret := []byte{0x00, 0x01, 0x02, 0x03} // i.e. NOT this. 25 | 26 | // Non-secret salt, optional (can be nil). 27 | // Recommended: hash-length random value. 28 | salt := make([]byte, hash().Size()) 29 | if _, err := rand.Read(salt); err != nil { 30 | panic(err) 31 | } 32 | 33 | // Non-secret context info, optional (can be nil). 34 | info := []byte("hkdf example") 35 | 36 | // Generate three 128-bit derived keys. 37 | hkdf := hkdf.New(hash, secret, salt, info) 38 | 39 | var keys [][]byte 40 | for i := 0; i < 3; i++ { 41 | key := make([]byte, 16) 42 | if _, err := io.ReadFull(hkdf, key); err != nil { 43 | panic(err) 44 | } 45 | keys = append(keys, key) 46 | } 47 | 48 | for i := range keys { 49 | fmt.Printf("Key #%d: %v\n", i+1, !bytes.Equal(keys[i], make([]byte, 16))) 50 | } 51 | 52 | // Output: 53 | // Key #1: true 54 | // Key #2: true 55 | // Key #3: true 56 | } 57 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/subtle/aliasing.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine 6 | 7 | // Package subtle implements functions that are often useful in cryptographic 8 | // code but require careful thought to use correctly. 9 | package subtle // import "golang.org/x/crypto/internal/subtle" 10 | 11 | import "unsafe" 12 | 13 | // AnyOverlap reports whether x and y share memory at any (not necessarily 14 | // corresponding) index. The memory beyond the slice length is ignored. 15 | func AnyOverlap(x, y []byte) bool { 16 | return len(x) > 0 && len(y) > 0 && 17 | uintptr(unsafe.Pointer(&x[0])) <= uintptr(unsafe.Pointer(&y[len(y)-1])) && 18 | uintptr(unsafe.Pointer(&y[0])) <= uintptr(unsafe.Pointer(&x[len(x)-1])) 19 | } 20 | 21 | // InexactOverlap reports whether x and y share memory at any non-corresponding 22 | // index. The memory beyond the slice length is ignored. Note that x and y can 23 | // have different lengths and still not have any inexact overlap. 24 | // 25 | // InexactOverlap can be used to implement the requirements of the crypto/cipher 26 | // AEAD, Block, BlockMode and Stream interfaces. 27 | func InexactOverlap(x, y []byte) bool { 28 | if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] { 29 | return false 30 | } 31 | return AnyOverlap(x, y) 32 | } 33 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/subtle/aliasing_appengine.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build appengine 6 | 7 | // Package subtle implements functions that are often useful in cryptographic 8 | // code but require careful thought to use correctly. 9 | package subtle // import "golang.org/x/crypto/internal/subtle" 10 | 11 | // This is the Google App Engine standard variant based on reflect 12 | // because the unsafe package and cgo are disallowed. 13 | 14 | import "reflect" 15 | 16 | // AnyOverlap reports whether x and y share memory at any (not necessarily 17 | // corresponding) index. The memory beyond the slice length is ignored. 18 | func AnyOverlap(x, y []byte) bool { 19 | return len(x) > 0 && len(y) > 0 && 20 | reflect.ValueOf(&x[0]).Pointer() <= reflect.ValueOf(&y[len(y)-1]).Pointer() && 21 | reflect.ValueOf(&y[0]).Pointer() <= reflect.ValueOf(&x[len(x)-1]).Pointer() 22 | } 23 | 24 | // InexactOverlap reports whether x and y share memory at any non-corresponding 25 | // index. The memory beyond the slice length is ignored. Note that x and y can 26 | // have different lengths and still not have any inexact overlap. 27 | // 28 | // InexactOverlap can be used to implement the requirements of the crypto/cipher 29 | // AEAD, Block, BlockMode and Stream interfaces. 30 | func InexactOverlap(x, y []byte) bool { 31 | if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] { 32 | return false 33 | } 34 | return AnyOverlap(x, y) 35 | } 36 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/subtle/aliasing_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package subtle_test 6 | 7 | import ( 8 | "testing" 9 | 10 | "golang.org/x/crypto/internal/subtle" 11 | ) 12 | 13 | var a, b [100]byte 14 | 15 | var aliasingTests = []struct { 16 | x, y []byte 17 | anyOverlap, inexactOverlap bool 18 | }{ 19 | {a[:], b[:], false, false}, 20 | {a[:], b[:0], false, false}, 21 | {a[:], b[:50], false, false}, 22 | {a[40:50], a[50:60], false, false}, 23 | {a[40:50], a[60:70], false, false}, 24 | {a[:51], a[50:], true, true}, 25 | {a[:], a[:], true, false}, 26 | {a[:50], a[:60], true, false}, 27 | {a[:], nil, false, false}, 28 | {nil, nil, false, false}, 29 | {a[:], a[:0], false, false}, 30 | {a[:10], a[:10:20], true, false}, 31 | {a[:10], a[5:10:20], true, true}, 32 | } 33 | 34 | func testAliasing(t *testing.T, i int, x, y []byte, anyOverlap, inexactOverlap bool) { 35 | any := subtle.AnyOverlap(x, y) 36 | if any != anyOverlap { 37 | t.Errorf("%d: wrong AnyOverlap result, expected %v, got %v", i, anyOverlap, any) 38 | } 39 | inexact := subtle.InexactOverlap(x, y) 40 | if inexact != inexactOverlap { 41 | t.Errorf("%d: wrong InexactOverlap result, expected %v, got %v", i, inexactOverlap, any) 42 | } 43 | } 44 | 45 | func TestAliasing(t *testing.T) { 46 | for i, tt := range aliasingTests { 47 | testAliasing(t, i, tt.x, tt.y, tt.anyOverlap, tt.inexactOverlap) 48 | testAliasing(t, i, tt.y, tt.x, tt.anyOverlap, tt.inexactOverlap) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/wycheproof/README.md: -------------------------------------------------------------------------------- 1 | This package runs a set of the Wycheproof tests provided by 2 | https://github.com/google/wycheproof. 3 | 4 | The JSON test files live in 5 | https://github.com/google/wycheproof/tree/master/testvectors 6 | and are being fetched and cached at a pinned version every time 7 | these tests are run. To change the version of the wycheproof 8 | repository that is being used for testing, update wycheproofModVer. 9 | 10 | The structs for these tests are generated from the 11 | schemas provided in https://github.com/google/wycheproof/tree/master/schemas 12 | using https://github.com/a-h/generate. -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/wycheproof/eddsa_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.13 6 | 7 | package wycheproof 8 | 9 | import ( 10 | "testing" 11 | 12 | "golang.org/x/crypto/ed25519" 13 | ) 14 | 15 | func TestEddsa(t *testing.T) { 16 | // Jwk the private key in webcrypto format 17 | type Jwk struct { 18 | } 19 | 20 | // Key unencoded key pair 21 | type Key struct { 22 | } 23 | 24 | // Notes a description of the labels used in the test vectors 25 | type Notes struct { 26 | } 27 | 28 | // SignatureTestVector 29 | type SignatureTestVector struct { 30 | 31 | // A brief description of the test case 32 | Comment string `json:"comment,omitempty"` 33 | 34 | // A list of flags 35 | Flags []string `json:"flags,omitempty"` 36 | 37 | // The message to sign 38 | Msg string `json:"msg,omitempty"` 39 | 40 | // Test result 41 | Result string `json:"result,omitempty"` 42 | 43 | // A signature for msg 44 | Sig string `json:"sig,omitempty"` 45 | 46 | // Identifier of the test case 47 | TcId int `json:"tcId,omitempty"` 48 | } 49 | 50 | // EddsaTestGroup 51 | type EddsaTestGroup struct { 52 | 53 | // the private key in webcrypto format 54 | Jwk *Jwk `json:"jwk,omitempty"` 55 | 56 | // unencoded key pair 57 | Key *Key `json:"key,omitempty"` 58 | 59 | // Asn encoded public key 60 | KeyDer string `json:"keyDer,omitempty"` 61 | 62 | // Pem encoded public key 63 | KeyPem string `json:"keyPem,omitempty"` 64 | Tests []*SignatureTestVector `json:"tests,omitempty"` 65 | Type interface{} `json:"type,omitempty"` 66 | } 67 | 68 | // Root 69 | type Root struct { 70 | 71 | // the primitive tested in the test file 72 | Algorithm string `json:"algorithm,omitempty"` 73 | 74 | // the version of the test vectors. 75 | GeneratorVersion string `json:"generatorVersion,omitempty"` 76 | 77 | // additional documentation 78 | Header []string `json:"header,omitempty"` 79 | 80 | // a description of the labels used in the test vectors 81 | Notes *Notes `json:"notes,omitempty"` 82 | 83 | // the number of test vectors in this test 84 | NumberOfTests int `json:"numberOfTests,omitempty"` 85 | Schema interface{} `json:"schema,omitempty"` 86 | TestGroups []*EddsaTestGroup `json:"testGroups,omitempty"` 87 | } 88 | 89 | var root Root 90 | readTestVector(t, "eddsa_test.json", &root) 91 | for _, tg := range root.TestGroups { 92 | pub := decodePublicKey(tg.KeyDer).(ed25519.PublicKey) 93 | for _, sig := range tg.Tests { 94 | got := ed25519.Verify(pub, decodeHex(sig.Msg), decodeHex(sig.Sig)) 95 | if want := shouldPass(sig.Result, sig.Flags, nil); got != want { 96 | t.Errorf("tcid: %d, type: %s, comment: %q, wanted success: %t", sig.TcId, sig.Result, sig.Comment, want) 97 | } 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/wycheproof/internal/dsa/dsa.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package dsa provides an internal version of dsa.Verify 6 | // that is used for the Wycheproof tests. 7 | package dsa 8 | 9 | import ( 10 | "crypto/dsa" 11 | "math/big" 12 | 13 | "golang.org/x/crypto/cryptobyte" 14 | "golang.org/x/crypto/cryptobyte/asn1" 15 | ) 16 | 17 | // VerifyASN1 verifies the ASN1 encoded signature, sig, of hash using the 18 | // public key, pub. Its return value records whether the signature is valid. 19 | func VerifyASN1(pub *dsa.PublicKey, hash, sig []byte) bool { 20 | var ( 21 | r, s = &big.Int{}, &big.Int{} 22 | inner cryptobyte.String 23 | ) 24 | input := cryptobyte.String(sig) 25 | if !input.ReadASN1(&inner, asn1.SEQUENCE) || 26 | !input.Empty() || 27 | !inner.ReadASN1Integer(r) || 28 | !inner.ReadASN1Integer(s) || 29 | !inner.Empty() { 30 | return false 31 | } 32 | return dsa.Verify(pub, hash, r, s) 33 | } 34 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/wycheproof/internal/ecdsa/ecdsa.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package ecdsa provides an internal version of ecdsa.Verify 6 | // that is used for the Wycheproof tests. 7 | package ecdsa 8 | 9 | import ( 10 | "crypto/ecdsa" 11 | "math/big" 12 | 13 | "golang.org/x/crypto/cryptobyte" 14 | "golang.org/x/crypto/cryptobyte/asn1" 15 | ) 16 | 17 | // VerifyASN1 verifies the ASN1 encoded signature, sig, of hash using the 18 | // public key, pub. Its return value records whether the signature is valid. 19 | func VerifyASN1(pub *ecdsa.PublicKey, hash, sig []byte) bool { 20 | var ( 21 | r, s = &big.Int{}, &big.Int{} 22 | inner cryptobyte.String 23 | ) 24 | input := cryptobyte.String(sig) 25 | if !input.ReadASN1(&inner, asn1.SEQUENCE) || 26 | !input.Empty() || 27 | !inner.ReadASN1Integer(r) || 28 | !inner.ReadASN1Integer(s) || 29 | !inner.Empty() { 30 | return false 31 | } 32 | return ecdsa.Verify(pub, hash, r, s) 33 | } 34 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/md4/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package md4_test 6 | 7 | import ( 8 | "fmt" 9 | "io" 10 | 11 | "golang.org/x/crypto/md4" 12 | ) 13 | 14 | func ExampleNew() { 15 | h := md4.New() 16 | data := "These pretzels are making me thirsty." 17 | io.WriteString(h, data) 18 | fmt.Printf("%x", h.Sum(nil)) 19 | // Output: 48c4e365090b30a32f084c4888deceaa 20 | } 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/md4/md4.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package md4 implements the MD4 hash algorithm as defined in RFC 1320. 6 | // 7 | // Deprecated: MD4 is cryptographically broken and should should only be used 8 | // where compatibility with legacy systems, not security, is the goal. Instead, 9 | // use a secure hash like SHA-256 (from crypto/sha256). 10 | package md4 // import "golang.org/x/crypto/md4" 11 | 12 | import ( 13 | "crypto" 14 | "hash" 15 | ) 16 | 17 | func init() { 18 | crypto.RegisterHash(crypto.MD4, New) 19 | } 20 | 21 | // The size of an MD4 checksum in bytes. 22 | const Size = 16 23 | 24 | // The blocksize of MD4 in bytes. 25 | const BlockSize = 64 26 | 27 | const ( 28 | _Chunk = 64 29 | _Init0 = 0x67452301 30 | _Init1 = 0xEFCDAB89 31 | _Init2 = 0x98BADCFE 32 | _Init3 = 0x10325476 33 | ) 34 | 35 | // digest represents the partial evaluation of a checksum. 36 | type digest struct { 37 | s [4]uint32 38 | x [_Chunk]byte 39 | nx int 40 | len uint64 41 | } 42 | 43 | func (d *digest) Reset() { 44 | d.s[0] = _Init0 45 | d.s[1] = _Init1 46 | d.s[2] = _Init2 47 | d.s[3] = _Init3 48 | d.nx = 0 49 | d.len = 0 50 | } 51 | 52 | // New returns a new hash.Hash computing the MD4 checksum. 53 | func New() hash.Hash { 54 | d := new(digest) 55 | d.Reset() 56 | return d 57 | } 58 | 59 | func (d *digest) Size() int { return Size } 60 | 61 | func (d *digest) BlockSize() int { return BlockSize } 62 | 63 | func (d *digest) Write(p []byte) (nn int, err error) { 64 | nn = len(p) 65 | d.len += uint64(nn) 66 | if d.nx > 0 { 67 | n := len(p) 68 | if n > _Chunk-d.nx { 69 | n = _Chunk - d.nx 70 | } 71 | for i := 0; i < n; i++ { 72 | d.x[d.nx+i] = p[i] 73 | } 74 | d.nx += n 75 | if d.nx == _Chunk { 76 | _Block(d, d.x[0:]) 77 | d.nx = 0 78 | } 79 | p = p[n:] 80 | } 81 | n := _Block(d, p) 82 | p = p[n:] 83 | if len(p) > 0 { 84 | d.nx = copy(d.x[:], p) 85 | } 86 | return 87 | } 88 | 89 | func (d0 *digest) Sum(in []byte) []byte { 90 | // Make a copy of d0, so that caller can keep writing and summing. 91 | d := new(digest) 92 | *d = *d0 93 | 94 | // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. 95 | len := d.len 96 | var tmp [64]byte 97 | tmp[0] = 0x80 98 | if len%64 < 56 { 99 | d.Write(tmp[0 : 56-len%64]) 100 | } else { 101 | d.Write(tmp[0 : 64+56-len%64]) 102 | } 103 | 104 | // Length in bits. 105 | len <<= 3 106 | for i := uint(0); i < 8; i++ { 107 | tmp[i] = byte(len >> (8 * i)) 108 | } 109 | d.Write(tmp[0:8]) 110 | 111 | if d.nx != 0 { 112 | panic("d.nx != 0") 113 | } 114 | 115 | for _, s := range d.s { 116 | in = append(in, byte(s>>0)) 117 | in = append(in, byte(s>>8)) 118 | in = append(in, byte(s>>16)) 119 | in = append(in, byte(s>>24)) 120 | } 121 | return in 122 | } 123 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/md4/md4block.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // MD4 block step. 6 | // In its own file so that a faster assembly or C version 7 | // can be substituted easily. 8 | 9 | package md4 10 | 11 | var shift1 = []uint{3, 7, 11, 19} 12 | var shift2 = []uint{3, 5, 9, 13} 13 | var shift3 = []uint{3, 9, 11, 15} 14 | 15 | var xIndex2 = []uint{0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15} 16 | var xIndex3 = []uint{0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15} 17 | 18 | func _Block(dig *digest, p []byte) int { 19 | a := dig.s[0] 20 | b := dig.s[1] 21 | c := dig.s[2] 22 | d := dig.s[3] 23 | n := 0 24 | var X [16]uint32 25 | for len(p) >= _Chunk { 26 | aa, bb, cc, dd := a, b, c, d 27 | 28 | j := 0 29 | for i := 0; i < 16; i++ { 30 | X[i] = uint32(p[j]) | uint32(p[j+1])<<8 | uint32(p[j+2])<<16 | uint32(p[j+3])<<24 31 | j += 4 32 | } 33 | 34 | // If this needs to be made faster in the future, 35 | // the usual trick is to unroll each of these 36 | // loops by a factor of 4; that lets you replace 37 | // the shift[] lookups with constants and, 38 | // with suitable variable renaming in each 39 | // unrolled body, delete the a, b, c, d = d, a, b, c 40 | // (or you can let the optimizer do the renaming). 41 | // 42 | // The index variables are uint so that % by a power 43 | // of two can be optimized easily by a compiler. 44 | 45 | // Round 1. 46 | for i := uint(0); i < 16; i++ { 47 | x := i 48 | s := shift1[i%4] 49 | f := ((c ^ d) & b) ^ d 50 | a += f + X[x] 51 | a = a<>(32-s) 52 | a, b, c, d = d, a, b, c 53 | } 54 | 55 | // Round 2. 56 | for i := uint(0); i < 16; i++ { 57 | x := xIndex2[i] 58 | s := shift2[i%4] 59 | g := (b & c) | (b & d) | (c & d) 60 | a += g + X[x] + 0x5a827999 61 | a = a<>(32-s) 62 | a, b, c, d = d, a, b, c 63 | } 64 | 65 | // Round 3. 66 | for i := uint(0); i < 16; i++ { 67 | x := xIndex3[i] 68 | s := shift3[i%4] 69 | h := b ^ c ^ d 70 | a += h + X[x] + 0x6ed9eba1 71 | a = a<>(32-s) 72 | a, b, c, d = d, a, b, c 73 | } 74 | 75 | a += aa 76 | b += bb 77 | c += cc 78 | d += dd 79 | 80 | p = p[_Chunk:] 81 | n += _Chunk 82 | } 83 | 84 | dig.s[0] = a 85 | dig.s[1] = b 86 | dig.s[2] = c 87 | dig.s[3] = d 88 | return n 89 | } 90 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/nacl/auth/auth.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package auth authenticates a message using a secret key. 7 | 8 | The Sum function, viewed as a function of the message for a uniform random 9 | key, is designed to meet the standard notion of unforgeability. This means 10 | that an attacker cannot find authenticators for any messages not authenticated 11 | by the sender, even if the attacker has adaptively influenced the messages 12 | authenticated by the sender. For a formal definition see, e.g., Section 2.4 13 | of Bellare, Kilian, and Rogaway, "The security of the cipher block chaining 14 | message authentication code," Journal of Computer and System Sciences 61 (2000), 15 | 362–399; http://www-cse.ucsd.edu/~mihir/papers/cbc.html. 16 | 17 | auth does not make any promises regarding "strong" unforgeability; perhaps 18 | one valid authenticator can be converted into another valid authenticator for 19 | the same message. NaCl also does not make any promises regarding "truncated 20 | unforgeability." 21 | 22 | This package is interoperable with NaCl: https://nacl.cr.yp.to/auth.html. 23 | */ 24 | package auth 25 | 26 | import ( 27 | "crypto/hmac" 28 | "crypto/sha512" 29 | ) 30 | 31 | const ( 32 | // Size is the size, in bytes, of an authenticated digest. 33 | Size = 32 34 | // KeySize is the size, in bytes, of an authentication key. 35 | KeySize = 32 36 | ) 37 | 38 | // Sum generates an authenticator for m using a secret key and returns the 39 | // 32-byte digest. 40 | func Sum(m []byte, key *[KeySize]byte) *[Size]byte { 41 | mac := hmac.New(sha512.New, key[:]) 42 | mac.Write(m) 43 | out := new([KeySize]byte) 44 | copy(out[:], mac.Sum(nil)[:Size]) 45 | return out 46 | } 47 | 48 | // Verify checks that digest is a valid authenticator of message m under the 49 | // given secret key. Verify does not leak timing information. 50 | func Verify(digest []byte, m []byte, key *[KeySize]byte) bool { 51 | if len(digest) != Size { 52 | return false 53 | } 54 | mac := hmac.New(sha512.New, key[:]) 55 | mac.Write(m) 56 | expectedMAC := mac.Sum(nil) // first 256 bits of 512-bit sum 57 | return hmac.Equal(digest, expectedMAC[:Size]) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/nacl/auth/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package auth_test 6 | 7 | import ( 8 | "encoding/hex" 9 | "fmt" 10 | 11 | "golang.org/x/crypto/nacl/auth" 12 | ) 13 | 14 | func Example() { 15 | // Load your secret key from a safe place and reuse it across multiple 16 | // Sum calls. (Obviously don't use this example key for anything 17 | // real.) If you want to convert a passphrase to a key, use a suitable 18 | // package like bcrypt or scrypt. 19 | secretKeyBytes, err := hex.DecodeString("6368616e676520746869732070617373776f726420746f206120736563726574") 20 | if err != nil { 21 | panic(err) 22 | } 23 | 24 | var secretKey [32]byte 25 | copy(secretKey[:], secretKeyBytes) 26 | 27 | mac := auth.Sum([]byte("hello world"), &secretKey) 28 | fmt.Printf("%x\n", *mac) 29 | result := auth.Verify(mac[:], []byte("hello world"), &secretKey) 30 | fmt.Println(result) 31 | badResult := auth.Verify(mac[:], []byte("different message"), &secretKey) 32 | fmt.Println(badResult) 33 | // Output: eca5a521f3d77b63f567fb0cb6f5f2d200641bc8dada42f60c5f881260c30317 34 | // true 35 | // false 36 | } 37 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/nacl/secretbox/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package secretbox_test 6 | 7 | import ( 8 | "crypto/rand" 9 | "encoding/hex" 10 | "fmt" 11 | "io" 12 | 13 | "golang.org/x/crypto/nacl/secretbox" 14 | ) 15 | 16 | func Example() { 17 | // Load your secret key from a safe place and reuse it across multiple 18 | // Seal calls. (Obviously don't use this example key for anything 19 | // real.) If you want to convert a passphrase to a key, use a suitable 20 | // package like bcrypt or scrypt. 21 | secretKeyBytes, err := hex.DecodeString("6368616e676520746869732070617373776f726420746f206120736563726574") 22 | if err != nil { 23 | panic(err) 24 | } 25 | 26 | var secretKey [32]byte 27 | copy(secretKey[:], secretKeyBytes) 28 | 29 | // You must use a different nonce for each message you encrypt with the 30 | // same key. Since the nonce here is 192 bits long, a random value 31 | // provides a sufficiently small probability of repeats. 32 | var nonce [24]byte 33 | if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil { 34 | panic(err) 35 | } 36 | 37 | // This encrypts "hello world" and appends the result to the nonce. 38 | encrypted := secretbox.Seal(nonce[:], []byte("hello world"), &nonce, &secretKey) 39 | 40 | // When you decrypt, you must use the same nonce and key you used to 41 | // encrypt the message. One way to achieve this is to store the nonce 42 | // alongside the encrypted message. Above, we stored the nonce in the first 43 | // 24 bytes of the encrypted text. 44 | var decryptNonce [24]byte 45 | copy(decryptNonce[:], encrypted[:24]) 46 | decrypted, ok := secretbox.Open(nil, encrypted[24:], &decryptNonce, &secretKey) 47 | if !ok { 48 | panic("decryption error") 49 | } 50 | 51 | fmt.Println(string(decrypted)) 52 | // Output: hello world 53 | } 54 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/nacl/sign/sign_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package sign 6 | 7 | import ( 8 | "bytes" 9 | "crypto/rand" 10 | "encoding/hex" 11 | "testing" 12 | ) 13 | 14 | var testSignedMessage, _ = hex.DecodeString("26a0a47f733d02ddb74589b6cbd6f64a7dab1947db79395a1a9e00e4c902c0f185b119897b89b248d16bab4ea781b5a3798d25c2984aec833dddab57e0891e0d68656c6c6f20776f726c64") 15 | var testMessage = testSignedMessage[Overhead:] 16 | var testPublicKey [32]byte 17 | var testPrivateKey = [64]byte{ 18 | 0x98, 0x3c, 0x6a, 0xa6, 0x21, 0xcc, 0xbb, 0xb2, 0xa7, 0xe8, 0x97, 0x94, 0xde, 0x5f, 0xf8, 0x11, 19 | 0x8a, 0xf3, 0x33, 0x1a, 0x03, 0x5c, 0x43, 0x99, 0x03, 0x13, 0x2d, 0xd7, 0xb4, 0xc4, 0x8b, 0xb0, 20 | 0xf6, 0x33, 0x20, 0xa3, 0x34, 0x8b, 0x7b, 0xe2, 0xfe, 0xb4, 0xe7, 0x3a, 0x54, 0x08, 0x2d, 0xd7, 21 | 0x0c, 0xb7, 0xc0, 0xe3, 0xbf, 0x62, 0x6c, 0x55, 0xf0, 0x33, 0x28, 0x52, 0xf8, 0x48, 0x7d, 0xfd, 22 | } 23 | 24 | func init() { 25 | copy(testPublicKey[:], testPrivateKey[32:]) 26 | } 27 | 28 | func TestSign(t *testing.T) { 29 | signedMessage := Sign(nil, testMessage, &testPrivateKey) 30 | if !bytes.Equal(signedMessage, testSignedMessage) { 31 | t.Fatalf("signed message did not match, got\n%x\n, expected\n%x", signedMessage, testSignedMessage) 32 | } 33 | } 34 | 35 | func TestOpen(t *testing.T) { 36 | message, ok := Open(nil, testSignedMessage, &testPublicKey) 37 | if !ok { 38 | t.Fatalf("valid signed message not successfully verified") 39 | } 40 | if !bytes.Equal(message, testMessage) { 41 | t.Fatalf("message did not match, got\n%x\n, expected\n%x", message, testMessage) 42 | } 43 | _, ok = Open(nil, testSignedMessage[1:], &testPublicKey) 44 | if ok { 45 | t.Fatalf("invalid signed message successfully verified") 46 | } 47 | 48 | badMessage := make([]byte, len(testSignedMessage)) 49 | copy(badMessage, testSignedMessage) 50 | badMessage[5] ^= 1 51 | if _, ok := Open(nil, badMessage, &testPublicKey); ok { 52 | t.Fatalf("Open succeeded with a corrupt message") 53 | } 54 | 55 | var badPublicKey [32]byte 56 | copy(badPublicKey[:], testPublicKey[:]) 57 | badPublicKey[5] ^= 1 58 | if _, ok := Open(nil, testSignedMessage, &badPublicKey); ok { 59 | t.Fatalf("Open succeeded with a corrupt public key") 60 | } 61 | } 62 | 63 | func TestGenerateSignOpen(t *testing.T) { 64 | publicKey, privateKey, _ := GenerateKey(rand.Reader) 65 | signedMessage := Sign(nil, testMessage, privateKey) 66 | message, ok := Open(nil, signedMessage, publicKey) 67 | if !ok { 68 | t.Fatalf("failed to verify signed message") 69 | } 70 | 71 | if !bytes.Equal(message, testMessage) { 72 | t.Fatalf("verified message does not match signed messge, got\n%x\n, expected\n%x", message, testMessage) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/canonical_text.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package openpgp 6 | 7 | import "hash" 8 | 9 | // NewCanonicalTextHash reformats text written to it into the canonical 10 | // form and then applies the hash h. See RFC 4880, section 5.2.1. 11 | func NewCanonicalTextHash(h hash.Hash) hash.Hash { 12 | return &canonicalTextHash{h, 0} 13 | } 14 | 15 | type canonicalTextHash struct { 16 | h hash.Hash 17 | s int 18 | } 19 | 20 | var newline = []byte{'\r', '\n'} 21 | 22 | func (cth *canonicalTextHash) Write(buf []byte) (int, error) { 23 | start := 0 24 | 25 | for i, c := range buf { 26 | switch cth.s { 27 | case 0: 28 | if c == '\r' { 29 | cth.s = 1 30 | } else if c == '\n' { 31 | cth.h.Write(buf[start:i]) 32 | cth.h.Write(newline) 33 | start = i + 1 34 | } 35 | case 1: 36 | cth.s = 0 37 | } 38 | } 39 | 40 | cth.h.Write(buf[start:]) 41 | return len(buf), nil 42 | } 43 | 44 | func (cth *canonicalTextHash) Sum(in []byte) []byte { 45 | return cth.h.Sum(in) 46 | } 47 | 48 | func (cth *canonicalTextHash) Reset() { 49 | cth.h.Reset() 50 | cth.s = 0 51 | } 52 | 53 | func (cth *canonicalTextHash) Size() int { 54 | return cth.h.Size() 55 | } 56 | 57 | func (cth *canonicalTextHash) BlockSize() int { 58 | return cth.h.BlockSize() 59 | } 60 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/canonical_text_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package openpgp 6 | 7 | import ( 8 | "bytes" 9 | "testing" 10 | ) 11 | 12 | type recordingHash struct { 13 | buf *bytes.Buffer 14 | } 15 | 16 | func (r recordingHash) Write(b []byte) (n int, err error) { 17 | return r.buf.Write(b) 18 | } 19 | 20 | func (r recordingHash) Sum(in []byte) []byte { 21 | return append(in, r.buf.Bytes()...) 22 | } 23 | 24 | func (r recordingHash) Reset() { 25 | panic("shouldn't be called") 26 | } 27 | 28 | func (r recordingHash) Size() int { 29 | panic("shouldn't be called") 30 | } 31 | 32 | func (r recordingHash) BlockSize() int { 33 | panic("shouldn't be called") 34 | } 35 | 36 | func testCanonicalText(t *testing.T, input, expected string) { 37 | r := recordingHash{bytes.NewBuffer(nil)} 38 | c := NewCanonicalTextHash(r) 39 | c.Write([]byte(input)) 40 | result := c.Sum(nil) 41 | if expected != string(result) { 42 | t.Errorf("input: %x got: %x want: %x", input, result, expected) 43 | } 44 | } 45 | 46 | func TestCanonicalText(t *testing.T) { 47 | testCanonicalText(t, "foo\n", "foo\r\n") 48 | testCanonicalText(t, "foo", "foo") 49 | testCanonicalText(t, "foo\r\n", "foo\r\n") 50 | testCanonicalText(t, "foo\r\nbar", "foo\r\nbar") 51 | testCanonicalText(t, "foo\r\nbar\n\n", "foo\r\nbar\r\n\r\n") 52 | } 53 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/elgamal/elgamal_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package elgamal 6 | 7 | import ( 8 | "bytes" 9 | "crypto/rand" 10 | "math/big" 11 | "testing" 12 | ) 13 | 14 | // This is the 1024-bit MODP group from RFC 5114, section 2.1: 15 | const primeHex = "B10B8F96A080E01DDE92DE5EAE5D54EC52C99FBCFB06A3C69A6A9DCA52D23B616073E28675A23D189838EF1E2EE652C013ECB4AEA906112324975C3CD49B83BFACCBDD7D90C4BD7098488E9C219A73724EFFD6FAE5644738FAA31A4FF55BCCC0A151AF5F0DC8B4BD45BF37DF365C1A65E68CFDA76D4DA708DF1FB2BC2E4A4371" 16 | 17 | const generatorHex = "A4D1CBD5C3FD34126765A442EFB99905F8104DD258AC507FD6406CFF14266D31266FEA1E5C41564B777E690F5504F213160217B4B01B886A5E91547F9E2749F4D7FBD7D3B9A92EE1909D0D2263F80A76A6A24C087A091F531DBF0A0169B6A28AD662A4D18E73AFA32D779D5918D08BC8858F4DCEF97C2A24855E6EEB22B3B2E5" 18 | 19 | func fromHex(hex string) *big.Int { 20 | n, ok := new(big.Int).SetString(hex, 16) 21 | if !ok { 22 | panic("failed to parse hex number") 23 | } 24 | return n 25 | } 26 | 27 | func TestEncryptDecrypt(t *testing.T) { 28 | priv := &PrivateKey{ 29 | PublicKey: PublicKey{ 30 | G: fromHex(generatorHex), 31 | P: fromHex(primeHex), 32 | }, 33 | X: fromHex("42"), 34 | } 35 | priv.Y = new(big.Int).Exp(priv.G, priv.X, priv.P) 36 | 37 | message := []byte("hello world") 38 | c1, c2, err := Encrypt(rand.Reader, &priv.PublicKey, message) 39 | if err != nil { 40 | t.Errorf("error encrypting: %s", err) 41 | } 42 | message2, err := Decrypt(priv, c1, c2) 43 | if err != nil { 44 | t.Errorf("error decrypting: %s", err) 45 | } 46 | if !bytes.Equal(message2, message) { 47 | t.Errorf("decryption failed, got: %x, want: %x", message2, message) 48 | } 49 | } 50 | 51 | func TestDecryptBadKey(t *testing.T) { 52 | priv := &PrivateKey{ 53 | PublicKey: PublicKey{ 54 | G: fromHex(generatorHex), 55 | P: fromHex("2"), 56 | }, 57 | X: fromHex("42"), 58 | } 59 | priv.Y = new(big.Int).Exp(priv.G, priv.X, priv.P) 60 | c1, c2 := fromHex("8"), fromHex("8") 61 | if _, err := Decrypt(priv, c1, c2); err == nil { 62 | t.Errorf("unexpected success decrypting") 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/errors/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package errors contains common error types for the OpenPGP packages. 6 | package errors // import "golang.org/x/crypto/openpgp/errors" 7 | 8 | import ( 9 | "strconv" 10 | ) 11 | 12 | // A StructuralError is returned when OpenPGP data is found to be syntactically 13 | // invalid. 14 | type StructuralError string 15 | 16 | func (s StructuralError) Error() string { 17 | return "openpgp: invalid data: " + string(s) 18 | } 19 | 20 | // UnsupportedError indicates that, although the OpenPGP data is valid, it 21 | // makes use of currently unimplemented features. 22 | type UnsupportedError string 23 | 24 | func (s UnsupportedError) Error() string { 25 | return "openpgp: unsupported feature: " + string(s) 26 | } 27 | 28 | // InvalidArgumentError indicates that the caller is in error and passed an 29 | // incorrect value. 30 | type InvalidArgumentError string 31 | 32 | func (i InvalidArgumentError) Error() string { 33 | return "openpgp: invalid argument: " + string(i) 34 | } 35 | 36 | // SignatureError indicates that a syntactically valid signature failed to 37 | // validate. 38 | type SignatureError string 39 | 40 | func (b SignatureError) Error() string { 41 | return "openpgp: invalid signature: " + string(b) 42 | } 43 | 44 | type keyIncorrectError int 45 | 46 | func (ki keyIncorrectError) Error() string { 47 | return "openpgp: incorrect key" 48 | } 49 | 50 | var ErrKeyIncorrect error = keyIncorrectError(0) 51 | 52 | type unknownIssuerError int 53 | 54 | func (unknownIssuerError) Error() string { 55 | return "openpgp: signature made by unknown entity" 56 | } 57 | 58 | var ErrUnknownIssuer error = unknownIssuerError(0) 59 | 60 | type keyRevokedError int 61 | 62 | func (keyRevokedError) Error() string { 63 | return "openpgp: signature made by revoked key" 64 | } 65 | 66 | var ErrKeyRevoked error = keyRevokedError(0) 67 | 68 | type UnknownPacketTypeError uint8 69 | 70 | func (upte UnknownPacketTypeError) Error() string { 71 | return "openpgp: unknown packet type: " + strconv.Itoa(int(upte)) 72 | } 73 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/packet/compressed_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packet 6 | 7 | import ( 8 | "bytes" 9 | "encoding/hex" 10 | "io" 11 | "io/ioutil" 12 | "testing" 13 | ) 14 | 15 | func TestCompressed(t *testing.T) { 16 | packet, err := Read(readerFromHex(compressedHex)) 17 | if err != nil { 18 | t.Errorf("failed to read Compressed: %s", err) 19 | return 20 | } 21 | 22 | c, ok := packet.(*Compressed) 23 | if !ok { 24 | t.Error("didn't find Compressed packet") 25 | return 26 | } 27 | 28 | contents, err := ioutil.ReadAll(c.Body) 29 | if err != nil && err != io.EOF { 30 | t.Error(err) 31 | return 32 | } 33 | 34 | expected, _ := hex.DecodeString(compressedExpectedHex) 35 | if !bytes.Equal(expected, contents) { 36 | t.Errorf("got:%x want:%x", contents, expected) 37 | } 38 | } 39 | 40 | const compressedHex = "a3013b2d90c4e02b72e25f727e5e496a5e49b11e1700" 41 | const compressedExpectedHex = "cb1062004d14c8fe636f6e74656e74732e0a" 42 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/packet/config.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packet 6 | 7 | import ( 8 | "crypto" 9 | "crypto/rand" 10 | "io" 11 | "time" 12 | ) 13 | 14 | // Config collects a number of parameters along with sensible defaults. 15 | // A nil *Config is valid and results in all default values. 16 | type Config struct { 17 | // Rand provides the source of entropy. 18 | // If nil, the crypto/rand Reader is used. 19 | Rand io.Reader 20 | // DefaultHash is the default hash function to be used. 21 | // If zero, SHA-256 is used. 22 | DefaultHash crypto.Hash 23 | // DefaultCipher is the cipher to be used. 24 | // If zero, AES-128 is used. 25 | DefaultCipher CipherFunction 26 | // Time returns the current time as the number of seconds since the 27 | // epoch. If Time is nil, time.Now is used. 28 | Time func() time.Time 29 | // DefaultCompressionAlgo is the compression algorithm to be 30 | // applied to the plaintext before encryption. If zero, no 31 | // compression is done. 32 | DefaultCompressionAlgo CompressionAlgo 33 | // CompressionConfig configures the compression settings. 34 | CompressionConfig *CompressionConfig 35 | // S2KCount is only used for symmetric encryption. It 36 | // determines the strength of the passphrase stretching when 37 | // the said passphrase is hashed to produce a key. S2KCount 38 | // should be between 1024 and 65011712, inclusive. If Config 39 | // is nil or S2KCount is 0, the value 65536 used. Not all 40 | // values in the above range can be represented. S2KCount will 41 | // be rounded up to the next representable value if it cannot 42 | // be encoded exactly. When set, it is strongly encrouraged to 43 | // use a value that is at least 65536. See RFC 4880 Section 44 | // 3.7.1.3. 45 | S2KCount int 46 | // RSABits is the number of bits in new RSA keys made with NewEntity. 47 | // If zero, then 2048 bit keys are created. 48 | RSABits int 49 | } 50 | 51 | func (c *Config) Random() io.Reader { 52 | if c == nil || c.Rand == nil { 53 | return rand.Reader 54 | } 55 | return c.Rand 56 | } 57 | 58 | func (c *Config) Hash() crypto.Hash { 59 | if c == nil || uint(c.DefaultHash) == 0 { 60 | return crypto.SHA256 61 | } 62 | return c.DefaultHash 63 | } 64 | 65 | func (c *Config) Cipher() CipherFunction { 66 | if c == nil || uint8(c.DefaultCipher) == 0 { 67 | return CipherAES128 68 | } 69 | return c.DefaultCipher 70 | } 71 | 72 | func (c *Config) Now() time.Time { 73 | if c == nil || c.Time == nil { 74 | return time.Now() 75 | } 76 | return c.Time() 77 | } 78 | 79 | func (c *Config) Compression() CompressionAlgo { 80 | if c == nil { 81 | return CompressionNone 82 | } 83 | return c.DefaultCompressionAlgo 84 | } 85 | 86 | func (c *Config) PasswordHashIterations() int { 87 | if c == nil || c.S2KCount == 0 { 88 | return 0 89 | } 90 | return c.S2KCount 91 | } 92 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/packet/literal.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packet 6 | 7 | import ( 8 | "encoding/binary" 9 | "io" 10 | ) 11 | 12 | // LiteralData represents an encrypted file. See RFC 4880, section 5.9. 13 | type LiteralData struct { 14 | IsBinary bool 15 | FileName string 16 | Time uint32 // Unix epoch time. Either creation time or modification time. 0 means undefined. 17 | Body io.Reader 18 | } 19 | 20 | // ForEyesOnly returns whether the contents of the LiteralData have been marked 21 | // as especially sensitive. 22 | func (l *LiteralData) ForEyesOnly() bool { 23 | return l.FileName == "_CONSOLE" 24 | } 25 | 26 | func (l *LiteralData) parse(r io.Reader) (err error) { 27 | var buf [256]byte 28 | 29 | _, err = readFull(r, buf[:2]) 30 | if err != nil { 31 | return 32 | } 33 | 34 | l.IsBinary = buf[0] == 'b' 35 | fileNameLen := int(buf[1]) 36 | 37 | _, err = readFull(r, buf[:fileNameLen]) 38 | if err != nil { 39 | return 40 | } 41 | 42 | l.FileName = string(buf[:fileNameLen]) 43 | 44 | _, err = readFull(r, buf[:4]) 45 | if err != nil { 46 | return 47 | } 48 | 49 | l.Time = binary.BigEndian.Uint32(buf[:4]) 50 | l.Body = r 51 | return 52 | } 53 | 54 | // SerializeLiteral serializes a literal data packet to w and returns a 55 | // WriteCloser to which the data itself can be written and which MUST be closed 56 | // on completion. The fileName is truncated to 255 bytes. 57 | func SerializeLiteral(w io.WriteCloser, isBinary bool, fileName string, time uint32) (plaintext io.WriteCloser, err error) { 58 | var buf [4]byte 59 | buf[0] = 't' 60 | if isBinary { 61 | buf[0] = 'b' 62 | } 63 | if len(fileName) > 255 { 64 | fileName = fileName[:255] 65 | } 66 | buf[1] = byte(len(fileName)) 67 | 68 | inner, err := serializeStreamHeader(w, packetTypeLiteralData) 69 | if err != nil { 70 | return 71 | } 72 | 73 | _, err = inner.Write(buf[:2]) 74 | if err != nil { 75 | return 76 | } 77 | _, err = inner.Write([]byte(fileName)) 78 | if err != nil { 79 | return 80 | } 81 | binary.BigEndian.PutUint32(buf[:], time) 82 | _, err = inner.Write(buf[:]) 83 | if err != nil { 84 | return 85 | } 86 | 87 | plaintext = inner 88 | return 89 | } 90 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/packet/ocfb_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packet 6 | 7 | import ( 8 | "bytes" 9 | "crypto/aes" 10 | "crypto/rand" 11 | "testing" 12 | ) 13 | 14 | var commonKey128 = []byte{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c} 15 | 16 | func testOCFB(t *testing.T, resync OCFBResyncOption) { 17 | block, err := aes.NewCipher(commonKey128) 18 | if err != nil { 19 | t.Error(err) 20 | return 21 | } 22 | 23 | plaintext := []byte("this is the plaintext, which is long enough to span several blocks.") 24 | randData := make([]byte, block.BlockSize()) 25 | rand.Reader.Read(randData) 26 | ocfb, prefix := NewOCFBEncrypter(block, randData, resync) 27 | ciphertext := make([]byte, len(plaintext)) 28 | ocfb.XORKeyStream(ciphertext, plaintext) 29 | 30 | ocfbdec := NewOCFBDecrypter(block, prefix, resync) 31 | if ocfbdec == nil { 32 | t.Errorf("NewOCFBDecrypter failed (resync: %t)", resync) 33 | return 34 | } 35 | plaintextCopy := make([]byte, len(plaintext)) 36 | ocfbdec.XORKeyStream(plaintextCopy, ciphertext) 37 | 38 | if !bytes.Equal(plaintextCopy, plaintext) { 39 | t.Errorf("got: %x, want: %x (resync: %t)", plaintextCopy, plaintext, resync) 40 | } 41 | } 42 | 43 | func TestOCFB(t *testing.T) { 44 | testOCFB(t, OCFBNoResync) 45 | testOCFB(t, OCFBResync) 46 | } 47 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/packet/one_pass_signature.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packet 6 | 7 | import ( 8 | "crypto" 9 | "encoding/binary" 10 | "golang.org/x/crypto/openpgp/errors" 11 | "golang.org/x/crypto/openpgp/s2k" 12 | "io" 13 | "strconv" 14 | ) 15 | 16 | // OnePassSignature represents a one-pass signature packet. See RFC 4880, 17 | // section 5.4. 18 | type OnePassSignature struct { 19 | SigType SignatureType 20 | Hash crypto.Hash 21 | PubKeyAlgo PublicKeyAlgorithm 22 | KeyId uint64 23 | IsLast bool 24 | } 25 | 26 | const onePassSignatureVersion = 3 27 | 28 | func (ops *OnePassSignature) parse(r io.Reader) (err error) { 29 | var buf [13]byte 30 | 31 | _, err = readFull(r, buf[:]) 32 | if err != nil { 33 | return 34 | } 35 | if buf[0] != onePassSignatureVersion { 36 | err = errors.UnsupportedError("one-pass-signature packet version " + strconv.Itoa(int(buf[0]))) 37 | } 38 | 39 | var ok bool 40 | ops.Hash, ok = s2k.HashIdToHash(buf[2]) 41 | if !ok { 42 | return errors.UnsupportedError("hash function: " + strconv.Itoa(int(buf[2]))) 43 | } 44 | 45 | ops.SigType = SignatureType(buf[1]) 46 | ops.PubKeyAlgo = PublicKeyAlgorithm(buf[3]) 47 | ops.KeyId = binary.BigEndian.Uint64(buf[4:12]) 48 | ops.IsLast = buf[12] != 0 49 | return 50 | } 51 | 52 | // Serialize marshals the given OnePassSignature to w. 53 | func (ops *OnePassSignature) Serialize(w io.Writer) error { 54 | var buf [13]byte 55 | buf[0] = onePassSignatureVersion 56 | buf[1] = uint8(ops.SigType) 57 | var ok bool 58 | buf[2], ok = s2k.HashToHashId(ops.Hash) 59 | if !ok { 60 | return errors.UnsupportedError("hash type: " + strconv.Itoa(int(ops.Hash))) 61 | } 62 | buf[3] = uint8(ops.PubKeyAlgo) 63 | binary.BigEndian.PutUint64(buf[4:12], ops.KeyId) 64 | if ops.IsLast { 65 | buf[12] = 1 66 | } 67 | 68 | if err := serializeHeader(w, packetTypeOnePassSignature, len(buf)); err != nil { 69 | return err 70 | } 71 | _, err := w.Write(buf[:]) 72 | return err 73 | } 74 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/packet/opaque_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packet 6 | 7 | import ( 8 | "bytes" 9 | "encoding/hex" 10 | "io" 11 | "testing" 12 | ) 13 | 14 | // Test packet.Read error handling in OpaquePacket.Parse, 15 | // which attempts to re-read an OpaquePacket as a supported 16 | // Packet type. 17 | func TestOpaqueParseReason(t *testing.T) { 18 | buf, err := hex.DecodeString(UnsupportedKeyHex) 19 | if err != nil { 20 | t.Fatal(err) 21 | } 22 | or := NewOpaqueReader(bytes.NewBuffer(buf)) 23 | count := 0 24 | badPackets := 0 25 | var uid *UserId 26 | for { 27 | op, err := or.Next() 28 | if err == io.EOF { 29 | break 30 | } else if err != nil { 31 | t.Errorf("#%d: opaque read error: %v", count, err) 32 | break 33 | } 34 | // try to parse opaque packet 35 | p, _ := op.Parse() 36 | switch pkt := p.(type) { 37 | case *UserId: 38 | uid = pkt 39 | case *OpaquePacket: 40 | // If an OpaquePacket can't re-parse, packet.Read 41 | // certainly had its reasons. 42 | if pkt.Reason == nil { 43 | t.Errorf("#%d: opaque packet, no reason", count) 44 | } else { 45 | badPackets++ 46 | } 47 | } 48 | count++ 49 | } 50 | 51 | const expectedBad = 3 52 | // Test post-conditions, make sure we actually parsed packets as expected. 53 | if badPackets != expectedBad { 54 | t.Errorf("unexpected # unparseable packets: %d (want %d)", badPackets, expectedBad) 55 | } 56 | if uid == nil { 57 | t.Errorf("failed to find expected UID in unsupported keyring") 58 | } else if uid.Id != "Armin M. Warda " { 59 | t.Errorf("unexpected UID: %v", uid.Id) 60 | } 61 | } 62 | 63 | // This key material has public key and signature packet versions modified to 64 | // an unsupported value (1), so that trying to parse the OpaquePacket to 65 | // a typed packet will get an error. It also contains a GnuPG trust packet. 66 | // (Created with: od -An -t x1 pubring.gpg | xargs | sed 's/ //g') 67 | const UnsupportedKeyHex = `988d012e7a18a20000010400d6ac00d92b89c1f4396c243abb9b76d2e9673ad63483291fed88e22b82e255e441c078c6abbbf7d2d195e50b62eeaa915b85b0ec20c225ce2c64c167cacb6e711daf2e45da4a8356a059b8160e3b3628ac0dd8437b31f06d53d6e8ea4214d4a26406a6b63e1001406ef23e0bb3069fac9a99a91f77dfafd5de0f188a5da5e3c9000511b42741726d696e204d2e205761726461203c7761726461406e657068696c696d2e727568722e64653e8900950105102e8936c705d1eb399e58489901013f0e03ff5a0c4f421e34fcfa388129166420c08cd76987bcdec6f01bd0271459a85cc22048820dd4e44ac2c7d23908d540f54facf1b36b0d9c20488781ce9dca856531e76e2e846826e9951338020a03a09b57aa5faa82e9267458bd76105399885ac35af7dc1cbb6aaed7c39e1039f3b5beda2c0e916bd38560509bab81235d1a0ead83b0020000` 68 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/packet/public_key_v3_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packet 6 | 7 | import ( 8 | "bytes" 9 | "encoding/hex" 10 | "testing" 11 | "time" 12 | ) 13 | 14 | var pubKeyV3Test = struct { 15 | hexFingerprint string 16 | creationTime time.Time 17 | pubKeyAlgo PublicKeyAlgorithm 18 | keyId uint64 19 | keyIdString string 20 | keyIdShort string 21 | }{ 22 | "103BECF5BD1E837C89D19E98487767F7", 23 | time.Unix(779753634, 0), 24 | PubKeyAlgoRSA, 25 | 0xDE0F188A5DA5E3C9, 26 | "DE0F188A5DA5E3C9", 27 | "5DA5E3C9"} 28 | 29 | func TestPublicKeyV3Read(t *testing.T) { 30 | i, test := 0, pubKeyV3Test 31 | packet, err := Read(v3KeyReader(t)) 32 | if err != nil { 33 | t.Fatalf("#%d: Read error: %s", i, err) 34 | } 35 | pk, ok := packet.(*PublicKeyV3) 36 | if !ok { 37 | t.Fatalf("#%d: failed to parse, got: %#v", i, packet) 38 | } 39 | if pk.PubKeyAlgo != test.pubKeyAlgo { 40 | t.Errorf("#%d: bad public key algorithm got:%x want:%x", i, pk.PubKeyAlgo, test.pubKeyAlgo) 41 | } 42 | if !pk.CreationTime.Equal(test.creationTime) { 43 | t.Errorf("#%d: bad creation time got:%v want:%v", i, pk.CreationTime, test.creationTime) 44 | } 45 | expectedFingerprint, _ := hex.DecodeString(test.hexFingerprint) 46 | if !bytes.Equal(expectedFingerprint, pk.Fingerprint[:]) { 47 | t.Errorf("#%d: bad fingerprint got:%x want:%x", i, pk.Fingerprint[:], expectedFingerprint) 48 | } 49 | if pk.KeyId != test.keyId { 50 | t.Errorf("#%d: bad keyid got:%x want:%x", i, pk.KeyId, test.keyId) 51 | } 52 | if g, e := pk.KeyIdString(), test.keyIdString; g != e { 53 | t.Errorf("#%d: bad KeyIdString got:%q want:%q", i, g, e) 54 | } 55 | if g, e := pk.KeyIdShortString(), test.keyIdShort; g != e { 56 | t.Errorf("#%d: bad KeyIdShortString got:%q want:%q", i, g, e) 57 | } 58 | } 59 | 60 | func TestPublicKeyV3Serialize(t *testing.T) { 61 | //for i, test := range pubKeyV3Tests { 62 | i := 0 63 | packet, err := Read(v3KeyReader(t)) 64 | if err != nil { 65 | t.Fatalf("#%d: Read error: %s", i, err) 66 | } 67 | pk, ok := packet.(*PublicKeyV3) 68 | if !ok { 69 | t.Fatalf("#%d: failed to parse, got: %#v", i, packet) 70 | } 71 | var serializeBuf bytes.Buffer 72 | if err = pk.Serialize(&serializeBuf); err != nil { 73 | t.Fatalf("#%d: failed to serialize: %s", i, err) 74 | } 75 | 76 | if packet, err = Read(bytes.NewBuffer(serializeBuf.Bytes())); err != nil { 77 | t.Fatalf("#%d: Read error (from serialized data): %s", i, err) 78 | } 79 | if pk, ok = packet.(*PublicKeyV3); !ok { 80 | t.Fatalf("#%d: failed to parse serialized data, got: %#v", i, packet) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/packet/reader.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packet 6 | 7 | import ( 8 | "golang.org/x/crypto/openpgp/errors" 9 | "io" 10 | ) 11 | 12 | // Reader reads packets from an io.Reader and allows packets to be 'unread' so 13 | // that they result from the next call to Next. 14 | type Reader struct { 15 | q []Packet 16 | readers []io.Reader 17 | } 18 | 19 | // New io.Readers are pushed when a compressed or encrypted packet is processed 20 | // and recursively treated as a new source of packets. However, a carefully 21 | // crafted packet can trigger an infinite recursive sequence of packets. See 22 | // http://mumble.net/~campbell/misc/pgp-quine 23 | // https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2013-4402 24 | // This constant limits the number of recursive packets that may be pushed. 25 | const maxReaders = 32 26 | 27 | // Next returns the most recently unread Packet, or reads another packet from 28 | // the top-most io.Reader. Unknown packet types are skipped. 29 | func (r *Reader) Next() (p Packet, err error) { 30 | if len(r.q) > 0 { 31 | p = r.q[len(r.q)-1] 32 | r.q = r.q[:len(r.q)-1] 33 | return 34 | } 35 | 36 | for len(r.readers) > 0 { 37 | p, err = Read(r.readers[len(r.readers)-1]) 38 | if err == nil { 39 | return 40 | } 41 | if err == io.EOF { 42 | r.readers = r.readers[:len(r.readers)-1] 43 | continue 44 | } 45 | if _, ok := err.(errors.UnknownPacketTypeError); !ok { 46 | return nil, err 47 | } 48 | } 49 | 50 | return nil, io.EOF 51 | } 52 | 53 | // Push causes the Reader to start reading from a new io.Reader. When an EOF 54 | // error is seen from the new io.Reader, it is popped and the Reader continues 55 | // to read from the next most recent io.Reader. Push returns a StructuralError 56 | // if pushing the reader would exceed the maximum recursion level, otherwise it 57 | // returns nil. 58 | func (r *Reader) Push(reader io.Reader) (err error) { 59 | if len(r.readers) >= maxReaders { 60 | return errors.StructuralError("too many layers of packets") 61 | } 62 | r.readers = append(r.readers, reader) 63 | return nil 64 | } 65 | 66 | // Unread causes the given Packet to be returned from the next call to Next. 67 | func (r *Reader) Unread(p Packet) { 68 | r.q = append(r.q, p) 69 | } 70 | 71 | func NewReader(r io.Reader) *Reader { 72 | return &Reader{ 73 | q: nil, 74 | readers: []io.Reader{r}, 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/packet/signature_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packet 6 | 7 | import ( 8 | "bytes" 9 | "crypto" 10 | "encoding/hex" 11 | "testing" 12 | ) 13 | 14 | func TestSignatureRead(t *testing.T) { 15 | packet, err := Read(readerFromHex(signatureDataHex)) 16 | if err != nil { 17 | t.Error(err) 18 | return 19 | } 20 | sig, ok := packet.(*Signature) 21 | if !ok || sig.SigType != SigTypeBinary || sig.PubKeyAlgo != PubKeyAlgoRSA || sig.Hash != crypto.SHA1 { 22 | t.Errorf("failed to parse, got: %#v", packet) 23 | } 24 | } 25 | 26 | func TestSignatureReserialize(t *testing.T) { 27 | packet, _ := Read(readerFromHex(signatureDataHex)) 28 | sig := packet.(*Signature) 29 | out := new(bytes.Buffer) 30 | err := sig.Serialize(out) 31 | if err != nil { 32 | t.Errorf("error reserializing: %s", err) 33 | return 34 | } 35 | 36 | expected, _ := hex.DecodeString(signatureDataHex) 37 | if !bytes.Equal(expected, out.Bytes()) { 38 | t.Errorf("output doesn't match input (got vs expected):\n%s\n%s", hex.Dump(out.Bytes()), hex.Dump(expected)) 39 | } 40 | } 41 | 42 | func TestSignUserId(t *testing.T) { 43 | sig := &Signature{ 44 | SigType: SigTypeGenericCert, 45 | PubKeyAlgo: PubKeyAlgoRSA, 46 | Hash: 0, // invalid hash function 47 | } 48 | 49 | packet, err := Read(readerFromHex(rsaPkDataHex)) 50 | if err != nil { 51 | t.Fatalf("failed to deserialize public key: %v", err) 52 | } 53 | pubKey := packet.(*PublicKey) 54 | 55 | packet, err = Read(readerFromHex(privKeyRSAHex)) 56 | if err != nil { 57 | t.Fatalf("failed to deserialize private key: %v", err) 58 | } 59 | privKey := packet.(*PrivateKey) 60 | 61 | err = sig.SignUserId("", pubKey, privKey, nil) 62 | if err == nil { 63 | t.Errorf("did not receive an error when expected") 64 | } 65 | 66 | sig.Hash = crypto.SHA256 67 | err = privKey.Decrypt([]byte("testing")) 68 | if err != nil { 69 | t.Fatalf("failed to decrypt private key: %v", err) 70 | } 71 | 72 | err = sig.SignUserId("", pubKey, privKey, nil) 73 | if err != nil { 74 | t.Errorf("failed to sign user id: %v", err) 75 | } 76 | } 77 | 78 | const signatureDataHex = "c2c05c04000102000605024cb45112000a0910ab105c91af38fb158f8d07ff5596ea368c5efe015bed6e78348c0f033c931d5f2ce5db54ce7f2a7e4b4ad64db758d65a7a71773edeab7ba2a9e0908e6a94a1175edd86c1d843279f045b021a6971a72702fcbd650efc393c5474d5b59a15f96d2eaad4c4c426797e0dcca2803ef41c6ff234d403eec38f31d610c344c06f2401c262f0993b2e66cad8a81ebc4322c723e0d4ba09fe917e8777658307ad8329adacba821420741009dfe87f007759f0982275d028a392c6ed983a0d846f890b36148c7358bdb8a516007fac760261ecd06076813831a36d0459075d1befa245ae7f7fb103d92ca759e9498fe60ef8078a39a3beda510deea251ea9f0a7f0df6ef42060f20780360686f3e400e" 79 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/packet/userattribute.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packet 6 | 7 | import ( 8 | "bytes" 9 | "image" 10 | "image/jpeg" 11 | "io" 12 | "io/ioutil" 13 | ) 14 | 15 | const UserAttrImageSubpacket = 1 16 | 17 | // UserAttribute is capable of storing other types of data about a user 18 | // beyond name, email and a text comment. In practice, user attributes are typically used 19 | // to store a signed thumbnail photo JPEG image of the user. 20 | // See RFC 4880, section 5.12. 21 | type UserAttribute struct { 22 | Contents []*OpaqueSubpacket 23 | } 24 | 25 | // NewUserAttributePhoto creates a user attribute packet 26 | // containing the given images. 27 | func NewUserAttributePhoto(photos ...image.Image) (uat *UserAttribute, err error) { 28 | uat = new(UserAttribute) 29 | for _, photo := range photos { 30 | var buf bytes.Buffer 31 | // RFC 4880, Section 5.12.1. 32 | data := []byte{ 33 | 0x10, 0x00, // Little-endian image header length (16 bytes) 34 | 0x01, // Image header version 1 35 | 0x01, // JPEG 36 | 0, 0, 0, 0, // 12 reserved octets, must be all zero. 37 | 0, 0, 0, 0, 38 | 0, 0, 0, 0} 39 | if _, err = buf.Write(data); err != nil { 40 | return 41 | } 42 | if err = jpeg.Encode(&buf, photo, nil); err != nil { 43 | return 44 | } 45 | uat.Contents = append(uat.Contents, &OpaqueSubpacket{ 46 | SubType: UserAttrImageSubpacket, 47 | Contents: buf.Bytes()}) 48 | } 49 | return 50 | } 51 | 52 | // NewUserAttribute creates a new user attribute packet containing the given subpackets. 53 | func NewUserAttribute(contents ...*OpaqueSubpacket) *UserAttribute { 54 | return &UserAttribute{Contents: contents} 55 | } 56 | 57 | func (uat *UserAttribute) parse(r io.Reader) (err error) { 58 | // RFC 4880, section 5.13 59 | b, err := ioutil.ReadAll(r) 60 | if err != nil { 61 | return 62 | } 63 | uat.Contents, err = OpaqueSubpackets(b) 64 | return 65 | } 66 | 67 | // Serialize marshals the user attribute to w in the form of an OpenPGP packet, including 68 | // header. 69 | func (uat *UserAttribute) Serialize(w io.Writer) (err error) { 70 | var buf bytes.Buffer 71 | for _, sp := range uat.Contents { 72 | sp.Serialize(&buf) 73 | } 74 | if err = serializeHeader(w, packetTypeUserAttribute, buf.Len()); err != nil { 75 | return err 76 | } 77 | _, err = w.Write(buf.Bytes()) 78 | return 79 | } 80 | 81 | // ImageData returns zero or more byte slices, each containing 82 | // JPEG File Interchange Format (JFIF), for each photo in the 83 | // user attribute packet. 84 | func (uat *UserAttribute) ImageData() (imageData [][]byte) { 85 | for _, sp := range uat.Contents { 86 | if sp.SubType == UserAttrImageSubpacket && len(sp.Contents) > 16 { 87 | imageData = append(imageData, sp.Contents[16:]) 88 | } 89 | } 90 | return 91 | } 92 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/openpgp/packet/userid_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packet 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | var userIdTests = []struct { 12 | id string 13 | name, comment, email string 14 | }{ 15 | {"", "", "", ""}, 16 | {"John Smith", "John Smith", "", ""}, 17 | {"John Smith ()", "John Smith", "", ""}, 18 | {"John Smith () <>", "John Smith", "", ""}, 19 | {"(comment", "", "comment", ""}, 20 | {"(comment)", "", "comment", ""}, 21 | {" sdfk", "", "", "email"}, 23 | {" John Smith ( Comment ) asdkflj < email > lksdfj", "John Smith", "Comment", "email"}, 24 | {" John Smith < email > lksdfj", "John Smith", "", "email"}, 25 | {"("}, 50 | {"foo", "bar", "", "foo (bar)"}, 51 | {"foo", "", "baz", "foo "}, 52 | {"", "bar", "baz", "(bar) "}, 53 | {"foo", "bar", "baz", "foo (bar) "}, 54 | } 55 | 56 | func TestNewUserId(t *testing.T) { 57 | for i, test := range newUserIdTests { 58 | uid := NewUserId(test.name, test.comment, test.email) 59 | if uid == nil { 60 | t.Errorf("#%d: returned nil", i) 61 | continue 62 | } 63 | if uid.Id != test.id { 64 | t.Errorf("#%d: got '%s', want '%s'", i, uid.Id, test.id) 65 | } 66 | } 67 | } 68 | 69 | var invalidNewUserIdTests = []struct { 70 | name, comment, email string 71 | }{ 72 | {"foo(", "", ""}, 73 | {"foo<", "", ""}, 74 | {"", "bar)", ""}, 75 | {"", "bar<", ""}, 76 | {"", "", "baz>"}, 77 | {"", "", "baz)"}, 78 | {"", "", "baz\x00"}, 79 | } 80 | 81 | func TestNewUserIdWithInvalidInput(t *testing.T) { 82 | for i, test := range invalidNewUserIdTests { 83 | if uid := NewUserId(test.name, test.comment, test.email); uid != nil { 84 | t.Errorf("#%d: returned non-nil value: %#v", i, uid) 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 7 | 2898 / PKCS #5 v2.0. 8 | 9 | A key derivation function is useful when encrypting data based on a password 10 | or any other not-fully-random data. It uses a pseudorandom function to derive 11 | a secure encryption key based on the password. 12 | 13 | While v2.0 of the standard defines only one pseudorandom function to use, 14 | HMAC-SHA1, the drafted v2.1 specification allows use of all five FIPS Approved 15 | Hash Functions SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512 for HMAC. To 16 | choose, you can pass the `New` functions from the different SHA packages to 17 | pbkdf2.Key. 18 | */ 19 | package pbkdf2 // import "golang.org/x/crypto/pbkdf2" 20 | 21 | import ( 22 | "crypto/hmac" 23 | "hash" 24 | ) 25 | 26 | // Key derives a key from the password, salt and iteration count, returning a 27 | // []byte of length keylen that can be used as cryptographic key. The key is 28 | // derived based on the method described as PBKDF2 with the HMAC variant using 29 | // the supplied hash function. 30 | // 31 | // For example, to use a HMAC-SHA-1 based PBKDF2 key derivation function, you 32 | // can get a derived key for e.g. AES-256 (which needs a 32-byte key) by 33 | // doing: 34 | // 35 | // dk := pbkdf2.Key([]byte("some password"), salt, 4096, 32, sha1.New) 36 | // 37 | // Remember to get a good random salt. At least 8 bytes is recommended by the 38 | // RFC. 39 | // 40 | // Using a higher iteration count will increase the cost of an exhaustive 41 | // search but will also make derivation proportionally slower. 42 | func Key(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte { 43 | prf := hmac.New(h, password) 44 | hashLen := prf.Size() 45 | numBlocks := (keyLen + hashLen - 1) / hashLen 46 | 47 | var buf [4]byte 48 | dk := make([]byte, 0, numBlocks*hashLen) 49 | U := make([]byte, hashLen) 50 | for block := 1; block <= numBlocks; block++ { 51 | // N.B.: || means concatenation, ^ means XOR 52 | // for each block T_i = U_1 ^ U_2 ^ ... ^ U_iter 53 | // U_1 = PRF(password, salt || uint(i)) 54 | prf.Reset() 55 | prf.Write(salt) 56 | buf[0] = byte(block >> 24) 57 | buf[1] = byte(block >> 16) 58 | buf[2] = byte(block >> 8) 59 | buf[3] = byte(block) 60 | prf.Write(buf[:4]) 61 | dk = prf.Sum(dk) 62 | T := dk[len(dk)-hashLen:] 63 | copy(U, T) 64 | 65 | // U_n = PRF(password, U_(n-1)) 66 | for n := 2; n <= iter; n++ { 67 | prf.Reset() 68 | prf.Write(U) 69 | U = U[:0] 70 | U = prf.Sum(U) 71 | for x := range U { 72 | T[x] ^= U[x] 73 | } 74 | } 75 | } 76 | return dk[:keyLen] 77 | } 78 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/pkcs12/bmp-string.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkcs12 6 | 7 | import ( 8 | "errors" 9 | "unicode/utf16" 10 | ) 11 | 12 | // bmpString returns s encoded in UCS-2 with a zero terminator. 13 | func bmpString(s string) ([]byte, error) { 14 | // References: 15 | // https://tools.ietf.org/html/rfc7292#appendix-B.1 16 | // https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane 17 | // - non-BMP characters are encoded in UTF 16 by using a surrogate pair of 16-bit codes 18 | // EncodeRune returns 0xfffd if the rune does not need special encoding 19 | // - the above RFC provides the info that BMPStrings are NULL terminated. 20 | 21 | ret := make([]byte, 0, 2*len(s)+2) 22 | 23 | for _, r := range s { 24 | if t, _ := utf16.EncodeRune(r); t != 0xfffd { 25 | return nil, errors.New("pkcs12: string contains characters that cannot be encoded in UCS-2") 26 | } 27 | ret = append(ret, byte(r/256), byte(r%256)) 28 | } 29 | 30 | return append(ret, 0, 0), nil 31 | } 32 | 33 | func decodeBMPString(bmpString []byte) (string, error) { 34 | if len(bmpString)%2 != 0 { 35 | return "", errors.New("pkcs12: odd-length BMP string") 36 | } 37 | 38 | // strip terminator if present 39 | if l := len(bmpString); l >= 2 && bmpString[l-1] == 0 && bmpString[l-2] == 0 { 40 | bmpString = bmpString[:l-2] 41 | } 42 | 43 | s := make([]uint16, 0, len(bmpString)/2) 44 | for len(bmpString) > 0 { 45 | s = append(s, uint16(bmpString[0])<<8+uint16(bmpString[1])) 46 | bmpString = bmpString[2:] 47 | } 48 | 49 | return string(utf16.Decode(s)), nil 50 | } 51 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/pkcs12/bmp-string_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkcs12 6 | 7 | import ( 8 | "bytes" 9 | "encoding/hex" 10 | "testing" 11 | ) 12 | 13 | var bmpStringTests = []struct { 14 | in string 15 | expectedHex string 16 | shouldFail bool 17 | }{ 18 | {"", "0000", false}, 19 | // Example from https://tools.ietf.org/html/rfc7292#appendix-B. 20 | {"Beavis", "0042006500610076006900730000", false}, 21 | // Some characters from the "Letterlike Symbols Unicode block". 22 | {"\u2115 - Double-struck N", "21150020002d00200044006f00750062006c0065002d00730074007200750063006b0020004e0000", false}, 23 | // any character outside the BMP should trigger an error. 24 | {"\U0001f000 East wind (Mahjong)", "", true}, 25 | } 26 | 27 | func TestBMPString(t *testing.T) { 28 | for i, test := range bmpStringTests { 29 | expected, err := hex.DecodeString(test.expectedHex) 30 | if err != nil { 31 | t.Fatalf("#%d: failed to decode expectation", i) 32 | } 33 | 34 | out, err := bmpString(test.in) 35 | if err == nil && test.shouldFail { 36 | t.Errorf("#%d: expected to fail, but produced %x", i, out) 37 | continue 38 | } 39 | 40 | if err != nil && !test.shouldFail { 41 | t.Errorf("#%d: failed unexpectedly: %s", i, err) 42 | continue 43 | } 44 | 45 | if !test.shouldFail { 46 | if !bytes.Equal(out, expected) { 47 | t.Errorf("#%d: expected %s, got %x", i, test.expectedHex, out) 48 | continue 49 | } 50 | 51 | roundTrip, err := decodeBMPString(out) 52 | if err != nil { 53 | t.Errorf("#%d: decoding output gave an error: %s", i, err) 54 | continue 55 | } 56 | 57 | if roundTrip != test.in { 58 | t.Errorf("#%d: decoding output resulted in %q, but it should have been %q", i, roundTrip, test.in) 59 | continue 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/pkcs12/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkcs12 6 | 7 | import "errors" 8 | 9 | var ( 10 | // ErrDecryption represents a failure to decrypt the input. 11 | ErrDecryption = errors.New("pkcs12: decryption error, incorrect padding") 12 | 13 | // ErrIncorrectPassword is returned when an incorrect password is detected. 14 | // Usually, P12/PFX data is signed to be able to verify the password. 15 | ErrIncorrectPassword = errors.New("pkcs12: decryption password incorrect") 16 | ) 17 | 18 | // NotImplementedError indicates that the input is not currently supported. 19 | type NotImplementedError string 20 | 21 | func (e NotImplementedError) Error() string { 22 | return "pkcs12: " + string(e) 23 | } 24 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/pkcs12/internal/rc2/bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package rc2 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | func BenchmarkEncrypt(b *testing.B) { 12 | r, _ := New([]byte{0, 0, 0, 0, 0, 0, 0, 0}, 64) 13 | b.ResetTimer() 14 | var src [8]byte 15 | for i := 0; i < b.N; i++ { 16 | r.Encrypt(src[:], src[:]) 17 | } 18 | } 19 | 20 | func BenchmarkDecrypt(b *testing.B) { 21 | r, _ := New([]byte{0, 0, 0, 0, 0, 0, 0, 0}, 64) 22 | b.ResetTimer() 23 | var src [8]byte 24 | for i := 0; i < b.N; i++ { 25 | r.Decrypt(src[:], src[:]) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/pkcs12/internal/rc2/rc2_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package rc2 6 | 7 | import ( 8 | "bytes" 9 | "encoding/hex" 10 | "testing" 11 | ) 12 | 13 | func TestEncryptDecrypt(t *testing.T) { 14 | // TODO(dgryski): add the rest of the test vectors from the RFC 15 | var tests = []struct { 16 | key string 17 | plain string 18 | cipher string 19 | t1 int 20 | }{ 21 | { 22 | "0000000000000000", 23 | "0000000000000000", 24 | "ebb773f993278eff", 25 | 63, 26 | }, 27 | { 28 | "ffffffffffffffff", 29 | "ffffffffffffffff", 30 | "278b27e42e2f0d49", 31 | 64, 32 | }, 33 | { 34 | "3000000000000000", 35 | "1000000000000001", 36 | "30649edf9be7d2c2", 37 | 64, 38 | }, 39 | { 40 | "88", 41 | "0000000000000000", 42 | "61a8a244adacccf0", 43 | 64, 44 | }, 45 | { 46 | "88bca90e90875a", 47 | "0000000000000000", 48 | "6ccf4308974c267f", 49 | 64, 50 | }, 51 | { 52 | "88bca90e90875a7f0f79c384627bafb2", 53 | "0000000000000000", 54 | "1a807d272bbe5db1", 55 | 64, 56 | }, 57 | { 58 | "88bca90e90875a7f0f79c384627bafb2", 59 | "0000000000000000", 60 | "2269552ab0f85ca6", 61 | 128, 62 | }, 63 | { 64 | "88bca90e90875a7f0f79c384627bafb216f80a6f85920584c42fceb0be255daf1e", 65 | "0000000000000000", 66 | "5b78d3a43dfff1f1", 67 | 129, 68 | }, 69 | } 70 | 71 | for _, tt := range tests { 72 | k, _ := hex.DecodeString(tt.key) 73 | p, _ := hex.DecodeString(tt.plain) 74 | c, _ := hex.DecodeString(tt.cipher) 75 | 76 | b, _ := New(k, tt.t1) 77 | 78 | var dst [8]byte 79 | 80 | b.Encrypt(dst[:], p) 81 | 82 | if !bytes.Equal(dst[:], c) { 83 | t.Errorf("encrypt failed: got % 2x wanted % 2x\n", dst, c) 84 | } 85 | 86 | b.Decrypt(dst[:], c) 87 | 88 | if !bytes.Equal(dst[:], p) { 89 | t.Errorf("decrypt failed: got % 2x wanted % 2x\n", dst, p) 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/pkcs12/mac.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkcs12 6 | 7 | import ( 8 | "crypto/hmac" 9 | "crypto/sha1" 10 | "crypto/x509/pkix" 11 | "encoding/asn1" 12 | ) 13 | 14 | type macData struct { 15 | Mac digestInfo 16 | MacSalt []byte 17 | Iterations int `asn1:"optional,default:1"` 18 | } 19 | 20 | // from PKCS#7: 21 | type digestInfo struct { 22 | Algorithm pkix.AlgorithmIdentifier 23 | Digest []byte 24 | } 25 | 26 | var ( 27 | oidSHA1 = asn1.ObjectIdentifier([]int{1, 3, 14, 3, 2, 26}) 28 | ) 29 | 30 | func verifyMac(macData *macData, message, password []byte) error { 31 | if !macData.Mac.Algorithm.Algorithm.Equal(oidSHA1) { 32 | return NotImplementedError("unknown digest algorithm: " + macData.Mac.Algorithm.Algorithm.String()) 33 | } 34 | 35 | key := pbkdf(sha1Sum, 20, 64, macData.MacSalt, password, macData.Iterations, 3, 20) 36 | 37 | mac := hmac.New(sha1.New, key) 38 | mac.Write(message) 39 | expectedMAC := mac.Sum(nil) 40 | 41 | if !hmac.Equal(macData.Mac.Digest, expectedMAC) { 42 | return ErrIncorrectPassword 43 | } 44 | return nil 45 | } 46 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/pkcs12/mac_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkcs12 6 | 7 | import ( 8 | "encoding/asn1" 9 | "testing" 10 | ) 11 | 12 | func TestVerifyMac(t *testing.T) { 13 | td := macData{ 14 | Mac: digestInfo{ 15 | Digest: []byte{0x18, 0x20, 0x3d, 0xff, 0x1e, 0x16, 0xf4, 0x92, 0xf2, 0xaf, 0xc8, 0x91, 0xa9, 0xba, 0xd6, 0xca, 0x9d, 0xee, 0x51, 0x93}, 16 | }, 17 | MacSalt: []byte{1, 2, 3, 4, 5, 6, 7, 8}, 18 | Iterations: 2048, 19 | } 20 | 21 | message := []byte{11, 12, 13, 14, 15} 22 | password, _ := bmpString("") 23 | 24 | td.Mac.Algorithm.Algorithm = asn1.ObjectIdentifier([]int{1, 2, 3}) 25 | err := verifyMac(&td, message, password) 26 | if _, ok := err.(NotImplementedError); !ok { 27 | t.Errorf("err: %v", err) 28 | } 29 | 30 | td.Mac.Algorithm.Algorithm = asn1.ObjectIdentifier([]int{1, 3, 14, 3, 2, 26}) 31 | err = verifyMac(&td, message, password) 32 | if err != ErrIncorrectPassword { 33 | t.Errorf("Expected incorrect password, got err: %v", err) 34 | } 35 | 36 | password, _ = bmpString("Sesame open") 37 | err = verifyMac(&td, message, password) 38 | if err != nil { 39 | t.Errorf("err: %v", err) 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/pkcs12/pbkdf_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkcs12 6 | 7 | import ( 8 | "bytes" 9 | "testing" 10 | ) 11 | 12 | func TestThatPBKDFWorksCorrectlyForLongKeys(t *testing.T) { 13 | cipherInfo := shaWithTripleDESCBC{} 14 | 15 | salt := []byte("\xff\xff\xff\xff\xff\xff\xff\xff") 16 | password, _ := bmpString("sesame") 17 | key := cipherInfo.deriveKey(salt, password, 2048) 18 | 19 | if expected := []byte("\x7c\xd9\xfd\x3e\x2b\x3b\xe7\x69\x1a\x44\xe3\xbe\xf0\xf9\xea\x0f\xb9\xb8\x97\xd4\xe3\x25\xd9\xd1"); bytes.Compare(key, expected) != 0 { 20 | t.Fatalf("expected key '%x', but found '%x'", expected, key) 21 | } 22 | } 23 | 24 | func TestThatPBKDFHandlesLeadingZeros(t *testing.T) { 25 | // This test triggers a case where I_j (in step 6C) ends up with leading zero 26 | // byte, meaning that len(Ijb) < v (leading zeros get stripped by big.Int). 27 | // This was previously causing bug whereby certain inputs would break the 28 | // derivation and produce the wrong output. 29 | key := pbkdf(sha1Sum, 20, 64, []byte("\xf3\x7e\x05\xb5\x18\x32\x4b\x4b"), []byte("\x00\x00"), 2048, 1, 24) 30 | expected := []byte("\x00\xf7\x59\xff\x47\xd1\x4d\xd0\x36\x65\xd5\x94\x3c\xb3\xc4\xa3\x9a\x25\x55\xc0\x2a\xed\x66\xe1") 31 | if bytes.Compare(key, expected) != 0 { 32 | t.Fatalf("expected key '%x', but found '%x'", expected, key) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/pkcs12/safebags.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkcs12 6 | 7 | import ( 8 | "crypto/x509" 9 | "encoding/asn1" 10 | "errors" 11 | ) 12 | 13 | var ( 14 | // see https://tools.ietf.org/html/rfc7292#appendix-D 15 | oidCertTypeX509Certificate = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 9, 22, 1}) 16 | oidPKCS8ShroundedKeyBag = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 10, 1, 2}) 17 | oidCertBag = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 10, 1, 3}) 18 | ) 19 | 20 | type certBag struct { 21 | Id asn1.ObjectIdentifier 22 | Data []byte `asn1:"tag:0,explicit"` 23 | } 24 | 25 | func decodePkcs8ShroudedKeyBag(asn1Data, password []byte) (privateKey interface{}, err error) { 26 | pkinfo := new(encryptedPrivateKeyInfo) 27 | if err = unmarshal(asn1Data, pkinfo); err != nil { 28 | return nil, errors.New("pkcs12: error decoding PKCS#8 shrouded key bag: " + err.Error()) 29 | } 30 | 31 | pkData, err := pbDecrypt(pkinfo, password) 32 | if err != nil { 33 | return nil, errors.New("pkcs12: error decrypting PKCS#8 shrouded key bag: " + err.Error()) 34 | } 35 | 36 | ret := new(asn1.RawValue) 37 | if err = unmarshal(pkData, ret); err != nil { 38 | return nil, errors.New("pkcs12: error unmarshaling decrypted private key: " + err.Error()) 39 | } 40 | 41 | if privateKey, err = x509.ParsePKCS8PrivateKey(pkData); err != nil { 42 | return nil, errors.New("pkcs12: error parsing PKCS#8 private key: " + err.Error()) 43 | } 44 | 45 | return privateKey, nil 46 | } 47 | 48 | func decodeCertBag(asn1Data []byte) (x509Certificates []byte, err error) { 49 | bag := new(certBag) 50 | if err := unmarshal(asn1Data, bag); err != nil { 51 | return nil, errors.New("pkcs12: error decoding cert bag: " + err.Error()) 52 | } 53 | if !bag.Id.Equal(oidCertTypeX509Certificate) { 54 | return nil, NotImplementedError("only X509 certificates are supported") 55 | } 56 | return bag.Data, nil 57 | } 58 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/poly1305/bits_compat.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.13 6 | 7 | package poly1305 8 | 9 | // Generic fallbacks for the math/bits intrinsics, copied from 10 | // src/math/bits/bits.go. They were added in Go 1.12, but Add64 and Sum64 had 11 | // variable time fallbacks until Go 1.13. 12 | 13 | func bitsAdd64(x, y, carry uint64) (sum, carryOut uint64) { 14 | sum = x + y + carry 15 | carryOut = ((x & y) | ((x | y) &^ sum)) >> 63 16 | return 17 | } 18 | 19 | func bitsSub64(x, y, borrow uint64) (diff, borrowOut uint64) { 20 | diff = x - y - borrow 21 | borrowOut = ((^x & y) | (^(x ^ y) & diff)) >> 63 22 | return 23 | } 24 | 25 | func bitsMul64(x, y uint64) (hi, lo uint64) { 26 | const mask32 = 1<<32 - 1 27 | x0 := x & mask32 28 | x1 := x >> 32 29 | y0 := y & mask32 30 | y1 := y >> 32 31 | w0 := x0 * y0 32 | t := x1*y0 + w0>>32 33 | w1 := t & mask32 34 | w2 := t >> 32 35 | w1 += x0 * y1 36 | hi = x1*y1 + w2 + w1>>32 37 | lo = x * y 38 | return 39 | } 40 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/poly1305/bits_go1.13.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.13 6 | 7 | package poly1305 8 | 9 | import "math/bits" 10 | 11 | func bitsAdd64(x, y, carry uint64) (sum, carryOut uint64) { 12 | return bits.Add64(x, y, carry) 13 | } 14 | 15 | func bitsSub64(x, y, borrow uint64) (diff, borrowOut uint64) { 16 | return bits.Sub64(x, y, borrow) 17 | } 18 | 19 | func bitsMul64(x, y uint64) (hi, lo uint64) { 20 | return bits.Mul64(x, y) 21 | } 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/poly1305/mac_noasm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !amd64,!ppc64le gccgo appengine 6 | 7 | package poly1305 8 | 9 | type mac struct{ macGeneric } 10 | 11 | func newMAC(key *[32]byte) mac { return mac{newMACGeneric(key)} } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/poly1305/sum_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,!gccgo,!appengine 6 | 7 | package poly1305 8 | 9 | //go:noescape 10 | func update(state *macState, msg []byte) 11 | 12 | func sum(out *[16]byte, m []byte, key *[32]byte) { 13 | h := newMAC(key) 14 | h.Write(m) 15 | h.Sum(out) 16 | } 17 | 18 | func newMAC(key *[32]byte) (h mac) { 19 | initialize(key, &h.r, &h.s) 20 | return 21 | } 22 | 23 | // mac is a wrapper for macGeneric that redirects calls that would have gone to 24 | // updateGeneric to update. 25 | // 26 | // Its Write and Sum methods are otherwise identical to the macGeneric ones, but 27 | // using function pointers would carry a major performance cost. 28 | type mac struct{ macGeneric } 29 | 30 | func (h *mac) Write(p []byte) (int, error) { 31 | nn := len(p) 32 | if h.offset > 0 { 33 | n := copy(h.buffer[h.offset:], p) 34 | if h.offset+n < TagSize { 35 | h.offset += n 36 | return nn, nil 37 | } 38 | p = p[n:] 39 | h.offset = 0 40 | update(&h.macState, h.buffer[:]) 41 | } 42 | if n := len(p) - (len(p) % TagSize); n > 0 { 43 | update(&h.macState, p[:n]) 44 | p = p[n:] 45 | } 46 | if len(p) > 0 { 47 | h.offset += copy(h.buffer[h.offset:], p) 48 | } 49 | return nn, nil 50 | } 51 | 52 | func (h *mac) Sum(out *[16]byte) { 53 | state := h.macState 54 | if h.offset > 0 { 55 | update(&state, h.buffer[:h.offset]) 56 | } 57 | finalize(out, &state.h, &state.s) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/poly1305/sum_noasm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build s390x,!go1.11 !amd64,!s390x,!ppc64le gccgo appengine nacl 6 | 7 | package poly1305 8 | 9 | func sum(out *[TagSize]byte, msg []byte, key *[32]byte) { 10 | h := newMAC(key) 11 | h.Write(msg) 12 | h.Sum(out) 13 | } 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/poly1305/sum_ppc64le.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ppc64le,!gccgo,!appengine 6 | 7 | package poly1305 8 | 9 | //go:noescape 10 | func update(state *macState, msg []byte) 11 | 12 | func sum(out *[16]byte, m []byte, key *[32]byte) { 13 | h := newMAC(key) 14 | h.Write(m) 15 | h.Sum(out) 16 | } 17 | 18 | func newMAC(key *[32]byte) (h mac) { 19 | initialize(key, &h.r, &h.s) 20 | return 21 | } 22 | 23 | // mac is a wrapper for macGeneric that redirects calls that would have gone to 24 | // updateGeneric to update. 25 | // 26 | // Its Write and Sum methods are otherwise identical to the macGeneric ones, but 27 | // using function pointers would carry a major performance cost. 28 | type mac struct{ macGeneric } 29 | 30 | func (h *mac) Write(p []byte) (int, error) { 31 | nn := len(p) 32 | if h.offset > 0 { 33 | n := copy(h.buffer[h.offset:], p) 34 | if h.offset+n < TagSize { 35 | h.offset += n 36 | return nn, nil 37 | } 38 | p = p[n:] 39 | h.offset = 0 40 | update(&h.macState, h.buffer[:]) 41 | } 42 | if n := len(p) - (len(p) % TagSize); n > 0 { 43 | update(&h.macState, p[:n]) 44 | p = p[n:] 45 | } 46 | if len(p) > 0 { 47 | h.offset += copy(h.buffer[h.offset:], p) 48 | } 49 | return nn, nil 50 | } 51 | 52 | func (h *mac) Sum(out *[16]byte) { 53 | state := h.macState 54 | if h.offset > 0 { 55 | update(&state, h.buffer[:h.offset]) 56 | } 57 | finalize(out, &state.h, &state.s) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/poly1305/sum_s390x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build s390x,go1.11,!gccgo,!appengine 6 | 7 | package poly1305 8 | 9 | import ( 10 | "golang.org/x/sys/cpu" 11 | ) 12 | 13 | // poly1305vx is an assembly implementation of Poly1305 that uses vector 14 | // instructions. It must only be called if the vector facility (vx) is 15 | // available. 16 | //go:noescape 17 | func poly1305vx(out *[16]byte, m *byte, mlen uint64, key *[32]byte) 18 | 19 | // poly1305vmsl is an assembly implementation of Poly1305 that uses vector 20 | // instructions, including VMSL. It must only be called if the vector facility (vx) is 21 | // available and if VMSL is supported. 22 | //go:noescape 23 | func poly1305vmsl(out *[16]byte, m *byte, mlen uint64, key *[32]byte) 24 | 25 | func sum(out *[16]byte, m []byte, key *[32]byte) { 26 | if cpu.S390X.HasVX { 27 | var mPtr *byte 28 | if len(m) > 0 { 29 | mPtr = &m[0] 30 | } 31 | if cpu.S390X.HasVXE && len(m) > 256 { 32 | poly1305vmsl(out, mPtr, uint64(len(m)), key) 33 | } else { 34 | poly1305vx(out, mPtr, uint64(len(m)), key) 35 | } 36 | } else { 37 | sumGeneric(out, m, key) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ripemd160/ripemd160_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ripemd160 6 | 7 | // Test vectors are from: 8 | // http://homes.esat.kuleuven.be/~bosselae/ripemd160.html 9 | 10 | import ( 11 | "fmt" 12 | "io" 13 | "testing" 14 | ) 15 | 16 | type mdTest struct { 17 | out string 18 | in string 19 | } 20 | 21 | var vectors = [...]mdTest{ 22 | {"9c1185a5c5e9fc54612808977ee8f548b2258d31", ""}, 23 | {"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", "a"}, 24 | {"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", "abc"}, 25 | {"5d0689ef49d2fae572b881b123a85ffa21595f36", "message digest"}, 26 | {"f71c27109c692c1b56bbdceb5b9d2865b3708dbc", "abcdefghijklmnopqrstuvwxyz"}, 27 | {"12a053384a9c0c88e405a06c27dcf49ada62eb2b", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"}, 28 | {"b0e20b6e3116640286ed3a87a5713079b21f5189", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"}, 29 | {"9b752e45573d4b39f4dbd3323cab82bf63326bfb", "12345678901234567890123456789012345678901234567890123456789012345678901234567890"}, 30 | } 31 | 32 | func TestVectors(t *testing.T) { 33 | for i := 0; i < len(vectors); i++ { 34 | tv := vectors[i] 35 | md := New() 36 | for j := 0; j < 3; j++ { 37 | if j < 2 { 38 | io.WriteString(md, tv.in) 39 | } else { 40 | io.WriteString(md, tv.in[0:len(tv.in)/2]) 41 | md.Sum(nil) 42 | io.WriteString(md, tv.in[len(tv.in)/2:]) 43 | } 44 | s := fmt.Sprintf("%x", md.Sum(nil)) 45 | if s != tv.out { 46 | t.Fatalf("RIPEMD-160[%d](%s) = %s, expected %s", j, tv.in, s, tv.out) 47 | } 48 | md.Reset() 49 | } 50 | } 51 | } 52 | 53 | func millionA() string { 54 | md := New() 55 | for i := 0; i < 100000; i++ { 56 | io.WriteString(md, "aaaaaaaaaa") 57 | } 58 | return fmt.Sprintf("%x", md.Sum(nil)) 59 | } 60 | 61 | func TestMillionA(t *testing.T) { 62 | const out = "52783243c1697bdbe16d37f97f68f08325dc1528" 63 | if s := millionA(); s != out { 64 | t.Fatalf("RIPEMD-160 (1 million 'a') = %s, expected %s", s, out) 65 | } 66 | } 67 | 68 | func BenchmarkMillionA(b *testing.B) { 69 | for i := 0; i < b.N; i++ { 70 | millionA() 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/salsa20/salsa/salsa20_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,!appengine,!gccgo 6 | 7 | package salsa 8 | 9 | //go:noescape 10 | 11 | // salsa2020XORKeyStream is implemented in salsa20_amd64.s. 12 | func salsa2020XORKeyStream(out, in *byte, n uint64, nonce, key *byte) 13 | 14 | // XORKeyStream crypts bytes from in to out using the given key and counters. 15 | // In and out must overlap entirely or not at all. Counter 16 | // contains the raw salsa20 counter bytes (both nonce and block counter). 17 | func XORKeyStream(out, in []byte, counter *[16]byte, key *[32]byte) { 18 | if len(in) == 0 { 19 | return 20 | } 21 | _ = out[len(in)-1] 22 | salsa2020XORKeyStream(&out[0], &in[0], uint64(len(in)), &counter[0], &key[0]) 23 | } 24 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/salsa20/salsa/salsa20_amd64_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,!appengine,!gccgo 6 | 7 | package salsa 8 | 9 | import ( 10 | "bytes" 11 | "testing" 12 | ) 13 | 14 | func TestCounterOverflow(t *testing.T) { 15 | in := make([]byte, 4096) 16 | key := &[32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 17 | 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2} 18 | for n, counter := range []*[16]byte{ 19 | &[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0}, // zero counter 20 | &[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff}, // counter about to overflow 32 bits 21 | &[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 0xff, 0xff, 0xff, 0xff}, // counter above 32 bits 22 | } { 23 | out := make([]byte, 4096) 24 | XORKeyStream(out, in, counter, key) 25 | outGeneric := make([]byte, 4096) 26 | genericXORKeyStream(outGeneric, in, counter, key) 27 | if !bytes.Equal(out, outGeneric) { 28 | t.Errorf("%d: assembly and go implementations disagree", n) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/salsa20/salsa/salsa20_noasm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !amd64 appengine gccgo 6 | 7 | package salsa 8 | 9 | // XORKeyStream crypts bytes from in to out using the given key and counters. 10 | // In and out must overlap entirely or not at all. Counter 11 | // contains the raw salsa20 counter bytes (both nonce and block counter). 12 | func XORKeyStream(out, in []byte, counter *[16]byte, key *[32]byte) { 13 | genericXORKeyStream(out, in, counter, key) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/salsa20/salsa/salsa_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package salsa 6 | 7 | import "testing" 8 | 9 | func TestCore208(t *testing.T) { 10 | in := [64]byte{ 11 | 0x7e, 0x87, 0x9a, 0x21, 0x4f, 0x3e, 0xc9, 0x86, 12 | 0x7c, 0xa9, 0x40, 0xe6, 0x41, 0x71, 0x8f, 0x26, 13 | 0xba, 0xee, 0x55, 0x5b, 0x8c, 0x61, 0xc1, 0xb5, 14 | 0x0d, 0xf8, 0x46, 0x11, 0x6d, 0xcd, 0x3b, 0x1d, 15 | 0xee, 0x24, 0xf3, 0x19, 0xdf, 0x9b, 0x3d, 0x85, 16 | 0x14, 0x12, 0x1e, 0x4b, 0x5a, 0xc5, 0xaa, 0x32, 17 | 0x76, 0x02, 0x1d, 0x29, 0x09, 0xc7, 0x48, 0x29, 18 | 0xed, 0xeb, 0xc6, 0x8d, 0xb8, 0xb8, 0xc2, 0x5e} 19 | 20 | out := [64]byte{ 21 | 0xa4, 0x1f, 0x85, 0x9c, 0x66, 0x08, 0xcc, 0x99, 22 | 0x3b, 0x81, 0xca, 0xcb, 0x02, 0x0c, 0xef, 0x05, 23 | 0x04, 0x4b, 0x21, 0x81, 0xa2, 0xfd, 0x33, 0x7d, 24 | 0xfd, 0x7b, 0x1c, 0x63, 0x96, 0x68, 0x2f, 0x29, 25 | 0xb4, 0x39, 0x31, 0x68, 0xe3, 0xc9, 0xe6, 0xbc, 26 | 0xfe, 0x6b, 0xc5, 0xb7, 0xa0, 0x6d, 0x96, 0xba, 27 | 0xe4, 0x24, 0xcc, 0x10, 0x2c, 0x91, 0x74, 0x5c, 28 | 0x24, 0xad, 0x67, 0x3d, 0xc7, 0x61, 0x8f, 0x81, 29 | } 30 | 31 | Core208(&in, &in) 32 | if in != out { 33 | t.Errorf("expected %x, got %x", out, in) 34 | } 35 | } 36 | 37 | func TestOutOfBoundsWrite(t *testing.T) { 38 | // encrypted "0123456789" 39 | cipherText := []byte{170, 166, 196, 104, 175, 121, 68, 44, 174, 51} 40 | var counter [16]byte 41 | var key [32]byte 42 | want := "abcdefghij" 43 | plainText := []byte(want) 44 | defer func() { 45 | err := recover() 46 | if err == nil { 47 | t.Error("XORKeyStream expected to panic on len(dst) < len(src), but didn't") 48 | } 49 | if plainText[3] == '3' { 50 | t.Errorf("XORKeyStream did out of bounds write, want %v, got %v", want, string(plainText)) 51 | } 52 | }() 53 | XORKeyStream(plainText[:3], cipherText, &counter, &key) 54 | } 55 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/salsa20/salsa20.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package salsa20 implements the Salsa20 stream cipher as specified in https://cr.yp.to/snuffle/spec.pdf. 7 | 8 | Salsa20 differs from many other stream ciphers in that it is message orientated 9 | rather than byte orientated. Keystream blocks are not preserved between calls, 10 | therefore each side must encrypt/decrypt data with the same segmentation. 11 | 12 | Another aspect of this difference is that part of the counter is exposed as 13 | a nonce in each call. Encrypting two different messages with the same (key, 14 | nonce) pair leads to trivial plaintext recovery. This is analogous to 15 | encrypting two different messages with the same key with a traditional stream 16 | cipher. 17 | 18 | This package also implements XSalsa20: a version of Salsa20 with a 24-byte 19 | nonce as specified in https://cr.yp.to/snuffle/xsalsa-20081128.pdf. Simply 20 | passing a 24-byte slice as the nonce triggers XSalsa20. 21 | */ 22 | package salsa20 // import "golang.org/x/crypto/salsa20" 23 | 24 | // TODO(agl): implement XORKeyStream12 and XORKeyStream8 - the reduced round variants of Salsa20. 25 | 26 | import ( 27 | "golang.org/x/crypto/internal/subtle" 28 | "golang.org/x/crypto/salsa20/salsa" 29 | ) 30 | 31 | // XORKeyStream crypts bytes from in to out using the given key and nonce. 32 | // In and out must overlap entirely or not at all. Nonce must 33 | // be either 8 or 24 bytes long. 34 | func XORKeyStream(out, in []byte, nonce []byte, key *[32]byte) { 35 | if len(out) < len(in) { 36 | panic("salsa20: output smaller than input") 37 | } 38 | if subtle.InexactOverlap(out[:len(in)], in) { 39 | panic("salsa20: invalid buffer overlap") 40 | } 41 | 42 | var subNonce [16]byte 43 | 44 | if len(nonce) == 24 { 45 | var subKey [32]byte 46 | var hNonce [16]byte 47 | copy(hNonce[:], nonce[:16]) 48 | salsa.HSalsa20(&subKey, &hNonce, key, &salsa.Sigma) 49 | copy(subNonce[:], nonce[16:]) 50 | key = &subKey 51 | } else if len(nonce) == 8 { 52 | copy(subNonce[:], nonce[:]) 53 | } else { 54 | panic("salsa20: nonce must be 8 or 24 bytes") 55 | } 56 | 57 | salsa.XORKeyStream(out, in, &subNonce, key) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/scrypt/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package scrypt_test 6 | 7 | import ( 8 | "encoding/base64" 9 | "fmt" 10 | "log" 11 | 12 | "golang.org/x/crypto/scrypt" 13 | ) 14 | 15 | func Example() { 16 | // DO NOT use this salt value; generate your own random salt. 8 bytes is 17 | // a good length. 18 | salt := []byte{0xc8, 0x28, 0xf2, 0x58, 0xa7, 0x6a, 0xad, 0x7b} 19 | 20 | dk, err := scrypt.Key([]byte("some password"), salt, 1<<15, 8, 1, 32) 21 | if err != nil { 22 | log.Fatal(err) 23 | } 24 | fmt.Println(base64.StdEncoding.EncodeToString(dk)) 25 | // Output: lGnMz8io0AUkfzn6Pls1qX20Vs7PGN6sbYQ2TQgY12M= 26 | } 27 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/sha3/hashes_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build gccgo appengine !s390x 6 | 7 | package sha3 8 | 9 | import ( 10 | "hash" 11 | ) 12 | 13 | // new224Asm returns an assembly implementation of SHA3-224 if available, 14 | // otherwise it returns nil. 15 | func new224Asm() hash.Hash { return nil } 16 | 17 | // new256Asm returns an assembly implementation of SHA3-256 if available, 18 | // otherwise it returns nil. 19 | func new256Asm() hash.Hash { return nil } 20 | 21 | // new384Asm returns an assembly implementation of SHA3-384 if available, 22 | // otherwise it returns nil. 23 | func new384Asm() hash.Hash { return nil } 24 | 25 | // new512Asm returns an assembly implementation of SHA3-512 if available, 26 | // otherwise it returns nil. 27 | func new512Asm() hash.Hash { return nil } 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/sha3/keccakf_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,!appengine,!gccgo 6 | 7 | package sha3 8 | 9 | // This function is implemented in keccakf_amd64.s. 10 | 11 | //go:noescape 12 | 13 | func keccakF1600(a *[25]uint64) 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/sha3/register.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.4 6 | 7 | package sha3 8 | 9 | import ( 10 | "crypto" 11 | ) 12 | 13 | func init() { 14 | crypto.RegisterHash(crypto.SHA3_224, New224) 15 | crypto.RegisterHash(crypto.SHA3_256, New256) 16 | crypto.RegisterHash(crypto.SHA3_384, New384) 17 | crypto.RegisterHash(crypto.SHA3_512, New512) 18 | } 19 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/sha3/sha3_s390x.s: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo,!appengine 6 | 7 | #include "textflag.h" 8 | 9 | // func kimd(function code, chain *[200]byte, src []byte) 10 | TEXT ·kimd(SB), NOFRAME|NOSPLIT, $0-40 11 | MOVD function+0(FP), R0 12 | MOVD chain+8(FP), R1 13 | LMG src+16(FP), R2, R3 // R2=base, R3=len 14 | 15 | continue: 16 | WORD $0xB93E0002 // KIMD --, R2 17 | BVS continue // continue if interrupted 18 | MOVD $0, R0 // reset R0 for pre-go1.8 compilers 19 | RET 20 | 21 | // func klmd(function code, chain *[200]byte, dst, src []byte) 22 | TEXT ·klmd(SB), NOFRAME|NOSPLIT, $0-64 23 | // TODO: SHAKE support 24 | MOVD function+0(FP), R0 25 | MOVD chain+8(FP), R1 26 | LMG dst+16(FP), R2, R3 // R2=base, R3=len 27 | LMG src+40(FP), R4, R5 // R4=base, R5=len 28 | 29 | continue: 30 | WORD $0xB93F0024 // KLMD R2, R4 31 | BVS continue // continue if interrupted 32 | MOVD $0, R0 // reset R0 for pre-go1.8 compilers 33 | RET 34 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/sha3/shake_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build gccgo appengine !s390x 6 | 7 | package sha3 8 | 9 | // newShake128Asm returns an assembly implementation of SHAKE-128 if available, 10 | // otherwise it returns nil. 11 | func newShake128Asm() ShakeHash { 12 | return nil 13 | } 14 | 15 | // newShake256Asm returns an assembly implementation of SHAKE-256 if available, 16 | // otherwise it returns nil. 17 | func newShake256Asm() ShakeHash { 18 | return nil 19 | } 20 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/sha3/testdata/keccakKats.json.deflate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parquery/revproxyry/54edc9726d86d5f1bdc5c09004898a3b9956d8ba/vendor/golang.org/x/crypto/sha3/testdata/keccakKats.json.deflate -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/sha3/xor.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !amd64,!386,!ppc64le appengine 6 | 7 | package sha3 8 | 9 | // A storageBuf is an aligned array of maxRate bytes. 10 | type storageBuf [maxRate]byte 11 | 12 | func (b *storageBuf) asBytes() *[maxRate]byte { 13 | return (*[maxRate]byte)(b) 14 | } 15 | 16 | var ( 17 | xorIn = xorInGeneric 18 | copyOut = copyOutGeneric 19 | xorInUnaligned = xorInGeneric 20 | copyOutUnaligned = copyOutGeneric 21 | ) 22 | 23 | const xorImplementationUnaligned = "generic" 24 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/sha3/xor_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package sha3 6 | 7 | import "encoding/binary" 8 | 9 | // xorInGeneric xors the bytes in buf into the state; it 10 | // makes no non-portable assumptions about memory layout 11 | // or alignment. 12 | func xorInGeneric(d *state, buf []byte) { 13 | n := len(buf) / 8 14 | 15 | for i := 0; i < n; i++ { 16 | a := binary.LittleEndian.Uint64(buf) 17 | d.a[i] ^= a 18 | buf = buf[8:] 19 | } 20 | } 21 | 22 | // copyOutGeneric copies ulint64s to a byte buffer. 23 | func copyOutGeneric(d *state, b []byte) { 24 | for i := 0; len(b) >= 8; i++ { 25 | binary.LittleEndian.PutUint64(b, d.a[i]) 26 | b = b[8:] 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/sha3/xor_unaligned.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64 386 ppc64le 6 | // +build !appengine 7 | 8 | package sha3 9 | 10 | import "unsafe" 11 | 12 | // A storageBuf is an aligned array of maxRate bytes. 13 | type storageBuf [maxRate / 8]uint64 14 | 15 | func (b *storageBuf) asBytes() *[maxRate]byte { 16 | return (*[maxRate]byte)(unsafe.Pointer(b)) 17 | } 18 | 19 | func xorInUnaligned(d *state, buf []byte) { 20 | n := len(buf) 21 | bw := (*[maxRate / 8]uint64)(unsafe.Pointer(&buf[0]))[: n/8 : n/8] 22 | if n >= 72 { 23 | d.a[0] ^= bw[0] 24 | d.a[1] ^= bw[1] 25 | d.a[2] ^= bw[2] 26 | d.a[3] ^= bw[3] 27 | d.a[4] ^= bw[4] 28 | d.a[5] ^= bw[5] 29 | d.a[6] ^= bw[6] 30 | d.a[7] ^= bw[7] 31 | d.a[8] ^= bw[8] 32 | } 33 | if n >= 104 { 34 | d.a[9] ^= bw[9] 35 | d.a[10] ^= bw[10] 36 | d.a[11] ^= bw[11] 37 | d.a[12] ^= bw[12] 38 | } 39 | if n >= 136 { 40 | d.a[13] ^= bw[13] 41 | d.a[14] ^= bw[14] 42 | d.a[15] ^= bw[15] 43 | d.a[16] ^= bw[16] 44 | } 45 | if n >= 144 { 46 | d.a[17] ^= bw[17] 47 | } 48 | if n >= 168 { 49 | d.a[18] ^= bw[18] 50 | d.a[19] ^= bw[19] 51 | d.a[20] ^= bw[20] 52 | } 53 | } 54 | 55 | func copyOutUnaligned(d *state, buf []byte) { 56 | ab := (*[maxRate]uint8)(unsafe.Pointer(&d.a[0])) 57 | copy(buf, ab[:]) 58 | } 59 | 60 | var ( 61 | xorIn = xorInUnaligned 62 | copyOut = copyOutUnaligned 63 | ) 64 | 65 | const xorImplementationUnaligned = "unaligned" 66 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/agent/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package agent_test 6 | 7 | import ( 8 | "log" 9 | "net" 10 | "os" 11 | 12 | "golang.org/x/crypto/ssh" 13 | "golang.org/x/crypto/ssh/agent" 14 | ) 15 | 16 | func ExampleNewClient() { 17 | // ssh-agent(1) provides a UNIX socket at $SSH_AUTH_SOCK. 18 | socket := os.Getenv("SSH_AUTH_SOCK") 19 | conn, err := net.Dial("unix", socket) 20 | if err != nil { 21 | log.Fatalf("Failed to open SSH_AUTH_SOCK: %v", err) 22 | } 23 | 24 | agentClient := agent.NewClient(conn) 25 | config := &ssh.ClientConfig{ 26 | User: "gopher", 27 | Auth: []ssh.AuthMethod{ 28 | // Use a callback rather than PublicKeys so we only consult the 29 | // agent once the remote server wants it. 30 | ssh.PublicKeysCallback(agentClient.Signers), 31 | }, 32 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 33 | } 34 | 35 | sshc, err := ssh.Dial("tcp", "localhost:22", config) 36 | if err != nil { 37 | log.Fatal(err) 38 | } 39 | // Use sshc... 40 | sshc.Close() 41 | } 42 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/agent/forward.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package agent 6 | 7 | import ( 8 | "errors" 9 | "io" 10 | "net" 11 | "sync" 12 | 13 | "golang.org/x/crypto/ssh" 14 | ) 15 | 16 | // RequestAgentForwarding sets up agent forwarding for the session. 17 | // ForwardToAgent or ForwardToRemote should be called to route 18 | // the authentication requests. 19 | func RequestAgentForwarding(session *ssh.Session) error { 20 | ok, err := session.SendRequest("auth-agent-req@openssh.com", true, nil) 21 | if err != nil { 22 | return err 23 | } 24 | if !ok { 25 | return errors.New("forwarding request denied") 26 | } 27 | return nil 28 | } 29 | 30 | // ForwardToAgent routes authentication requests to the given keyring. 31 | func ForwardToAgent(client *ssh.Client, keyring Agent) error { 32 | channels := client.HandleChannelOpen(channelType) 33 | if channels == nil { 34 | return errors.New("agent: already have handler for " + channelType) 35 | } 36 | 37 | go func() { 38 | for ch := range channels { 39 | channel, reqs, err := ch.Accept() 40 | if err != nil { 41 | continue 42 | } 43 | go ssh.DiscardRequests(reqs) 44 | go func() { 45 | ServeAgent(keyring, channel) 46 | channel.Close() 47 | }() 48 | } 49 | }() 50 | return nil 51 | } 52 | 53 | const channelType = "auth-agent@openssh.com" 54 | 55 | // ForwardToRemote routes authentication requests to the ssh-agent 56 | // process serving on the given unix socket. 57 | func ForwardToRemote(client *ssh.Client, addr string) error { 58 | channels := client.HandleChannelOpen(channelType) 59 | if channels == nil { 60 | return errors.New("agent: already have handler for " + channelType) 61 | } 62 | conn, err := net.Dial("unix", addr) 63 | if err != nil { 64 | return err 65 | } 66 | conn.Close() 67 | 68 | go func() { 69 | for ch := range channels { 70 | channel, reqs, err := ch.Accept() 71 | if err != nil { 72 | continue 73 | } 74 | go ssh.DiscardRequests(reqs) 75 | go forwardUnixSocket(channel, addr) 76 | } 77 | }() 78 | return nil 79 | } 80 | 81 | func forwardUnixSocket(channel ssh.Channel, addr string) { 82 | conn, err := net.Dial("unix", addr) 83 | if err != nil { 84 | return 85 | } 86 | 87 | var wg sync.WaitGroup 88 | wg.Add(2) 89 | go func() { 90 | io.Copy(conn, channel) 91 | conn.(*net.UnixConn).CloseWrite() 92 | wg.Done() 93 | }() 94 | go func() { 95 | io.Copy(channel, conn) 96 | channel.CloseWrite() 97 | wg.Done() 98 | }() 99 | 100 | wg.Wait() 101 | conn.Close() 102 | channel.Close() 103 | } 104 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/agent/keyring_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package agent 6 | 7 | import "testing" 8 | 9 | func addTestKey(t *testing.T, a Agent, keyName string) { 10 | err := a.Add(AddedKey{ 11 | PrivateKey: testPrivateKeys[keyName], 12 | Comment: keyName, 13 | }) 14 | if err != nil { 15 | t.Fatalf("failed to add key %q: %v", keyName, err) 16 | } 17 | } 18 | 19 | func removeTestKey(t *testing.T, a Agent, keyName string) { 20 | err := a.Remove(testPublicKeys[keyName]) 21 | if err != nil { 22 | t.Fatalf("failed to remove key %q: %v", keyName, err) 23 | } 24 | } 25 | 26 | func validateListedKeys(t *testing.T, a Agent, expectedKeys []string) { 27 | listedKeys, err := a.List() 28 | if err != nil { 29 | t.Fatalf("failed to list keys: %v", err) 30 | return 31 | } 32 | actualKeys := make(map[string]bool) 33 | for _, key := range listedKeys { 34 | actualKeys[key.Comment] = true 35 | } 36 | 37 | matchedKeys := make(map[string]bool) 38 | for _, expectedKey := range expectedKeys { 39 | if !actualKeys[expectedKey] { 40 | t.Fatalf("expected key %q, but was not found", expectedKey) 41 | } else { 42 | matchedKeys[expectedKey] = true 43 | } 44 | } 45 | 46 | for actualKey := range actualKeys { 47 | if !matchedKeys[actualKey] { 48 | t.Fatalf("key %q was found, but was not expected", actualKey) 49 | } 50 | } 51 | } 52 | 53 | func TestKeyringAddingAndRemoving(t *testing.T) { 54 | keyNames := []string{"dsa", "ecdsa", "rsa", "user"} 55 | 56 | // add all test private keys 57 | k := NewKeyring() 58 | for _, keyName := range keyNames { 59 | addTestKey(t, k, keyName) 60 | } 61 | validateListedKeys(t, k, keyNames) 62 | 63 | // remove a key in the middle 64 | keyToRemove := keyNames[1] 65 | keyNames = append(keyNames[:1], keyNames[2:]...) 66 | 67 | removeTestKey(t, k, keyToRemove) 68 | validateListedKeys(t, k, keyNames) 69 | 70 | // remove all keys 71 | err := k.RemoveAll() 72 | if err != nil { 73 | t.Fatalf("failed to remove all keys: %v", err) 74 | } 75 | validateListedKeys(t, k, []string{}) 76 | } 77 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/agent/testdata_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // IMPLEMENTATION NOTE: To avoid a package loop, this file is in three places: 6 | // ssh/, ssh/agent, and ssh/test/. It should be kept in sync across all three 7 | // instances. 8 | 9 | package agent 10 | 11 | import ( 12 | "crypto/rand" 13 | "fmt" 14 | 15 | "golang.org/x/crypto/ssh" 16 | "golang.org/x/crypto/ssh/testdata" 17 | ) 18 | 19 | var ( 20 | testPrivateKeys map[string]interface{} 21 | testSigners map[string]ssh.Signer 22 | testPublicKeys map[string]ssh.PublicKey 23 | ) 24 | 25 | func init() { 26 | var err error 27 | 28 | n := len(testdata.PEMBytes) 29 | testPrivateKeys = make(map[string]interface{}, n) 30 | testSigners = make(map[string]ssh.Signer, n) 31 | testPublicKeys = make(map[string]ssh.PublicKey, n) 32 | for t, k := range testdata.PEMBytes { 33 | testPrivateKeys[t], err = ssh.ParseRawPrivateKey(k) 34 | if err != nil { 35 | panic(fmt.Sprintf("Unable to parse test key %s: %v", t, err)) 36 | } 37 | testSigners[t], err = ssh.NewSignerFromKey(testPrivateKeys[t]) 38 | if err != nil { 39 | panic(fmt.Sprintf("Unable to create signer for test key %s: %v", t, err)) 40 | } 41 | testPublicKeys[t] = testSigners[t].PublicKey() 42 | } 43 | 44 | // Create a cert and sign it for use in tests. 45 | testCert := &ssh.Certificate{ 46 | Nonce: []byte{}, // To pass reflect.DeepEqual after marshal & parse, this must be non-nil 47 | ValidPrincipals: []string{"gopher1", "gopher2"}, // increases test coverage 48 | ValidAfter: 0, // unix epoch 49 | ValidBefore: ssh.CertTimeInfinity, // The end of currently representable time. 50 | Reserved: []byte{}, // To pass reflect.DeepEqual after marshal & parse, this must be non-nil 51 | Key: testPublicKeys["ecdsa"], 52 | SignatureKey: testPublicKeys["rsa"], 53 | Permissions: ssh.Permissions{ 54 | CriticalOptions: map[string]string{}, 55 | Extensions: map[string]string{}, 56 | }, 57 | } 58 | testCert.SignCert(rand.Reader, testSigners["rsa"]) 59 | testPrivateKeys["cert"] = testPrivateKeys["ecdsa"] 60 | testSigners["cert"], err = ssh.NewCertSigner(testCert, testSigners["ecdsa"]) 61 | if err != nil { 62 | panic(fmt.Sprintf("Unable to create certificate signer: %v", err)) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/benchmark_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | import ( 8 | "errors" 9 | "io" 10 | "net" 11 | "testing" 12 | ) 13 | 14 | type server struct { 15 | *ServerConn 16 | chans <-chan NewChannel 17 | } 18 | 19 | func newServer(c net.Conn, conf *ServerConfig) (*server, error) { 20 | sconn, chans, reqs, err := NewServerConn(c, conf) 21 | if err != nil { 22 | return nil, err 23 | } 24 | go DiscardRequests(reqs) 25 | return &server{sconn, chans}, nil 26 | } 27 | 28 | func (s *server) Accept() (NewChannel, error) { 29 | n, ok := <-s.chans 30 | if !ok { 31 | return nil, io.EOF 32 | } 33 | return n, nil 34 | } 35 | 36 | func sshPipe() (Conn, *server, error) { 37 | c1, c2, err := netPipe() 38 | if err != nil { 39 | return nil, nil, err 40 | } 41 | 42 | clientConf := ClientConfig{ 43 | User: "user", 44 | HostKeyCallback: InsecureIgnoreHostKey(), 45 | } 46 | serverConf := ServerConfig{ 47 | NoClientAuth: true, 48 | } 49 | serverConf.AddHostKey(testSigners["ecdsa"]) 50 | done := make(chan *server, 1) 51 | go func() { 52 | server, err := newServer(c2, &serverConf) 53 | if err != nil { 54 | done <- nil 55 | } 56 | done <- server 57 | }() 58 | 59 | client, _, reqs, err := NewClientConn(c1, "", &clientConf) 60 | if err != nil { 61 | return nil, nil, err 62 | } 63 | 64 | server := <-done 65 | if server == nil { 66 | return nil, nil, errors.New("server handshake failed.") 67 | } 68 | go DiscardRequests(reqs) 69 | 70 | return client, server, nil 71 | } 72 | 73 | func BenchmarkEndToEnd(b *testing.B) { 74 | b.StopTimer() 75 | 76 | client, server, err := sshPipe() 77 | if err != nil { 78 | b.Fatalf("sshPipe: %v", err) 79 | } 80 | 81 | defer client.Close() 82 | defer server.Close() 83 | 84 | size := (1 << 20) 85 | input := make([]byte, size) 86 | output := make([]byte, size) 87 | b.SetBytes(int64(size)) 88 | done := make(chan int, 1) 89 | 90 | go func() { 91 | newCh, err := server.Accept() 92 | if err != nil { 93 | b.Fatalf("Client: %v", err) 94 | } 95 | ch, incoming, err := newCh.Accept() 96 | if err != nil { 97 | b.Fatalf("Accept: %v", err) 98 | } 99 | go DiscardRequests(incoming) 100 | for i := 0; i < b.N; i++ { 101 | if _, err := io.ReadFull(ch, output); err != nil { 102 | b.Fatalf("ReadFull: %v", err) 103 | } 104 | } 105 | ch.Close() 106 | done <- 1 107 | }() 108 | 109 | ch, in, err := client.OpenChannel("speed", nil) 110 | if err != nil { 111 | b.Fatalf("OpenChannel: %v", err) 112 | } 113 | go DiscardRequests(in) 114 | 115 | b.ResetTimer() 116 | b.StartTimer() 117 | for i := 0; i < b.N; i++ { 118 | if _, err := ch.Write(input); err != nil { 119 | b.Fatalf("WriteFull: %v", err) 120 | } 121 | } 122 | ch.Close() 123 | b.StopTimer() 124 | 125 | <-done 126 | } 127 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/buffer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | import ( 8 | "io" 9 | "sync" 10 | ) 11 | 12 | // buffer provides a linked list buffer for data exchange 13 | // between producer and consumer. Theoretically the buffer is 14 | // of unlimited capacity as it does no allocation of its own. 15 | type buffer struct { 16 | // protects concurrent access to head, tail and closed 17 | *sync.Cond 18 | 19 | head *element // the buffer that will be read first 20 | tail *element // the buffer that will be read last 21 | 22 | closed bool 23 | } 24 | 25 | // An element represents a single link in a linked list. 26 | type element struct { 27 | buf []byte 28 | next *element 29 | } 30 | 31 | // newBuffer returns an empty buffer that is not closed. 32 | func newBuffer() *buffer { 33 | e := new(element) 34 | b := &buffer{ 35 | Cond: newCond(), 36 | head: e, 37 | tail: e, 38 | } 39 | return b 40 | } 41 | 42 | // write makes buf available for Read to receive. 43 | // buf must not be modified after the call to write. 44 | func (b *buffer) write(buf []byte) { 45 | b.Cond.L.Lock() 46 | e := &element{buf: buf} 47 | b.tail.next = e 48 | b.tail = e 49 | b.Cond.Signal() 50 | b.Cond.L.Unlock() 51 | } 52 | 53 | // eof closes the buffer. Reads from the buffer once all 54 | // the data has been consumed will receive io.EOF. 55 | func (b *buffer) eof() { 56 | b.Cond.L.Lock() 57 | b.closed = true 58 | b.Cond.Signal() 59 | b.Cond.L.Unlock() 60 | } 61 | 62 | // Read reads data from the internal buffer in buf. Reads will block 63 | // if no data is available, or until the buffer is closed. 64 | func (b *buffer) Read(buf []byte) (n int, err error) { 65 | b.Cond.L.Lock() 66 | defer b.Cond.L.Unlock() 67 | 68 | for len(buf) > 0 { 69 | // if there is data in b.head, copy it 70 | if len(b.head.buf) > 0 { 71 | r := copy(buf, b.head.buf) 72 | buf, b.head.buf = buf[r:], b.head.buf[r:] 73 | n += r 74 | continue 75 | } 76 | // if there is a next buffer, make it the head 77 | if len(b.head.buf) == 0 && b.head != b.tail { 78 | b.head = b.head.next 79 | continue 80 | } 81 | 82 | // if at least one byte has been copied, return 83 | if n > 0 { 84 | break 85 | } 86 | 87 | // if nothing was read, and there is nothing outstanding 88 | // check to see if the buffer is closed. 89 | if b.closed { 90 | err = io.EOF 91 | break 92 | } 93 | // out of buffers, wait for producer 94 | b.Cond.Wait() 95 | } 96 | return 97 | } 98 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/buffer_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | import ( 8 | "io" 9 | "testing" 10 | ) 11 | 12 | var alphabet = []byte("abcdefghijklmnopqrstuvwxyz") 13 | 14 | func TestBufferReadwrite(t *testing.T) { 15 | b := newBuffer() 16 | b.write(alphabet[:10]) 17 | r, _ := b.Read(make([]byte, 10)) 18 | if r != 10 { 19 | t.Fatalf("Expected written == read == 10, written: 10, read %d", r) 20 | } 21 | 22 | b = newBuffer() 23 | b.write(alphabet[:5]) 24 | r, _ = b.Read(make([]byte, 10)) 25 | if r != 5 { 26 | t.Fatalf("Expected written == read == 5, written: 5, read %d", r) 27 | } 28 | 29 | b = newBuffer() 30 | b.write(alphabet[:10]) 31 | r, _ = b.Read(make([]byte, 5)) 32 | if r != 5 { 33 | t.Fatalf("Expected written == 10, read == 5, written: 10, read %d", r) 34 | } 35 | 36 | b = newBuffer() 37 | b.write(alphabet[:5]) 38 | b.write(alphabet[5:15]) 39 | r, _ = b.Read(make([]byte, 10)) 40 | r2, _ := b.Read(make([]byte, 10)) 41 | if r != 10 || r2 != 5 || 15 != r+r2 { 42 | t.Fatal("Expected written == read == 15") 43 | } 44 | } 45 | 46 | func TestBufferClose(t *testing.T) { 47 | b := newBuffer() 48 | b.write(alphabet[:10]) 49 | b.eof() 50 | _, err := b.Read(make([]byte, 5)) 51 | if err != nil { 52 | t.Fatal("expected read of 5 to not return EOF") 53 | } 54 | b = newBuffer() 55 | b.write(alphabet[:10]) 56 | b.eof() 57 | r, err := b.Read(make([]byte, 5)) 58 | r2, err2 := b.Read(make([]byte, 10)) 59 | if r != 5 || r2 != 5 || err != nil || err2 != nil { 60 | t.Fatal("expected reads of 5 and 5") 61 | } 62 | 63 | b = newBuffer() 64 | b.write(alphabet[:10]) 65 | b.eof() 66 | r, err = b.Read(make([]byte, 5)) 67 | r2, err2 = b.Read(make([]byte, 10)) 68 | r3, err3 := b.Read(make([]byte, 10)) 69 | if r != 5 || r2 != 5 || r3 != 0 || err != nil || err2 != nil || err3 != io.EOF { 70 | t.Fatal("expected reads of 5 and 5 and 0, with EOF") 71 | } 72 | 73 | b = newBuffer() 74 | b.write(make([]byte, 5)) 75 | b.write(make([]byte, 10)) 76 | b.eof() 77 | r, err = b.Read(make([]byte, 9)) 78 | r2, err2 = b.Read(make([]byte, 3)) 79 | r3, err3 = b.Read(make([]byte, 3)) 80 | r4, err4 := b.Read(make([]byte, 10)) 81 | if err != nil || err2 != nil || err3 != nil || err4 != io.EOF { 82 | t.Fatalf("Expected EOF on forth read only, err=%v, err2=%v, err3=%v, err4=%v", err, err2, err3, err4) 83 | } 84 | if r != 9 || r2 != 3 || r3 != 3 || r4 != 0 { 85 | t.Fatal("Expected written == read == 15", r, r2, r3, r4) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package ssh implements an SSH client and server. 7 | 8 | SSH is a transport security protocol, an authentication protocol and a 9 | family of application protocols. The most typical application level 10 | protocol is a remote shell and this is specifically implemented. However, 11 | the multiplexed nature of SSH is exposed to users that wish to support 12 | others. 13 | 14 | References: 15 | [PROTOCOL.certkeys]: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?rev=HEAD 16 | [SSH-PARAMETERS]: http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xml#ssh-parameters-1 17 | 18 | This package does not fall under the stability promise of the Go language itself, 19 | so its API may be changed when pressing needs arise. 20 | */ 21 | package ssh // import "golang.org/x/crypto/ssh" 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/kex_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | // Key exchange tests. 8 | 9 | import ( 10 | "crypto/rand" 11 | "reflect" 12 | "testing" 13 | ) 14 | 15 | func TestKexes(t *testing.T) { 16 | type kexResultErr struct { 17 | result *kexResult 18 | err error 19 | } 20 | 21 | for name, kex := range kexAlgoMap { 22 | a, b := memPipe() 23 | 24 | s := make(chan kexResultErr, 1) 25 | c := make(chan kexResultErr, 1) 26 | var magics handshakeMagics 27 | go func() { 28 | r, e := kex.Client(a, rand.Reader, &magics) 29 | a.Close() 30 | c <- kexResultErr{r, e} 31 | }() 32 | go func() { 33 | r, e := kex.Server(b, rand.Reader, &magics, testSigners["ecdsa"]) 34 | b.Close() 35 | s <- kexResultErr{r, e} 36 | }() 37 | 38 | clientRes := <-c 39 | serverRes := <-s 40 | if clientRes.err != nil { 41 | t.Errorf("client: %v", clientRes.err) 42 | } 43 | if serverRes.err != nil { 44 | t.Errorf("server: %v", serverRes.err) 45 | } 46 | if !reflect.DeepEqual(clientRes.result, serverRes.result) { 47 | t.Errorf("kex %q: mismatch %#v, %#v", name, clientRes.result, serverRes.result) 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/mac.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | // Message authentication support 8 | 9 | import ( 10 | "crypto/hmac" 11 | "crypto/sha1" 12 | "crypto/sha256" 13 | "hash" 14 | ) 15 | 16 | type macMode struct { 17 | keySize int 18 | etm bool 19 | new func(key []byte) hash.Hash 20 | } 21 | 22 | // truncatingMAC wraps around a hash.Hash and truncates the output digest to 23 | // a given size. 24 | type truncatingMAC struct { 25 | length int 26 | hmac hash.Hash 27 | } 28 | 29 | func (t truncatingMAC) Write(data []byte) (int, error) { 30 | return t.hmac.Write(data) 31 | } 32 | 33 | func (t truncatingMAC) Sum(in []byte) []byte { 34 | out := t.hmac.Sum(in) 35 | return out[:len(in)+t.length] 36 | } 37 | 38 | func (t truncatingMAC) Reset() { 39 | t.hmac.Reset() 40 | } 41 | 42 | func (t truncatingMAC) Size() int { 43 | return t.length 44 | } 45 | 46 | func (t truncatingMAC) BlockSize() int { return t.hmac.BlockSize() } 47 | 48 | var macModes = map[string]*macMode{ 49 | "hmac-sha2-256-etm@openssh.com": {32, true, func(key []byte) hash.Hash { 50 | return hmac.New(sha256.New, key) 51 | }}, 52 | "hmac-sha2-256": {32, false, func(key []byte) hash.Hash { 53 | return hmac.New(sha256.New, key) 54 | }}, 55 | "hmac-sha1": {20, false, func(key []byte) hash.Hash { 56 | return hmac.New(sha1.New, key) 57 | }}, 58 | "hmac-sha1-96": {20, false, func(key []byte) hash.Hash { 59 | return truncatingMAC{12, hmac.New(sha1.New, key)} 60 | }}, 61 | } 62 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/mempipe_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | import ( 8 | "io" 9 | "sync" 10 | "testing" 11 | ) 12 | 13 | // An in-memory packetConn. It is safe to call Close and writePacket 14 | // from different goroutines. 15 | type memTransport struct { 16 | eof bool 17 | pending [][]byte 18 | write *memTransport 19 | sync.Mutex 20 | *sync.Cond 21 | } 22 | 23 | func (t *memTransport) readPacket() ([]byte, error) { 24 | t.Lock() 25 | defer t.Unlock() 26 | for { 27 | if len(t.pending) > 0 { 28 | r := t.pending[0] 29 | t.pending = t.pending[1:] 30 | return r, nil 31 | } 32 | if t.eof { 33 | return nil, io.EOF 34 | } 35 | t.Cond.Wait() 36 | } 37 | } 38 | 39 | func (t *memTransport) closeSelf() error { 40 | t.Lock() 41 | defer t.Unlock() 42 | if t.eof { 43 | return io.EOF 44 | } 45 | t.eof = true 46 | t.Cond.Broadcast() 47 | return nil 48 | } 49 | 50 | func (t *memTransport) Close() error { 51 | err := t.write.closeSelf() 52 | t.closeSelf() 53 | return err 54 | } 55 | 56 | func (t *memTransport) writePacket(p []byte) error { 57 | t.write.Lock() 58 | defer t.write.Unlock() 59 | if t.write.eof { 60 | return io.EOF 61 | } 62 | c := make([]byte, len(p)) 63 | copy(c, p) 64 | t.write.pending = append(t.write.pending, c) 65 | t.write.Cond.Signal() 66 | return nil 67 | } 68 | 69 | func memPipe() (a, b packetConn) { 70 | t1 := memTransport{} 71 | t2 := memTransport{} 72 | t1.write = &t2 73 | t2.write = &t1 74 | t1.Cond = sync.NewCond(&t1.Mutex) 75 | t2.Cond = sync.NewCond(&t2.Mutex) 76 | return &t1, &t2 77 | } 78 | 79 | func TestMemPipe(t *testing.T) { 80 | a, b := memPipe() 81 | if err := a.writePacket([]byte{42}); err != nil { 82 | t.Fatalf("writePacket: %v", err) 83 | } 84 | if err := a.Close(); err != nil { 85 | t.Fatal("Close: ", err) 86 | } 87 | p, err := b.readPacket() 88 | if err != nil { 89 | t.Fatal("readPacket: ", err) 90 | } 91 | if len(p) != 1 || p[0] != 42 { 92 | t.Fatalf("got %v, want {42}", p) 93 | } 94 | p, err = b.readPacket() 95 | if err != io.EOF { 96 | t.Fatalf("got %v, %v, want EOF", p, err) 97 | } 98 | } 99 | 100 | func TestDoubleClose(t *testing.T) { 101 | a, _ := memPipe() 102 | err := a.Close() 103 | if err != nil { 104 | t.Errorf("Close: %v", err) 105 | } 106 | err = a.Close() 107 | if err != io.EOF { 108 | t.Errorf("expect EOF on double close.") 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/tcpip_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | func TestAutoPortListenBroken(t *testing.T) { 12 | broken := "SSH-2.0-OpenSSH_5.9hh11" 13 | works := "SSH-2.0-OpenSSH_6.1" 14 | if !isBrokenOpenSSHVersion(broken) { 15 | t.Errorf("version %q not marked as broken", broken) 16 | } 17 | if isBrokenOpenSSHVersion(works) { 18 | t.Errorf("version %q marked as broken", works) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_aix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build aix 6 | 7 | package terminal 8 | 9 | import "golang.org/x/sys/unix" 10 | 11 | const ioctlReadTermios = unix.TCGETS 12 | const ioctlWriteTermios = unix.TCSETS 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_bsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd netbsd openbsd 6 | 7 | package terminal 8 | 9 | import "golang.org/x/sys/unix" 10 | 11 | const ioctlReadTermios = unix.TIOCGETA 12 | const ioctlWriteTermios = unix.TIOCSETA 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package terminal 6 | 7 | import "golang.org/x/sys/unix" 8 | 9 | const ioctlReadTermios = unix.TCGETS 10 | const ioctlWriteTermios = unix.TCSETS 11 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_plan9.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package terminal provides support functions for dealing with terminals, as 6 | // commonly found on UNIX systems. 7 | // 8 | // Putting a terminal into raw mode is the most common requirement: 9 | // 10 | // oldState, err := terminal.MakeRaw(0) 11 | // if err != nil { 12 | // panic(err) 13 | // } 14 | // defer terminal.Restore(0, oldState) 15 | package terminal 16 | 17 | import ( 18 | "fmt" 19 | "runtime" 20 | ) 21 | 22 | type State struct{} 23 | 24 | // IsTerminal returns whether the given file descriptor is a terminal. 25 | func IsTerminal(fd int) bool { 26 | return false 27 | } 28 | 29 | // MakeRaw put the terminal connected to the given file descriptor into raw 30 | // mode and returns the previous state of the terminal so that it can be 31 | // restored. 32 | func MakeRaw(fd int) (*State, error) { 33 | return nil, fmt.Errorf("terminal: MakeRaw not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 34 | } 35 | 36 | // GetState returns the current state of a terminal which may be useful to 37 | // restore the terminal after a signal. 38 | func GetState(fd int) (*State, error) { 39 | return nil, fmt.Errorf("terminal: GetState not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 40 | } 41 | 42 | // Restore restores the terminal connected to the given file descriptor to a 43 | // previous state. 44 | func Restore(fd int, state *State) error { 45 | return fmt.Errorf("terminal: Restore not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 46 | } 47 | 48 | // GetSize returns the dimensions of the given terminal. 49 | func GetSize(fd int) (width, height int, err error) { 50 | return 0, 0, fmt.Errorf("terminal: GetSize not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 51 | } 52 | 53 | // ReadPassword reads a line of input from a terminal without local echo. This 54 | // is commonly used for inputting passwords and other sensitive data. The slice 55 | // returned does not include the \n. 56 | func ReadPassword(fd int) ([]byte, error) { 57 | return nil, fmt.Errorf("terminal: ReadPassword not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/test/agent_unix_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build aix darwin dragonfly freebsd linux netbsd openbsd 6 | 7 | package test 8 | 9 | import ( 10 | "bytes" 11 | "testing" 12 | 13 | "golang.org/x/crypto/ssh" 14 | "golang.org/x/crypto/ssh/agent" 15 | ) 16 | 17 | func TestAgentForward(t *testing.T) { 18 | server := newServer(t) 19 | defer server.Shutdown() 20 | conn := server.Dial(clientConfig()) 21 | defer conn.Close() 22 | 23 | keyring := agent.NewKeyring() 24 | if err := keyring.Add(agent.AddedKey{PrivateKey: testPrivateKeys["dsa"]}); err != nil { 25 | t.Fatalf("Error adding key: %s", err) 26 | } 27 | if err := keyring.Add(agent.AddedKey{ 28 | PrivateKey: testPrivateKeys["dsa"], 29 | ConfirmBeforeUse: true, 30 | LifetimeSecs: 3600, 31 | }); err != nil { 32 | t.Fatalf("Error adding key with constraints: %s", err) 33 | } 34 | pub := testPublicKeys["dsa"] 35 | 36 | sess, err := conn.NewSession() 37 | if err != nil { 38 | t.Fatalf("NewSession: %v", err) 39 | } 40 | if err := agent.RequestAgentForwarding(sess); err != nil { 41 | t.Fatalf("RequestAgentForwarding: %v", err) 42 | } 43 | 44 | if err := agent.ForwardToAgent(conn, keyring); err != nil { 45 | t.Fatalf("SetupForwardKeyring: %v", err) 46 | } 47 | out, err := sess.CombinedOutput("ssh-add -L") 48 | if err != nil { 49 | t.Fatalf("running ssh-add: %v, out %s", err, out) 50 | } 51 | key, _, _, _, err := ssh.ParseAuthorizedKey(out) 52 | if err != nil { 53 | t.Fatalf("ParseAuthorizedKey(%q): %v", out, err) 54 | } 55 | 56 | if !bytes.Equal(key.Marshal(), pub.Marshal()) { 57 | t.Fatalf("got key %s, want %s", ssh.MarshalAuthorizedKey(key), ssh.MarshalAuthorizedKey(pub)) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/test/banner_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build aix darwin dragonfly freebsd linux netbsd openbsd 6 | 7 | package test 8 | 9 | import ( 10 | "testing" 11 | ) 12 | 13 | func TestBannerCallbackAgainstOpenSSH(t *testing.T) { 14 | server := newServer(t) 15 | defer server.Shutdown() 16 | 17 | clientConf := clientConfig() 18 | 19 | var receivedBanner string 20 | clientConf.BannerCallback = func(message string) error { 21 | receivedBanner = message 22 | return nil 23 | } 24 | 25 | conn := server.Dial(clientConf) 26 | defer conn.Close() 27 | 28 | expected := "Server Banner" 29 | if receivedBanner != expected { 30 | t.Fatalf("got %v; want %v", receivedBanner, expected) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/test/cert_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build aix darwin dragonfly freebsd linux netbsd openbsd 6 | 7 | package test 8 | 9 | import ( 10 | "bytes" 11 | "crypto/rand" 12 | "testing" 13 | 14 | "golang.org/x/crypto/ssh" 15 | ) 16 | 17 | // Test both logging in with a cert, and also that the certificate presented by an OpenSSH host can be validated correctly 18 | func TestCertLogin(t *testing.T) { 19 | s := newServer(t) 20 | defer s.Shutdown() 21 | 22 | // Use a key different from the default. 23 | clientKey := testSigners["dsa"] 24 | caAuthKey := testSigners["ecdsa"] 25 | cert := &ssh.Certificate{ 26 | Key: clientKey.PublicKey(), 27 | ValidPrincipals: []string{username()}, 28 | CertType: ssh.UserCert, 29 | ValidBefore: ssh.CertTimeInfinity, 30 | } 31 | if err := cert.SignCert(rand.Reader, caAuthKey); err != nil { 32 | t.Fatalf("SetSignature: %v", err) 33 | } 34 | 35 | certSigner, err := ssh.NewCertSigner(cert, clientKey) 36 | if err != nil { 37 | t.Fatalf("NewCertSigner: %v", err) 38 | } 39 | 40 | conf := &ssh.ClientConfig{ 41 | User: username(), 42 | HostKeyCallback: (&ssh.CertChecker{ 43 | IsHostAuthority: func(pk ssh.PublicKey, addr string) bool { 44 | return bytes.Equal(pk.Marshal(), testPublicKeys["ca"].Marshal()) 45 | }, 46 | }).CheckHostKey, 47 | } 48 | conf.Auth = append(conf.Auth, ssh.PublicKeys(certSigner)) 49 | 50 | for _, test := range []struct { 51 | addr string 52 | succeed bool 53 | }{ 54 | {addr: "host.example.com:22", succeed: true}, 55 | {addr: "host.example.com:10000", succeed: true}, // non-standard port must be OK 56 | {addr: "host.example.com", succeed: false}, // port must be specified 57 | {addr: "host.ex4mple.com:22", succeed: false}, // wrong host 58 | } { 59 | client, err := s.TryDialWithAddr(conf, test.addr) 60 | 61 | // Always close client if opened successfully 62 | if err == nil { 63 | client.Close() 64 | } 65 | 66 | // Now evaluate whether the test failed or passed 67 | if test.succeed { 68 | if err != nil { 69 | t.Fatalf("TryDialWithAddr: %v", err) 70 | } 71 | } else { 72 | if err == nil { 73 | t.Fatalf("TryDialWithAddr, unexpected success") 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/test/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package test contains integration tests for the 6 | // golang.org/x/crypto/ssh package. 7 | package test // import "golang.org/x/crypto/ssh/test" 8 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/test/testdata_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // IMPLEMENTATION NOTE: To avoid a package loop, this file is in three places: 6 | // ssh/, ssh/agent, and ssh/test/. It should be kept in sync across all three 7 | // instances. 8 | 9 | package test 10 | 11 | import ( 12 | "crypto/rand" 13 | "fmt" 14 | 15 | "golang.org/x/crypto/ssh" 16 | "golang.org/x/crypto/ssh/testdata" 17 | ) 18 | 19 | var ( 20 | testPrivateKeys map[string]interface{} 21 | testSigners map[string]ssh.Signer 22 | testPublicKeys map[string]ssh.PublicKey 23 | ) 24 | 25 | func init() { 26 | var err error 27 | 28 | n := len(testdata.PEMBytes) 29 | testPrivateKeys = make(map[string]interface{}, n) 30 | testSigners = make(map[string]ssh.Signer, n) 31 | testPublicKeys = make(map[string]ssh.PublicKey, n) 32 | for t, k := range testdata.PEMBytes { 33 | testPrivateKeys[t], err = ssh.ParseRawPrivateKey(k) 34 | if err != nil { 35 | panic(fmt.Sprintf("Unable to parse test key %s: %v", t, err)) 36 | } 37 | testSigners[t], err = ssh.NewSignerFromKey(testPrivateKeys[t]) 38 | if err != nil { 39 | panic(fmt.Sprintf("Unable to create signer for test key %s: %v", t, err)) 40 | } 41 | testPublicKeys[t] = testSigners[t].PublicKey() 42 | } 43 | 44 | // Create a cert and sign it for use in tests. 45 | testCert := &ssh.Certificate{ 46 | Nonce: []byte{}, // To pass reflect.DeepEqual after marshal & parse, this must be non-nil 47 | ValidPrincipals: []string{"gopher1", "gopher2"}, // increases test coverage 48 | ValidAfter: 0, // unix epoch 49 | ValidBefore: ssh.CertTimeInfinity, // The end of currently representable time. 50 | Reserved: []byte{}, // To pass reflect.DeepEqual after marshal & parse, this must be non-nil 51 | Key: testPublicKeys["ecdsa"], 52 | SignatureKey: testPublicKeys["rsa"], 53 | Permissions: ssh.Permissions{ 54 | CriticalOptions: map[string]string{}, 55 | Extensions: map[string]string{}, 56 | }, 57 | } 58 | testCert.SignCert(rand.Reader, testSigners["rsa"]) 59 | testPrivateKeys["cert"] = testPrivateKeys["ecdsa"] 60 | testSigners["cert"], err = ssh.NewCertSigner(testCert, testSigners["ecdsa"]) 61 | if err != nil { 62 | panic(fmt.Sprintf("Unable to create certificate signer: %v", err)) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/testdata/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This package contains test data shared between the various subpackages of 6 | // the golang.org/x/crypto/ssh package. Under no circumstance should 7 | // this data be used for production code. 8 | package testdata // import "golang.org/x/crypto/ssh/testdata" 9 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/testdata_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // IMPLEMENTATION NOTE: To avoid a package loop, this file is in three places: 6 | // ssh/, ssh/agent, and ssh/test/. It should be kept in sync across all three 7 | // instances. 8 | 9 | package ssh 10 | 11 | import ( 12 | "crypto/rand" 13 | "fmt" 14 | 15 | "golang.org/x/crypto/ssh/testdata" 16 | ) 17 | 18 | var ( 19 | testPrivateKeys map[string]interface{} 20 | testSigners map[string]Signer 21 | testPublicKeys map[string]PublicKey 22 | ) 23 | 24 | func init() { 25 | var err error 26 | 27 | n := len(testdata.PEMBytes) 28 | testPrivateKeys = make(map[string]interface{}, n) 29 | testSigners = make(map[string]Signer, n) 30 | testPublicKeys = make(map[string]PublicKey, n) 31 | for t, k := range testdata.PEMBytes { 32 | testPrivateKeys[t], err = ParseRawPrivateKey(k) 33 | if err != nil { 34 | panic(fmt.Sprintf("Unable to parse test key %s: %v", t, err)) 35 | } 36 | testSigners[t], err = NewSignerFromKey(testPrivateKeys[t]) 37 | if err != nil { 38 | panic(fmt.Sprintf("Unable to create signer for test key %s: %v", t, err)) 39 | } 40 | testPublicKeys[t] = testSigners[t].PublicKey() 41 | } 42 | 43 | // Create a cert and sign it for use in tests. 44 | testCert := &Certificate{ 45 | Nonce: []byte{}, // To pass reflect.DeepEqual after marshal & parse, this must be non-nil 46 | ValidPrincipals: []string{"gopher1", "gopher2"}, // increases test coverage 47 | ValidAfter: 0, // unix epoch 48 | ValidBefore: CertTimeInfinity, // The end of currently representable time. 49 | Reserved: []byte{}, // To pass reflect.DeepEqual after marshal & parse, this must be non-nil 50 | Key: testPublicKeys["ecdsa"], 51 | SignatureKey: testPublicKeys["rsa"], 52 | Permissions: Permissions{ 53 | CriticalOptions: map[string]string{}, 54 | Extensions: map[string]string{}, 55 | }, 56 | } 57 | testCert.SignCert(rand.Reader, testSigners["rsa"]) 58 | testPrivateKeys["cert"] = testPrivateKeys["ecdsa"] 59 | testSigners["cert"], err = NewCertSigner(testCert, testSigners["ecdsa"]) 60 | if err != nil { 61 | panic(fmt.Sprintf("Unable to create certificate signer: %v", err)) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/xtea/block.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Implementation adapted from Needham and Wheeler's paper: 7 | http://www.cix.co.uk/~klockstone/xtea.pdf 8 | 9 | A precalculated look up table is used during encryption/decryption for values that are based purely on the key. 10 | */ 11 | 12 | package xtea 13 | 14 | // XTEA is based on 64 rounds. 15 | const numRounds = 64 16 | 17 | // blockToUint32 reads an 8 byte slice into two uint32s. 18 | // The block is treated as big endian. 19 | func blockToUint32(src []byte) (uint32, uint32) { 20 | r0 := uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3]) 21 | r1 := uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7]) 22 | return r0, r1 23 | } 24 | 25 | // uint32ToBlock writes two uint32s into an 8 byte data block. 26 | // Values are written as big endian. 27 | func uint32ToBlock(v0, v1 uint32, dst []byte) { 28 | dst[0] = byte(v0 >> 24) 29 | dst[1] = byte(v0 >> 16) 30 | dst[2] = byte(v0 >> 8) 31 | dst[3] = byte(v0) 32 | dst[4] = byte(v1 >> 24) 33 | dst[5] = byte(v1 >> 16) 34 | dst[6] = byte(v1 >> 8) 35 | dst[7] = byte(v1 >> 0) 36 | } 37 | 38 | // encryptBlock encrypts a single 8 byte block using XTEA. 39 | func encryptBlock(c *Cipher, dst, src []byte) { 40 | v0, v1 := blockToUint32(src) 41 | 42 | // Two rounds of XTEA applied per loop 43 | for i := 0; i < numRounds; { 44 | v0 += ((v1<<4 ^ v1>>5) + v1) ^ c.table[i] 45 | i++ 46 | v1 += ((v0<<4 ^ v0>>5) + v0) ^ c.table[i] 47 | i++ 48 | } 49 | 50 | uint32ToBlock(v0, v1, dst) 51 | } 52 | 53 | // decryptBlock decrypts a single 8 byte block using XTEA. 54 | func decryptBlock(c *Cipher, dst, src []byte) { 55 | v0, v1 := blockToUint32(src) 56 | 57 | // Two rounds of XTEA applied per loop 58 | for i := numRounds; i > 0; { 59 | i-- 60 | v1 -= ((v0<<4 ^ v0>>5) + v0) ^ c.table[i] 61 | i-- 62 | v0 -= ((v1<<4 ^ v1>>5) + v1) ^ c.table[i] 63 | } 64 | 65 | uint32ToBlock(v0, v1, dst) 66 | } 67 | --------------------------------------------------------------------------------