Skip to content

Commit

Permalink
Update for nkey changes
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Sep 13, 2018
1 parent 662f71e commit 16c0f5b
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 51 deletions.
2 changes: 1 addition & 1 deletion server/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (s *Server) isClientAuthorized(c *client) bool {
if c.opts.Sig == "" {
return false
}
sig, err := base64.RawURLEncoding.DecodeString(c.opts.Sig)
sig, err := base64.StdEncoding.DecodeString(c.opts.Sig)
if err != nil {
return false
}
Expand Down
6 changes: 3 additions & 3 deletions server/nkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

// Raw length of the nonce challenge
const (
nonceRawLen = 16
nonceLen = 22 // base64.RawURLEncoding.EncodedLen(nonceRawLen)
nonceRawLen = 11
nonceLen = 16 // base64.StdEncoding.EncodedLen(nonceRawLen)
)

// nonceRequired tells us if we should send a nonce.
Expand All @@ -35,5 +35,5 @@ func (s *Server) generateNonce(n []byte) {
var raw [nonceRawLen]byte
data := raw[:]
s.prand.Read(data)
base64.RawURLEncoding.Encode(n, data)
base64.StdEncoding.Encode(n, data)
}
12 changes: 6 additions & 6 deletions server/nkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type nonceInfo struct {
}

// This is a seed for a user. We can extract public and private keys from this for testing.
const seed = "SUAOB32VQGYIOM622XYNXN4Q6GQR5I6DFZPPYZMNI5MMNVAQZDAL3OLH554ISOUTJM4EC6NWS5UHMS4CMONVVRW3VXXEQULMR6MDLPOEUVFPU"
const seed = "SUAKYRHVIOREXV7EUZTBHUHL7NUMHPMAS7QMDU3GTIUWEI5LDNOXD43IZY"

func nkeyBasicSetup() (*Server, *client, *bufio.Reader, string) {
kp, _ := nkeys.FromSeed(seed)
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestNkeyClientConnect(t *testing.T) {
if err != nil {
t.Fatalf("Failed signing nonce: %v", err)
}
sig := base64.RawURLEncoding.EncodeToString(sigraw)
sig := base64.StdEncoding.EncodeToString(sigraw)

// PING needed to flush the +OK to us.
cs = fmt.Sprintf("CONNECT {\"nkey\":%q,\"sig\":\"%s\",\"verbose\":true,\"pedantic\":true}\r\nPING\r\n", pubKey, sig)
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestMixedClientConnect(t *testing.T) {
if err != nil {
t.Fatalf("Failed signing nonce: %v", err)
}
sig := base64.RawURLEncoding.EncodeToString(sigraw)
sig := base64.StdEncoding.EncodeToString(sigraw)

// PING needed to flush the +OK to us.
cs := fmt.Sprintf("CONNECT {\"nkey\":%q,\"sig\":\"%s\",\"verbose\":true,\"pedantic\":true}\r\nPING\r\n", pubKey, sig)
Expand Down Expand Up @@ -252,17 +252,17 @@ func BenchmarkNonceGeneration(b *testing.B) {
prand := mrand.New(mrand.NewSource(time.Now().UnixNano()))
for i := 0; i < b.N; i++ {
prand.Read(data)
base64.RawURLEncoding.Encode(b64, data)
base64.StdEncoding.Encode(b64, data)
}
}

func BenchmarkPublicVerify(b *testing.B) {
data := make([]byte, nonceRawLen)
nonce := make([]byte, nonceLen)
mrand.Read(data)
base64.RawURLEncoding.Encode(nonce, data)
base64.StdEncoding.Encode(nonce, data)

user, err := nkeys.CreateUser(nil)
user, err := nkeys.CreateUser()
if err != nil {
b.Fatalf("Error creating User Nkey: %v", err)
}
Expand Down
10 changes: 7 additions & 3 deletions vendor/github.com/nats-io/nkeys/keypair.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 24 additions & 16 deletions vendor/github.com/nats-io/nkeys/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 28 additions & 20 deletions vendor/github.com/nats-io/nkeys/nk/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/nats-io/nkeys/strkey.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"importpath": "github.com/nats-io/nkeys",
"repository": "https://github.com/nats-io/nkeys",
"vcs": "git",
"revision": "b1c20ce69b6a01afa42403ea6f7b408d6cbc8e4e",
"revision": "9206fa847ab4dfdf7378fb1965717f32978852e2",
"branch": "master",
"notests": true
},
Expand Down

0 comments on commit 16c0f5b

Please sign in to comment.