Skip to content

Commit 635aaad

Browse files
authored
Merge pull request #213 from zigbee-alliance/light-client-proxy-tls
Support TLS for Light Client Proxy
2 parents 8b16bff + eea6bf2 commit 635aaad

File tree

2 files changed

+34
-513
lines changed

2 files changed

+34
-513
lines changed

cmd/dcld/cmd/light.go

+34-17
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,25 @@ import (
3131
// mostly copied from https://github.com/tendermint/tendermint/blob/master/cmd/tendermint/commands/light.go
3232

3333
const (
34-
FlagListenAddr = "laddr"
35-
FlagPrimary = "primary"
36-
FlagPrimaryShort = "p"
37-
FlagWitness = "witnesses"
38-
FlagWitnessShort = "w"
39-
FlagHeight = "height"
40-
FlagHash = "hash"
41-
FlagDir = "dir"
42-
FlagDirShort = "d"
43-
FlagLogLevel = "log-level"
44-
FlagSeq = "sequential"
45-
FlagTrustLevel = "trust-level"
46-
FlagMaxConn = "max-open-connections"
47-
FlagTrustPeriod = "trusting-period"
48-
FlagStartTimeout = "start-timeout"
34+
FlagListenAddr = "laddr"
35+
FlagPrimary = "primary"
36+
FlagPrimaryShort = "p"
37+
FlagWitness = "witnesses"
38+
FlagWitnessShort = "w"
39+
FlagHeight = "height"
40+
FlagHash = "hash"
41+
FlagDir = "dir"
42+
FlagDirShort = "d"
43+
FlagLogLevel = "log-level"
44+
FlagSeq = "sequential"
45+
FlagTrustLevel = "trust-level"
46+
FlagMaxConn = "max-open-connections"
47+
FlagTrustPeriod = "trusting-period"
48+
FlagStartTimeout = "start-timeout"
49+
FlagTlsCertFile = "tls-cert-file"
50+
FlagTlsCertFileShort = "c"
51+
FlagTlsKeyFile = "tls-key-file"
52+
FlagTlsKeyFileShort = "k"
4953
)
5054

5155
// LightCmd represents the base command when called without any subcommands.
@@ -97,6 +101,9 @@ var (
97101
witnessesKey = []byte("witnesses")
98102

99103
startTimeout int64
104+
105+
tlsCertFile string
106+
tlsKeyFile string
100107
)
101108

102109
func init() {
@@ -127,6 +134,9 @@ func init() {
127134
)
128135
LightCmd.Flags().Int64Var(&startTimeout, FlagStartTimeout, 0,
129136
"How many seconds to wait before starting the light client proxy. Mostly for test purposes when light client is started at the same time as the pool.")
137+
138+
LightCmd.Flags().StringVarP(&tlsCertFile, FlagTlsCertFile, FlagTlsCertFileShort, "", "Path to the TLS certificate file")
139+
LightCmd.Flags().StringVarP(&tlsKeyFile, FlagTlsKeyFile, FlagTlsKeyFileShort, "", "Path to the TLS key file")
130140
}
131141

132142
func runProxy(cmd *cobra.Command, args []string) error {
@@ -252,8 +262,15 @@ func runProxy(cmd *cobra.Command, args []string) error {
252262
p.Listener.Close()
253263
}()
254264

255-
logger.Info("Starting proxy...", "laddr", listenAddr)
256-
if err := p.ListenAndServe(); errors.Is(err, http.ErrServerClosed) {
265+
if tlsCertFile != "" && tlsKeyFile != "" {
266+
logger.Info("Starting Light Client Proxy over TLS/HTTPS...", "laddr", listenAddr)
267+
err = p.ListenAndServeTLS(tlsCertFile, tlsKeyFile)
268+
} else {
269+
logger.Info("Starting Light Client Proxy over HTTP...", "laddr", listenAddr)
270+
err = p.ListenAndServe()
271+
}
272+
273+
if errors.Is(err, http.ErrServerClosed) {
257274
// Error starting or closing listener:
258275
logger.Error("proxy ListenAndServe", "err", err)
259276
}

0 commit comments

Comments
 (0)