func Init(conf map[string]interface{}) bl.Output { hosts := bl.GArrString("hosts", conf) if len(hosts) == 0 { log.Fatalf("[ERROR] [%s] There is no valid hosts", module) } else { timeout := int64(bl.GInt("timeout", conf)) if timeout <= 0 { log.Fatalf("[ERROR] [%s] You must specify right timeout (%v)", module, timeout) } else { SSLCertificate := bl.GString("ssl_cert", conf) SSLKey := bl.GString("ssl_key", conf) SSLCA := bl.GString("ssl_ca", conf) tag := bl.GString("tag", conf) res := Out_logear_forwarder{ tag: tag, c: make(chan *bl.Message), conn: nil, hosts: hosts, SSLCertificate: SSLCertificate, SSLKey: SSLKey, SSLCA: SSLCA, timeout: time.Second * time.Duration(timeout)} res.loadCerts() return &res } } return nil }
func Init(messageQueue chan *bl.Message, conf map[string]interface{}) bl.Input { var tlsConfig tls.Config tag := bl.GString("tag", conf) bind := bl.GString("bind", conf) timeout := int64(bl.GInt("timeout", conf)) if timeout <= 0 { log.Fatalf("[ERROR] [%s] You must specify right timeout (%d)", module, timeout) } SSLCertificate := bl.GString("ssl_cert", conf) SSLKey := bl.GString("ssl_key", conf) SSLCA := bl.GString("ssl_ca", conf) if len(SSLCertificate) > 0 && len(SSLKey) > 0 { tlsConfig.MinVersion = tls.VersionTLS12 log.Printf("[INFO] [%s] Loading server ssl certificate and key from \"%s\" and \"%s\"", tag, SSLCertificate, SSLKey) cert, err := tls.LoadX509KeyPair(SSLCertificate, SSLKey) if err != nil { log.Fatalf("[ERROR] [%s] Failed loading server ssl certificate: %s", tag, err) } tlsConfig.Certificates = []tls.Certificate{cert} if len(SSLCA) > 0 { log.Printf("[INFO] [%s] Loading CA certificate from file: %s\n", tag, SSLCA) tlsConfig.ClientCAs = x509.NewCertPool() tlsConfig.ClientAuth = tls.RequireAndVerifyClientCert pemdata, err := ioutil.ReadFile(SSLCA) if err != nil { log.Fatalf("[ERROR] [%s] Failure reading CA certificate: %s\n", tag, err) } block, _ := pem.Decode(pemdata) if block == nil { log.Fatalf("[ERROR] [%s] Failed to decode PEM data of CA certificate from \"%s\"\n", tag, SSLCA) } if block.Type != "CERTIFICATE" { log.Fatalf("[ERROR] [%s] This is not a certificate file: %s\n", tag, SSLCA) } cacert, err := x509.ParseCertificate(block.Bytes) if err != nil { log.Fatalf("[ERROR] [%s] Failed to parse CA certificate: %s\n", tag, SSLCA) } tlsConfig.ClientCAs.AddCert(cacert) } v := &In_logear_forwarder{tag: tag, messageQueue: messageQueue, tlsConfig: tlsConfig, bind: bind, timeout: time.Second * time.Duration(timeout)} return v } else { log.Fatalf("[ERROR] [%s] You must specify ssl_cert and ssl_key", module) } return nil }