{"modulePath":"github.com/42wim/httpsig","version":"v1.3.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpsig\n\nImplements HTTP request and response signing and verification. Supports the major MAC and asymmetric key signature algorithms. It has several safety restrictions: One, none of the widely known non-cryptographically safe algorithms are permitted; Two, the RSA SHA256 algorithms must be available in the binary (and it should, barring export restrictions); Finally, the library assumes either the 'Authorizationn' or 'Signature' headers are to be set (but not both).\n\n## Constants\n\n```go\nconst (\n\n\t// RequestTarget specifies to include the http request method and\n\t// entire URI in the signature. Pass it as a header to NewSigner.\n\tRequestTarget = \"(request-target)\"\n)\n```\n\n## Functions\n\n```go\nfunc IsSupportedDigestAlgorithm(algo string) bool\n```\nIsSupportedDigestAlgorithm returns true if hte string is supported by this library, is not a hash known to be weak, and is supported by the hardware.\n\n```go\nfunc IsSupportedHttpSigAlgorithm(algo string) bool\n```\nIsSupportedHttpSigAlgorithm returns true if the string is supported by this library, is not a hash known to be weak, and is supported by the hardware.\n\n```go\nfunc NewSSHSigner(s ssh.Signer, dAlgo DigestAlgorithm, headers []string, scheme SignatureScheme, expiresIn int64) (SSHSigner, Algorithm, error)\n```\nNewwSSHSigner creates a new Signer using the specified ssh.Signer At the moment only ed25519, rsa and ecdsa-sha2-nistp256 ssh keys (including their OpenSSH certificate variants) are supported. The headers specified will be included into the HTTP signatures.\n\nThe Digest will also be calculated on a request's body using the provided digest algorithm, if \"Digest\" is one of the headers listed.\n\nThe provided scheme determines which header is populated with the HTTP Signature.\n\n```go\nfunc NewSigner(prefs []Algorithm, dAlgo DigestAlgorithm, headers []string, scheme SignatureScheme, expiresIn int64) (Signer, Algorithm, error)\n```\nNewSigner creates a new Signer with the provided algorithm preferences to make HTTP signatures. Only the first available algorithm will be used, which is returned by this function along with the Signer. If none of the preferred algorithms were available, then the default algorithm is used. The headers specified will be included into the HTTP signatures.\n\nThe Digest will also be calculated on a request's body using the provided digest algorithm, if \"Digest\" is one of the headers listed.\n\nThe provided scheme determines which header is populated with the HTTP Signature.\n\nAn error is returned if an unknown or a known cryptographically insecure Algorithm is provided.\n\n## Types\n\n```go\ntype Algorithm string\n```\nAlgorithm specifies a cryptography secure algorithm for signing HTTP requests and responses.\n\n```go\nconst (\n\t// MAC-based algoirthms.\n\tHMAC_SHA224      Algorithm = hmacPrefix + \"-\" + sha224String\n\tHMAC_SHA256      Algorithm = hmacPrefix + \"-\" + sha256String\n\tHMAC_SHA384      Algorithm = hmacPrefix + \"-\" + sha384String\n\tHMAC_SHA512      Algorithm = hmacPrefix + \"-\" + sha512String\n\tHMAC_SHA3_224    Algorithm = hmacPrefix + \"-\" + sha3_224String\n\tHMAC_SHA3_256    Algorithm = hmacPrefix + \"-\" + sha3_256String\n\tHMAC_SHA3_384    Algorithm = hmacPrefix + \"-\" + sha3_384String\n\tHMAC_SHA3_512    Algorithm = hmacPrefix + \"-\" + sha3_512String\n\tHMAC_SHA512_224  Algorithm = hmacPrefix + \"-\" + sha512_224String\n\tHMAC_SHA512_256  Algorithm = hmacPrefix + \"-\" + sha512_256String\n\tHMAC_BLAKE2S_256 Algorithm = hmacPrefix + \"-\" + blake2s_256String\n\tHMAC_BLAKE2B_256 Algorithm = hmacPrefix + \"-\" + blake2b_256String\n\tHMAC_BLAKE2B_384 Algorithm = hmacPrefix + \"-\" + blake2b_384String\n\tHMAC_BLAKE2B_512 Algorithm = hmacPrefix + \"-\" + blake2b_512String\n\tBLAKE2S_256      Algorithm = blake2s_256String\n\tBLAKE2B_256      Algorithm = blake2b_256String\n\tBLAKE2B_384      Algorithm = blake2b_384String\n\tBLAKE2B_512      Algorithm = blake2b_512String\n\t// RSA-based algorithms.\n\tRSA_SHA224 Algorithm = rsaPrefix + \"-\" + sha224String\n\t// RSA_SHA256 is the default algorithm.\n\tRSA_SHA256 Algorithm = rsaPrefix + \"-\" + sha256String\n\tRSA_SHA384 Algorithm = rsaPrefix + \"-\" + sha384String\n\tRSA_SHA512 Algorithm = rsaPrefix + \"-\" + sha512String\n\t// ECDSA algorithms\n\tECDSA_SHA224 Algorithm = ecdsaPrefix + \"-\" + sha224String\n\tECDSA_SHA256 Algorithm = ecdsaPrefix + \"-\" + sha256String\n\tECDSA_SHA384 Algorithm = ecdsaPrefix + \"-\" + sha384String\n\tECDSA_SHA512 Algorithm = ecdsaPrefix + \"-\" + sha512String\n\t// ED25519 algorithms\n\t// can only be SHA512\n\tED25519 Algorithm = ed25519Prefix\n)\n```\n\n```go\ntype DigestAlgorithm string\n```\n\n```go\nconst (\n\tDigestSha256 DigestAlgorithm = \"SHA-256\"\n\tDigestSha512                 = \"SHA-512\"\n)\n```\n\n```go\ntype ECDSASignature struct {\n\tR, S *big.Int\n}\n```\n\n```go\ntype SSHSigner interface {\n\t// SignRequest signs the request using ssh.Signer.\n\t// The public key id is used by the HTTP server to identify which key to use\n\t// to verify the signature.\n\t//\n\t// A Digest (RFC 3230) will be added to the request. The body provided\n\t// must match the body used in the request, and is allowed to be nil.\n\t// The Digest ensures the request body is not tampered with in flight,\n\t// and if the signer is created to also sign the \"Digest\" header, the\n\t// HTTP Signature will then ensure both the Digest and body are not both\n\t// modified to maliciously represent different content.\n\tSignRequest(pubKeyId string, r *http.Request, body []byte) error\n\t// SignResponse signs the response using ssh.Signer. The public key\n\t// id is used by the HTTP client to identify which key to use to verify\n\t// the signature.\n\t//\n\t// A Digest (RFC 3230) will be added to the response. The body provided\n\t// must match the body written in the response, and is allowed to be\n\t// nil. The Digest ensures the response body is not tampered with in\n\t// flight, and if the signer is created to also sign the \"Digest\"\n\t// header, the HTTP Signature will then ensure both the Digest and body\n\t// are not both modified to maliciously represent different content.\n\tSignResponse(pubKeyId string, r http.ResponseWriter, body []byte) error\n}\n```\nSigners will sign HTTP requests or responses based on the algorithms and headers selected at creation time.\n\nSigners are not safe to use between multiple goroutines.\n\nNote that signatures do set the deprecated 'algorithm' parameter for backwards compatibility.\n\n```go\ntype Sha256Signer struct {\n\tssh.Signer\n}\n```\nA struct to wrap an SSH Signer with one that will switch to SHA256 Signatures. Replaces the call to Sign() with a call to SignWithOpts using HashFunc() algorithm.\n\n```go\nfunc (s Sha256Signer) HashFunc() crypto.Hash\n```\n\n```go\nfunc (s Sha256Signer) Sign(rand io.Reader, data []byte) (*ssh.Signature, error)\n```\n\n```go\ntype SignatureScheme string\n```\nHTTP Signatures can be applied to different HTTP headers, depending on the expected application behavior.\n\n```go\nconst (\n\t// Signature will place the HTTP Signature into the 'Signature' HTTP\n\t// header.\n\tSignature SignatureScheme = \"Signature\"\n\t// Authorization will place the HTTP Signature into the 'Authorization'\n\t// HTTP header.\n\tAuthorization SignatureScheme = \"Authorization\"\n)\n```\n\n```go\ntype Signer interface {\n\t// SignRequest signs the request using a private key. The public key id\n\t// is used by the HTTP server to identify which key to use to verify the\n\t// signature.\n\t//\n\t// If the Signer was created using a MAC based algorithm, then the key\n\t// is expected to be of type []byte. If the Signer was created using an\n\t// RSA based algorithm, then the private key is expected to be of type\n\t// *rsa.PrivateKey.\n\t//\n\t// A Digest (RFC 3230) will be added to the request. The body provided\n\t// must match the body used in the request, and is allowed to be nil.\n\t// The Digest ensures the request body is not tampered with in flight,\n\t// and if the signer is created to also sign the \"Digest\" header, the\n\t// HTTP Signature will then ensure both the Digest and body are not both\n\t// modified to maliciously represent different content.\n\tSignRequest(pKey crypto.PrivateKey, pubKeyId string, r *http.Request, body []byte) error\n\t// SignResponse signs the response using a private key. The public key\n\t// id is used by the HTTP client to identify which key to use to verify\n\t// the signature.\n\t//\n\t// If the Signer was created using a MAC based algorithm, then the key\n\t// is expected to be of type []byte. If the Signer was created using an\n\t// RSA based algorithm, then the private key is expected to be of type\n\t// *rsa.PrivateKey.\n\t//\n\t// A Digest (RFC 3230) will be added to the response. The body provided\n\t// must match the body written in the response, and is allowed to be\n\t// nil. The Digest ensures the response body is not tampered with in\n\t// flight, and if the signer is created to also sign the \"Digest\"\n\t// header, the HTTP Signature will then ensure both the Digest and body\n\t// are not both modified to maliciously represent different content.\n\tSignResponse(pKey crypto.PrivateKey, pubKeyId string, r http.ResponseWriter, body []byte) error\n}\n```\nSigners will sign HTTP requests or responses based on the algorithms and headers selected at creation time.\n\nSigners are not safe to use between multiple goroutines.\n\nNote that signatures do set the deprecated 'algorithm' parameter for backwards compatibility.\n\n```go\ntype Verifier interface {\n\t// KeyId gets the public key id that the signature is signed with.\n\t//\n\t// Note that the application is expected to determine the algorithm\n\t// used based on metadata or out-of-band information for this key id.\n\tKeyId() string\n\t// Verify accepts the public key specified by KeyId and returns an\n\t// error if verification fails or if the signature is malformed. The\n\t// algorithm must be the one used to create the signature in order to\n\t// pass verification. The algorithm is determined based on metadata or\n\t// out-of-band information for the key id.\n\t//\n\t// If the signature was created using a MAC based algorithm, then the\n\t// key is expected to be of type []byte. If the signature was created\n\t// using an RSA based algorithm, then the public key is expected to be\n\t// of type *rsa.PublicKey.\n\tVerify(pKey crypto.PublicKey, algo Algorithm) error\n}\n```\nVerifier verifies HTTP Signatures.\n\nIt will determine which of the supported headers has the parameters that define the signature.\n\nVerifiers are not safe to use between multiple goroutines.\n\nNote that verification ignores the deprecated 'algorithm' parameter.\n\n```go\nfunc NewResponseVerifier(r *http.Response) (Verifier, error)\n```\nNewResponseVerifier verifies the given response. It returns errors under the same conditions as NewVerifier.\n\n```go\nfunc NewVerifier(r *http.Request) (Verifier, error)\n```\nNewVerifier verifies the given request. It returns an error if the HTTP Signature parameters are not present in any headers, are present in more than one header, are malformed, or are missing required parameters. It ignores unknown HTTP Signature parameters.\n\n","path":"github.com/42wim/httpsig","name":"httpsig","synopsis":"Implements HTTP request and response signing and verification.","isRedistributable":true}
