@@ -1757,6 +1757,69 @@ void ObjectTests::testDefaultRSAPubAttributes()
17571757 checkCommonRSAPublicKeyAttributes (hSession, hObject, pN, sizeof (pN), 512 , pE, sizeof (pE));
17581758}
17591759
1760+ void ObjectTests::testDefaultRSAPubAttributesWithDates ()
1761+ {
1762+ CK_RV rv;
1763+ CK_SESSION_HANDLE hSession;
1764+ CK_OBJECT_HANDLE hObject = CK_INVALID_HANDLE;
1765+
1766+ // Minimal RSA public key object
1767+ CK_OBJECT_CLASS objClass = CKO_PUBLIC_KEY;
1768+ CK_KEY_TYPE objType = CKK_RSA;
1769+ CK_BYTE pN[] = { 0xC6 , 0x47 , 0xDD , 0x74 , 0x3B , 0xCB , 0xDC , 0x6F , 0xCE , 0xA7 ,
1770+ 0xF0 , 0x5F , 0x29 , 0x4B , 0x27 , 0x00 , 0xCC , 0x92 , 0xE9 , 0x20 ,
1771+ 0x8A , 0x2C , 0x87 , 0x36 , 0x47 , 0x24 , 0xB0 , 0xD5 , 0x7D , 0xB0 ,
1772+ 0x92 , 0x01 , 0xA0 , 0xA3 , 0x55 , 0x2E , 0x3F , 0xFE , 0xA7 , 0x4C ,
1773+ 0x4B , 0x3F , 0x9D , 0x4E , 0xCB , 0x78 , 0x12 , 0xA9 , 0x42 , 0xAD ,
1774+ 0x51 , 0x1F , 0x3B , 0xBD , 0x3D , 0x6A , 0xE5 , 0x38 , 0xB7 , 0x45 ,
1775+ 0x65 , 0x50 , 0x30 , 0x35 };
1776+ CK_BYTE pE[] = { 0x01 , 0x00 , 0x01 };
1777+ CK_DATE startDate = {
1778+ {' 2' , ' 0' , ' 2' , ' 2' },
1779+ {' 0' , ' 1' },
1780+ {' 0' , ' 1' }
1781+ };
1782+ CK_DATE endDate = {
1783+ {' 3' , ' 9' , ' 9' , ' 9' },
1784+ {' 1' , ' 2' },
1785+ {' 3' , ' 1' }
1786+ };
1787+ CK_ATTRIBUTE objTemplate[] = {
1788+ { CKA_CLASS, &objClass, sizeof (objClass) },
1789+ { CKA_KEY_TYPE, &objType, sizeof (objType) },
1790+ { CKA_MODULUS, pN, sizeof (pN) },
1791+ { CKA_PUBLIC_EXPONENT, pE, sizeof (pE) },
1792+ { CKA_START_DATE, &startDate, sizeof (startDate) },
1793+ { CKA_END_DATE, &endDate, sizeof (endDate) }
1794+ };
1795+
1796+ // Just make sure that we finalize any previous tests
1797+ CRYPTOKI_F_PTR ( C_Finalize (NULL_PTR) );
1798+
1799+ // Initialize the library and start the test.
1800+ rv = CRYPTOKI_F_PTR ( C_Initialize (NULL_PTR) );
1801+ CPPUNIT_ASSERT (rv == CKR_OK);
1802+
1803+ // Open read-write session
1804+ rv = CRYPTOKI_F_PTR ( C_OpenSession (m_initializedTokenSlotID, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL_PTR, NULL_PTR, &hSession) );
1805+ CPPUNIT_ASSERT (rv == CKR_OK);
1806+
1807+ // Login USER into the sessions so we can create a private objects
1808+ rv = CRYPTOKI_F_PTR ( C_Login (hSession, CKU_USER, m_userPin1, m_userPin1Length) );
1809+ CPPUNIT_ASSERT (rv == CKR_OK);
1810+
1811+ // Create minimal RSA public key object
1812+ rv = CRYPTOKI_F_PTR ( C_CreateObject (hSession, objTemplate, sizeof (objTemplate)/sizeof (CK_ATTRIBUTE), &hObject) );
1813+ CPPUNIT_ASSERT (rv == CKR_OK);
1814+
1815+ // Check attributes in RSA public key object
1816+ checkCommonObjectAttributes (hSession, hObject, objClass);
1817+ checkCommonStorageObjectAttributes (hSession, hObject, CK_FALSE, CK_FALSE, CK_TRUE, NULL_PTR, 0 , CK_TRUE, CK_TRUE);
1818+ checkCommonKeyAttributes (hSession, hObject, objType, NULL_PTR, 0 , startDate, sizeof (&startDate), endDate, sizeof (&endDate), CK_FALSE, CK_FALSE, CK_UNAVAILABLE_INFORMATION, NULL_PTR, 0 );
1819+ checkCommonPublicKeyAttributes (hSession, hObject, NULL_PTR, 0 , CK_TRUE, CK_TRUE, CK_TRUE, CK_TRUE, CK_FALSE, NULL_PTR, 0 );
1820+ checkCommonRSAPublicKeyAttributes (hSession, hObject, pN, sizeof (pN), 512 , pE, sizeof (pE));
1821+ }
1822+
17601823void ObjectTests::testDefaultRSAPrivAttributes ()
17611824{
17621825 CK_RV rv;
@@ -1822,6 +1885,80 @@ void ObjectTests::testDefaultRSAPrivAttributes()
18221885 checkToTrueAttributes (hSession, hObject);
18231886}
18241887
1888+ void ObjectTests::testDefaultRSAPrivAttributesWithDates ()
1889+ {
1890+ CK_RV rv;
1891+ CK_SESSION_HANDLE hSession;
1892+ CK_OBJECT_HANDLE hObject = CK_INVALID_HANDLE;
1893+
1894+ // Minimal RSA private key object
1895+ CK_OBJECT_CLASS objClass = CKO_PRIVATE_KEY;
1896+ CK_KEY_TYPE objType = CKK_RSA;
1897+ CK_BBOOL bTrue = CK_TRUE;
1898+ CK_BBOOL bFalse = CK_FALSE;
1899+ CK_BYTE pN[] = { 0xC6 , 0x47 , 0xDD , 0x74 , 0x3B , 0xCB , 0xDC , 0x6F , 0xCE , 0xA7 ,
1900+ 0xF0 , 0x5F , 0x29 , 0x4B , 0x27 , 0x00 , 0xCC , 0x92 , 0xE9 , 0x20 ,
1901+ 0x8A , 0x2C , 0x87 , 0x36 , 0x47 , 0x24 , 0xB0 , 0xD5 , 0x7D , 0xB0 ,
1902+ 0x92 , 0x01 , 0xA0 , 0xA3 , 0x55 , 0x2E , 0x3F , 0xFE , 0xA7 , 0x4C ,
1903+ 0x4B , 0x3F , 0x9D , 0x4E , 0xCB , 0x78 , 0x12 , 0xA9 , 0x42 , 0xAD ,
1904+ 0x51 , 0x1F , 0x3B , 0xBD , 0x3D , 0x6A , 0xE5 , 0x38 , 0xB7 , 0x45 ,
1905+ 0x65 , 0x50 , 0x30 , 0x35 };
1906+ CK_BYTE pD[] = { 0x6D , 0x94 , 0x6B , 0xEB , 0xFF , 0xDC , 0x03 , 0x80 , 0x7B , 0x0A ,
1907+ 0x4F , 0x0A , 0x98 , 0x6C , 0xA3 , 0x2A , 0x8A , 0xE4 , 0xAA , 0x18 ,
1908+ 0x44 , 0xA4 , 0xA5 , 0x39 , 0x37 , 0x0A , 0x2C , 0xFC , 0x5F , 0xD1 ,
1909+ 0x44 , 0x6E , 0xCE , 0x25 , 0x9B , 0xE5 , 0xD1 , 0x51 , 0xAF , 0xA8 ,
1910+ 0x30 , 0xD1 , 0x4D , 0x3C , 0x60 , 0x33 , 0xB5 , 0xED , 0x4C , 0x39 ,
1911+ 0xDA , 0x68 , 0x78 , 0xF9 , 0x6B , 0x4F , 0x47 , 0x55 , 0xB2 , 0x02 ,
1912+ 0x00 , 0x7E , 0x9C , 0x05 };
1913+ CK_DATE startDate = {
1914+ {' 2' , ' 0' , ' 2' , ' 2' },
1915+ {' 0' , ' 1' },
1916+ {' 0' , ' 1' }
1917+ };
1918+ CK_DATE endDate = {
1919+ {' 3' , ' 9' , ' 9' , ' 9' },
1920+ {' 1' , ' 2' },
1921+ {' 3' , ' 1' }
1922+ };
1923+ // Make the key non-sensitive and extractable so that we can test it.
1924+ CK_ATTRIBUTE objTemplate[] = {
1925+ { CKA_CLASS, &objClass, sizeof (objClass) },
1926+ { CKA_KEY_TYPE, &objType, sizeof (objType) },
1927+ { CKA_SENSITIVE, &bFalse, sizeof (bFalse) },
1928+ { CKA_EXTRACTABLE, &bTrue, sizeof (bTrue) },
1929+ { CKA_MODULUS, pN, sizeof (pN) },
1930+ { CKA_PRIVATE_EXPONENT, pD, sizeof (pD) },
1931+ { CKA_START_DATE, &startDate, sizeof (startDate) },
1932+ { CKA_END_DATE, &endDate, sizeof (endDate) }
1933+ };
1934+
1935+ // Just make sure that we finalize any previous tests
1936+ CRYPTOKI_F_PTR ( C_Finalize (NULL_PTR) );
1937+
1938+ // Initialize the library and start the test.
1939+ rv = CRYPTOKI_F_PTR ( C_Initialize (NULL_PTR) );
1940+ CPPUNIT_ASSERT (rv == CKR_OK);
1941+
1942+ // Open read-write session
1943+ rv = CRYPTOKI_F_PTR ( C_OpenSession (m_initializedTokenSlotID, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL_PTR, NULL_PTR, &hSession) );
1944+ CPPUNIT_ASSERT (rv == CKR_OK);
1945+
1946+ // Login USER into the sessions so we can create a private objects
1947+ rv = CRYPTOKI_F_PTR ( C_Login (hSession, CKU_USER, m_userPin1, m_userPin1Length) );
1948+ CPPUNIT_ASSERT (rv == CKR_OK);
1949+
1950+ // Create minimal RSA public key object
1951+ rv = CRYPTOKI_F_PTR ( C_CreateObject (hSession, objTemplate, sizeof (objTemplate)/sizeof (CK_ATTRIBUTE), &hObject) );
1952+ CPPUNIT_ASSERT (rv == CKR_OK);
1953+
1954+ // Check attributes in RSA public key object
1955+ checkCommonObjectAttributes (hSession, hObject, objClass);
1956+ checkCommonStorageObjectAttributes (hSession, hObject, CK_FALSE, CK_TRUE, CK_TRUE, NULL_PTR, 0 , CK_TRUE, CK_TRUE);
1957+ checkCommonKeyAttributes (hSession, hObject, objType, NULL_PTR, 0 , startDate, sizeof (&startDate), endDate, sizeof (&endDate), CK_FALSE, CK_FALSE, CK_UNAVAILABLE_INFORMATION, NULL_PTR, 0 );
1958+ checkCommonPrivateKeyAttributes (hSession, hObject, NULL_PTR, 0 , CK_FALSE, CK_TRUE, CK_TRUE, CK_TRUE, CK_TRUE, CK_TRUE, CK_FALSE, CK_FALSE, CK_FALSE, NULL_PTR, 0 , CK_FALSE);
1959+ checkCommonRSAPrivateKeyAttributes (hSession, hObject, pN, sizeof (pN), NULL_PTR, 0 , pD, sizeof (pD), NULL_PTR, 0 , NULL_PTR, 0 , NULL_PTR, 0 , NULL_PTR, 0 , NULL_PTR, 0 );
1960+ }
1961+
18251962void ObjectTests::testAlwaysNeverAttribute ()
18261963{
18271964 CK_RV rv;
0 commit comments