NingSun | 0c89b3c | 2018-02-08 08:34:03 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2012 SURFnet |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 20 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 22 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 24 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | /***************************************************************************** |
| 28 | ObjectTests.h |
| 29 | |
| 30 | Contains test cases to C_CreateObject, C_CopyObject, C_DestroyObject, |
| 31 | C_GetAttributeValue, C_SetAttributeValue, C_FindObjectsInit, |
| 32 | C_FindObjects, C_FindObjectsFinal, C_GenerateKeyPair |
| 33 | *****************************************************************************/ |
| 34 | |
| 35 | #ifndef _SOFTHSM_V2_OBJECTTESTS_H |
| 36 | #define _SOFTHSM_V2_OBJECTTESTS_H |
| 37 | |
| 38 | #include "TestsBase.h" |
| 39 | #include <cppunit/extensions/HelperMacros.h> |
| 40 | |
| 41 | class ObjectTests : public TestsBase |
| 42 | { |
| 43 | CPPUNIT_TEST_SUITE(ObjectTests); |
| 44 | CPPUNIT_TEST(testCreateObject); |
| 45 | CPPUNIT_TEST(testCopyObject); |
| 46 | CPPUNIT_TEST(testDestroyObject); |
| 47 | CPPUNIT_TEST(testGetObjectSize); |
| 48 | CPPUNIT_TEST(testGetAttributeValue); |
| 49 | CPPUNIT_TEST(testSetAttributeValue); |
| 50 | CPPUNIT_TEST(testFindObjects); |
| 51 | CPPUNIT_TEST(testGenerateKeys); |
| 52 | CPPUNIT_TEST(testCreateCertificates); |
| 53 | CPPUNIT_TEST(testDefaultDataAttributes); |
| 54 | CPPUNIT_TEST(testDefaultX509CertAttributes); |
| 55 | CPPUNIT_TEST(testDefaultRSAPubAttributes); |
| 56 | CPPUNIT_TEST(testDefaultRSAPrivAttributes); |
| 57 | CPPUNIT_TEST(testAlwaysNeverAttribute); |
| 58 | CPPUNIT_TEST(testSensitiveAttributes); |
| 59 | CPPUNIT_TEST(testGetInvalidAttribute); |
| 60 | CPPUNIT_TEST(testAllowedMechanisms); |
| 61 | CPPUNIT_TEST(testReAuthentication); |
| 62 | CPPUNIT_TEST(testTemplateAttribute); |
| 63 | CPPUNIT_TEST(testCreateSecretKey); |
| 64 | CPPUNIT_TEST_SUITE_END(); |
| 65 | |
| 66 | public: |
| 67 | void testCreateObject(); |
| 68 | void testCopyObject(); |
| 69 | void testDestroyObject(); |
| 70 | void testGetObjectSize(); |
| 71 | void testGetAttributeValue(); |
| 72 | void testSetAttributeValue(); |
| 73 | void testFindObjects(); |
| 74 | void testGenerateKeys(); |
| 75 | void testCreateCertificates(); |
| 76 | void testDefaultDataAttributes(); |
| 77 | void testDefaultX509CertAttributes(); |
| 78 | void testDefaultRSAPubAttributes(); |
| 79 | void testDefaultRSAPrivAttributes(); |
| 80 | void testAlwaysNeverAttribute(); |
| 81 | void testSensitiveAttributes(); |
| 82 | void testGetInvalidAttribute(); |
| 83 | void testReAuthentication(); |
| 84 | void testAllowedMechanisms(); |
| 85 | void testTemplateAttribute(); |
| 86 | void testCreateSecretKey(); |
| 87 | |
| 88 | protected: |
| 89 | void checkCommonObjectAttributes |
| 90 | ( CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, |
| 91 | CK_OBJECT_CLASS objectClass |
| 92 | ); |
| 93 | void checkCommonStorageObjectAttributes |
| 94 | ( CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, |
| 95 | CK_BBOOL bToken, |
| 96 | CK_BBOOL bPrivate, |
| 97 | CK_BBOOL bModifiable, |
| 98 | CK_UTF8CHAR_PTR pLabel, CK_ULONG ulLabelLen, |
| 99 | CK_BBOOL bCopyable, |
| 100 | CK_BBOOL bDestroyable |
| 101 | ); |
| 102 | void checkDataObjectAttributes |
| 103 | ( CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, |
| 104 | CK_UTF8CHAR_PTR pApplication, CK_ULONG ulApplicationLen, |
| 105 | CK_BYTE_PTR pObjectID, CK_ULONG ulObjectIdLen, |
| 106 | CK_BYTE_PTR pValue, CK_ULONG ulValueLen |
| 107 | ); |
| 108 | void checkCommonCertificateObjectAttributes |
| 109 | ( CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, |
| 110 | CK_CERTIFICATE_TYPE certType, |
| 111 | CK_BBOOL bTrusted, |
| 112 | CK_ULONG ulCertificateCategory, |
| 113 | CK_BYTE_PTR pCheckValue, CK_ULONG ulCheckValueLen, |
| 114 | CK_DATE startDate, CK_ULONG ulStartDateLen, |
| 115 | CK_DATE endDate, CK_ULONG ulEndDateLen |
| 116 | ); |
| 117 | void checkX509CertificateObjectAttributes |
| 118 | ( CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, |
| 119 | CK_BYTE_PTR pSubject, CK_ULONG ulSubjectLen, |
| 120 | CK_BYTE_PTR pId, CK_ULONG ulIdLen, |
| 121 | CK_BYTE_PTR pIssuer, CK_ULONG ulIssuerLen, |
| 122 | CK_BYTE_PTR pSerialNumber, CK_ULONG ulSerialNumberLen, |
| 123 | CK_BYTE_PTR pValue, CK_ULONG ulValueLen, |
| 124 | CK_BYTE_PTR pUrl, CK_ULONG ulUrlLen, |
| 125 | CK_BYTE_PTR pHashOfSubjectPublicKey, CK_ULONG ulHashOfSubjectPublicKeyLen, |
| 126 | CK_BYTE_PTR pHashOfIssuerPublicKey, CK_ULONG ulHashOfIssuerPublicKeyLen, |
| 127 | CK_ULONG ulJavaMidpSecurityDomain, |
| 128 | CK_MECHANISM_TYPE nameHashAlgorithm |
| 129 | ); |
| 130 | void checkCommonKeyAttributes |
| 131 | ( CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, |
| 132 | CK_KEY_TYPE keyType, |
| 133 | CK_BYTE_PTR pId, CK_ULONG ulIdLen, |
| 134 | CK_DATE startDate, CK_ULONG ulStartDateLen, |
| 135 | CK_DATE endDate, CK_ULONG ulEndDateLen, |
| 136 | CK_BBOOL bDerive, |
| 137 | CK_BBOOL bLocal, |
| 138 | CK_MECHANISM_TYPE keyMechanismType, |
| 139 | CK_MECHANISM_TYPE_PTR pAllowedMechanisms, CK_ULONG ulAllowedMechanismsLen /* len = count * sizeof(CK_MECHANISM_TYPE) */ |
| 140 | ); |
| 141 | void checkCommonPublicKeyAttributes |
| 142 | ( CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, |
| 143 | CK_BYTE_PTR pSubject, CK_ULONG ulSubjectLen, |
| 144 | CK_BBOOL bEncrypt, |
| 145 | CK_BBOOL bVerify, |
| 146 | CK_BBOOL bVerifyRecover, |
| 147 | CK_BBOOL bWrap, |
| 148 | CK_BBOOL bTrusted, |
| 149 | CK_ATTRIBUTE_PTR pWrapTemplate, CK_ULONG ulWrapTemplateLen /* len = count * sizeof(CK_ATTRIBUTE) */ |
| 150 | ); |
| 151 | void checkCommonPrivateKeyAttributes |
| 152 | ( CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, |
| 153 | CK_BYTE_PTR pSubject, CK_ULONG ulSubjectLen, |
| 154 | CK_BBOOL bSensitive, |
| 155 | CK_BBOOL bDecrypt, |
| 156 | CK_BBOOL bSign, |
| 157 | CK_BBOOL bSignRecover, |
| 158 | CK_BBOOL bUnwrap, |
| 159 | CK_BBOOL bExtractable, |
| 160 | CK_BBOOL bAlwaysSensitive, |
| 161 | CK_BBOOL bNeverExtractable, |
| 162 | CK_BBOOL bWrapWithTrusted, |
| 163 | CK_ATTRIBUTE_PTR pUnwrapTemplate, CK_ULONG ulUnwrapTemplateLen, /* len = count * sizeof(CK_ATTRIBUTE) */ |
| 164 | CK_BBOOL bAlwaysAuthenticate |
| 165 | ); |
| 166 | void checkCommonRSAPublicKeyAttributes |
| 167 | ( CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, |
| 168 | CK_BYTE_PTR pModulus, CK_ULONG ulModulusLen, |
| 169 | CK_ULONG ulModulusBits, |
| 170 | CK_BYTE_PTR pPublicExponent, CK_ULONG ulPublicExponentLen |
| 171 | ); |
| 172 | void checkCommonRSAPrivateKeyAttributes |
| 173 | ( CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, |
| 174 | CK_BYTE_PTR pModulus, CK_ULONG ulModulusLen, |
| 175 | CK_BYTE_PTR pPublicExponent, CK_ULONG ulPublicExponentLen, |
| 176 | CK_BYTE_PTR pPrivateExponent, CK_ULONG ulPrivateExponentLen, |
| 177 | CK_BYTE_PTR pPrime1, CK_ULONG ulPrime1Len, |
| 178 | CK_BYTE_PTR pPrime2, CK_ULONG ulPrime2Len, |
| 179 | CK_BYTE_PTR pExponent1, CK_ULONG ulExponent1Len, |
| 180 | CK_BYTE_PTR pExponent2, CK_ULONG ulExponent2Len, |
| 181 | CK_BYTE_PTR pCoefficient, CK_ULONG ulCoefficientLen |
| 182 | ); |
| 183 | |
| 184 | CK_RV createDataObjectMinimal(CK_SESSION_HANDLE hSession, CK_BBOOL bToken, CK_BBOOL bPrivate, CK_OBJECT_HANDLE &hObject); |
| 185 | CK_RV createDataObjectMCD(CK_SESSION_HANDLE hSession, CK_BBOOL bToken, CK_BBOOL bPrivate, CK_BBOOL bModifiable, CK_BBOOL bCopyable, CK_BBOOL bDestroyable, CK_OBJECT_HANDLE &hObject); |
| 186 | CK_RV createDataObjectNormal(CK_SESSION_HANDLE hSession, CK_BBOOL bToken, CK_BBOOL bPrivate, CK_OBJECT_HANDLE &hObject); |
| 187 | |
| 188 | CK_RV createCertificateObjectIncomplete(CK_SESSION_HANDLE hSession, CK_BBOOL bToken, CK_BBOOL bPrivate, CK_OBJECT_HANDLE &hObject); |
| 189 | CK_RV createCertificateObjectX509(CK_SESSION_HANDLE hSession, CK_BBOOL bToken, CK_BBOOL bPrivate, CK_OBJECT_HANDLE &hObject); |
| 190 | |
| 191 | CK_RV generateRsaKeyPair(CK_SESSION_HANDLE hSession, CK_BBOOL bTokenPuk, CK_BBOOL bPrivatePuk, CK_BBOOL bTokenPrk, CK_BBOOL bPrivatePrk, CK_OBJECT_HANDLE &hPuk, CK_OBJECT_HANDLE &hPrk); |
| 192 | }; |
| 193 | |
| 194 | #endif // !_SOFTHSM_V2_OBJECTTESTS_H |