Skip to content

Commit df9254c

Browse files
DerekBumoleg-jukovec
authored andcommitted
api: remove ssl
`OpenSslDialer` and all of its helper functions and tests were rellocated to the `go-tlsdialer` [1] package (and renamed to `OpenSSLDialer`). So now we can safely remove all the copy-pasted code from `go-tarantool`. This way, in order to use SSL, user should import the `go-tlsdialer` package and call functions from there. 1. https://github.com/tarantool/go-tlsdialer/ Part of #301
1 parent c83fcdc commit df9254c

23 files changed

+119
-1329
lines changed

.github/workflows/testing.yml

-23
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,6 @@ jobs:
103103
make test
104104
make testrace
105105
106-
- name: Run regression tests with disabled SSL
107-
run: |
108-
make test TAGS="go_tarantool_ssl_disable"
109-
make testrace TAGS="go_tarantool_ssl_disable"
110-
111106
- name: Run fuzzing tests
112107
if: ${{ matrix.fuzzing }}
113108
run: make fuzzing TAGS="go_tarantool_decimal_fuzzing"
@@ -149,16 +144,13 @@ jobs:
149144
- 'sdk-1.10.15-0-r598'
150145
coveralls: [false]
151146
fuzzing: [false]
152-
ssl: [false]
153147
include:
154148
- sdk-path: 'release/linux/x86_64/2.10/'
155149
sdk-version: 'sdk-gc64-2.10.8-0-r598.linux.x86_64'
156150
coveralls: false
157-
ssl: true
158151
- sdk-path: 'release/linux/x86_64/2.11/'
159152
sdk-version: 'sdk-gc64-2.11.1-0-r598.linux.x86_64'
160153
coveralls: true
161-
ssl: true
162154

