refine cert config in http

pull/168/head
v2ray 2016-05-07 10:06:12 +02:00
parent 67db5830be
commit 301b0ccff7
2 changed files with 32 additions and 8 deletions

View File

@ -1,13 +1,19 @@
package http package http
import ( import (
"crypto/tls"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
) )
type CertificateConfig struct {
Domain string
Certificate tls.Certificate
}
type TlsConfig struct { type TlsConfig struct {
Enabled bool Enabled bool
CertFile string Certs []*CertificateConfig
KeyFile string
} }
type Config struct { type Config struct {

View File

@ -3,17 +3,36 @@
package http package http
import ( import (
"crypto/tls"
"encoding/json" "encoding/json"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy/internal/config" "github.com/v2ray/v2ray-core/proxy/internal/config"
) )
func (this *CertificateConfig) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
Domain string `json:"domain"`
CertFile string `json:"cert"`
KeyFile string `json:"key"`
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
cert, err := tls.LoadX509KeyPair(jsonConfig.CertFile, jsonConfig.KeyFile)
if err != nil {
return err
}
this.Domain = jsonConfig.Domain
this.Certificate = cert
}
func (this *TlsConfig) UnmarshalJSON(data []byte) error { func (this *TlsConfig) UnmarshalJSON(data []byte) error {
type JsonConfig struct { type JsonConfig struct {
Enabled bool Enabled bool `json:"enable"`
CertFile string Certs []*CertificateConfig `json:"certs"`
KeyFile string
} }
jsonConfig := new(JsonConfig) jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil { if err := json.Unmarshal(data, jsonConfig); err != nil {
@ -21,8 +40,7 @@ func (this *TlsConfig) UnmarshalJSON(data []byte) error {
} }
this.Enabled = jsonConfig.Enabled this.Enabled = jsonConfig.Enabled
this.CertFile = jsonConfig.CertFile this.Certs = jsonConfig.Certs
this.KeyFile = jsonConfig.KeyFile
return nil return nil
} }