Skip to content

Commit 2cceb77

Browse files
authored
🤖 Merge PR DefinitelyTyped#72977 [chrome] update PlatformKeys namespace by @erwanjugand
1 parent 691cee1 commit 2cceb77

File tree

2 files changed

+91
-31
lines changed

2 files changed

+91
-31
lines changed

types/chrome/index.d.ts

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7813,88 +7813,100 @@ declare namespace chrome {
78137813
export interface Match {
78147814
/** The DER encoding of a X.509 certificate. */
78157815
certificate: ArrayBuffer;
7816-
/** The KeyAlgorithm of the certified key. This contains algorithm parameters that are inherent to the key of the certificate (e.g. the key length). Other parameters like the hash function used by the sign function are not included. */
7816+
/** The KeyAlgorithm of the certified key. This contains algorithm parameters that are inherent to the key of the certificate (e.g. the key length). Other parameters like the hash function used by the sign function are not included. */
78177817
keyAlgorithm: KeyAlgorithm;
78187818
}
78197819

7820-
export interface ClientCertificateSelectRequestDetails {
7821-
/** This field is a list of the types of certificates requested, sorted in order of the server's preference. Only certificates of a type contained in this list will be retrieved. If certificateTypes is the empty list, however, certificates of any type will be returned. */
7822-
certificateTypes: string[];
7820+
export interface ClientCertificateRequest {
7821+
/** This field is a list of the types of certificates requested, sorted in order of the server's preference. Only certificates of a type contained in this list will be retrieved. If `certificateTypes` is the empty list, however, certificates of any type will be returned. */
7822+
certificateTypes: `${ClientCertificateType}`[];
78237823
/** List of distinguished names of certificate authorities allowed by the server. Each entry must be a DER-encoded X.509 DistinguishedName. */
78247824
certificateAuthorities: ArrayBuffer[];
78257825
}
78267826

7827-
export interface ClientCertificateSelectDetails {
7827+
export enum ClientCertificateType {
7828+
ECDSA_SIGN = "ecdsaSign",
7829+
RAS_SIGN = "rasSign",
7830+
}
7831+
7832+
export interface SelectDetails {
78287833
/** Only certificates that match this request will be returned. */
7829-
request: ClientCertificateSelectRequestDetails;
7830-
/**
7831-
* Optional.
7832-
* If given, the selectClientCertificates operates on this list. Otherwise, obtains the list of all certificates from the platform's certificate stores that are available to this extensions. Entries that the extension doesn't have permission for or which doesn't match the request, are removed.
7833-
*/
7834+
request: ClientCertificateRequest;
7835+
/** If given, the `selectClientCertificates` operates on this list. Otherwise, obtains the list of all certificates from the platform's certificate stores that are available to this extensions. Entries that the extension doesn't have permission for or which doesn't match the request, are removed. */
78347836
clientCerts?: ArrayBuffer[] | undefined;
78357837
/** If true, the filtered list is presented to the user to manually select a certificate and thereby granting the extension access to the certificate(s) and key(s). Only the selected certificate(s) will be returned. If is false, the list is reduced to all certificates that the extension has been granted access to (automatically or manually). */
78367838
interactive: boolean;
78377839
}
78387840

7839-
export interface ServerCertificateVerificationDetails {
7841+
export interface VerificationDetails {
78407842
/** Each chain entry must be the DER encoding of a X.509 certificate, the first entry must be the server certificate and each entry must certify the entry preceding it. */
78417843
serverCertificateChain: ArrayBuffer[];
7842-
/** The hostname of the server to verify the certificate for, e.g. the server that presented the serverCertificateChain. */
7844+
/** The hostname of the server to verify the certificate for, e.g. the server that presented the `serverCertificateChain`. */
78437845
hostname: string;
78447846
}
78457847

7846-
export interface ServerCertificateVerificationResult {
7848+
export interface VerificationResult {
78477849
/** The result of the trust verification: true if trust for the given verification details could be established and false if trust is rejected for any reason. */
78487850
trusted: boolean;
78497851
/**
78507852
* If the trust verification failed, this array contains the errors reported by the underlying network layer. Otherwise, this array is empty.
7853+
*
78517854
* Note: This list is meant for debugging only and may not contain all relevant errors. The errors returned may change in future revisions of this API, and are not guaranteed to be forwards or backwards compatible.
78527855
*/
78537856
debug_errors: string[];
78547857
}
78557858

78567859
/**
7857-
* This function filters from a list of client certificates the ones that are known to the platform, match request and for which the extension has permission to access the certificate and its private key. If interactive is true, the user is presented a dialog where they can select from matching certificates and grant the extension access to the certificate. The selected/filtered client certificates will be passed to callback.
7858-
* Parameter matches: The list of certificates that match the request, that the extension has permission for and, if interactive is true, that were selected by the user.
7860+
* This method filters from a list of client certificates the ones that are known to the platform, match `request` and for which the extension has permission to access the certificate and its private key. If `interactive` is true, the user is presented a dialog where they can select from matching certificates and grant the extension access to the certificate. The selected/filtered client certificates will be passed to `callback`.
7861+
*
7862+
* Can return its result via Promise in Manifest V3 or later since Chrome 121.
78597863
*/
7864+
export function selectClientCertificates(details: SelectDetails): Promise<Match[]>;
78607865
export function selectClientCertificates(
7861-
details: ClientCertificateSelectDetails,
7866+
details: SelectDetails,
78627867
callback: (matches: Match[]) => void,
78637868
): void;
7869+
78647870
/**
7865-
* Passes the key pair of certificate for usage with platformKeys.subtleCrypto to callback.
7866-
* @param certificate The certificate of a Match returned by selectClientCertificates.
7867-
* @param parameters Determines signature/hash algorithm parameters additionally to the parameters fixed by the key itself. The same parameters are accepted as by WebCrypto's importKey function, e.g. RsaHashedImportParams for a RSASSA-PKCS1-v1_5 key. For RSASSA-PKCS1-v1_5 keys, additionally the parameters { 'hash': { 'name': 'none' } } are supported. The sign function will then apply PKCS#1 v1.5 padding and but not hash the given data.
7868-
* @param callback The public and private CryptoKey of a certificate which can only be used with platformKeys.subtleCrypto.
7869-
* Optional parameter privateKey: Might be null if this extension does not have access to it.
7871+
* Passes the key pair of `certificate` for usage with {@link platformKeys.subtleCrypto} to `callback`.
7872+
* @param certificate The certificate of a {@link Match} returned by {@link selectClientCertificates}.
7873+
* @param parameters Determines signature/hash algorithm parameters additionally to the parameters fixed by the key itself. The same parameters are accepted as by WebCrypto's importKey function, e.g. `RsaHashedImportParams` for a RSASSA-PKCS1-v1_5 key and `EcKeyImportParams` for EC key. Additionally for RSASSA-PKCS1-v1_5 keys, hashing algorithm name parameter can be specified with one of the following values: "none", "SHA-1", "SHA-256", "SHA-384", or "SHA-512", e.g. `{"hash": { "name": "none" } }`. The sign function will then apply PKCS#1 v1.5 padding but not hash the given data.
7874+
*
7875+
* Currently, this method only supports the "RSASSA-PKCS1-v1\_5" and "ECDSA" algorithms.
78707876
*/
78717877
export function getKeyPair(
78727878
certificate: ArrayBuffer,
78737879
parameters: { [key: string]: unknown },
78747880
callback: (publicKey: CryptoKey, privateKey: CryptoKey | null) => void,
78757881
): void;
7882+
78767883
/**
7877-
* Passes the key pair of publicKeySpkiDer for usage with platformKeys.subtleCrypto to callback.
7884+
* Passes the key pair identified by `publicKeySpkiDer` for usage with {@link platformKeys.subtleCrypto} to `callback`.
7885+
*
78787886
* @param publicKeySpkiDer A DER-encoded X.509 SubjectPublicKeyInfo, obtained e.g. by calling WebCrypto's exportKey function with format="spki".
7879-
* @param parameters Provides signature and hash algorithm parameters, in addition to those fixed by the key itself. The same parameters are accepted as by WebCrypto's importKey function, e.g. RsaHashedImportParams for a RSASSA-PKCS1-v1_5 key. For RSASSA-PKCS1-v1_5 keys, we need to also pass a "hash" parameter { "hash": { "name": string } }. The "hash" parameter represents the name of the hashing algorithm to be used in the digest operation before a sign. It is possible to pass "none" as the hash name, in which case the sign function will apply PKCS#1 v1.5 padding and but not hash the given data.
7880-
* Currently, this function only supports the "RSASSA-PKCS1-v1_5" algorithm with one of the hashing algorithms "none", "SHA-1", "SHA-256", "SHA-384", and "SHA-512".
7881-
* @param callback The public and private CryptoKey of a certificate which can only be used with platformKeys.subtleCrypto.
7882-
* Optional parameter privateKey: Might be null if this extension does not have access to it.
7887+
* @param parameters Provides signature and hash algorithm parameters, in addition to those fixed by the key itself. The same parameters are accepted as by WebCrypto's [importKey](https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-importKey) function, e.g. `RsaHashedImportParams` for a RSASSA-PKCS1-v1\_5 key. For RSASSA-PKCS1-v1\_5 keys, we need to also pass a "hash" parameter `{ "hash": { "name": string } }`. The "hash" parameter represents the name of the hashing algorithm to be used in the digest operation before a sign. It is possible to pass "none" as the hash name, in which case the sign function will apply PKCS#1 v1.5 padding and but not hash the given data.
7888+
*
7889+
* Currently, this method supports the "ECDSA" algorithm with named-curve P-256 and "RSASSA-PKCS1-v1\_5" algorithm with one of the hashing algorithms "none", "SHA-1", "SHA-256", "SHA-384", and "SHA-512".
78837890
* @since Chrome 85
78847891
*/
78857892
export function getKeyPairBySpki(
78867893
publicKeySpkiDer: ArrayBuffer,
78877894
parameters: { [key: string]: unknown },
78887895
callback: (publicKey: CryptoKey, privateKey: CryptoKey | null) => void,
78897896
): void;
7890-
/** An implementation of WebCrypto's SubtleCrypto that allows crypto operations on keys of client certificates that are available to this extension. */
7891-
export function subtleCrypto(): SubtleCrypto;
7897+
7898+
/** An implementation of WebCrypto's SubtleCrypto that allows crypto operations on keys of client certificates that are available to this extension. */
7899+
export function subtleCrypto(): SubtleCrypto | undefined;
7900+
78927901
/**
7893-
* Checks whether details.serverCertificateChain can be trusted for details.hostname according to the trust settings of the platform. Note: The actual behavior of the trust verification is not fully specified and might change in the future. The API implementation verifies certificate expiration, validates the certification path and checks trust by a known CA. The implementation is supposed to respect the EKU serverAuth and to support subject alternative names.
7902+
* Checks whether `details.serverCertificateChain` can be trusted for `details.hostname` according to the trust settings of the platform. Note: The actual behavior of the trust verification is not fully specified and might change in the future. The API implementation verifies certificate expiration, validates the certification path and checks trust by a known CA. The implementation is supposed to respect the EKU serverAuth and to support subject alternative names.
7903+
*
7904+
* Can return its result via Promise in Manifest V3 or later since Chrome 121.
78947905
*/
7906+
export function verifyTLSServerCertificate(details: VerificationDetails): Promise<VerificationResult>;
78957907
export function verifyTLSServerCertificate(
7896-
details: ServerCertificateVerificationDetails,
7897-
callback: (result: ServerCertificateVerificationResult) => void,
7908+
details: VerificationDetails,
7909+
callback: (result: VerificationResult) => void,
78987910
): void;
78997911
}
79007912

types/chrome/test/index.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4948,6 +4948,54 @@ function testPower() {
49484948
chrome.power.reportActivity(() => {}).then(() => {});
49494949
}
49504950

4951+
// https://developer.chrome.com/docs/extensions/reference/api/platformKeys
4952+
function testPlatformKeys() {
4953+
chrome.platformKeys.ClientCertificateType.ECDSA_SIGN === "ecdsaSign";
4954+
chrome.platformKeys.ClientCertificateType.RAS_SIGN === "rasSign";
4955+
4956+
const arrayBuffer = new ArrayBuffer(0);
4957+
4958+
chrome.platformKeys.getKeyPair(arrayBuffer, {}, (publicKey, privateKey) => { // $ExpectType void
4959+
publicKey; // $ExpectType CryptoKey
4960+
privateKey; // $ExpectType CryptoKey | null
4961+
});
4962+
4963+
chrome.platformKeys.getKeyPairBySpki(arrayBuffer, {}, (publicKey, privateKey) => { // $ExpectType void
4964+
publicKey; // $ExpectType CryptoKey
4965+
privateKey; // $ExpectType CryptoKey | null
4966+
});
4967+
4968+
const selectDetails: chrome.platformKeys.SelectDetails = {
4969+
clientCerts: [],
4970+
interactive: true,
4971+
request: {
4972+
certificateAuthorities: [],
4973+
certificateTypes: ["ecdsaSign", chrome.platformKeys.ClientCertificateType.RAS_SIGN],
4974+
},
4975+
};
4976+
4977+
chrome.platformKeys.selectClientCertificates(selectDetails); // Promise<Match[]>
4978+
chrome.platformKeys.selectClientCertificates(selectDetails, matches => { // $ExpectType void
4979+
matches; // $ExpectType Match[]
4980+
});
4981+
// @ts-expect-error
4982+
chrome.platformKeys.selectClientCertificates(selectDetails, () => {}).then(() => {});
4983+
4984+
chrome.platformKeys.subtleCrypto(); // $ExpectType SubtleCrypto | undefined
4985+
4986+
const verificationDetails: chrome.platformKeys.VerificationDetails = {
4987+
hostname: "",
4988+
serverCertificateChain: [],
4989+
};
4990+
4991+
chrome.platformKeys.verifyTLSServerCertificate(verificationDetails); // $ExpectType Promise<VerificationResult>
4992+
chrome.platformKeys.verifyTLSServerCertificate(verificationDetails, (result) => { // $ExpectType void
4993+
result; // $ExpectType VerificationResult
4994+
});
4995+
// @ts-expect-error
4996+
chrome.platformKeys.verifyTLSServerCertificate(verificationDetails, () => {}).then(() => {});
4997+
}
4998+
49514999
// https://developer.chrome.com/docs/extensions/reference/api/printing
49525000
function testPrinting() {
49535001
chrome.printing.MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE === 20;

0 commit comments

Comments
 (0)