@sap_oss/wdio-qmate-service 2.13.2 → 2.14.1

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.
Files changed (39) hide show
  1. package/.eslintignore +2 -1
  2. package/lib/reuse/modules/types.d.ts +5 -0
  3. package/lib/reuse/modules/util/Util.d.ts +2 -1
  4. package/lib/reuse/modules/util/Util.js +1 -0
  5. package/lib/reuse/modules/util/Util.js.map +1 -1
  6. package/lib/reuse/modules/util/data.d.ts +6 -2
  7. package/lib/reuse/modules/util/data.js +21 -9
  8. package/lib/reuse/modules/util/data.js.map +1 -1
  9. package/lib/scripts/hooks/utils/decryption.d.ts +0 -17
  10. package/lib/scripts/hooks/utils/decryption.js +24 -121
  11. package/lib/scripts/hooks/utils/decryption.js.map +1 -1
  12. package/package.json +3 -2
  13. package/packages/qcrypt/dist/classes/Decrypter.d.ts +41 -0
  14. package/packages/qcrypt/dist/classes/Decrypter.js +172 -0
  15. package/packages/qcrypt/dist/classes/Encrypter.d.ts +49 -0
  16. package/packages/qcrypt/dist/classes/Encrypter.js +164 -0
  17. package/packages/qcrypt/dist/classes/KeyGenerator.d.ts +19 -0
  18. package/packages/qcrypt/dist/classes/KeyGenerator.js +53 -0
  19. package/packages/qcrypt/dist/classes/helper/ErrorHandler.d.ts +11 -0
  20. package/packages/qcrypt/dist/classes/helper/ErrorHandler.js +69 -0
  21. package/packages/qcrypt/dist/classes/helper/Util.d.ts +69 -0
  22. package/packages/qcrypt/dist/classes/helper/Util.js +126 -0
  23. package/packages/qcrypt/dist/constants/common.d.ts +12 -0
  24. package/packages/qcrypt/dist/constants/common.js +15 -0
  25. package/packages/qcrypt/dist/index.d.ts +4 -0
  26. package/packages/qcrypt/dist/index.js +12 -0
  27. package/packages/qcrypt/dist/keys/public.key +8 -0
  28. package/packages/qcrypt/dist/types/common.d.ts +27 -0
  29. package/packages/qcrypt/dist/types/common.js +2 -0
  30. package/packages/qcrypt/package.json +8 -0
  31. package/test/reuse/util/data/data/decrypt.base64.secure.json +3 -0
  32. package/test/reuse/util/data/data/decrypt.noRepo.secure.json +3 -0
  33. package/test/reuse/util/data/data/decrypt.secure.json +3 -0
  34. package/test/reuse/util/data/data/{test.secure.json → getSecureData.secure.json} +1 -1
  35. package/test/reuse/util/data/decrypt.spec.js +57 -4
  36. package/test/reuse/util/data/{getSecureData.spec.js → getSecureData1.spec.js} +11 -15
  37. package/test/reuse/util/data/getSecureData2.spec.js +11 -0
  38. package/test/reuse/util/data/test.data.privacy.conf.js +5 -2
  39. /package/test/reuse/util/data/customSourceData/{test.secure.json → getSecureData.secure.json} +0 -0
