Skip to content

Commit

Permalink
refactor and cleanup for v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cornfeedhobo committed Nov 20, 2017
1 parent 1bdfde5 commit af490d5
Show file tree
Hide file tree
Showing 12 changed files with 723 additions and 208 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go:
- 1.9

script:
- go test -v ./...
- go get github.com/mitchellh/gox
- CGO_ENABLED=0 gox -ldflags "-s" -rebuild

Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* Mon Nov 20 2017 cornfeedhobo 0.2.0
- Refactor key management to a struct-based approach
- Drop printing to stdout and switch to writing files like OpenSSH's ssh-keygen
- Refactor resource names
- Style clean up
- Add configurable work factor
- Add tests

* Sun Nov 12 2017 cornfeedhobo 0.1.0
- initial draft
42 changes: 31 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
ssh-keydgen [![Travis](https://img.shields.io/travis/cornfeedhobo/ssh-keydgen.svg)]() [![Github All Releases](https://img.shields.io/github/downloads/cornfeedhobo/ssh-keydgen/total.svg)]()
===========

Generate _Deterministic_ SSH keys

## Usage
Generate _Deterministic_ SSH keys

```text
NAME:
ssh-keydgen - deterministic authentication key generation
ssh-keydgen - Deterministic authentication key generation
USAGE:
ssh-keydgen [-t] [-b] [-c] [-o] [-a]
ssh-keydgen [-t] [-b] [-c] [-n] [-f] [-a]
AUTHOR:
cornfeedhobo
OPTIONS:
-t type Specifies the type of key to create. The possible values are “dsa”, “ecdsa”, “ed25519”, or “rsa”. (default: "ed25519")
-b bits Specifies the number of bits in the key to create. Possible values are restricted by key type. (default: 2048)
-c curve Specifies the elliptic curve to use. The possible values are 256, 384, or 521. (default: 256)
-o path Specifies the path to output the generated key.
-a Add the generated key to the running ssh-agent.
-t type Specifies the type of key to create. The possible values are "dsa", "ecdsa", "rsa", or "ed25519". (default: "ed25519")
-b bits Specifies the number of bits in the key to create. Possible values are restricted by key type. (default: 2048)
-c curve Specifies the elliptic curve to use. The possible values are 256, 384, or 521. (default: 256)
-n factor Specifies the work factor, or "difficulty", applied to the key generation function. (default: 16384)
-f filename Specifies the filename of the key file.
-a Add the generated key to the running ssh-agent.
COPYRIGHT:
(c) 2017 cornfeedhobo
```



## Usage

1) Generate your keys
```bash
keydgen -f deterministic_key
ls -lh deterministic_key*
```

2) Allow time to pass, hoping an emergency does not arise when you have no access to your keys ...

_If_ the time comes where you need access but can't get to your keys, you can then obtain this
utility and re-generate, or even directly add your key to a running `ssh-agent`.
```bash
keydgen -a
```
3) Profit!
## Is it any good?
[Yes](http://news.ycombinator.com/item?id=3067434)
[Yes](http://news.ycombinator.com/item?id=3067434)
37 changes: 37 additions & 0 deletions deterministic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"crypto/sha512"

"golang.org/x/crypto/ripemd160"
"golang.org/x/crypto/scrypt"
)

var WorkFactor int

type Deterministic struct {
seed []byte
salt []byte
}

func (d *Deterministic) Read(p []byte) (int, error) {

var sha = sha512.New()
if _, err := sha.Write(d.seed); err != nil {
return 0, err
}
d.seed = sha.Sum(nil)

var ripe = ripemd160.New()
if _, err := ripe.Write(d.salt); err != nil {
return 0, err
}
d.salt = ripe.Sum(nil)

dk, err := scrypt.Key(d.seed, d.salt, WorkFactor, 8, 1, len(p))
if err != nil {
return 0, err
}
return copy(p, dk), nil

}
Loading

0 comments on commit af490d5

Please sign in to comment.