163155
steps:
164156
- name: Clone the connector
@@ -195,14 +187,6 @@ jobs:
195187
source tarantool-enterprise/env.sh
196188
make test
197189
make testrace
198-
env:
199-
TEST_TNT_SSL: ${{matrix.ssl}}
200-
201-
- name: Run regression tests with disabled SSL
202-
run: |
203-
source tarantool-enterprise/env.sh
204-
make test TAGS="go_tarantool_ssl_disable"
205-
make testrace TAGS="go_tarantool_ssl_disable"
206190
207191
- name: Run fuzzing tests
208192
if: ${{ matrix.fuzzing }}
@@ -212,7 +196,6 @@ jobs:
212196
if: ${{ matrix.coveralls }}
213197
env:
214198
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
215-
TEST_TNT_SSL: ${{matrix.ssl}}
216199
run: |
217200
source tarantool-enterprise/env.sh
218201
make coveralls
@@ -376,12 +359,6 @@ jobs:
376359
make test
377360
make testrace
378361
379-
- name: Run regression tests with disabled SSL
380-
run: |
381-
cd "${SRCDIR}"
382-
make test TAGS="go_tarantool_ssl_disable"
383-
make testrace TAGS="go_tarantool_ssl_disable"
384-
385362
- name: Run fuzzing tests
386363
if: ${{ matrix.fuzzing }}
387364
run: |

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1515
- IsNullable flag for Field (#302)
1616
- More linters on CI (#310)
1717
- Meaningful description for read/write socket errors (#129)
18-
- Support password and password file to decrypt private SSL key file (#319)
1918
- Support `operation_data` in `crud.Error` (#330)
2019
- Support `fetch_latest_metadata` option for crud requests with metadata (#335)
2120
- Support `noreturn` option for data change crud requests (#335)
@@ -127,6 +126,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
127126
- Code() method from the Request interface (#158)
128127
- `Schema` field from the `Connection` struct (#7)
129128
- `OkCode` and `PushCode` constants (#237)
129+
- SSL support (#301)
130130

131131
### Fixed
132132

CONTRIBUTING.md

-14
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@ make testrace
3434
The tests set up all required `tarantool` processes before run and clean up
3535
afterwards.
3636

37-
If you want to run the tests with specific build tags:
38-
```bash
39-
make test TAGS=go_tarantool_ssl_disable
40-
make testrace TAGS=go_tarantool_ssl_disable
41-
```
42-
43-
If you have Tarantool Enterprise Edition 2.10 or newer, you can run additional
44-
SSL tests. To do this, you need to set an environment variable 'TEST_TNT_SSL':
45-
46-
```bash
47-
TEST_TNT_SSL=true make test
48-
TEST_TNT_SSL=true make testrace
49-
```
50-
5137
If you want to run the tests for a specific package:
5238
```bash
5339
make test-<SUBDIR>

README.md

+59-7
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ We define multiple [build tags](https://pkg.go.dev/go/build#hdr-Build_Constraint
6868

6969
This allows us to introduce new features without losing backward compatibility.
7070

71-
1. To disable SSL support and linking with OpenSSL, you can use the tag:
72-
```
73-
go_tarantool_ssl_disable
74-
```
75-
2. To run fuzz tests with decimals, you can use the build tag:
71+
1. To run fuzz tests with decimals, you can use the build tag:
7672
```
7773
go_tarantool_decimal_fuzzing
7874
```
@@ -169,6 +165,60 @@ otherwise it will have a description which can be retrieved with `err.Error()`.
169165
by the method `Do` of object `conn` which is the object that was returned
170166
by `Connect()`.
171167

168+
### Example with encrypting traffic
169+
170+
For SSL-enabled connections, use `OpenSSLDialer` from the [`go-tlsdialer`](https://github.com/tarantool/go-tlsdialer)
171+
package.
172+
173+
Here is small example with importing `go-tlsdialer` and using the
174+
`OpenSSLDialer`:
175+
176+
```go
177+
package tarantool
178+
179+
import (
180+
"context"
181+
"fmt"
182+
"time"
183+
184+
"github.com/tarantool/go-tarantool/v2"
185+
"github.com/tarantool/go-tlsdialer"
186+
)
187+
188+
func main() {
189+
sslDialer := tlsdialer.OpenSSLDialer{
190+
Address: "127.0.0.1:3013",
191+
User: "test",
192+
Password: "test",
193+
SslKeyFile: "testdata/localhost.key",
194+
SslCertFile: "testdata/localhost.crt",
195+
SslCaFile: "testdata/ca.crt",
196+
}
197+
opts := tarantool.Opts{
198+
Timeout: time.Second,
199+
}
200+
201+
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
202+
defer cancel()
203+
conn, err := tarantool.Connect(ctx, sslDialer, opts)
204+
if err != nil {
205+
fmt.Printf("Connection refused: %s", err)
206+
}
207+
208+
data, err := conn.Do(tarantool.NewInsertRequest(999).
209+
Tuple([]interface{}{99999, "BB"}),
210+
).Get()
211+
if err != nil {
212+
fmt.Printf("Error: %s", err)
213+
} else {
214+
fmt.Printf("Data: %v", data)
215+
}
216+
}
217+
```
218+
219+
Note that [traffic encryption](https://www.tarantool.io/en/doc/latest/enterprise/security/#encrypting-traffic)
220+
is only available in Tarantool Enterprise Edition 2.10 or newer.
221+
172222
### Migration to v2
173223

174224
The article describes migration from go-tarantool to go-tarantool/v2.
@@ -315,8 +365,10 @@ and user may cancel it in process.
315365

316366
Now you need to pass `Dialer` as the second argument instead of URI.
317367
If you were using a non-SSL connection, you need to create `NetDialer`.
318-
For SSL-enabled connections, use `OpenSslDialer`. Please note that the options
319-
for creating a connection are now stored in corresponding `Dialer`, not in `Opts`.
368+
For SSL-enabled connections, use `OpenSSLDialer` from the `go-tlsdialer`
369+
package.
370+
Please note that the options for creating a connection are now stored in
371+
corresponding `Dialer`, not in `Opts`.
320372

321373
#### Connection schema
322374

dial.go

-109
Original file line numberDiff line numberDiff line change
@@ -205,115 +205,6 @@ func (d NetDialer) Dial(ctx context.Context, opts DialOpts) (Conn, error) {
205205
return dialer.Dial(ctx, opts)
206206
}
207207

208-
type openSslDialer struct {
209-
address string
210-
sslKeyFile string
211-
sslCertFile string
212-
sslCaFile string
213-
sslCiphers string
214-
sslPassword string
215-
sslPasswordFile string
216-
}
217-
218-
func (d openSslDialer) Dial(ctx context.Context, opts DialOpts) (Conn, error) {
219-
var err error
220-
conn := new(tntConn)
221-
222-
network, address := parseAddress(d.address)
223-
conn.net, err = sslDialContext(ctx, network, address, sslOpts{
224-
KeyFile: d.sslKeyFile,
225-
CertFile: d.sslCertFile,
226-
CaFile: d.sslCaFile,
227-
Ciphers: d.sslCiphers,
228-
Password: d.sslPassword,
229-
PasswordFile: d.sslPasswordFile,
230-
})
231-
if err != nil {
232-
return nil, fmt.Errorf("failed to dial: %w", err)
233-
}
234-
235-
dc := &deadlineIO{to: opts.IoTimeout, c: conn.net}
236-
conn.reader = bufio.NewReaderSize(dc, bufSize)
237-
conn.writer = bufio.NewWriterSize(dc, bufSize)
238-
239-
return conn, nil
240-
}
241-
242-
// OpenSslDialer allows to use SSL transport for connection.
243-
type OpenSslDialer struct {
244-
// Address is an address to connect.
245-
// It could be specified in following ways:
246-
//
247-
// - TCP connections (tcp://192.168.1.1:3013, tcp://my.host:3013,
248-
// tcp:192.168.1.1:3013, tcp:my.host:3013, 192.168.1.1:3013, my.host:3013)
249-
//
250-
// - Unix socket, first '/' or '.' indicates Unix socket
251-
// (unix:///abs/path/tnt.sock, unix:path/tnt.sock, /abs/path/tnt.sock,
252-
// ./rel/path/tnt.sock, unix/:path/tnt.sock)
253-
Address string
254-
// Auth is an authentication method.
255-
Auth Auth
256-
// Username for logging in to Tarantool.
257-
User string
258-
// User password for logging in to Tarantool.
259-
Password string
260-
// RequiredProtocol contains minimal protocol version and
261-
// list of protocol features that should be supported by
262-
// Tarantool server. By default, there are no restrictions.
263-
RequiredProtocolInfo ProtocolInfo
264-
// SslKeyFile is a path to a private SSL key file.
265-
SslKeyFile string
266-
// SslCertFile is a path to an SSL certificate file.
267-
SslCertFile string
268-
// SslCaFile is a path to a trusted certificate authorities (CA) file.
269-
SslCaFile string
270-
// SslCiphers is a colon-separated (:) list of SSL cipher suites the connection
271-
// can use.
272-
//
273-
// We don't provide a list of supported ciphers. This is what OpenSSL
274-
// does. The only limitation is usage of TLSv1.2 (because other protocol
275-
// versions don't seem to support the GOST cipher). To add additional
276-
// ciphers (GOST cipher), you must configure OpenSSL.
277-
//
278-
// See also
279-
//
280-
// * https://www.openssl.org/docs/man1.1.1/man1/ciphers.html
281-
SslCiphers string
282-
// SslPassword is a password for decrypting the private SSL key file.
283-
// The priority is as follows: try to decrypt with SslPassword, then
284-
// try SslPasswordFile.
285-
SslPassword string
286-
// SslPasswordFile is a path to the list of passwords for decrypting
287-
// the private SSL key file. The connection tries every line from the
288-
// file as a password.
289-
SslPasswordFile string
290-
}
291-
292-
// Dial makes OpenSslDialer satisfy the Dialer interface.
293-
func (d OpenSslDialer) Dial(ctx context.Context, opts DialOpts) (Conn, error) {
294-
dialer := AuthDialer{
295-
Dialer: ProtocolDialer{
296-
Dialer: GreetingDialer{
297-
Dialer: openSslDialer{
298-
address: d.Address,
299-
sslKeyFile: d.SslKeyFile,
300-
sslCertFile: d.SslCertFile,
301-
sslCaFile: d.SslCaFile,
302-
sslCiphers: d.SslCiphers,
303-
sslPassword: d.SslPassword,
304-
sslPasswordFile: d.SslPasswordFile,
305-
},
306-
},
307-
RequiredProtocolInfo: d.RequiredProtocolInfo,
308-
},
309-
Auth: d.Auth,
310-
Username: d.User,
311-
Password: d.Password,
312-
}
313-
314-
return dialer.Dial(ctx, opts)
315-
}
316-
317208
type fdAddr struct {
318209
Fd uintptr
319210
}

dial_test.go

+38-10
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ type testDialOpts struct {
442442
isErrGreeting bool
443443
isErrId bool
444444
isIdUnsupported bool
445-
isPapSha256Auth bool
446445
isErrAuth bool
447446
isEmptyAuth bool
448447
}
@@ -485,9 +484,7 @@ func testDialAccept(opts testDialOpts, l net.Listener) chan dialServerActual {
485484

486485
// Read Auth request.
487486
authRequestExpected := authRequestExpectedChapSha1
488-
if opts.isPapSha256Auth {
489-
authRequestExpected = authRequestExpectedPapSha256
490-
} else if opts.isEmptyAuth {
487+
if opts.isEmptyAuth {
491488
authRequestExpected = []byte{}
492489
}
493490
authRequestActual := make([]byte, len(authRequestExpected))
@@ -530,9 +527,7 @@ func testDialer(t *testing.T, l net.Listener, dialer tarantool.Dialer,
530527
require.Equal(t, idRequestExpected, actual.IdRequest)
531528

532529
authRequestExpected := authRequestExpectedChapSha1
533-
if opts.isPapSha256Auth {
534-
authRequestExpected = authRequestExpectedPapSha256
535-
} else if opts.isEmptyAuth {
530+
if opts.isEmptyAuth {
536531
authRequestExpected = []byte{}
537532
}
538533
require.Equal(t, authRequestExpected, actual.AuthRequest)
@@ -749,11 +744,44 @@ func TestAuthDialer_Dial(t *testing.T) {
749744
conn.Close()
750745
}
751746

752-
assert.Nil(t, err)
747+
assert.NoError(t, err)
753748
assert.NotNil(t, conn)
754749
assert.Equal(t, authRequestExpectedChapSha1[:41], dialer.conn.writebuf.Bytes()[:41])
755750
}
756751

752+
func TestAuthDialer_Dial_PapSha256Auth(t *testing.T) {
753+
salt := fmt.Sprintf("%s", testDialSalt)
754+
salt = base64.StdEncoding.EncodeToString([]byte(salt))
755+
dialer := mockIoDialer{
756+
init: func(conn *mockIoConn) {
757+
conn.greeting.Salt = salt
758+
conn.writeWgDelay = 1
759+
conn.readWgDelay = 2
760+
conn.readbuf.Write(okResponse)
761+
},
762+
}
763+
defer func() {
764+
dialer.conn.writeWg.Done()
765+
}()
766+
767+
authDialer := tarantool.AuthDialer{
768+
Dialer: &dialer,
769+
Username: "test",
770+
Password: "test",
771+
Auth: tarantool.PapSha256Auth,
772+
}
773+
ctx, cancel := test_helpers.GetConnectContext()
774+
defer cancel()
775+
conn, err := authDialer.Dial(ctx, tarantool.DialOpts{})
776+
if conn != nil {
777+
conn.Close()
778+
}
779+
780+
assert.NoError(t, err)
781+
assert.NotNil(t, conn)
782+
assert.Equal(t, authRequestExpectedPapSha256[:41], dialer.conn.writebuf.Bytes()[:41])
783+
}
784+
757785
func TestProtocolDialer_Dial_DialerError(t *testing.T) {
758786
dialer := tarantool.ProtocolDialer{
759787
Dialer: mockErrorDialer{
@@ -847,7 +875,7 @@ func TestProtocolDialer_Dial(t *testing.T) {
847875
conn.Close()
848876
}
849877

850-
assert.Nil(t, err)
878+
assert.NoError(t, err)
851879
assert.NotNil(t, conn)
852880
assert.Equal(t, protoInfo, conn.ProtocolInfo())
853881
}
@@ -913,7 +941,7 @@ func TestGreetingDialer_Dial(t *testing.T) {
913941
conn.Close()
914942
}
915943

916-
assert.Nil(t, err)
944+
assert.NoError(t, err)
917945
assert.NotNil(t, conn)
918946
assert.Equal(t, string(testDialVersion[:]), conn.Greeting().Version)
919947
assert.Equal(t, string(testDialSalt[:44]), conn.Greeting().Salt)

0 commit comments

Comments
 (0)