Skip to content

Commit 446fd3f

Browse files
thefringeninjapgermishuys
authored andcommitted
Initial commit
0 parents  commit 446fd3f

File tree

12 files changed

+861
-0
lines changed

12 files changed

+861
-0
lines changed

Diff for: .github/workflows/ci.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
tags:
9+
- "*"
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
- name: Set up Go
19+
uses: actions/setup-go@v2
20+
with:
21+
go-version: 1.14
22+
- name: Calculate Version
23+
shell: bash
24+
run: |
25+
cd /tmp
26+
go get github.com/mdomke/git-semver
27+
cd -
28+
version=$(~/go/bin/git-semver)
29+
echo "::set-env name=VERSION::${version}"
30+
- name: Build and Publish
31+
uses: goreleaser/goreleaser-action@v2
32+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
33+
with:
34+
version: latest
35+
args: release --rm-dist
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
- name: Build and Publish (Dry Run)
39+
uses: goreleaser/goreleaser-action@v2
40+
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
41+
with:
42+
version: latest
43+
args: release --skip-publish --rm-dist --snapshot
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Diff for: .gitignore

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2+
*.o
3+
*.a
4+
*.so
5+
6+
# Folders
7+
_obj
8+
_test
9+
10+
# Architecture specific extensions/prefixes
11+
*.[568vq]
12+
[568vq].out
13+
14+
*.cgo1.go
15+
*.cgo2.c
16+
_cgo_defun.c
17+
_cgo_gotypes.go
18+
_cgo_export.*
19+
20+
_testmain.go
21+
22+
*.exe
23+
*.test
24+
*.prof
25+
26+
.idea/
27+
binaries/
28+
ca/

Diff for: .goreleaser.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
- go generate ./...
5+
dist: binaries
6+
builds:
7+
- goos:
8+
- darwin
9+
- linux
10+
- windows
11+
ldflags:
12+
- -s -w -X "main.version={{.Env.VERSION}}"
13+
archives:
14+
-
15+
id: "es-gencert-cli"
16+
builds: ['es-gencert-cli']
17+
format: tar.gz
18+
format_overrides:
19+
- goos: windows
20+
format: zip
21+
name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"
22+
replacements:
23+
darwin: Darwin
24+
linux: Linux
25+
windows: Windows
26+
386: i386
27+
amd64: x86_64
28+
changelog:
29+
sort: asc
30+
filters:
31+
exclude:
32+
- '^docs:'
33+
- '^test:'

Diff for: LICENSE

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Event Store Certificate Generation CLI License
2+
3+
Copyright (c) 2020, Event Store Ltd. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
Redistributions in binary form must reproduce the above copyright notice, this
12+
list of conditions and the following disclaimer in the documentation and/or
13+
other materials provided with the distribution.
14+
15+
Neither the name of Event Store LLP nor the names of its contributors may be
16+
used to endorse or promote products derived from this software without specific
17+
prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Diff for: README.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Event Store Certificate Generation CLI
2+
3+
The command line interface to ease the generation of a certificate authority and node certificates for Event Store Db 20.6.x and above.
4+
5+
## Getting Started
6+
7+
### Releases
8+
The latest release for the ESGenCert CLI can be found under the [github releases page](https://github.com/EventStore/es-gencert-cli/releases).
9+
We releases binaries for Windows/ Linux and MacOS.
10+
11+
### Usage
12+
13+
Basic usage for es-gencert-cli:
14+
```
15+
./es-gencert-cli [options] <command> [args]
16+
```
17+
18+
Getting help for a specific command
19+
```
20+
./es-gencert-cli -help <command>
21+
```
22+
e.g.
23+
```
24+
./es-gencert-cli -help create-ca
25+
26+
Usage: create_ca [options]
27+
Generate a root/CA TLS certificate to be used with EventStoreDB
28+
Options:
29+
-days The validity period of the certificate in days (default: 5 years)
30+
-out The output directory (default: ./ca)
31+
```
32+
33+
### Examples
34+
Generating a certificate authority
35+
```
36+
.\es-gencert-cli create-ca -out .\es-ca
37+
```
38+
39+
Generating a certificate for an Event Store Db node
40+
```
41+
.\es-gencert-cli-cli.exe create-node -ca-certificate .\es-ca\ca.crt -ca-key .\es-ca\ca.key -out .\node1 -ip-addresses 127.0.0.1,172.20.240.1 -dns-names eventstore-node1.localhost.com
42+
```
43+
44+
## Development
45+
46+
Building or working on `es-gencert-cli` requires a Go environment, version 1.14 or higher.

Diff for: certificates/certificates.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package certificates
2+
3+
import (
4+
"log"
5+
"os"
6+
"strings"
7+
8+
"github.com/mitchellh/cli"
9+
)
10+
11+
type Certificates struct {
12+
Ui cli.Ui
13+
}
14+
15+
func (command *Certificates) Run(args []string) int {
16+
ui := &cli.BasicUi{
17+
Reader: os.Stdin,
18+
Writer: os.Stdout,
19+
ErrorWriter: os.Stderr,
20+
}
21+
c := cli.NewCLI("Event Store CLI certificates", "")
22+
c.Args = args
23+
c.Commands = map[string]cli.CommandFactory{
24+
"create-ca": func() (cli.Command, error) {
25+
return &CreateCA{
26+
Ui: &cli.ColoredUi{
27+
Ui: ui,
28+
OutputColor: cli.UiColorBlue,
29+
},
30+
}, nil
31+
},
32+
"create-node": func() (cli.Command, error) {
33+
return &CreateNode{
34+
Ui: &cli.ColoredUi{
35+
Ui: ui,
36+
OutputColor: cli.UiColorBlue,
37+
},
38+
}, nil
39+
},
40+
}
41+
exitStatus, err := c.Run()
42+
if err != nil {
43+
log.Println(err)
44+
}
45+
return exitStatus
46+
}
47+
48+
func (c *Certificates) Help() string {
49+
helpText := `
50+
usage: certificates [--help] <command> [<args>]
51+
52+
Available commands:
53+
`
54+
helpText += c.Synopsis()
55+
return strings.TrimSpace(helpText)
56+
}
57+
58+
func (c *Certificates) Synopsis() string {
59+
return "certificates (create_ca, create_node)"
60+
}

Diff for: certificates/common.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package certificates
2+
3+
import (
4+
"crypto/rand"
5+
"crypto/sha256"
6+
"math/big"
7+
)
8+
9+
const defaultKeySize = 2048
10+
11+
func generateSerialNumber(bits uint) (*big.Int, error) {
12+
maxValue := new(big.Int).Lsh(big.NewInt(1), bits)
13+
randValue, err := rand.Int(rand.Reader, maxValue)
14+
if err != nil {
15+
return nil, err
16+
}
17+
return randValue, nil
18+
}
19+
20+
func generateKeyIDFromRSAPublicKey(N *big.Int, e int) []byte {
21+
//according to RFC 3280, the Subject key ID must be derived from the public key
22+
x := new(big.Int).Lsh(N, 32)
23+
x.Add(x, big.NewInt(int64(e)))
24+
h := sha256.New()
25+
h.Write(x.Bytes())
26+
return h.Sum(nil)
27+
}

0 commit comments

Comments
 (0)