go-cert-gen/README.md

95 lines
2.7 KiB
Markdown
Raw Normal View History

2023-02-15 19:41:00 +01:00
# go-gen-cert
2023-02-15 19:45:27 +01:00
## Preamble
I've decided to create this project based on [this example](https://github.com/yasushi-saito/grpc-ssl-example/blob/master/go/main.go) but with some improvements, which I would like to give thanks.
I had some trouble during TLS communication between both of my gRPC server and client. I've decided to create a tool to generate SSL certificates following a little of this [guide](https://jamielinux.com/docs/openssl-certificate-authority/create-the-intermediate-pair.html).
## TODO:
2023-02-15 19:47:58 +01:00
- [ ] Create intermediate authority to sign certificates on behalf CA to add more security. If intermediate is hacked then you can revoke from CA and generate new intermediates keeping CA isolated from beeing hacked.
2023-03-08 12:17:48 +01:00
- ~~[x] Complete tests~~
2023-02-15 19:45:27 +01:00
2023-02-15 19:41:00 +01:00
## Configuration
If you are on `dev` environment, like I've been doing, you must create `.env` file similar as `.env.example` in this repo:
```bash
VIPER_CONFIG=your-viper-file-name-without-extension
VIPER_CONFIG_TYPE=yaml
ENV=dev
```
Then add viper configuration file, yaml for example, in your root directory:
```yaml
export_dir: "/home"
ca:
serial_number: 12152 # serial number
subject:
organization: "yourdomain.com"
common_name: "*.yourdomain.com"
key_usage: 1
ext_key_usage:
- 1
- 2
2023-02-20 21:37:22 +01:00
duration: "8760h0m0s" #1 year
2023-02-15 19:41:00 +01:00
client:
serial_number: 12151232 # serial number
subject:
organization: "yourdomain.com"
country: "RM"
province: "REML"
locality: ""
street_address: ""
postal_code: ""
subject_key_id:
- 1
- 2
- 3
- 4
- 6
key_usage: 1
ext_key_usage:
- 1
- 2
2023-02-20 21:37:22 +01:00
duration: "8760h0m0s"
2023-02-15 19:41:00 +01:00
```
## Execution
Then you can just run
```bash
go run main.go
2023-02-15 20:05:21 +01:00
```
2023-03-08 12:17:48 +01:00
## tests
Just simply run make command and watch coverage results on `cover.html` within `coverage`
```shell
make test-coverage
rm -rf coverage
mkdir coverage
go test -v -coverprofile coverage/cover.out ./...
=== RUN TestCredentialsFromKeyWithPasswd
--- PASS: TestCredentialsFromKeyWithPasswd (0.37s)
=== RUN TestCredentialsFromKeyWithPasswdError
--- PASS: TestCredentialsFromKeyWithPasswdError (0.46s)
PASS
coverage: 90.9% of statements
ok gitea.urkob.com/urko/go-grpc-certificate/pkg/credentials 0.839s coverage: 90.9% of statements
go tool cover -html coverage/cover.out -o coverage/cover.html
```
2023-02-15 20:05:21 +01:00
## goreportcard
```bash
make goreportcard
```
output:
```bash
2023-03-03 22:46:10 +01:00
➜ go-cert-gen git:(main) goreportcard-cli -v
Grade .......... A+ 100.0%
Files ................. 12
Issues ................. 0
2023-02-15 20:05:21 +01:00
gofmt ............... 100%
go_vet .............. 100%
gocyclo ............. 100%
ineffassign ......... 100%
2023-03-03 22:46:10 +01:00
license ............. 100%
2023-02-15 20:05:21 +01:00
misspell ............ 100%
2023-02-15 19:41:00 +01:00
```