-
Notifications
You must be signed in to change notification settings - Fork 47
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.
- Loading branch information
Florian Wernli
committed
Dec 6, 2023
1 parent
b6f60aa
commit 14ab66f
Showing
4 changed files
with
93 additions
and
2 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
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,61 @@ | ||
/* Copyright (C) 2022 Simo Sorce <simo@redhat.com> | ||
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[]) | ||
{ | ||
unsigned char pk11out[EVP_MAX_MD_SIZE]; | ||
unsigned int pk11len; | ||
bool pk11_tested = false; | ||
const char *propq = "provider=pkcs11"; | ||
const char *digest = "sha256"; | ||
const char *data = "Digest This!"; | ||
const char *provname; | ||
const OSSL_PROVIDER *pk11prov; | ||
int ret; | ||
|
||
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); | ||
|
||
pk11_tested = true; | ||
|
||
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 <simo@redhat.com> | ||
# 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 |