-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nkey support #399
Nkey support #399
Conversation
Signed-off-by: Derek Collison <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Option setter should be added and not sure of the place of the check of absence of signature callback if NKey is specified. But this could be addressed later if needed.
nats.go
Outdated
@@ -94,6 +95,8 @@ var ( | |||
ErrInvalidContext = errors.New("nats: invalid context") | |||
ErrNoEchoNotSupported = errors.New("nats: no echo option not supported by this server") | |||
ErrClientIDNotSupported = errors.New("nats: client ID not supported by this server") | |||
ErrNkeyButNoSigCB = errors.New("nats: Nkey defined without a signature handler") | |||
ErrNkeysNoSupported = errors.New("nats: Nkeys not supported by the server.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No punctuation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
nats.go
Outdated
@@ -1208,6 +1227,16 @@ func (nc *Conn) checkForSecure() error { | |||
o.Secure = true | |||
} | |||
|
|||
if o.Nkey != "" && nc.info.Nonce == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if user defines NKey, then it can connect only to servers that support it, is that ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe so, if a user defines them that is what they expect and if the server does not support it that should error IMO.
nats.go
Outdated
|
||
// Check if we have an nkey but no signature callback | ||
// defined. | ||
if o.Nkey != "" && o.SignatureCB == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why put this test in here? Since we have a test above that basically says that a client that has NKey cannot connect to a server that does not support it, why not do this test early in Connect()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can move it..
// SignatureCB designates the function used to sign the nonce | ||
// presented from the server. | ||
SignatureCB SignatureHandler | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no option function to set those, forcing users to use old methods of connecting from Options. I would recommend adding one function that sets the NKey and SignatureCB at the same time, which could ensure that signature is set or otherwise return error. We would still need to do the check outside, though, in case users connection from Options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree will add it.
I am not sure we should call the interface keypair, since that could be confused with the Nkey keypair. For java and TS we called it AuthHandler I think. |
Signed-off-by: Derek Collison <[email protected]>
nats.go
Outdated
@@ -1227,16 +1240,6 @@ func (nc *Conn) checkForSecure() error { | |||
o.Secure = true | |||
} | |||
|
|||
if o.Nkey != "" && nc.info.Nonce == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not really the one I say we should be moving
Signed-off-by: Derek Collison <[email protected]>
Base nkey support.
Signed-off-by: Derek Collison [email protected]