Skip to content

Commit 2b0db88

Browse files
committed
feat: allow specify multi certs for each vhost
1 parent 24fd705 commit 2b0db88

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

src/app/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func NewApp(params []*param.Param) *App {
7373
// init vhost
7474
listens := p.Listens
7575
if len(listens) == 0 && len(p.ListensPlain) == 0 && len(p.ListensTLS) == 0 {
76-
if p.Certificate == nil {
76+
if len(p.Certificates) == 0 {
7777
listens = []string{":80"}
7878
} else {
7979
listens = []string{":443"}
@@ -84,7 +84,7 @@ func NewApp(params []*param.Param) *App {
8484
Listens: listens,
8585
ListensPlain: p.ListensPlain,
8686
ListensTLS: p.ListensTLS,
87-
Cert: p.Certificate,
87+
Certs: p.Certificates,
8888
HostNames: p.HostNames,
8989
Handler: vhHandler.Handler,
9090
})

src/param/cli.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"../serverErrHandler"
66
"../util"
77
"../version"
8-
"errors"
98
"fmt"
109
"os"
1110
"strings"
@@ -119,10 +118,10 @@ func init() {
119118
err = options.AddFlag("usermatchcase", "--user-match-case", "GHFS_USER_MATCH_CASE", "username should be case sensitive")
120119
serverErrHandler.CheckFatal(err)
121120

122-
err = options.AddFlagsValue("key", []string{"-k", "--key"}, "GHFS_KEY", "", "TLS certificate key path")
121+
err = options.AddFlagsValues("certs", []string{"-c", "--cert"}, "GHFS_CERT", nil, "TLS certificate path")
123122
serverErrHandler.CheckFatal(err)
124123

125-
err = options.AddFlagsValue("cert", []string{"-c", "--cert"}, "GHFS_CERT", "", "TLS certificate path")
124+
err = options.AddFlagsValues("keys", []string{"-k", "--key"}, "GHFS_KEY", nil, "TLS certificate key path")
126125
serverErrHandler.CheckFatal(err)
127126

128127
err = options.AddFlagsValues("listens", []string{"-l", "--listen"}, "GHFS_LISTEN", nil, "address and port to listen")
@@ -276,18 +275,13 @@ func doParseCli() []*Param {
276275
param.GlobalHeaders = entriesToHeaders(globalHeaders)
277276

278277
// certificate
279-
key, _ := result.GetString("key")
280-
cert, _ := result.GetString("cert")
281-
if len(key) > 0 && len(cert) > 0 {
282-
var err error
283-
param.Certificate, err = LoadCertificate(cert, key)
284-
if err != nil {
285-
serverErrHandler.CheckFatal(err)
286-
}
287-
} else if len(key) > 0 && len(cert) == 0 {
288-
serverErrHandler.CheckFatal(errors.New("missing certificate file"))
289-
} else if len(key) == 0 && len(cert) > 0 {
290-
serverErrHandler.CheckFatal(errors.New("missing certificate key file"))
278+
certFiles, _ := result.GetStrings("certs")
279+
keyFiles, _ := result.GetStrings("keys")
280+
certs, errs := LoadCertificates(certFiles, keyFiles)
281+
if len(errs) > 0 {
282+
serverErrHandler.CheckFatal(errs...)
283+
} else {
284+
param.Certificates = certs
291285
}
292286

293287
// normalize aliases

src/param/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type Param struct {
5252
UsersSha512 []*user
5353
UserMatchCase bool
5454

55-
Certificate *tls.Certificate
55+
Certificates []tls.Certificate
5656
Listens []string
5757
ListensPlain []string
5858
ListensTLS []string

src/param/objUtil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"strings"
99
)
1010

11-
func LoadCertificate(certFile, keyFile string) (*tls.Certificate, error) {
12-
return goVirtualHost.LoadCertificate(certFile, keyFile)
11+
func LoadCertificates(certFiles, keyFiles []string) ([]tls.Certificate, []error) {
12+
return goVirtualHost.LoadCertificates(certFiles, keyFiles)
1313
}
1414

1515
func EntriesToUsers(entries []string) []*user {

0 commit comments

Comments
 (0)