Skip to content

Commit f2c1066

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into autoconf-fixes
2 parents 6bf8cc5 + a8cabf5 commit f2c1066

File tree

11 files changed

+166
-18
lines changed

11 files changed

+166
-18
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @softhsm/core

.github/workflows/ci.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- master
8+
pull_request:
9+
10+
jobs:
11+
linux:
12+
name: Linux (${{ matrix.backend }})
13+
runs-on: ubuntu-20.04 # for OpenSSL 1.1.1
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- backend: openssl
19+
- backend: botan
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Prepare
23+
run: |
24+
sudo apt update -qq
25+
sudo apt install libcppunit-dev libbotan-2-dev p11-kit
26+
- name: Build
27+
run: |
28+
./autogen.sh
29+
./configure --with-crypto-backend=${{ matrix.backend }}
30+
make
31+
- name: Test
32+
run: |
33+
make check || (find . -name test-suite.log -exec cat {} \; && false)
34+
35+
macos:
36+
name: macOS (${{ matrix.backend }})
37+
runs-on: macos-14
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
include:
42+
- backend: openssl
43+
extra-options: --with-openssl=$(brew --prefix [email protected])
44+
- backend: botan
45+
extra-options: --with-botan=$(brew --prefix botan@2)
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: Prepare
49+
run: |
50+
brew install automake libtool cppunit botan@2
51+
- name: Build
52+
run: |
53+
./autogen.sh
54+
./configure --with-crypto-backend=${{ matrix.backend }} ${{ matrix.extra-options }}
55+
make
56+
- name: Test
57+
run: |
58+
make check || (find . -name test-suite.log -exec cat {} \; && false)
59+
60+
windows:
61+
name: Windows (${{ matrix.arch }}, ${{ matrix.backend }})
62+
runs-on: windows-2022
63+
strategy:
64+
fail-fast: false
65+
matrix:
66+
include:
67+
- arch: x64
68+
backend: openssl
69+
target-platform: x64
70+
build-options:
71+
- arch: x64
72+
backend: botan
73+
target-platform: x64
74+
build-options: -DENABLE_ECC=OFF -DENABLE_EDDSA=OFF
75+
- arch: x86
76+
backend: openssl
77+
target-platform: Win32
78+
build-options: -DENABLE_ECC=OFF -DENABLE_EDDSA=OFF
79+
steps:
80+
- uses: actions/checkout@v4
81+
- uses: ilammy/msvc-dev-cmd@v1
82+
with:
83+
arch: ${{ matrix.arch }}
84+
- name: Create vcpkg.json
85+
run: >
86+
echo '{ "dependencies": [ "openssl", "botan", "cppunit" ],
87+
"overrides": [ { "name": "openssl", "version-string": "1.1.1n" },
88+
{ "name": "botan", "version-string": "2.19.3" } ],
89+
"builtin-baseline": "38d1652f152d36481f2f4e8a85c0f1e14f3769f7" }' > vcpkg.json
90+
- uses: seanmiddleditch/vcpkg-action@master
91+
id: vcpkg
92+
with:
93+
manifest-dir: ${{ github.workspace }}
94+
triplet: ${{ matrix.arch }}-windows
95+
token: ${{ github.token }}
96+
- name: Build
97+
run: |
98+
mkdir build
99+
cmake -B build ${{ steps.vcpkg.outputs.vcpkg-cmake-config }} -A ${{ matrix.target-platform }} -DWITH_CRYPTO_BACKEND=${{ matrix.backend }} ${{ matrix.build-options }} -DDISABLE_NON_PAGED_MEMORY=ON -DBUILD_TESTS=ON
100+
cmake --build build
101+
- name: Test
102+
env:
103+
CTEST_OUTPUT_ON_FAILURE: 1
104+
run: |
105+
cmake --build build --target RUN_TESTS

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ set(DEFAULT_LOG_LEVEL "INFO"
5050
CACHE STRING "The default log level")
5151
set(DEFAULT_OBJECTSTORE_BACKEND "file"
5252
CACHE STRING "Default storage backend for token objects")
53-
set(DEFAULT_PKCS11_LIB "${CMAKE_INSTALL_FULL_LIBDIR}/softhsm/libsofthsm2.so"
53+
set(DEFAULT_PKCS11_LIB "${CMAKE_INSTALL_FULL_LIBDIR}/softhsm/libsofthsm2${CMAKE_SHARED_LIBRARY_SUFFIX}"
5454
CACHE STRING "The default PKCS#11 library")
5555
set(DEFAULT_SOFTHSM2_CONF "${CMAKE_INSTALL_FULL_SYSCONFDIR}/softhsm2.conf"
5656
CACHE STRING "The default location of softhsm.conf")

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ The unit tests requires CppUnit.
6464
If the code is downloaded directly from the code repository, you have to
6565
prepare the configuration scripts before continuing.
6666

67-
1. You need to install automake, autoconf, libtool, libtool-ltdl-devel (RHEL/CentOS), pkg-config.
67+
1. You need to install automake, autoconf, libtool, libtool-ltdl-devel (RHEL/CentOS/Fedora), pkg-config.
6868
2. Run the command 'sh autogen.sh'
6969

7070
### Configure
@@ -113,18 +113,18 @@ Running the unit tests requires CppUnit.
113113

114114
### Install Library
115115

116-
Install the library using the follow command:
116+
Install the library using the following command:
117117

118118
sudo make install
119119

120120
### Configure
121121

122122
The default location of the config file is /etc/softhsm2.conf. This location
123-
can be change by setting the environment variable.
123+
can be changed by setting the SOFTHSM2\_CONF environment variable.
124124

125125
export SOFTHSM2_CONF=/home/user/config.file
126126

127-
Details on the configuration can be found in "man softhsm2.conf".
127+
Details on the configuration can be found through command "man softhsm2.conf".
128128

129129
Create the token directory you defined in your config file:
130130

src/lib/SoftHSM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ CK_RV SoftHSM::C_Initialize(CK_VOID_PTR pInitArgs)
597597
}
598598

