-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for quirk no-operation-state. Signed-off-by: Florian Wernli <[email protected]>
- Loading branch information
Showing
5 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ jobs: | |
test-wrapper | ||
thkdf | ||
toaepsha2 | ||
top_state | ||
tpubkey | ||
trand | ||
trsapss | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* Copyright (C) 2022 Simo Sorce <[email protected]> | ||
SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <openssl/evp.h> | ||
#include <openssl/err.h> | ||
#include <openssl/provider.h> | ||
|
||
#define EXIT_TEST_SKIPPED 77 | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
const char *propq = "provider=pkcs11"; | ||
const char *digest = "sha256"; | ||
const char *provname; | ||
const OSSL_PROVIDER *pk11prov; | ||
|
||
EVP_MD *pk11md = EVP_MD_fetch(NULL, digest, propq); | ||
if (!pk11md) { | ||
fprintf(stderr, "%s: Unsupported by pkcs11 token\n", digest); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
pk11prov = EVP_MD_get0_provider(pk11md); | ||
provname = OSSL_PROVIDER_get0_name(pk11prov); | ||
|
||
if (strcmp(provname, "pkcs11") != 0) { | ||
fprintf(stderr, "%s: Not a pkcs11 method, provider=%s\n", digest, | ||
provname); | ||
EVP_MD_free(pk11md); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
EVP_MD_CTX *mdctx = EVP_MD_CTX_new(); | ||
EVP_DigestInit_ex(mdctx, pk11md, NULL); | ||
|
||
EVP_MD_CTX *mdctx_dup = EVP_MD_CTX_new(); | ||
EVP_MD_CTX_copy(mdctx_dup, mdctx); | ||
|
||
char error_string[2048]; | ||
ERR_error_string_n(ERR_peek_last_error(), error_string, | ||
sizeof error_string); | ||
printf("%s\n", error_string); | ||
|
||
EVP_MD_CTX_free(mdctx); | ||
EVP_MD_CTX_free(mdctx_dup); | ||
|
||
EVP_MD_free(pk11md); | ||
|
||
exit(EXIT_SUCCESS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash -e | ||
# Copyright (C) 2022 Simo Sorce <[email protected]> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
source "${TESTSSRCDIR}/helpers.sh" | ||
|
||
title PARA "OSSL error stack has error from failing C_Get/SetOperationState" | ||
# We need to configure early loading otherwise no digests are loaded, | ||
# and all checks are skipped | ||
sed "s/#pkcs11-module-load-behavior/pkcs11-module-load-behavior = early/" \ | ||
"${OPENSSL_CONF}" > "${OPENSSL_CONF}.op_state.early_load" | ||
OPENSSL_CONF=${OPENSSL_CONF}.op_state.early_load | ||
|
||
$CHECKER ./tdigest_dupctx | grep -e "error:.*:pkcs11::reason(84)" | ||
|
||
|
||
title PARA "No error is logged when quirk no-operation-state is enabled" | ||
sed "s/pkcs11-module-quirks = /pkcs11-module-quirks = no-operation-state /" \ | ||
"${OPENSSL_CONF}" > "${OPENSSL_CONF}.no_op_state" | ||
OPENSSL_CONF=${OPENSSL_CONF}.no_op_state | ||
|
||
title PARA "Test Digests support" | ||
$CHECKER ./tdigest_dupctx | grep -e "error:.*:lib(0)::reason(0)" | ||
|
||
exit 0 |