check_securechannel.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <src_generated/ua_types_generated.h>
  7. #include <ua_types_encoding_binary.h>
  8. #include <src_generated/ua_transport_generated_encoding_binary.h>
  9. #include <src_generated/ua_transport_generated.h>
  10. #include <ua_types.h>
  11. #include <src_generated/ua_types_generated_encoding_binary.h>
  12. #include <ua_plugin_securitypolicy.h>
  13. #include <src_generated/ua_transport_generated_handling.h>
  14. #include "testing_networklayers.h"
  15. #include "testing_policy.h"
  16. #include "ua_securechannel.h"
  17. #include "check.h"
  18. #define UA_BYTESTRING_STATIC(s) {sizeof(s)-1, (UA_Byte*)(s)}
  19. // Some default testing sizes. Can be overwritten in testing functions.
  20. #define DEFAULT_SYM_ENCRYPTION_BLOCK_SIZE 2
  21. #define DEFAULT_SYM_SIGNING_KEY_LENGTH 3
  22. #define DEFAULT_SYM_ENCRYPTION_KEY_LENGTH 5
  23. #define DEFAULT_ASYM_REMOTE_SIGNATURE_SIZE 7
  24. #define DEFAULT_ASYM_LOCAL_SIGNATURE_SIZE 11
  25. #define DEFAULT_ASYM_REMOTE_PLAINTEXT_BLOCKSIZE 256
  26. #define DEFAULT_ASYM_REMOTE_BLOCKSIZE 256
  27. UA_SecureChannel testChannel;
  28. UA_ByteString dummyCertificate = UA_BYTESTRING_STATIC("DUMMY CERTIFICATE DUMMY CERTIFICATE DUMMY CERTIFICATE");
  29. UA_SecurityPolicy dummyPolicy;
  30. UA_Connection testingConnection;
  31. UA_ByteString sentData;
  32. static funcs_called fCalled;
  33. static key_sizes keySizes;
  34. static void
  35. setup_secureChannel(void) {
  36. TestingPolicy(&dummyPolicy, dummyCertificate, &fCalled, &keySizes);
  37. UA_SecureChannel_init(&testChannel, &dummyPolicy, &dummyCertificate);
  38. testingConnection = createDummyConnection(65535, &sentData);
  39. UA_Connection_attachSecureChannel(&testingConnection, &testChannel);
  40. testChannel.connection = &testingConnection;
  41. }
  42. static void
  43. teardown_secureChannel(void) {
  44. UA_SecureChannel_deleteMembersCleanup(&testChannel);
  45. dummyPolicy.deleteMembers(&dummyPolicy);
  46. testingConnection.close(&testingConnection);
  47. }
  48. static void
  49. setup_funcs_called(void) {
  50. memset(&fCalled, 0, sizeof(struct funcs_called));
  51. }
  52. static void
  53. teardown_funcs_called(void) {
  54. memset(&fCalled, 0, sizeof(struct funcs_called));
  55. }
  56. static void
  57. setup_key_sizes(void) {
  58. memset(&keySizes, 0, sizeof(struct key_sizes));
  59. keySizes.sym_sig_keyLen = DEFAULT_SYM_SIGNING_KEY_LENGTH;
  60. keySizes.sym_enc_blockSize = DEFAULT_SYM_ENCRYPTION_BLOCK_SIZE;
  61. keySizes.sym_enc_keyLen = DEFAULT_SYM_ENCRYPTION_KEY_LENGTH;
  62. keySizes.asym_lcl_sig_size = DEFAULT_ASYM_LOCAL_SIGNATURE_SIZE;
  63. keySizes.asym_rmt_sig_size = DEFAULT_ASYM_REMOTE_SIGNATURE_SIZE;
  64. keySizes.asym_rmt_ptext_blocksize = DEFAULT_ASYM_REMOTE_PLAINTEXT_BLOCKSIZE;
  65. keySizes.asym_rmt_blocksize = DEFAULT_ASYM_REMOTE_BLOCKSIZE;
  66. keySizes.asym_rmt_enc_key_size = 2048;
  67. keySizes.asym_lcl_enc_key_size = 1024;
  68. }
  69. static void
  70. teardown_key_sizes(void) {
  71. memset(&keySizes, 0, sizeof(struct key_sizes));
  72. }
  73. START_TEST(SecureChannel_initAndDelete)
  74. {
  75. TestingPolicy(&dummyPolicy, dummyCertificate, &fCalled, &keySizes);
  76. UA_StatusCode retval;
  77. UA_SecureChannel channel;
  78. retval = UA_SecureChannel_init(&channel, &dummyPolicy, &dummyCertificate);
  79. ck_assert_msg(retval == UA_STATUSCODE_GOOD, "Expected StatusCode to be good");
  80. ck_assert_msg(channel.state == UA_SECURECHANNELSTATE_FRESH, "Expected state to be fresh");
  81. ck_assert_msg(fCalled.newContext, "Expected newContext to have been called");
  82. ck_assert_msg(fCalled.makeCertificateThumbprint, "Expected makeCertificateThumbprint to have been called");
  83. ck_assert_msg(channel.securityPolicy == &dummyPolicy, "SecurityPolicy not set correctly");
  84. UA_SecureChannel_deleteMembersCleanup(&channel);
  85. ck_assert_msg(fCalled.deleteContext, "Expected deleteContext to have been called");
  86. dummyPolicy.deleteMembers(&dummyPolicy);
  87. }END_TEST
  88. START_TEST(SecureChannel_generateNewKeys)
  89. {
  90. UA_StatusCode retval = UA_SecureChannel_generateNewKeys(&testChannel);
  91. ck_assert_msg(retval == UA_STATUSCODE_GOOD, "Expected Statuscode to be good");
  92. ck_assert_msg(fCalled.generateKey, "Expected generateKey to have been called");
  93. ck_assert_msg(fCalled.setLocalSymEncryptingKey, "Expected setLocalSymEncryptingKey to have been called");
  94. ck_assert_msg(fCalled.setLocalSymSigningKey, "Expected setLocalSymSigningKey to have been called");
  95. ck_assert_msg(fCalled.setLocalSymIv, "Expected setLocalSymIv to have been called");
  96. ck_assert_msg(fCalled.setRemoteSymEncryptingKey, "Expected setRemoteSymEncryptingKey to have been called");
  97. ck_assert_msg(fCalled.setRemoteSymSigningKey, "Expected setRemoteSymSigningKey to have been called");
  98. ck_assert_msg(fCalled.setRemoteSymIv, "Expected setRemoteSymIv to have been called");
  99. }END_TEST
  100. START_TEST(SecureChannel_revolveTokens)
  101. {
  102. // Fake that no token was issued by setting 0
  103. testChannel.nextSecurityToken.tokenId = 0;
  104. UA_StatusCode retval = UA_SecureChannel_revolveTokens(&testChannel);
  105. ck_assert_msg(retval == UA_STATUSCODE_BADSECURECHANNELTOKENUNKNOWN,
  106. "Expected failure because tokenId 0 signifies that no token was issued");
  107. // Fake an issued token by setting an id
  108. testChannel.nextSecurityToken.tokenId = 10;
  109. retval = UA_SecureChannel_revolveTokens(&testChannel);
  110. ck_assert_msg(retval == UA_STATUSCODE_GOOD, "Expected function to return GOOD");
  111. ck_assert_msg(fCalled.generateKey,
  112. "Expected generateKey to be called because new keys need to be generated,"
  113. "when switching to the next token.");
  114. UA_ChannelSecurityToken testToken;
  115. UA_ChannelSecurityToken_init(&testToken);
  116. ck_assert_msg(memcmp(&testChannel.nextSecurityToken, &testToken, sizeof(UA_ChannelSecurityToken)) == 0,
  117. "Expected the next securityToken to be freshly initialized");
  118. ck_assert_msg(testChannel.securityToken.tokenId == 10, "Expected token to have been copied");
  119. }END_TEST
  120. static void
  121. createDummyResponse(UA_OpenSecureChannelResponse *response) {
  122. UA_OpenSecureChannelResponse_init(response);
  123. memset(response, 0, sizeof(UA_OpenSecureChannelResponse));
  124. }
  125. START_TEST(SecureChannel_sendAsymmetricOPNMessage_withoutConnection)
  126. {
  127. UA_OpenSecureChannelResponse dummyResponse;
  128. createDummyResponse(&dummyResponse);
  129. testChannel.securityMode = UA_MESSAGESECURITYMODE_NONE;
  130. // Remove connection to provoke error
  131. UA_Connection_detachSecureChannel(testChannel.connection);
  132. testChannel.connection = NULL;
  133. UA_StatusCode retval = UA_SecureChannel_sendAsymmetricOPNMessage(&testChannel, 42, &dummyResponse,
  134. &UA_TYPES[UA_TYPES_OPENSECURECHANNELRESPONSE]);
  135. ck_assert_msg(retval != UA_STATUSCODE_GOOD, "Expected failure without a connection");
  136. }END_TEST
  137. START_TEST(SecureChannel_sendAsymmetricOPNMessage_invalidParameters)
  138. {
  139. UA_OpenSecureChannelResponse dummyResponse;
  140. createDummyResponse(&dummyResponse);
  141. UA_StatusCode retval = UA_SecureChannel_sendAsymmetricOPNMessage(&testChannel, 42, NULL,
  142. &UA_TYPES[UA_TYPES_OPENSECURECHANNELRESPONSE]);
  143. ck_assert_msg(retval != UA_STATUSCODE_GOOD, "Expected failure");
  144. retval = UA_SecureChannel_sendAsymmetricOPNMessage(&testChannel, 42, &dummyResponse, NULL);
  145. ck_assert_msg(retval != UA_STATUSCODE_GOOD, "Expected failure");
  146. }END_TEST
  147. START_TEST(SecureChannel_sendAsymmetricOPNMessage_SecurityModeInvalid)
  148. {
  149. // Configure our channel correctly for OPN messages and setup dummy message
  150. UA_OpenSecureChannelResponse dummyResponse;
  151. createDummyResponse(&dummyResponse);
  152. testChannel.securityMode = UA_MESSAGESECURITYMODE_INVALID;
  153. UA_StatusCode retval = UA_SecureChannel_sendAsymmetricOPNMessage(&testChannel, 42, &dummyResponse,
  154. &UA_TYPES[UA_TYPES_OPENSECURECHANNELRESPONSE]);
  155. ck_assert_msg(retval == UA_STATUSCODE_BADSECURITYMODEREJECTED, "Expected SecurityMode rejected error");
  156. }
  157. END_TEST
  158. START_TEST(SecureChannel_sendAsymmetricOPNMessage_SecurityModeNone)
  159. {
  160. // Configure our channel correctly for OPN messages and setup dummy message
  161. UA_OpenSecureChannelResponse dummyResponse;
  162. createDummyResponse(&dummyResponse);
  163. testChannel.securityMode = UA_MESSAGESECURITYMODE_NONE;
  164. UA_StatusCode retval = UA_SecureChannel_sendAsymmetricOPNMessage(&testChannel, 42, &dummyResponse,
  165. &UA_TYPES[UA_TYPES_OPENSECURECHANNELRESPONSE]);
  166. ck_assert_msg(retval == UA_STATUSCODE_GOOD, "Expected function to succeed");
  167. ck_assert_msg(!fCalled.asym_enc, "Message encryption was called but should not have been");
  168. ck_assert_msg(!fCalled.asym_sign, "Message signing was called but should not have been");
  169. }
  170. END_TEST
  171. START_TEST(SecureChannel_sendAsymmetricOPNMessage_SecurityModeSign)
  172. {
  173. // Configure our channel correctly for OPN messages and setup dummy message
  174. UA_OpenSecureChannelResponse dummyResponse;
  175. createDummyResponse(&dummyResponse);
  176. testChannel.securityMode = UA_MESSAGESECURITYMODE_SIGN;
  177. UA_StatusCode retval = UA_SecureChannel_sendAsymmetricOPNMessage(&testChannel, 42, &dummyResponse,
  178. &UA_TYPES[UA_TYPES_OPENSECURECHANNELRESPONSE]);
  179. ck_assert_msg(retval == UA_STATUSCODE_GOOD, "Expected function to succeed");
  180. ck_assert_msg(fCalled.asym_enc, "Expected message to have been encrypted but it was not");
  181. ck_assert_msg(fCalled.asym_sign, "Expected message to have been signed but it was not");
  182. }END_TEST
  183. START_TEST(SecureChannel_sendAsymmetricOPNMessage_SecurityModeSignAndEncrypt)
  184. {
  185. // Configure our channel correctly for OPN messages and setup dummy message
  186. UA_OpenSecureChannelResponse dummyResponse;
  187. createDummyResponse(&dummyResponse);
  188. testChannel.securityMode = UA_MESSAGESECURITYMODE_SIGNANDENCRYPT;
  189. UA_StatusCode retval = UA_SecureChannel_sendAsymmetricOPNMessage(&testChannel, 42, &dummyResponse,
  190. &UA_TYPES[UA_TYPES_OPENSECURECHANNELRESPONSE]);
  191. ck_assert_msg(retval == UA_STATUSCODE_GOOD, "Expected function to succeed");
  192. ck_assert_msg(fCalled.asym_enc, "Expected message to have been encrypted but it was not");
  193. ck_assert_msg(fCalled.asym_sign, "Expected message to have been signed but it was not");
  194. }END_TEST
  195. START_TEST(SecureChannel_sendAsymmetricOPNMessage_sentDataIsValid)
  196. {
  197. UA_OpenSecureChannelResponse dummyResponse;
  198. createDummyResponse(&dummyResponse);
  199. testChannel.securityMode = UA_MESSAGESECURITYMODE_SIGNANDENCRYPT;
  200. UA_UInt32 requestId = UA_UInt32_random();
  201. UA_StatusCode retval = UA_SecureChannel_sendAsymmetricOPNMessage(&testChannel, requestId, &dummyResponse,
  202. &UA_TYPES[UA_TYPES_OPENSECURECHANNELRESPONSE]);
  203. ck_assert_msg(retval == UA_STATUSCODE_GOOD, "Expected function to succeed");
  204. size_t offset = 0;
  205. UA_SecureConversationMessageHeader header;
  206. UA_SecureConversationMessageHeader_decodeBinary(&sentData, &offset, &header);
  207. UA_AsymmetricAlgorithmSecurityHeader asymSecurityHeader;
  208. UA_AsymmetricAlgorithmSecurityHeader_decodeBinary(&sentData, &offset, &asymSecurityHeader);
  209. ck_assert_msg(UA_ByteString_equal(&dummyCertificate, &asymSecurityHeader.senderCertificate),
  210. "Expected the certificate to be equal to the one used by the secureChannel");
  211. ck_assert_msg(UA_ByteString_equal(&testChannel.securityPolicy->policyUri,
  212. &asymSecurityHeader.securityPolicyUri),
  213. "Expected securityPolicyUri to be equal to the one used by the secureChannel");
  214. UA_ByteString thumbPrint = {20, testChannel.remoteCertificateThumbprint};
  215. ck_assert_msg(UA_ByteString_equal(&thumbPrint,
  216. &asymSecurityHeader.receiverCertificateThumbprint),
  217. "Expected receiverCertificateThumbprint to be equal to the one set in the secureChannel");
  218. for(size_t i = offset; i < header.messageHeader.messageSize; ++i) {
  219. sentData.data[i] = (UA_Byte)((sentData.data[i] - 1) % (UA_BYTE_MAX + 1));
  220. }
  221. UA_SequenceHeader sequenceHeader;
  222. UA_SequenceHeader_decodeBinary(&sentData, &offset, &sequenceHeader);
  223. ck_assert_msg(sequenceHeader.requestId == requestId, "Expected requestId to be %i but was %i",
  224. requestId,
  225. sequenceHeader.requestId);
  226. UA_NodeId original = UA_NODEID_NUMERIC(0, UA_TYPES[UA_TYPES_OPENSECURECHANNELRESPONSE].binaryEncodingId);
  227. UA_NodeId requestTypeId;
  228. UA_NodeId_decodeBinary(&sentData, &offset, &requestTypeId);
  229. ck_assert_msg(UA_NodeId_equal(&original, &requestTypeId), "Expected nodeIds to be equal");
  230. UA_OpenSecureChannelResponse sentResponse;
  231. UA_OpenSecureChannelResponse_decodeBinary(&sentData, &offset, &sentResponse);
  232. ck_assert_msg(memcmp(&sentResponse, &dummyResponse, sizeof(UA_OpenSecureChannelResponse)) == 0,
  233. "Expected the sent response to be equal to the one supplied to the send function");
  234. UA_Byte paddingByte = sentData.data[offset];
  235. size_t paddingSize = (size_t)paddingByte;
  236. for(size_t i = 0; i <= paddingSize; ++i) {
  237. ck_assert_msg(sentData.data[offset + i] == paddingByte,
  238. "Expected padding byte %i to be %i but got value %i",
  239. i, paddingByte, sentData.data[offset + i]);
  240. }
  241. ck_assert_msg(sentData.data[offset + paddingSize + 1] == '*', "Expected first byte of signature");
  242. UA_SecureConversationMessageHeader_deleteMembers(&header);
  243. UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&asymSecurityHeader);
  244. UA_SequenceHeader_deleteMembers(&sequenceHeader);
  245. UA_OpenSecureChannelResponse_deleteMembers(&sentResponse);
  246. }
  247. END_TEST
  248. START_TEST(Securechannel_sendAsymmetricOPNMessage_extraPaddingPresentWhenKeyLargerThan2048Bits)
  249. {
  250. keySizes.asym_rmt_enc_key_size = 4096;
  251. keySizes.asym_rmt_blocksize = 4096;
  252. keySizes.asym_rmt_ptext_blocksize = 4096;
  253. UA_OpenSecureChannelResponse dummyResponse;
  254. createDummyResponse(&dummyResponse);
  255. testChannel.securityMode = UA_MESSAGESECURITYMODE_SIGNANDENCRYPT;
  256. UA_UInt32 requestId = UA_UInt32_random();
  257. UA_StatusCode retval = UA_SecureChannel_sendAsymmetricOPNMessage(&testChannel, requestId, &dummyResponse,
  258. &UA_TYPES[UA_TYPES_OPENSECURECHANNELRESPONSE]);
  259. ck_assert_msg(retval == UA_STATUSCODE_GOOD, "Expected function to succeed");
  260. size_t offset = 0;
  261. UA_SecureConversationMessageHeader header;
  262. UA_SecureConversationMessageHeader_decodeBinary(&sentData, &offset, &header);
  263. UA_AsymmetricAlgorithmSecurityHeader asymSecurityHeader;
  264. UA_AsymmetricAlgorithmSecurityHeader_decodeBinary(&sentData, &offset, &asymSecurityHeader);
  265. ck_assert_msg(UA_ByteString_equal(&dummyCertificate, &asymSecurityHeader.senderCertificate),
  266. "Expected the certificate to be equal to the one used by the secureChannel");
  267. ck_assert_msg(UA_ByteString_equal(&testChannel.securityPolicy->policyUri,
  268. &asymSecurityHeader.securityPolicyUri),
  269. "Expected securityPolicyUri to be equal to the one used by the secureChannel");
  270. UA_ByteString thumbPrint = {20, testChannel.remoteCertificateThumbprint};
  271. ck_assert_msg(UA_ByteString_equal(&thumbPrint,
  272. &asymSecurityHeader.receiverCertificateThumbprint),
  273. "Expected receiverCertificateThumbprint to be equal to the one set in the secureChannel");
  274. for(size_t i = offset; i < header.messageHeader.messageSize; ++i) {
  275. sentData.data[i] = (UA_Byte)((sentData.data[i] - 1) % (UA_BYTE_MAX + 1));
  276. }
  277. UA_SequenceHeader sequenceHeader;
  278. UA_SequenceHeader_decodeBinary(&sentData, &offset, &sequenceHeader);
  279. ck_assert_msg(sequenceHeader.requestId == requestId, "Expected requestId to be %i but was %i",
  280. requestId,
  281. sequenceHeader.requestId);
  282. UA_NodeId original = UA_NODEID_NUMERIC(0, UA_TYPES[UA_TYPES_OPENSECURECHANNELRESPONSE].binaryEncodingId);
  283. UA_NodeId requestTypeId;
  284. UA_NodeId_decodeBinary(&sentData, &offset, &requestTypeId);
  285. ck_assert_msg(UA_NodeId_equal(&original, &requestTypeId), "Expected nodeIds to be equal");
  286. UA_OpenSecureChannelResponse sentResponse;
  287. UA_OpenSecureChannelResponse_decodeBinary(&sentData, &offset, &sentResponse);
  288. ck_assert_msg(memcmp(&sentResponse, &dummyResponse, sizeof(UA_OpenSecureChannelResponse)) == 0,
  289. "Expected the sent response to be equal to the one supplied to the send function");
  290. UA_Byte paddingByte = sentData.data[offset];
  291. UA_Byte extraPaddingByte = sentData.data[sentData.length - keySizes.asym_lcl_sig_size - 1];
  292. size_t paddingSize = (size_t)paddingByte;
  293. paddingSize |= extraPaddingByte << 8;
  294. for(size_t i = 0; i <= paddingSize; ++i) {
  295. ck_assert_msg(sentData.data[offset + i] == paddingByte,
  296. "Expected padding byte %i to be %i but got value %i",
  297. i,
  298. paddingByte,
  299. sentData.data[offset + i]);
  300. }
  301. ck_assert_msg(sentData.data[offset + paddingSize + 1] == extraPaddingByte,
  302. "Expected extra padding byte to be %i but got %i",
  303. extraPaddingByte, sentData.data[offset + paddingSize + 1]);
  304. ck_assert_msg(sentData.data[offset + paddingSize + 2] == '*',
  305. "Expected first byte 42 of signature but got %i",
  306. sentData.data[offset + paddingSize + 2]);
  307. UA_SecureConversationMessageHeader_deleteMembers(&header);
  308. UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&asymSecurityHeader);
  309. UA_SequenceHeader_deleteMembers(&sequenceHeader);
  310. UA_OpenSecureChannelResponse_deleteMembers(&sentResponse);
  311. }END_TEST
  312. static Suite *
  313. testSuite_SecureChannel(void) {
  314. Suite *s = suite_create("SecureChannel");
  315. TCase *tc_initAndDelete = tcase_create("Initialize and delete Securechannel");
  316. tcase_add_checked_fixture(tc_initAndDelete, setup_funcs_called, teardown_funcs_called);
  317. tcase_add_checked_fixture(tc_initAndDelete, setup_key_sizes, teardown_key_sizes);
  318. tcase_add_test(tc_initAndDelete, SecureChannel_initAndDelete);
  319. suite_add_tcase(s, tc_initAndDelete);
  320. TCase *tc_generateNewKeys = tcase_create("Test generateNewKeys function");
  321. tcase_add_checked_fixture(tc_generateNewKeys, setup_funcs_called, teardown_funcs_called);
  322. tcase_add_checked_fixture(tc_generateNewKeys, setup_key_sizes, teardown_key_sizes);
  323. tcase_add_checked_fixture(tc_generateNewKeys, setup_secureChannel, teardown_secureChannel);
  324. tcase_add_test(tc_generateNewKeys, SecureChannel_generateNewKeys);
  325. suite_add_tcase(s, tc_generateNewKeys);
  326. TCase *tc_revolveTokens = tcase_create("Test revolveTokens function");
  327. tcase_add_checked_fixture(tc_revolveTokens, setup_funcs_called, teardown_funcs_called);
  328. tcase_add_checked_fixture(tc_revolveTokens, setup_key_sizes, teardown_key_sizes);
  329. tcase_add_checked_fixture(tc_revolveTokens, setup_secureChannel, teardown_secureChannel);
  330. tcase_add_test(tc_revolveTokens, SecureChannel_revolveTokens);
  331. suite_add_tcase(s, tc_revolveTokens);
  332. TCase *tc_sendAsymmetricOPNMessage = tcase_create("Test sendAsymmetricOPNMessage function");
  333. tcase_add_checked_fixture(tc_sendAsymmetricOPNMessage, setup_funcs_called, teardown_funcs_called);
  334. tcase_add_checked_fixture(tc_sendAsymmetricOPNMessage, setup_key_sizes, teardown_key_sizes);
  335. tcase_add_checked_fixture(tc_sendAsymmetricOPNMessage, setup_secureChannel, teardown_secureChannel);
  336. tcase_add_test(tc_sendAsymmetricOPNMessage, SecureChannel_sendAsymmetricOPNMessage_withoutConnection);
  337. tcase_add_test(tc_sendAsymmetricOPNMessage, SecureChannel_sendAsymmetricOPNMessage_invalidParameters);
  338. tcase_add_test(tc_sendAsymmetricOPNMessage, SecureChannel_sendAsymmetricOPNMessage_SecurityModeInvalid);
  339. tcase_add_test(tc_sendAsymmetricOPNMessage, SecureChannel_sendAsymmetricOPNMessage_SecurityModeNone);
  340. tcase_add_test(tc_sendAsymmetricOPNMessage, SecureChannel_sendAsymmetricOPNMessage_SecurityModeSign);
  341. tcase_add_test(tc_sendAsymmetricOPNMessage, SecureChannel_sendAsymmetricOPNMessage_SecurityModeSignAndEncrypt);
  342. tcase_add_test(tc_sendAsymmetricOPNMessage, SecureChannel_sendAsymmetricOPNMessage_sentDataIsValid);
  343. tcase_add_test(tc_sendAsymmetricOPNMessage,
  344. Securechannel_sendAsymmetricOPNMessage_extraPaddingPresentWhenKeyLargerThan2048Bits);
  345. suite_add_tcase(s, tc_sendAsymmetricOPNMessage);
  346. return s;
  347. }
  348. int
  349. main(void) {
  350. Suite *s = testSuite_SecureChannel();
  351. SRunner *sr = srunner_create(s);
  352. srunner_set_fork_status(sr, CK_NOFORK);
  353. srunner_run_all(sr, CK_NORMAL);
  354. int number_failed = srunner_ntests_failed(sr);
  355. srunner_free(sr);
  356. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  357. }