This package is a golang command line tool implementation of self-signing certificates.
Also, we expected to link third party CA certificates to generate certificates in the future.
gantt
title 2024
dateFormat MM-DD
axisFormat %m-%d
section v1.0.0
private key: active, private-key, 11-13, 1d
csr: active, csr, 11-13, 1d
certificate: active, certificate, 11-13, 2d
Release: milestone, after certificate
section v2.0.0
cobra cmd: active, cobra-cmd, 11-14, 1d
test: done, test, 11-14, 2d
Release: milestone, after test
section v2.x.x
TBA: active, TBA, 11-16, 2d
section v3.0.0
third party: crit, third-party, 11-18, 1d
Type | Version |
---|---|
OS | ubuntu 22.04.5 |
Golang | go1.22.5 linux/amd64 |
-
Prepare the destination directory for the private key, certificate, and CSR. This step is required for all the following steps.
-
Modify the
cfg.yml
file to set the appropriate values(you can use thedefaultCfg.yml
file as your template). -
Import the
certgo
package in your code.import "github.com/Alonza0314/cert-go"
-
For create private key, you need to specify the path of the destination file. Then, use this function:
CreatePrivateKey(keyPath string) (*ecdsa.PrivateKey, error)
The return value is the private key in
*ecdsa.PrivateKey
type. -
For create csr, you need to specify the certificate structure. You can use
ReadYamlFileToStruct
function to read the configuration file and convert it to the certificate structure.util.ReadYamlFileToStruct(yamlPath string, v interface{}) error
Then, use this function:
CreateCsr(cfg model.Certificate) (*x509.CertificateRequest, error)
The return value is the csr in
*x509.CertificateRequest
type.NOTICE:
- If the private key is not existed, the function will automatically create one in default.
-
For sign certificate, you need to specify the yaml file path of the CA configuration. Then, use these functions for different types of certificates:
SignRootCertificate(yamlPath string) ([]byte, error) SignIntermediateCertificate(yamlPath string) ([]byte, error) SignServerCertificate(yamlPath string) ([]byte, error) SignClientCertificate(yamlPath string) ([]byte, error)
The return value is the signed certificate in
[]byte
type after encoding to PEM format.NOTICE:
- If the private key is not existed, the function will automatically create one in default.
- If the csr is not existed, the function will automatically create one in default.
-
In the end, it is expected to see the private key, certificate, and csr in the destination directory.
go test ./... -v
./build_cmd.sh
Then, you can find the executable file in the build
directory.
You can download the binary file from the release page and execute it directly.
Go to the release page to download the binary file