@@ -187,6 +187,8 @@ CK_INTERFACE compat_interfaces[NUM_INTERFACES] = {
187
187
{"PKCS 11" , NULL , 0 }
188
188
};
189
189
190
+ CK_INTERFACE spy_interface = {"PKCS 11" , NULL , 0 };
191
+
190
192
/* Inits the spy. If successful, po != NULL */
191
193
static CK_RV
192
194
init_spy (void )
@@ -1610,22 +1612,24 @@ C_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, CK_VOID_PTR pRserved)
1610
1612
return retne (rv );
1611
1613
}
1612
1614
1613
- /* PKCS #11 3.0 functions */
1615
+ /* Returns spied PKCS #11 3.0 interface based on the interface version returned from the
1616
+ * underlying pkcs11 module, respecting major versions */
1614
1617
static void
1615
- spy_interface_function_list (CK_INTERFACE_PTR pInterface )
1618
+ spy_interface_function_list (CK_INTERFACE_PTR pInterface , CK_INTERFACE_PTR_PTR retInterface )
1616
1619
{
1617
1620
CK_VERSION * version ;
1618
1621
1619
1622
/* Do not touch unknown interfaces. We can not do anything with these */
1620
1623
if (strcmp (pInterface -> pInterfaceName , "PKCS 11" ) != 0 ) {
1624
+ * retInterface = pInterface ;
1621
1625
return ;
1622
1626
}
1623
1627
1624
1628
version = (CK_VERSION * )pInterface -> pFunctionList ;
1625
1629
if (version -> major == 2 ) {
1626
- pInterface -> pFunctionList = pkcs11_spy ;
1630
+ ( * retInterface ) -> pFunctionList = pkcs11_spy ;
1627
1631
} else if (version -> major == 3 && version -> minor == 0 ) {
1628
- pInterface -> pFunctionList = pkcs11_spy_3_0 ;
1632
+ ( * retInterface ) -> pFunctionList = pkcs11_spy_3_0 ;
1629
1633
}
1630
1634
}
1631
1635
@@ -1686,7 +1690,8 @@ C_GetInterfaceList(CK_INTERFACE_PTR pInterfacesList, CK_ULONG_PTR pulCount)
1686
1690
1687
1691
/* Now, replace function lists of known interfaces (PKCS 11, v 2.x and 3.0) */
1688
1692
for (i = 0 ; i < * pulCount ; i ++ ) {
1689
- spy_interface_function_list (& pInterfacesList [i ]);
1693
+ CK_INTERFACE_PTR pInterface = & pInterfacesList [i ];
1694
+ spy_interface_function_list (pInterface , & pInterface );
1690
1695
}
1691
1696
}
1692
1697
@@ -1726,10 +1731,12 @@ C_GetInterface(CK_UTF8CHAR_PTR pInterfaceName, CK_VERSION_PTR pVersion,
1726
1731
fprintf (spy_output , "[in] flags = %s\n" ,
1727
1732
(flags & CKF_INTERFACE_FORK_SAFE ? "CKF_INTERFACE_FORK_SAFE" : "" ));
1728
1733
if (po -> version .major >= 3 ) {
1734
+ CK_INTERFACE_PTR rInterface = NULL ;
1735
+
1729
1736
/* We can not assume the version we told the caller matches the version in the underlying
1730
1737
* pkcs11 module so map it back to the known ones */
1731
- CK_VERSION in_version ;
1732
1738
if ((pInterfaceName == NULL || strcmp ((char * )pInterfaceName , "PKCS 11" ) == 0 ) && pVersion ) {
1739
+ CK_VERSION in_version ;
1733
1740
for (unsigned long i = 0 ; i < num_orig_interfaces ; i ++ ) {
1734
1741
CK_VERSION * v = (CK_VERSION * )orig_interfaces [i ].pFunctionList ;
1735
1742
/* We found the same major version. Copy the minor and call it a day */
@@ -1745,9 +1752,10 @@ C_GetInterface(CK_UTF8CHAR_PTR pInterfaceName, CK_VERSION_PTR pVersion,
1745
1752
/* If not found, see what we will get */
1746
1753
}
1747
1754
1748
- rv = po -> C_GetInterface (pInterfaceName , pVersion , ppInterface , flags );
1749
- if (rv == CKR_OK && ppInterface != NULL ) {
1750
- spy_interface_function_list (* ppInterface );
1755
+ rv = po -> C_GetInterface (pInterfaceName , pVersion , & rInterface , flags );
1756
+ if (rv == CKR_OK && rInterface != NULL ) {
1757
+ * ppInterface = & spy_interface ;
1758
+ spy_interface_function_list (rInterface , ppInterface );
1751
1759
}
1752
1760
} else {
1753
1761
if ((pInterfaceName == NULL_PTR || strcmp ((char * )pInterfaceName , "PKCS 11" ) == 0 ) &&
0 commit comments