@@ -18,6 +18,151 @@ 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 OpenSSL 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+ ### Building with system OpenSSL
125+
126+ Build your application using the command:
127+ 1 . ** Static build** .
128+ ``` shell
129+ CGO_ENABLED=1 go build -ldflags " -linkmode external -extldflags '-static -lssl -lcrypto'" -o myapp main.go
130+ ```
131+ 2 . ** Dynamic build** .
132+ ``` shell
133+ CGO_ENABLED=1 go build -o myapp main.go
134+ ```
135+
136+ ### Building with a custom OpenSSL version
137+
138+ OpenSSL could be build in two ways. Both of them require downloading the source
139+ code of OpenSSL. It could be done from the [ official website] ( https://www.openssl.org/source/ )
140+ or from the [ GitHub repository] ( https://github.com/openssl/openssl ) .
141+ 1 . ** Static build** . Run this command from the installation directory to configure
142+ the OpenSSL:
143+ ``` shell
144+ ./config no-shared --prefix=/tmp/openssl/
145+ ```
146+ 2 . ** Dynamic build** . Run this command from the installation directory to configure
147+ the OpenSSL:
148+ ``` shell
149+ ./config --prefix=/tmp/openssl/
150+ ```
151+ After configuring, run this command to install and build OpenSSL:
152+ ``` shell
153+ make install
154+ ```
155+ And then build your application using the command:
156+ 1 . ** Static build** .
157+ ``` shell
158+ CGO_ENABLED=1 CGO_CFLAGS=" -I/tmp/openssl/include" CGO_LDFLAGS=" -L/tmp/openssl/lib" PKG_CONFIG_PATH=" /tmp/openssl/lib/pkgconfig" go build -ldflags " -linkmode=external -extldflags '-static -lssl -lcrypto'" -o myapp main.go
159+ ```
160+ 2 . ** Dynamic build** .
161+ ``` shell
162+ CGO_ENABLED=1 CGO_CFLAGS=" -I/tmp/openssl/include" CGO_LDFLAGS=" -L/tmp/openssl/lib" PKG_CONFIG_PATH=" /tmp/openssl/lib/pkgconfig" go build -o myapp main.go
163+ ```
164+ After compiling your Go application, you can run it as usual.
165+
21166[ godoc-badge ] : https://pkg.go.dev/badge/github.com/tarantool/go-tlsdialer.svg
22167[ godoc-url ] : https://pkg.go.dev/github.com/tarantool/go-tlsdialer
23168[ coverage-badge ] : https://coveralls.io/repos/github/tarantool/go-tlsdialer/badge.svg?branch=master
0 commit comments