@deephaven-enterprise/auth-nodejs 1.20240723.107-alpha-auth-nodejs.23555

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,136 @@
1
+ Deephaven Data Labs is dedicated to developing Deephaven's software in the open
2
+ and is making software available under the following licenses:
3
+
4
+ - **Deephaven Open Source** is made available under the Apache 2.0 License
5
+ - **Deephaven Community** is provided under a source-available license, the
6
+ Deephaven Community License Agreement
7
+
8
+ To request a commercial license for software or uses not covered by these
9
+ licenses or to ask any license-related question, please contact us at:
10
+ [license@deephaven.io](mailto:license@deephaven.io)
11
+
12
+
13
+ # Deephaven Community License Agreement Version 1.0
14
+
15
+ 1. **ACCEPTANCE.** This Deephaven Community License Agreement is entered into by
16
+ and between Deephaven Data Labs LLC, a Delaware Limited Liability Company, with
17
+ an address of 2800 Niagara Lane North, Plymouth, MN 55447 ("Deephaven") and
18
+ “You” (a) in your individual capacity, or (b) on behalf of your company if you
19
+ are licensing the Software for a company for which or with which you work. By
20
+ using the Software, You agree to all of the terms and conditions in this
21
+ Deephaven Community License Agreement (the "Agreement").
22
+
23
+ 2. **THE SOFTWARE.** The "Software" means the version of the Deephaven Community
24
+ Software provided to the original licensee with this Agreement. The Software may
25
+ include third party owned code. Each third party module is subject to the terms
26
+ of its respective license; the details of which can be found in the notices
27
+ served at [https://github.com/deephaven/deephaven-core](https://github.com/deephaven/deephaven-core).
28
+ Since licensees may contribute back to the Software as provided for in Section
29
+ 3(b), the Software may include any such contributions.
30
+
31
+ 3. **GRANT OF LICENSE.** Subject to the terms and conditions of this Agreement,
32
+ Deephaven hereby grants You a royalty-free, worldwide, non-exclusive,
33
+ non-transferable license to the Software (the "License"), subject, in all of the
34
+ cases, to applicable laws and regulations, but not for the Prohibited Use (as
35
+ provided for in Section 4), solely as follows:
36
+
37
+ - a. **Internal Use.** A license to use, copy, compile, and install the
38
+ Software for Your internal use;
39
+
40
+ - b. **Derivative Works.** A license to (i) prepare, develop, compile, and test
41
+ Derivative Works of the Software, (ii) use Your Derivative Works for Your
42
+ internal use solely as expressly permitted in Section 3(a), and (iii) distribute
43
+ Your Derivative Works back to Deephaven under a separate Deephaven Contributor
44
+ Agreement for potential incorporation into the Software at Deephaven's sole
45
+ discretion. A "Derivative Work" means any work that (A) is based on or derived
46
+ from the Software including any modifications to the Software, or (B) meets the
47
+ definition of derivative work under the United States Copyright Act of 1976, 17
48
+ U.S.C. Section 101; and
49
+
50
+ - c. **Distribution and redistribution.** A license to distribute or
51
+ redistribute the Software and Your Derivative Works, and copies of the Software
52
+ and Your Derivative Works, to customers and other third parties for their use
53
+ pursuant to this Agreement subject to the prohibitions in Section 4 and
54
+ Agreement requirement as provided for in Section 5.
55
+
56
+ 4. **PROHIBITED USE.** Notwithstanding any provision of this Agreement to the
57
+ contrary, the original licensee is prohibited from using, distributing, or
58
+ deploying the Software or Derivative Works in such a way that a third party
59
+ (including any recipient under Section 3(c)) can, directly or indirectly
60
+ through the original licensee, its agents, its technology, or solutions made
61
+ available to them, add, define, redefine, or modify the schema for any input
62
+ tables (including source tables, or other input objects) that the Software or
63
+ Derivative Works access. For clarification, every recipient of the Software or
64
+ Derivative Works after the original licensee of the Software is prohibited from
65
+ adding, defining, redefining, or modifying the schema for any input tables
66
+ (including source tables, or other input objects) that the Software or
67
+ Derivative Works access. This prohibition in no way affects the ability of a
68
+ third party to add, define, redefine, or modify the schema of output tables
69
+ (including output tables that are interim or derived). Further, this
70
+ prohibition in no way affects the ability of a third party to add, define,
71
+ redefine, or modify data (as opposed to schema), nor does it cause You to be
72
+ limited in any capacity for Your internal use as permitted in Section 3(a). If
73
+ You have any questions on this prohibition, please contact us at:
74
+ [license@deephaven.io](mailto:license@deephaven.io)
75
+
76
+ 5. **AGREEMENT.** If You distribute the Software, whether directly, as a copy,
77
+ or via Your Derivative Works you must provide recipients a copy of this
78
+ Agreement (which will bind each recipient directly) and You must ensure that all
79
+ copyright, patent, trademark, and attribution notices from the Software are
80
+ retained.
81
+
82
+ 6. **AFFILIATES.** You may permit Your affiliates to exercise the License,
83
+ provided that such exercise must be solely for Your benefit and/or the benefit
84
+ of Your affiliate, and You shall be responsible for all acts and omissions of
85
+ such affiliates in connection with such exercise of the License, including but
86
+ not limited to breach of any terms of this Agreement.
87
+
88
+ 7. **SUBLICENSE.** The License is sublicensable only to Your third-party
89
+ subcontractors and contractors performing services on Your or Your affiliates'
90
+ behalf, subject to the terms and conditions of this Agreement. The License is
91
+ not sublicensable to any other third party nor is it further sublicensable. You
92
+ shall be responsible for all acts and omissions of such subcontractor and
93
+ contractors in connection with such exercise of the sublicense, including but
94
+ not limited to breach of any terms of this Agreement.
95
+
96
+ 8. **PATENTS.** Rights to use the Software do not give You any right to
97
+ implement or use Deephaven's patents independently of the permitted use of the
98
+ Software.
99
+
100
+ 9. **RESERVATION OF RIGHTS.** Deephaven reserves all rights not granted in this
101
+ Agreement. You have no right to use Deephaven trade names, trademarks, service
102
+ marks, or product names except as required for reasonable and customary use in
103
+ describing the origin of the Software.
104
+
105
+ 10. **DISCLAIMER OF WARRANTY.** THE SOFTWARE IS LICENSED ON AN "AS IS" BASIS
106
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. DEEPHAVEN DISCLAIMS ALL
107
+ WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF
108
+ TITLE, NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
109
+ You are solely responsible for determining the appropriateness of using,
110
+ distributing or redistributing the Software and Derivative Works and assume all
111
+ risks associated with Your exercise of the License.
112
+
113
+ 11. **INDEMNIFICATION.** If You distribute or redistribute the Software or
114
+ Derivative Works, You agree to defend on request, and indemnify, Deephaven and
115
+ its affiliates, officers, directors, employees and agents from and against any
116
+ and all losses, damages, liabilities, claims, costs and expenses (including
117
+ reasonable attorney’s fees and expenses) incurred or arising from the
118
+ exploitation of the Software or Derivative Works.
119
+
120
+ 12. **LIMITATION OF LIABILITY.** THE LICENSE IS GRANTED FOR NO FEE. IN NO EVENT
121
+ AND UNDER NO LEGAL THEORY, WHETHER IN TORT (INCLUDING NEGLIGENCE), CONTRACT, OR
122
+ OTHERWISE, SHALL DEEPHAVEN BE LIABLE FOR ANY DAMAGES ARISING OUT OF OR AS A
123
+ RESULT OF THIS AGREEMENT, INCLUDING ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
124
+ OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO DAMAGES FOR LOSS OF
125
+ GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR LOSS OR CORRUPTION
126
+ OF DATA), EVEN IF DEEPHAVEN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
127
+
128
+ 13. **TERMINATION.** The License will automatically terminate if You violate the
129
+ use rights or prohibitions in this Agreement.
130
+
131
+ 14. **GOVERNING LAW.** This Agreement will be interpreted, construed and
132
+ enforced in all respects in accordance with the laws of the State of Delaware,
133
+ USA without reference to its choice of law rules to the contrary.
134
+
135
+
136
+ # END OF AGREEMENT
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @deephaven-enterprise/auth-nodejs
2
+
3
+ Deephaven Enterprise Auth Utils for NodeJS
@@ -0,0 +1,3 @@
1
+ export * from './keyPairUtils.js';
2
+ export * from './types.js';
3
+ export * from './loginUtils.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './keyPairUtils.js';
2
+ export * from './types.js';
3
+ export * from './loginUtils.js';
@@ -0,0 +1,31 @@
1
+ import type { Base64KeyPair, Base64Nonce, Base64PrivateKey, Base64PublicKey, Base64Signature, KeyPairType } from './types.js';
2
+ import type { EnterpriseClient, LoginCredentials } from '@deephaven-enterprise/jsapi-types';
3
+ /**
4
+ * Generate a base64 encoded asymmetric key pair using eliptic curve.
5
+ * @returns The base64 encoded public and private keys.
6
+ */
7
+ export declare function generateBase64KeyPair(): Base64KeyPair;
8
+ /**
9
+ * Prepend a sentinal value to a public key based on the given type. The
10
+ * sentinel is the uppercase type followed by a colon.
11
+ * @param type Keypair type.
12
+ * @param key Base64 encoded public key.
13
+ * @returns The key with the sentinel prepended.
14
+ */
15
+ export declare function keyWithSentinel(type: KeyPairType, key: Base64PublicKey): string;
16
+ /**
17
+ * Sign a nonce using a private key.
18
+ * @param nonce Base64 encoded nonce.
19
+ * @param privateKey Base64 encoded private key.
20
+ * @returns The base64 encoded signature.
21
+ */
22
+ export declare function signWithPrivateKey(nonce: Base64Nonce, privateKey: Base64PrivateKey): Base64Signature;
23
+ /**
24
+ * Upload a public key to a DHE server.
25
+ * @param dheClient The DHE client to use.
26
+ * @param dheCredentials The credentials to use for authentication.
27
+ * @param publicKey The base64 encoded public key.
28
+ * @param type The type of key pair.
29
+ * @returns The response from the server.
30
+ */
31
+ export declare function uploadPublicKey(dheClient: EnterpriseClient, dheCredentials: LoginCredentials, publicKey: Base64PublicKey, type: KeyPairType): Promise<Response>;
@@ -0,0 +1,85 @@
1
+ import { generateKeyPairSync, sign } from 'node:crypto';
2
+ /*
3
+ * Named curve to use for generating key pairs.
4
+ * Note that 'prime256v1' is synonymous with 'secp256r1'.
5
+ */
6
+ const NAMED_CURVE = 'prime256v1';
7
+ /**
8
+ * Generate a base64 encoded asymmetric key pair using eliptic curve.
9
+ * @returns The base64 encoded public and private keys.
10
+ */
11
+ export function generateBase64KeyPair() {
12
+ const type = 'ec';
13
+ const { publicKey: publicKeyBuffer, privateKey: privateKeyBuffer } = generateKeyPairSync(type, {
14
+ namedCurve: NAMED_CURVE,
15
+ publicKeyEncoding: { type: 'spki', format: 'der' },
16
+ privateKeyEncoding: { type: 'pkcs8', format: 'der' },
17
+ });
18
+ const publicKey = publicKeyBuffer.toString('base64');
19
+ const privateKey = privateKeyBuffer.toString('base64');
20
+ return { type, publicKey, privateKey };
21
+ }
22
+ /**
23
+ * Prepend a sentinal value to a public key based on the given type. The
24
+ * sentinel is the uppercase type followed by a colon.
25
+ * @param type Keypair type.
26
+ * @param key Base64 encoded public key.
27
+ * @returns The key with the sentinel prepended.
28
+ */
29
+ export function keyWithSentinel(type, key) {
30
+ const ucSentinel = `${type.toUpperCase()}:`;
31
+ // The 'EC:' sentinel just happens to be 3 characters long. This plays nice
32
+ // with Base64 encoding such that it doesn't matter whether we concatenate
33
+ // before or after encoding to Base64. If we ever support sentinels with
34
+ // lengths that are not multiples of 3, changing the order of concatenation vs
35
+ // encoding produces different results. Therefore, we are concatenating bytes
36
+ // and then encoding the combined value to Base64 to match the methodology
37
+ // expected by the server and to better future proof this function if we ever
38
+ // suport types other than 'ec'.
39
+ const sentinelBytes = Buffer.from(ucSentinel);
40
+ const keyBytes = Buffer.from(key, 'base64');
41
+ return Buffer.concat([sentinelBytes, keyBytes]).toString('base64');
42
+ }
43
+ /**
44
+ * Sign a nonce using a private key.
45
+ * @param nonce Base64 encoded nonce.
46
+ * @param privateKey Base64 encoded private key.
47
+ * @returns The base64 encoded signature.
48
+ */
49
+ export function signWithPrivateKey(nonce, privateKey) {
50
+ const nonceBytes = Buffer.from(nonce, 'base64');
51
+ const privateKeyBytes = Buffer.from(privateKey, 'base64');
52
+ return sign('sha256', nonceBytes, {
53
+ key: privateKeyBytes,
54
+ format: 'der',
55
+ type: 'pkcs8',
56
+ }).toString('base64');
57
+ }
58
+ /**
59
+ * Upload a public key to a DHE server.
60
+ * @param dheClient The DHE client to use.
61
+ * @param dheCredentials The credentials to use for authentication.
62
+ * @param publicKey The base64 encoded public key.
63
+ * @param type The type of key pair.
64
+ * @returns The response from the server.
65
+ */
66
+ export async function uploadPublicKey(dheClient, dheCredentials, publicKey, type) {
67
+ await dheClient.login(dheCredentials);
68
+ const { dbAclWriterHost, dbAclWriterPort } = await dheClient.getServerConfigValues();
69
+ const body = {
70
+ user: dheCredentials.username,
71
+ encodedStr: keyWithSentinel(type, publicKey),
72
+ algorithm: type.toUpperCase(),
73
+ comment: `Generated by vscode extension ${new Date().toISOString()}`,
74
+ };
75
+ return fetch(`https://${dbAclWriterHost}:${dbAclWriterPort}/acl/publickey`, {
76
+ method: 'POST',
77
+ headers: {
78
+ /* eslint-disable @typescript-eslint/naming-convention */
79
+ Authorization: await dheClient.createAuthToken('DbAclWriteServer'),
80
+ 'Content-Type': 'application/json',
81
+ /* eslint-enable @typescript-eslint/naming-convention */
82
+ },
83
+ body: JSON.stringify(body),
84
+ });
85
+ }
@@ -0,0 +1,16 @@
1
+ import type { AuthenticatedClient, PasswordCredentials, KeyPairCredentials, UnauthenticatedClient } from './types.js';
2
+ /**
3
+ * Authenticate a given client with username and password. Return the
4
+ * authenticated client.
5
+ * @param dheClient The DHE client to authenticate.
6
+ * @param credentials The user / password credentials to use for authentication.
7
+ * @returns The authenticated client.
8
+ */
9
+ export declare function loginClientWithPassword(dheClient: UnauthenticatedClient, credentials: PasswordCredentials): Promise<AuthenticatedClient>;
10
+ /**
11
+ * Authenticate a given client with a key pair. Return the authenticated client.
12
+ * @param dheClient The DHE client to authenticate.
13
+ * @param credentials The key pair credentials to use for authentication.
14
+ * @returns The authenticated client.
15
+ */
16
+ export declare function loginClientWithKeyPair(dheClient: UnauthenticatedClient, credentials: KeyPairCredentials): Promise<AuthenticatedClient>;
@@ -0,0 +1,44 @@
1
+ // Have to use full path with extension in order to get type safety.
2
+ // deephaven/web-client-ui/issues/2273 to address the underlying issue.
3
+ import Log from '@deephaven/log/dist/Log.js';
4
+ import { keyWithSentinel, signWithPrivateKey } from './keyPairUtils.js';
5
+ const logger = Log.module('@deephaven-enterprise/auth-nodejs:loginUtils');
6
+ /**
7
+ * Authenticate a given client with username and password. Return the
8
+ * authenticated client.
9
+ * @param dheClient The DHE client to authenticate.
10
+ * @param credentials The user / password credentials to use for authentication.
11
+ * @returns The authenticated client.
12
+ */
13
+ export async function loginClientWithPassword(dheClient, credentials) {
14
+ logger.debug('Login with username / password:', credentials.username);
15
+ try {
16
+ await dheClient.login(credentials);
17
+ }
18
+ catch (err) {
19
+ logger.error('An error occurred when signing in with username / password', err);
20
+ throw err;
21
+ }
22
+ return dheClient;
23
+ }
24
+ /**
25
+ * Authenticate a given client with a key pair. Return the authenticated client.
26
+ * @param dheClient The DHE client to authenticate.
27
+ * @param credentials The key pair credentials to use for authentication.
28
+ * @returns The authenticated client.
29
+ */
30
+ export async function loginClientWithKeyPair(dheClient, credentials) {
31
+ logger.debug('Login with private key:', credentials.username);
32
+ const { username, keyPair, operateAs = username } = credentials;
33
+ const { type, publicKey, privateKey } = keyPair;
34
+ try {
35
+ const { nonce } = await dheClient.getChallengeNonce();
36
+ const signedNonce = signWithPrivateKey(nonce, privateKey);
37
+ await dheClient.challengeResponse(signedNonce, keyWithSentinel(type, publicKey), username, operateAs);
38
+ }
39
+ catch (err) {
40
+ logger.error('An error occurred when signing in with public / private key', err);
41
+ throw err;
42
+ }
43
+ return dheClient;
44
+ }
@@ -0,0 +1,41 @@
1
+ import type { Brand } from '@deephaven/utils/dist/TypeUtils.js';
2
+ import type { EnterpriseClient } from '@deephaven-enterprise/jsapi-types';
3
+ export type AuthenticatedClient = Brand<'AuthenticatedClient', EnterpriseClient>;
4
+ export type UnauthenticatedClient = Brand<'UnauthenticatedClient', EnterpriseClient>;
5
+ export type Base64Nonce = Brand<'Base64Nonce', string>;
6
+ export type Base64Signature = Brand<'Base64Signature', string>;
7
+ export type Base64PrivateKey = Brand<'Base64PrivateKey', string>;
8
+ export type Base64PublicKey = Brand<'Base64PublicKey', string>;
9
+ export type KeyPairType = 'ec';
10
+ export type Base64KeyPair = {
11
+ type: KeyPairType;
12
+ publicKey: Base64PublicKey;
13
+ privateKey: Base64PrivateKey;
14
+ };
15
+ export type Username = Brand<'Username', string>;
16
+ export type OperateAsUsername = Brand<'OperateAsUsername', string>;
17
+ export type PasswordCredentialsType = 'password';
18
+ export type KeyPairCredentialsType = 'keyPair';
19
+ export type PasswordCredentials = {
20
+ type: PasswordCredentialsType;
21
+ username: Username;
22
+ token: string;
23
+ operateAs?: OperateAsUsername;
24
+ };
25
+ export type KeyPairCredentials = {
26
+ type: KeyPairCredentialsType;
27
+ username: Username;
28
+ keyPair: Base64KeyPair;
29
+ operateAs?: OperateAsUsername;
30
+ };
31
+ /**
32
+ * Overrides of jsapi-types.
33
+ */
34
+ declare module '@deephaven-enterprise/jsapi-types' {
35
+ interface EnterpriseClient {
36
+ getChallengeNonce(): Promise<{
37
+ algorithm: 'SHA256withDSA';
38
+ nonce: Base64Nonce;
39
+ }>;
40
+ }
41
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@deephaven-enterprise/auth-nodejs",
3
+ "version": "1.20240723.107-alpha-auth-nodejs.23555+733874b7bf",
4
+ "description": "Deephaven Enterprise Auth Utils for NodeJS",
5
+ "author": "Deephaven Data Labs LLC",
6
+ "license": "SEE LICENSE IN LICENSE.md",
7
+ "type": "module",
8
+ "private": false,
9
+ "source": "src/index.ts",
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "sideEffects": false,
16
+ "scripts": {
17
+ "build": "tsc --build"
18
+ },
19
+ "dependencies": {
20
+ "@deephaven-enterprise/jsapi-types": "^1.20240723.107-alpha-auth-nodejs.23555+733874b7bf",
21
+ "@deephaven/log": "^0.97.0",
22
+ "@deephaven/utils": "^0.97.0"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "gitHead": "733874b7bf600538bbef2641047b258dc03ef83a"
28
+ }