Skip to content

Commit 2645ec5

Browse files
committed
add mongo v5 SASL authentication support
1 parent eeefdec commit 2645ec5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+102
-69
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
_harness
2-
.vscode
2+
.vscode
3+
.idea

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: go
22

3-
go_import_path: github.com/globalsign/mgo
3+
go_import_path: github.com/libi/mgo
44

55
go:
66
- 1.9.x
@@ -33,7 +33,7 @@ install:
3333

3434
before_script:
3535
- golint ./... | grep -v 'ID' | cat
36-
- go vet github.com/globalsign/mgo/bson github.com/globalsign/mgo/txn github.com/globalsign/mgo
36+
- go vet github.com/libi/mgo/bson github.com/libi/mgo/txn github.com/libi/mgo
3737
- export NOIPV6=1
3838
- make startdb
3939

auth.go

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
"fmt"
3535
"sync"
3636

37-
"github.com/globalsign/mgo/bson"
38-
"github.com/globalsign/mgo/internal/scram"
37+
"github.com/libi/mgo/bson"
38+
"github.com/libi/mgo/internal/scram"
3939
)
4040

4141
type authCmd struct {
@@ -77,6 +77,18 @@ type saslCmd struct {
7777
Payload []byte
7878
}
7979

80+
type saslStartCmd struct {
81+
Start int `bson:"saslStart,omitempty"`
82+
Mechanism string `bson:"mechanism,omitempty"`
83+
Payload []byte
84+
}
85+
86+
type saslContinueCmd struct {
87+
Continue int `bson:"saslContinue,omitempty"`
88+
ConversationId int `bson:"conversationId,omitempty"`
89+
Payload []byte
90+
}
91+
8092
type saslResult struct {
8193
Ok bool `bson:"ok"`
8294
NotOk bool `bson:"code"` // Server <= 2.3.2 returns ok=1 & code>0 on errors (WTF?)
@@ -309,9 +321,30 @@ func (socket *mongoSocket) loginSASL(cred Credential) error {
309321
lock(true)
310322
defer lock(false)
311323

312-
start := 1
313-
cmd := saslCmd{}
324+
startStep, _, err := sasl.Step([]byte{})
325+
if err != nil {
326+
return err
327+
}
328+
329+
lock(false)
314330
res := saslResult{}
331+
startCmd := saslStartCmd{
332+
Start: 1,
333+
Mechanism: cred.Mechanism,
334+
Payload: startStep,
335+
}
336+
err = socket.loginRun(cred.Source, &startCmd, &res, func() error {
337+
// See the comment on lock for why this is necessary.
338+
lock(true)
339+
if !res.Ok || res.NotOk {
340+
return fmt.Errorf("server returned error on SASL authentication step: %s", res.ErrMsg)
341+
}
342+
return nil
343+
})
344+
if err != nil {
345+
return err
346+
}
347+
cmd := saslContinueCmd{}
315348
for {
316349
payload, done, err := sasl.Step(res.Payload)
317350
if err != nil {
@@ -324,14 +357,11 @@ func (socket *mongoSocket) loginSASL(cred Credential) error {
324357
}
325358
lock(false)
326359

327-
cmd = saslCmd{
328-
Start: start,
329-
Continue: 1 - start,
360+
cmd = saslContinueCmd{
361+
Continue: 1,
330362
ConversationId: res.ConversationId,
331-
Mechanism: cred.Mechanism,
332363
Payload: payload,
333364
}
334-
start = 0
335365
err = socket.loginRun(cred.Source, &cmd, &res, func() error {
336366
// See the comment on lock for why this is necessary.
337367
lock(true)

auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
"sync"
4040
"time"
4141

42-
"github.com/globalsign/mgo"
42+
"github.com/libi/mgo"
4343
. "gopkg.in/check.v1"
4444
)
4545

bson/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![GoDoc](https://godoc.org/github.com/globalsign/mgo/bson?status.svg)](https://godoc.org/github.com/globalsign/mgo/bson)
1+
[![GoDoc](https://godoc.org/github.com/libi/mgo/bson?status.svg)](https://godoc.org/github.com/libi/mgo/bson)
22

33
An Implementation of BSON for Go
44
--------------------------------

bson/bson_corpus_spec_test.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bson/bson_corpus_spec_test_generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"path/filepath"
1313
"strings"
1414

15-
"github.com/globalsign/mgo/internal/json"
15+
"github.com/libi/mgo/internal/json"
1616
)
1717

1818
func main() {
@@ -162,7 +162,7 @@ import (
162162
"time"
163163
164164
. "gopkg.in/check.v1"
165-
"github.com/globalsign/mgo/bson"
165+
"github.com/libi/mgo/bson"
166166
)
167167
168168
func testValid(c *C, in []byte, expected []byte, result interface{}) {

bson/bson_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
"testing"
4141
"time"
4242

43-
"github.com/globalsign/mgo/bson"
43+
"github.com/libi/mgo/bson"
4444
. "gopkg.in/check.v1"
4545
)
4646

bson/compatability_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package bson_test
22

33
import (
4-
"github.com/globalsign/mgo/bson"
4+
"github.com/libi/mgo/bson"
55
. "gopkg.in/check.v1"
66
)
77

bson/decimal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"regexp"
3434
"strings"
3535

36-
"github.com/globalsign/mgo/bson"
36+
"github.com/libi/mgo/bson"
3737

3838
. "gopkg.in/check.v1"
3939
)

0 commit comments

Comments
 (0)