Skip to content

Commit b29c6a5

Browse files
committed
Bumped secrecy crate from 0.8.0 to 0.10.3
- Modified cryptoki/Cargo.toml to bump version. - Added INSTALL_NOTES.md to start capturing installation notes for specific development environments. - Changed deprecated SecretVec<u8> to SecretBox<Vec<u8>>. - Grammar fixes. Signed-off-by: Todd Decker <ptdecker@mac.com>
1 parent 68813c6 commit b29c6a5

File tree

6 files changed

+121
-16
lines changed

6 files changed

+121
-16
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
*DS_Store
55
*.patch
66
*NVChip
7+
8+
#IDEs
79
.vscode
10+
.idea
11+
12+
#build artifacts
13+
cryptoki-sys/pkcs11-precompile.h

Cargo.lock

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

INSTALL_NOTES.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Installation Notes
2+
3+
Some rough notes for installing Cryptoki and the requisite SoftHSMv2 for testing
4+
5+
## MacOS Installation of Cryptoki crate and SoftHSMv2 for testing purposes
6+
7+
Below is a rough guide to the installation flow for Cryptoki and for the required SoftHSMv2 dependency to support the
8+
execution of the Cryptoki test suite where Homebrew is used as the package manager. These are rough notes developed
9+
on macOS Sequoia 15.5 with Homebrew 4.5.6 on a Macbook M1 Pro with a bash shell
10+
(version 5.2.37(1)-release (aarch64-apple-darwin24.2.0)).
11+
12+
## SoftHSMv2 Installation
13+
14+
SoftHSMv2 is required for Cryptoki test suite execution. Below are the rough steps required to install, build, and
15+
check SoftHWMv2 on macOS using Homebrew. Some hoops were jumped through to manually disable DES tests which were causing
16+
issue. The result was a clean make check excepting some PKCS#11 DES check failures.
17+
18+
> *NOTE* The `--pin` and `--so-pin` values are hard coded in the Cryptoki test suite to the values used below.
19+
20+
```bash
21+
$ cd ~/code
22+
$ gh repo clone softhsm/SoftHSMv2
23+
$ brew install automake cppunit
24+
$ brew reinstall autoconf automake
25+
$ export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/cppunit/include"
26+
$ export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib -L/opt/homebrew/opt/cppunit/lib"
27+
$ mkdir -p ~/softhsm2/tokens
28+
$ echo "directories.tokendir = $HOME/softhsm2/tokens" > ~/softhsm2/softhsm2.conf
29+
$ export SOFTHSM2_CONF=$HOME/softhsm2/softhsm2.conf
30+
$ ./src/bin/util/softhsm2-util --init-token --slot 0 --label "TestToken" --so-pin abcdef --pin fedcba --module ./src/lib/.libs/libsofthsm2.so
31+
$ vi openssl.cnf
32+
```
33+
34+
Create an openssl.cnf file with the following contents:
35+
36+
```ini
37+
openssl_conf = openssl_init
38+
39+
[openssl_init]
40+
providers = provider_sect
41+
42+
[provider_sect]
43+
default = default_sect
44+
legacy = legacy_sect
45+
46+
[default_sect]
47+
activate = 1
48+
49+
[legacy_sect]
50+
activate = 1
51+
```
52+
53+
Continuing...
54+
55+
```bash
56+
$ export OPENSSL_CONF=/full/path/to/openssl.cnf
57+
$ make distclean
58+
$ cd src/lib/crypto/test
59+
$ mv DESTests.cpp DESTests.cpp.disabled
60+
$ vi Makefile.am
61+
```
62+
63+
Remove the DESTests.cpp line.
64+
65+
Continuing...
66+
67+
```bash
68+
$ cd -
69+
$ autoreconf -fvi
70+
$ ./autogen.sh
71+
$ ./configure --with-crypto-backend=openssl --enable-des
72+
$ make clean
73+
$ make -j$(sysctl -n hw.ncpu)
74+
$ make check
75+
```
76+
77+
## Cryptoki Installation, Build, and Test
78+
79+
```bash
80+
$ cd ~/code
81+
$ gh repo clone parallaxsecond/rust-cryptoki
82+
$ cd rust-cryptoki/
83+
$ export TEST_PKCS11_MODULE=~/code/SoftHSMv2/src/lib/.libs/libsofthsm2.so
84+
$ cargo build
85+
$ cargo test
86+
```
87+
88+
## Resetting the SoftHSMv2 Configuration
89+
90+
If you need to reset the SoftHSM configuration (like to change a pin, slot, etc.) you can:
91+
92+
```bash
93+
$ rm -rf $HOME/softhsm2/
94+
$ echo "directories.tokendir = $HOME/softhsm2/tokens" > $HOME/softhsm2/softhsm2.conf
95+
$ export SOFTHSM2_CONF=$HOME/softhsm2/softhsm2.conf
96+
$ rm -rf $HOME/softhsm2/tokens
97+
$ mkdir -p $HOME/softhsm2/tokens
98+
$ ./src/bin/util/softhsm2-util --show-slots --module ./src/lib/.libs/libsofthsm2.so
99+
$ ./src/bin/util/softhsm2-util --init-token --slot 0 --label "TestToken" --so-pin abcdef --pin fedcba --module ./src/lib/.libs/libsofthsm2.so
100+
```

