Skip to content

Commit 6abe872

Browse files
committed
Merge branch 'dev-E2EE-2407' into 'master'
feat(E2EE-2407): Add support of PrehashedAndEncryptedPassphrase in Enroll API See merge request TankerHQ/sdk-rust!188
2 parents ebc749b + c669234 commit 6abe872

File tree

6 files changed

+643
-369
lines changed

6 files changed

+643
-369
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[flake8]
22
max-line-length=100
3-
ignore=D100, D101, D102, D103, D104, D105, D107, D400, E731
3+
ignore=D100, D101, D102, D103, D104, D105, D107, D400, E731, W503
44

55
exclude =
66
build

poetry.lock

Lines changed: 577 additions & 338 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package-mode = false
88
[tool.poetry.dependencies]
99
python = "^3.12"
1010

11-
tankerci = { version = "== 2024.4.5183", source = "gitlab" }
11+
tankerci = { version = "== 2024.12.5467", source = "gitlab" }
1212

1313
[tool.poetry.dev-dependencies]
1414
black = "24.3.0"

run-ci.py

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def get_android_bin_path() -> Path:
110110

111111

112112
def bind_gen(
113-
*, header_source: Path, output_file: Path, include_path: Path, dynamic_loading: bool
113+
*, header_source: Path, output_file: Path, include_path: Path, dynamic_loading: bool
114114
) -> None:
115115
args = []
116116
if dynamic_loading:
@@ -133,7 +133,7 @@ def bind_gen(
133133

134134
class Builder:
135135
def __init__(
136-
self, *, src_path: Path, build_profile: Profile, host_profile: Profile
136+
self, *, src_path: Path, build_profile: Profile, host_profile: Profile
137137
):
138138
self.src_path = src_path
139139
self.host_profile = host_profile
@@ -187,7 +187,9 @@ def _copy_includes(self, package_path: Path, depsConfig: DepsConfig) -> None:
187187
# This is necessary on 64bit android archs, as Clang doesn't build them by default,
188188
# and Google's NDK distribution doesn't take care of that either...
189189
@staticmethod
190-
def _armerge_soft_float128_compiler_rt_builtins(compiler_rt_lib: Path, output_path: Path, env: dict[str, str]):
190+
def _armerge_soft_float128_compiler_rt_builtins(
191+
compiler_rt_lib: Path, output_path: Path, env: dict[str, str]
192+
) -> None:
191193
f128_builtins = [
192194
"__addtf3",
193195
"__subtf3",
@@ -230,7 +232,7 @@ def _armerge_soft_float128_compiler_rt_builtins(compiler_rt_lib: Path, output_pa
230232
"__multc3",
231233
"__divtc3",
232234
]
233-
keep_symbol_args = [e for sym_name in f128_builtins for e in ['-k', sym_name]]
235+
keep_symbol_args = [e for sym_name in f128_builtins for e in ["-k", sym_name]]
234236

235237
tankerci.run(
236238
"armerge",
@@ -243,7 +245,7 @@ def _armerge_soft_float128_compiler_rt_builtins(compiler_rt_lib: Path, output_pa
243245
)
244246

245247
def _merge_all_libs(
246-
self, depsConfig: DepsConfig, package_path: Path, native_path: Path
248+
self, depsConfig: DepsConfig, package_path: Path, native_path: Path
247249
) -> None:
248250
with tankerci.working_directory(package_path):
249251
env = os.environ.copy()
@@ -266,18 +268,28 @@ def _merge_all_libs(
266268
ndk_arch = NDK_ARCH_TARGETS[self.arch]
267269
android_lib_path = android_bin_path / f"../sysroot/usr/lib/{ndk_arch}"
268270

269-
# Starting with NDK r23, Google in its infinite wisdom has decided to make things more interesting
271+
# Starting with NDK r23, Google in its infinite wisdom has decided to make things
272+
# more interesting
270273
# libgcc is gone, and now we use clang's libcxx and compiler-rt.
271-
# Unfortunately, the libcxx_static.a is currently missing soft float128 builtins for 64bit archs
272-
# (See https://reviews.llvm.org/D53608 and https://github.com/llvm/llvm-project/issues/51395)
274+
# Unfortunately, the libcxx_static.a is currently missing soft float128 builtins
275+
# for 64bit archs (See https://reviews.llvm.org/D53608 and
276+
# https://github.com/llvm/llvm-project/issues/51395)
273277
# It is possible to find those symbols in the separate libclang_rt.builtins libs
274-
# However, we can't pull in all of rt.builtins, or we will have duplicate symbols and fail linking
275-
if self.arch in ['x86_64', 'armv8']:
278+
# However, we can't pull in all of rt.builtins, or we will have duplicate symbols
279+
# and fail linking
280+
if self.arch in ["x86_64", "armv8"]:
276281
compiler_rt_arch = CLANG_RT_ARCH_TARGETS[self.arch]
277-
compiler_rt_dir = android_bin_path / f"../lib/clang/17/lib/linux/"
278-
compiler_rt_lib = compiler_rt_dir / f"libclang_rt.builtins-{compiler_rt_arch}.a"
279-
out_path = cxx_package_libs / f"libclang_rt.builtins.float128-{compiler_rt_arch}.a"
280-
self._armerge_soft_float128_compiler_rt_builtins(compiler_rt_lib, out_path, env)
282+
compiler_rt_dir = android_bin_path / "../lib/clang/17/lib/linux/"
283+
compiler_rt_lib = (
284+
compiler_rt_dir / f"libclang_rt.builtins-{compiler_rt_arch}.a"
285+
)
286+
out_path = (
287+
cxx_package_libs
288+
/ f"libclang_rt.builtins.float128-{compiler_rt_arch}.a"
289+
)
290+
self._armerge_soft_float128_compiler_rt_builtins(
291+
compiler_rt_lib, out_path, env
292+
)
281293

282294
for lib in android_lib_path.glob("*.a"):
283295
# Rust already links some (non-C++) NDK libs, skip to avoid duplicate symbols
@@ -374,10 +386,10 @@ def _prepare_profile(self) -> None:
374386
shutil.copyfile(native_path / "ctanker.rs", mingw_path / "ctanker.rs")
375387

376388
def prepare(
377-
self,
378-
update: bool,
379-
tanker_source: TankerSource,
380-
tanker_ref: Optional[str] = None,
389+
self,
390+
update: bool,
391+
tanker_source: TankerSource,
392+
tanker_ref: Optional[str] = None,
381393
) -> None:
382394
tanker_deployed_ref = tanker_ref
383395
if tanker_source == TankerSource.DEPLOYED and not tanker_ref:
@@ -469,11 +481,11 @@ def test(self) -> None:
469481

470482

471483
def prepare(
472-
tanker_source: TankerSource,
473-
*,
474-
profiles: List[Profile],
475-
update: bool = False,
476-
tanker_ref: Optional[str] = None,
484+
tanker_source: TankerSource,
485+
*,
486+
profiles: List[Profile],
487+
update: bool = False,
488+
tanker_ref: Optional[str] = None,
477489
) -> None:
478490
build_profile = tankerci.conan.get_build_profile()
479491
for host_profile in profiles:
@@ -484,9 +496,9 @@ def prepare(
484496

485497

486498
def build(
487-
*,
488-
profiles: List[Profile],
489-
test: bool = False,
499+
*,
500+
profiles: List[Profile],
501+
test: bool = False,
490502
) -> None:
491503
build_profile = tankerci.conan.get_build_profile()
492504
if os.environ.get("CI"):
@@ -591,7 +603,7 @@ def main() -> None:
591603
if args.command == "build":
592604
profiles = [Profile(p) for p in args.profiles]
593605
with tankerci.conan.ConanContextManager(
594-
[args.remote, "conancenter"], conan_home=user_home
606+
[args.remote, "conancenter"], conan_home=user_home
595607
):
596608
build(
597609
profiles=profiles,
@@ -601,7 +613,7 @@ def main() -> None:
601613
deploy(args)
602614
elif args.command == "prepare":
603615
with tankerci.conan.ConanContextManager(
604-
[args.remote, "conancenter"], conan_home=user_home
616+
[args.remote, "conancenter"], conan_home=user_home
605617
):
606618
profiles = [Profile(p) for p in args.profiles]
607619
prepare(

src/verification.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::ctanker::{
44
};
55
use std::ffi::CString;
66

7-
const CVERIFICATION_VERSION: u8 = 8;
7+
const CVERIFICATION_VERSION: u8 = 9;
88
const CEMAIL_VERIFICATION_VERSION: u8 = 1;
99
const CPHONE_NUMBER_VERIFICATION_VERSION: u8 = 1;
1010
const CPREVERIFIED_OIDC_VERIFICATION_VERSION: u8 = 1;
@@ -23,6 +23,7 @@ enum Type {
2323
E2ePassphrase = 8,
2424
PreverifiedOIDC = 9,
2525
OIDCAuthorizationCode = 10,
26+
PrehashedAndEncryptedPassphrase = 11,
2627
}
2728

2829
pub(crate) struct CVerificationWrapper {
@@ -68,6 +69,7 @@ impl CVerificationWrapper {
6869
authorization_code: std::ptr::null(),
6970
state: std::ptr::null(),
7071
},
72+
prehashed_and_encrypted_passphrase: std::ptr::null(),
7173
},
7274
}
7375
}
@@ -166,6 +168,19 @@ impl CVerificationWrapper {
166168
wrapper
167169
}
168170

171+
pub(self) fn with_prehashed_and_encrypted_passphrase(
172+
prehashed_and_encrypted_passphrase: &str,
173+
) -> Self {
174+
let mut wrapper = Self::new();
175+
let cpaep = CString::new(prehashed_and_encrypted_passphrase).unwrap();
176+
177+
wrapper.cverif.verification_method_type = Type::PrehashedAndEncryptedPassphrase as u8;
178+
wrapper.cverif.prehashed_and_encrypted_passphrase = cpaep.as_ptr();
179+
180+
wrapper.cstrings.push(cpaep);
181+
wrapper
182+
}
183+
169184
pub(self) fn with_preverifed_oidc(subject: &str, provider_id: &str) -> Self {
170185
let mut wrapper = Self::new();
171186
let csubject = CString::new(subject).unwrap();
@@ -240,6 +255,7 @@ pub enum Verification {
240255
authorization_code: String,
241256
state: String,
242257
},
258+
PrehashedAndEncryptedPassphrase(String),
243259
}
244260

245261
impl Verification {
@@ -281,6 +297,11 @@ impl Verification {
281297
authorization_code,
282298
state,
283299
),
300+
Verification::PrehashedAndEncryptedPassphrase(prehashed_and_encrypted_passphrase) => {
301+
CVerificationWrapper::with_prehashed_and_encrypted_passphrase(
302+
prehashed_and_encrypted_passphrase,
303+
)
304+
}
284305
}
285306
}
286307
}

src/verification_methods.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub enum VerificationMethod {
2525
E2ePassphrase,
2626
// PreverifiedOIDC is not exposed as a VerificationMethod
2727
// OIDCAuthorizationCode is not exposed as a VerificationMethod
28+
// PrehashedAndEncryptedPassphrase is not exposed as a VerificationMethod
2829
}
2930

3031
#[derive(FromPrimitive)]
@@ -42,6 +43,7 @@ enum CMethodType {
4243
E2ePassphrase = 8,
4344
// PreverifiedOIDC = 9, PreverifiedOIDC is not exposed as a VerificationMethod
4445
// OIDCAuthorizationCode = 10, OIDCAuthorizationCode is not exposed as a VerificationMethod
46+
// PrehashedAndEncryptedPassphrase = 11, PrehashedAndEncryptedPassphraseis not exposed as a VerificationMethod
4547
#[num_enum(default)]
4648
Invalid,
4749
}

0 commit comments

Comments
 (0)