@@ -0,0 +1,49 @@
1
+ import { EncodedData, EncryptionOptions, PrintOptions, PublicKey } from "../types/common";
2
+ export default abstract class Encrypter {
3
+ /**
4
+ * @description Retrieves public keys from the file system and encrypts data for all of them.
5
+ * @param data Data to be encrypted.
6
+ * @param encryptionOptions Encryption options.
7
+ * @param printOptions Print options defining if the input and output is logged or not.
8
+ */
9
+ static encryptDataForAvailableKeys(data: string, encryptionOptions: EncryptionOptions, printOptions: PrintOptions): Array<EncodedData>;
10
+ /**
11
+ * @description Encrypts data for all passed public keys.
12
+ * @param data Data to be encrypted.
13
+ * @param encryptionOptions Encryption options.
14
+ * @param publicKeys Public keys for encryption.
15
+ */
16
+ static encryptDataForMultipleKeys(data: string, encryptionOptions: EncryptionOptions, publicKeys: Array<PublicKey>): Array<EncodedData>;
17
+ /**
18
+ * @description Retrieves the public keys from the file system.
19
+ * @param keyPath Path to the directory containing the public key.
20
+ * @returns An array containing public key objects.
21
+ */
22
+ private static _retrievePublicKeys;
23
+ /**
24
+ * @description Encrypts the given data with the provided public key and options.
25
+ * @param data Data to be encrypted.
26
+ * @param publicKey Public key for encryption.
27
+ * @param options Encryption options.
28
+ * @returns The encrypted data.
29
+ */
30
+ private static _encryptData;
31
+ /**
32
+ * @description Encrypts data using AES-256-CBC encryption and PBKDF2 key derivation. The key is derived from the repo URL or a static password.
33
+ * @param data Data to be encrypted.
34
+ * @param options Encryption options.
35
+ * @returns The AES encrypted data.
36
+ */
37
+ private static _encryptDataWithPassword;
38
+ /**
39
+ * @description Prints the input options and data to the console.
40
+ * @param options Encryption options.
41
+ * @param data Data to be encrypted.
42
+ */
43
+ private static _printInput;
44
+ /**
45
+ * @description Prints the output data and metadata to the console for multiple pieces of data.
46
+ * @param encodedDataList An array of encoded data objects containing root and encodedData.
47
+ */
48
+ private static _printOutput;
49
+ }
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // Imports
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const crypto_1 = __importDefault(require("crypto"));
10
+ const Util_1 = __importDefault(require("./helper/Util"));
11
+ const ErrorHandler_1 = __importDefault(require("./helper/ErrorHandler"));
12
+ // Constants
13
+ const common_1 = require("../constants/common");
14
+ class Encrypter {
15
+ // ========================== Public functions ==========================
16
+ /**
17
+ * @description Retrieves public keys from the file system and encrypts data for all of them.
18
+ * @param data Data to be encrypted.
19
+ * @param encryptionOptions Encryption options.
20
+ * @param printOptions Print options defining if the input and output is logged or not.
21
+ */
22
+ static encryptDataForAvailableKeys(data, encryptionOptions, printOptions) {
23
+ if (printOptions === null || printOptions === void 0 ? void 0 : printOptions.printInput) {
24
+ this._printInput(data, encryptionOptions);
25
+ }
26
+ const commonKeyPath = path_1.default.resolve(__dirname, "../keys");
27
+ const publicKeys = this._retrievePublicKeys(commonKeyPath);
28
+ const encryptedData = this.encryptDataForMultipleKeys(data, encryptionOptions, publicKeys);
29
+ if (printOptions === null || printOptions === void 0 ? void 0 : printOptions.printOutput) {
30
+ this._printOutput(encryptedData);
31
+ }
32
+ return encryptedData;
33
+ }
34
+ /**
35
+ * @description Encrypts data for all passed public keys.
36
+ * @param data Data to be encrypted.
37
+ * @param encryptionOptions Encryption options.
38
+ * @param publicKeys Public keys for encryption.
39
+ */
40
+ static encryptDataForMultipleKeys(data, encryptionOptions, publicKeys) {
41
+ const encodedDataAggregated = [];
42
+ data = encryptionOptions.useBase64Input ? Util_1.default.base64ToUtf8(data) : data;
43
+ for (const pk of publicKeys) {
44
+ let encryptedData;
45
+ try {
46
+ encryptedData = this._encryptData(data, pk.key, encryptionOptions);
47
+ }
48
+ catch (error) {
49
+ ErrorHandler_1.default.handleAndThrowError(error, `Encryption failed`);
50
+ }
51
+ const encodedData = encryptionOptions.useBase64Output ? Util_1.default.utf8ToBase64(encryptedData) : encryptedData;
52
+ encodedDataAggregated.push({ root: pk.root, encodedData });
53
+ }
54
+ return encodedDataAggregated;
55
+ }
56
+ // ========================== Private functions ==========================
57
+ /**
58
+ * @description Retrieves the public keys from the file system.
59
+ * @param keyPath Path to the directory containing the public key.
60
+ * @returns An array containing public key objects.
61
+ */
62
+ static _retrievePublicKeys(keyPath) {
63
+ const publicKeys = [];
64
+ try {
65
+ const publicKey = fs_1.default.readFileSync(path_1.default.resolve(process.cwd(), common_1.PUBLIC_KEY_NAME), "utf8");
66
+ publicKeys.push({ root: "cwd", key: publicKey });
67
+ }
68
+ catch (_a) {
69
+ // Do nothing
70
+ }
71
+ try {
72
+ const publicKey = fs_1.default.readFileSync(path_1.default.resolve(keyPath, common_1.PUBLIC_KEY_NAME), "utf8");
73
+ publicKeys.push({ root: "qmate", key: publicKey });
74
+ }
75
+ catch (_b) {
76
+ // Do nothing
77
+ }
78
+ if (publicKeys.length < 1) {
79
+ throw new Error(`${ErrorHandler_1.default.NO_PUBLIC_KEY_ERROR_MESSAGE}.`);
80
+ }
81
+ return publicKeys;
82
+ }
83
+ /**
84
+ * @description Encrypts the given data with the provided public key and options.
85
+ * @param data Data to be encrypted.
86
+ * @param publicKey Public key for encryption.
87
+ * @param options Encryption options.
88
+ * @returns The encrypted data.
89
+ */
90
+ static _encryptData(data, publicKey, options) {
91
+ try {
92
+ const encryptedDataByKey = crypto_1.default.publicEncrypt({
93
+ key: Util_1.default.parseKeyByEncoding(publicKey),
94
+ padding: crypto_1.default.constants.RSA_PKCS1_OAEP_PADDING,
95
+ oaepHash: "sha256"
96
+ }, Buffer.from(data));
97
+ return this._encryptDataWithPassword(encryptedDataByKey.toString("base64"), options);
98
+ }
99
+ catch (error) {
100
+ ErrorHandler_1.default.handleAndThrowError(error);
101
+ }
102
+ }
103
+ /**
104
+ * @description Encrypts data using AES-256-CBC encryption and PBKDF2 key derivation. The key is derived from the repo URL or a static password.
105
+ * @param data Data to be encrypted.
106
+ * @param options Encryption options.
107
+ * @returns The AES encrypted data.
108
+ */
109
+ static _encryptDataWithPassword(data, options) {
110
+ let key;
111
+ if (options.includeRepoUrl) {
112
+ const repoUrl = Util_1.default.getRepoUrl();
113
+ const repoUrlContractHashed = Util_1.default.unifyRepoUrl(repoUrl);
114
+ key = crypto_1.default.pbkdf2Sync(repoUrlContractHashed, common_1.SALT, common_1.ITERATIONS, common_1.KEY_LENGTH, common_1.DIGEST);
115
+ }
116
+ else {
117
+ key = crypto_1.default.pbkdf2Sync(common_1.STATIC_PASSWORD, common_1.SALT, common_1.ITERATIONS, common_1.KEY_LENGTH, common_1.DIGEST);
118
+ }
119
+ const cipher = crypto_1.default.createCipheriv(common_1.ALGORITHM, key, common_1.IV);
120
+ let encryptedData = cipher.update(data, "utf-8", "hex");
121
+ encryptedData += cipher.final("hex");
122
+ return encryptedData;
123
+ }
124
+ /**
125
+ * @description Prints the input options and data to the console.
126
+ * @param options Encryption options.
127
+ * @param data Data to be encrypted.
128
+ */
129
+ static _printInput(data, options) {
130
+ console.log("\n===========INPUT==========================================================");
131
+ if (options.includeRepoUrl || options.useBase64Output || options.useBase64Input) {
132
+ console.log("Options:");
133
+ if (options.includeRepoUrl) {
134
+ console.log("\x1b[33m - Using repo URL in key derivation.\x1b[0m");
135
+ }
136
+ if (options.useBase64Input) {
137
+ console.log("\x1b[33m - Input data is processed as base64 format.\x1b[0m");
138
+ }
139
+ if (options.useBase64Output) {
140
+ console.log("\x1b[33m - Output data is displayed in base64 format.\x1b[0m");
141
+ }
142
+ console.log("");
143
+ }
144
+ console.log(`Input Data: ${data}`);
145
+ console.log("==========================================================================\n");
146
+ }
147
+ /**
148
+ * @description Prints the output data and metadata to the console for multiple pieces of data.
149
+ * @param encodedDataList An array of encoded data objects containing root and encodedData.
150
+ */
151
+ static _printOutput(encodedDataList) {
152
+ console.log("\n===========OUTPUT=========================================================");
153
+ console.log(`Processing Info:`);
154
+ // Iterate through the array and print details for each entry
155
+ encodedDataList.forEach(({ root, encodedData }) => {
156
+ const rootMessage = root === "cwd" ? "current working directory" : "qmate module";
157
+ console.log(`\x1b[33m - Public key is used from ${rootMessage}.\x1b[0m\n`);
158
+ console.log("Encrypted Data ⬎");
159
+ console.log(`\x1b[32m${encodedData}\x1b[0m\n`);
160
+ });
161
+ console.log("==========================================================================");
162
+ }
163
+ }
164
+ exports.default = Encrypter;
@@ -0,0 +1,19 @@
1
+ import { KeyGenerationOptions } from "../types/common";
2
+ export default abstract class KeyGenerator {
3
+ /**
4
+ * @description Generates a key pair and prints it to the console.
5
+ * @param options Key generation options.
6
+ */
7
+ static generateKeyPair(options: KeyGenerationOptions): void;
8
+ /**
9
+ * @description Prints the input options to the console.
10
+ * @param options Key generation options.
11
+ */
12
+ private static _printInput;
13
+ /**
14
+ * @description Prints the generated key pair to the console.
15
+ * @param publicKey The generated public key.
16
+ * @param privateKey The generated private key.
17
+ */
18
+ private static _printOutput;
19
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // Imports
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ // Constants
9
+ const common_1 = require("../constants/common");
10
+ class KeyGenerator {
11
+ // ========================== Public functions ==========================
12
+ /**
13
+ * @description Generates a key pair and prints it to the console.
14
+ * @param options Key generation options.
15
+ */
16
+ static generateKeyPair(options) {
17
+ this._printInput(options);
18
+ const { publicKey, privateKey } = crypto_1.default.generateKeyPairSync(common_1.KEY_TYPE, { modulusLength: 2048 });
19
+ const publicKeyExported = publicKey.export({ type: common_1.KEY_EXPORT_TYPE, format: common_1.KEY_EXPORT_FORMAT });
20
+ const privateKeyExported = privateKey.export({ type: common_1.KEY_EXPORT_TYPE, format: common_1.KEY_EXPORT_FORMAT });
21
+ const publicKeyFormatted = options.useBase64Encoding ? Buffer.from(publicKeyExported, "utf8").toString("base64") : publicKeyExported;
22
+ const privateKeyFormatted = options.useBase64Encoding ? Buffer.from(privateKeyExported, "utf8").toString("base64") : privateKeyExported;
23
+ this._printOutput(publicKeyFormatted, privateKeyFormatted);
24
+ }
25
+ // ========================== Private functions ==========================
26
+ /**
27
+ * @description Prints the input options to the console.
28
+ * @param options Key generation options.
29
+ */
30
+ static _printInput(options) {
31
+ if (options.useBase64Encoding) {
32
+ console.log("\n===========OPTIONS==========================================================");
33
+ if (options.useBase64Encoding) {
34
+ console.log("\x1b[33m - Output data is displayed in base64 format.\x1b[0m");
35
+ }
36
+ console.log("==========================================================================");
37
+ }
38
+ }
39
+ /**
40
+ * @description Prints the generated key pair to the console.
41
+ * @param publicKey The generated public key.
42
+ * @param privateKey The generated private key.
43
+ */
44
+ static _printOutput(publicKey, privateKey) {
45
+ console.log("\n===========OUTPUT=========================================================");
46
+ console.log("Public Key ⬎");
47
+ console.log(`\x1b[32m${publicKey}\x1b[0m\n`);
48
+ console.log("Private Key ⬎");
49
+ console.log(`\x1b[33m${privateKey}\x1b[0m`);
50
+ console.log("==========================================================================");
51
+ }
52
+ }
53
+ exports.default = KeyGenerator;
@@ -0,0 +1,11 @@
1
+ import { DecryptionOptions } from "../../types/common";
2
+ export default abstract class ErrorHandler {
3
+ static UNKNOWN_ERROR_MESSAGE: string;
4
+ static NO_PUBLIC_KEY_ERROR_MESSAGE: string;
5
+ static NO_PRIVATE_KEY_ERROR_MESSAGE: string;
6
+ static INVALID_PRIVATE_KEY_ERROR_MESSAGE: string;
7
+ static DECRYPTION_ERROR_MESSAGE: string;
8
+ static handleAndThrowError(error: Error | unknown, customMessage?: string): never;
9
+ static handleDecryptDataWithPasswordError(error: Error, options: DecryptionOptions): string;
10
+ static handleDecryptDataWithPrivateKeyError(error: Error): string;
11
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ErrorHandler {
4
+ // ========================== Public functions ==========================
5
+ // Common error handlers
6
+ static handleAndThrowError(error, customMessage) {
7
+ if (error instanceof Error) {
8
+ if (customMessage) {
9
+ throw new Error(`${customMessage}: ${error.message}`);
10
+ }
11
+ else {
12
+ throw new Error(error.message);
13
+ }
14
+ }
15
+ else {
16
+ throw new Error(ErrorHandler.UNKNOWN_ERROR_MESSAGE);
17
+ }
18
+ }
19
+ // Decryption error handlers
20
+ static handleDecryptDataWithPasswordError(error, options) {
21
+ let errorMessage = error.message;
22
+ switch (error.message) {
23
+ case "error:1C800064:Provider routines::bad decrypt":
24
+ errorMessage = "The data is not encrypted with the correct key.";
25
+ if (options.includeRepoUrl) {
26
+ errorMessage += " Make sure the data is encrypted from the correct repository.";
27
+ }
28
+ break;
29
+ case "error:1C80006B:Provider routines::wrong final block length":
30
+ errorMessage = "The data is not encrypted with the correct key or the data is corrupted.";
31
+ if (options.useBase64Input) {
32
+ errorMessage += " Make sure the input data is valid base64 format.";
33
+ }
34
+ if (options.includeRepoUrl) {
35
+ errorMessage += " Make sure the data is encrypted from the correct repository.";
36
+ }
37
+ break;
38
+ default:
39
+ errorMessage = `${this.UNKNOWN_ERROR_MESSAGE}: ${error.message}`;
40
+ break;
41
+ }
42
+ return errorMessage;
43
+ }
44
+ static handleDecryptDataWithPrivateKeyError(error) {
45
+ let errorMessage = error.message;
46
+ switch (error.message) {
47
+ case "error:1E08010C:DECODER routines::unsupported":
48
+ errorMessage = `${this.INVALID_PRIVATE_KEY_ERROR_MESSAGE}.`;
49
+ break;
50
+ case "Invalid base64 format. Please provide a valid base64 encoded string.":
51
+ errorMessage = `${this.INVALID_PRIVATE_KEY_ERROR_MESSAGE}.`;
52
+ break;
53
+ default:
54
+ errorMessage = `${this.UNKNOWN_ERROR_MESSAGE}: ${error.message}`;
55
+ break;
56
+ }
57
+ return errorMessage;
58
+ }
59
+ }
60
+ // ========================== Constants =================================
61
+ // Common error messages
62
+ ErrorHandler.UNKNOWN_ERROR_MESSAGE = "Unknown error occurred";
63
+ // Encryption error messages
64
+ ErrorHandler.NO_PUBLIC_KEY_ERROR_MESSAGE = "Encryption failed: No public key found";
65
+ // Decryption error messages
66
+ ErrorHandler.NO_PRIVATE_KEY_ERROR_MESSAGE = "Decryption failed: No private key found";
67
+ ErrorHandler.INVALID_PRIVATE_KEY_ERROR_MESSAGE = "Invalid private key";
68
+ ErrorHandler.DECRYPTION_ERROR_MESSAGE = "Decryption failed: None of the given data values could be decrypted using the given private key";
69
+ exports.default = ErrorHandler;
@@ -0,0 +1,69 @@
1
+ export default abstract class Util {
2
+ /**
3
+ * @description Converts the given string to base64.
4
+ * @param string The string to be converted.
5
+ * @returns The base64 encoded string.
6
+ */
7
+ static base64ToUtf8(string: string): string;
8
+ /**
9
+ * @description Converts the given string to base64.
10
+ * @param string The string to be converted.
11
+ * @returns The base64 encoded string.
12
+ */
13
+ static utf8ToBase64(string: string): string;
14
+ /**
15
+ * @description Checks if the given string is base64 encoded.
16
+ * @param string The string to be checked.
17
+ * @returns True if the string is base64 encoded, false otherwise.
18
+ */
19
+ static isBase64(string: string): boolean;
20
+ /**
21
+ * @description Parses the key by encoding.
22
+ * @param key The key to be parsed.
23
+ * @returns The parsed key.
24
+ */
25
+ static parseKeyByEncoding(key: string): string;
26
+ /**
27
+ * @description Normalizes the key by removing spaces and new lines.
28
+ * @param key The key to be normalized.
29
+ * @returns The normalized key.
30
+ */
31
+ static normalizeKey(key: string): string;
32
+ /**
33
+ * @description Retrieves the repository URL from the git configuration.
34
+ * @returns The repository URL.
35
+ */
36
+ static getRepoUrl(): string;
37
+ /**
38
+ * @description Unifies the repository URL into a consistent hash format.
39
+ * @param url The repository URL.
40
+ * @returns The hashed URL.
41
+ */
42
+ static unifyRepoUrl(url: string): string;
43
+ /**
44
+ * @description Unifies the HTTP repository URL into a consistent hash format.
45
+ * @param url The repository URL.
46
+ * @returns The hashed URL.
47
+ */
48
+ static unifyHTTPUrl(url: string): string;
49
+ /**
50
+ * @description Unifies the SSH repository URL into a consistent hash format.
51
+ * @param url The repository URL.
52
+ * @returns The hashed URL.
53
+ */
54
+ static unifySSHUrl(url: string): string;
55
+ /**
56
+ * @description Hashes the host, account, and repository into a consistent format.
57
+ * @param host The repository host.
58
+ * @param account The repository account.
59
+ * @param repo The repository name.
60
+ * @returns The hashed host, account, and repository.
61
+ */
62
+ static hashHostAccountAndRepo(host: string, account: string, repo: string): string;
63
+ /**
64
+ * @description Converts the given string to an array of strings if not yet an array.
65
+ * @param data The string or array of strings.
66
+ * @returns The array of strings.
67
+ */
68
+ static convertStringToArray(data: string | Array<string>): Array<string>;
69
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // Imports
7
+ const child_process_1 = __importDefault(require("child_process"));
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ class Util {
10
+ /**
11
+ * @description Converts the given string to base64.
12
+ * @param string The string to be converted.
13
+ * @returns The base64 encoded string.
14
+ */
15
+ static base64ToUtf8(string) {
16
+ if (!this.isBase64(string)) {
17
+ throw new Error("Invalid base64 format. Please provide a valid base64 encoded string.");
18
+ }
19
+ return Buffer.from(string, "base64").toString("utf-8");
20
+ }
21
+ /**
22
+ * @description Converts the given string to base64.
23
+ * @param string The string to be converted.
24
+ * @returns The base64 encoded string.
25
+ */
26
+ static utf8ToBase64(string) {
27
+ return Buffer.from(string, "utf-8").toString("base64");
28
+ }
29
+ /**
30
+ * @description Checks if the given string is base64 encoded.
31
+ * @param string The string to be checked.
32
+ * @returns True if the string is base64 encoded, false otherwise.
33
+ */
34
+ static isBase64(string) {
35
+ const base64Regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
36
+ return base64Regex.test(string);
37
+ }
38
+ /**
39
+ * @description Parses the key by encoding.
40
+ * @param key The key to be parsed.
41
+ * @returns The parsed key.
42
+ */
43
+ static parseKeyByEncoding(key) {
44
+ const utf8Regex = /-*(BEGIN|END)\s\w*\s(PUBLIC|PRIVATE)\sKEY-*/;
45
+ return utf8Regex.test(key) ? key : this.base64ToUtf8(key);
46
+ }
47
+ /**
48
+ * @description Normalizes the key by removing spaces and new lines.
49
+ * @param key The key to be normalized.
50
+ * @returns The normalized key.
51
+ */
52
+ static normalizeKey(key) {
53
+ return key.replace(/\\n/gm, "\n").replace(/\\s/gm, " ");
54
+ }
55
+ /**
56
+ * @description Retrieves the repository URL from the git configuration.
57
+ * @returns The repository URL.
58
+ */
59
+ static getRepoUrl() {
60
+ try {
61
+ return child_process_1.default.execSync("git config --get remote.origin.url").toString().trim();
62
+ }
63
+ catch (_a) {
64
+ throw new Error("Please execute from a valid git repository.");
65
+ }
66
+ }
67
+ /**
68
+ * @description Unifies the repository URL into a consistent hash format.
69
+ * @param url The repository URL.
70
+ * @returns The hashed URL.
71
+ */
72
+ static unifyRepoUrl(url) {
73
+ const httpsRegex = /https?:\/\/.+/;
74
+ const sshRegex = /git@.*:.+/;
75
+ if (httpsRegex.test(url)) {
76
+ return this.unifyHTTPUrl(url);
77
+ }
78
+ else if (sshRegex.test(url)) {
79
+ return this.unifySSHUrl(url);
80
+ }
81
+ else {
82
+ throw new Error("Repo URL is not valid.");
83
+ }
84
+ }
85
+ /**
86
+ * @description Unifies the HTTP repository URL into a consistent hash format.
87
+ * @param url The repository URL.
88
+ * @returns The hashed URL.
89
+ */
90
+ static unifyHTTPUrl(url) {
91
+ const [host, account, repo] = url.replace(/https?:\/\//, "").split("/");
92
+ return this.hashHostAccountAndRepo(host, account, repo.replace(/\.git$/, ""));
93
+ }
94
+ /**
95
+ * @description Unifies the SSH repository URL into a consistent hash format.
96
+ * @param url The repository URL.
97
+ * @returns The hashed URL.
98
+ */
99
+ static unifySSHUrl(url) {
100
+ const [hostAccount, repo] = url.replace("git@", "").split(":");
101
+ const [host, account] = hostAccount.split("/");
102
+ return this.hashHostAccountAndRepo(host, account, repo.replace(/\.git$/, ""));
103
+ }
104
+ /**
105
+ * @description Hashes the host, account, and repository into a consistent format.
106
+ * @param host The repository host.
107
+ * @param account The repository account.
108
+ * @param repo The repository name.
109
+ * @returns The hashed host, account, and repository.
110
+ */
111
+ static hashHostAccountAndRepo(host, account, repo) {
112
+ return crypto_1.default.createHash("sha256").update(`${host}${account}${repo}`).digest("hex");
113
+ }
114
+ /**
115
+ * @description Converts the given string to an array of strings if not yet an array.
116
+ * @param data The string or array of strings.
117
+ * @returns The array of strings.
118
+ */
119
+ static convertStringToArray(data) {
120
+ if (typeof data === "string") {
121
+ data = [data];
122
+ }
123
+ return data;
124
+ }
125
+ }
126
+ exports.default = Util;
@@ -0,0 +1,12 @@
1
+ export declare const PUBLIC_KEY_NAME = "public.key";
2
+ export declare const PRIVATE_KEY_NAME = "private.key";
3
+ export declare const STATIC_PASSWORD = "QMATE_STATIC";
4
+ export declare const ALGORITHM = "aes-256-cbc";
5
+ export declare const DIGEST = "sha512";
6
+ export declare const SALT = "72hdh393987f0hdc";
7
+ export declare const IV = "203efccd80e94d9f";
8
+ export declare const ITERATIONS = 100000;
9
+ export declare const KEY_LENGTH = 32;
10
+ export declare const KEY_TYPE = "rsa";
11
+ export declare const KEY_EXPORT_TYPE = "pkcs1";
12
+ export declare const KEY_EXPORT_FORMAT = "pem";
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KEY_EXPORT_FORMAT = exports.KEY_EXPORT_TYPE = exports.KEY_TYPE = exports.KEY_LENGTH = exports.ITERATIONS = exports.IV = exports.SALT = exports.DIGEST = exports.ALGORITHM = exports.STATIC_PASSWORD = exports.PRIVATE_KEY_NAME = exports.PUBLIC_KEY_NAME = void 0;
4
+ exports.PUBLIC_KEY_NAME = "public.key";
5
+ exports.PRIVATE_KEY_NAME = "private.key";
6
+ exports.STATIC_PASSWORD = "QMATE_STATIC";
7
+ exports.ALGORITHM = "aes-256-cbc";
8
+ exports.DIGEST = "sha512";
9
+ exports.SALT = "72hdh393987f0hdc";
10
+ exports.IV = "203efccd80e94d9f";
11
+ exports.ITERATIONS = 100000;
12
+ exports.KEY_LENGTH = 32;
13
+ exports.KEY_TYPE = "rsa";
14
+ exports.KEY_EXPORT_TYPE = "pkcs1";
15
+ exports.KEY_EXPORT_FORMAT = "pem";
@@ -0,0 +1,4 @@
1
+ import Encrypter from "./classes/Encrypter";
2
+ import Decrypter from "./classes/Decrypter";
3
+ import KeyGenerator from "./classes/KeyGenerator";
4
+ export { Decrypter, Encrypter, KeyGenerator };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.KeyGenerator = exports.Encrypter = exports.Decrypter = void 0;
7
+ const Encrypter_1 = __importDefault(require("./classes/Encrypter"));
8
+ exports.Encrypter = Encrypter_1.default;
9
+ const Decrypter_1 = __importDefault(require("./classes/Decrypter"));
10
+ exports.Decrypter = Decrypter_1.default;
11
+ const KeyGenerator_1 = __importDefault(require("./classes/KeyGenerator"));
12
+ exports.KeyGenerator = KeyGenerator_1.default;
@@ -0,0 +1,8 @@
1
+ -----BEGIN RSA PUBLIC KEY-----
2
+ MIIBCgKCAQEA4IRW72V6EgSF4ukoToruv7M5tOVw+SyAxnicAAQ6ByZZkXeDgrIC
3
+ ePxceWVugIDazNC0fOCKARFd06OThhRfQ9UftIb2Aju/00AygY3jsO/xTmwTLwcK
4
+ mVYbFeSUc4NKYyqvB2vfJeC0Y6zSzlMmWe9NL8vTpHsrLT9jBaeG+8Yc6Uw/j+qH
5
+ swxdu9lyzTgcIiq3oYuDQIQr8jDclQ8oLVo11xTyvcmOpyrtSan7d953sxgsSKr6
6
+ +fGkLXrfzBswTGxYyQkqVdYiRGI0HFLcYDk6Qd77q0GQjF3zP0v3o1CA943I75i1
7
+ 5RMPI29WGC+QIHm6XFVcq4ie/D6Ixx2/IQIDAQAB
8
+ -----END RSA PUBLIC KEY-----
@@ -0,0 +1,27 @@
1
+ export interface EncryptionOptions {
2
+ includeRepoUrl: boolean;
3
+ useBase64Output: boolean;
4
+ useBase64Input: boolean;
5
+ }
6
+ export interface DecryptionOptions {
7
+ includeRepoUrl: boolean;
8
+ useBase64Output: boolean;
9
+ useBase64Input: boolean;
10
+ }
11
+ export interface KeyGenerationOptions {
12
+ useBase64Encoding: boolean;
13
+ }
14
+ export interface PrintOptions {
15
+ printInput: boolean;
16
+ printOutput: boolean;
17
+ }
18
+ export interface PublicKey {
19
+ root: KeyRoot;
20
+ key: string;
21
+ }
22
+ export interface EncodedData {
23
+ root: KeyRoot;
24
+ encodedData: string;
25
+ }
26
+ export type KeyRoot = "cwd" | "qmate";
27
+ export type SecureData = string | Array<string>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "qcrypt",
3
+ "version": "1.0.2",
4
+ "description": "Local version of qcrypt package",
5
+ "author": "I503232",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts"
8
+ }