opaque-ke

This commit is contained in:
Szilard Szaloki
2025-03-28 18:51:54 -06:00
parent cd74e28c6f
commit 70c5352cb1
25 changed files with 970 additions and 13 deletions
+1
View File
@@ -66,3 +66,4 @@ test/data/tor/tor_control/*_win/controlport text eol=crlf
# cargo calculates the checksums based on the line endings of the vendored deps,
# and not based on what we have set for the different file types above.
tools/crates/vendor/** -text
ui/webui/resources/wasm/vendor/** -text
+2
View File
@@ -57,10 +57,12 @@ npm-debug.log
engflow.crt
*.key
!tools/crates/vendor/**/*.key
!ui/webui/resources/wasm/vendor/**/*.key
privkey.pem
*~
CMakeLists.txt
!tools/crates/vendor/**/CMakeLists.txt
!ui/webui/resources/wasm/vendor/**/CMakeLists.txt
cmake-build-debug/
coverage/
/build/rustup/
+1
View File
@@ -27,3 +27,4 @@ tests/
# Ignore third_party rust libraries
third_party/rust/
tools/crates/vendor/
ui/webui/resources/wasm/vendor/
@@ -14,6 +14,9 @@ import { getCss } from './brave_account_create_dialog.css.js'
import { getHtml } from './brave_account_create_dialog.html.js'
import { isEmailValid } from './brave_account_common.js'
// @ts-ignore
import { Registration } from 'chrome://resources/brave/opaque_ke.bundle.js'
class PasswordStrengthMeter extends I18nMixinLit(CrLitElement) {
static get is() {
return 'password-strength-meter'
@@ -177,6 +180,7 @@ export class SettingsBraveAccountCreateDialogElement extends CrLitElement {
protected password: string = ''
protected passwordConfirmation: string = ''
protected passwordStrength: number = 0
protected registration = new Registration()
}
declare global {
@@ -9,6 +9,9 @@ import { getCss } from './brave_account_sign_in_dialog.css.js'
import { getHtml } from './brave_account_sign_in_dialog.html.js'
import { isEmailValid } from './brave_account_common.js'
// @ts-ignore
import { Login } from 'chrome://resources/brave/opaque_ke.bundle.js'
export class SettingsBraveAccountSignInDialogElement extends CrLitElement {
static get is() {
return 'settings-brave-account-sign-in-dialog'
@@ -42,6 +45,7 @@ export class SettingsBraveAccountSignInDialogElement extends CrLitElement {
protected email: string = ''
protected isEmailValid: boolean = false
protected isPasswordValid: boolean = false
protected login = new Login()
}
declare global {
@@ -0,0 +1,11 @@
/* Copyright (c) 2025 The Brave Authors. All rights reserved.
* 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 https://mozilla.org/MPL/2.0/. */
const config = require('../lib/config')
const path = require('path')
const util = require('../lib/util')
args = [path.join(config.srcDir, 'brave', 'ui', 'webui', 'resources', 'wasm', 'update.py')]
util.run('vpython3', args, config.defaultOptions)
+1
View File
@@ -65,6 +65,7 @@
"tools/crates/",
"win_build_output/",
"third_party/ios_deps/",
"ui/webui/resources/wasm/vendor/",
],
// Regex to match function names in the current presubmit stack trace. Matched
@@ -0,0 +1,14 @@
# Copyright (c) 2025 The Brave Authors. All rights reserved.
# 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 https://mozilla.org/MPL/2.0/. */
import override_utils
@override_utils.override_function(globals())
def Minify(original_function, source, filename):
with override_utils.override_scope_variable(
globals(), 'js_minifier_ignore_list',
js_minifier_ignore_list + ['gen/brave/web-ui-opaque_ke/']):
return original_function(source, filename)
+6
View File
@@ -24,6 +24,9 @@ template("rust_to_wasm") {
inputs = [ wasm_pack_exe ]
sources = invoker.rust_packages
inputs += sources
if (defined(invoker.inputs)) {
inputs += invoker.inputs
}
script = "//brave/script/rust_to_wasm.py"
@@ -57,9 +60,12 @@ template("rust_to_wasm") {
"--out-name",
"index",
"--",
"--config",
rebase_path("//{{source_root_relative_dir}}/.cargo/config.toml"),
"--target-dir",
rebase_path(
"$root_gen_dir/{{source_root_relative_dir}}/$wasm_pack_target/target"),
"--frozen",
]
# common output files for all the wasm-pack targets
+1
View File
@@ -95,6 +95,7 @@ brave_common_web_compile_inputs = [
template("transpile_web_ui") {
if (defined(invoker.rust_packages)) {
rust_to_wasm("build_rust_packages") {
forward_variables_from(invoker, [ "inputs" ])
rust_packages = invoker.rust_packages
}
}
+2 -1
View File
@@ -49,7 +49,8 @@
"ios_pack_js": "webpack --config ios/brave-ios/webpack.config.js",
"ios_bootstrap": "node ./build/commands/scripts/iosCommands.js ios_bootstrap",
"update_brave_tools_crates": "node ./build/commands/scripts/updateBraveToolsCrates.js",
"build_rust_toolchain_aux": "node ./build/commands/scripts/buildRustToolchainAux.js"
"build_rust_toolchain_aux": "node ./build/commands/scripts/buildRustToolchainAux.js",
"update_wasm_resources": "node ./build/commands/scripts/updateWasmResources.js"
},
"repository": {
"type": "git",
@@ -0,0 +1,10 @@
diff --git a/tools/grit/grit/format/minifier.py b/tools/grit/grit/format/minifier.py
index bd2dc7f9936a3c3a1d892be3b05be02a6910c571..9f176d2f5124036ae748f98aa80e7b9ab60ec716 100644
--- a/tools/grit/grit/format/minifier.py
+++ b/tools/grit/grit/format/minifier.py
@@ -48,3 +48,4 @@ def Minify(source, filename):
print(stderr)
sys.exit(p.returncode)
return stdout
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
\ No newline at end of file
@@ -1,5 +1,5 @@
diff --git a/tools/gritsettings/resource_ids.spec b/tools/gritsettings/resource_ids.spec
index 2cd6ca756a745e1387469914eb3d649dff104ccb..85ededbcaee08c17355571e5749f811e777cdc2d 100644
index 2cd6ca756a745e1387469914eb3d649dff104ccb..ddf9a6d25ad7ee50057b97a6298ce939cd32e2f8 100644
--- a/tools/gritsettings/resource_ids.spec
+++ b/tools/gritsettings/resource_ids.spec
@@ -38,6 +38,9 @@
@@ -45,7 +45,7 @@ index 2cd6ca756a745e1387469914eb3d649dff104ccb..85ededbcaee08c17355571e5749f811e
},
"<(SHARED_INTERMEDIATE_DIR)/ui/webui/resources/webui_resources.grd": {
- "META": {"sizes": {"includes": [1100]}},
+ "META": {"sizes": {"includes": [1113]}},
+ "META": {"sizes": {"includes": [1115]}},
"includes": [10000],
},
"weblayer/weblayer_resources.grd": {
@@ -1,12 +1,12 @@
diff --git a/ui/webui/resources/tools/bundle_js_excludes.gni b/ui/webui/resources/tools/bundle_js_excludes.gni
index 544a35127374b54700255f5902e881fc5fb89d7d..31ceaa0ee30563ce5fb74bcad9dd39a8aece9507 100644
index 544a35127374b54700255f5902e881fc5fb89d7d..404a2df5c69987461df2d18bd8383016b8cf6ee4 100644
--- a/ui/webui/resources/tools/bundle_js_excludes.gni
+++ b/ui/webui/resources/tools/bundle_js_excludes.gni
@@ -14,6 +14,7 @@ foreach(excluded_file,
"resources/js/load_time_data.js",
"resources/ash/common/load_time_data.m.js",
"resources/mwc/lit/index.js",
+ "resources/brave/leo.bundle.js",
+ "resources/brave/leo.bundle.js", "resources/brave/opaque_ke.bundle.js",
]) {
# Exclude both the chrome://resources form and the scheme-relative form.
BUNDLE_JS_EXCLUDES += [
+27
View File
@@ -4,8 +4,10 @@
# You can obtain one at https://mozilla.org/MPL/2.0/.
import os
from pathlib import Path
import re
import subprocess
import tomllib
BRAVE_SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
@@ -20,6 +22,28 @@ DESKTOP_ONLY_PATHS = []
_REPOSITORY_ROOT = None
def GetRustWorkspaceTransitiveDeps(workspace):
ws_abs_path = Path(f'{_REPOSITORY_ROOT}/{workspace}')
def GetMembers():
with open(Path(f'{ws_abs_path}/Cargo.toml'), 'rb') as f:
return tomllib.load(f)['workspace']['members']
# The `members` field in `[workspace]` is an array of directories
# (as opposed to an array of package names), hence inspecting the
# Cargo.toml of each member, instead of using the Cargo.lock
# of the workspace.
def GetDepsForMember(member):
with open(Path(f'{ws_abs_path}/{member}/Cargo.toml'), 'rb') as f:
return list(tomllib.load(f)['dependencies'].keys())
all_deps = next(os.walk(Path(f'{ws_abs_path}/vendor')))[1]
direct_deps = [GetDepsForMember(member) for member in GetMembers()]
return [
str(Path(f'{workspace}/vendor/{dep}')) for dep in all_deps
if dep not in sum(direct_deps, [])
]
def AddBraveCredits(root, prune_paths, special_cases, prune_dirs,
additional_paths):
global _REPOSITORY_ROOT # pylint: disable=global-statement
@@ -156,6 +180,9 @@ def AddBraveCredits(root, prune_paths, special_cases, prune_dirs,
os.path.join('brave', 'vendor', 'omaha', 'omaha', 'scons-out'),
os.path.join('brave', 'third_party', 'libdmg-hfsplus'),
os.path.join('brave', 'tools', 'crates', 'vendor'),
# Transitive deps in brave/ui/webui/resources/wasm.
*GetRustWorkspaceTransitiveDeps(Path('brave/ui/webui/resources/wasm')),
])
# Add the licensing info that would normally be in a README.chromium file.
+25 -5
View File
@@ -114,15 +114,35 @@ def override_scope_variable(scope,
yield
return
var_exist = hasattr(scope, name)
is_dict_scope = isinstance(scope, dict)
def _has(scope, name):
return name in scope if is_dict_scope else hasattr(scope, name)
def _get(scope, name):
return scope[name] if is_dict_scope else getattr(scope, name)
def _set(scope, name, value):
if is_dict_scope:
scope[name] = value
else:
setattr(scope, name, value)
def _del(scope, name):
if is_dict_scope:
del scope[name]
else:
delattr(scope, name)
var_exist = _has(scope, name)
if fail_if_not_found and not var_exist:
raise NameError(f'Failed to override scope variable: {name} not found')
original_value = getattr(scope, name) if var_exist else None
original_value = _get(scope, name) if var_exist else None
try:
setattr(scope, name, value)
_set(scope, name, value)
yield
finally:
if var_exist:
setattr(scope, name, original_value)
_set(scope, name, original_value)
else:
delattr(scope, name)
_del(scope, name)
+18 -3
View File
@@ -1,4 +1,13 @@
#!/usr/bin/env vpython3
# Copyright (c) 2025 The Brave Authors. All rights reserved.
# 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 https://mozilla.org/MPL/2.0/.
# update.py vendors the CLI tools in versions.py and their deps.
# Run this script via npm run update_brave_tools_crates
# whenever you need to add a new CLI tool,
# or bump the version of an existing one.
import fnmatch
import json
@@ -6,10 +15,16 @@ import os
from pathlib import Path
import shutil
import subprocess
import sys
import toml
import brave_chromium_utils
import versions
with brave_chromium_utils.sys_path('//tools/rust'):
import update_rust
CARGO = os.path.join(update_rust.RUST_TOOLCHAIN_OUT_DIR, 'bin',
'cargo' + ('.exe' if sys.platform == 'win32' else ''))
REMOVE_CRATES = ['winapi-*gnu*', 'windows_*gnu*']
@@ -51,13 +66,13 @@ def add_dependencies():
dict = vars(versions)
for dep in dependencies:
version = dict[f'{dep.replace("-", "_").upper()}_VERSION']
subprocess.run(['cargo', 'add', f'{dep}@{version}'], check=True)
subprocess.run([CARGO, 'add', f'{dep}@{version}'], check=True)
# Update dependencies
subprocess.run(['cargo', 'update'], check=True)
subprocess.run([CARGO, 'update'], check=True)
# Vendor dependencies
subprocess.run(['cargo', 'vendor'], check=True)
subprocess.run([CARGO, 'vendor'], check=True)
def create_dependency_placeholders():
+23
View File
@@ -29,6 +29,7 @@ group("grdp") {
":fonts_grdp",
":icons_grdp",
":leo_web_components",
":opaque_ke",
":static_grdp",
]
if (include_polymer) {
@@ -101,6 +102,28 @@ transpile_web_ui("leo_web_components") {
resource_name = "leo"
}
transpile_web_ui("opaque_ke") {
resource_name = "opaque_ke"
generate_grdp = true
resource_path_prefix = "brave"
entry_points = [ [
"opaque_ke",
rebase_path("wasm/opaque_ke/index.js"),
] ]
inputs = [
rebase_path("wasm/Cargo.lock"),
rebase_path("wasm/opaque_ke/src/lib.rs"),
]
rust_packages = [ rebase_path("wasm/opaque_ke/Cargo.toml") ]
no_iife = true
output_module = true
public_asset_path = "chrome://resources/brave/"
}
# Create a grdp that //ui/webui/resources can include in its main resources GRD
generate_grd("static_grdp") {
grd_prefix = "brave_webui"
+1
View File
@@ -11,6 +11,7 @@ brave_resources_extra_grdps_path = "$root_gen_dir/brave/ui/webui/resources"
brave_resources_extra_grdps = [
"$brave_resources_extra_grdps_path/brave_static_resources.grdp",
"$root_gen_dir/brave/web-ui-leo/leo.grdp",
"$root_gen_dir/brave/web-ui-opaque_ke/opaque_ke.grdp",
]
brave_resources_extra_grdps_deps = [ "//brave/ui/webui/resources:grdp" ]
+611
View File
@@ -0,0 +1,611 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "argon2"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072"
dependencies = [
"base64ct",
"blake2",
"cpufeatures",
"password-hash",
]
[[package]]
name = "base16ct"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf"
[[package]]
name = "base64ct"
version = "1.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3"
[[package]]
name = "blake2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe"
dependencies = [
"digest",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "bumpalo"
version = "3.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "const-oid"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
[[package]]
name = "cpufeatures"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
dependencies = [
"libc",
]
[[package]]
name = "crypto-bigint"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76"
dependencies = [
"generic-array",
"rand_core",
"subtle",
"zeroize",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "curve25519-dalek"
version = "4.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be"
dependencies = [
"cfg-if",
"cpufeatures",
"curve25519-dalek-derive",
"fiat-crypto",
"rand_core",
"rustc_version",
"subtle",
"zeroize",
]
[[package]]
name = "curve25519-dalek-derive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "der"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0"
dependencies = [
"const-oid",
"zeroize",
]
[[package]]
name = "derive-where"
version = "1.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
"subtle",
]
[[package]]
name = "displaydoc"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "elliptic-curve"
version = "0.13.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47"
dependencies = [
"base16ct",
"crypto-bigint",
"digest",
"ff",
"generic-array",
"group",
"rand_core",
"sec1",
"subtle",
"zeroize",
]
[[package]]
name = "ff"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393"
dependencies = [
"rand_core",
"subtle",
]
[[package]]
name = "fiat-crypto"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"serde",
"typenum",
"version_check",
"zeroize",
]
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"wasi",
"wasm-bindgen",
]
[[package]]
name = "group"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63"
dependencies = [
"ff",
"rand_core",
"subtle",
]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "hkdf"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7"
dependencies = [
"hmac",
]
[[package]]
name = "hmac"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [
"digest",
]
[[package]]
name = "js-sys"
version = "0.3.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
dependencies = [
"once_cell",
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.171"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
[[package]]
name = "log"
version = "0.4.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e"
[[package]]
name = "once_cell"
version = "1.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc"
[[package]]
name = "opaque-ke"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb31f7b2c5760d8ffbc39652043f5cff14029b6249a2280b28ae6f0cd61f5098"
dependencies = [
"argon2",
"curve25519-dalek",
"derive-where",
"digest",
"displaydoc",
"elliptic-curve",
"generic-array",
"getrandom",
"hkdf",
"hmac",
"rand",
"serde",
"subtle",
"voprf",
"zeroize",
]
[[package]]
name = "opaque-ke-wasm"
version = "0.1.0"
dependencies = [
"argon2",
"hex",
"opaque-ke",
"rand",
"wasm-bindgen",
]
[[package]]
name = "password-hash"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166"
dependencies = [
"base64ct",
"rand_core",
"subtle",
]
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "rustc_version"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
dependencies = [
"semver",
]
[[package]]
name = "rustversion"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
[[package]]
name = "sec1"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc"
dependencies = [
"base16ct",
"der",
"generic-array",
"subtle",
"zeroize",
]
[[package]]
name = "semver"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0"
[[package]]
name = "serde"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "sha2"
version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "subtle"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "2.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "typenum"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "voprf"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28f59c30c76e2fea54cdece6a054e2662feffa7ab19658a7887524265ee39470"
dependencies = [
"curve25519-dalek",
"derive-where",
"digest",
"displaydoc",
"elliptic-curve",
"generic-array",
"rand_core",
"serde",
"sha2",
"subtle",
"zeroize",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
dependencies = [
"cfg-if",
"once_cell",
"rustversion",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
dependencies = [
"bumpalo",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
dependencies = [
"unicode-ident",
]
[[package]]
name = "zerocopy"
version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "zeroize"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
dependencies = [
"zeroize_derive",
]
[[package]]
name = "zeroize_derive"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
+3
View File
@@ -0,0 +1,3 @@
[workspace]
resolver = "2"
members = ["opaque_ke"]
@@ -0,0 +1,14 @@
[package]
name = "opaque-ke-wasm"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
argon2 = { version = "0.5", default-features = false, features = ["alloc"] }
hex = "0.4"
opaque-ke = { version = "3.0.0", features = [ "argon2", "std" ] }
rand = { version = "*", features = [ "getrandom" ] }
wasm-bindgen = "=0.2.100" # Must match the wasm-bindgen-cli version under brave/tools/crates!
@@ -0,0 +1,6 @@
/* Copyright (c) 2025 The Brave Authors. All rights reserved.
* 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 https://mozilla.org/MPL/2.0/. */
export { Login, Registration } from 'gen/brave/ui/webui/resources/wasm/opaque_ke/bundler/pkg'
@@ -0,0 +1,127 @@
/* Copyright (c) 2025 The Brave Authors. All rights reserved.
* 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 https://mozilla.org/MPL/2.0/. */
use argon2::Argon2;
use opaque_ke::ciphersuite::CipherSuite;
use opaque_ke::rand::rngs::OsRng;
use opaque_ke::{
ClientLogin,
ClientLoginFinishParameters,
ClientRegistration,
ClientRegistrationFinishParameters,
CredentialResponse,
Identifiers,
RegistrationResponse
};
use wasm_bindgen::prelude::*;
pub struct DefaultCipherSuite;
impl CipherSuite for DefaultCipherSuite {
type OprfCs = opaque_ke::Ristretto255;
type KeGroup = opaque_ke::Ristretto255;
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDh;
type Ksf = Argon2<'static>;
}
#[wasm_bindgen]
pub struct Registration {
state: Option<ClientRegistration<DefaultCipherSuite>>,
rng: OsRng
}
#[wasm_bindgen]
impl Registration {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
Self {
state: None,
rng: OsRng
}
}
// result => POST /v2/accounts/password/init
pub fn start(&mut self, password: &str) -> Result<String, JsValue> {
let result = ClientRegistration::<DefaultCipherSuite>::start(
&mut self.rng, &password.as_bytes()
).map_err(|_| "ClientRegistration::<DefaultCipherSuite>::start() failed!")?;
self.state = Some(result.state);
Ok(hex::encode(result.message.serialize()))
}
// result => POST /v2/accounts/password/finalize
pub fn finish(&mut self, hex_response: &str, password: &str, email: &str) -> Result<String, JsValue> {
let serialized_response = hex::decode(&hex_response)
.map_err(|_| "hex::decode() failed!")?;
let response = RegistrationResponse::deserialize(&serialized_response)
.map_err(|_| "RegistrationResponse::deserialize() failed!")?;
let result = self.state.take().ok_or(
"Calling Registration::finish() without first calling Registration::start()!"
)?.finish(
&mut self.rng,
password.as_bytes(),
response,
ClientRegistrationFinishParameters {
identifiers: Identifiers {
client: Some(email.as_bytes()),
..Default::default()
},
..Default::default()
}
).map_err(|_| "ClientRegistration::<DefaultCipherSuite>::finish() failed!")?;
Ok(hex::encode(result.message.serialize()))
}
}
#[wasm_bindgen]
pub struct Login {
state: Option<ClientLogin<DefaultCipherSuite>>,
rng: OsRng
}
#[wasm_bindgen]
impl Login {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
Self {
state: None,
rng: OsRng
}
}
// result => POST /v2/auth/login/init
pub fn start(&mut self, password: &str) -> Result<String, JsValue> {
let result = ClientLogin::<DefaultCipherSuite>::start(
&mut self.rng, &password.as_bytes()
).map_err(|_| "ClientLogin::<DefaultCipherSuite>::start() failed!")?;
self.state = Some(result.state);
Ok(hex::encode(result.message.serialize()))
}
// result => POST /v2/auth/login/finalize
pub fn finish(&mut self, hex_response: &str, password: &str, email: &str) -> Result<String, JsValue> {
let serialized_response = hex::decode(&hex_response)
.map_err(|_| "hex::decode() failed!")?;
let response = CredentialResponse::deserialize(&serialized_response)
.map_err(|_| "CredentialResponse::deserialize() failed!")?;
let result = self.state.take().ok_or(
"Calling Login::finish() without first calling Login::start()!"
)?.finish(
password.as_bytes(),
response,
ClientLoginFinishParameters {
identifiers: Identifiers {
client: Some(email.as_bytes()),
server: None,
},
..Default::default()
}
).map_err(|_| "ClientLogin::<DefaultCipherSuite>::finish() failed!")?;
Ok(hex::encode(result.message.serialize()))
}
}
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env vpython3
# Copyright (c) 2025 The Brave Authors. All rights reserved.
# 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 https://mozilla.org/MPL/2.0/.
# update.py vendors the deps of the Rust workspace in `wasm`.
# Run this script via npm run update_wasm_resources
# whenever you need to add a new workspace member,
# or bump the version of an existing member's deps.
import os
from pathlib import Path
import shutil
import subprocess
import sys
import toml
import brave_chromium_utils
with brave_chromium_utils.sys_path('//tools/rust'):
import update_rust
CARGO = os.path.join(update_rust.RUST_TOOLCHAIN_OUT_DIR, 'bin',
'cargo' + ('.exe' if sys.platform == 'win32' else ''))
CONFIG_TOML = {
'source': {
'crates-io': {
'replace-with': 'vendored-sources'
},
'vendored-sources': {
'directory': '../vendor'
}
}
}
def main():
os.chdir(os.path.dirname(os.path.realpath(__file__)))
members = toml.load('Cargo.toml')['workspace']['members']
shutil.rmtree('vendor', ignore_errors=True)
for member in members:
Path(f'{member}/.cargo/config.toml').unlink(missing_ok=True)
subprocess.run([CARGO, 'vendor'], check=True)
for member in members:
Path(f'{member}/.cargo').mkdir(exist_ok=True)
with open(Path(f'{member}/.cargo/config.toml'), 'w') as f:
toml.dump(CONFIG_TOML, f)
if __name__ == '__main__':
main()