@@ -107,7 +107,14 @@ type Signer interface {
107107 // is expected to be of type []byte. If the Signer was created using an
108108 // RSA based algorithm, then the private key is expected to be of type
109109 // *rsa.PrivateKey.
110- SignRequest (pKey crypto.PrivateKey , pubKeyId string , r * http.Request ) error
110+ //
111+ // A Digest (RFC 3230) will be added to the request. The body provided
112+ // must match the body used in the request, and is allowed to be nil.
113+ // The Digest ensures the request body is not tampered with in flight,
114+ // and if the signer is created to also sign the "Digest" header, the
115+ // HTTP Signature will then ensure both the Digest and body are not both
116+ // modified to maliciously represent different content.
117+ SignRequest (pKey crypto.PrivateKey , pubKeyId string , r * http.Request , body []byte ) error
111118 // SignResponse signs the response using a private key. The public key
112119 // id is used by the HTTP client to identify which key to use to verify
113120 // the signature.
@@ -116,7 +123,14 @@ type Signer interface {
116123 // is expected to be of type []byte. If the Signer was created using an
117124 // RSA based algorithm, then the private key is expected to be of type
118125 // *rsa.PrivateKey.
119- SignResponse (pKey crypto.PrivateKey , pubKeyId string , r http.ResponseWriter ) error
126+ //
127+ // A Digest (RFC 3230) will be added to the response. The body provided
128+ // must match the body written in the response, and is allowed to be
129+ // nil. The Digest ensures the response body is not tampered with in
130+ // flight, and if the signer is created to also sign the "Digest"
131+ // header, the HTTP Signature will then ensure both the Digest and body
132+ // are not both modified to maliciously represent different content.
133+ SignResponse (pKey crypto.PrivateKey , pubKeyId string , r http.ResponseWriter , body []byte ) error
120134}
121135
122136// NewSigner creates a new Signer with the provided algorithm preferences to
@@ -125,20 +139,23 @@ type Signer interface {
125139// algorithms were available, then the default algorithm is used. The headers
126140// specified will be included into the HTTP signatures.
127141//
142+ // The Digest will also be calculated on a request's body using the provided
143+ // digest algorithm, if "Digest" is one of the headers listed.
144+ //
128145// The provided scheme determines which header is populated with the HTTP
129146// Signature.
130147//
131148// An error is returned if an unknown or a known cryptographically insecure
132149// Algorithm is provided.
133- func NewSigner (prefs []Algorithm , headers []string , scheme SignatureScheme ) (Signer , Algorithm , error ) {
150+ func NewSigner (prefs []Algorithm , dAlgo DigestAlgorithm , headers []string , scheme SignatureScheme ) (Signer , Algorithm , error ) {
134151 for _ , pref := range prefs {
135- s , err := newSigner (pref , headers , scheme )
152+ s , err := newSigner (pref , dAlgo , headers , scheme )
136153 if err != nil {
137154 continue
138155 }
139156 return s , pref , err
140157 }
141- s , err := newSigner (defaultAlgorithm , headers , scheme )
158+ s , err := newSigner (defaultAlgorithm , dAlgo , headers , scheme )
142159 return s , defaultAlgorithm , err
143160}
144161
@@ -187,11 +204,12 @@ func NewResponseVerifier(r *http.Response) (Verifier, error) {
187204 })
188205}
189206
190- func newSigner (algo Algorithm , headers []string , scheme SignatureScheme ) (Signer , error ) {
207+ func newSigner (algo Algorithm , dAlgo DigestAlgorithm , headers []string , scheme SignatureScheme ) (Signer , error ) {
191208 s , err := signerFromString (string (algo ))
192209 if err == nil {
193210 a := & asymmSigner {
194211 s : s ,
212+ dAlgo : dAlgo ,
195213 headers : headers ,
196214 targetHeader : scheme ,
197215 prefix : scheme .authScheme (),
@@ -204,6 +222,7 @@ func newSigner(algo Algorithm, headers []string, scheme SignatureScheme) (Signer
204222 }
205223 c := & macSigner {
206224 m : m ,
225+ dAlgo : dAlgo ,
207226 headers : headers ,
208227 targetHeader : scheme ,
209228 prefix : scheme .authScheme (),
0 commit comments