-
Notifications
You must be signed in to change notification settings - Fork 34
/
handlers_racing_test.go
263 lines (250 loc) · 20.4 KB
/
handlers_racing_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//go:build !race
// +build !race
package main
import (
"bytes"
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/mozilla-services/autograph/formats"
"github.com/mozilla-services/autograph/signer/apk2"
"github.com/mozilla-services/autograph/signer/contentsignature"
"github.com/mozilla-services/autograph/signer/mar"
"github.com/mozilla-services/autograph/signer/xpi"
margo "go.mozilla.org/mar"
)
func TestSignaturePass(t *testing.T) {
t.Parallel()
ag, conf := newTestAutographer(t)
var TESTCASES = []struct {
endpoint string
signaturerequests []formats.SignatureRequest
}{
{
// Sign hash with Content Signature
"/sign/hash",
[]formats.SignatureRequest{
// request signature of a precomputed sha384 hash
formats.SignatureRequest{
Input: "y0hdfsN8tHlCG82JLywb4d2U+VGWWry8dzwIC3Hk6j32mryUHxUel9SWM5TWkk0d",
KeyID: "appkey1",
},
},
},
{
// Sign a regular add-on
"/sign/data",
[]formats.SignatureRequest{
formats.SignatureRequest{
Input: "U2lnbmF0dXJlLVZlcnNpb246IDEuMApNRDUtRGlnZXN0LU1hbmlmZXN0OiA3d3RFNTF2bW00NlZQRmEvNkF0NWZ3PT0KU0hBMS1EaWdlc3QtTWFuaWZlc3Q6IEZMZEFIZHQvVjdFVHozK0JMUUtHcFFBenoyRT0KCg==",
KeyID: "webextensions-rsa",
Options: map[string]string{
"id": "[email protected]",
},
},
},
},
{
// Sign an extension
"/sign/data",
[]formats.SignatureRequest{
formats.SignatureRequest{
Input: "U2lnbmF0dXJlLVZlcnNpb246IDEuMApNRDUtRGlnZXN0LU1hbmlmZXN0OiA3d3RFNTF2bW00NlZQRmEvNkF0NWZ3PT0KU0hBMS1EaWdlc3QtTWFuaWZlc3Q6IEZMZEFIZHQvVjdFVHozK0JMUUtHcFFBenoyRT0KCg==",
KeyID: "extensions-ecdsa",
Options: map[string]string{
"id": "[email protected]",
},
},
},
},
{
// Sign data with Content-Signature
"/sign/data",
[]formats.SignatureRequest{
formats.SignatureRequest{
Input: "PCFET0NUWVBFIEhUTUw+CjxodG1sPgo8IS0tIGh0dHBzOi8vYnVnemlsbGEubW96aWxsYS5vcmcvc2hvd19idWcuY2dpP2lkPTEyMjY5MjggLS0+CjxoZWFkPgogIDxtZXRhIGNoYXJzZXQ9InV0Zi04Ij4KICA8dGl0bGU+VGVzdHBhZ2UgZm9yIGJ1ZyAxMjI2OTI4PC90aXRsZT4KPC9oZWFkPgo8Ym9keT4KICBKdXN0IGEgZnVsbHkgZ29vZCB0ZXN0cGFnZSBmb3IgQnVnIDEyMjY5Mjg8YnIvPgo8L2JvZHk+CjwvaHRtbD4K",
KeyID: "appkey2",
},
},
},
{
// Sign an APK file
"/sign/file",
[]formats.SignatureRequest{
formats.SignatureRequest{
Input: "UEsDBBQAAAAIAAAAfgEMqbyCAwIAALoDAAAVABwAYnVpbGQt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AB0aGlyZF9wYXJ0eS9qYXZhX3NyYy9lcnJvcl9wcm9uZS9VVAUAA665slp1eAsAAQToAwAABOgDAABQSwECHgMKAAAAAAB1f3VMAAAAAAAAAAAAAAAAKQAYAAAAAAAAABAA7UFDEQAAdGhpcmRfcGFydHkvamF2YV9zcmMvZXJyb3JfcHJvbmUvcHJvamVjdC9VVAUAA665slp1eAsAAQToAwAABOgDAABQSwECHgMKAAAAAAB1f3VMAAAAAAAAAAAAAAAANQAYAAAAAAAAABAA7UGmEQAAdGhpcmRfcGFydHkvamF2YV9zcmMvZXJyb3JfcHJvbmUvcHJvamVjdC9hbm5vdGF0aW9ucy9VVAUAA665slp1eAsAAQToAwAABOgDAABQSwECHgMUAAAACAAAAH4BCmgnsZIAAADVAAAATAAYAAAAAAABAAAApIEVEgAAdGhpcmRfcGFydHkvamF2YV9zcmMvZXJyb3JfcHJvbmUvcHJvamVjdC9hbm5vdGF0aW9ucy9Hb29nbGVfaW50ZXJuYWwuZ3d0LnhtbFVUBQADUEGHFHV4CwABBOgDAAAE6AMAAFBLAQIeAxQAAAAIAAAAfgHAqt49uQAAAHcBAABIABgAAAAAAAEAAACkgS0TAAB0aGlyZF9wYXJ0eS9qYXZhX3NyYy9lcnJvcl9wcm9uZS9wcm9qZWN0L2Fubm90YXRpb25zL0Fubm90YXRpb25zLmd3dC54bWxVVAUAA1BBhxR1eAsAAQToAwAABOgDAABQSwUGAAAAABoAGgCiCgAAaBQAAAAA",
KeyID: "testapp-android",
},
},
},
{
// Sign MAR data
"/sign/data",
[]formats.SignatureRequest{
formats.SignatureRequest{
Input: "Y2FyaWJvdW1hdXJpY2U=",
KeyID: "testmar",
},
},
},
{
// Sign a MAR file
"/sign/file",
[]formats.SignatureRequest{
formats.SignatureRequest{
// Input is the base64 of miniMarB from the mar signer unit tests
Input: "TUFSMQAAAX0AAAAAAAABlgAAAAIAAAACAAABACDExrLgT1Lc1TbLUiKbIVxQl60L6ATvYe6L6JwewAbVSjhEUCGMQ0OK1TmKi18GGijNxaf/uU7Lm/RTyvm0VL7gcODm/pogDmRttf+rc2UfX7nthPxCgB/oOj7fXqDwYpiBPNSSHMIATUb7fnRRHqVTdqhkQZ2RqQsyKL7O6D/bN62EHmVTnn5LbYqYnDLhp+bEVGPo9ETsUpSk7XlFq3v96blLi4Iazm4LyPUXtQmixNwe6OOGpS+ZqobGAtooe7nPPC0Q/kqqKKQmcwCyTP/+lD1Vk7JXbDyGzYj9f9Cloq8PH7gyxOmNvwfHxMU95Jw/ExdFUDdK6QW7UPRTx7AAAAADAAAAQMSHgnYz95K8msSv6YA6IWRfT99ig0W74KDl0QvM0Ti+BRvI7FSmjjt4QOfVHRDko31NuVa2sUCo/PibauLI7GwAAAAAYWFhYWFhYWFhYWFhYWFhYWFhYWFhAAAAFQAAAWgAAAAVAAACWC9mb28vYmFyAA==",
KeyID: "testmar",
},
},
},
}
for i, testcase := range TESTCASES {
userid := conf.Authorizations[0].ID
body, err := json.Marshal(testcase.signaturerequests)
if err != nil {
t.Fatal(err)
}
rdr := bytes.NewReader(body)
req, err := http.NewRequest("POST",
"http://foo.bar"+testcase.endpoint,
rdr)
if err != nil {
t.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
// generate a hawk header for the request
testAuth, err := ag.getAuthByID(userid)
if err != nil {
t.Fatal(err)
}
authheader := getAuthHeader(req,
testAuth.ID,
testAuth.Key,
sha256.New,
id(),
"application/json",
body)
req.Header.Set("Authorization", authheader)
// send the request to the handler
w := httptest.NewRecorder()
ag.handleSignature(w, req)
if w.Code != http.StatusCreated || w.Body.String() == "" {
t.Fatalf("failed with %d: %s; request was: %+v", w.Code, w.Body.String(), req)
}
// parse the response
var responses []formats.SignatureResponse
err = json.Unmarshal(w.Body.Bytes(), &responses)
if err != nil {
t.Fatal(err)
}
// we should have received the same number of responses as we sent requests
if len(responses) != len(testcase.signaturerequests) {
t.Fatalf("in test case %d, failed to receive as many responses (%d) as we sent requests (%d)",
i, len(responses), len(testcase.signaturerequests))
}
// verify the signature in each response
for j, response := range responses {
switch response.Type {
case contentsignature.Type:
rawInput, decodeErr := base64.StdEncoding.DecodeString(testcase.signaturerequests[j].Input)
if decodeErr != nil {
t.Fatalf("in test case %d on endpoint %q, error '%v' in response %d;\nrequest was: %+v\nresponse was: %+v failed to decode input",
i, testcase.endpoint, decodeErr, j, testcase.signaturerequests[j], response)
}
if req.URL.RequestURI() == "/sign/hash" {
err = contentsignature.VerifyResponseHash(rawInput, response)
} else {
err = contentsignature.VerifyResponse(rawInput, response)
}
case xpi.Type:
err = verifyXPISignature(testcase.signaturerequests[j].Input, response.Signature)
case apk2.Type:
if req.URL.RequestURI() == "/sign/data" {
// ok this is a bit of a hack but since apk signatures are really just pkcs7 we can
// reuse the xpi verification code here...
err = verifyAPKManifestSignature(testcase.signaturerequests[j].Input, response.Signature)
} else {
signedAPK, _ := base64.StdEncoding.DecodeString(response.SignedFile)
err = verifyAPKSignature(signedAPK)
}
case mar.Type:
switch req.URL.RequestURI() {
case "/sign/file":
// use the margo pkg to calculate the signable block of the mar file
// as input for the signature verification
rawInput, err := base64.StdEncoding.DecodeString(testcase.signaturerequests[j].Input)
if err != nil {
t.Fatalf("in test case %d on endpoint %q, error '%v' in response %d;\nrequest was: %+v\nresponse was: %+v failed to decode input",
i, testcase.endpoint, err, j, testcase.signaturerequests[j], response)
}
if !bytes.Equal(miniMarB, rawInput) {
t.Fatalf("in test case %d on endpoint %q, error '%v' in response %d;\nrequest was: %+v\nresponse was: %+v decoded input did not match expected input",
i, testcase.endpoint, err, j, testcase.signaturerequests[j], response)
}
var marFile margo.File
err = margo.Unmarshal(rawInput, &marFile)
if err != nil {
t.Fatalf("in test case %d on endpoint %q, error '%v' in response %d;\nrequest was: %+v\nresponse was: %+v failed to unmarshal mar sig",
i, testcase.endpoint, err, j, testcase.signaturerequests[j], response)
}
rawKey, err := base64.StdEncoding.DecodeString(response.PublicKey)
if err != nil {
t.Fatalf("in test case %d on endpoint %q, error '%v' in response %d;\nrequest was: %+v\nresponse was: %+v",
i, testcase.endpoint, err, j, testcase.signaturerequests[j], response)
}
pubkey, err := x509.ParsePKIXPublicKey(rawKey)
if err != nil {
t.Fatalf("in test case %d on endpoint %q, error '%v' in response %d;\nrequest was: %+v\nresponse was: %+v",
i, testcase.endpoint, err, j, testcase.signaturerequests[j], response)
}
err = marFile.VerifySignature(pubkey)
// TODO: figure out why testcase 6 fails with "error verifying mar signature 'no valid signature found'"
if err == nil {
t.Fatalf("in test case %d on endpoint %q, did not error verifying mar signature as expected",
i, testcase.endpoint)
}
default:
err = verifyMARSignature(testcase.signaturerequests[j].Input, response.Signature, response.PublicKey, margo.SigAlgRsaPkcs1Sha384)
}
default:
err = fmt.Errorf("unknown signature type %q", response.Type)
}
if err != nil {
t.Fatalf("in test case %d on endpoint %q, error '%v' in response %d;\nrequest was: %+v\nresponse was: %+v",
i, testcase.endpoint, err, j, testcase.signaturerequests[j], response)
}
}
}
}
var miniMarB = []byte("\x4D\x41\x52\x31\x00\x00\x01\x7D\x00\x00\x00\x00\x00\x00\x01\x96" +
"\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x01\x00\x20\xC4\xC6\xB2" +
"\xE0\x4F\x52\xDC\xD5\x36\xCB\x52\x22\x9B\x21\x5C\x50\x97\xAD\x0B" +
"\xE8\x04\xEF\x61\xEE\x8B\xE8\x9C\x1E\xC0\x06\xD5\x4A\x38\x44\x50" +
"\x21\x8C\x43\x43\x8A\xD5\x39\x8A\x8B\x5F\x06\x1A\x28\xCD\xC5\xA7" +
"\xFF\xB9\x4E\xCB\x9B\xF4\x53\xCA\xF9\xB4\x54\xBE\xE0\x70\xE0\xE6" +
"\xFE\x9A\x20\x0E\x64\x6D\xB5\xFF\xAB\x73\x65\x1F\x5F\xB9\xED\x84" +
"\xFC\x42\x80\x1F\xE8\x3A\x3E\xDF\x5E\xA0\xF0\x62\x98\x81\x3C\xD4" +
"\x92\x1C\xC2\x00\x4D\x46\xFB\x7E\x74\x51\x1E\xA5\x53\x76\xA8\x64" +
"\x41\x9D\x91\xA9\x0B\x32\x28\xBE\xCE\xE8\x3F\xDB\x37\xAD\x84\x1E" +
"\x65\x53\x9E\x7E\x4B\x6D\x8A\x98\x9C\x32\xE1\xA7\xE6\xC4\x54\x63" +
"\xE8\xF4\x44\xEC\x52\x94\xA4\xED\x79\x45\xAB\x7B\xFD\xE9\xB9\x4B" +
"\x8B\x82\x1A\xCE\x6E\x0B\xC8\xF5\x17\xB5\x09\xA2\xC4\xDC\x1E\xE8" +
"\xE3\x86\xA5\x2F\x99\xAA\x86\xC6\x02\xDA\x28\x7B\xB9\xCF\x3C\x2D" +
"\x10\xFE\x4A\xAA\x28\xA4\x26\x73\x00\xB2\x4C\xFF\xFE\x94\x3D\x55" +
"\x93\xB2\x57\x6C\x3C\x86\xCD\x88\xFD\x7F\xD0\xA5\xA2\xAF\x0F\x1F" +
"\xB8\x32\xC4\xE9\x8D\xBF\x07\xC7\xC4\xC5\x3D\xE4\x9C\x3F\x13\x17" +
"\x45\x50\x37\x4A\xE9\x05\xBB\x50\xF4\x53\xC7\xB0\x00\x00\x00\x03" +
"\x00\x00\x00\x40\xC4\x87\x82\x76\x33\xF7\x92\xBC\x9A\xC4\xAF\xE9" +
"\x80\x3A\x21\x64\x5F\x4F\xDF\x62\x83\x45\xBB\xE0\xA0\xE5\xD1\x0B" +
"\xCC\xD1\x38\xBE\x05\x1B\xC8\xEC\x54\xA6\x8E\x3B\x78\x40\xE7\xD5" +
"\x1D\x10\xE4\xA3\x7D\x4D\xB9\x56\xB6\xB1\x40\xA8\xFC\xF8\x9B\x6A" +
"\xE2\xC8\xEC\x6C\x00\x00\x00\x00\x61\x61\x61\x61\x61\x61\x61\x61" +
"\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x00\x00\x00" +
"\x15\x00\x00\x01\x68\x00\x00\x00\x15\x00\x00\x02\x58\x2F\x66\x6F" +
"\x6F\x2F\x62\x61\x72\x00")