Skip to content

Commit 339ee13

Browse files
committed
Certificate Authority work
1 parent ae00ab0 commit 339ee13

35 files changed

+735
-134
lines changed

backend/embed/api_docs/components/CertificateAuthorityObject.json

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
"created_on",
88
"modified_on",
99
"name",
10-
"acme2_url"
10+
"acmesh_server",
11+
"ca_bundle",
12+
"max_domains",
13+
"is_wildcard_supported",
14+
"is_setup"
1115
],
1216
"properties": {
1317
"id": {
@@ -27,10 +31,25 @@
2731
"minLength": 1,
2832
"maxLength": 100
2933
},
30-
"acme2_url": {
34+
"acmesh_server": {
3135
"type": "string",
32-
"minLength": 8,
36+
"minLength": 2,
3337
"maxLength": 255
38+
},
39+
"ca_bundle": {
40+
"type": "string",
41+
"minLength": 0,
42+
"maxLength": 255
43+
},
44+
"max_domains": {
45+
"type": "integer",
46+
"minimum": 1
47+
},
48+
"is_wildcard_supported": {
49+
"type": "boolean"
50+
},
51+
"is_setup": {
52+
"type": "boolean"
3453
}
3554
}
3655
}

backend/embed/api_docs/components/CertificateObject.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
"type": "integer",
5050
"minimum": 0
5151
},
52+
"certificate_authority": {
53+
"$ref": "#/components/schemas/CertificateAuthorityObject"
54+
},
5255
"dns_provider_id": {
5356
"type": "integer",
5457
"minimum": 0

backend/embed/api_docs/paths/certificates-authorities/caID/get.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@
3737
"value": {
3838
"result": {
3939
"id": 1,
40-
"created_on": 1602588511,
41-
"modified_on": 1602588511,
42-
"name": "Let's Encrypt",
43-
"acme2_url": "https://acme-v02.api.letsencrypt.org/directory"
40+
"created_on": 1627531400,
41+
"modified_on": 1627531400,
42+
"name": "ZeroSSL",
43+
"acmesh_server": "zerossl",
44+
"ca_bundle": "",
45+
"max_domains": 10,
46+
"is_wildcard_supported": true,
47+
"is_setup": false
4448
}
4549
}
4650
}

backend/embed/api_docs/paths/certificates-authorities/caID/put.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@
4646
"value": {
4747
"result": {
4848
"id": 1,
49-
"created_on": 1602588511,
50-
"modified_on": 1602588511,
51-
"name": "Let's Encrypt",
52-
"acme2_url": "https://acme-v02.api.letsencrypt.org/directory"
49+
"created_on": 1627531400,
50+
"modified_on": 1627531400,
51+
"name": "ZeroSSL",
52+
"acmesh_server": "zerossl",
53+
"ca_bundle": "",
54+
"max_domains": 10,
55+
"is_wildcard_supported": true,
56+
"is_setup": false
5357
}
5458
}
5559
}

backend/embed/api_docs/paths/certificates-authorities/get.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,25 @@
6464
"items": [
6565
{
6666
"id": 1,
67-
"created_on": 1602588511,
68-
"modified_on": 1602588511,
69-
"name": "Let's Encrypt",
70-
"acme2_url": "https://acme-v02.api.letsencrypt.org/directory"
67+
"created_on": 1627531400,
68+
"modified_on": 1627531400,
69+
"name": "ZeroSSL",
70+
"acmesh_server": "zerossl",
71+
"ca_bundle": "",
72+
"max_domains": 10,
73+
"is_wildcard_supported": true,
74+
"is_setup": false
7175
},
7276
{
7377
"id": 2,
74-
"created_on": 1602588511,
75-
"modified_on": 1602588511,
76-
"name": "Let's Encrypt (Staging)",
77-
"acme2_url": "https://acme-staging-v02.api.letsencrypt.org/directory"
78+
"created_on": 1627531400,
79+
"modified_on": 1627531400,
80+
"name": "Let's Encrypt",
81+
"acmesh_server": "https://acme-v02.api.letsencrypt.org/directory",
82+
"ca_bundle": "",
83+
"max_domains": 10,
84+
"is_wildcard_supported": true,
85+
"is_setup": false
7886
}
7987
]
8088
}

backend/embed/api_docs/paths/certificates-authorities/post.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@
3232
"default": {
3333
"value": {
3434
"result": {
35-
"id": 3,
36-
"created_on": 1602588900,
37-
"modified_on": 1602588900,
38-
"name": "Boulder",
39-
"acme2_url": "https://boulder.local/directory"
35+
"id": 1,
36+
"created_on": 1627531400,
37+
"modified_on": 1627531400,
38+
"name": "ZeroSSL",
39+
"acmesh_server": "zerossl",
40+
"ca_bundle": "",
41+
"max_domains": 10,
42+
"is_wildcard_supported": true,
43+
"is_setup": false
4044
}
4145
}
4246
}

backend/embed/migrations/20201013035318_initial_schema.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ CREATE TABLE IF NOT EXISTS `certificate_authority`
5656
created_on INTEGER NOT NULL DEFAULT 0,
5757
modified_on INTEGER NOT NULL DEFAULT 0,
5858
name TEXT NOT NULL,
59-
acme2_url TEXT NOT NULL,
59+
acmesh_server TEXT NOT NULL DEFAULT "",
60+
is_setup INTEGER NOT NULL DEFAULT 0,
61+
ca_bundle TEXT NOT NULL DEFAULT "",
62+
is_wildcard_supported INTEGER NOT NULL DEFAULT 0, -- specific to each CA, acme v1 doesn't usually have wildcards
63+
max_domains INTEGER NOT NULL DEFAULT 5, -- per request
6064
is_deleted INTEGER NOT NULL DEFAULT 0
6165
);
6266

backend/embed/migrations/20201013035839_initial_data.sql

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,51 @@ INSERT INTO `certificate_authority` (
3636
created_on,
3737
modified_on,
3838
name,
39-
acme2_url
39+
acmesh_server,
40+
is_wildcard_supported,
41+
max_domains
4042
) VALUES (
43+
strftime('%s', 'now'),
44+
strftime('%s', 'now'),
45+
"ZeroSSL",
46+
"zerossl",
47+
1,
48+
10
49+
), (
4150
strftime('%s', 'now'),
4251
strftime('%s', 'now'),
4352
"Let's Encrypt",
44-
"https://acme-v02.api.letsencrypt.org/directory"
53+
"https://acme-v02.api.letsencrypt.org/directory",
54+
1,
55+
10
56+
), (
57+
strftime('%s', 'now'),
58+
strftime('%s', 'now'),
59+
"Buypass Go SSL",
60+
"https://api.buypass.com/acme/directory",
61+
0,
62+
5
63+
), (
64+
strftime('%s', 'now'),
65+
strftime('%s', 'now'),
66+
"Let's Encrypt (Testing)",
67+
"https://acme-staging-v02.api.letsencrypt.org/directory",
68+
1,
69+
10
4570
), (
4671
strftime('%s', 'now'),
4772
strftime('%s', 'now'),
48-
"Let's Encrypt (Staging)",
49-
"https://acme-staging-v02.api.letsencrypt.org/directory"
73+
"Buypass Go SSL (Testing)",
74+
"https://api.test4.buypass.no/acme/directory",
75+
0,
76+
5
77+
), (
78+
strftime('%s', 'now'),
79+
strftime('%s', 'now'),
80+
"SSL.com",
81+
"ssl.com",
82+
0,
83+
10
5084
);
5185

52-
5386
-- migrate:down
54-
55-
-- Not allowed to go down from initial

backend/internal/acme/acmesh.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var acmeShFile string
1717

1818
// GetAcmeShVersion will return the acme.sh script version
1919
func GetAcmeShVersion() string {
20-
if r, err := acmeShExec("--version"); err == nil {
20+
if r, err := shExec("--version"); err == nil {
2121
// modify the output
2222
r = strings.Trim(r, "\n")
2323
v := strings.Split(r, "\n")
@@ -26,13 +26,15 @@ func GetAcmeShVersion() string {
2626
return ""
2727
}
2828

29-
func acmeShExec(args ...string) (string, error) {
29+
// shExec executes the acme.sh with arguments
30+
func shExec(args ...string) (string, error) {
3031
if _, err := os.Stat(acmeShFile); os.IsNotExist(err) {
3132
e := fmt.Errorf("%s does not exist", acmeShFile)
3233
logger.Error("AcmeShError", e)
3334
return "", e
3435
}
3536

37+
logger.Debug("CMD: %s %v", acmeShFile, args)
3638
// nolint: gosec
3739
c := exec.Command(acmeShFile, args...)
3840
b, e := c.Output()
@@ -61,3 +63,33 @@ func WriteAcmeSh() {
6163
logger.Info("Wrote %s", acmeShFile)
6264
}
6365
}
66+
67+
// RequestCert does all the heavy lifting
68+
func RequestCert(domains []string, method string) error {
69+
args := []string{"--issue"}
70+
71+
webroot := "/home/wwwroot/example.com"
72+
73+
// Add domains to args
74+
for _, ___domain := range domains {
75+
args = append(args, "-d", ___domain)
76+
}
77+
78+
switch method {
79+
// case "dns":
80+
case "http":
81+
args = append(args, "-w", webroot)
82+
83+
default:
84+
return fmt.Errorf("RequestCert method not supported: %s", method)
85+
}
86+
87+
ret, err := shExec(args...)
88+
if err != nil {
89+
return err
90+
}
91+
92+
logger.Debug("ret: %+v", ret)
93+
94+
return nil
95+
}

backend/internal/api/schema/create_certificate_authority.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ func CreateCertificateAuthority() string {
1010
"additionalProperties": false,
1111
"required": [
1212
"name",
13-
"acme2_url"
13+
"acmesh_server",
14+
"max_domains"
1415
],
1516
"properties": {
1617
"name": %s,
17-
"acme2_url": %s
18+
"acmesh_server": %s,
19+
"max_domains": %s
1820
}
1921
}
20-
`, stringMinMax(1, 100), stringMinMax(8, 255))
22+
`, stringMinMax(1, 100), stringMinMax(2, 255), intMinOne)
2123
}

0 commit comments

Comments
 (0)