-
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
[Key Vault Keys] Add new algorithms #11380
Changes from 7 commits
d3f9360
e363ffd
8e6d77b
f296714
d437ff9
359a578
9fb0ab1
e155811
872e597
57e2019
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 |
---|---|---|
|
@@ -32,7 +32,6 @@ import { | |
GetKeyOptions, | ||
KeyVaultKey, | ||
LATEST_API_VERSION, | ||
CryptographyOptions, | ||
CryptographyClientOptions, | ||
KeyOperation | ||
} from "./keysModels"; | ||
|
@@ -46,7 +45,13 @@ import { | |
SignatureAlgorithm, | ||
SignResult, | ||
VerifyResult, | ||
EncryptResult | ||
EncryptResult, | ||
EncryptOptions, | ||
DecryptOptions, | ||
WrapKeyOptions, | ||
UnwrapKeyOptions, | ||
SignOptions, | ||
VerifyOptions | ||
} from "./cryptographyClientModels"; | ||
import { KeyBundle } from "./generated/models"; | ||
import { parseKeyVaultKeyId } from "./identifier"; | ||
|
@@ -55,7 +60,7 @@ import { parseKeyVaultKeyId } from "./identifier"; | |
* Checks whether a key can be used at that specific moment, | ||
* by comparing the current date with the bundle's notBefore and expires values. | ||
*/ | ||
export function checkKeyValidity(keyId?: string, keyBundle?: KeyBundle) { | ||
export function checkKeyValidity(keyId?: string, keyBundle?: KeyBundle): void { | ||
const attributes = keyBundle?.attributes || {}; | ||
const { notBefore, expires } = attributes; | ||
const now = new Date(); | ||
|
@@ -148,6 +153,10 @@ export class CryptographyClient { | |
} | ||
} | ||
|
||
// Renaming parameters | ||
|
||
requestOptions.aad = options.additionalAuthenticatedData; | ||
|
||
// Default to the service | ||
|
||
let result; | ||
|
@@ -177,7 +186,7 @@ export class CryptographyClient { | |
* ``` | ||
* @param {EncryptionAlgorithm} algorithm The algorithm to use. | ||
* @param {Uint8Array} ciphertext The text to decrypt. | ||
* @param {EncryptOptions} [options] Additional options. | ||
* @param {DecryptOptions} [options] Additional options. | ||
*/ | ||
|
||
public async decrypt( | ||
|
@@ -192,6 +201,10 @@ export class CryptographyClient { | |
await this.getLocalCryptographyClient(); | ||
checkKeyValidity(this.getKeyID(), this.keyBundle); | ||
|
||
// Renaming parameters | ||
|
||
requestOptions.aad = options.additionalAuthenticatedData; | ||
|
||
// Default to the service | ||
|
||
let result; | ||
|
@@ -221,7 +234,7 @@ export class CryptographyClient { | |
* ``` | ||
* @param {KeyWrapAlgorithm} algorithm The encryption algorithm to use to wrap the given key. | ||
* @param {Uint8Array} key The key to wrap. | ||
* @param {EncryptOptions} [options] Additional options. | ||
* @param {WrapKeyOptions} [options] Additional options. | ||
*/ | ||
public async wrapKey( | ||
algorithm: KeyWrapAlgorithm, | ||
|
@@ -247,6 +260,10 @@ export class CryptographyClient { | |
} | ||
} | ||
|
||
// Renaming parameters | ||
|
||
requestOptions.aad = options.additionalAuthenticatedData; | ||
|
||
// Default to the service | ||
|
||
let result; | ||
|
@@ -276,7 +293,7 @@ export class CryptographyClient { | |
* ``` | ||
* @param {KeyWrapAlgorithm} algorithm The decryption algorithm to use to unwrap the key. | ||
* @param {Uint8Array} encryptedKey The encrypted key to unwrap. | ||
* @param {EncryptOptions} [options] Additional options. | ||
* @param {UnwrapKeyOptions} [options] Additional options. | ||
*/ | ||
public async unwrapKey( | ||
algorithm: KeyWrapAlgorithm, | ||
|
@@ -290,6 +307,10 @@ export class CryptographyClient { | |
await this.getLocalCryptographyClient(); | ||
checkKeyValidity(this.getKeyID(), this.keyBundle); | ||
|
||
// Renaming parameters | ||
|
||
requestOptions.aad = options.additionalAuthenticatedData; | ||
|
||
// Default to the service | ||
|
||
let result; | ||
|
@@ -319,7 +340,7 @@ export class CryptographyClient { | |
* ``` | ||
* @param {KeySignatureAlgorithm} algorithm The signing algorithm to use. | ||
* @param {Uint8Array} digest The digest of the data to sign. | ||
* @param {EncryptOptions} [options] Additional options. | ||
* @param {SignOptions} [options] Additional options. | ||
*/ | ||
public async sign( | ||
algorithm: SignatureAlgorithm, | ||
|
@@ -361,7 +382,7 @@ export class CryptographyClient { | |
* @param {KeySignatureAlgorithm} algorithm The signing algorithm to use to verify with. | ||
* @param {Uint8Array} digest The digest to verify. | ||
* @param {Uint8Array} signature The signature to verify the digest against. | ||
* @param {EncryptOptions} [options] Additional options. | ||
* @param {VerifyOptions} [options] Additional options. | ||
*/ | ||
public async verify( | ||
algorithm: SignatureAlgorithm, | ||
|
@@ -404,7 +425,7 @@ export class CryptographyClient { | |
* ``` | ||
* @param {KeySignatureAlgorithm} algorithm The signing algorithm to use. | ||
* @param {Uint8Array} data The data to sign. | ||
* @param {EncryptOptions} [options] Additional options. | ||
* @param {SignOptions} [options] Additional options. | ||
*/ | ||
public async signData( | ||
algorithm: SignatureAlgorithm, | ||
|
@@ -459,7 +480,7 @@ export class CryptographyClient { | |
* @param {KeySignatureAlgorithm} algorithm The algorithm to use to verify with. | ||
* @param {Uint8Array} data The signed block of data to verify. | ||
* @param {Uint8Array} signature The signature to verify the block against. | ||
* @param {EncryptOptions} [options] Additional options. | ||
* @param {VerifyOptions} [options] Additional options. | ||
*/ | ||
public async verifyData( | ||
algorithm: SignatureAlgorithm, | ||
|
@@ -737,33 +758,3 @@ export class CryptographyClient { | |
} | ||
} | ||
} | ||
|
||
/** | ||
* Options for {@link encrypt}. | ||
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. I moved these from this file to the models file. It made more sense to me. |
||
*/ | ||
export interface EncryptOptions extends CryptographyOptions {} | ||
|
||
/** | ||
* Options for {@link decrypt}. | ||
*/ | ||
export interface DecryptOptions extends CryptographyOptions {} | ||
|
||
/** | ||
* Options for {@link sign}. | ||
*/ | ||
export interface SignOptions extends CryptographyOptions {} | ||
|
||
/** | ||
* Options for {@link verify}. | ||
*/ | ||
export interface VerifyOptions extends CryptographyOptions {} | ||
|
||
/** | ||
* Options for {@link wrapKey}. | ||
*/ | ||
export interface WrapKeyOptions extends CryptographyOptions {} | ||
|
||
/** | ||
* Options for {@link unwrapKey}. | ||
*/ | ||
export interface UnwrapKeyOptions extends CryptographyOptions {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { CryptographyOptions } from "./keysModels"; | ||
|
||
/** | ||
* Defines values for SignatureAlgorithm. | ||
* @readonly | ||
|
@@ -20,11 +22,26 @@ export type SignatureAlgorithm = | |
|
||
/** | ||
* Defines values for EncryptionAlgorithm. | ||
* Possible values include: 'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5' | ||
* Possible values include: 'RSA-OAEP', 'RSA-OAEP-256', 'RSA1_5', 'A128GCM', 'A192GCM', 'A256GCM', 'A128KW', 'A192KW', 'A256KW', 'A128CBC', 'A192CBC', 'A256CBC', 'A128CBCPAD', 'A192CBCPAD', 'A256CBCPAD' | ||
* @readonly | ||
* @enum {string} | ||
*/ | ||
export type EncryptionAlgorithm = "RSA-OAEP" | "RSA-OAEP-256" | "RSA1_5"; | ||
export type EncryptionAlgorithm = | ||
| "RSA-OAEP" | ||
| "RSA-OAEP-256" | ||
| "RSA1_5" | ||
| "A128GCM" | ||
| "A192GCM" | ||
| "A256GCM" | ||
| "A128KW" | ||
| "A192KW" | ||
| "A256KW" | ||
| "A128CBC" | ||
| "A192CBC" | ||
| "A256CBC" | ||
| "A128CBCPAD" | ||
| "A192CBCPAD" | ||
| "A256CBCPAD"; | ||
|
||
/** | ||
* Defines values for KeyCurveName. | ||
|
@@ -137,3 +154,52 @@ export interface VerifyResult { | |
*/ | ||
keyID?: string; | ||
} | ||
|
||
/** | ||
* Common optional properties for encrypt, decrypt, wrap and unwrap. | ||
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. I moved these from this file to the models file. It made more sense to me. |
||
*/ | ||
export interface KeyOperationsOptions extends CryptographyOptions { | ||
/** | ||
* Initialization vector for symmetric algorithms. | ||
*/ | ||
iv?: Uint8Array; | ||
/** | ||
* Additional data to authenticate but not encrypt/decrypt when using authenticated crypto | ||
* algorithms. | ||
*/ | ||
additionalAuthenticatedData?: Uint8Array; | ||
/** | ||
* The tag to authenticate when performing decryption with an authenticated algorithm. | ||
*/ | ||
tag?: Uint8Array; | ||
} | ||
|
||
/** | ||
* Options for {@link encrypt}. | ||
*/ | ||
export interface EncryptOptions extends KeyOperationsOptions {} | ||
|
||
/** | ||
* Options for {@link decrypt}. | ||
*/ | ||
export interface DecryptOptions extends KeyOperationsOptions {} | ||
|
||
/** | ||
* Options for {@link sign}. | ||
*/ | ||
export interface SignOptions extends CryptographyOptions {} | ||
|
||
/** | ||
* Options for {@link verify}. | ||
*/ | ||
export interface VerifyOptions extends CryptographyOptions {} | ||
|
||
/** | ||
* Options for {@link wrapKey}. | ||
*/ | ||
export interface WrapKeyOptions extends KeyOperationsOptions {} | ||
|
||
/** | ||
* Options for {@link unwrapKey}. | ||
*/ | ||
export interface UnwrapKeyOptions extends KeyOperationsOptions {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,7 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { | |
const hash = createHash("sha256"); | ||
hash.update(signatureValue); | ||
const digest = hash.digest(); | ||
console.log({ digest }); | ||
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. this seems like something not meant to be left in? 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. Oh my bad, thank you! |
||
const signature = await cryptoClient.sign("RS256", digest); | ||
const verifyResult = await cryptoClient.verify("RS256", digest, signature.result); | ||
assert.ok(verifyResult); | ||
|
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.
why do we have to do this? Feels like a swagger transform could make the generated client take the better name.
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.
Thank you! I'll try with something like this: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/textanalytics/ai-text-analytics/swagger/README.md
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 did the change in two parts:
Please let me know how it looks 🌞
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.
Nice! LGTM