Skip to content

Commit

Permalink
add https custom key ctr
Browse files Browse the repository at this point in the history
  • Loading branch information
deepch committed Mar 5, 2021
1 parent 2be23e9 commit 21490d5
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 2 deletions.
28 changes: 27 additions & 1 deletion apiHTTPRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ func HTTPAPIServer() {
if Storage.ServerHTTPDemo() {
public.StaticFS("/static", http.Dir(Storage.ServerHTTPDir()+"/static"))
}
/*
HTTPS Mode Cert
# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048
# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
#openssl ecparam -genkey -name secp384r1 -out server.key
#Generation of self-signed(x509) public key (PEM-encodings .pem|.crt) based on the private (.key)
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
*/
if Storage.ServerHTTPS() {
go func() {
err := public.RunTLS(Storage.ServerHTTPSPort(), Storage.ServerHTTPSCert(), Storage.ServerHTTPSKey())
if err != nil {
log.WithFields(logrus.Fields{
"module": "http_router",
"func": "HTTPSAPIServer",
"call": "ServerHTTPSPort",
}).Fatalln(err.Error())
os.Exit(1)
}
}()
}
err := public.Run(Storage.ServerHTTPPort())
if err != nil {
log.WithFields(logrus.Fields{
Expand All @@ -109,6 +134,7 @@ func HTTPAPIServer() {
}).Fatalln(err.Error())
os.Exit(1)
}

}

//HTTPAPIServerIndex index file
Expand Down Expand Up @@ -236,7 +262,7 @@ func HTTPAPIFullScreenMultiView(c *gin.Context) {
"version": time.Now().String(),
"options": createParams,
"page": "fullscreenmulti",
"query": c.Request.URL.Query(),
"query": c.Request.URL.Query(),
})
}

Expand Down
6 changes: 5 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"http_password": "demo",
"http_port": ":8083",
"log_level": "debug",
"rtsp_port": ":5541"
"rtsp_port": ":5541",
"https": false,
"https_port": ":443",
"https_cert": "server.crt",
"https_key": "server.key"
},
"streams": {
"demo": {
Expand Down
14 changes: 14 additions & 0 deletions server.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN CERTIFICATE-----
MIICGjCCAZ8CCQCLGA2sAHSd1DAKBggqhkjOPQQDAjB2MQswCQYDVQQGEwJERTEN
MAsGA1UECAwEREVNTzENMAsGA1UEBwwEREVNTzENMAsGA1UECgwEREVNTzENMAsG
A1UECwwEREVNTzENMAsGA1UEAwwEREVNTzEcMBoGCSqGSIb3DQEJARYNZGVtb0Bk
ZW1vLmNvbTAeFw0yMTAzMDUxMzIyNDhaFw0zMTAzMDMxMzIyNDhaMHYxCzAJBgNV
BAYTAkRFMQ0wCwYDVQQIDARERU1PMQ0wCwYDVQQHDARERU1PMQ0wCwYDVQQKDARE
RU1PMQ0wCwYDVQQLDARERU1PMQ0wCwYDVQQDDARERU1PMRwwGgYJKoZIhvcNAQkB
Fg1kZW1vQGRlbW8uY29tMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEpQ5/6akj0JiG
CE0sAnWzcecbcgXY74KgG4X4+0Z8YF7B6LwI57yIQD/9LiUvPwHl7rlT9B+s31Ui
ZQ6U0Y5ChES0jeISmLhkAUkGHM8wjPUGRa23FgEgalw/I3+KPMRnMAoGCCqGSM49
BAMCA2kAMGYCMQCLIugTO5xINyl32k1F3edgxun6NLhu/k+c+lvBi8EMcq8aERVC
kPU1hWhF7BD0JfkCMQDS5FzusPPfK7maBF11XXuwBFJ3Zke96mSmpohuTBxT7yfW
TIPP+Rk2MzxMKh/RLHw=
-----END CERTIFICATE-----
9 changes: 9 additions & 0 deletions server.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN EC PARAMETERS-----
BgUrgQQAIg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MIGkAgEBBDDBqBCdv9p3NihNJi3lrVfu700/pXm+tZcm22axGDZZXoWTt5c9k6W7
PzK/0TgZwsmgBwYFK4EEACKhZANiAASlDn/pqSPQmIYITSwCdbNx5xtyBdjvgqAb
hfj7RnxgXsHovAjnvIhAP/0uJS8/AeXuuVP0H6zfVSJlDpTRjkKERLSN4hKYuGQB
SQYczzCM9QZFrbcWASBqXD8jf4o8xGc=
-----END EC PRIVATE KEY-----
28 changes: 28 additions & 0 deletions storageServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,31 @@ func (obj *StorageST) ServerRTSPPort() string {
defer obj.mutex.RUnlock()
return obj.Server.RTSPPort
}

//ServerHTTPSPort read HTTPS Port options
func (obj *StorageST) ServerHTTPS() bool {
obj.mutex.RLock()
defer obj.mutex.RUnlock()
return obj.Server.HTTPS
}

//ServerHTTPSPort read HTTPS Port options
func (obj *StorageST) ServerHTTPSPort() string {
obj.mutex.RLock()
defer obj.mutex.RUnlock()
return obj.Server.HTTPSPort
}

//ServerHTTPSCert read HTTPS Cert options
func (obj *StorageST) ServerHTTPSCert() string {
obj.mutex.RLock()
defer obj.mutex.RUnlock()
return obj.Server.HTTPSCert
}

//ServerHTTPSKey read HTTPS Key options
func (obj *StorageST) ServerHTTPSKey() string {
obj.mutex.RLock()
defer obj.mutex.RUnlock()
return obj.Server.HTTPSKey
}
4 changes: 4 additions & 0 deletions storageStruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ type ServerST struct {
HTTPDir string `json:"http_dir" groups:"api,config"`
HTTPPort string `json:"http_port" groups:"api,config"`
RTSPPort string `json:"rtsp_port" groups:"api,config"`
HTTPS bool `json:"https" groups:"api,config"`
HTTPSPort string `json:"https_port" groups:"api,config"`
HTTPSCert string `json:"https_cert" groups:"api,config"`
HTTPSKey string `json:"https_key" groups:"api,config"`
}

//ServerST stream storage section
Expand Down

0 comments on commit 21490d5

Please sign in to comment.