Skip to content

Commit faaa53f

Browse files
committed
Add multiple signatures (proxy) per the new Sec. 4.3
1 parent 08e7c57 commit faaa53f

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

signatures_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,7 @@ Signature: sig1=:hNojB+wWw4A7SYF3qK1S01Y4UP5i2JZFYa2WOlMB4Np5iWmJSO0bDe2hrYRbcIW
13911391
13921392
`
13931393

1394+
// This was superseded once again in draft -17. See TestMultipleSignatures17.
13941395
func TestMultipleSignatures(t *testing.T) {
13951396
req := readRequest(httpreq9)
13961397
pubKey1, err := parseECPublicKeyFromPemStr(p256PubKey2)
@@ -2050,3 +2051,54 @@ func TestRequestBinding17(t *testing.T) {
20502051
err = ValidateContentDigestHeader(responseContentDigest, &res.Body, []string{DigestSha512})
20512052
assert.NoError(t, err, "validate response digest")
20522053
}
2054+
2055+
var httpreq12 = `POST /foo?param=Value&Pet=dog HTTP/1.1
2056+
Host: origin.host.internal.example
2057+
Date: Tue, 20 Apr 2021 02:07:56 GMT
2058+
Content-Type: application/json
2059+
Content-Length: 18
2060+
Forwarded: for=192.0.2.123;host=example.com;proto=https
2061+
Content-Digest: sha-512=:WZDPaVn/7XgHaAy8pmojAkGWoRx2UFChF41A2svX+TaPm+AbwAgBWnrIiYllu7BNNyealdVLvRwEmTHWXvJwew==:
2062+
Signature-Input: sig1=("@method" "@authority" "@path" "content-digest" "content-type" "content-length");created=1618884475;keyid="test-key-ecc-p256", proxy_sig=("@method" "@authority" "@path" "content-digest" "content-type" "content-length" "forwarded");created=1618884480;keyid="test-key-rsa";alg="rsa-v1_5-sha256";expires=1618884540
2063+
Signature: sig1=:X5spyd6CFnAG5QnDyHfqoSNICd+BUP4LYMz2Q0JXlb//4Ijpzp+kve2w4NIyqeAuM7jTDX+sNalzA8ESSaHD3A==:, proxy_sig=:S6ZzPXSdAMOPjN/6KXfXWNO/f7V6cHm7BXYUh3YD/fRad4BCaRZxP+JH+8XY1I6+8Cy+CM5g92iHgxtRPz+MjniOaYmdkDcnL9cCpXJleXsOckpURl49GwiyUpZ10KHgOEe11sx3G2gxI8S0jnxQB+Pu68U9vVcasqOWAEObtNKKZd8tSFu7LB5YAv0RAGhB8tmpv7sFnIm9y+7X5kXQfi8NMaZaA8i2ZHwpBdg7a6CMfwnnrtflzvZdXAsD3LH2TwevU+/PBPv0B6NMNk93wUs/vfJvye+YuI87HU38lZHowtznbLVdp770I6VHR6WfgS9ddzirrswsE1w5o0LV/g==:
2064+
2065+
{"hello": "world"}
2066+
`
2067+
2068+
var httpreq13 = `POST /foo?param=Value&Pet=dog HTTP/1.1
2069+
Host: example.com
2070+
Date: Tue, 20 Apr 2021 02:07:56 GMT
2071+
Content-Type: application/json
2072+
Content-Length: 18
2073+
Content-Digest: sha-512=:WZDPaVn/7XgHaAy8pmojAkGWoRx2UFChF41A2svX+TaPm+AbwAgBWnrIiYllu7BNNyealdVLvRwEmTHWXvJwew==:
2074+
Signature-Input: sig1=("@method" "@authority" "@path" "content-digest" "content-type" "content-length");created=1618884475;keyid="test-key-ecc-p256"
2075+
Signature: sig1=:X5spyd6CFnAG5QnDyHfqoSNICd+BUP4LYMz2Q0JXlb//4Ijpzp+kve2w4NIyqeAuM7jTDX+sNalzA8ESSaHD3A==:
2076+
2077+
{"hello": "world"}
2078+
`
2079+
2080+
// New in draft -17, signing the message components instead of the signature.
2081+
func TestMultipleSignatures17(t *testing.T) {
2082+
req := readRequest(httpreq12)
2083+
pubKey1, err := parseECPublicKeyFromPemStr(p256PubKey2)
2084+
assert.NoError(t, err, "cannot parse ECC public key")
2085+
verifier1, err := NewP256Verifier("test-key-ecc-p256", *pubKey1, NewVerifyConfig().
2086+
SetVerifyCreated(false), Headers("@method", "@authority", "@path", "content-digest",
2087+
"content-type", "content-length"))
2088+
assert.NoError(t, err, "cannot create verifier1")
2089+
_, err = verifyRequestDebug("sig1", *verifier1, req)
2090+
assert.Error(t, err, "sig1 cannot be verified, because the proxy modified the authority field")
2091+
2092+
pubKey2, err := parseRsaPublicKey(rsaPubKey)
2093+
assert.NoError(t, err, "cannot parse RSA public key")
2094+
verifier2, err := NewRSAVerifier("test-key-rsa", *pubKey2, NewVerifyConfig().
2095+
SetVerifyCreated(false).SetRejectExpired(false), *NewFields().AddHeaders("@authority", "forwarded"))
2096+
assert.NoError(t, err, "cannot create verifier2")
2097+
_, err = verifyRequestDebug("proxy_sig", *verifier2, req)
2098+
assert.NoError(t, err, "proxy signature not verified")
2099+
2100+
req = readRequest(httpreq13)
2101+
sigBase, err := verifyRequestDebug("sig1", *verifier1, req)
2102+
assert.NotEmpty(t, sigBase)
2103+
assert.NoError(t, err, "sig1 should verify for the original message that the proxy received")
2104+
}

0 commit comments

Comments
 (0)