Ejemplo n.º 1
0
func NewTcpTransportFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.TransportFactory, error) {
	var err error

	ret := &TransportTcpFactory{
		transport:   name,
		hostport_re: regexp.MustCompile(`^\[?([^]]+)\]?:([0-9]+)$`),
	}

	// Only allow SSL configurations if this is "tls"
	if name == "tls" {
		if err = config.PopulateConfig(ret, config_path, unused); err != nil {
			return nil, err
		}

		if len(ret.SSLCertificate) > 0 && len(ret.SSLKey) > 0 {
			cert, err := tls.LoadX509KeyPair(ret.SSLCertificate, ret.SSLKey)
			if err != nil {
				return nil, fmt.Errorf("Failed loading client ssl certificate: %s", err)
			}

			ret.tls_config.Certificates = []tls.Certificate{cert}
		}

		if len(ret.SSLCA) > 0 {
			ret.tls_config.RootCAs = x509.NewCertPool()

			pemdata, err := ioutil.ReadFile(ret.SSLCA)
			if err != nil {
				return nil, fmt.Errorf("Failure reading CA certificate: %s", err)
			}

			block, _ := pem.Decode(pemdata)
			if block == nil {
				return nil, errors.New("Failed to decode CA certificate data")
			}
			if block.Type != "CERTIFICATE" {
				return nil, fmt.Errorf("Specified CA certificate is not a certificate: %s", ret.SSLCA)
			}

			cert, err := x509.ParseCertificate(block.Bytes)
			if err != nil {
				return nil, fmt.Errorf("Failed to parse CA certificate: %s", err)
			}

			ret.tls_config.RootCAs.AddCert(cert)
		}
	} else {
		if err := config.ReportUnusedConfig(config_path, unused); err != nil {
			return nil, err
		}
	}

	return ret, nil
}
Ejemplo n.º 2
0
func NewZmqTransportFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.TransportFactory, error) {
	var err error

	ret := &TransportZmqFactory{
		transport:   name,
		hostport_re: regexp.MustCompile(`^\[?([^]]+)\]?:([0-9]+)$`),
	}

	if name == "zmq" {
		if err = config.PopulateConfig(ret, config_path, unused); err != nil {
			return nil, err
		}

		if len(ret.CurveServerkey) == 0 {
			return nil, fmt.Errorf("Option %scurve server key is required", config_path)
		} else if len(ret.CurveServerkey) != 40 || !z85Validate(ret.CurveServerkey) {
			return nil, fmt.Errorf("Option %scurve server key must be a valid 40 character Z85 encoded string", config_path)
		}
		if len(ret.CurvePublickey) == 0 {
			return nil, fmt.Errorf("Option %scurve public key is required", config_path)
		} else if len(ret.CurvePublickey) != 40 || !z85Validate(ret.CurvePublickey) {
			return nil, fmt.Errorf("Option %scurve public key must be a valid 40 character Z85 encoded string", config_path)
		}
		if len(ret.CurveSecretkey) == 0 {
			return nil, fmt.Errorf("Option %scurve secret key is required", config_path)
		} else if len(ret.CurveSecretkey) != 40 || !z85Validate(ret.CurveSecretkey) {
			return nil, fmt.Errorf("Option %scurve secret key must be a valid 40 character Z85 encoded string", config_path)
		}
	} else {
		if err := config.ReportUnusedConfig(config_path, unused); err != nil {
			return nil, err
		}
	}

	return ret, nil
}
Ejemplo n.º 3
0
func NewPlainCodecFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.CodecFactory, error) {
	if err := config.ReportUnusedConfig(config_path, unused); err != nil {
		return nil, err
	}
	return &CodecPlainFactory{}, nil
}