Commit iniziale

This commit is contained in:
Paolo A
2025-02-18 22:59:07 +00:00
commit 4bbf35cefb
6879 changed files with 623784 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
import { ICrypto, PkceCodes } from "@azure/msal-common/node";
/**
* This class implements MSAL node's crypto interface, which allows it to perform base64 encoding and decoding, generating cryptographically random GUIDs and
* implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
* @public
*/
export declare class CryptoProvider implements ICrypto {
private pkceGenerator;
private guidGenerator;
private hashUtils;
constructor();
/**
* base64 URL safe encoded string
*/
base64UrlEncode(): string;
/**
* Stringifies and base64Url encodes input public key
* @param inputKid - public key id
* @returns Base64Url encoded public key
*/
encodeKid(): string;
/**
* Creates a new random GUID - used to populate state and nonce.
* @returns string (GUID)
*/
createNewGuid(): string;
/**
* Encodes input string to base64.
* @param input - string to be encoded
*/
base64Encode(input: string): string;
/**
* Decodes input string from base64.
* @param input - string to be decoded
*/
base64Decode(input: string): string;
/**
* Generates PKCE codes used in Authorization Code Flow.
*/
generatePkceCodes(): Promise<PkceCodes>;
/**
* Generates a keypair, stores it and returns a thumbprint - not yet implemented for node
*/
getPublicKeyThumbprint(): Promise<string>;
/**
* Removes cryptographic keypair from key store matching the keyId passed in
* @param kid - public key id
*/
removeTokenBindingKey(): Promise<boolean>;
/**
* Removes all cryptographic keys from Keystore
*/
clearKeystore(): Promise<boolean>;
/**
* Signs the given object as a jwt payload with private key retrieved by given kid - currently not implemented for node
*/
signJwt(): Promise<string>;
/**
* Returns the SHA-256 hash of an input string
*/
hashString(plainText: string): Promise<string>;
}
//# sourceMappingURL=CryptoProvider.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"CryptoProvider.d.ts","sourceRoot":"","sources":["../../src/crypto/CryptoProvider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAM7D;;;;GAIG;AACH,qBAAa,cAAe,YAAW,OAAO;IAC1C,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,SAAS,CAAY;;IAS7B;;OAEG;IACH,eAAe,IAAI,MAAM;IAGzB;;;;OAIG;IACH,SAAS,IAAI,MAAM;IAInB;;;OAGG;IACH,aAAa,IAAI,MAAM;IAIvB;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAInC;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAInC;;OAEG;IACH,iBAAiB,IAAI,OAAO,CAAC,SAAS,CAAC;IAIvC;;OAEG;IACH,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIzC;;;OAGG;IACH,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC;IAIzC;;OAEG;IACH,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1B;;OAEG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAMvD"}

View File

