diff options
Diffstat (limited to 'nearby/connections')
25 files changed, 744 insertions, 733 deletions
diff --git a/nearby/connections/connections_adv/connections_adv/Cargo.toml b/nearby/connections/connections_adv/connections_adv/Cargo.toml deleted file mode 100644 index 2b0710d..0000000 --- a/nearby/connections/connections_adv/connections_adv/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "connections_adv" -version.workspace = true -edition.workspace = true -publish.workspace = true - -[lints] -workspace = true
\ No newline at end of file diff --git a/nearby/connections/connections_adv/connections_adv/src/lib.rs b/nearby/connections/connections_adv/connections_adv/src/lib.rs deleted file mode 100644 index 4cfcdfa..0000000 --- a/nearby/connections/connections_adv/connections_adv/src/lib.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Placeholder crate for connections advertisements - -/// placeholder -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} diff --git a/nearby/connections/ukey2/ukey2/Cargo.toml b/nearby/connections/ukey2/ukey2/Cargo.toml index 161c5b4..2ac6f3a 100644 --- a/nearby/connections/ukey2/ukey2/Cargo.toml +++ b/nearby/connections/ukey2/ukey2/Cargo.toml @@ -19,7 +19,7 @@ rand.workspace = true ukey2_proto.workspace = true log.workspace = true -num-bigint = "0.4.3" +num-bigint = "0.4.4" [dev-dependencies] rand = { workspace = true, features = ["std_rng", "getrandom"] } diff --git a/nearby/connections/ukey2/ukey2_c_ffi/cpp/CMakeLists.txt b/nearby/connections/ukey2/ukey2_c_ffi/cpp/CMakeLists.txt index 165d861..a8b7b9d 100644 --- a/nearby/connections/ukey2/ukey2_c_ffi/cpp/CMakeLists.txt +++ b/nearby/connections/ukey2/ukey2_c_ffi/cpp/CMakeLists.txt @@ -21,7 +21,9 @@ enable_testing() include_directories( ${CMAKE_SOURCE_DIR}/ukey2_c_ffi/cpp/) +include(GoogleTest) include(ExternalProject) + set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/target/tmp) ExternalProject_Add( ukey2_c_ffi @@ -35,11 +37,9 @@ ExternalProject_Add( set(CMAKE_CXX_STANDARD 20) if(UNIX) - add_compile_options(-Wall -Werror -Wextra -Wimplicit-fallthrough -Wextra-semi + add_compile_options(-Wall -Wextra -Wimplicit-fallthrough -Wextra-semi -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi - -Wno-unneeded-internal-declaration - -Wno-ignored-pragma-optimize - -Wno-bitfield-constant-conversion -Wno-deprecated-this-capture -Wshadow + -Wshadow -Wsign-compare) elseif(MSVC) add_compile_options(-W4 -MD) @@ -83,5 +83,4 @@ elseif(MSVC) ) endif() -include(GoogleTest) gtest_discover_tests(ffi_test) diff --git a/nearby/connections/ukey2/ukey2_connections/Cargo.toml b/nearby/connections/ukey2/ukey2_connections/Cargo.toml index e7884c4..b1c34a1 100644 --- a/nearby/connections/ukey2/ukey2_connections/Cargo.toml +++ b/nearby/connections/ukey2/ukey2_connections/Cargo.toml @@ -19,8 +19,8 @@ ukey2_rs = { path = "../ukey2" } crypto_provider.workspace = true rand = { workspace = true, features = ["std", "std_rng"] } ukey2_proto.workspace = true -nom = { version = "7.1.1", features = ["alloc"] } -bytes = "1.2.1" +nom = { version = "7.1.3", features = ["alloc"] } +bytes = "1.5.0" criterion.workspace = true [dev-dependencies] diff --git a/nearby/connections/ukey2/ukey2_connections/fuzz/Cargo.lock b/nearby/connections/ukey2/ukey2_connections/fuzz/Cargo.lock index 3f72ae0..167e0de 100644 --- a/nearby/connections/ukey2/ukey2_connections/fuzz/Cargo.lock +++ b/nearby/connections/ukey2/ukey2_connections/fuzz/Cargo.lock @@ -69,6 +69,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] name = "anyhow" version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -84,17 +90,6 @@ dependencies = [ ] [[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - -[[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -113,6 +108,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] name = "block-buffer" version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -138,9 +139,9 @@ checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "bytes" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cast" @@ -211,26 +212,30 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.25" +version = "4.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +checksum = "33e92c5c1a78c62968ec57dbc2440366a2d6e5a23faf829970ff1585dc6b18e2" dependencies = [ - "bitflags", - "clap_lex", - "indexmap", - "textwrap", + "clap_builder", ] [[package]] -name = "clap_lex" -version = "0.2.4" +name = "clap_builder" +version = "4.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "f4323769dc8a61e2c39ad7dc26f6f2800524691a44d74fe3d1071a5c24db6370" dependencies = [ - "os_str_bytes", + "anstyle", + "clap_lex", ] [[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] name = "const-oid" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -247,19 +252,19 @@ dependencies = [ [[package]] name = "criterion" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" dependencies = [ "anes", - "atty", "cast", "ciborium", "clap", "criterion-plot", + "is-terminal", "itertools", - "lazy_static", "num-traits", + "once_cell", "oorandom", "plotters", "rayon", @@ -412,7 +417,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn", ] [[package]] @@ -426,17 +431,6 @@ dependencies = [ ] [[package]] -name = "derive-getters" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0122f262bf9c9a367829da84f808d9fb128c10ef283bbe7b0922a77cf07b2747" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] name = "derive_arbitrary" version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -444,7 +438,7 @@ checksum = "53e0efad4403bfc52dc201159c4b842a246a14b98c64b55dfd0f2d89729dfeb8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn", ] [[package]] @@ -469,14 +463,15 @@ dependencies = [ [[package]] name = "ed25519-dalek" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" +checksum = "1f628eaec48bfd21b865dc2950cfa014450c01d2fa2b69a86c2fd5844ec523c0" dependencies = [ "curve25519-dalek", "ed25519", "rand_core", "sha2", + "subtle", ] [[package]] @@ -512,7 +507,7 @@ checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -607,15 +602,6 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" @@ -673,9 +659,20 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi", "libc", - "windows-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "is-terminal" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" +dependencies = [ + "hermit-abi", + "rustix 0.38.13", + "windows-sys 0.52.0", ] [[package]] @@ -712,12 +709,6 @@ dependencies = [ ] [[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] name = "libc" version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -741,10 +732,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] +name = "linux-raw-sys" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" + +[[package]] name = "log" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" @@ -779,9 +776,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" dependencies = [ "autocfg", "num-integer", @@ -800,9 +797,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] @@ -813,7 +810,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi", "libc", ] @@ -836,12 +833,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] -name = "os_str_bytes" -version = "6.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" - -[[package]] name = "p256" version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1039,7 +1030,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1086,12 +1077,25 @@ version = "0.37.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", - "linux-raw-sys", - "windows-sys", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + +[[package]] +name = "rustix" +version = "0.38.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662" +dependencies = [ + "bitflags 2.4.1", + "errno", + "libc", + "linux-raw-sys 0.4.12", + "windows-sys 0.48.0", ] [[package]] @@ -1151,7 +1155,7 @@ checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn", ] [[package]] @@ -1167,9 +1171,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", @@ -1190,17 +1194,6 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" version = "2.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970" @@ -1220,17 +1213,11 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall", - "rustix", - "windows-sys", + "rustix 0.37.23", + "windows-sys 0.48.0", ] [[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - -[[package]] name = "thiserror" version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1247,7 +1234,7 @@ checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn", ] [[package]] @@ -1310,7 +1297,6 @@ name = "ukey2_rs" version = "0.1.0" dependencies = [ "crypto_provider", - "derive-getters", "log", "num-bigint", "rand", @@ -1376,7 +1362,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.26", + "syn", "wasm-bindgen-shared", ] @@ -1398,7 +1384,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1467,7 +1453,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.1", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", ] [[package]] @@ -1476,13 +1471,28 @@ version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", ] [[package]] @@ -1492,42 +1502,84 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + +[[package]] name = "windows_aarch64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + +[[package]] name = "windows_i686_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + +[[package]] name = "windows_i686_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + +[[package]] name = "windows_x86_64_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + +[[package]] name = "windows_x86_64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + +[[package]] name = "windows_x86_64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + +[[package]] name = "x25519-dalek" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/nearby/connections/ukey2/ukey2_jni/java/build.gradle.kts b/nearby/connections/ukey2/ukey2_jni/java/build.gradle.kts index 58c58fc..78b0ebc 100644 --- a/nearby/connections/ukey2/ukey2_jni/java/build.gradle.kts +++ b/nearby/connections/ukey2/ukey2_jni/java/build.gradle.kts @@ -44,6 +44,7 @@ dependencies { implementation("com.google.code.findbugs:jsr305:3.0.2") implementation(kotlin("stdlib")) testImplementation("org.junit.jupiter:junit-jupiter:5.9.2") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2") } kotlin { @@ -51,10 +52,10 @@ kotlin { } tasks.jmh { - jvmArgs.value(mutableListOf("-Djava.library.path=../../../../target/release")) + jvmArgs.value(mutableListOf("-Djava.library.path=$projectDir/../../../../target/release")) } tasks.test { useJUnitPlatform() - jvmArgs = mutableListOf("-Djava.library.path=../../../../target/debug") + jvmArgs = mutableListOf("-Djava.library.path=$projectDir/../../../../target/debug") } diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/jmh/java/com/google/security/cryptauth/lib/securegcm/Ukey2Benchmark.java b/nearby/connections/ukey2/ukey2_jni/java/src/jmh/java/com/google/security/cryptauth/lib/securegcm/Ukey2Benchmark.java deleted file mode 100644 index eb063cc..0000000 --- a/nearby/connections/ukey2/ukey2_jni/java/src/jmh/java/com/google/security/cryptauth/lib/securegcm/Ukey2Benchmark.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.security.cryptauth.lib.securegcm; - -import org.openjdk.jmh.annotations.*; -import org.openjdk.jmh.infra.Blackhole; -import org.openjdk.jmh.profile.GCProfiler; -import org.openjdk.jmh.runner.Runner; -import org.openjdk.jmh.runner.RunnerException; -import org.openjdk.jmh.runner.options.Options; -import org.openjdk.jmh.runner.options.OptionsBuilder; - -import java.nio.charset.StandardCharsets; -import java.time.Duration; -import java.util.concurrent.TimeUnit; -import java.util.Random; - -/** - * Benchmark for encoding and decoding UKEY2 messages over the JNI, analogous to - * `ukey2_benches.rs`. The parameters and the operations also roughly matches the that of the Rust - * Criterion benchmark. That said, since the benchmark infrastructure is different, there will - * inevitably be differences the skews the number in certain ways – comparison of numbers from the - * different benchmarks should compared on order-of-magnitudes only. To get the JNI overhead, for - * example, it would be better use this JMH infra to measure a call into a no-op Rust function, - * which is a more apples-to-apples comparison. - * - * To run this benchmark, run - * cargo build -p ukey2_jni --release && ./gradlew jmh - */ -@State(Scope.Benchmark) -@OutputTimeUnit(TimeUnit.SECONDS) -@BenchmarkMode(Mode.Throughput) -public class Ukey2Benchmark { - - @State(Scope.Thread) - public static class ConnectionState { - D2DConnectionContextV1 connContext; - D2DConnectionContextV1 serverConnContext; - @Param({"10", "1024"}) - int sizeKibs; - byte[] inputBytes; - - @Setup - public void setup() throws Exception { - D2DHandshakeContext initiatorContext = - new D2DHandshakeContext(D2DHandshakeContext.Role.Initiator); - D2DHandshakeContext serverContext = - new D2DHandshakeContext(D2DHandshakeContext.Role.Responder); - serverContext.parseHandshakeMessage(initiatorContext.getNextHandshakeMessage()); - initiatorContext.parseHandshakeMessage(serverContext.getNextHandshakeMessage()); - serverContext.parseHandshakeMessage(initiatorContext.getNextHandshakeMessage()); - connContext = initiatorContext.toConnectionContext(); - serverConnContext = serverContext.toConnectionContext(); - Random random = new Random(); - inputBytes = new byte[sizeKibs * 1024]; - random.nextBytes(inputBytes); - } - } - - @Benchmark - @Fork(3) - @Warmup(iterations = 2, time = 500, timeUnit = TimeUnit.MILLISECONDS) - @Measurement(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS) - public void encodeAndDecode(ConnectionState state, Blackhole blackhole) throws Exception { - byte[] encoded = state.connContext.encodeMessageToPeer(state.inputBytes, null); - byte[] decoded = state.serverConnContext.decodeMessageFromPeer(encoded, null); - blackhole.consume(decoded); - } -} diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/jmh/java/com/google/security/cryptauth/lib/securegcm/ukey2/Ukey2Benchmark.java b/nearby/connections/ukey2/ukey2_jni/java/src/jmh/java/com/google/security/cryptauth/lib/securegcm/ukey2/Ukey2Benchmark.java new file mode 100644 index 0000000..9cca229 --- /dev/null +++ b/nearby/connections/ukey2/ukey2_jni/java/src/jmh/java/com/google/security/cryptauth/lib/securegcm/ukey2/Ukey2Benchmark.java @@ -0,0 +1,78 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.security.cryptauth.lib.securegcm.ukey2; + +import com.google.security.cryptauth.lib.securegcm.ukey2.D2DHandshakeContext.Role; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.Blackhole; + +import java.util.concurrent.TimeUnit; +import java.util.Random; + +/** + * Benchmark for encoding and decoding UKEY2 messages over the JNI, analogous to `ukey2_benches.rs`. + * The parameters and the operations also roughly matches the that of the Rust Criterion benchmark. + * That said, since the benchmark infrastructure is different, there will inevitably be differences + * the skews the number in certain ways – comparison of numbers from the different benchmarks should + * compared on order-of-magnitudes only. To get the JNI overhead, for example, it would be better + * use this JMH infra to measure a call into a no-op Rust function, which is a more apples-to-apples + * comparison. + * + * <p>To run this benchmark, run cargo build -p ukey2_jni --release && ./gradlew jmh + */ +@State(Scope.Benchmark) +@OutputTimeUnit(TimeUnit.SECONDS) +@BenchmarkMode(Mode.Throughput) +public class Ukey2Benchmark { + + @State(Scope.Thread) + public static class ConnectionState { + D2DConnectionContextV1 connContext; + D2DConnectionContextV1 serverConnContext; + + @Param({"10", "1024"}) + int sizeKibs; + + byte[] inputBytes; + + @Setup + public void setup() throws Exception { + D2DHandshakeContext initiatorContext = + new D2DHandshakeContext(Role.INITIATOR); + D2DHandshakeContext serverContext = + new D2DHandshakeContext(Role.RESPONDER); + serverContext.parseHandshakeMessage(initiatorContext.getNextHandshakeMessage()); + initiatorContext.parseHandshakeMessage(serverContext.getNextHandshakeMessage()); + serverContext.parseHandshakeMessage(initiatorContext.getNextHandshakeMessage()); + connContext = initiatorContext.toConnectionContext(); + serverConnContext = serverContext.toConnectionContext(); + Random random = new Random(); + inputBytes = new byte[sizeKibs * 1024]; + random.nextBytes(inputBytes); + } + } + + @Benchmark + @Fork(3) + @Warmup(iterations = 2, time = 500, timeUnit = TimeUnit.MILLISECONDS) + @Measurement(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS) + public void encodeAndDecode(ConnectionState state, Blackhole blackhole) throws Exception { + byte[] encoded = state.connContext.encodeMessageToPeer(state.inputBytes, null); + byte[] decoded = state.serverConnContext.decodeMessageFromPeer(encoded, null); + blackhole.consume(decoded); + } +} diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/D2DConnectionContextV1.java b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/D2DConnectionContextV1.java deleted file mode 100644 index 7874cd9..0000000 --- a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/D2DConnectionContextV1.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.security.cryptauth.lib.securegcm; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -public class D2DConnectionContextV1 { - - static { - System.loadLibrary("ukey2_jni"); - } - - private static native byte[] encode_message_to_peer(long contextPtr, byte[] payload, byte[] associatedData) throws BadHandleException; - - private static native byte[] decode_message_from_peer(long contextPtr, byte[] message, byte[] associatedData) throws CryptoException; - - private static native byte[] get_session_unique(long contextPtr) throws BadHandleException; - - private static native int get_sequence_number_for_encoding(long contextPtr) throws BadHandleException; - - private static native int get_sequence_number_for_decoding(long contextPtr) throws BadHandleException; - - private static native byte[] save_session(long contextPtr) throws BadHandleException; - - private static native long from_saved_session(byte[] savedSessionInfo); - - private final long contextPtr; - - /** - * Java wrapper for D2DConnectionContextV1 to interact with the underlying Rust implementation - * - * @param contextPtr the handle to the Rust implementation. - */ - D2DConnectionContextV1(@Nonnull long contextPtr) { - this.contextPtr = contextPtr; - } - - /** - * Encode a message to the connection peer using session keys derived from the handshake. - * - * @param payload The message to be encrypted. - * @return The encrypted/encoded message. - */ - @Nonnull - public byte[] encodeMessageToPeer(@Nonnull byte[] payload, @Nullable byte[] associatedData) throws BadHandleException { - return encode_message_to_peer(contextPtr, payload, associatedData); - } - - /** - * Decodes/decrypts a message from the connection peer. - * - * @param message The message received over the connection. - * @return The decoded message from the connection peer. - */ - @Nonnull - public byte[] decodeMessageFromPeer(@Nonnull byte[] message, @Nullable byte[] associatedData) throws CryptoException { - return decode_message_from_peer(contextPtr, message, associatedData); - } - - /** - * A unique session identifier derived from session-specific information - * - * @return The session unique identifier - */ - @Nonnull - public byte[] getSessionUnique() throws BadHandleException { - return get_session_unique(contextPtr); - } - - /** - * Returns the encoding sequence number. - * - * @return the encoding sequence number. - */ - public int getSequenceNumberForEncoding() throws BadHandleException { - return get_sequence_number_for_encoding(contextPtr); - } - - /** - * Returns the decoding sequence number. - * - * @return the decoding sequence number. - */ - public int getSequenceNumberForDecoding() throws BadHandleException { - return get_sequence_number_for_decoding(contextPtr); - } - - /** - * Serializes the current session in a form usable by {@link D2DConnectionContextV1#fromSavedSession} - * - * @return a byte array representing the current session. - */ - @Nonnull - public byte[] saveSession() throws BadHandleException { - return save_session(contextPtr); - } - - /** - * Reconstructs and returns the session originally serialized by {@link D2DConnectionContextV1#saveSession} - * - * @param savedSessionInfo the byte array from saveSession() - * @return a D2DConnectionContextV1 session with the same properties as the context saved. - */ - public static D2DConnectionContextV1 fromSavedSession(@Nonnull byte[] savedSessionInfo) { - return new D2DConnectionContextV1(from_saved_session(savedSessionInfo)); - } - -} diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/D2DHandshakeContext.java b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/D2DHandshakeContext.java deleted file mode 100644 index 39f7aa9..0000000 --- a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/D2DHandshakeContext.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.security.cryptauth.lib.securegcm; - -import javax.annotation.Nonnull; - -public class D2DHandshakeContext { - static { - System.loadLibrary("ukey2_jni"); - } - - public enum Role { - INITIATOR, - RESPONDER, - } - - private final long contextPtr; - - private static native boolean is_handshake_complete(long contextPtr) throws BadHandleException; - - private static native long create_context(boolean isClient); - - private static native byte[] get_next_handshake_message(long contextPtr) throws BadHandleException; - - private static native void parse_handshake_message(long contextPtr, byte[] message) throws BadHandleException, HandshakeException; - - private static native byte[] get_verification_string(long contextPtr, int length) throws BadHandleException, HandshakeException; - - private static native long to_connection_context(long contextPtr) throws HandshakeException; - - public D2DHandshakeContext(@Nonnull Role role) { - this.contextPtr = create_context(role == Role.INITIATOR); - } - - /** - * Convenience constructor that creates a UKEY2 D2DHandshakeContext for the initiator role. - * - * @return a D2DHandshakeContext for the role of initiator in the handshake. - */ - public static D2DHandshakeContext forInitiator() { - return new D2DHandshakeContext(Role.INITIATOR); - } - - /** - * Convenience constructor that creates a UKEY2 D2DHandshakeContext for the initiator role. - * - * @return a D2DHandshakeContext for the role of responder/server in the handshake. - */ - public static D2DHandshakeContext forResponder() { - return new D2DHandshakeContext(Role.RESPONDER); - } - - /** - * Function that checks if the handshake is completed. - * - * @return true/false depending on if the handshake is complete. - */ - public boolean isHandshakeComplete() throws BadHandleException { - return is_handshake_complete(contextPtr); - } - - /** - * Gets the next handshake message in the exchange. - * - * @return handshake message encoded in a SecureMessage. - */ - @Nonnull - public byte[] getNextHandshakeMessage() throws BadHandleException { - return get_next_handshake_message(contextPtr); - } - - /** - * Parses the handshake message. - * - * @param message - handshake message from the other side. - */ - @Nonnull - public void parseHandshakeMessage(@Nonnull byte[] message) throws BadHandleException, HandshakeException { - parse_handshake_message(contextPtr, message); - } - - /** - * Returns an authentication string suitable for authenticating the handshake out-of-band. Note - * that the authentication string can be short (e.g., a 6 digit visual confirmation code). Note: - * this should only be called when {#isHandshakeComplete} returns true. - * This code is analogous to the authentication string described in the spec. - * - * @param length - The length of the returned verification string. - * @return - The returned verification string as a byte array. - * @throws BadHandleException - Thrown if the handle is no longer valid, for example after calling {@link D2DHandshakeContext#toConnectionContext} - * @throws HandshakeException - Thrown if the handshake is not complete when this function is called. - */ - @Nonnull - public byte[] getVerificationString(int length) throws BadHandleException, HandshakeException { - return get_verification_string(contextPtr, length); - } - - /** - * Function to create a secure communication channel from the handshake after confirming the auth string generated by - * the handshake out-of-band (i.e. via a user-facing UI). - * - * @return a new {@link D2DConnectionContextV1} with the next protocol specified when creating the D2DHandshakeContext. - * @throws HandshakeException if the handsshake is not complete when this function is called. - */ - public D2DConnectionContextV1 toConnectionContext() throws HandshakeException { - return new D2DConnectionContextV1(to_connection_context(contextPtr)); - } -} diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/BadHandleException.java b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/BadHandleException.java index 2efd7c4..78f0e5e 100644 --- a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/BadHandleException.java +++ b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/BadHandleException.java @@ -12,10 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.google.security.cryptauth.lib.securegcm; +package com.google.security.cryptauth.lib.securegcm.ukey2; /** - * Represents an unrecoverable error (invalid handle) that has occurred during the handshake/connection. + * Represents an unrecoverable error (invalid handle) that has occurred during the + * handshake/connection. */ public class BadHandleException extends Exception { public BadHandleException(String message) { @@ -29,4 +30,4 @@ public class BadHandleException extends Exception { public BadHandleException(String message, Exception e) { super(message, e); } -}
\ No newline at end of file +} diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/CryptoException.java b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/CryptoException.java index 6abeb53..11b5c9b 100644 --- a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/CryptoException.java +++ b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/CryptoException.java @@ -12,11 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.google.security.cryptauth.lib.securegcm; +package com.google.security.cryptauth.lib.securegcm.ukey2; -/** - * Represents an unrecoverable error that has occurred during the handshake procedure. - */ +/** Represents an unrecoverable error that has occurred during the handshake procedure. */ public class CryptoException extends Exception { public CryptoException(String message) { super(message); @@ -29,4 +27,4 @@ public class CryptoException extends Exception { public CryptoException(String message, Exception e) { super(message, e); } -}
\ No newline at end of file +} diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/D2DConnectionContextV1.java b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/D2DConnectionContextV1.java new file mode 100644 index 0000000..9ce2517 --- /dev/null +++ b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/D2DConnectionContextV1.java @@ -0,0 +1,139 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.security.cryptauth.lib.securegcm.ukey2; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class D2DConnectionContextV1 { + + static { + var path = System.getProperty("java.library.path"); + + if (path == null) { + throw new RuntimeException("Path isn't set."); + } + + var paths = java.util.List.of(path.split(";")); + paths.forEach(System.out::println); + + System.loadLibrary("ukey2_jni"); + } + + private static native byte[] encode_message_to_peer( + long contextPtr, byte[] payload, byte[] associatedData) throws BadHandleException; + + private static native byte[] decode_message_from_peer( + long contextPtr, byte[] message, byte[] associatedData) throws CryptoException; + + private static native byte[] get_session_unique(long contextPtr) throws BadHandleException; + + private static native int get_sequence_number_for_encoding(long contextPtr) + throws BadHandleException; + + private static native int get_sequence_number_for_decoding(long contextPtr) + throws BadHandleException; + + private static native byte[] save_session(long contextPtr) throws BadHandleException; + + private static native long from_saved_session(byte[] savedSessionInfo); + + private final long contextPtr; + + /** + * Java wrapper for D2DConnectionContextV1 to interact with the underlying Rust implementation + * + * @param contextPtr the handle to the Rust implementation. + */ + D2DConnectionContextV1(@Nonnull long contextPtr) { + this.contextPtr = contextPtr; + } + + /** + * Encode a message to the connection peer using session keys derived from the handshake. + * + * @param payload The message to be encrypted. + * @return The encrypted/encoded message. + */ + @Nonnull + public byte[] encodeMessageToPeer(@Nonnull byte[] payload, @Nullable byte[] associatedData) + throws BadHandleException { + return encode_message_to_peer(contextPtr, payload, associatedData); + } + + /** + * Decodes/decrypts a message from the connection peer. + * + * @param message The message received over the connection. + * @return The decoded message from the connection peer. + */ + @Nonnull + public byte[] decodeMessageFromPeer(@Nonnull byte[] message, @Nullable byte[] associatedData) + throws CryptoException { + return decode_message_from_peer(contextPtr, message, associatedData); + } + + /** + * A unique session identifier derived from session-specific information + * + * @return The session unique identifier + */ + @Nonnull + public byte[] getSessionUnique() throws BadHandleException { + return get_session_unique(contextPtr); + } + + /** + * Returns the encoding sequence number. + * + * @return the encoding sequence number. + */ + public int getSequenceNumberForEncoding() throws BadHandleException { + return get_sequence_number_for_encoding(contextPtr); + } + + /** + * Returns the decoding sequence number. + * + * @return the decoding sequence number. + */ + public int getSequenceNumberForDecoding() throws BadHandleException { + return get_sequence_number_for_decoding(contextPtr); + } + + /** + * Serializes the current session in a form usable by {@link + * D2DConnectionContextV1#fromSavedSession} + * + * @return a byte array representing the current session. + */ + @Nonnull + public byte[] saveSession() throws BadHandleException { + return save_session(contextPtr); + } + + /** + * Reconstructs and returns the session originally serialized by {@link + * D2DConnectionContextV1#saveSession} + * + * @param savedSessionInfo the byte array from saveSession() + * @return a D2DConnectionContextV1 session with the same properties as the context saved. + */ + public static D2DConnectionContextV1 fromSavedSession(@Nonnull byte[] savedSessionInfo) { + return new D2DConnectionContextV1(from_saved_session(savedSessionInfo)); + } +} diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/D2DHandshakeContext.java b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/D2DHandshakeContext.java new file mode 100644 index 0000000..429295e --- /dev/null +++ b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/D2DHandshakeContext.java @@ -0,0 +1,129 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.security.cryptauth.lib.securegcm.ukey2; + +import javax.annotation.Nonnull; + +public class D2DHandshakeContext { + static { + System.loadLibrary("ukey2_jni"); + } + + public enum Role { + INITIATOR, + RESPONDER, + } + + private final long contextPtr; + + private static native boolean is_handshake_complete(long contextPtr) throws BadHandleException; + + private static native long create_context(boolean isClient); + + private static native byte[] get_next_handshake_message(long contextPtr) + throws BadHandleException; + + private static native void parse_handshake_message(long contextPtr, byte[] message) + throws BadHandleException, HandshakeException; + + private static native byte[] get_verification_string(long contextPtr, int length) + throws BadHandleException, HandshakeException; + + private static native long to_connection_context(long contextPtr) throws HandshakeException; + + public D2DHandshakeContext(@Nonnull Role role) { + this.contextPtr = create_context(role == Role.INITIATOR); + } + + /** + * Convenience constructor that creates a UKEY2 D2DHandshakeContext for the initiator role. + * + * @return a D2DHandshakeContext for the role of initiator in the handshake. + */ + public static D2DHandshakeContext forInitiator() { + return new D2DHandshakeContext(Role.INITIATOR); + } + + /** + * Convenience constructor that creates a UKEY2 D2DHandshakeContext for the initiator role. + * + * @return a D2DHandshakeContext for the role of responder/server in the handshake. + */ + public static D2DHandshakeContext forResponder() { + return new D2DHandshakeContext(Role.RESPONDER); + } + + /** + * Function that checks if the handshake is completed. + * + * @return true/false depending on if the handshake is complete. + */ + public boolean isHandshakeComplete() throws BadHandleException { + return is_handshake_complete(contextPtr); + } + + /** + * Gets the next handshake message in the exchange. + * + * @return handshake message encoded in a SecureMessage. + */ + @Nonnull + public byte[] getNextHandshakeMessage() throws BadHandleException { + return get_next_handshake_message(contextPtr); + } + + /** + * Parses the handshake message. + * + * @param message - handshake message from the other side. + */ + @Nonnull + public void parseHandshakeMessage(@Nonnull byte[] message) + throws BadHandleException, HandshakeException { + parse_handshake_message(contextPtr, message); + } + + /** + * Returns an authentication string suitable for authenticating the handshake out-of-band. Note + * that the authentication string can be short (e.g., a 6 digit visual confirmation code). Note: + * this should only be called when {#isHandshakeComplete} returns true. This code is analogous to + * the authentication string described in the spec. + * + * @param length - The length of the returned verification string. + * @return - The returned verification string as a byte array. + * @throws BadHandleException - Thrown if the handle is no longer valid, for example after calling + * {@link D2DHandshakeContext#toConnectionContext} + * @throws HandshakeException - Thrown if the handshake is not complete when this function is + * called. + */ + @Nonnull + public byte[] getVerificationString(int length) throws BadHandleException, HandshakeException { + return get_verification_string(contextPtr, length); + } + + /** + * Function to create a secure communication channel from the handshake after confirming the auth + * string generated by the handshake out-of-band (i.e. via a user-facing UI). + * + * @return a new {@link D2DConnectionContextV1} with the next protocol specified when creating the + * D2DHandshakeContext. + * @throws HandshakeException if the handsshake is not complete when this function is called. + */ + public D2DConnectionContextV1 toConnectionContext() throws HandshakeException { + return new D2DConnectionContextV1(to_connection_context(contextPtr)); + } +} diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/HandshakeException.java b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/HandshakeException.java index 17928e9..20d3112 100644 --- a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/HandshakeException.java +++ b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/HandshakeException.java @@ -12,21 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.google.security.cryptauth.lib.securegcm; +package com.google.security.cryptauth.lib.securegcm.ukey2; -/** - * Represents an unrecoverable error that has occurred during the handshake procedure. - */ +/** Represents an unrecoverable error that has occurred during the handshake procedure. */ public class HandshakeException extends Exception { - public HandshakeException(String message) { - super(message); - } + public HandshakeException(String message) { + super(message); + } - public HandshakeException(Exception e) { - super(e); - } + public HandshakeException(Exception e) { + super(e); + } - public HandshakeException(String message, Exception e) { - super(message, e); - } -}
\ No newline at end of file + public HandshakeException(String message, Exception e) { + super(message, e); + } +} diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/SessionRestoreException.java b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/SessionRestoreException.java index c780973..026f8c5 100644 --- a/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/SessionRestoreException.java +++ b/nearby/connections/ukey2/ukey2_jni/java/src/main/java/com/google/security/cryptauth/lib/securegcm/ukey2/SessionRestoreException.java @@ -12,11 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.google.security.cryptauth.lib.securegcm; +package com.google.security.cryptauth.lib.securegcm.ukey2; -/** - * Represents an unrecoverable error that has occurred during the handshake procedure. - */ +/** Represents an unrecoverable error that has occurred during the handshake procedure. */ public class SessionRestoreException extends Exception { public SessionRestoreException(String message) { super(message); @@ -29,4 +27,4 @@ public class SessionRestoreException extends Exception { public SessionRestoreException(String message, Exception e) { super(message, e); } -}
\ No newline at end of file +} diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/test/java/com/google/security/cryptauth/lib/securegcm/TestUkey2Protocol.kt b/nearby/connections/ukey2/ukey2_jni/java/src/test/java/com/google/security/cryptauth/lib/securegcm/TestUkey2Protocol.kt deleted file mode 100644 index 79cbd15..0000000 --- a/nearby/connections/ukey2/ukey2_jni/java/src/test/java/com/google/security/cryptauth/lib/securegcm/TestUkey2Protocol.kt +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * This Java source file was generated by the Gradle 'init' task. - */ -package com.google.security.cryptauth.lib.securegcm - -import java.nio.charset.StandardCharsets -import org.junit.jupiter.api.Assertions.assertArrayEquals -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertFalse -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertDoesNotThrow -import org.junit.jupiter.api.assertThrows - -// Driver code -// Tests exception handling and the handshake routine, as well as encrypting/decrypting short message between the server and initiator contexts. -@Suppress("UNUSED_VARIABLE") -class TestUkey2Protocol { - @Test - fun testHandshake() { - val initiatorContext = - D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) - assertFalse(initiatorContext.isHandshakeComplete) - val serverContext = - D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) - assertFalse(serverContext.isHandshakeComplete) - assertDoesNotThrow { - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - assertTrue(initiatorContext.isHandshakeComplete) - assertTrue(serverContext.isHandshakeComplete) - } - } - - @Test - fun testSendReceiveMessage() { - val initiatorContext = - D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) - val serverContext = - D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) - assertDoesNotThrow { - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - val connContext = initiatorContext.toConnectionContext() - val serverConnContext = serverContext.toConnectionContext() - val initialShareString = "Nearby sharing to server" - val encoded = connContext.encodeMessageToPeer( - initialShareString.toByteArray( - StandardCharsets.UTF_8 - ), null - ) - val response = - String(serverConnContext.decodeMessageFromPeer(encoded, null), StandardCharsets.UTF_8) - assertEquals(response, initialShareString) - } - } - - @Test - fun testSaveRestoreSession() { - val initiatorContext = - D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) - val serverContext = - D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) - assertDoesNotThrow { - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - val connContext = initiatorContext.toConnectionContext() - val serverConnContext = serverContext.toConnectionContext() - val initiatorSavedSession = connContext.saveSession() - val restored = D2DConnectionContextV1.fromSavedSession(initiatorSavedSession) - assertArrayEquals(connContext.sessionUnique, restored.sessionUnique) - val initialShareString = "Nearby sharing to server" - val encoded = serverConnContext.encodeMessageToPeer( - initialShareString.toByteArray( - StandardCharsets.UTF_8 - ), null - ) - val response = String(restored.decodeMessageFromPeer(encoded, null), StandardCharsets.UTF_8) - assertEquals(response, initialShareString) - } - } - - @Test - fun testSaveRestoreBadSession() { - val initiatorContext = - D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) - val serverContext = - D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) - val deriveInitiatorSavedSession = { - assertDoesNotThrow { - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - val connContext = initiatorContext.toConnectionContext() - val serverConnContext = serverContext.toConnectionContext() - connContext.saveSession() - } - } - assertThrows<SessionRestoreException> { - val unused = D2DConnectionContextV1.fromSavedSession(deriveInitiatorSavedSession().copyOfRange(0, 20)) - } - } - - @Test - fun tryReuseHandshakeContext() { - val initiatorContext = - D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) - val serverContext = - D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) - assertDoesNotThrow { - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - val connContext = initiatorContext.toConnectionContext() - val serverConnContext = serverContext.toConnectionContext() - } - assertThrows<BadHandleException> { - val unused = serverContext.nextHandshakeMessage - } - } - - @Test - fun testSendReceiveMessageWithAssociatedData() { - val initiatorContext = - D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) - val serverContext = - D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) - val associatedData = "Associated data.".toByteArray() - assertDoesNotThrow { - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - val connContext = initiatorContext.toConnectionContext() - val serverConnContext = serverContext.toConnectionContext() - val initialShareString = "Nearby sharing to server" - val encoded = connContext.encodeMessageToPeer( - initialShareString.toByteArray( - StandardCharsets.UTF_8 - ), associatedData - ) - val response = - String(serverConnContext.decodeMessageFromPeer(encoded, associatedData), StandardCharsets.UTF_8) - assertEquals(response, initialShareString) - } - } - - @Test - fun testVerificationString() { - val initiatorContext = - D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) - val serverContext = - D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) - assertDoesNotThrow { - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) - serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) - } - assert(serverContext.isHandshakeComplete) - assert(initiatorContext.isHandshakeComplete) - assertArrayEquals(serverContext.getVerificationString(32), initiatorContext.getVerificationString(32)) - } -}
\ No newline at end of file diff --git a/nearby/connections/ukey2/ukey2_jni/java/src/test/java/com/google/security/cryptauth/lib/securegcm/ukey2/TestUkey2Protocol.kt b/nearby/connections/ukey2/ukey2_jni/java/src/test/java/com/google/security/cryptauth/lib/securegcm/ukey2/TestUkey2Protocol.kt new file mode 100644 index 0000000..f770977 --- /dev/null +++ b/nearby/connections/ukey2/ukey2_jni/java/src/test/java/com/google/security/cryptauth/lib/securegcm/ukey2/TestUkey2Protocol.kt @@ -0,0 +1,167 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package com.google.security.cryptauth.lib.securegcm.ukey2 + +import java.nio.charset.StandardCharsets +import org.junit.jupiter.api.Assertions.assertArrayEquals +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertDoesNotThrow +import org.junit.jupiter.api.assertThrows + +// Driver code +// Tests exception handling and the handshake routine, as well as encrypting/decrypting short +// message between the server and initiator contexts. +@Suppress("UNUSED_VARIABLE") +class TestUkey2Protocol { + @Test + fun testHandshake() { + val initiatorContext = D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) + println("got initial context") + assertFalse(initiatorContext.isHandshakeComplete) + val serverContext = D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) + assertFalse(serverContext.isHandshakeComplete) + assertDoesNotThrow { + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + assertTrue(initiatorContext.isHandshakeComplete) + assertTrue(serverContext.isHandshakeComplete) + } + } + + @Test + fun testSendReceiveMessage() { + val initiatorContext = D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) + val serverContext = D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) + assertDoesNotThrow { + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + val connContext = initiatorContext.toConnectionContext() + val serverConnContext = serverContext.toConnectionContext() + val initialShareString = "Nearby sharing to server" + val encoded = + connContext.encodeMessageToPeer( + initialShareString.toByteArray(StandardCharsets.UTF_8), null) + val response = + String(serverConnContext.decodeMessageFromPeer(encoded, null), StandardCharsets.UTF_8) + assertEquals(response, initialShareString) + } + } + + @Test + fun testSaveRestoreSession() { + val initiatorContext = D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) + val serverContext = D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) + assertDoesNotThrow { + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + val connContext = initiatorContext.toConnectionContext() + val serverConnContext = serverContext.toConnectionContext() + val initiatorSavedSession = connContext.saveSession() + val restored = D2DConnectionContextV1.fromSavedSession(initiatorSavedSession) + assertArrayEquals(connContext.sessionUnique, restored.sessionUnique) + val initialShareString = "Nearby sharing to server" + val encoded = + serverConnContext.encodeMessageToPeer( + initialShareString.toByteArray(StandardCharsets.UTF_8), null) + val response = String(restored.decodeMessageFromPeer(encoded, null), StandardCharsets.UTF_8) + assertEquals(response, initialShareString) + } + } + + @Test + fun testSaveRestoreBadSession() { + val initiatorContext = D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) + val serverContext = D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) + val deriveInitiatorSavedSession = { + assertDoesNotThrow { + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + val connContext = initiatorContext.toConnectionContext() + val serverConnContext = serverContext.toConnectionContext() + connContext.saveSession() + } + } + assertThrows<SessionRestoreException> { + val unused = + D2DConnectionContextV1.fromSavedSession(deriveInitiatorSavedSession().copyOfRange(0, 20)) + } + } + + @Test + fun tryReuseHandshakeContext() { + val initiatorContext = D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) + val serverContext = D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) + assertDoesNotThrow { + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + val connContext = initiatorContext.toConnectionContext() + val serverConnContext = serverContext.toConnectionContext() + } + assertThrows<BadHandleException> { + val unused = serverContext.nextHandshakeMessage + } + } + + @Test + fun testSendReceiveMessageWithAssociatedData() { + val initiatorContext = D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) + val serverContext = D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) + val associatedData = "Associated data.".toByteArray() + assertDoesNotThrow { + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + val connContext = initiatorContext.toConnectionContext() + val serverConnContext = serverContext.toConnectionContext() + val initialShareString = "Nearby sharing to server" + val encoded = + connContext.encodeMessageToPeer( + initialShareString.toByteArray(StandardCharsets.UTF_8), associatedData) + val response = + String( + serverConnContext.decodeMessageFromPeer(encoded, associatedData), + StandardCharsets.UTF_8) + assertEquals(response, initialShareString) + } + } + + @Test + fun testVerificationString() { + val initiatorContext = D2DHandshakeContext(D2DHandshakeContext.Role.INITIATOR) + val serverContext = D2DHandshakeContext(D2DHandshakeContext.Role.RESPONDER) + assertDoesNotThrow { + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + initiatorContext.parseHandshakeMessage(serverContext.nextHandshakeMessage) + serverContext.parseHandshakeMessage(initiatorContext.nextHandshakeMessage) + } + assert(serverContext.isHandshakeComplete) + assert(initiatorContext.isHandshakeComplete) + assertArrayEquals( + serverContext.getVerificationString(32), initiatorContext.getVerificationString(32)) + } +} diff --git a/nearby/connections/ukey2/ukey2_jni/src/lib.rs b/nearby/connections/ukey2/ukey2_jni/src/lib.rs index 597c973..c500ddd 100644 --- a/nearby/connections/ukey2/ukey2_jni/src/lib.rs +++ b/nearby/connections/ukey2/ukey2_jni/src/lib.rs @@ -59,12 +59,12 @@ fn generate_handle() -> u64 { pub(crate) fn insert_handshake_handle(item: D2DBox) -> u64 { let mut handle = generate_handle(); - let map = HANDLE_MAPPING.lock(); + let mut map = HANDLE_MAPPING.lock(); while map.contains_key(&handle) { handle = generate_handle(); } - let result = HANDLE_MAPPING.lock().insert(handle, item); + let result = map.insert(handle, item); // result should always be None since we checked that handle map does not contain the key already assert!(result.is_none()); handle @@ -72,12 +72,12 @@ pub(crate) fn insert_handshake_handle(item: D2DBox) -> u64 { pub(crate) fn insert_conn_handle(item: ConnectionBox) -> u64 { let mut handle = generate_handle(); - let map = CONNECTION_HANDLE_MAPPING.lock(); + let mut map = CONNECTION_HANDLE_MAPPING.lock(); while map.contains_key(&handle) { handle = generate_handle(); } - let result = CONNECTION_HANDLE_MAPPING.lock().insert(handle, item); + let result = map.insert(handle, item); // result should always be None since we checked that handle map does not contain the key already assert!(result.is_none()); handle @@ -94,7 +94,7 @@ enum JniError { /// Tells the caller whether the handshake has completed or not. If the handshake is complete, /// the caller may call `to_connection_context`to obtain a connection context. #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHandshakeContext_is_1handshake_1complete( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DHandshakeContext_is_1handshake_1complete( env: JNIEnv, _: JClass, context_handle: jlong, @@ -103,7 +103,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHands if let Some(ctx) = HANDLE_MAPPING.lock().get(&(context_handle as u64)) { is_complete = ctx.is_handshake_complete(); } else { - env.throw_new("com/google/security/cryptauth/lib/securegcm/BadHandleException", "") + env.throw_new("com/google/security/cryptauth/lib/securegcm/ukey2/BadHandleException", "") .expect("failed to find error class"); } is_complete as jboolean @@ -111,7 +111,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHands /// Creates a new handshake context #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHandshakeContext_create_1context( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DHandshakeContext_create_1context( _: JNIEnv, _: JClass, is_client: jboolean, @@ -131,7 +131,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHands /// Constructs the next message that should be sent in the handshake. #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHandshakeContext_get_1next_1handshake_1message( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DHandshakeContext_get_1next_1handshake_1message( env: JNIEnv, _: JClass, context_handle: jlong, @@ -140,7 +140,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHands let next_message = if let Some(ctx) = HANDLE_MAPPING.lock().get(&(context_handle as u64)) { ctx.get_next_handshake_message() } else { - env.throw_new("com/google/security/cryptauth/lib/securegcm/BadHandleException", "") + env.throw_new("com/google/security/cryptauth/lib/securegcm/ukey2/BadHandleException", "") .expect("failed to find error class"); None }; @@ -156,7 +156,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHands // Safety: We know the message pointer is safe as it is coming directly from the JVM. #[allow(clippy::not_unsafe_ptr_arg_deref)] #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHandshakeContext_parse_1handshake_1message( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DHandshakeContext_parse_1handshake_1message( env: JNIEnv, _: JClass, context_handle: jlong, @@ -166,14 +166,14 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHands let result = if let Some(ctx) = HANDLE_MAPPING.lock().get_mut(&(context_handle as u64)) { ctx.handle_handshake_message(rust_buffer.as_slice()).map_err(JniError::HandleMessageError) } else { - env.throw_new("com/google/security/cryptauth/lib/securegcm/BadHandleException", "") + env.throw_new("com/google/security/cryptauth/lib/securegcm/ukey2/BadHandleException", "") .expect("failed to find error class"); Err(JniError::BadHandle) }; if let Err(e) = result { if !env.exception_check().unwrap() { env.throw_new( - "com/google/security/cryptauth/lib/securegcm/HandshakeException", + "com/google/security/cryptauth/lib/securegcm/ukey2/HandshakeException", match e { JniError::BadHandle => "Bad handle", JniError::DecodeError(_) => "Unable to decode message", @@ -189,7 +189,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHands /// Returns the `CompletedHandshake` using the results from this handshake context. May only /// be called if `is_handshake_complete` returns true. #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHandshakeContext_get_1verification_1string( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DHandshakeContext_get_1verification_1string( env: JNIEnv, _: JClass, context_handle: jlong, @@ -201,14 +201,14 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHands .map_err(|_| JniError::HandshakeError(HandshakeError::HandshakeNotComplete)) .map(|h| h.auth_string::<CryptoProvider>().derive_vec(length as usize).unwrap()) } else { - env.throw_new("com/google/security/cryptauth/lib/securegcm/BadHandleException", "") + env.throw_new("com/google/security/cryptauth/lib/securegcm/ukey2/BadHandleException", "") .expect("failed to find error class"); Err(JniError::BadHandle) }; if let Err(e) = result { if !env.exception_check().unwrap() { env.throw_new( - "com/google/security/cryptauth/lib/securegcm/HandshakeException", + "com/google/security/cryptauth/lib/securegcm/ukey2/HandshakeException", match e { JniError::BadHandle => "Bad handle", JniError::DecodeError(_) => "Unable to decode message", @@ -228,7 +228,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHands /// Creates a [`D2DConnectionContextV1`] using the results of the handshake. May only be called /// if `is_handshake_complete` returns true. #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHandshakeContext_to_1connection_1context( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DHandshakeContext_to_1connection_1context( env: JNIEnv, _: JClass, context_handle: jlong, @@ -240,7 +240,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHands }; if let Err(error) = conn_context { env.throw_new( - "com/google/security/cryptauth/lib/securegcm/HandshakeException", + "com/google/security/cryptauth/lib/securegcm/ukey2/HandshakeException", match error { JniError::BadHandle => "Bad context handle", JniError::HandshakeError(_) => "Handshake not complete", @@ -261,7 +261,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DHands // from the JVM. #[allow(clippy::not_unsafe_ptr_arg_deref)] #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConnectionContextV1_encode_1message_1to_1peer( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DConnectionContextV1_encode_1message_1to_1peer( env: JNIEnv, _: JClass, context_handle: jlong, @@ -291,7 +291,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne if let Ok(ret_vec) = result { env.byte_array_from_slice(ret_vec.as_slice()).expect("unable to create jByteArray") } else { - env.throw_new("com/google/security/cryptauth/lib/securegcm/BadHandleException", "") + env.throw_new("com/google/security/cryptauth/lib/securegcm/ukey2/BadHandleException", "") .expect("failed to find error class"); empty_array } @@ -304,7 +304,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne // from the JVM. #[allow(clippy::not_unsafe_ptr_arg_deref)] #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConnectionContextV1_decode_1message_1from_1peer( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DConnectionContextV1_decode_1message_1from_1peer( env: JNIEnv, _: JClass, context_handle: jlong, @@ -334,7 +334,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne env.byte_array_from_slice(message.as_slice()).expect("unable to create jByteArray") } else { env.throw_new( - "com/google/security/cryptauth/lib/securegcm/CryptoException", + "com/google/security/cryptauth/lib/securegcm/ukey2/CryptoException", match result.unwrap_err() { JniError::BadHandle => "Bad context handle", JniError::DecodeError(e) => match e { @@ -352,7 +352,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne /// Returns the last sequence number used to encode a message. #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConnectionContextV1_get_1sequence_1number_1for_1encoding( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DConnectionContextV1_get_1sequence_1number_1for_1encoding( env: JNIEnv, _: JClass, context_handle: jlong, @@ -360,7 +360,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne if let Some(ctx) = CONNECTION_HANDLE_MAPPING.lock().get(&(context_handle as u64)) { ctx.get_sequence_number_for_encoding() } else { - env.throw_new("com/google/security/cryptauth/lib/securegcm/BadHandleException", "") + env.throw_new("com/google/security/cryptauth/lib/securegcm/ukey2/BadHandleException", "") .expect("failed to find error class"); -1 } @@ -368,7 +368,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne /// Returns the last sequence number used to decode a message. #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConnectionContextV1_get_1sequence_1number_1for_1decoding( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DConnectionContextV1_get_1sequence_1number_1for_1decoding( env: JNIEnv, _: JClass, context_handle: jlong, @@ -376,7 +376,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne if let Some(ctx) = CONNECTION_HANDLE_MAPPING.lock().get(&(context_handle as u64)) { ctx.get_sequence_number_for_decoding() } else { - env.throw_new("com/google/security/cryptauth/lib/securegcm/BadHandleException", "") + env.throw_new("com/google/security/cryptauth/lib/securegcm/ukey2/BadHandleException", "") .expect("failed to find error class"); -1 } @@ -385,7 +385,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne /// Creates a saved session that can later be used for resumption. The session data may be /// persisted, but it must be stored in a secure location. #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConnectionContextV1_save_1session( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DConnectionContextV1_save_1session( env: JNIEnv, _: JClass, context_handle: jlong, @@ -394,7 +394,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne if let Some(ctx) = CONNECTION_HANDLE_MAPPING.lock().get(&(context_handle as u64)) { env.byte_array_from_slice(ctx.save_session().as_slice()).expect("unable to save session") } else { - env.throw_new("com/google/security/cryptauth/lib/securegcm/BadHandleException", "") + env.throw_new("com/google/security/cryptauth/lib/securegcm/ukey2/BadHandleException", "") .expect("failed to find error class"); empty_array } @@ -404,7 +404,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne // Safety: We know the session_info pointer is safe because it is coming directly from the JVM. #[no_mangle] #[allow(clippy::not_unsafe_ptr_arg_deref)] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConnectionContextV1_from_1saved_1session( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DConnectionContextV1_from_1saved_1session( env: JNIEnv, _: JClass, session_info: jbyteArray, @@ -416,7 +416,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne D2DConnectionContextV1::from_saved_session::<CryptoProvider>(session_info_rust.as_slice()); if ctx.is_err() { env.throw_new( - "com/google/security/cryptauth/lib/securegcm/SessionRestoreException", + "com/google/security/cryptauth/lib/securegcm/ukey2/SessionRestoreException", match ctx.err().unwrap() { DeserializeError::BadDataLength => "DeserializeError: bad session_info length", DeserializeError::BadProtocolVersion => "DeserializeError: bad protocol version", @@ -435,7 +435,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne /// of the ASCII string "D2D". Since the server and client share the same session keys, the /// resulting session unique is also the same. #[no_mangle] -pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConnectionContextV1_get_1session_1unique( +pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_ukey2_D2DConnectionContextV1_get_1session_1unique( env: JNIEnv, _: JClass, context_handle: jlong, @@ -445,7 +445,7 @@ pub extern "system" fn Java_com_google_security_cryptauth_lib_securegcm_D2DConne env.byte_array_from_slice(ctx.get_session_unique::<CryptoProvider>().as_slice()) .expect("unable to get unique session id") } else { - env.throw_new("com/google/security/cryptauth/lib/securegcm/BadHandleException", "") + env.throw_new("com/google/security/cryptauth/lib/securegcm/ukey2/BadHandleException", "") .expect("failed to find error class"); empty_array } diff --git a/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/device_to_device_messages.rs b/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/device_to_device_messages.rs index 3c2da35..71c247b 100644 --- a/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/device_to_device_messages.rs +++ b/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/device_to_device_messages.rs @@ -13,7 +13,7 @@ // limitations under the License. // This file is generated by rust-protobuf 3.2.0. Do not edit -// .proto file is parsed by protoc 3.19.1 +// .proto file is parsed by protoc 3.21.12 // @generated // https://github.com/rust-lang/rust-clippy/issues/702 diff --git a/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/securegcm.rs b/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/securegcm.rs index 3231440..70a927d 100644 --- a/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/securegcm.rs +++ b/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/securegcm.rs @@ -13,7 +13,7 @@ // limitations under the License. // This file is generated by rust-protobuf 3.2.0. Do not edit -// .proto file is parsed by protoc 3.19.1 +// .proto file is parsed by protoc 3.21.12 // @generated // https://github.com/rust-lang/rust-clippy/issues/702 diff --git a/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/securemessage.rs b/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/securemessage.rs index 161e0be..d83d137 100644 --- a/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/securemessage.rs +++ b/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/securemessage.rs @@ -13,7 +13,7 @@ // limitations under the License. // This file is generated by rust-protobuf 3.2.0. Do not edit -// .proto file is parsed by protoc 3.19.1 +// .proto file is parsed by protoc 3.21.12 // @generated // https://github.com/rust-lang/rust-clippy/issues/702 diff --git a/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/ukey.rs b/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/ukey.rs index 5370207..9be6b3d 100644 --- a/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/ukey.rs +++ b/nearby/connections/ukey2/ukey2_proto/src/ukey2_all_proto/ukey.rs @@ -13,7 +13,7 @@ // limitations under the License. // This file is generated by rust-protobuf 3.2.0. Do not edit -// .proto file is parsed by protoc 3.19.1 +// .proto file is parsed by protoc 3.21.12 // @generated // https://github.com/rust-lang/rust-clippy/issues/702 diff --git a/nearby/connections/ukey2/ukey2_shell/Cargo.toml b/nearby/connections/ukey2/ukey2_shell/Cargo.toml index 9a2856d..2ac12fa 100644 --- a/nearby/connections/ukey2/ukey2_shell/Cargo.toml +++ b/nearby/connections/ukey2/ukey2_shell/Cargo.toml @@ -11,4 +11,4 @@ workspace = true crypto_provider_rustcrypto = { workspace = true, features = [ "alloc" ] } ukey2_rs = { version = "0.1.0", path = "../ukey2" } ukey2_connections = { version = "0.1.0", path = "../ukey2_connections" } -clap = { version = "4.0.17", default-features = false, features = ["std", "derive"] } +clap = { workspace = true, features = ["std", "derive"] } |