Skip to content

Commit

Permalink
[KeyVault] - Add key_ops to JWK and deprecate keyOps (#17914)
Browse files Browse the repository at this point in the history
## What

- Add `key_ops` to `JsonWebKey` model
- Mark `keyOps` as deprecated in `JsonWebKey`

## Why

As per [IETF rfc7517](https://datatracker.ietf.org/doc/html/rfc7517#section-4.3) the correct name for this field is `key_ops`... our TypeScript codegen will of course camelCase this
but snake_case is the expected convention.

I am only marking `keyOps` as deprecated in the JWK, and of course we will continue to populate it for 4.x, but this will
allow anyone to take the key material and use it where a JWK is expected without any conversions.

Resolves #17721
  • Loading branch information
maorleger authored Sep 28, 2021
1 parent ffd13c1 commit 0ad4ea3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions sdk/keyvault/keyvault-keys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Added support for automated key rotation in Azure Key Vault.
- Added `KeyClient.rotateKey` to rotate a key on-demand.
- Added `KeyClient.updateKeyRotationPolicy` to update a key's automated rotation policy.
- Added `JsonWebKey.key_ops` property to `JsonWebKey` in addition to the existing `JsonWebKey.keyOps` property in order to comply with the JSON Web Key spec.

### Breaking Changes

Expand Down
2 changes: 2 additions & 0 deletions sdk/keyvault/keyvault-keys/review/keyvault-keys.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ export interface JsonWebKey {
dq?: Uint8Array;
e?: Uint8Array;
k?: Uint8Array;
key_ops?: KeyOperation[];
// @deprecated
keyOps?: KeyOperation[];
kid?: string;
kty?: KeyType;
Expand Down
3 changes: 1 addition & 2 deletions sdk/keyvault/keyvault-keys/src/cryptographyClientModels.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { CryptographyOptions, KeyVaultKey } from "./keysModels";
import { CryptographyOptions, KeyVaultKey, JsonWebKey } from "./keysModels";

import {
JsonWebKey,
JsonWebKeyCurveName as KeyCurveName,
KnownJsonWebKeyCurveName as KnownKeyCurveNames,
JsonWebKeyEncryptionAlgorithm as EncryptionAlgorithm,
Expand Down
7 changes: 7 additions & 0 deletions sdk/keyvault/keyvault-keys/src/keysModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@ export interface JsonWebKey {
/**
* Json web key operations. For more
* information on possible key operations, see KeyOperation.
*
* @deprecated Use {@link key_ops} instead. keyOps will be removed in version 5.x of `@azure/keyvault-keys`.
*/
keyOps?: KeyOperation[];
/**
* Json web key operations. For more
* information on possible key operations, see KeyOperation.
*/
key_ops?: KeyOperation[];
/**
* RSA modulus.
*/
Expand Down
6 changes: 2 additions & 4 deletions sdk/keyvault/keyvault-keys/src/transformations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { parseKeyVaultKeyIdentifier } from "./identifier";
import {
DeletedKey,
KeyVaultKey,
JsonWebKey,
KeyOperation,
KeyProperties,
KeyRotationPolicy,
KeyRotationPolicyProperties
Expand All @@ -37,10 +35,10 @@ export function getKeyFromKeyBundle(
delete keyBundle.attributes;

const resultObject: KeyVaultKey | DeletedKey = {
key: keyBundle.key as JsonWebKey,
key: { ...keyBundle.key, key_ops: keyBundle.key?.keyOps },
id: keyBundle.key ? keyBundle.key.kid : undefined,
name: parsedId.name,
keyOperations: keyBundle.key ? (keyBundle.key.keyOps as KeyOperation[]) : undefined,
keyOperations: keyBundle.key ? keyBundle.key.keyOps : undefined,
keyType: keyBundle.key ? keyBundle.key.kty : undefined,
properties: {
tags: keyBundle.tags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ describe("Transformations", () => {
kid:
"https://azure_managedhsm.managedhsm.azure.net/keys/transformations/f03e8b3d76554e8b9749994bcf72fc61",
kty: "oct-HSM",
keyOps: ["encrypt", "decrypt"]
keyOps: ["encrypt", "decrypt"],
key_ops: ["encrypt", "decrypt"]
},
name: "transformations",
id:
Expand Down Expand Up @@ -126,7 +127,8 @@ describe("Transformations", () => {
kid:
"https://azure_managedhsm.managedhsm.azure.net/keys/transformations/f03e8b3d76554e8b9749994bcf72fc61",
kty: "oct-HSM",
keyOps: ["encrypt", "decrypt"]
keyOps: ["encrypt", "decrypt"],
key_ops: ["encrypt", "decrypt"]
},
name: "transformations",
id:
Expand Down

0 comments on commit 0ad4ea3

Please sign in to comment.