@@ -25,6 +25,11 @@ const (
2525 connClosed = 2
2626)
2727
28+ const (
29+ connTransportNone = ""
30+ connTransportSsl = "ssl"
31+ )
32+
2833type ConnEventKind int
2934type ConnLogKind int
3035
@@ -207,6 +212,32 @@ type Opts struct {
207212 Handle interface {}
208213 // Logger is user specified logger used for error messages.
209214 Logger Logger
215+ // Transport is the connection type, by default the connection is unencrypted.
216+ Transport string
217+ // SslOpts is used only if the Transport == 'ssl' is set.
218+ Ssl SslOpts
219+ }
220+
221+ // SslOpts is a way to configure ssl transport.
222+ type SslOpts struct {
223+ // KeyFile is a path to a private SSL key file.
224+ KeyFile string
225+ // CertFile is a path to an SSL sertificate file.
226+ CertFile string
227+ // CaFile is a path to a trusted certificate authorities (CA) file.
228+ CaFile string
229+ // Ciphers is a colon-separated (:) list of SSL cipher suites the connection
230+ // can use.
231+ //
232+ // We don't provide a list of supported ciphers. This is what OpenSSL
233+ // does. The only limitation is usage of TLSv1.2 (because other protocol
234+ // versions don't seem to support the GOST cipher). To add additional
235+ // ciphers (GOST cipher), you must configure OpenSSL.
236+ //
237+ // See also
238+ //
239+ // * https://www.openssl.org/docs/man1.1.1/man1/ciphers.html
240+ Ciphers string
210241}
211242
212243// Connect creates and configures a new Connection.
@@ -358,8 +389,10 @@ func (conn *Connection) Handle() interface{} {
358389func (conn * Connection ) dial () (err error ) {
359390 var connection net.Conn
360391 network := "tcp"
392+ opts := conn .opts
361393 address := conn .addr
362- timeout := conn .opts .Reconnect / 2
394+ timeout := opts .Reconnect / 2
395+ transport := opts .Transport
363396 if timeout == 0 {
364397 timeout = 500 * time .Millisecond
365398 } else if timeout > 5 * time .Second {
@@ -383,11 +416,17 @@ func (conn *Connection) dial() (err error) {
383416 } else if addrLen >= 4 && address [0 :4 ] == "tcp:" {
384417 address = address [4 :]
385418 }
386- connection , err = net .DialTimeout (network , address , timeout )
419+ if transport == connTransportNone {
420+ connection , err = net .DialTimeout (network , address , timeout )
421+ } else if transport == connTransportSsl {
422+ connection , err = sslDialTimeout (network , address , timeout , opts .Ssl )
423+ } else {
424+ err = errors .New ("An unsupported transport type: " + transport )
425+ }
387426 if err != nil {
388427 return
389428 }
390- dc := & DeadlineIO {to : conn . opts .Timeout , c : connection }
429+ dc := & DeadlineIO {to : opts .Timeout , c : connection }
391430 r := bufio .NewReaderSize (dc , 128 * 1024 )
392431 w := bufio .NewWriterSize (dc , 128 * 1024 )
393432 greeting := make ([]byte , 128 )
@@ -400,8 +439,8 @@ func (conn *Connection) dial() (err error) {
400439 conn .Greeting .auth = bytes .NewBuffer (greeting [64 :108 ]).String ()
401440
402441 // Auth
403- if conn . opts .User != "" {
404- scr , err := scramble (conn .Greeting .auth , conn . opts .Pass )
442+ if opts .User != "" {
443+ scr , err := scramble (conn .Greeting .auth , opts .Pass )
405444 if err != nil {
406445 err = errors .New ("auth: scrambling failure " + err .Error ())
407446 connection .Close ()
0 commit comments