Skip to content

Commit

Permalink
feat: docs, name, license
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Mar 8, 2022
1 parent b898a7f commit b726378
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Charmbracelet, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 51 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
# TODO: decide name
# Melt

Backups and restores SSH private keys to/from a mnemonic set of words,
using [bip39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki).
Backup and restore a SSH private key to mnemonic word set you can memorize.

## Usage

You check its `backup` and `restore` subcommands:

```shell
melt backup ~/.ssh/id_ed25519
melt restore --mnemonic "words from backup" ./recovered_id_ed25519
```

You can also pipe to and from a file directly, e.g.:

```shell
melt backup ~/.ssh/id_ed25519 > words
melt restore ./recovered_id_ed25519 < words
```

## How it works

It all comes down to the private key __seed__:

> Ed25519 keys start life as a 32-byte (256-bit) uniformly random binary seed (e.g. the output of SHA256 on some random input). The seed is then hashed using SHA512, which gets you 64 bytes (512 bits), which is then split into a “left half” (the first 32 bytes) and a “right half”. The left half is massaged into a curve25519 private scalar “a” by setting and clearing a few high/low-order bits. The pubkey is generated by multiplying this secret scalar by “B” (the generator), which yields a 32-byte/256-bit group element “A”.
> https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
Knowing that, we open the key and extract its seed, and use it as __entropy__ for the [bip39][] algorithm, which states:

> The mnemonic must encode entropy in a multiple of 32 bits. With more entropy security is improved but the sentence length increases. We refer to the initial entropy length as ENT. The allowed size of ENT is 128-256 bits.
Doing that, we get the __mnemonic__ set of words back.

To restore, we:

- get the __entropy__ from the __mnemonic__
- the __entropy__ is effectively the key __seed__, so we use it to create a SSH key pair
- the key is effectively the same that was backup up, as the key is the same.

[bip39]: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki

## Caveats

At this time, only `ed25519` keys are supported.

## License

[MIT](https://github.com/charmbracelet/melt/raw/master/LICENSE)

***

Part of [Charm](https://charm.sh).

<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge-unrounded.jpg" width="400"></a>
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/caarlos0/keybackup
module github.com/charmbracelet/melt

go 1.17

Expand Down

0 comments on commit b726378

Please sign in to comment.