599599
// Load the enabled list of algorithms
600-
prepareSupportedMecahnisms(mechanisms_table);
600+
prepareSupportedMechanisms(mechanisms_table);
601601

602602
isRemovable = Configuration::i()->getBool("slots.removable", false);
603603

@@ -720,7 +720,7 @@ CK_RV SoftHSM::C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo)
720720
return token->getTokenInfo(pInfo);
721721
}
722722

723-
void SoftHSM::prepareSupportedMecahnisms(std::map<std::string, CK_MECHANISM_TYPE> &t)
723+
void SoftHSM::prepareSupportedMechanisms(std::map<std::string, CK_MECHANISM_TYPE> &t)
724724
{
725725
#ifndef WITH_FIPS
726726
t["CKM_MD5"] = CKM_MD5;

src/lib/SoftHSM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ class SoftHSM
490490
CK_RV MechParamCheckRSAPKCSOAEP(CK_MECHANISM_PTR pMechanism);
491491

492492
bool isMechanismPermitted(OSObject* key, CK_MECHANISM_PTR pMechanism);
493-
void prepareSupportedMecahnisms(std::map<std::string, CK_MECHANISM_TYPE> &t);
493+
void prepareSupportedMechanisms(std::map<std::string, CK_MECHANISM_TYPE> &t);
494494
bool detectFork(void);
495495
};
496496

