@@ -18,6 +18,137 @@ To run a default set of tests:
1818go test -v ./...
1919```
2020
21+ ## OpenSslDialer
22+
23+ User can create a dialer by filling the struct:
24+ ``` go
25+ // OpenSslDialer allows to use SSL transport for connection.
26+ type OpenSslDialer struct {
27+ // Address is an address to connect.
28+ // It could be specified in following ways:
29+ //
30+ // - TCP connections (tcp://192.168.1.1:3013, tcp://my.host:3013,
31+ // tcp:192.168.1.1:3013, tcp:my.host:3013, 192.168.1.1:3013, my.host:3013)
32+ //
33+ // - Unix socket, first '/' or '.' indicates Unix socket
34+ // (unix:///abs/path/tt.sock, unix:path/tt.sock, /abs/path/tt.sock,
35+ // ./rel/path/tt.sock, unix/:path/tt.sock)
36+ Address string
37+ // Auth is an authentication method.
38+ Auth tarantool.Auth
39+ // Username for logging in to Tarantool.
40+ User string
41+ // User password for logging in to Tarantool.
42+ Password string
43+ // RequiredProtocol contains minimal protocol version and
44+ // list of protocol features that should be supported by
45+ // Tarantool server. By default, there are no restrictions.
46+ RequiredProtocolInfo tarantool.ProtocolInfo
47+ // SslKeyFile is a path to a private SSL key file.
48+ SslKeyFile string
49+ // SslCertFile is a path to an SSL certificate file.
50+ SslCertFile string
51+ // SslCaFile is a path to a trusted certificate authorities (CA) file.
52+ SslCaFile string
53+ // SslCiphers is a colon-separated (:) list of SSL cipher suites the connection
54+ // can use.
55+ //
56+ // We don't provide a list of supported ciphers. This is what OpenSSL
57+ // does. The only limitation is usage of TLSv1.2 (because other protocol
58+ // versions don't seem to support the GOST cipher). To add additional
59+ // ciphers (GOST cipher), you must configure OpenSSL.
60+ //
61+ // See also
62+ //
63+ // * https://www.openssl.org/docs/man1.1.1/man1/ciphers.html
64+ SslCiphers string
65+ // SslPassword is a password for decrypting the private SSL key file.
66+ // The priority is as follows: try to decrypt with SslPassword, then
67+ // try SslPasswordFile.
68+ SslPassword string
69+ // SslPasswordFile is a path to the list of passwords for decrypting
70+ // the private SSL key file. The connection tries every line from the
71+ // file as a password.
72+ SslPasswordFile string
73+ }
74+ ```
75+ To create a connection from the created dialer a ` Dial ` function could be used:
76+ ``` go
77+ package tarantool
78+
79+ import (
80+ " context"
81+ " fmt"
82+ " time"
83+
84+ " github.com/tarantool/go-tarantool/v2"
85+ " github.com/tarantool/go-tlsdialer"
86+ )
87+
88+ func main () {
89+ dialer := tlsdialer.OpenSslDialer {
90+ Address: " 127.0.0.1:3301" ,
91+ User: " guest" ,
92+ }
93+ opts := tarantool.Opts {
94+ Timeout: 5 * time.Second ,
95+ }
96+
97+ ctx , cancel := context.WithTimeout (context.Background (), 500 *time.Millisecond )
98+ defer cancel ()
99+
100+ conn , err := tarantool.Connect (ctx, dialer, opts)
101+ if err != nil {
102+ fmt.Printf (" Failed to create an example connection: %s " , err)
103+ return
104+ }
105+
106+ // Use the connection.
107+ data , err := conn.Do (tarantool.NewInsertRequest (999 ).
108+ Tuple ([]interface {}{99999 , " BB" }),
109+ ).Get ()
110+ if err != nil {
111+ fmt.Printf (" Error: %s " , err)
112+ } else {
113+ fmt.Printf (" Data: %v " , data)
114+ }
115+ }
116+ ```
117+
118+ ### Application build
119+
120+ Since tlsdialer uses SSL for connection to the Tarantool-EE, Cgo should be
121+ enabled while building and OpenSSL libraries and includes should be available
122+ in build time.
123+
124+ OpenSSL could be build in two ways. Both of them require downloading the source
125+ code of OpenSSL. It could be done from the [ official website] ( https://www.openssl.org/source/ )
126+ or from the [ GitHub repository] ( https://github.com/openssl/openssl ) .
127+ 1 . ** Static build** . Run this command from the installation directory to configure
128+ the OpenSSL:
129+ ``` shell
130+ ./config no-shared --prefix=/tmp/openssl/ --openssldir=/usr/local/ssl/
131+ ```
132+ 2 . ** Dynamic build** . Run this command from the installation directory to configure
133+ the OpenSSL:
134+ ``` shell
135+ ./config --prefix=/tmp/openssl/ --openssldir=/usr/local/ssl/
136+ ```
137+ After configuring, run this command to install and build OpenSSL:
138+ ``` shell
139+ make install --prefix=/tmp/openssl/
140+ ```
141+ And then build your application using the command:
142+ 1 . ** Static build** .
143+ ``` shell
144+ CGO_ENABLED=1 CGO_CFLAGS=" -I/tmp/openssl/include" CGO_LDFLAGS=" -L/tmp/openssl/lib64" PKG_CONFIG_PATH=" /tmp/openssl/lib64/pkgconfig" go build -ldflags ' -linkmode=external -extldflags "-static -lssl -lcrypto"' -o myapp main.go
145+ ```
146+ 2 . ** Dynamic build** .
147+ ``` shell
148+ CGO_ENABLED=1 CGO_CFLAGS=" -I/tmp/openssl/include" CGO_LDFLAGS=" -L/tmp/openssl/lib64" PKG_CONFIG_PATH=" /tmp/openssl/lib64/pkgconfig" go build -o myapp main.go
149+ ```
150+ After compiling your Go application, you can run it as usual.
151+
21152[ godoc-badge ] : https://pkg.go.dev/badge/github.com/tarantool/go-tlsdialer.svg
22153[ godoc-url ] : https://pkg.go.dev/github.com/tarantool/go-tlsdialer
23154[ coverage-badge ] : https://coveralls.io/repos/github/tarantool/go-tlsdialer/badge.svg?branch=master
0 commit comments