@@ -0,0 +1,99 @@
/*! @azure/msal-node v2.16.2 2024-11-19 */
'use strict';
import { GuidGenerator } from './GuidGenerator.mjs';
import { EncodingUtils } from '../utils/EncodingUtils.mjs';
import { PkceGenerator } from './PkceGenerator.mjs';
import { HashUtils } from './HashUtils.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* This class implements MSAL node's crypto interface, which allows it to perform base64 encoding and decoding, generating cryptographically random GUIDs and
* implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
* @public
*/
class CryptoProvider {
constructor() {
// Browser crypto needs to be validated first before any other classes can be set.
this.pkceGenerator = new PkceGenerator();
this.guidGenerator = new GuidGenerator();
this.hashUtils = new HashUtils();
}
/**
* base64 URL safe encoded string
*/
base64UrlEncode() {
throw new Error("Method not implemented.");
}
/**
* Stringifies and base64Url encodes input public key
* @param inputKid - public key id
* @returns Base64Url encoded public key
*/
encodeKid() {
throw new Error("Method not implemented.");
}
/**
* Creates a new random GUID - used to populate state and nonce.
* @returns string (GUID)
*/
createNewGuid() {
return this.guidGenerator.generateGuid();
}
/**
* Encodes input string to base64.
* @param input - string to be encoded
*/
base64Encode(input) {
return EncodingUtils.base64Encode(input);
}
/**
* Decodes input string from base64.
* @param input - string to be decoded
*/
base64Decode(input) {
return EncodingUtils.base64Decode(input);
}
/**
* Generates PKCE codes used in Authorization Code Flow.
*/
generatePkceCodes() {
return this.pkceGenerator.generatePkceCodes();
}
/**
* Generates a keypair, stores it and returns a thumbprint - not yet implemented for node
*/
getPublicKeyThumbprint() {
throw new Error("Method not implemented.");
}
/**
* Removes cryptographic keypair from key store matching the keyId passed in
* @param kid - public key id
*/
removeTokenBindingKey() {
throw new Error("Method not implemented.");
}
/**
* Removes all cryptographic keys from Keystore
*/
clearKeystore() {
throw new Error("Method not implemented.");
}
/**
* Signs the given object as a jwt payload with private key retrieved by given kid - currently not implemented for node
*/
signJwt() {
throw new Error("Method not implemented.");
}
/**
* Returns the SHA-256 hash of an input string
*/
async hashString(plainText) {
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(plainText).toString("base64"), "base64");
}
}
export { CryptoProvider };
//# sourceMappingURL=CryptoProvider.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"CryptoProvider.mjs","sources":["../../src/crypto/CryptoProvider.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAAA;;;AAGG;AAQH;;;;AAIG;MACU,cAAc,CAAA;AAKvB,IAAA,WAAA,GAAA;;AAEI,QAAA,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;AACzC,QAAA,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;AACzC,QAAA,IAAI,CAAC,SA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

View File

@@ -0,0 +1,15 @@
import { IGuidGenerator } from "@azure/msal-common/node";
export declare class GuidGenerator implements IGuidGenerator {
/**
*
* RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers.
* uuidv4 generates guids from cryprtographically-string random
*/
generateGuid(): string;
/**
* verifies if a string is GUID
* @param guid
*/
isGuid(guid: string): boolean;
}
//# sourceMappingURL=GuidGenerator.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GuidGenerator.d.ts","sourceRoot":"","sources":["../../src/crypto/GuidGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,qBAAa,aAAc,YAAW,cAAc;IAChD;;;;OAIG;IACH,YAAY,IAAI,MAAM;IAItB;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAKhC"}

View File

@@ -0,0 +1,29 @@
/*! @azure/msal-node v2.16.2 2024-11-19 */
'use strict';
import { v4 } from 'uuid';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
class GuidGenerator {
/**
*
* RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers.
* uuidv4 generates guids from cryprtographically-string random
*/
generateGuid() {
return v4();
}
/**
* verifies if a string is GUID
* @param guid
*/
isGuid(guid) {
const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
return regexGuid.test(guid);
}
}
export { GuidGenerator };
//# sourceMappingURL=GuidGenerator.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GuidGenerator.mjs","sources":["../../src/crypto/GuidGenerator.ts"],"sourcesContent":[null],"names":["uuidv4"],"mappings":";;;;AAAA;;;AAGG;MAKU,aAAa,CAAA;AACtB;;;;AAIG;IACH,YAAY,GAAA;QACR,OAAOA,EAAM,EAAE,CAAC;KACnB;AAED;;;AAGG;AACH,IAAA,MAAM,CAAC,IAAY,EAAA;QACf,MAAM,SAAS,GACX,4EAA4E,CAAC;AACjF,QAAA,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC/B;AACJ;;;;"}

View File

@@ -0,0 +1,9 @@
/// <reference types="node" resolution-mode="require"/>
export declare class HashUtils {
/**
* generate 'SHA256' hash
* @param buffer
*/
sha256(buffer: string): Buffer;
}
//# sourceMappingURL=HashUtils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"HashUtils.d.ts","sourceRoot":"","sources":["../../src/crypto/HashUtils.ts"],"names":[],"mappings":";AAQA,qBAAa,SAAS;IAClB;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAGjC"}

View File

