| 1 | package httpsigscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/" |
| 5 | "cryptoscip-go gomod github.com/golang/go/src go1.25.0 crypto/" |
| 6 | "crypto/randscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rand`/" |
| 7 | "crypto/rsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/" |
| 8 | "crypto/sha256scip-go gomod github.com/golang/go/src go1.25.0 `crypto/sha256`/" |
| 9 | "crypto/x509scip-go gomod github.com/golang/go/src go1.25.0 `crypto/x509`/" |
| 10 | "encoding/asn1scip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/" |
| 11 | "encoding/base64scip-go gomod github.com/golang/go/src go1.25.0 `encoding/base64`/" |
| 12 | "encoding/pemscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/" |
| 13 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 14 | "io/ioutilscip-go gomod github.com/golang/go/src go1.25.0 `io/ioutil`/" |
| 15 | "net/httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/" |
| 16 | "net/http/httptestscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/" |
| 17 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 18 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 19 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 20 | |
| 21 | "golang.org/x/crypto/ed25519scip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/" |
| 22 | ) |
| 23 | |
| 24 | const ( |
| 25 | testUrlscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testUrl. = "foo.net/bar/baz?q=test&r=ok" |
| 26 | testUrlPathscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testUrlPath. = "bar/baz" |
| 27 | testDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDate. = "Tue, 07 Jun 2014 20:51:35 GMT" |
| 28 | testDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDigest. = "SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=" |
| 29 | testMethodscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testMethod. = "GET" |
| 30 | ) |
| 31 | |
| 32 | type httpsigTestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest# struct { |
| 33 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name. string |
| 34 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs. []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm# |
| 35 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg. DigestAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestAlgorithm# |
| 36 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers. []string |
| 37 | bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body. []byte |
| 38 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme. SignatureSchemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/SignatureScheme# |
| 39 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey. cryptoscip-go gomod github.com/golang/go/src go1.25.0 crypto/.PrivateKeyscip-go gomod github.com/golang/go/src go1.25.0 crypto/PrivateKey# |
| 40 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey. cryptoscip-go gomod github.com/golang/go/src go1.25.0 crypto/.PublicKeyscip-go gomod github.com/golang/go/src go1.25.0 crypto/PublicKey# |
| 41 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId. string |
| 42 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm. string |
| 43 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm. Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm# |
| 44 | expectErrorSigningResponsescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectErrorSigningResponse. bool |
| 45 | expectRequestPathscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectRequestPath. bool |
| 46 | expectedDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedDigest. string |
| 47 | } |
| 48 | |
| 49 | type ed25519PrivKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PrivKey# struct { |
| 50 | Versionscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PrivKey#Version. int |
| 51 | ObjectIdentifierscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PrivKey#ObjectIdentifier. struct { |
| 52 | ObjectIdentifierscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PrivKey#$anon_ef5470ce68a67940#ObjectIdentifier. asn1scip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/ObjectIdentifier# |
| 53 | } |
| 54 | PrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PrivKey#PrivateKey. []byte |
| 55 | } |
| 56 | |
| 57 | type ed25519PubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PubKey# struct { |
| 58 | OBjectIdentifierscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PubKey#OBjectIdentifier. struct { |
| 59 | ObjectIdentifierscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PubKey#$anon_ef5470ce68a67940#ObjectIdentifier. asn1scip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/ObjectIdentifier# |
| 60 | } |
| 61 | PublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PubKey#PublicKey. asn1scip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/BitString# |
| 62 | } |
| 63 | |
| 64 | var ( |
| 65 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey. *rsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey# |
| 66 | macKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/macKey. []byte |
| 67 | testsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/tests. []httpsigTestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest# |
| 68 | testSpecRSAPrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecRSAPrivateKey. *rsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey# |
| 69 | testSpecRSAPublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecRSAPublicKey. *rsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/.PublicKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PublicKey# |
| 70 | testEd25519PrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testEd25519PrivateKey. ed25519scip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/.PrivateKeyscip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/PrivateKey# |
| 71 | testEd25519PublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testEd25519PublicKey. ed25519scip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/.PublicKeyscip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/PublicKey# |
| 72 | ) |
| 73 | |
| 74 | func initscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/init().() { |
| 75 | var err error |
| 76 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey., err = rsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/.GenerateKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/GenerateKey().(randscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rand`/Reader., 2048) |
| 77 | if err != nil { |
| 78 | panic(err) |
| 79 | } |
| 80 | pubEd25519Key, privEd25519Key, err := ed25519scip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/.GenerateKeyscip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/GenerateKey().(randscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rand`/Reader.) |
| 81 | if err != nil { |
| 82 | panic(err) |
| 83 | } |
| 84 | macKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/macKey. = make([]byte, 128) |
| 85 | err = readFullFromCryptoscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/readFullFromCrypto().(macKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/macKey.) |
| 86 | if err != nil { |
| 87 | panic(err) |
| 88 | } |
| 89 | testsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/tests. = []httpsigTestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#{ |
| 90 | { |
| 91 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "rsa signature", |
| 92 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512.}, |
| 93 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 94 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest"}, |
| 95 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 96 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey., |
| 97 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey..Publicscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Public().(), |
| 98 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 99 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512., |
| 100 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 101 | }, |
| 102 | { |
| 103 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "ed25519 signature", |
| 104 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{ED25519scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ED25519.}, |
| 105 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha512., |
| 106 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest"}, |
| 107 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 108 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: privEd25519Key, |
| 109 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: pubEd25519Key, |
| 110 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 111 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: ED25519scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ED25519., |
| 112 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 113 | }, |
| 114 | { |
| 115 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "digest on rsa signature", |
| 116 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512.}, |
| 117 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 118 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest"}, |
| 119 | bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body.: []byte("Last night as I lay dreaming This strangest kind of feeling Revealed its secret meaning And now I know..."), |
| 120 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 121 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey., |
| 122 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey..Publicscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Public().(), |
| 123 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 124 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512., |
| 125 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 126 | expectedDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedDigest.: "SHA-256=07PJQngqg8+BlomdI6zM7ieOxhINWI+iivJxBDSm3Dg=", |
| 127 | }, |
| 128 | { |
| 129 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "digest on ed25519 signature", |
| 130 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{ED25519scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ED25519.}, |
| 131 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 132 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest"}, |
| 133 | bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body.: []byte("Last night as I lay dreaming This strangest kind of feeling Revealed its secret meaning And now I know..."), |
| 134 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 135 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: privEd25519Key, |
| 136 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: pubEd25519Key, |
| 137 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 138 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: ED25519scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ED25519., |
| 139 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 140 | expectedDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedDigest.: "SHA-256=07PJQngqg8+BlomdI6zM7ieOxhINWI+iivJxBDSm3Dg=", |
| 141 | }, |
| 142 | { |
| 143 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "hmac signature", |
| 144 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{HMAC_SHA256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/HMAC_SHA256.}, |
| 145 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 146 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest"}, |
| 147 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 148 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: macKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/macKey., |
| 149 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: macKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/macKey., |
| 150 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 151 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: HMAC_SHA256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/HMAC_SHA256., |
| 152 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 153 | }, |
| 154 | { |
| 155 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "digest on hmac signature", |
| 156 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{HMAC_SHA256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/HMAC_SHA256.}, |
| 157 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 158 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest"}, |
| 159 | bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body.: []byte("I've never ever been to paradise I've never ever seen no angel's eyes You'll never ever let this magic die No matter where you are, you are my lucky star."), |
| 160 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 161 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: macKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/macKey., |
| 162 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: macKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/macKey., |
| 163 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 164 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: HMAC_SHA256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/HMAC_SHA256., |
| 165 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 166 | expectedDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedDigest.: "SHA-256=d0JoDjbDZRZF7/gUdgrazZCdKCJ9z9uUcMd6n1YKWRU=", |
| 167 | }, |
| 168 | { |
| 169 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "rsa authorization", |
| 170 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512.}, |
| 171 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 172 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest"}, |
| 173 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Authorizationscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Authorization., |
| 174 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey., |
| 175 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey..Publicscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Public().(), |
| 176 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 177 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512., |
| 178 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 179 | }, |
| 180 | { |
| 181 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "ed25519 authorization", |
| 182 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{ED25519scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ED25519.}, |
| 183 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 184 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest"}, |
| 185 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Authorizationscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Authorization., |
| 186 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: privEd25519Key, |
| 187 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: pubEd25519Key, |
| 188 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 189 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: ED25519scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ED25519., |
| 190 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 191 | }, |
| 192 | { |
| 193 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "hmac authorization", |
| 194 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{HMAC_SHA256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/HMAC_SHA256.}, |
| 195 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 196 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest"}, |
| 197 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Authorizationscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Authorization., |
| 198 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: macKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/macKey., |
| 199 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: macKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/macKey., |
| 200 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 201 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: HMAC_SHA256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/HMAC_SHA256., |
| 202 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 203 | }, |
| 204 | { |
| 205 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "default algo", |
| 206 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 207 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest"}, |
| 208 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 209 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey., |
| 210 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey..Publicscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Public().(), |
| 211 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 212 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: RSA_SHA256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA256., |
| 213 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 214 | }, |
| 215 | { |
| 216 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "default headers", |
| 217 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512.}, |
| 218 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 219 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 220 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey., |
| 221 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey..Publicscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Public().(), |
| 222 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 223 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512., |
| 224 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 225 | }, |
| 226 | { |
| 227 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "different pub key id", |
| 228 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512.}, |
| 229 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 230 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest"}, |
| 231 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 232 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey., |
| 233 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey..Publicscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Public().(), |
| 234 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "i write code that sucks", |
| 235 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512., |
| 236 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 237 | }, |
| 238 | { |
| 239 | namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name.: "with request target", |
| 240 | prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs.: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512.}, |
| 241 | digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg.: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 242 | headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.: []string{"Date", "Digest", RequestTargetscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RequestTarget.}, |
| 243 | schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 244 | privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey., |
| 245 | pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey.: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey..Publicscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Public().(), |
| 246 | pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.: "pubKeyId", |
| 247 | expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.: RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512., |
| 248 | expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.: "hs2019", |
| 249 | expectErrorSigningResponsescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectErrorSigningResponse.: true, |
| 250 | expectRequestPathscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectRequestPath.: true, |
| 251 | }, |
| 252 | } |
| 253 | |
| 254 | testSpecRSAPrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecRSAPrivateKey., err = loadPrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/loadPrivateKey().([]byte(testSpecPrivateKeyPEMscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecPrivateKeyPEM.)) |
| 255 | if err != nil { |
| 256 | panic(err) |
| 257 | } |
| 258 | |
| 259 | testSpecRSAPublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecRSAPublicKey., err = loadPublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/loadPublicKey().([]byte(testSpecPublicKeyPEMscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecPublicKeyPEM.)) |
| 260 | if err != nil { |
| 261 | panic(err) |
| 262 | } |
| 263 | |
| 264 | testEd25519PrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testEd25519PrivateKey., err = loadEd25519PrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/loadEd25519PrivateKey().([]byte(testEd25519PrivateKeyPEMscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testEd25519PrivateKeyPEM.)) |
| 265 | if err != nil { |
| 266 | panic(err) |
| 267 | } |
| 268 | |
| 269 | testEd25519PublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testEd25519PublicKey., err = loadEd25519PublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/loadEd25519PublicKey().([]byte(testEd25519PublicKeyPEMscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testEd25519PublicKeyPEM.)) |
| 270 | if err != nil { |
| 271 | panic(err) |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | func toSignatureParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/toSignatureParameter().(k, v string) string { |
| 276 | return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s%s%s%s%s", k, parameterKVSeparaterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/parameterKVSeparater., parameterValueDelimiterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/parameterValueDelimiter., v, parameterValueDelimiterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/parameterValueDelimiter.) |
| 277 | } |
| 278 | |
| 279 | func toHeaderSignatureParametersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/toHeaderSignatureParameters().(k string, vals []string) string { |
| 280 | if len(vals) == 0 { |
| 281 | vals = defaultHeadersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/defaultHeaders. |
| 282 | } |
| 283 | v := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.0 strings/Join().(vals, headerParameterValueDelimscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/headerParameterValueDelim.) |
| 284 | k = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(k) |
| 285 | v = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(v) |
| 286 | return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s%s%s%s%s", k, parameterKVSeparaterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/parameterKVSeparater., parameterValueDelimiterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/parameterValueDelimiter., v, parameterValueDelimiterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/parameterValueDelimiter.) |
| 287 | } |
| 288 | |
| 289 | func TestSignerRequestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/TestSignerRequest().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 290 | testFn := func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, test httpsigTestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#) { |
| 291 | s, a, err := NewSignerscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewSigner().(test.prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs., test.digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg., test.headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers., test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme., 0) |
| 292 | if err != nil { |
| 293 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 294 | } |
| 295 | if a != test.expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm. { |
| 296 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("got %s, want %s", a, test.expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.) |
| 297 | } |
| 298 | // Test request signing |
| 299 | req, err := httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/NewRequest().(testMethodscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testMethod., testUrlscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testUrl., nil) |
| 300 | if err != nil { |
| 301 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 302 | } |
| 303 | req.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Date", testDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDate.) |
| 304 | if test.bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body. == nil { |
| 305 | req.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Digest", testDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDigest.) |
| 306 | } |
| 307 | err = s.SignRequestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signer#SignRequest.(test.privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey., test.pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId., req, test.bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body.) |
| 308 | if err != nil { |
| 309 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 310 | } |
| 311 | vals, ok := req.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.[string(test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.)] |
| 312 | if !ok { |
| 313 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("not in header %s", test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.) |
| 314 | } |
| 315 | if len(vals) != 1 { |
| 316 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("too many in header %s: %d", test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme., len(vals)) |
| 317 | } |
| 318 | if p := toSignatureParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/toSignatureParameter().(keyIdParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/keyIdParameter., test.pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.); !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(vals[0], p) { |
| 319 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not contain\n%s", vals[0], p) |
| 320 | } else if p := toSignatureParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/toSignatureParameter().(algorithmParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/algorithmParameter., string(test.expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.)); !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(vals[0], p) { |
| 321 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not contain\n%s", vals[0], p) |
| 322 | } else if p := toHeaderSignatureParametersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/toHeaderSignatureParameters().(headersParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/headersParameter., test.headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.); !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(vals[0], p) { |
| 323 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not contain\n%s", vals[0], p) |
| 324 | } else if !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(vals[0], signatureParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/signatureParameter.) { |
| 325 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not contain\n%s", vals[0], signatureParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/signatureParameter.) |
| 326 | } else if test.bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body. != nil && req.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Get().("Digest") != test.expectedDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedDigest. { |
| 327 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not match\n%s", req.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Get().("Digest"), test.expectedDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedDigest.) |
| 328 | } |
| 329 | // For schemes with an authScheme, enforce its is present and at the beginning |
| 330 | if len(test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme..authSchemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/SignatureScheme#authScheme().()) > 0 { |
| 331 | if !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(vals[0], test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme..authSchemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/SignatureScheme#authScheme().()) { |
| 332 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not start with\n%s", vals[0], test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme..authSchemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/SignatureScheme#authScheme().()) |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | for _, test := range testsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/tests. { |
| 337 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(test.namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name., func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 338 | testFn(t, test) |
| 339 | }) |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | func TestSignerResponsescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/TestSignerResponse().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 344 | testFn := func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, test httpsigTestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#) { |
| 345 | s, _, err := NewSignerscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewSigner().(test.prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs., test.digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg., test.headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers., test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme., 0) |
| 346 | // Test response signing |
| 347 | resp := httptestscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/NewRecorder().() |
| 348 | resp.HeaderMapscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/ResponseRecorder#HeaderMap..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Date", testDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDate.) |
| 349 | if test.bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body. == nil { |
| 350 | resp.HeaderMapscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/ResponseRecorder#HeaderMap..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Digest", testDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDigest.) |
| 351 | } |
| 352 | err = s.SignResponsescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signer#SignResponse.(test.privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey., test.pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId., resp, test.bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body.) |
| 353 | if test.expectErrorSigningResponsescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectErrorSigningResponse. { |
| 354 | if err != nil { |
| 355 | // Skip rest of testing |
| 356 | return |
| 357 | } else { |
| 358 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected error, got nil") |
| 359 | } |
| 360 | } |
| 361 | vals, ok := resp.HeaderMapscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/ResponseRecorder#HeaderMap.[string(test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.)] |
| 362 | if !ok { |
| 363 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("not in header %s", test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme.) |
| 364 | } |
| 365 | if len(vals) != 1 { |
| 366 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("too many in header %s: %d", test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme., len(vals)) |
| 367 | } |
| 368 | if p := toSignatureParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/toSignatureParameter().(keyIdParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/keyIdParameter., test.pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.); !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(vals[0], p) { |
| 369 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not contain\n%s", vals[0], p) |
| 370 | } else if p := toSignatureParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/toSignatureParameter().(algorithmParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/algorithmParameter., string(test.expectedSignatureAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedSignatureAlgorithm.)); !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(vals[0], p) { |
| 371 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not contain\n%s", vals[0], p) |
| 372 | } else if p := toHeaderSignatureParametersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/toHeaderSignatureParameters().(headersParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/headersParameter., test.headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers.); !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(vals[0], p) { |
| 373 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not contain\n%s", vals[0], p) |
| 374 | } else if !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(vals[0], signatureParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/signatureParameter.) { |
| 375 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not contain\n%s", vals[0], signatureParameterscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/signatureParameter.) |
| 376 | } else if test.bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body. != nil && resp.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/ResponseRecorder#Header().().Getscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Get().("Digest") != test.expectedDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedDigest. { |
| 377 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not match\n%s", resp.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/ResponseRecorder#Header().().Getscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Get().("Digest"), test.expectedDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedDigest.) |
| 378 | } |
| 379 | // For schemes with an authScheme, enforce its is present and at the beginning |
| 380 | if len(test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme..authSchemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/SignatureScheme#authScheme().()) > 0 { |
| 381 | if !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(vals[0], test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme..authSchemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/SignatureScheme#authScheme().()) { |
| 382 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s\ndoes not start with\n%s", vals[0], test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme..authSchemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/SignatureScheme#authScheme().()) |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | for _, test := range testsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/tests. { |
| 387 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(test.namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name., func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 388 | testFn(t, test) |
| 389 | }) |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | func TestNewSignerRequestMissingHeadersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/TestNewSignerRequestMissingHeaders().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 394 | failingTests := []struct { |
| 395 | name string |
| 396 | prefs []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm# |
| 397 | digestAlg DigestAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestAlgorithm# |
| 398 | headers []string |
| 399 | scheme SignatureSchemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/SignatureScheme# |
| 400 | privKey cryptoscip-go gomod github.com/golang/go/src go1.25.0 crypto/.PrivateKeyscip-go gomod github.com/golang/go/src go1.25.0 crypto/PrivateKey# |
| 401 | pubKeyId string |
| 402 | expectedAlgorithm Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm# |
| 403 | expectedSignatureAlgorithm string |
| 404 | }{ |
| 405 | { |
| 406 | name: "wants digest", |
| 407 | prefs: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512.}, |
| 408 | digestAlg: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 409 | headers: []string{"Date", "Digest"}, |
| 410 | scheme: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 411 | privKey: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey., |
| 412 | pubKeyId: "pubKeyId", |
| 413 | expectedSignatureAlgorithm: "hs2019", |
| 414 | expectedAlgorithm: RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512., |
| 415 | }, |
| 416 | } |
| 417 | for _, test := range failingTests { |
| 418 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 419 | test := test |
| 420 | s, a, err := NewSignerscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewSigner().(test.prefs, test.digestAlg, test.headers, test.scheme, 0) |
| 421 | if err != nil { |
| 422 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 423 | } |
| 424 | if a != test.expectedAlgorithm { |
| 425 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("got %s, want %s", a, test.expectedAlgorithm) |
| 426 | } |
| 427 | req, err := httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/NewRequest().(testMethodscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testMethod., testUrlscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testUrl., nil) |
| 428 | if err != nil { |
| 429 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 430 | } |
| 431 | req.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Date", testDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDate.) |
| 432 | err = s.SignRequestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signer#SignRequest.(test.privKey, test.pubKeyId, req, nil) |
| 433 | if err == nil { |
| 434 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expect error but got nil") |
| 435 | } |
| 436 | }) |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | func TestNewSignerResponseMissingHeadersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/TestNewSignerResponseMissingHeaders().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 441 | failingTests := []struct { |
| 442 | name string |
| 443 | prefs []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm# |
| 444 | digestAlg DigestAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestAlgorithm# |
| 445 | headers []string |
| 446 | scheme SignatureSchemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/SignatureScheme# |
| 447 | privKey cryptoscip-go gomod github.com/golang/go/src go1.25.0 crypto/.PrivateKeyscip-go gomod github.com/golang/go/src go1.25.0 crypto/PrivateKey# |
| 448 | pubKeyId string |
| 449 | expectedAlgorithm Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm# |
| 450 | expectErrorSigningResponse bool |
| 451 | expectedSignatureAlgorithm string |
| 452 | }{ |
| 453 | { |
| 454 | name: "want digest", |
| 455 | prefs: []Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512.}, |
| 456 | digestAlg: DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., |
| 457 | headers: []string{"Date", "Digest"}, |
| 458 | scheme: Signaturescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signature., |
| 459 | privKey: privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/privKey., |
| 460 | pubKeyId: "pubKeyId", |
| 461 | expectedSignatureAlgorithm: "hs2019", |
| 462 | expectedAlgorithm: RSA_SHA512scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA512., |
| 463 | }, |
| 464 | } |
| 465 | for _, test := range failingTests { |
| 466 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 467 | test := test |
| 468 | s, a, err := NewSignerscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewSigner().(test.prefs, test.digestAlg, test.headers, test.scheme, 0) |
| 469 | if err != nil { |
| 470 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 471 | } |
| 472 | if a != test.expectedAlgorithm { |
| 473 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("got %s, want %s", a, test.expectedAlgorithm) |
| 474 | } |
| 475 | resp := httptestscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/NewRecorder().() |
| 476 | resp.HeaderMapscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/ResponseRecorder#HeaderMap..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Date", testDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDate.) |
| 477 | resp.HeaderMapscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/ResponseRecorder#HeaderMap..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Digest", testDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDigest.) |
| 478 | err = s.SignResponsescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signer#SignResponse.(test.privKey, test.pubKeyId, resp, nil) |
| 479 | if err != nil { |
| 480 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected error, got nil") |
| 481 | } |
| 482 | }) |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | func TestNewVerifierscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/TestNewVerifier().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 487 | for _, test := range testsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/tests. { |
| 488 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(test.namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name., func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 489 | test := test |
| 490 | // Prepare |
| 491 | req, err := httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/NewRequest().(testMethodscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testMethod., testUrlscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testUrl., nil) |
| 492 | if err != nil { |
| 493 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 494 | } |
| 495 | req.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Date", testDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDate.) |
| 496 | if test.bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body. == nil { |
| 497 | req.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Digest", testDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDigest.) |
| 498 | } |
| 499 | s, _, err := NewSignerscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewSigner().(test.prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs., test.digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg., test.headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers., test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme., 0) |
| 500 | if err != nil { |
| 501 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 502 | } |
| 503 | err = s.SignRequestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signer#SignRequest.(test.privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey., test.pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId., req, test.bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body.) |
| 504 | if err != nil { |
| 505 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 506 | } |
| 507 | // Test verification |
| 508 | v, err := NewVerifierscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewVerifier().(req) |
| 509 | if err != nil { |
| 510 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 511 | } |
| 512 | if v.KeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#KeyId.() != test.pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId. { |
| 513 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("got %s, want %s", v.KeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#KeyId.(), test.pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.) |
| 514 | } |
| 515 | err = v.Verifyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#Verify.(test.pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey., test.expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.) |
| 516 | if err != nil { |
| 517 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 518 | } |
| 519 | }) |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | func TestNewResponseVerifierscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/TestNewResponseVerifier().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 524 | for _, test := range testsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/tests. { |
| 525 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(test.namescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#name., func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 526 | test := test |
| 527 | if test.expectErrorSigningResponsescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectErrorSigningResponse. { |
| 528 | return |
| 529 | } |
| 530 | // Prepare |
| 531 | resp := httptestscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/NewRecorder().() |
| 532 | resp.HeaderMapscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/ResponseRecorder#HeaderMap..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Date", testDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDate.) |
| 533 | if test.bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body. == nil { |
| 534 | resp.HeaderMapscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/ResponseRecorder#HeaderMap..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Digest", testDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testDigest.) |
| 535 | } |
| 536 | s, _, err := NewSignerscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewSigner().(test.prefsscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#prefs., test.digestAlgscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#digestAlg., test.headersscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#headers., test.schemescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#scheme., 0) |
| 537 | if err != nil { |
| 538 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 539 | } |
| 540 | err = s.SignResponsescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signer#SignResponse.(test.privKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#privKey., test.pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId., resp, test.bodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#body.) |
| 541 | if err != nil { |
| 542 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 543 | } |
| 544 | // Test verification |
| 545 | v, err := NewResponseVerifierscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewResponseVerifier().(resp.Resultscip-go gomod github.com/golang/go/src go1.25.0 `net/http/httptest`/ResponseRecorder#Result().()) |
| 546 | if err != nil { |
| 547 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 548 | } |
| 549 | if v.KeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#KeyId.() != test.pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId. { |
| 550 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("got %s, want %s", v.KeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#KeyId.(), test.pubKeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKeyId.) |
| 551 | } |
| 552 | err = v.Verifyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#Verify.(test.pubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#pubKey., test.expectedAlgorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/httpsigTest#expectedAlgorithm.) |
| 553 | if err != nil { |
| 554 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s", err) |
| 555 | } |
| 556 | }) |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | // Test_Signing_HTTP_Messages_AppendixC implement tests from Appendix C |
| 561 | // in the http signatures specification: |
| 562 | // https://tools.ietf.org/html/draft-cavage-http-signatures-10#appendix-C |
| 563 | func Test_Signing_HTTP_Messages_AppendixCscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Test_Signing_HTTP_Messages_AppendixC().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 564 | specTests := []struct { |
| 565 | name string |
| 566 | headers []string |
| 567 | expectedSignature string |
| 568 | }{ |
| 569 | { |
| 570 | name: "C.1. Default Test", |
| 571 | headers: []string{}, |
| 572 | // NOTE: In the Appendix C tests, the following is NOT included: |
| 573 | // `headers="date"` |
| 574 | // But httpsig will ALWAYS explicitly list the headers used in its |
| 575 | // signature. Hence, I have introduced it here. |
| 576 | // |
| 577 | // NOTE: In verification, if there are no headers listed, the |
| 578 | // default headers (date) are indeed used as required by the |
| 579 | // specification. |
| 580 | expectedSignature: `Authorization: Signature keyId="Test",algorithm="hs2019",headers="date",signature="SjWJWbWN7i0wzBvtPl8rbASWz5xQW6mcJmn+ibttBqtifLN7Sazz6m79cNfwwb8DMJ5cou1s7uEGKKCs+FLEEaDV5lp7q25WqS+lavg7T8hc0GppauB6hbgEKTwblDHYGEtbGmtdHgVCk9SuS13F0hZ8FD0k/5OxEPXe5WozsbM="`, |
| 581 | }, |
| 582 | { |
| 583 | name: "C.2. Basic Test", |
| 584 | headers: []string{"(request-target)", "host", "date"}, |
| 585 | expectedSignature: `Authorization: Signature keyId="Test",algorithm="hs2019",headers="(request-target) host date",signature="qdx+H7PHHDZgy4y/Ahn9Tny9V3GP6YgBPyUXMmoxWtLbHpUnXS2mg2+SbrQDMCJypxBLSPQR2aAjn7ndmw2iicw3HMbe8VfEdKFYRqzic+efkb3nndiv/x1xSHDJWeSWkx3ButlYSuBskLu6kd9Fswtemr3lgdDEmn04swr2Os0="`, |
| 586 | }, |
| 587 | { |
| 588 | name: "C.3. All Headers Test", |
| 589 | headers: []string{"(request-target)", "host", "date", "content-type", "digest", "content-length"}, |
| 590 | expectedSignature: `Authorization: Signature keyId="Test",algorithm="hs2019",headers="(request-target) host date content-type digest content-length",signature="vSdrb+dS3EceC9bcwHSo4MlyKS59iFIrhgYkz8+oVLEEzmYZZvRs8rgOp+63LEM3v+MFHB32NfpB2bEKBIvB1q52LaEUHFv120V01IL+TAD48XaERZFukWgHoBTLMhYS2Gb51gWxpeIq8knRmPnYePbF5MOkR0Zkly4zKH7s1dE="`, |
| 591 | }, |
| 592 | } |
| 593 | |
| 594 | for _, test := range specTests { |
| 595 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 596 | test := test |
| 597 | r, err := httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/NewRequest().("POST", "http://example.com/foo?param=value&pet=dog", bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewBuffer().([]byte(testSpecBodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecBody.))) |
| 598 | if err != nil { |
| 599 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error creating request: %s", err) |
| 600 | } |
| 601 | |
| 602 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Date"] = []string{testSpecDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecDate.} |
| 603 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Host"] = []string{r.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Hostscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Host.} |
| 604 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Content-Length"] = []string{strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(len(testSpecBodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecBody.))} |
| 605 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Content-Type"] = []string{"application/json"} |
| 606 | setDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/setDigest().(r) |
| 607 | |
| 608 | s, _, err := NewSignerscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewSigner().([]Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{RSA_SHA256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA256.}, DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., test.headers, Authorizationscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Authorization., 0) |
| 609 | if err != nil { |
| 610 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error creating signer: %s", err) |
| 611 | } |
| 612 | |
| 613 | if err := s.SignRequestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signer#SignRequest.(testSpecRSAPrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecRSAPrivateKey., "Test", r, nil); err != nil { |
| 614 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error signing request: %s", err) |
| 615 | } |
| 616 | |
| 617 | expectedAuth := test.expectedSignature |
| 618 | gotAuth := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Authorization: %s", r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Authorization"][0]) |
| 619 | if gotAuth != expectedAuth { |
| 620 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Signature string mismatch\nGot: %s\nWant: %s", gotAuth, expectedAuth) |
| 621 | } |
| 622 | }) |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | func TestSigningEd25519scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/TestSigningEd25519().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 627 | specTests := []struct { |
| 628 | name string |
| 629 | headers []string |
| 630 | expectedSignature string |
| 631 | }{ |
| 632 | { |
| 633 | name: "Default Test", |
| 634 | headers: []string{}, |
| 635 | // NOTE: In the Appendix C tests, the following is NOT included: |
| 636 | // `headers="date"` |
| 637 | // But httpsig will ALWAYS explicitly list the headers used in its |
| 638 | // signature. Hence, I have introduced it here. |
| 639 | // |
| 640 | // NOTE: In verification, if there are no headers listed, the |
| 641 | // default headers (date) are indeed used as required by the |
| 642 | // specification. |
| 643 | expectedSignature: `Authorization: Signature keyId="Test",algorithm="hs2019",headers="date",signature="6G9bNnUfph4pnl3j8l4UTcSPJVg6r4tM73eWFAn+w4IdIi8yzzZs65QlgM31lAuVCRKlqMzME9VGgMt16nU1AQ=="`, |
| 644 | }, |
| 645 | { |
| 646 | name: "Basic Test", |
| 647 | headers: []string{"(request-target)", "host", "date"}, |
| 648 | expectedSignature: `Authorization: Signature keyId="Test",algorithm="hs2019",headers="(request-target) host date",signature="upsoNpw5oJTD3lTIQHEnDGWTaKmlT7o2c9Lz3kqy2UTwOEpEop3Sd7F/K2bYD2lQ4AH1HRyvC4/9AcKgNBg1AA=="`, |
| 649 | }, |
| 650 | { |
| 651 | name: "All Headers Test", |
| 652 | headers: []string{"(request-target)", "host", "date", "content-type", "digest", "content-length"}, |
| 653 | expectedSignature: `Authorization: Signature keyId="Test",algorithm="hs2019",headers="(request-target) host date content-type digest content-length",signature="UkxhZl0W5/xcuCIP5xOPv4V6rX0TmaV2lmrYYGWauKhdFHihpW80tCqTNFDhyD+nYeGNCRSFRHmDS0bGm0PVAg=="`, |
| 654 | }, |
| 655 | } |
| 656 | |
| 657 | for _, test := range specTests { |
| 658 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 659 | test := test |
| 660 | r, err := httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/NewRequest().("POST", "http://example.com/foo?param=value&pet=dog", bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewBuffer().([]byte(testSpecBodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecBody.))) |
| 661 | if err != nil { |
| 662 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error creating request: %s", err) |
| 663 | } |
| 664 | |
| 665 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Date"] = []string{testSpecDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecDate.} |
| 666 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Host"] = []string{r.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Hostscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Host.} |
| 667 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Content-Length"] = []string{strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(len(testSpecBodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecBody.))} |
| 668 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Content-Type"] = []string{"application/json"} |
| 669 | setDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/setDigest().(r) |
| 670 | |
| 671 | s, _, err := NewSignerscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewSigner().([]Algorithmscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Algorithm#{ED25519scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ED25519.}, DigestSha256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/DigestSha256., test.headers, Authorizationscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Authorization., 0) |
| 672 | if err != nil { |
| 673 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error creating signer: %s", err) |
| 674 | } |
| 675 | |
| 676 | if err := s.SignRequestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Signer#SignRequest.(testEd25519PrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testEd25519PrivateKey., "Test", r, nil); err != nil { |
| 677 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error signing request: %s", err) |
| 678 | } |
| 679 | |
| 680 | expectedAuth := test.expectedSignature |
| 681 | gotAuth := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Authorization: %s", r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Authorization"][0]) |
| 682 | if gotAuth != expectedAuth { |
| 683 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Signature string mismatch\nGot: %s\nWant: %s", gotAuth, expectedAuth) |
| 684 | } |
| 685 | }) |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | // Test_Verifying_HTTP_Messages_AppendixC implement tests from Appendix C |
| 690 | // in the http signatures specification: |
| 691 | // https://tools.ietf.org/html/draft-cavage-http-signatures-10#appendix-C |
| 692 | func Test_Verifying_HTTP_Messages_AppendixCscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Test_Verifying_HTTP_Messages_AppendixC().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 693 | specTests := []struct { |
| 694 | name string |
| 695 | headers []string |
| 696 | signature string |
| 697 | }{ |
| 698 | { |
| 699 | name: "C.1. Default Test", |
| 700 | headers: []string{}, |
| 701 | signature: `Signature keyId="Test",algorithm="rsa-sha256",signature="SjWJWbWN7i0wzBvtPl8rbASWz5xQW6mcJmn+ibttBqtifLN7Sazz6m79cNfwwb8DMJ5cou1s7uEGKKCs+FLEEaDV5lp7q25WqS+lavg7T8hc0GppauB6hbgEKTwblDHYGEtbGmtdHgVCk9SuS13F0hZ8FD0k/5OxEPXe5WozsbM="`, |
| 702 | }, |
| 703 | { |
| 704 | name: "C.2. Basic Test", |
| 705 | headers: []string{"(request-target)", "host", "date"}, |
| 706 | signature: `Signature keyId="Test",algorithm="rsa-sha256",headers="(request-target) host date",signature="qdx+H7PHHDZgy4y/Ahn9Tny9V3GP6YgBPyUXMmoxWtLbHpUnXS2mg2+SbrQDMCJypxBLSPQR2aAjn7ndmw2iicw3HMbe8VfEdKFYRqzic+efkb3nndiv/x1xSHDJWeSWkx3ButlYSuBskLu6kd9Fswtemr3lgdDEmn04swr2Os0="`, |
| 707 | }, |
| 708 | { |
| 709 | name: "C.3. All Headers Test", |
| 710 | headers: []string{"(request-target)", "host", "date", "content-type", "digest", "content-length"}, |
| 711 | signature: `Signature keyId="Test",algorithm="rsa-sha256",headers="(request-target) host date content-type digest content-length",signature="vSdrb+dS3EceC9bcwHSo4MlyKS59iFIrhgYkz8+oVLEEzmYZZvRs8rgOp+63LEM3v+MFHB32NfpB2bEKBIvB1q52LaEUHFv120V01IL+TAD48XaERZFukWgHoBTLMhYS2Gb51gWxpeIq8knRmPnYePbF5MOkR0Zkly4zKH7s1dE="`, |
| 712 | }, |
| 713 | } |
| 714 | |
| 715 | for _, test := range specTests { |
| 716 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 717 | test := test |
| 718 | r, err := httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/NewRequest().("POST", "http://example.com/foo?param=value&pet=dog", bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewBuffer().([]byte(testSpecBodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecBody.))) |
| 719 | if err != nil { |
| 720 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error creating request: %s", err) |
| 721 | } |
| 722 | |
| 723 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Date"] = []string{testSpecDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecDate.} |
| 724 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Host"] = []string{r.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Hostscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Host.} |
| 725 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Content-Length"] = []string{strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(len(testSpecBodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecBody.))} |
| 726 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Content-Type"] = []string{"application/json"} |
| 727 | setDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/setDigest().(r) |
| 728 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Authorization"] = []string{test.signature} |
| 729 | |
| 730 | v, err := NewVerifierscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewVerifier().(r) |
| 731 | if err != nil { |
| 732 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error creating verifier: %s", err) |
| 733 | } |
| 734 | |
| 735 | if "Test" != v.KeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#KeyId.() { |
| 736 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("KeyId mismatch\nGot: %s\nWant: Test", v.KeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#KeyId.()) |
| 737 | } |
| 738 | if err := v.Verifyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#Verify.(testSpecRSAPublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecRSAPublicKey., RSA_SHA256scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/RSA_SHA256.); err != nil { |
| 739 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Verification failure: %s", err) |
| 740 | } |
| 741 | }) |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | func TestVerifyingEd25519scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/TestVerifyingEd25519().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 746 | specTests := []struct { |
| 747 | name string |
| 748 | headers []string |
| 749 | signature string |
| 750 | }{ |
| 751 | { |
| 752 | name: "Default Test", |
| 753 | headers: []string{}, |
| 754 | signature: `Signature keyId="Test",algorithm="hs2019",headers="date",signature="6G9bNnUfph4pnl3j8l4UTcSPJVg6r4tM73eWFAn+w4IdIi8yzzZs65QlgM31lAuVCRKlqMzME9VGgMt16nU1AQ=="`, |
| 755 | }, |
| 756 | { |
| 757 | name: "Basic Test", |
| 758 | headers: []string{"(request-target)", "host", "date"}, |
| 759 | signature: `Signature keyId="Test",algorithm="hs2019",headers="(request-target) host date",signature="upsoNpw5oJTD3lTIQHEnDGWTaKmlT7o2c9Lz3kqy2UTwOEpEop3Sd7F/K2bYD2lQ4AH1HRyvC4/9AcKgNBg1AA=="`, |
| 760 | }, |
| 761 | { |
| 762 | name: "All Headers Test", |
| 763 | headers: []string{"(request-target)", "host", "date", "content-type", "digest", "content-length"}, |
| 764 | signature: `Signature keyId="Test",algorithm="hs2019",headers="(request-target) host date content-type digest content-length",signature="UkxhZl0W5/xcuCIP5xOPv4V6rX0TmaV2lmrYYGWauKhdFHihpW80tCqTNFDhyD+nYeGNCRSFRHmDS0bGm0PVAg=="`, |
| 765 | }, |
| 766 | } |
| 767 | |
| 768 | for _, test := range specTests { |
| 769 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 770 | test := test |
| 771 | r, err := httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/NewRequest().("POST", "http://example.com/foo?param=value&pet=dog", bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewBuffer().([]byte(testSpecBodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecBody.))) |
| 772 | if err != nil { |
| 773 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error creating request: %s", err) |
| 774 | } |
| 775 | |
| 776 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Date"] = []string{testSpecDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecDate.} |
| 777 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Host"] = []string{r.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Hostscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Host.} |
| 778 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Content-Length"] = []string{strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(len(testSpecBodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecBody.))} |
| 779 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Content-Type"] = []string{"application/json"} |
| 780 | setDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/setDigest().(r) |
| 781 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Authorization"] = []string{test.signature} |
| 782 | |
| 783 | v, err := NewVerifierscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/NewVerifier().(r) |
| 784 | if err != nil { |
| 785 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error creating verifier: %s", err) |
| 786 | } |
| 787 | |
| 788 | if "Test" != v.KeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#KeyId.() { |
| 789 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("KeyId mismatch\nGot: %s\nWant: Test", v.KeyIdscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#KeyId.()) |
| 790 | } |
| 791 | if err := v.Verifyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/Verifier#Verify.(testEd25519PublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testEd25519PublicKey., ED25519scip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ED25519.); err != nil { |
| 792 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Verification failure: %s", err) |
| 793 | } |
| 794 | }) |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | func loadPrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/loadPrivateKey().(keyData []byte) (*rsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#, error) { |
| 799 | pem, _ := pemscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Decode().(keyData) |
| 800 | if pem.Typescip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Block#Type. != "RSA PRIVATE KEY" { |
| 801 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("RSA private key is of the wrong type: %s", pem.Typescip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Block#Type.) |
| 802 | } |
| 803 | |
| 804 | return x509scip-go gomod github.com/golang/go/src go1.25.0 `crypto/x509`/.ParsePKCS1PrivateKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/x509`/ParsePKCS1PrivateKey().(pem.Bytesscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Block#Bytes.) |
| 805 | } |
| 806 | |
| 807 | // taken from https://blainsmith.com/articles/signing-jwts-with-gos-crypto-ed25519/ |
| 808 | func loadEd25519PrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/loadEd25519PrivateKey().(keyData []byte) (ed25519scip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/.PrivateKeyscip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/PrivateKey#, error) { |
| 809 | var block *pemscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/.Blockscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Block# |
| 810 | block, _ = pemscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Decode().(keyData) |
| 811 | |
| 812 | var asn1PrivKey ed25519PrivKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PrivKey# |
| 813 | asn1scip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/Unmarshal().(block.Bytesscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Block#Bytes., &asn1PrivKey) |
| 814 | |
| 815 | // [2:] is skipping the byte for TAG and the byte for LEN |
| 816 | // see also https://tools.ietf.org/html/draft-ietf-curdle-pkix-10#section-10.3 |
| 817 | return ed25519scip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/.NewKeyFromSeedscip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/NewKeyFromSeed().(asn1PrivKey.PrivateKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PrivKey#PrivateKey.[2:]), nil |
| 818 | } |
| 819 | |
| 820 | func loadPublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/loadPublicKey().(keyData []byte) (*rsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/.PublicKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PublicKey#, error) { |
| 821 | pem, _ := pemscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Decode().(keyData) |
| 822 | if pem.Typescip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Block#Type. != "PUBLIC KEY" { |
| 823 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("public key is of the wrong type: %s", pem.Typescip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Block#Type.) |
| 824 | } |
| 825 | |
| 826 | key, err := x509scip-go gomod github.com/golang/go/src go1.25.0 `crypto/x509`/.ParsePKIXPublicKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/x509`/ParsePKIXPublicKey().(pem.Bytesscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Block#Bytes.) |
| 827 | if err != nil { |
| 828 | return nil, err |
| 829 | } |
| 830 | |
| 831 | return key.(*rsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/.PublicKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PublicKey#), nil |
| 832 | } |
| 833 | |
| 834 | // taken from https://blainsmith.com/articles/signing-jwts-with-gos-crypto-ed25519/ |
| 835 | func loadEd25519PublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/loadEd25519PublicKey().(keyData []byte) (ed25519scip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/.PublicKeyscip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/PublicKey#, error) { |
| 836 | var block *pemscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/.Blockscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Block# |
| 837 | block, _ = pemscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Decode().(keyData) |
| 838 | |
| 839 | var asn1PubKey ed25519PubKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PubKey# |
| 840 | asn1scip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/Unmarshal().(block.Bytesscip-go gomod github.com/golang/go/src go1.25.0 `encoding/pem`/Block#Bytes., &asn1PubKey) |
| 841 | |
| 842 | return ed25519scip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/.PublicKeyscip-go gomod golang.org/x/crypto v0.49.0 `golang.org/x/crypto/ed25519`/PublicKey#(asn1PubKey.PublicKeyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/ed25519PubKey#PublicKey..Bytesscip-go gomod github.com/golang/go/src go1.25.0 `encoding/asn1`/BitString#Bytes.), nil |
| 843 | } |
| 844 | |
| 845 | func setDigestscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/setDigest().(r *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#) ([]byte, error) { |
| 846 | var bodyBytes []byte |
| 847 | if _, ok := r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Digest"]; !ok { |
| 848 | body := "" |
| 849 | if r.Bodyscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Body. != nil { |
| 850 | var err error |
| 851 | bodyBytes, err = ioutilscip-go gomod github.com/golang/go/src go1.25.0 `io/ioutil`/.ReadAllscip-go gomod github.com/golang/go/src go1.25.0 `io/ioutil`/ReadAll().(r.Bodyscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Body.) |
| 852 | if err != nil { |
| 853 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("error reading body. %v", err) |
| 854 | } |
| 855 | |
| 856 | // And now set a new body, which will simulate the same data we read: |
| 857 | r.Bodyscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Body. = ioutilscip-go gomod github.com/golang/go/src go1.25.0 `io/ioutil`/.NopCloserscip-go gomod github.com/golang/go/src go1.25.0 `io/ioutil`/NopCloser().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewBuffer().(bodyBytes)) |
| 858 | body = string(bodyBytes) |
| 859 | } |
| 860 | |
| 861 | d := sha256scip-go gomod github.com/golang/go/src go1.25.0 `crypto/sha256`/.Sum256scip-go gomod github.com/golang/go/src go1.25.0 `crypto/sha256`/Sum256().([]byte(body)) |
| 862 | r.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header.["Digest"] = []string{fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("SHA-256=%s", base64scip-go gomod github.com/golang/go/src go1.25.0 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.25.0 `encoding/base64`/StdEncoding..EncodeToStringscip-go gomod github.com/golang/go/src go1.25.0 `encoding/base64`/Encoding#EncodeToString().(d[:]))} |
| 863 | } |
| 864 | |
| 865 | return bodyBytes, nil |
| 866 | } |
| 867 | |
| 868 | const testSpecBodyscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecBody. = `{"hello": "world"}` |
| 869 | |
| 870 | const testSpecDatescip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecDate. = `Sun, 05 Jan 2014 21:31:40 GMT` |
| 871 | |
| 872 | const testSpecPrivateKeyPEMscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecPrivateKeyPEM. = `-----BEGIN RSA PRIVATE KEY----- |
| 873 | MIICXgIBAAKBgQDCFENGw33yGihy92pDjZQhl0C36rPJj+CvfSC8+q28hxA161QF |
| 874 | NUd13wuCTUcq0Qd2qsBe/2hFyc2DCJJg0h1L78+6Z4UMR7EOcpfdUE9Hf3m/hs+F |
| 875 | UR45uBJeDK1HSFHD8bHKD6kv8FPGfJTotc+2xjJwoYi+1hqp1fIekaxsyQIDAQAB |
| 876 | AoGBAJR8ZkCUvx5kzv+utdl7T5MnordT1TvoXXJGXK7ZZ+UuvMNUCdN2QPc4sBiA |
| 877 | QWvLw1cSKt5DsKZ8UETpYPy8pPYnnDEz2dDYiaew9+xEpubyeW2oH4Zx71wqBtOK |
| 878 | kqwrXa/pzdpiucRRjk6vE6YY7EBBs/g7uanVpGibOVAEsqH1AkEA7DkjVH28WDUg |
| 879 | f1nqvfn2Kj6CT7nIcE3jGJsZZ7zlZmBmHFDONMLUrXR/Zm3pR5m0tCmBqa5RK95u |
| 880 | 412jt1dPIwJBANJT3v8pnkth48bQo/fKel6uEYyboRtA5/uHuHkZ6FQF7OUkGogc |
| 881 | mSJluOdc5t6hI1VsLn0QZEjQZMEOWr+wKSMCQQCC4kXJEsHAve77oP6HtG/IiEn7 |
| 882 | kpyUXRNvFsDE0czpJJBvL/aRFUJxuRK91jhjC68sA7NsKMGg5OXb5I5Jj36xAkEA |
| 883 | gIT7aFOYBFwGgQAQkWNKLvySgKbAZRTeLBacpHMuQdl1DfdntvAyqpAZ0lY0RKmW |
| 884 | G6aFKaqQfOXKCyWoUiVknQJAXrlgySFci/2ueKlIE1QqIiLSZ8V8OlpFLRnb1pzI |
| 885 | 7U1yQXnTAEFYM560yJlzUpOb1V4cScGd365tiSMvxLOvTA== |
| 886 | -----END RSA PRIVATE KEY-----` |
| 887 | |
| 888 | const testSpecPublicKeyPEMscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testSpecPublicKeyPEM. = `-----BEGIN PUBLIC KEY----- |
| 889 | MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCFENGw33yGihy92pDjZQhl0C3 |
| 890 | 6rPJj+CvfSC8+q28hxA161QFNUd13wuCTUcq0Qd2qsBe/2hFyc2DCJJg0h1L78+6 |
| 891 | Z4UMR7EOcpfdUE9Hf3m/hs+FUR45uBJeDK1HSFHD8bHKD6kv8FPGfJTotc+2xjJw |
| 892 | oYi+1hqp1fIekaxsyQIDAQAB |
| 893 | -----END PUBLIC KEY-----` |
| 894 | |
| 895 | const testEd25519PrivateKeyPEMscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testEd25519PrivateKeyPEM. = `-----BEGIN PRIVATE KEY----- |
| 896 | MC4CAQAwBQYDK2VwBCIEIAP+PK4NtdzCe04sbtwBvf9IShlky298SMMBqkCCToHn |
| 897 | -----END PRIVATE KEY-----` |
| 898 | |
| 899 | const testEd25519PublicKeyPEMscip-go gomod github.com/42wim/httpsig . `github.com/42wim/httpsig`/testEd25519PublicKeyPEM. = `-----BEGIN PUBLIC KEY----- |
| 900 | MCowBQYDK2VwAyEAhyP+7zpNCsr7/ipGJjK0zVszTEQ5tooyX3VLAnBSc1c= |
| 901 | -----END PUBLIC KEY-----` |