Skip to content

Commit 33080c3

Browse files
authored
Add signature verification to V2 tool install endpoint (#826)
* modify examples * add signature * goa gen github.com/arduino/arduino-create-agent/design * make signatureKey global * move `verifyCommandLine` to utilities package * implement signature verification in case of tool install with URL The endpoint affected is `/v2/pkgs/tools/installed`. If the signature is invalid the endpoint returns 500 with "rsa verification error" If the signature is not present we try to install the tool using "name, version, packager" arguments * use subtests and add test cases
1 parent e740ad9 commit 33080c3

File tree

16 files changed

+304
-169
lines changed

16 files changed

+304
-169
lines changed

Diff for: conn.go

+1-25
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@ package main
1919

2020
import (
2121
"bytes"
22-
"crypto"
23-
"crypto/rsa"
24-
"crypto/sha256"
25-
"crypto/x509"
26-
"encoding/hex"
2722
"encoding/json"
28-
"encoding/pem"
29-
"errors"
3023
"fmt"
3124
"net/http"
3225
"os"
@@ -114,7 +107,7 @@ func uploadHandler(c *gin.Context) {
114107
return
115108
}
116109

117-
err := verifyCommandLine(data.Commandline, data.Signature)
110+
err := utilities.VerifyInput(data.Commandline, data.Signature)
118111

119112
if err != nil {
120113
c.String(http.StatusBadRequest, "signature is invalid")
@@ -219,23 +212,6 @@ func send(args map[string]string) {
219212
h.broadcastSys <- mapB
220213
}
221214

222-
func verifyCommandLine(input string, signature string) error {
223-
sign, _ := hex.DecodeString(signature)
224-
block, _ := pem.Decode([]byte(*signatureKey))
225-
if block == nil {
226-
return errors.New("invalid key")
227-
}
228-
key, err := x509.ParsePKIXPublicKey(block.Bytes)
229-
if err != nil {
230-
return err
231-
}
232-
rsaKey := key.(*rsa.PublicKey)
233-
h := sha256.New()
234-
h.Write([]byte(input))
235-
d := h.Sum(nil)
236-
return rsa.VerifyPKCS1v15(rsaKey, crypto.SHA256, d, sign)
237-
}
238-
239215
func wsHandler() *WsServer {
240216
server, err := socketio.NewServer(nil)
241217
if err != nil {

Diff for: design/pkgs.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,29 @@ var ToolPayload = Type("arduino.tool", func() {
110110
TypeName("ToolPayload")
111111

112112
Attribute("name", String, "The name of the tool", func() {
113-
Example("avrdude")
113+
Example("bossac")
114114
})
115115
Attribute("version", String, "The version of the tool", func() {
116-
Example("6.3.0-arduino9")
116+
Example("1.7.0-arduino3")
117117
})
118118
Attribute("packager", String, "The packager of the tool", func() {
119119
Example("arduino")
120120
})
121121

122122
Attribute("url", String, `The url where the package can be found. Optional.
123-
If present checksum must also be present.`)
123+
If present checksum must also be present.`, func() {
124+
Example("http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz")
125+
})
124126

125127
Attribute("checksum", String, `A checksum of the archive. Mandatory when url is present.
126-
This ensures that the package is downloaded correcly.`)
128+
This ensures that the package is downloaded correcly.`, func() {
129+
Example("SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100")
130+
})
131+
132+
Attribute("signature", String, `The signature used to sign the url. Mandatory when url is present.
133+
This ensure the security of the file downloaded`, func() {
134+
Example("382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0")
135+
})
127136

128137
Required("name", "version", "packager")
129138
})

Diff for: gen/http/cli/arduino_create_agent/cli.go

+9-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: gen/http/openapi.json

+1-1
Large diffs are not rendered by default.

Diff for: gen/http/openapi.yaml

+52-32
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ paths:
2626
type: array
2727
items:
2828
type: string
29-
example: Repudiandae dignissimos consectetur eos molestiae culpa soluta.
29+
example: Pariatur laudantium inventore qui.
3030
"400":
3131
description: Bad Request response.
3232
schema:
@@ -193,14 +193,14 @@ definitions:
193193
timeout:
194194
type: boolean
195195
description: Is the error a timeout?
196-
example: false
196+
example: true
197197
description: url invalid (default view)
198198
example:
199199
fault: false
200200
id: 123abc
201201
message: parameter 'p' must be an integer
202202
name: bad_request
203-
temporary: false
203+
temporary: true
204204
timeout: false
205205
required:
206206
- name
@@ -241,7 +241,7 @@ definitions:
241241
fault:
242242
type: boolean
243243
description: Is the error a server-side fault?
244-
example: true
244+
example: false
245245
id:
246246
type: string
247247
description: ID is a unique identifier for this particular occurrence of the problem.
@@ -261,14 +261,14 @@ definitions:
261261
timeout:
262262
type: boolean
263263
description: Is the error a timeout?
264-
example: false
264+
example: true
265265
description: url invalid (default view)
266266
example:
267-
fault: true
267+
fault: false
268268
id: 123abc
269269
message: parameter 'p' must be an integer
270270
name: bad_request
271-
temporary: true
271+
temporary: false
272272
timeout: true
273273
required:
274274
- name
@@ -284,7 +284,7 @@ definitions:
284284
fault:
285285
type: boolean
286286
description: Is the error a server-side fault?
287-
example: false
287+
example: true
288288
id:
289289
type: string
290290
description: ID is a unique identifier for this particular occurrence of the problem.
@@ -300,19 +300,19 @@ definitions:
300300
temporary:
301301
type: boolean
302302
description: Is the error temporary?
303-
example: true
303+
example: false
304304
timeout:
305305
type: boolean
306306
description: Is the error a timeout?
307-
example: true
307+
example: false
308308
description: url invalid (default view)
309309
example:
310-
fault: false
310+
fault: true
311311
id: 123abc
312312
message: parameter 'p' must be an integer
313313
name: bad_request
314314
temporary: true
315-
timeout: false
315+
timeout: true
316316
required:
317317
- name
318318
- id
@@ -352,20 +352,20 @@ definitions:
352352
name:
353353
type: string
354354
description: The name of the tool
355-
example: avrdude
355+
example: bossac
356356
packager:
357357
type: string
358358
description: The packager of the tool
359359
example: arduino
360360
version:
361361
type: string
362362
description: The version of the tool
363-
example: 6.3.0-arduino9
363+
example: 1.7.0-arduino3
364364
description: A tool is an executable program that can upload sketches. (default view)
365365
example:
366-
name: avrdude
366+
name: bossac
367367
packager: arduino
368-
version: 6.3.0-arduino9
368+
version: 1.7.0-arduino3
369369
required:
370370
- name
371371
- version
@@ -377,29 +377,36 @@ definitions:
377377
checksum:
378378
type: string
379379
description: "A checksum of the archive. Mandatory when url is present. \n\tThis ensures that the package is downloaded correcly."
380-
example: Totam cum inventore exercitationem in.
380+
example: SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100
381381
name:
382382
type: string
383383
description: The name of the tool
384-
example: avrdude
384+
example: bossac
385385
packager:
386386
type: string
387387
description: The packager of the tool
388388
example: arduino
389+
signature:
390+
type: string
391+
description: |-
392+
The signature used to sign the url. Mandatory when url is present.
393+
This ensure the security of the file downloaded
394+
example: 382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0
389395
url:
390396
type: string
391397
description: "The url where the package can be found. Optional. \n\tIf present checksum must also be present."
392-
example: Totam vero ipsum corporis nihil voluptatem id.
398+
example: http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz
393399
version:
394400
type: string
395401
description: The version of the tool
396-
example: 6.3.0-arduino9
402+
example: 1.7.0-arduino3
397403
example:
398-
checksum: Modi dolorem reprehenderit perspiciatis illo aspernatur.
399-
name: avrdude
404+
checksum: SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100
405+
name: bossac
400406
packager: arduino
401-
url: Officia optio inventore atque in voluptatibus qui.
402-
version: 6.3.0-arduino9
407+
signature: 382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0
408+
url: http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz
409+
version: 1.7.0-arduino3
403410
required:
404411
- name
405412
- version
@@ -424,14 +431,21 @@ definitions:
424431
checksum:
425432
type: string
426433
description: "A checksum of the archive. Mandatory when url is present. \n\tThis ensures that the package is downloaded correcly."
427-
example: Et qui id et cumque illo.
434+
example: SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100
435+
signature:
436+
type: string
437+
description: |-
438+
The signature used to sign the url. Mandatory when url is present.
439+
This ensure the security of the file downloaded
440+
example: 382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0
428441
url:
429442
type: string
430443
description: "The url where the package can be found. Optional. \n\tIf present checksum must also be present."
431-
example: Officia maiores reiciendis est nemo.
444+
example: http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz
432445
example:
433-
checksum: Corporis eum et numquam sapiente.
434-
url: Est voluptatem eos reprehenderit quo sint quod.
446+
checksum: SHA-256:1ae54999c1f97234a5c603eb99ad39313b11746a4ca517269a9285afa05f9100
447+
signature: 382898a97b5a86edd74208f10107d2fecbf7059ffe9cc856e045266fb4db4e98802728a0859cfdcda1c0b9075ec01e42dbea1f430b813530d5a6ae1766dfbba64c3e689b59758062dc2ab2e32b2a3491dc2b9a80b9cda4ae514fbe0ec5af210111b6896976053ab76bac55bcecfcececa68adfa3299e3cde6b7f117b3552a7d80ca419374bb497e3c3f12b640cf5b20875416b45e662fc6150b99b178f8e41d6982b4c0a255925ea39773683f9aa9201dc5768b6fc857c87ff602b6a93452a541b8ec10ca07f166e61a9e9d91f0a6090bd2038ed4427af6251039fb9fe8eb62ec30d7b0f3df38bc9de7204dec478fb86f8eb3f71543710790ee169dce039d3e0
448+
url: http://downloads.arduino.cc/tools/bossac-1.7.0-arduino3-linux64.tar.gz
435449
ToolsRemoveResponseBody:
436450
title: 'Mediatype identifier: application/vnd.arduino.operation; view=default'
437451
type: object
@@ -452,9 +466,15 @@ definitions:
452466
$ref: '#/definitions/ToolResponse'
453467
description: AvailableResponseBody is the result type for an array of ToolResponse (default view)
454468
example:
455-
- name: avrdude
469+
- name: bossac
470+
packager: arduino
471+
version: 1.7.0-arduino3
472+
- name: bossac
473+
packager: arduino
474+
version: 1.7.0-arduino3
475+
- name: bossac
456476
packager: arduino
457-
version: 6.3.0-arduino9
458-
- name: avrdude
477+
version: 1.7.0-arduino3
478+
- name: bossac
459479
packager: arduino
460-
version: 6.3.0-arduino9
480+
version: 1.7.0-arduino3

0 commit comments

Comments
 (0)