Skip to content

Commit 6f6fbfb

Browse files
authored
feature: ec crt/refactor cmd/add info/version command (#2)
* feat: support ec/refactor cmd * feat: info subcommand * feat: version subcommand * fix: docs update, some bugfix Signed-off-by: xiexianbin <me@xiexianbin.cn>
1 parent e3f360e commit 6f6fbfb

File tree

20 files changed

+1454
-664
lines changed

20 files changed

+1454
-664
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
1616
.DS_Store
17-
bin/
1817
.history/
1918
.idea/
2019
.lh/
20+
bin/
21+
vendor
2122
x-ca

Makefile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,40 +69,40 @@ clean: ## Run clean bin files
6969

7070
.PHONY: build
7171
build: ## Build for current os
72-
${SUB_BUILD_CMD} -o bin/$(BINARY_NAME)
72+
${SUB_BUILD_CMD} -o bin/$(BINARY_NAME) ./cmd/...
7373

7474
.PHONY: linux-amd64
7575
linux-amd64: ## Build linux amd64
76-
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@
76+
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ ./cmd/...
7777

7878
.PHONY: linux-arm64
7979
linux-arm64: ## Build linux arm64
80-
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@
80+
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ ./cmd/...
8181

8282
.PHONY: linux-ppc64le
8383
linux-ppc64le: ## Build linux ppc64le
84-
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@
84+
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ ./cmd/...
8585

8686
.PHONY: linux-s390x
8787
linux-s390x: ## Build linux s390x
88-
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@
88+
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ ./cmd/...
8989

9090
.PHONY: darwin-amd64
9191
darwin-amd64: ## Build darwin amd64
92-
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@
92+
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ ./cmd/...
9393

9494
.PHONY: darwin-arm64
9595
darwin-arm64: ## Build darwin arm64
96-
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@
96+
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ ./cmd/...
9797

9898
.PHONY: windows-amd64
9999
windows-amd64: ## Build windows amd64
100-
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@.exe
100+
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@.exe ./cmd/...
101101

102-
.PHONY: docker-build
103-
docker-build: test ## Build docker image
104-
docker build -t ${IMG} .
102+
# .PHONY: docker-build
103+
# docker-build: test ## Build docker image
104+
# docker build -t ${IMG} .
105105

106-
.PHONY: docker-push
107-
docker-push: ## Push docker image
108-
docker push ${IMG}
106+
# .PHONY: docker-push
107+
# docker-push: ## Push docker image
108+
# docker push ${IMG}

README.md

Lines changed: 75 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
golang x-ca client, which can simple Sign Self Root/Second-Level CA, and sign for Domains and IPs.
88

9-
shell implement at [x-ca/x-ca](https://github.com/x-ca/x-ca)
9+
- shell implement at [x-ca/x-ca](https://github.com/x-ca/x-ca)
10+
- [import Self Sign CA To System](https://www.xiexianbin.cn/http/ssl/2017-02-15-openssl-self-sign-ca/#导出导入自签名证书) `x-ca/ca/root-ca.crt` and `x-ca/ca/tls-ca.crt` to trust Your CA.
1011

1112
## install
1213

@@ -19,81 +20,70 @@ mv xca /usr/local/bin/
1920
## Help
2021

2122
```
22-
$ xca --help
23-
Create Root CA and TLS CA:
24-
xca -create-ca true \
25-
-root-cert x-ca/ca/root-ca.crt \
26-
-root-key x-ca/ca/root-ca/private/root-ca.key \
27-
-tls-cert x-ca/ca/tls-ca.crt \
28-
-tls-key x-ca/ca/tls-ca/private/tls-ca.key \
29-
-tls-chain x-ca/ca/tls-ca-chain.pem
30-
31-
Sign Domains or Ips:
32-
xca -cn xxxx \
33-
--domains "xxx,xxx" --ips "xxx,xxx" \
34-
-tls-cert x-ca/ca/tls-ca.crt \
35-
-tls-key x-ca/ca/tls-ca/private/tls-ca.key \
36-
-tls-chain x-ca/ca/tls-ca-chain.pem
37-
38-
Usage:
39-
-cn string
40-
sign cert common name.
41-
-create-ca
42-
Create Root CA.
43-
-domains string
44-
Comma-Separated domain names.
45-
-help
46-
show help message
47-
-ips string
48-
Comma-Separated IP addresses.
49-
-root-cert string
50-
Root certificate file path, PEM format. (default "x-ca/ca/root-ca.crt")
51-
-root-key string
52-
Root private key file path, PEM format. (default "x-ca/ca/root-ca/private/root-ca.key")
53-
-tls-cert string
54-
Second-Level certificate file path, PEM format. (default "x-ca/ca/tls-ca.crt")
55-
-tls-chain string
56-
Root/Second-Level CA Chain file path, PEM format. (default "x-ca/ca/tls-ca-chain.pem")
57-
-tls-key string
58-
Second-Level private key file path, PEM format. (default "x-ca/ca/tls-ca/private/tls-ca.key")
59-
-tls-key-password string
60-
tls key password, only work for load github.com/x-ca/x-ca.
61-
-version
62-
show version info.
63-
64-
Source Code:
65-
https://github.com/x-ca/go-ca
23+
xca --help
24+
xca create-ca --help
25+
xca sign --help
6626
```
6727

68-
## Usage Demo
69-
70-
- create ca
71-
72-
```
73-
xca -create-ca true \
74-
-root-cert x-ca/ca/root-ca.crt \
75-
-root-key x-ca/ca/root-ca/private/root-ca.key \
76-
-tls-cert x-ca/ca/tls-ca.crt \
77-
-tls-key x-ca/ca/tls-ca/private/tls-ca.key
7828
```
29+
$ xca --help
30+
XCA is a command-line tool for creating and managing Root/Second-Level Certificate Authorities (CAs)
31+
and signing certificates for domains and IP addresses.
7932
80-
[install](https://www.xiexianbin.cn/http/ssl/2017-02-15-openssl-self-sign-ca/#导出导入自签名证书) `x-ca/ca/root-ca.crt` and `x-ca/ca/tls-ca.crt` to trust Your CA.
33+
Available Commands:
34+
create-ca Create root and TLS CA certificates
35+
info Display information about Certificates
36+
sign Sign a certificate for domains and/or IPs
37+
version Show version information
8138
82-
- or use x-ca
39+
Environment:
40+
XCA_ROOT_PATH Which path to store Root/Second-Level/TLS cert, default is "$(pwd)/x-ca"
8341
42+
Examples:
43+
xca create-ca --key-type ec --curve P256
44+
xca sign example.com --domains "example.com,www.example.com"
45+
xca sign 192.168.1.1 --ips "192.168.1.1"
46+
47+
Source Code:
48+
https://github.com/x-ca/go-ca
8449
```
85-
mkdir path
86-
git clone git@github.com:x-ca/ca.git x-ca
87-
```
8850

89-
- sign domain
51+
## Usage Demo
52+
53+
You can specify the key type (`-key-type`) and curve (`-curve`) to create an EC root CA and TLS CA:
9054

9155
```
92-
xca -cn xiexianbin.cn \
93-
--domains "*.xiexianbin.cn,*.80.xyz" \
94-
--ips 100.80.0.128 \
95-
-tls-cert x-ca/ca/tls-ca.crt \
96-
-tls-key x-ca/ca/tls-ca/private/[tls-ca.key | tls-ca-des3.key]
56+
# Create EC CA
57+
$ xca create-ca --key-type ec --curve P256
58+
59+
# default out `x-ca/...`
60+
$ tree x-ca
61+
x-ca
62+
└── ca
63+
├── root-ca
64+
│ └── private
65+
│ └── root-ca.key
66+
├── root-ca.crt
67+
├── tls-ca
68+
│ └── private
69+
│ └── tls-ca.key
70+
├── tls-ca-chain.pem
71+
└── tls-ca.crt
72+
73+
6 directories, 5 files
74+
75+
# Show CA info
76+
$ xca info ./x-ca/ca/root-ca.crt
77+
$ xca info ./x-ca/ca/tls-ca.crt
78+
79+
# Sign Domains certificate
80+
xca sign example.com --domains "example.com,www.example.com"
81+
82+
# Sign Domains and IPs certificate
83+
$ xca sign xiexianbin.cn --ips "192.168.1.1,*.xiexianbin.cn,*.dev.xiexianbin.cn"
84+
85+
# Show TLS cert info
86+
$ xca info ./x-ca/certs/xiexianbin.cn/xiexianbin.cn.crt
9787
```
9888

9989
- test cert
@@ -107,7 +97,25 @@ docker run -it -d \
10797
nginx
10898
```
10999

110-
visit https://dev.xiexianbin.cn:8443/
100+
- to verify, visit https://dev.xiexianbin.cn:8443/ in brower or run command:
101+
102+
```
103+
curl -i -v -k https://dev.xiexianbin.cn:8443/ --resolve dev.xiexianbin.cn:8443:127.0.0.1
104+
```
105+
106+
## Dev
107+
108+
- core file
109+
110+
```
111+
go.mod - Added cobra dependency
112+
ca/baseca.go - Common CA functionality
113+
ca/common.go - Shared utilities
114+
cmd/create.go - create-ca command
115+
cmd/sign.go - sign command
116+
cmd/root.go - root cobra command
117+
cmd/xca.go - main entry point (refactored)
118+
```
111119

112120
## FaQ
113121

0 commit comments

Comments
 (0)