2018-12-02 03:32:22 +00:00
|
|
|
# SSH to JWK (for node.js)
|
|
|
|
|
|
|
|
A minimal library to parse an SSH public key (`id_rsa.pub`)
|
|
|
|
and convert it into a public JWK.
|
|
|
|
|
|
|
|
Works for RSA and ECDSA public keys.
|
|
|
|
|
2018-12-12 05:31:32 +00:00
|
|
|
# Features
|
2018-12-02 03:32:22 +00:00
|
|
|
|
|
|
|
< 100 lines of code | <1kb gzipped | 1.8kb minified | 3.1kb with comments
|
|
|
|
|
2018-12-12 05:31:32 +00:00
|
|
|
* [x] SSH Public Keys ([RFC 4253](https://coolaj86.com/articles/the-ssh-public-key-format/))
|
2018-12-03 05:07:51 +00:00
|
|
|
* fingerprint
|
2018-12-12 05:31:32 +00:00
|
|
|
* [x] OpenSSH Private Keys
|
|
|
|
* [x] RSA
|
|
|
|
* 2048, 3072, 4096
|
2018-12-02 03:32:22 +00:00
|
|
|
* [x] EC Public Keys
|
|
|
|
* P-256 (prime256v1, secp256r1)
|
|
|
|
* P-384 (secp384r1)
|
2018-12-02 05:05:03 +00:00
|
|
|
* [x] Browser Version
|
|
|
|
* [Bluecrypt SSH to JWK](https://git.coolaj86.com/coolaj86/bluecrypt-ssh-to-jwk.js)
|
2018-12-02 03:32:22 +00:00
|
|
|
|
2018-12-12 05:31:32 +00:00
|
|
|
Note: Lines of code have increased by about 2x since adding private key support.
|
|
|
|
|
2018-12-02 03:32:22 +00:00
|
|
|
### Need JWK to SSH? SSH to PEM?
|
|
|
|
|
|
|
|
Try one of these:
|
|
|
|
|
|
|
|
* [jwk-to-ssh.js](https://git.coolaj86.com/coolaj86/jwk-to-ssh.js) (RSA + EC)
|
|
|
|
* [Eckles.js](https://git.coolaj86.com/coolaj86/eckles.js) (more EC utils)
|
|
|
|
* [Rasha.js](https://git.coolaj86.com/coolaj86/eckles.js) (more RSA utils)
|
|
|
|
|
|
|
|
### Need SSH Private Keys?
|
|
|
|
|
2018-12-09 08:28:03 +00:00
|
|
|
Many SSH private keys are just normal PEM files,
|
2018-12-02 03:32:22 +00:00
|
|
|
so you can use Eckles or Rasha, as mentioned above.
|
|
|
|
|
2018-12-09 08:28:03 +00:00
|
|
|
As for the [OpenSSH-specific Private Keys](https://coolaj86.com/articles/the-openssh-private-key-format/),
|
2018-12-12 05:31:32 +00:00
|
|
|
both EC and RSA are fully supported.
|
2018-12-09 08:28:03 +00:00
|
|
|
|
2018-12-02 03:32:22 +00:00
|
|
|
# CLI
|
|
|
|
|
|
|
|
You can install `ssh-to-jwk` and use it from command line:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
npm install -g ssh-to-jwk
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
ssh-to-jwk ~/.ssh/id_rsa.pub
|
|
|
|
```
|
|
|
|
|
2018-12-09 08:43:41 +00:00
|
|
|
```bash
|
|
|
|
ssh-to-jwk ~/.ssh/id_rsa
|
|
|
|
```
|
|
|
|
|
2018-12-02 03:32:22 +00:00
|
|
|
# Usage
|
|
|
|
|
|
|
|
You can also use it from JavaScript:
|
|
|
|
|
2018-12-03 05:07:51 +00:00
|
|
|
**SSH to JWK**
|
|
|
|
|
2018-12-02 03:32:22 +00:00
|
|
|
```js
|
|
|
|
var fs = require('fs');
|
2018-12-02 05:05:03 +00:00
|
|
|
var sshtojwk = require('ssh-to-jwk');
|
2018-12-09 08:43:41 +00:00
|
|
|
var ssh;
|
2018-12-02 03:32:22 +00:00
|
|
|
|
2018-12-09 08:43:41 +00:00
|
|
|
ssh = sshtojwk.parse({ pub: fs.readFileSync("./id_rsa.pub") });
|
|
|
|
console.info(ssh.jwk);
|
2018-12-02 03:32:22 +00:00
|
|
|
|
2018-12-09 08:43:41 +00:00
|
|
|
// For OpenSSH PEMs only, use Rasha for standard RSA or Eckles for standard EC
|
|
|
|
ssh = sshtojwk.parse({ pem: fs.readFileSync("./id_rsa") });
|
2018-12-02 05:05:03 +00:00
|
|
|
console.info(ssh.jwk);
|
2018-12-02 03:32:22 +00:00
|
|
|
```
|
|
|
|
|
2018-12-03 05:07:51 +00:00
|
|
|
**SSH Fingerprint**
|
|
|
|
|
|
|
|
```js
|
|
|
|
var fs = require('fs');
|
|
|
|
var sshtojwk = require('ssh-to-jwk');
|
|
|
|
var pub = fs.readFileSync("./id_rsa.pub");
|
|
|
|
|
|
|
|
sshtojwk.fingerprint({ pub: pub }).then(function (fingerprint) {
|
|
|
|
console.info(fingerprint);
|
|
|
|
// SHA256:yCB62vBVsOwqksgYwy/WDbaMF2PhPijAwcrlzmrxfko
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
# Legal
|
2018-12-02 03:32:22 +00:00
|
|
|
|
|
|
|
[ssh-to-jwk.js](https://git.coolaj86.com/coolaj86/ssh-to-jwk.js) |
|
|
|
|
MPL-2.0 |
|
|
|
|
[Terms of Use](https://therootcompany.com/legal/#terms) |
|
|
|
|
[Privacy Policy](https://therootcompany.com/legal/#privacy)
|