Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PKCS11 3.0 #183

Merged
merged 25 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
311dae1
Use PKCS11 3.0 headers
qpernil Jun 18, 2021
542aa52
Added files to be installed
qpernil Jun 18, 2021
bf03494
Basic PKCS11 3.0 support
qpernil Jun 21, 2021
8c7d783
Make function lists static
qpernil Jun 22, 2021
7df7fd7
Make function lists const
qpernil Jun 22, 2021
b5ae5f3
Refactored C_Login and C_LoginUser
qpernil Jun 24, 2021
d9bf622
Rebase fixes
qpernil Dec 9, 2021
09ede45
Rebase changes
qpernil Dec 22, 2021
11949ee
Support ed25519
qpernil Aug 16, 2022
34526ae
Fix attributes for ed25519 keys
qpernil Sep 30, 2022
078a0ae
ed25519 keys are considered 255 bits. Refactor getting CKA_EC_POINT s…
qpernil Sep 30, 2022
6e79dd6
pkc11 3.1
qpernil Oct 5, 2022
645928a
fix buffer_length check for EdDSA in util_pkcs11.c (#390)
marcwillert Feb 16, 2024
ce3834e
PKCS11: Rebase on current master
aveenismail May 16, 2024
a8bd9aa
PKCS11: Fix include for older OSs. Githubactions: Fix OpenSSL install…
aveenismail May 16, 2024
abab264
PKCS11: Compile ED25519 code only when OpenSSL is higher than 1.0. Bu…
aveenismail May 16, 2024
c19e753
PKCS11: Fix header inclusion in test
aveenismail May 16, 2024
77ba6c7
PKCS11: Update tests to use PKCS11_3 functionlist. Add test for PKCS1…
aveenismail May 22, 2024
a676bb4
PKCS11: Remove unnecessary KDF definitions
aveenismail May 22, 2024
49fc533
PKCS11: Fix PKCS11 interfaces test
aveenismail May 31, 2024
ceb6dfa
PKCS11_3: return CKR_PIN_INCORRECT when logging in with wrong password
aveenismail Jun 3, 2024
71bb386
Only C_GetInfo from 3.x function list returns 3.x cryptoki version
qpernil Jun 19, 2024
ce68338
PKCS11_3: Use snprintf instead of sprintf
aveenismail Jun 19, 2024
0af4448
PKCS11_3: Fix allocation of arrays
aveenismail Jun 19, 2024
64a013d
More usage of snprintf
qpernil Jun 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/build_and_test_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ jobs:
Set-PSDebug -Trace 1
$YHSHELL_SRC_DIR="$env:GITHUB_WORKSPACE\yubihsm-shell-"
$MERGEDPATH = Get-ChildItem "C:\Program Files*\Microsoft Visual Studio\*\Enterprise\VC\Redist\MSVC\v14*\MergeModules\Microsoft_VC*_CRT_$env:ARCH.msm"
echo "MERGEDPATH = $MERGEDPATH"
cd $YHSHELL_SRC_DIR/resources/release/win
./make_release_binaries.ps1 $env:ARCH_CMAKE C:/vcpkg
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ jobs:
set -x
tar xf yubihsm-shell-$VERSION.tar.gz
- name: Install dependecies
run: |
brew update
brew install cmake pkg-config gengetopt help2man
brew reinstall openssl@3
- name: Build and make MSI installer
env:
ARCH: ${{ matrix.arch }}
Expand Down
2 changes: 1 addition & 1 deletion cmake/SecurityFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
add_compile_options (-Wall -Wextra -Werror)
add_compile_options (-Wformat -Wformat-nonliteral -Wformat-security)
add_compile_options (-Wshadow)
add_compile_options (-Wcast-qual)
#add_compile_options (-Wcast-qual)
add_compile_options (-Wmissing-prototypes)
add_compile_options (-Wbad-function-cast)
add_compile_options (-pedantic -pedantic-errors)
Expand Down
2 changes: 1 addition & 1 deletion examples/p11_generate_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <stdlib.h>
#include <string.h>

#include <pkcs11.h>
#include <pkcs11y.h>

int main(int argc, char *argv[]) {
if (argc != 2) {
Expand Down
6 changes: 3 additions & 3 deletions lib/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ struct yh_connector {
void *backend;
struct backend_functions *bf;
yh_backend *connection;
char *status_url;
char *api_url;
char status_url[256];
char api_url[256];
bool has_device;
uint8_t version_major;
uint8_t version_minor;
uint8_t version_patch;
uint8_t address[32];
char address[32];
uint32_t port;
uint32_t pid;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/lib_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void parse_status_data(char *data, yh_connector *connector) {

connector->pid = pid;
} else if (strncmp(str, ADDRESS_STR, strlen(ADDRESS_STR)) == 0) {
strncpy((char *) connector->address, str + strlen(ADDRESS_STR),
strncpy(connector->address, str + strlen(ADDRESS_STR),
sizeof(connector->address) - 1);
} else if (strncmp(str, PORT_STR, strlen(PORT_STR)) == 0) {
char *endptr;
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/test_parsing.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void test_capabilities2(void) {
size_t len = 0;
for (size_t i = 0;
i < sizeof(capabilities_list) / sizeof(capabilities_list[0]); i++) {
sprintf(capabilities_string + len, "%s:", capabilities_list[i]);
snprintf(capabilities_string + len, sizeof(capabilities_string) - len, "%s:", capabilities_list[i]);
len += strlen(capabilities_list[i]) + 1;
}
capabilities_string[len - 1] = '\0';
Expand Down
18 changes: 9 additions & 9 deletions lib/tests/test_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ static void test_status(void) {
yh_connector c;
} tests[] = {
{"status=OK\nversion=1.2.3\n",
{NULL, NULL, NULL, NULL, NULL, true, 1, 2, 3, "", 0, 0}},
{"", {NULL, NULL, NULL, NULL, NULL, false, 0, 0, 0, "", 0, 0}},
{"foobar", {NULL, NULL, NULL, NULL, NULL, false, 0, 0, 0, "", 0, 0}},
{"\n\n\n\n\n\n", {NULL, NULL, NULL, NULL, NULL, false, 0, 0, 0, "", 0, 0}},
{NULL, NULL, NULL, {0}, {0}, true, 1, 2, 3, "", 0, 0}},
{"", {NULL, NULL, NULL, {0}, {0}, false, 0, 0, 0, "", 0, 0}},
{"foobar", {NULL, NULL, NULL, {0}, {0}, false, 0, 0, 0, "", 0, 0}},
{"\n\n\n\n\n\n", {NULL, NULL, NULL, {0}, {0}, false, 0, 0, 0, "", 0, 0}},
{"status=NO_DEVICE\nserial=*\nversion=1.0.2\npid=412\naddress=\nport=12345",
{NULL, NULL, NULL, NULL, NULL, false, 1, 0, 2, "", 12345, 412}},
{"version=1.2", {NULL, NULL, NULL, NULL, NULL, false, 1, 2, 0, "", 0, 0}},
{NULL, NULL, NULL, {0}, {0}, false, 1, 0, 2, "", 12345, 412}},
{"version=1.2", {NULL, NULL, NULL, {0}, {0}, false, 1, 2, 0, "", 0, 0}},
{"version=foobar",
{NULL, NULL, NULL, NULL, NULL, false, 0, 0, 0, "", 0, 0}},
{NULL, NULL, NULL, {0}, {0}, false, 0, 0, 0, "", 0, 0}},
{"version=2..\nstatus=OK",
{NULL, NULL, NULL, NULL, NULL, true, 2, 0, 0, "", 0, 0}},
{NULL, NULL, NULL, {0}, {0}, true, 2, 0, 0, "", 0, 0}},
};

for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
yh_connector c = {NULL, NULL, NULL, NULL, NULL, false, 0, 0, 0, "", 0, 0};
yh_connector c = {NULL, NULL, NULL, {0}, {0}, false, 0, 0, 0, "", 0, 0};
char *data = strdup(tests[i].data);

parse_status_data(data, &c);
Expand Down
52 changes: 8 additions & 44 deletions lib/yubihsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ yh_rc yh_get_connector_address(yh_connector *connector, char **const address) {
return YHR_INVALID_PARAMETERS;
}

*address = (char *) connector->address;
*address = connector->address;

return YHR_SUCCESS;
}
Expand Down Expand Up @@ -4305,31 +4305,11 @@ static yh_rc create_connector(yh_connector **connector, const char *url,
yh_rc rc = YHR_SUCCESS;

if (strncmp(url, YH_USB_URL_SCHEME, strlen(YH_USB_URL_SCHEME)) == 0) {
(*connector)->status_url = strdup(url);
if ((*connector)->status_url == NULL) {
rc = YHR_MEMORY_ERROR;
goto cc_failure;
}
(*connector)->api_url = strdup(url);
if ((*connector)->api_url == NULL) {
rc = YHR_MEMORY_ERROR;
goto cc_failure;
}
snprintf((*connector)->status_url, sizeof((*connector)->status_url), "%s", url);
snprintf((*connector)->api_url, sizeof((*connector)->api_url), "%s", url);
} else {
(*connector)->status_url =
calloc(1, strlen(url) + strlen(STATUS_ENDPOINT) + 1);
if ((*connector)->status_url == NULL) {
rc = YHR_MEMORY_ERROR;
goto cc_failure;
}
sprintf((*connector)->status_url, "%s%s", url, STATUS_ENDPOINT);

(*connector)->api_url = calloc(1, strlen(url) + strlen(API_ENDPOINT) + 1);
if ((*connector)->api_url == NULL) {
rc = YHR_MEMORY_ERROR;
goto cc_failure;
}
sprintf((*connector)->api_url, "%s%s", url, API_ENDPOINT);
snprintf((*connector)->status_url, sizeof((*connector)->status_url), "%s%s", url, STATUS_ENDPOINT);
snprintf((*connector)->api_url, sizeof((*connector)->api_url), "%s%s", url, API_ENDPOINT);
}

(*connector)->connection = bf->backend_create();
Expand All @@ -4344,15 +4324,6 @@ static yh_rc create_connector(yh_connector **connector, const char *url,
return YHR_SUCCESS;

cc_failure:
if ((*connector)->status_url) {
free((*connector)->status_url);
(*connector)->status_url = NULL;
}

if ((*connector)->api_url) {
free((*connector)->api_url);
(*connector)->api_url = NULL;
}

if (*connector) {
free(*connector);
Expand All @@ -4373,15 +4344,8 @@ static void destroy_connector(yh_connector *connector) {
connector->connection = NULL;
}

if (connector->status_url != NULL) {
free(connector->status_url);
connector->status_url = NULL;
}

if (connector->api_url != NULL) {
free(connector->api_url);
connector->api_url = NULL;
}
memset(connector->status_url, 0, sizeof(connector->status_url));
memset(connector->api_url, 0, sizeof(connector->api_url));

if (connector->bf) {
connector->bf->backend_cleanup();
Expand Down Expand Up @@ -4746,7 +4710,7 @@ yh_rc yh_get_key_bitlength(yh_algorithm algorithm, size_t *result) {
break;

case YH_ALGO_EC_ED25519:
*result = 256;
*result = 255;
break;

case YH_ALGO_HMAC_SHA1:
Expand Down
2 changes: 2 additions & 0 deletions pkcs11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ install(
LIBRARY DESTINATION "${YUBIHSM_INSTALL_LIB_DIR}/pkcs11"
RUNTIME DESTINATION "${YUBIHSM_INSTALL_BIN_DIR}/pkcs11")
install(FILES pkcs11.h DESTINATION "${YUBIHSM_INSTALL_INC_DIR}/pkcs11")
install(FILES pkcs11t.h DESTINATION "${YUBIHSM_INSTALL_INC_DIR}/pkcs11")
install(FILES pkcs11f.h DESTINATION "${YUBIHSM_INSTALL_INC_DIR}/pkcs11")
install(FILES pkcs11y.h DESTINATION "${YUBIHSM_INSTALL_INC_DIR}/pkcs11")

add_subdirectory (tests)
Loading
Loading