Bug 1539578 - Add telemetry for DH use in WebCrypto API r=keeler

Our WebCrypto implementation supports using DH as an algorithm in generateKey,
which is not one of the recognized algorithms in the published specification [0].

We should seek to remove it from Firefox, but before we do, it'd be good to
gather some telemetry on whether it's used at all, even in its' non-standard
form.

[0] https://www.w3.org/TR/WebCryptoAPI/#algorithm-overview

Differential Revision: https://phabricator.services.mozilla.com/D25291

--HG--
extra : moz-landing-system : lando
This commit is contained in:
J.C. Jones 2019-04-02 22:25:04 +00:00
Родитель e88f725dc2
Коммит 47b914e9b8
5 изменённых файлов: 70 добавлений и 0 удалений

Просмотреть файл

@ -85,6 +85,7 @@ enum TelemetryAlgorithm {
TA_PBKDF2 = 21,
TA_ECDSA = 22,
TA_HKDF = 23,
TA_DH = 24,
};
// Convenience functions for extracting / converting information
@ -2883,6 +2884,7 @@ class DeriveDhBitsTask : public ReturnArrayBufferViewTask {
}
void Init(JSContext* aCx, const ObjectOrString& aAlgorithm, CryptoKey& aKey) {
Telemetry::Accumulate(Telemetry::WEBCRYPTO_ALG, TA_DH);
CHECK_KEY_ALGORITHM(aKey.Algorithm(), WEBCRYPTO_ALG_DH);
// Check that we have a private key.

Просмотреть файл

@ -34,3 +34,4 @@ LOCAL_INCLUDES += [
]
MOCHITEST_MANIFESTS += ['test/mochitest.ini']
BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']

Просмотреть файл

@ -0,0 +1,8 @@
[DEFAULT]
support-files =
head.js
../test-vectors.js
../util.js
[browser_WebCrypto_telemetry.js]
disabled = for telemetry intermittents, see bug 1539578

Просмотреть файл

@ -0,0 +1,41 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/* global tv */
const WEBCRYPTO_ALG_PROBE = "WEBCRYPTO_ALG";
ChromeUtils.defineModuleGetter(this, "TelemetryTestUtils",
"resource://testing-common/TelemetryTestUtils.jsm");
add_task(async function ecdh_key() {
let hist = TelemetryTestUtils.getAndClearHistogram(WEBCRYPTO_ALG_PROBE);
let alg = { name: "ECDH", namedCurve: "P-256" };
let x = await crypto.subtle.generateKey(alg, false, ["deriveKey", "deriveBits"]);
let data = await crypto.subtle.deriveBits({ name: "ECDH", public: x.publicKey }, x.privateKey, 128);
is(data.byteLength, 128 / 8, "Should be 16 bytes derived");
TelemetryTestUtils.assertHistogram(hist, 20, 1);
});
add_task(async function dh_key() {
let hist = TelemetryTestUtils.getAndClearHistogram(WEBCRYPTO_ALG_PROBE);
let alg = {
name: "DH",
prime: tv.dh.prime,
generator: new Uint8Array([0x02]),
};
let x = await crypto.subtle.generateKey(alg, false, ["deriveKey", "deriveBits"]);
let data = await crypto.subtle.deriveBits({ name: "DH", public: x.publicKey }, x.privateKey, 128);
is(data.byteLength, 128 / 8, "Should be 16 bytes derived");
TelemetryTestUtils.assertHistogram(hist, 24, 1);
});

Просмотреть файл

@ -0,0 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
let exports = this;
const scripts = [
"util.js",
"test-vectors.js",
];
for (let script of scripts) {
Services.scriptloader.loadSubScript(
`chrome://mochitests/content/browser/dom/crypto/test/browser/${script}`,
this);
}