Skip to content

Commit 96e62fe

Browse files
Update tpm ecdh
p256 used to provide a From implementation for AffinePoint to SharedSecret. We can recreate what it was doing using the AffineCoordinates trait. RustCrypto/elliptic-curves@a7011d2#diff-c6f073a6c542e656510c60595c86058a65f58dc3f00824c7f505cf6b556d3b73L49-L53
1 parent e20774d commit 96e62fe

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

.devcontainer/Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM mcr.microsoft.com/devcontainers/rust:1-bullseye
2+
3+
# Install required system packages
4+
RUN apt-get update && apt-get install -y \
5+
clang-11 \
6+
libclang-11-dev \
7+
llvm-11-dev \
8+
cmake \
9+
pkg-config \
10+
libssl-dev \
11+
tpm2-tss-dev \
12+
libtss2-dev \
13+
build-essential \
14+
curl \
15+
libcurl4-openssl-dev \
16+
make \
17+
sudo \
18+
&& apt-get clean \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
# Set environment variable so bindgen can find libclang
22+
ENV LIBCLANG_PATH=/usr/lib/llvm-11/lib
23+
24+
RUN apt-get install -y llvm-11-dev clang-11 libclang-11-dev
25+
RUN export LIBCLANG_PATH=/usr/lib/llvm-11/lib
26+
27+
28+
# Set up rust toolchain components
29+
RUN rustup target add x86_64-unknown-linux-gnu && \
30+
rustup component add clippy rustfmt rust-analyzer
31+
32+
# Create a non-root user
33+
ARG USERNAME=vscode
34+
ARG USER_UID=1000
35+
ARG USER_GID=$USER_UID
36+
37+
RUN groupadd --gid $USER_GID $USERNAME && \
38+
useradd --uid $USER_UID --gid $USER_GID -m $USERNAME && \
39+
echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME && \
40+
chmod 0440 /etc/sudoers.d/$USERNAME
41+
42+
USER $USERNAME
43+
44+
WORKDIR /app

.devcontainer/devcontainer.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "Rust Linux Development",
3+
"image": "mcr.microsoft.com/devcontainers/rust:1-bullseye",
4+
"features": {
5+
"ghcr.io/devcontainers/features/common-utils:2": {
6+
"installZsh": true,
7+
"username": "vscode",
8+
"upgradePackages": true
9+
}
10+
},
11+
"runArgs": [
12+
"--cap-add=SYS_PTRACE",
13+
"--security-opt",
14+
"seccomp=unconfined"
15+
],
16+
"customizations": {
17+
"vscode": {
18+
"extensions": [
19+
"rust-lang.rust-analyzer",
20+
"tamasfe.even-better-toml",
21+
"serayuzgur.crates"
22+
],
23+
"settings": {
24+
"rust-analyzer.server.path": "/usr/local/cargo/bin/rust-analyzer",
25+
"rust-analyzer.cargo.extraEnv": {
26+
"LIBCLANG_PATH": "/usr/lib/llvm-11/lib"
27+
},
28+
"rust-analyzer.server.extraEnv": {
29+
"LIBCLANG_PATH": "/usr/lib/llvm-11/lib"
30+
},
31+
"rust-analyzer.check.extraEnv": {
32+
"LIBCLANG_PATH": "/usr/lib/llvm-11/lib"
33+
}
34+
}
35+
}
36+
},
37+
"containerEnv": {
38+
"LIBCLANG_PATH": "/usr/lib/llvm-11/lib"
39+
},
40+
"postCreateCommand": "sudo apt-get update && sudo apt-get install -y pkg-config libtss2-dev libssl-dev libtss2-dev llvm-11-dev clang-11 libclang-11-dev && export LIBCLANG_PATH=/usr/lib/llvm-11/lib",
41+
"remoteUser": "vscode"
42+
}

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ rsa = { version = "0.4", optional = true, default-features = false, features = [
3535
"pem",
3636
] }
3737
ecc608-linux = { version = "0", optional = true }
38-
tss-esapi = { version = "7", optional = true }
38+
tss-esapi = { version = "7", optional = true, features = ["generate-bindings"] }
3939
libc = { version = "0", optional = true }
4040
byteorder = { version = "1", optional = true }
4141
multihash = { version = "0.18", optional = true }
@@ -44,7 +44,7 @@ solana-sdk = { version = ">= 2.2", optional = true }
4444
uuid = { version = "1", features = ["v4", "fast-rng"], optional = true }
4545

4646
[features]
47-
default = ["rsa"]
47+
default = ["rsa", "tpm"]
4848
ecc608 = ["ecc608-linux"]
4949
rsa = ["dep:rsa", "byteorder"]
5050
tpm = ["tss-esapi", "libc", "drop_guard"]

src/tpm/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ impl KeypairHandle {
101101
let encoded_point = p256::EncodedPoint::from_bytes(shared_secret_bytes.as_slice())
102102
.map_err(p256::elliptic_curve::Error::from)?;
103103
let affine_point = p256::AffinePoint::from_encoded_point(&encoded_point).unwrap();
104+
104105
Ok(ecc_compact::SharedSecret(p256::ecdh::SharedSecret::from(
105-
&affine_point,
106+
p256::elliptic_curve::point::AffineCoordinates::x(&affine_point),
106107
)))
107108
}
108109
}

0 commit comments

Comments
 (0)