-
Notifications
You must be signed in to change notification settings - Fork 147
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
client and server tls UPDATE add pkcs11 engine support #454
Open
vkarpenk
wants to merge
1
commit into
CESNET:master
Choose a base branch
from
vkarpenk:pkcs11_sgx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
#include <openssl/ssl.h> | ||
#include <openssl/x509.h> | ||
#include <openssl/x509v3.h> | ||
#include <openssl/engine.h> | ||
|
||
#include "compat.h" | ||
#include "config.h" | ||
|
@@ -862,6 +863,9 @@ nc_tls_ctx_set_server_cert_key(SSL_CTX *tls_ctx, struct nc_server_tls_opts *opts | |
NC_PRIVKEY_FORMAT privkey_type; | ||
X509 *cert = NULL; | ||
EVP_PKEY *pkey = NULL; | ||
ENGINE *pkcs11 = NULL; | ||
const char* uri = getenv("TOKEN_KEY_URI"); | ||
const char* pin = getenv("DEFAULT_USER_PIN"); | ||
Comment on lines
+867
to
+868
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these standard variable names, and are they documented somewhere? |
||
|
||
NC_CHECK_ARG_RET(NULL, tls_ctx, opts, -1); | ||
|
||
|
@@ -896,12 +900,52 @@ nc_tls_ctx_set_server_cert_key(SSL_CTX *tls_ctx, struct nc_server_tls_opts *opts | |
goto cleanup; | ||
} | ||
|
||
/* load the private key */ | ||
pkey = base64der_to_privatekey(privkey_data, nc_privkey_format_to_str(privkey_type)); | ||
if (!pkey) { | ||
ERR(NULL, "Converting private key data to private key format failed."); | ||
ret = -1; | ||
goto cleanup; | ||
ENGINE_load_dynamic(); | ||
pkcs11 = ENGINE_by_id("pkcs11"); | ||
if (!pkcs11) | ||
{ | ||
/* load the private key */ | ||
pkey = base64der_to_privatekey(privkey_data, nc_privkey_format_to_str(privkey_type)); | ||
if (!pkey) { | ||
ERR(NULL, "Converting private key data to private key format failed."); | ||
ret = -1; | ||
goto cleanup; | ||
} | ||
} else { | ||
if (!uri) { | ||
ERR(NULL, "TOKEN_KEY_URI is not set. Loading private key using pkcs11 engine failed."); | ||
ret = -1; | ||
goto cleanup; | ||
} | ||
|
||
if (!pin) { | ||
ERR(NULL, "DEFAULT_USER_PIN is not set. Loading private key using pkcs11 engine failed."); | ||
ret = -1; | ||
goto cleanup; | ||
} | ||
|
||
if (!ENGINE_init(pkcs11)) | ||
{ | ||
ERR(NULL, "Initializing the pkcs11 engine failed (%s).", ERR_reason_error_string(ERR_get_error())); | ||
ret = -1; | ||
goto cleanup; | ||
} | ||
|
||
if (!ENGINE_ctrl_cmd_string(pkcs11, "PIN", pin, 0)) | ||
{ | ||
ERR(NULL, "Setting pin failed (%s).", ERR_reason_error_string(ERR_get_error())); | ||
ret = -1; | ||
goto cleanup; | ||
} | ||
|
||
/* load server key using pkcs11 engine*/ | ||
pkey = ENGINE_load_private_key(pkcs11, uri, NULL, NULL); | ||
if (!pkey) | ||
{ | ||
ERR(NULL, "Reading the private key failed (%s).", ERR_reason_error_string(ERR_get_error())); | ||
ret = -1; | ||
goto cleanup; | ||
} | ||
} | ||
|
||
/* set server key */ | ||
|
@@ -917,6 +961,9 @@ nc_tls_ctx_set_server_cert_key(SSL_CTX *tls_ctx, struct nc_server_tls_opts *opts | |
cleanup: | ||
X509_free(cert); | ||
EVP_PKEY_free(pkey); | ||
if (pkcs11) { | ||
ENGINE_free(pkcs11); | ||
} | ||
return ret; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a standard variable name used by other projects, and does it conform to how the OpenSSL API is "supposed to be used"? Where is the documentation?