@@ -90,6 +90,19 @@ struct NetworkContext
90
90
*/
91
91
static int32_t opensslError ( void );
92
92
93
+ /**
94
+ * @brief Load a certificate with the given PKCS#11 URI and return the resulting openssl X509 object.
95
+ *
96
+ * @param[out] ppX509Cert Location to store a pointer to the created X509 certificate object.
97
+ * @param[in] pEngine Pointer to the pre-initialized openssl PKCS11 engine.
98
+ * @param[in] pCertURI PKCS#11 URI for the desired certificate.
99
+ *
100
+ * @return 1 on success; -1, 0 on failure.
101
+ */
102
+ static int32_t loadCertificateFromPkcs11 ( X509 * * ppX509Cert ,
103
+ ENGINE * pEngine ,
104
+ const char * pCertURI );
105
+
93
106
/**
94
107
* @brief Add X509 certificate from a file to the trusted list of root certificates.
95
108
*
@@ -168,17 +181,10 @@ static int32_t setPrivateKeyFromPkcs11( SSL_CTX * pSslContext,
168
181
* @brief Initialize the openssl pkcs11 engine.
169
182
*
170
183
* @param[out] ppEngine Pointer to write the resulting ENGINE object pointer to.
171
- * @param[in] pP11ModulePath String containing the path to the PKCS11 module.
172
- * @param[in] pP11ModulePin String containing the pin code (if needed).
173
- *
174
- * The pP11ModulePath and pP11ModulePin parameters may be NULL if spcified
175
- * in the relevant URI or openssl configuration file.
176
184
*
177
185
* @return 1 on success; 0 on failure.
178
186
*/
179
- static int32_t initializePkcs11Engine ( ENGINE * * ppEngine ,
180
- const char * pP11ModulePath ,
181
- const char * pP11ModulePin );
187
+ static int32_t initializePkcs11Engine ( ENGINE * * ppEngine );
182
188
183
189
/**
184
190
* @brief Passes TLS credentials to the OpenSSL library.
@@ -690,9 +696,7 @@ static int32_t opensslError( void )
690
696
}
691
697
692
698
/*-----------------------------------------------------------*/
693
- static int32_t initializePkcs11Engine ( ENGINE * * ppEngine ,
694
- const char * pP11ModulePath ,
695
- const char * pP11ModulePin )
699
+ static int32_t initializePkcs11Engine ( ENGINE * * ppEngine )
696
700
{
697
701
int32_t sslStatus = 1 ;
698
702
ENGINE * pEngine = NULL ;
@@ -713,23 +717,13 @@ static int32_t initializePkcs11Engine( ENGINE ** ppEngine,
713
717
/* Increase log level if necessary */
714
718
#if LIBRARY_LOG_LEVEL >= LOG_INFO
715
719
if ( ( sslStatus == 1 ) &&
716
- ( ENGINE_ctrl_cmd_string (engine , "VERBOSE" , NULL , 0 ) != 1 ) )
720
+ ( ENGINE_ctrl_cmd_string (pEngine , "VERBOSE" , NULL , 0 ) != 1 ) )
717
721
{
718
722
LogError ( ( "Failed to increment the pkcs11 engine verbosity level." ) );
719
723
sslStatus = opensslError ();
720
724
}
721
725
#endif
722
726
723
- /* Set module path if specified */
724
- if ( sslStatus == 1 && pP11ModulePath != NULL )
725
- {
726
- if ( ENGINE_ctrl_cmd_string ( pEngine , "MODULE_PATH" , pP11ModulePath , 0 ) != 1 )
727
- {
728
- LogError ( ( "Failed to set the pkcs11 module path: %s." , pP11ModulePath ) );
729
- sslStatus = opensslError ();
730
- }
731
- }
732
-
733
727
if ( sslStatus == 1 )
734
728
{
735
729
/* Initialize the pkcs11 engine and acquire a functional reference to it */
@@ -740,16 +734,6 @@ static int32_t initializePkcs11Engine( ENGINE ** ppEngine,
740
734
}
741
735
}
742
736
743
- /* Unlock with pin code if specified */
744
- if ( sslStatus == 1 && pP11ModulePin != NULL )
745
- {
746
- if ( ENGINE_ctrl_cmd_string ( pEngine , "PIN" , pP11ModulePin , 0 ) != 1 )
747
- {
748
- LogError ( ( "Failed to unlock the pkcs11 module with the given pin code." ) );
749
- sslStatus = opensslError ();
750
- }
751
- }
752
-
753
737
if ( sslStatus == 1 )
754
738
{
755
739
* ppEngine = pEngine ;
@@ -799,9 +783,7 @@ static int32_t setCredentials( SSL_CTX * pSslContext,
799
783
800
784
if ( pkeyFromP11 == true || certFromP11 == true || rootCaFromP11 == true )
801
785
{
802
- sslStatus = initializePkcs11Engine ( & pEngine ,
803
- pOpensslCredentials -> pP11ModulePath ,
804
- pOpensslCredentials -> pP11ModulePin );
786
+ sslStatus = initializePkcs11Engine ( & pEngine );
805
787
}
806
788
}
807
789
0 commit comments