cryptoki/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ libloading = "0.8.6"
1818
log = "0.4.14"
1919
cryptoki-sys = { path = "../cryptoki-sys", version = "0.4.0" }
2020
paste = "1.0.6"
21-
secrecy = "0.8.0"
21+
secrecy = "0.10.3"
2222

2323
[dev-dependencies]
2424
num-traits = "0.2.14"

cryptoki/src/session/session_management.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ impl Session {
6262
}
6363

6464
/// Logs a session in using a slice of raw bytes as a PIN. Some dongle drivers allow
65-
/// non UTF-8 characters in the PIN and as a result, we aren't guaranteed that we can
66-
/// pass in a UTF-8 string to login. Therefore, it's useful to be able to pass in raw bytes
65+
/// non UTF-8 characters in the PIN and, as a result, we aren't guaranteed that we can
66+
/// pass in a UTF-8 string to `login`. Therefore, it's useful to be able to pass in raw bytes
6767
/// rather than convert a UTF-8 string to bytes.
6868
///
6969
/// # Arguments

cryptoki/src/types.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
55
use crate::error::{Error, Result};
66
use cryptoki_sys::*;
7-
use secrecy::SecretString;
8-
use secrecy::SecretVec;
7+
use secrecy::{SecretBox, SecretString};
98
use std::convert::TryFrom;
109
use std::convert::TryInto;
1110
use std::fmt::Formatter;
@@ -29,7 +28,7 @@ impl Date {
2928
///
3029
/// # Errors
3130
///
32-
/// If the lengths are invalid a `Error::InvalidValue` will be returned
31+
/// If the lengths are invalid, an `Error::InvalidValue` will be returned
3332
pub fn new_from_str_slice(year: &str, month: &str, day: &str) -> Result<Self> {
3433
if year.len() != 4 || month.len() != 2 || day.len() != 2 {
3534
Err(Error::InvalidValue)
@@ -222,22 +221,22 @@ impl From<CK_VERSION> for Version {
222221
/// A UTC datetime returned by a token's clock if present.
223222
#[derive(Copy, Clone, Debug)]
224223
pub struct UtcTime {
225-
/// **[Conformance](crate#conformance-notes):**
224+
/// **[Conformance](crate#conformance-notes): **
226225
/// Guaranteed to be in range 0..=9999
227226
pub year: u16,
228-
/// **[Conformance](crate#conformance-notes):**
227+
/// **[Conformance](crate#conformance-notes): **
229228
/// Guaranteed to be in range 0..=99
230229
pub month: u8,
231-
/// **[Conformance](crate#conformance-notes):**
230+
/// **[Conformance](crate#conformance-notes): **
232231
/// Guaranteed to be in range 0..=99
233232
pub day: u8,
234-
/// **[Conformance](crate#conformance-notes):**
233+
/// **[Conformance](crate#conformance-notes): **
235234
/// Guaranteed to be in range 0..=99
236235
pub hour: u8,
237-
/// **[Conformance](crate#conformance-notes):**
236+
/// **[Conformance](crate#conformance-notes): **
238237
/// Guaranteed to be in range 0..=99
239238
pub minute: u8,
240-
/// **[Conformance](crate#conformance-notes):**
239+
/// **[Conformance](crate#conformance-notes): **
241240
/// Guaranteed to be in range 0..=99
242241
pub second: u8,
243242
}
@@ -248,7 +247,7 @@ impl UtcTime {
248247
/// PKCS#11 and ISO are unrelated standards, and this function is provided
249248
/// only for convenience. ISO format is more widely recognized and parsable
250249
/// by various date/time utilities, while PKCS#11's internal representation
251-
/// of this type is is not used elsewhere.
250+
/// of this type is not used elsewhere.
252251
/// Other than formatting, this crate does not guarantee or enforce any part
253252
/// of the ISO standard.
254253
pub fn as_iso8601_string(&self) -> String {
@@ -281,7 +280,7 @@ pub type AuthPin = SecretString;
281280
/// Secret wrapper for a raw non UTF-8 Pin
282281
///
283282
/// Enable the `serde` feature to add support for Deserialize
284-
pub type RawAuthPin = SecretVec<u8>;
283+
pub type RawAuthPin = SecretBox<Vec<u8>>;
285284

286285
#[cfg(test)]
287286
mod test {

0 commit comments

Comments
 (0)