File tree 2 files changed +28
-25
lines changed
2 files changed +28
-25
lines changed Original file line number Diff line number Diff line change @@ -19,14 +19,7 @@ package main
19
19
20
20
import (
21
21
"bytes"
22
- "crypto"
23
- "crypto/rsa"
24
- "crypto/sha256"
25
- "crypto/x509"
26
- "encoding/hex"
27
22
"encoding/json"
28
- "encoding/pem"
29
- "errors"
30
23
"fmt"
31
24
"net/http"
32
25
"os"
@@ -114,7 +107,7 @@ func uploadHandler(c *gin.Context) {
114
107
return
115
108
}
116
109
117
- err := verifyCommandLine (data .Commandline , data .Signature )
110
+ err := utilities . VerifyInput (data .Commandline , data .Signature )
118
111
119
112
if err != nil {
120
113
c .String (http .StatusBadRequest , "signature is invalid" )
@@ -215,23 +208,6 @@ func send(args map[string]string) {
215
208
h .broadcastSys <- mapB
216
209
}
217
210
218
- func verifyCommandLine (input string , signature string ) error {
219
- sign , _ := hex .DecodeString (signature )
220
- block , _ := pem .Decode ([]byte (* signatureKey ))
221
- if block == nil {
222
- return errors .New ("invalid key" )
223
- }
224
- key , err := x509 .ParsePKIXPublicKey (block .Bytes )
225
- if err != nil {
226
- return err
227
- }
228
- rsaKey := key .(* rsa.PublicKey )
229
- h := sha256 .New ()
230
- h .Write ([]byte (input ))
231
- d := h .Sum (nil )
232
- return rsa .VerifyPKCS1v15 (rsaKey , crypto .SHA256 , d , sign )
233
- }
234
-
235
211
func wsHandler () * WsServer {
236
212
server , err := socketio .NewServer (nil )
237
213
if err != nil {
Original file line number Diff line number Diff line change @@ -18,12 +18,20 @@ package utilities
18
18
import (
19
19
"archive/zip"
20
20
"bytes"
21
+ "crypto"
22
+ "crypto/rsa"
23
+ "crypto/sha256"
24
+ "crypto/x509"
25
+ "encoding/hex"
26
+ "encoding/pem"
21
27
"errors"
22
28
"io"
23
29
"os"
24
30
"os/exec"
25
31
"path"
26
32
"path/filepath"
33
+
34
+ "github.com/arduino/arduino-create-agent/globals"
27
35
)
28
36
29
37
// SaveFileonTempDir creates a temp directory and saves the file data as the
@@ -141,3 +149,22 @@ func Unzip(zippath string, destination string) (err error) {
141
149
}
142
150
return
143
151
}
152
+
153
+ // VerifyInput will verify an input against a signature
154
+ // A valid signature is indicated by returning a nil error.
155
+ func VerifyInput (input string , signature string ) error {
156
+ sign , _ := hex .DecodeString (signature )
157
+ block , _ := pem .Decode ([]byte (globals .SignatureKey ))
158
+ if block == nil {
159
+ return errors .New ("invalid key" )
160
+ }
161
+ key , err := x509 .ParsePKIXPublicKey (block .Bytes )
162
+ if err != nil {
163
+ return err
164
+ }
165
+ rsaKey := key .(* rsa.PublicKey )
166
+ h := sha256 .New ()
167
+ h .Write ([]byte (input ))
168
+ d := h .Sum (nil )
169
+ return rsa .VerifyPKCS1v15 (rsaKey , crypto .SHA256 , d , sign )
170
+ }
You can’t perform that action at this time.
0 commit comments