@@ -0,0 +1,21 @@
/*! @azure/msal-node v2.16.2 2024-11-19 */
'use strict';
import { Hash } from '../utils/Constants.mjs';
import crypto from 'crypto';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
class HashUtils {
/**
* generate 'SHA256' hash
* @param buffer
*/
sha256(buffer) {
return crypto.createHash(Hash.SHA256).update(buffer).digest();
}
}
export { HashUtils };
//# sourceMappingURL=HashUtils.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"HashUtils.mjs","sources":["../../src/crypto/HashUtils.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;;;AAGG;MAKU,SAAS,CAAA;AAClB;;;AAGG;AACH,IAAA,MAAM,CAAC,MAAc,EAAA;AACjB,QAAA,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;KACjE;AACJ;;;;"}

View File

@@ -0,0 +1,23 @@
import { PkceCodes } from "@azure/msal-common/node";
/**
* https://tools.ietf.org/html/rfc7636#page-8
*/
export declare class PkceGenerator {
private hashUtils;
constructor();
/**
* generates the codeVerfier and the challenge from the codeVerfier
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
*/
generatePkceCodes(): Promise<PkceCodes>;
/**
* generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
*/
private generateCodeVerifier;
/**
* generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
* @param codeVerifier
*/
private generateCodeChallengeFromVerifier;
}
//# sourceMappingURL=PkceGenerator.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"PkceGenerator.d.ts","sourceRoot":"","sources":["../../src/crypto/PkceGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAa,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAM/D;;GAEG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,SAAS,CAAY;;IAK7B;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC,SAAS,CAAC;IAM7C;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAmB5B;;;OAGG;IACH,OAAO,CAAC,iCAAiC;CAM5C"}

View File

@@ -0,0 +1,60 @@
/*! @azure/msal-node v2.16.2 2024-11-19 */
'use strict';
import { Constants } from '@azure/msal-common/node';
import { RANDOM_OCTET_SIZE, CharSet } from '../utils/Constants.mjs';
import { EncodingUtils } from '../utils/EncodingUtils.mjs';
import { HashUtils } from './HashUtils.mjs';
import crypto from 'crypto';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* https://tools.ietf.org/html/rfc7636#page-8
*/
class PkceGenerator {
constructor() {
this.hashUtils = new HashUtils();
}
/**
* generates the codeVerfier and the challenge from the codeVerfier
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
*/
async generatePkceCodes() {
const verifier = this.generateCodeVerifier();
const challenge = this.generateCodeChallengeFromVerifier(verifier);
return { verifier, challenge };
}
/**
* generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
*/
generateCodeVerifier() {
const charArr = [];
const maxNumber = 256 - (256 % CharSet.CV_CHARSET.length);
while (charArr.length <= RANDOM_OCTET_SIZE) {
const byte = crypto.randomBytes(1)[0];
if (byte >= maxNumber) {
/*
* Ignore this number to maintain randomness.
* Including it would result in an unequal distribution of characters after doing the modulo
*/
continue;
}
const index = byte % CharSet.CV_CHARSET.length;
charArr.push(CharSet.CV_CHARSET[index]);
}
const verifier = charArr.join(Constants.EMPTY_STRING);
return EncodingUtils.base64EncodeUrl(verifier);
}
/**
* generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
* @param codeVerifier
*/
generateCodeChallengeFromVerifier(codeVerifier) {
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
}
}
export { PkceGenerator };
//# sourceMappingURL=PkceGenerator.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"PkceGenerator.mjs","sources":["../../src/crypto/PkceGenerator.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;AAAA;;;AAGG;AAQH;;AAEG;MACU,aAAa,CAAA;AAGtB,IAAA,WAAA,GAAA;AACI,QAAA,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;KACpC;AACD;;;AAGG;AACH,IAAA,MAAM,iBAAiB,GAAA;AACnB,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,iCAAiC,CAAC,QAAQ,CAAC,CAAC;AACnE,QAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;KAClC;AAED;;AAEG;IACK,oBAAoB,GAAA;QACxB,MAAM,OAAO,GAAG,EAAE,CAAC;AACnB,QAAA,MAAM,SAAS,GAAG,GAAG,IAAI,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAC1D,QAAA,OAAO,OAAO,CAA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