You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you use the above key in Node then it appears to work:
> require("crypto").sign("sha1", Buffer.alloc(500), privateKey);
<Buffer e1 cc 1b f1 a5 e2 89 bd a7 c7 fb 71 58 ca 5e 81 17 82 8f 15 5a 4e 23 e2 34 11 d6 b3 fc a1 61 65 bf 8c 87 7e e6 7c a2 00 cb 1d 46 0e 73 71 45 ed 2a da ... 334 more bytes>
However if you do the same thing in Electron's Renderer (i.e. Chromium) then you get this error:
"Error: Error while signing data with privateKey: error:06000066:public key routines:OPENSSL_internal:DECODE_ERROR
at signOneShot (internal/crypto/sig.js:124:10)
at OpenSSH_Private.sign (http://localhost:8080/js/entry_renderer.js:168552:16)
...
The difference is that Node uses OpenSSL whereas Chromium uses BoringSSL. BoringSSL is more strict about parsing keys, and according to them, this key is encoded incorrectly. We can get a similar error by saving the above RSA PRIVATE KEY to id_rsa and running BoringSSL on the command line:
$ openssl dgst -sha1 -sign id_rsa any_file.txt
<it prints some binary data>
This is the issue according to David Ben in that link above:
The private key is incorrectly encoded with some negative components. (In DER, if the high bit of your positive INTEGER is set, you need a leading zero.) In particular, dmp1 and dmq1 are negative and missing a leading zero. Closing this as it's not a bug in BoringSSL (the other parsers are insufficiently strict here).
Note that I have tested this both with version 0.4.10, and with master, both of which include this recent patch that looks like it was an attempt to fix this.
In fact, looking at that fix it makes no sense to me:
// BER/DER integers require leading zero byte to denote a positive value
// when first byte >= 0x80
if (sigbit === 56 || (sigbit >= 97 && sigbit <= 102))
hex = '00' + hex;
You add 00 if hex starts with 8 or a-f. What about 9? In fact adding || sigbit === 57 fixes the issue!
I suggest using fewer magic numbers in your code to avoid this in future! It's also easy to check for !(0-7) than 8, 9, a-f, A-F (pretty risky to assume lowercase). Try this code:
var sighex = hex.charCodeAt(0);
const ASCII_0 = 0x30;
const ASCII_7 = 0x38;
// BER/DER integers require leading zero byte to denote a positive value
// when first byte >= 0x80
if (sighex < ASCII_0 || sighex > ASCII_7)
hex = '00' + hex;
(Renamed sigbit because it isn't a bit - it is a nibble / hex character.)
The text was updated successfully, but these errors were encountered:
Timmmm
pushed a commit
to Timmmm/ssh2-streams
that referenced
this issue
Aug 20, 2020
This is currently preventing Mongodb Compass from connecting to a GCE instance using the gcloud compute config-ssh keys. I imagine the problem is pretty widespread, since any Electron app that uses an SSH tunnel (like MongoDB Compass) won't work on Mac.
We have an OpenSSH key that was generated on MacOS.
ssh2-streams
unfortunately decodes it incorrectly:Running the above code gives:
If you use the above key in Node then it appears to work:
However if you do the same thing in Electron's Renderer (i.e. Chromium) then you get this error:
The difference is that Node uses OpenSSL whereas Chromium uses BoringSSL. BoringSSL is more strict about parsing keys, and according to them, this key is encoded incorrectly. We can get a similar error by saving the above
RSA PRIVATE KEY
toid_rsa
and running BoringSSL on the command line:OpenSSL is more lax and outputs some data:
This is the issue according to David Ben in that link above:
Note that I have tested this both with version 0.4.10, and with
master
, both of which include this recent patch that looks like it was an attempt to fix this.In fact, looking at that fix it makes no sense to me:
You add
00
ifhex
starts with8
ora-f
. What about9
? In fact adding|| sigbit === 57
fixes the issue!I suggest using fewer magic numbers in your code to avoid this in future! It's also easy to check for !(0-7) than 8, 9, a-f, A-F (pretty risky to assume lowercase). Try this code:
(Renamed
sigbit
because it isn't a bit - it is a nibble / hex character.)The text was updated successfully, but these errors were encountered: