• R/O
  • HTTP
  • SSH
  • HTTPS

bytom: Commit

Official Go implementation of the Bytom protocol


Commit MetaInfo

Révisiond78c99f2eff51ab555e4f8810ce893c8e4807609 (tree)
l'heure2020-12-26 16:21:41
AuteurLonelyPale <lonelypale@126....>
CommiterLonelyPale

Message de Log

api server add https support

Change Summary

Modification

--- a/api/api.go
+++ b/api/api.go
@@ -164,8 +164,16 @@ func (a *API) StartServer(address string) {
164164 // it's blocking and we need to proceed to the rest of the core setup after
165165 // we call it.
166166 go func() {
167- if err := a.server.Serve(listener); err != nil {
168- log.WithFields(log.Fields{"module": logModule, "error": errors.Wrap(err, "Serve")}).Error("Rpc server")
167+ if cfg.CommonConfig.Https.EnableTLS {
168+ certFile := cfg.CommonConfig.RootDir + "/" + cfg.CommonConfig.Https.CertFile
169+ keyFile := cfg.CommonConfig.RootDir + "/" + cfg.CommonConfig.Https.KeyFile
170+ if err = a.server.ServeTLS(listener, certFile, keyFile); err != nil {
171+ log.WithFields(log.Fields{"module": logModule, "error": errors.Wrap(err, "ServeTLS")}).Error("Rpc server")
172+ }
173+ } else {
174+ if err := a.server.Serve(listener); err != nil {
175+ log.WithFields(log.Fields{"module": logModule, "error": errors.Wrap(err, "Serve")}).Error("Rpc server")
176+ }
169177 }
170178 }()
171179 }
--- a/config/config.go
+++ b/config/config.go
@@ -28,6 +28,7 @@ type Config struct {
2828 Web *WebConfig `mapstructure:"web"`
2929 Simd *SimdConfig `mapstructure:"simd"`
3030 Websocket *WebsocketConfig `mapstructure:"ws"`
31+ Https *HttpsConfig `mapstructure:"https"`
3132 }
3233
3334 // Default configurable parameters.
@@ -205,6 +206,13 @@ type WebsocketConfig struct {
205206 MaxNumConcurrentReqs int `mapstructure:"max_num_concurrent_reqs"`
206207 }
207208
209+// enable https
210+type HttpsConfig struct {
211+ EnableTLS bool `mapstructure:"enable_tls"`
212+ CertFile string `mapstructure:"cert_file"`
213+ KeyFile string `mapstructure:"key_file"`
214+}
215+
208216 // Default configurable rpc's auth parameters.
209217 func DefaultRPCAuthConfig() *RPCAuthConfig {
210218 return &RPCAuthConfig{
@@ -243,6 +251,14 @@ func DefaultWebsocketConfig() *WebsocketConfig {
243251 }
244252 }
245253
254+func DefaultHttpsConfig() *HttpsConfig {
255+ return &HttpsConfig{
256+ EnableTLS: false,
257+ CertFile: "key/cert.pem",
258+ KeyFile: "key/key.pem",
259+ }
260+}
261+
246262 //-----------------------------------------------------------------------------
247263 // Utils
248264
--- a/config/toml.go
+++ b/config/toml.go
@@ -1,6 +1,8 @@
11 package config
22
33 import (
4+ "os"
5+ "os/exec"
46 "path"
57
68 cmn "github.com/tendermint/tmlibs/common"
@@ -17,6 +19,16 @@ func EnsureRoot(rootDir string, network string) {
1719 if !cmn.FileExists(configFilePath) {
1820 cmn.MustWriteFile(configFilePath, []byte(selectNetwork(network)), 0644)
1921 }
22+
23+ cmn.EnsureDir(rootDir+"/key", 0700)
24+ if err := os.Chdir(rootDir + "/key"); err != nil {
25+ panic(err)
26+ }
27+
28+ cmd := exec.Command("/bin/bash", "-c", `go run $GOROOT/src/crypto/tls/generate_cert.go --host="localhost"`)
29+ if err := cmd.Run(); err != nil {
30+ panic(err)
31+ }
2032 }
2133
2234 var defaultConfigTmpl = `# This is a TOML config file.
@@ -45,14 +57,21 @@ laddr = "tcp://0.0.0.0:46658"
4557 seeds = ""
4658 `
4759
60+var httpsConfigTmpl = `
61+[https]
62+enable_tls = true
63+cert_file = "key/cert.pem"
64+key_file = "key/key.pem"
65+`
66+
4867 // Select network seeds to merge a new string.
4968 func selectNetwork(network string) string {
5069 switch network {
5170 case "mainnet":
52- return defaultConfigTmpl + mainNetConfigTmpl
71+ return defaultConfigTmpl + mainNetConfigTmpl + httpsConfigTmpl
5372 case "testnet":
54- return defaultConfigTmpl + testNetConfigTmpl
73+ return defaultConfigTmpl + testNetConfigTmpl + httpsConfigTmpl
5574 default:
56- return defaultConfigTmpl + soloNetConfigTmpl
75+ return defaultConfigTmpl + soloNetConfigTmpl + httpsConfigTmpl
5776 }
5877 }
--- /dev/null
+++ b/notes.md
@@ -0,0 +1,14 @@
1+# 信通院安全评测版本
2+
3+```shell script
4+root
5+123456
6+
7+make bytomd
8+make install
9+
10+bytomd init --chain_id testnet
11+bytomd node --auth.disable
12+
13+curl -k https://localhost:9888/net-info
14+```
Afficher sur ancien navigateur de dépôt.