-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[KeyVault Keys] Fixed the rollup warnings #11549
Changes from all commits
01f179e
d38c845
b7789ff
3d67616
5ab2536
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { LocalAssertion, LocalSupportedAlgorithmsRecord } from "./models"; | ||
|
||
/** | ||
* This file contains the implementation of local supported algorithms for the browser. | ||
* | ||
* We currently don't support any cryptography operation in the browser. | ||
* | ||
*/ | ||
|
||
/** | ||
* @internal | ||
* @ignore | ||
* The list of known assertions so far. | ||
* Assertions verify that the requirements to execute a local cryptography operation are met. | ||
*/ | ||
export const assertions: Record<string, LocalAssertion> = {}; | ||
|
||
/** | ||
* A plain object containing all of the locally supported algorithms. | ||
*/ | ||
export const localSupportedAlgorithms: LocalSupportedAlgorithmsRecord = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we keep the current types as is, this contraption is necessary. As soon as we get into browser support, this will expand and be coherent. |
||
RSA1_5: undefined, | ||
"RSA-OAEP": undefined, | ||
PS256: undefined, | ||
RS256: undefined, | ||
PS384: undefined, | ||
RS384: undefined, | ||
PS512: undefined, | ||
RS512: undefined | ||
}; | ||
|
||
/** | ||
* Checks whether a given algorithm name is supported or not. | ||
* @param algorithm string name of the algorithm | ||
*/ | ||
export function isLocallySupported(_algorithm: string): boolean { | ||
return false; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,14 @@ import { publicEncrypt, createVerify } from "crypto"; | |
import * as constants from "constants"; | ||
import { isNode } from "@azure/core-http"; | ||
import { JsonWebKey, KeyOperation } from "../keysModels"; | ||
import { LocalCryptographyUnsupportedError } from "./models"; | ||
import { | ||
LocalAssertion, | ||
LocalCryptographyOperationName, | ||
LocalCryptographyUnsupportedError, | ||
LocalSupportedAlgorithm, | ||
LocalSupportedAlgorithmName, | ||
LocalSupportedAlgorithmsRecord | ||
} from "./models"; | ||
import { createHash } from "./hash"; | ||
|
||
/** | ||
|
@@ -23,19 +30,6 @@ import { createHash } from "./hash"; | |
* we will be able to increase the support of our existing algorithms. | ||
*/ | ||
|
||
/** | ||
* @internal | ||
* @ignore | ||
* Abstract representation of a assertion. | ||
* Assertions verify that the requirements to execute a local cryptography operation are met. | ||
* @param key The JSON Web Key that will be used during the local operation. | ||
* @param operationName The name of the operation, as in "encrypt", "decrypt", "sign", etc. | ||
*/ | ||
export type LocalAssertion = ( | ||
key?: JsonWebKey, | ||
operationName?: LocalCryptographyOperationName | ||
) => void; | ||
|
||
/** | ||
* @internal | ||
* @ignore | ||
|
@@ -80,77 +74,6 @@ const pipeAssertions = (...assertions: LocalAssertion[]): LocalAssertion => (... | |
} | ||
}; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These types were moved to |
||
* TypeScript fancy for making plain objects require at least one key-value pair of another set of key-values. | ||
*/ | ||
export type RequireAtLeastOne<T> = { | ||
[K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>; | ||
}[keyof T]; | ||
|
||
/** | ||
* Union type representing the names of the supported local cryptography operations. | ||
*/ | ||
export type LocalCryptographyOperationName = "encrypt" | "wrapKey" | "createHash" | "verify"; | ||
|
||
/** | ||
* Abstract representation of a Local Cryptography Operation function. | ||
* @param keyPEM The string representation of a PEM key. | ||
* @param data The data used on the cryptography operation, in Buffer type. | ||
*/ | ||
export type LocalCryptographyOperationFunction = (keyPEM: string, data: Buffer) => Promise<Buffer>; | ||
|
||
/** | ||
* Abstract representation of a Local Cryptography Operation function, this time with an additional signature buffer. | ||
* @param keyPEM The string representation of a PEM key. | ||
* @param data The data used on the cryptography operation, in Buffer type. | ||
* @param signature The signature used on the cryptography operation, in Buffer type. | ||
*/ | ||
export type LocalCryptographyOperationFunctionWithSignature = ( | ||
keyPEM: string, | ||
data: Buffer, | ||
signature: Buffer | ||
) => Promise<boolean>; | ||
|
||
/** | ||
* Key-value map of local cryptography operations. | ||
*/ | ||
export type LocalCryptographyOperations = Record< | ||
LocalCryptographyOperationName, | ||
LocalCryptographyOperationFunction | LocalCryptographyOperationFunctionWithSignature | ||
>; | ||
|
||
/** | ||
* Abstract representation of a locally supported cryptography algorithm, with its assertions, | ||
* and its operations. | ||
*/ | ||
export interface LocalSupportedAlgorithm { | ||
/** | ||
* List of assertions that need to pass in order to execute this cryptography operation. | ||
*/ | ||
validate: LocalAssertion; | ||
/** | ||
* Optional algorithm used to sign or validate data. | ||
*/ | ||
signAlgorithm?: string; | ||
/** | ||
* List of local cryptography operations supported by an algorithm. | ||
*/ | ||
operations: RequireAtLeastOne<LocalCryptographyOperations>; | ||
} | ||
|
||
/** | ||
* A union type representing the names of all of the locally supported algorithms. | ||
*/ | ||
export type LocalSupportedAlgorithmName = | ||
| "RSA1_5" | ||
| "RSA-OAEP" | ||
| "PS256" | ||
| "RS256" | ||
| "PS384" | ||
| "RS384" | ||
| "PS512" | ||
| "RS512"; | ||
|
||
/** | ||
* Local support of the RSA1_5 algorithm. | ||
* We currently only support encrypting and wrapping keys with it. | ||
|
@@ -212,14 +135,6 @@ const makeSigner = (signAlgorithm: SignAlgorithmName): LocalSupportedAlgorithm = | |
}; | ||
}; | ||
|
||
/** | ||
* A Record containing all of the locally supported algorithms. | ||
*/ | ||
export type LocalSupportedAlgorithmsRecord = Record< | ||
LocalSupportedAlgorithmName, | ||
LocalSupportedAlgorithm | ||
>; | ||
|
||
/** | ||
* A plain object containing all of the locally supported algorithms. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { LocalCryptographyUnsupportedError } from "./models"; | ||
|
||
/** | ||
* @internal | ||
* @ignore | ||
* Use the platform-local hashing functionality | ||
*/ | ||
export async function createHash(_algorithm: string, _data: Uint8Array): Promise<Buffer> { | ||
throw new LocalCryptographyUnsupportedError( | ||
"Our libraries don't currently support browser hashing" | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,98 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { JsonWebKey } from "../keysModels"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These types were just moved out of the |
||
|
||
/** | ||
* TypeScript fancy for making plain objects require at least one key-value pair of another set of key-values. | ||
*/ | ||
export type RequireAtLeastOne<T> = { | ||
[K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>; | ||
}[keyof T]; | ||
|
||
/** | ||
* Union type representing the names of the supported local cryptography operations. | ||
*/ | ||
export type LocalCryptographyOperationName = "encrypt" | "wrapKey" | "createHash" | "verify"; | ||
|
||
/** | ||
* @internal | ||
* @ignore | ||
* Abstract representation of a assertion. | ||
* Assertions verify that the requirements to execute a local cryptography operation are met. | ||
* @param key The JSON Web Key that will be used during the local operation. | ||
* @param operationName The name of the operation, as in "encrypt", "decrypt", "sign", etc. | ||
*/ | ||
export type LocalAssertion = ( | ||
key?: JsonWebKey, | ||
operationName?: LocalCryptographyOperationName | ||
) => void; | ||
|
||
/** | ||
* A union type representing the names of all of the locally supported algorithms. | ||
*/ | ||
export type LocalSupportedAlgorithmName = | ||
| "RSA1_5" | ||
| "RSA-OAEP" | ||
| "PS256" | ||
| "RS256" | ||
| "PS384" | ||
| "RS384" | ||
| "PS512" | ||
| "RS512"; | ||
|
||
/** | ||
* Abstract representation of a Local Cryptography Operation function. | ||
* @param keyPEM The string representation of a PEM key. | ||
* @param data The data used on the cryptography operation, in Buffer type. | ||
*/ | ||
export type LocalCryptographyOperationFunction = (keyPEM: string, data: Buffer) => Promise<Buffer>; | ||
|
||
/** | ||
* Abstract representation of a Local Cryptography Operation function, this time with an additional signature buffer. | ||
* @param keyPEM The string representation of a PEM key. | ||
* @param data The data used on the cryptography operation, in Buffer type. | ||
* @param signature The signature used on the cryptography operation, in Buffer type. | ||
*/ | ||
export type LocalCryptographyOperationFunctionWithSignature = ( | ||
keyPEM: string, | ||
data: Buffer, | ||
signature: Buffer | ||
) => Promise<boolean>; | ||
|
||
/** | ||
* Key-value map of local cryptography operations. | ||
*/ | ||
export type LocalCryptographyOperations = Record< | ||
LocalCryptographyOperationName, | ||
LocalCryptographyOperationFunction | LocalCryptographyOperationFunctionWithSignature | ||
>; | ||
|
||
/** | ||
* Abstract representation of a locally supported cryptography algorithm, with its assertions, | ||
* and its operations. | ||
*/ | ||
export interface LocalSupportedAlgorithm { | ||
/** | ||
* List of assertions that need to pass in order to execute this cryptography operation. | ||
*/ | ||
validate: LocalAssertion; | ||
/** | ||
* Optional algorithm used to sign or validate data. | ||
*/ | ||
signAlgorithm?: string; | ||
/** | ||
* List of local cryptography operations supported by an algorithm. | ||
*/ | ||
operations: RequireAtLeastOne<LocalCryptographyOperations>; | ||
} | ||
|
||
/** | ||
* A Record containing all of the locally supported algorithms. | ||
*/ | ||
export type LocalSupportedAlgorithmsRecord = Record< | ||
LocalSupportedAlgorithmName, | ||
LocalSupportedAlgorithm | undefined | ||
>; | ||
|
||
export class LocalCryptographyUnsupportedError extends Error {} |
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.
Please note, the below feedback is not a blocker for this PR, but we should look into this nevertheless and do any follow ups in a separate PR.
I was trying to figure out whey we need to export these
assertions
. We use theseassertions
only in thevalidate
method in each algorithm. Since we dont have any algorithm in browser, this got me thinking as to why we even need it which then lead me to the tests in the filelocalCryptography.spect.ts
file. So, a few questions:localCryptography.spect.ts
in CI in the browser, what isassertions
pointing to? If it is the assertions in the algorithms.ts file, then we are essentially not getting the coverage for "browser code". If it is the assertions in the algorithms.browser.ts file, then tests would fail because assertions is an empty object as seen above. This delves into a generic question around how do we expect our tests to work when the code is split between node and browser like how are are doing in this PR and how we have done in many other placesvalidate()
on the different algorithms and checking if the expected error was thrown?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 like those ideas! After this release, I'll go back to this PR and make issues based on your feedback. Thank you 🌞
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.
We don't currently run cryptography tests on the browser. I can take your validate feedback and work with it on a separate issue! Here's the issue: #11779