src/lib/crypto/BotanSymmetricAlgorithm.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,26 @@ bool BotanSymmetricAlgorithm::encryptInit(const SymmetricKey* key, const SymMode
169169
try
170170
{
171171
Botan::SymmetricKey botanKey = Botan::SymmetricKey(key->getKeyBits().const_byte_str(), key->getKeyBits().size());
172-
if (mode == SymMode::GCM)
172+
if (mode == SymMode::ECB)
173+
{
174+
// ECB cipher mode was dropped in Botan 2.0
175+
const std::vector<std::string> algo_parts = split_on_delim(cipherName, '/');
176+
const std::string cipher_name = algo_parts[0];
177+
bool with_pkcs7_padding;
178+
if (algo_parts.size() == 3 && algo_parts[2] == "PKCS7")
179+
{
180+
with_pkcs7_padding = true;
181+
}
182+
else
183+
{
184+
with_pkcs7_padding = false;
185+
}
186+
std::unique_ptr<Botan::BlockCipher> bc(Botan::BlockCipher::create(cipher_name));
187+
Botan::Keyed_Filter* cipher = new Botan::Cipher_Mode_Filter(new Botan::ECB_Encryption(bc.release(), with_pkcs7_padding));
188+
cipher->set_key(botanKey);
189+
cryption = new Botan::Pipe(cipher);
190+
}
191+
else if (mode == SymMode::GCM)
173192
{
174193
Botan::AEAD_Mode* aead = Botan::get_aead(cipherName, Botan::ENCRYPTION);
175194
aead->set_key(botanKey);
@@ -385,7 +404,26 @@ bool BotanSymmetricAlgorithm::decryptInit(const SymmetricKey* key, const SymMode
385404
try
386405
{
387406
Botan::SymmetricKey botanKey = Botan::SymmetricKey(key->getKeyBits().const_byte_str(), key->getKeyBits().size());
388-
if (mode == SymMode::GCM)
407+
if (mode == SymMode::ECB)
408+
{
409+
// ECB cipher mode was dropped in Botan 2.0
410+
const std::vector<std::string> algo_parts = split_on_delim(cipherName, '/');
411+
const std::string cipher_name = algo_parts[0];
412+
bool with_pkcs7_padding;
413+
if (algo_parts.size() == 3 && algo_parts[2] == "PKCS7")
414+
{
415+
with_pkcs7_padding = true;
416+
}
417+
else
418+
{
419+
with_pkcs7_padding = false;
420+
}
421+
std::unique_ptr<Botan::BlockCipher> bc(Botan::BlockCipher::create(cipher_name));
422+
Botan::Keyed_Filter* cipher = new Botan::Cipher_Mode_Filter(new Botan::ECB_Decryption(bc.release(),with_pkcs7_padding));
423+
cipher->set_key(botanKey);
424+
cryption = new Botan::Pipe(cipher);
425+
}
426+
else if (mode == SymMode::GCM)
389427
{
390428
Botan::AEAD_Mode* aead = Botan::get_aead(cipherName, Botan::DECRYPTION);
391429
aead->set_key(botanKey);

src/lib/crypto/Botan_ecb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Botan {
2222
/**
2323
* ECB mode
2424
*/
25-
class BOTAN_DLL ECB_Mode : public Cipher_Mode
25+
class ECB_Mode : public Cipher_Mode
2626
{
2727
public:
2828
std::string name() const override;
@@ -57,7 +57,7 @@ class BOTAN_DLL ECB_Mode : public Cipher_Mode
5757
/**
5858
* ECB Encryption
5959
*/
60-
class BOTAN_DLL ECB_Encryption final : public ECB_Mode
60+
class ECB_Encryption final : public ECB_Mode
6161
{
6262
public:
6363
/**
@@ -78,7 +78,7 @@ class BOTAN_DLL ECB_Encryption final : public ECB_Mode
7878
/**
7979
* ECB Decryption
8080
*/
81-
class BOTAN_DLL ECB_Decryption final : public ECB_Mode
81+
class ECB_Decryption final : public ECB_Mode
8282
{
8383
public:
8484
/**

src/lib/crypto/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ if(WITH_BOTAN)
9595
BotanDSAKeyPair.cpp
9696
BotanDSAPrivateKey.cpp
9797
BotanDSAPublicKey.cpp
98+
Botan_ecb.cpp
9899
BotanECDH.cpp
99100
BotanECDHKeyPair.cpp
100101
BotanECDHPrivateKey.cpp

src/lib/test/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@ set(SOURCES p11test.cpp
3232
add_executable(${PROJECT_NAME} ${SOURCES})
3333

3434
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
35-
list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/../win32/setenv.cpp ${PROJECT_SOURCE_DIR}/../win32/syslog.cpp)
35+
target_sources(${PROJECT_NAME} PRIVATE
36+
${PROJECT_SOURCE_DIR}/../win32/setenv.cpp
37+
${PROJECT_SOURCE_DIR}/../win32/syslog.cpp)
3638
list(APPEND COMPILE_OPTIONS "/DCRYPTOKI_STATIC")
3739
else()
38-
list(APPEND SOURCES "ForkTests.cpp")
40+
target_sources(${PROJECT_NAME} PRIVATE "ForkTests.cpp")
3941
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS -pthread)
4042
endif()
4143

4244
include_directories(${INCLUDE_DIRS})
4345

4446

4547
target_link_libraries(${PROJECT_NAME} softhsm2-static ${SQLITE3_LIBS} ${CPPUNIT_LIBRARIES})
46-
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS -pthread)
4748

4849
target_compile_options(${PROJECT_NAME} PRIVATE ${COMPILE_OPTIONS})
4950

0 commit comments

Comments
 (0)