-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a static string based auth handler
Added tests Updated jwt and creds for auth tests Fixed optional auth tests to now run with nats-server Fixes #261
- Loading branch information
Stephen Asbury
committed
Aug 23, 2019
1 parent
80eee58
commit 427bb71
Showing
9 changed files
with
183 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2018 The NATS Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package io.nats.client.impl; | ||
|
||
import io.nats.client.AuthHandler; | ||
import io.nats.client.NKey; | ||
|
||
class StringAuthHandler implements AuthHandler { | ||
private char[] nkey; | ||
private char[] jwt; | ||
|
||
StringAuthHandler(char[] jwt, char[] nkey) { | ||
this.jwt = jwt; | ||
this.nkey = nkey; | ||
} | ||
|
||
/** | ||
* Sign is called by the library when the server sends a nonce. | ||
* The client's NKey should be used to sign the provided value. | ||
* | ||
* @param nonce the nonce to sign | ||
* @return the signature for the nonce | ||
*/ | ||
public byte[] sign(byte[] nonce) { | ||
try { | ||
NKey nkey = NKey.fromSeed(this.nkey); | ||
byte[] sig = nkey.sign(nonce); | ||
nkey.clear(); | ||
return sig; | ||
} catch (Exception exp) { | ||
throw new IllegalStateException("problem signing nonce", exp); | ||
} | ||
} | ||
|
||
/** | ||
* getID should return a public key associated with a client key known to the server. | ||
* If the server is not in nonce-mode, this array can be empty. | ||
* | ||
* @return the public key as a char array | ||
*/ | ||
public char[] getID() { | ||
try { | ||
NKey nkey = NKey.fromSeed(this.nkey); | ||
char[] pubKey = nkey.getPublicKey(); | ||
nkey.clear(); | ||
return pubKey; | ||
} catch (Exception exp) { | ||
throw new IllegalStateException("problem getting public key", exp); | ||
} | ||
} | ||
|
||
/** | ||
* getJWT should return the user JWT associated with this connection. | ||
* This can return null for challenge only authentication, but for account/user | ||
* JWT-based authentication you need to return the JWT bytes here. | ||
* | ||
* @return the user JWT | ||
*/ | ||
public char[] getJWT() { | ||
return this.jwt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
-----BEGIN TEST OPERATOR JWT----- | ||
eyJ0eXAiOiJqd3QiLCJhbGciOiJlZDI1NTE5In0.eyJqdGkiOiJXSFBHWURTQkVOS1Q3REZJWVFWSFlJMjNLWVVJTEVRN0JOSkFYTktHVVZCRlNaR0lSM1BRIiwiaWF0IjoxNTQzOTU1MjUzLCJpc3MiOiJPRFNEUFhUSjZLNUxYREoyT0FEV0laM0haMkhTN08yU0lDVE1DT05MM0ZJN0VVRklZTzdOV1JOQyIsIm5hbWUiOiJzeW5hZGlhX29wZXJhdG9yIiwic3ViIjoiT0RTRFBYVEo2SzVMWERKMk9BRFdJWjNIWjJIUzdPMlNJQ1RNQ09OTDNGSTdFVUZJWU83TldSTkMiLCJ0eXBlIjoib3BlcmF0b3IifQ.kbbUr4zZ7oSsTW3zqBTpRNsxH-DewiczmJjf2jNLth7Zxj2g4c3CKqnT9O5Cb3f8VtaJo6bpjfJ6Am-U2uMUAw | ||
eyJ0eXAiOiJqd3QiLCJhbGciOiJlZDI1NTE5In0.eyJqdGkiOiJKV01TUzNRUFpDS0lHSE1BWko3RUpQSlVHN01DTFNQUkJaTEpSUUlRQkRVTkFaUE5MQVVBIiwiaWF0IjoxNTY1ODg5NzEyLCJpc3MiOiJPQU01VlNINDJXRlZWTkpXNFNMRTZRVkpCREpVRTJGUVNYWkxRTk1SRDdBMlBaTTIzTDIyWFlVWSIsIm5hbWUiOiJzeW5hZGlhIiwic3ViIjoiT0FNNVZTSDQyV0ZWVk5KVzRTTEU2UVZKQkRKVUUyRlFTWFpMUU5NUkQ3QTJQWk0yM0wyMlhZVVkiLCJ0eXBlIjoib3BlcmF0b3IiLCJuYXRzIjp7ImFjY291bnRfc2VydmVyX3VybCI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjA2MC9qd3QvdjEiLCJvcGVyYXRvcl9zZXJ2aWNlX3VybHMiOlsibmF0czovL2xvY2FsaG9zdDo0MTQxIl19fQ.XPvAezQj3AxwEvYLVBq-EIssP4OhjoMGLbIaripzBKv1oCtHdPNKz96YwB2vUoY-4OrN9ZOPo9TKR3jVxq0uBQ | ||
------END TEST OPERATOR JWT------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
-----BEGIN NATS USER JWT----- | ||
eyJ0eXAiOiJqd3QiLCJhbGciOiJlZDI1NTE5In0.eyJqdGkiOiJJSEczV1JJMzZVUUVHQUZNMkxVN0tWUVozWVVVTVpYWEE0VUpHVUNLUlpVTE9VUzNSTDNRIiwiaWF0IjoxNTQzOTYzNzM4LCJpc3MiOiJBQ0g0N1ZMQVdXM0dQS0tVSEhYN0hLSklEQzVQTVVRVjY2QkdBR0E0UlVLMlpHNTdKNEdRVzNQWSIsIm5hbWUiOiJ0ZXN0Iiwic3ViIjoiVUNQSE0yV0lHSERFRENHQTdNWkxYR1BFSVEzUlJPUk5PQ0xHWk1XT0RVMlVZRFNFQ0VZS1Y2NDYiLCJ0eXBlIjoidXNlciIsIm5hdHMiOnsicHViIjp7fSwic3ViIjp7fX19.IjDhjHH4_CaOpfa2G-japnyzrqy0Uo4bHDNkM0wm3-lwhOrrUy_TLGekH1BlhdBTFpJzMB3_REleRXmElswrDw | ||
eyJ0eXAiOiJqd3QiLCJhbGciOiJlZDI1NTE5In0.eyJqdGkiOiI3UE1GTkc0R1c1WkE1NEg3N09TUUZKNkJNQURaSUQ2NTRTVk1XMkRFQVZINVIyUVU0MkhBIiwiaWF0IjoxNTY1ODg5ODk4LCJpc3MiOiJBQUhWU0k1NVlQTkJRWjVQN0Y2NzZDRkFPNFBIQlREWUZRSUVHVEtMUVRJUEVZUEZEVEpOSEhPNCIsIm5hbWUiOiJkZW1vIiwic3ViIjoiVUMzT01MSlhUWVBZN0ZUTVVZNUNaNExHRVdRSTNZUzZKVFZXU0VGRURBMk9MTEpZSVlaVFo3WTMiLCJ0eXBlIjoidXNlciIsIm5hdHMiOnsicHViIjp7fSwic3ViIjp7fX19.ROSJ7D9ETt9c8ZVHxsM4_FU2dBRLh5cNfb56MxPQth74HAxxtGMl0nn-9VVmWjXgFQn4JiIbwrGfFDBRMzxsAA | ||
------END NATS USER JWT------ | ||
|
||
************************* IMPORTANT ************************* | ||
NKEY Seed printed below can be used to sign and prove identity. | ||
NKEYs are sensitive and should be treated as secrets. | ||
|
||
-----BEGIN USER NKEY SEED----- | ||
SUAI3GND23IWH6RFCQTJFYYUTSPKIXWV42YGKJ7WIY6ZB2KOZVXPDFRIVY | ||
SUAFYHVVQVOIDOOQ4MTOCTLGNZCJ5PZ4HPV5WAPROGTEIOF672D3R7GBY4 | ||
------END USER NKEY SEED------ | ||
|
||
************************************************************* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters