Ejemplo n.º 1
0
func (this *TLSConfig) Build() (*loader.TypedSettings, error) {
	config := new(tls.Config)
	config.Certificate = make([]*tls.Certificate, len(this.Certs))
	for idx, certConf := range this.Certs {
		cert, err := ioutil.ReadFile(certConf.CertFile)
		if err != nil {
			return nil, errors.New("TLS: Failed to load certificate file: " + err.Error())
		}
		key, err := ioutil.ReadFile(certConf.KeyFile)
		if err != nil {
			return nil, errors.New("TLS: Failed to load key file: " + err.Error())
		}
		config.Certificate[idx] = &tls.Certificate{
			Key:         key,
			Certificate: cert,
		}
	}
	config.AllowInsecure = this.Insecure
	return loader.NewTypedSettings(config), nil
}
Ejemplo n.º 2
0
func (v *TLSConfig) Build() (*serial.TypedMessage, error) {
	config := new(tls.Config)
	config.Certificate = make([]*tls.Certificate, len(v.Certs))
	for idx, certConf := range v.Certs {
		cert, err := ioutil.ReadFile(certConf.CertFile)
		if err != nil {
			return nil, errors.Base(err).Message("Failed to load TLS certificate file: ", certConf.CertFile)
		}
		key, err := ioutil.ReadFile(certConf.KeyFile)
		if err != nil {
			return nil, errors.Base(err).Message("Failed to load TLS key file: ", certConf.KeyFile)
		}
		config.Certificate[idx] = &tls.Certificate{
			Key:         key,
			Certificate: cert,
		}
	}
	config.AllowInsecure = v.Insecure
	if len(v.ServerName) > 0 {
		config.ServerName = v.ServerName
	}
	return serial.ToTypedMessage(config), nil
}