Debian Codegraph @

src/security/core/tests/common/test_utils.h

raw
1 /*
2 * Copyright(c) 2006 to 2021 ZettaScale Technology and others
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0 which is available at
6 * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
7 * v. 1.0 which is available at
8 * http://www.eclipse.org/org/documents/edl-v10.php.
9 *
10 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11 */
12 #ifndef SECURITY_CORE_TEST_UTILS_H_
13 #define SECURITY_CORE_TEST_UTILS_H_
14
15 #include "dds/dds.h"
16 #include "dds/ddsrt/sync.h"
17
18 #include "dds/security/dds_security_api.h"
19
20 #define PK_N DDS_SECURITY_PROTECTION_KIND_NONE
21 #define PK_S DDS_SECURITY_PROTECTION_KIND_SIGN
22 #define PK_SOA DDS_SECURITY_PROTECTION_KIND_SIGN_WITH_ORIGIN_AUTHENTICATION
23 #define PK_E DDS_SECURITY_PROTECTION_KIND_ENCRYPT
24 #define PK_EOA DDS_SECURITY_PROTECTION_KIND_ENCRYPT_WITH_ORIGIN_AUTHENTICATION
25 #define BPK_N DDS_SECURITY_BASICPROTECTION_KIND_NONE
26 #define BPK_S DDS_SECURITY_BASICPROTECTION_KIND_SIGN
27 #define BPK_E DDS_SECURITY_BASICPROTECTION_KIND_ENCRYPT
28
29 #define PF_F "file:"
30 #define PF_D "data:,"
31
32 #define MAX_LOCAL_IDENTITIES 8
33 #define MAX_REMOTE_IDENTITIES 8
34 #define MAX_HANDSHAKES 32
35
36 union guid {
37 DDS_Security_GUID_t g;
38 unsigned u[4];
39 };
40
41 enum hs_node_type
42 {
43 HSN_UNDEFINED,
44 HSN_REQUESTER,
45 HSN_REPLIER
46 };
47
48 struct Identity
49 {
50 DDS_Security_IdentityHandle handle;
51 union guid guid;
52 };
53
54 struct Handshake
55 {
56 DDS_Security_HandshakeHandle handle;
57 enum hs_node_type node_type;
58 int lidx;
59 int ridx;
60 DDS_Security_ValidationResult_t handshakeResult;
61 DDS_Security_ValidationResult_t finalResult;
62 char * err_msg;
63 };
64
65 void print_test_msg (const char *msg, ...);
66 void validate_handshake (dds_domainid_t domain_id, bool exp_localid_fail, const char * exp_localid_msg, struct Handshake *hs_list[], int *nhs, dds_duration_t timeout);
67 void validate_handshake_nofail (dds_domainid_t domain_id, dds_duration_t timeout);
68 void validate_handshake_result (struct Handshake *hs, bool exp_fail_hs_req, const char * fail_hs_req_msg, bool exp_fail_hs_reply, const char * fail_hs_reply_msg);
69 void handshake_list_fini (struct Handshake *hs_list, int nhs);
70 char *create_topic_name (const char *prefix, uint32_t nr, char *name, size_t size);
71 void sync_writer_to_readers (dds_entity_t pp_wr, dds_entity_t wr, uint32_t exp_count, dds_time_t abstimeout);
72 void sync_reader_to_writers (dds_entity_t pp_rd, dds_entity_t rd, uint32_t exp_count, dds_time_t abstimeout);
73 bool reader_wait_for_data (dds_entity_t pp, dds_entity_t rd, dds_duration_t dur);
74 dds_qos_t * get_default_test_qos (void);
75 void rd_wr_init (
76 dds_entity_t pp_wr, dds_entity_t *pub, dds_entity_t *pub_tp, dds_entity_t *wr,
77 dds_entity_t pp_rd, dds_entity_t *sub, dds_entity_t *sub_tp, dds_entity_t *rd,
78 const char * topic_name);
79 void rd_wr_init_fail (
80 dds_entity_t pp_wr, dds_entity_t *pub, dds_entity_t *pub_tp, dds_entity_t *wr,
81 dds_entity_t pp_rd, dds_entity_t *sub, dds_entity_t *sub_tp, dds_entity_t *rd,
82 const char * topic_name,
83 bool exp_pubtp_fail, bool exp_wr_fail,
84 bool exp_subtp_fail, bool exp_rd_fail);
85 void rd_wr_init_w_partitions_fail(
86 dds_entity_t pp_wr, dds_entity_t *pub, dds_entity_t *pub_tp, dds_entity_t *wr,
87 dds_entity_t pp_rd, dds_entity_t *sub, dds_entity_t *sub_tp, dds_entity_t *rd,
88 const char * topic_name,
89 const char ** partition_names,
90 bool exp_pubtp_fail, bool exp_wr_fail,
91 bool exp_subtp_fail, bool exp_rd_fail);
92 void write_read_for (dds_entity_t wr, dds_entity_t pp_rd, dds_entity_t rd, dds_duration_t dur, bool exp_write_fail, bool exp_read_fail);
93 const char * pk_to_str (DDS_Security_ProtectionKind pk);
94 const char * bpk_to_str (DDS_Security_BasicProtectionKind bpk);
95 DDS_Security_DatawriterCryptoHandle get_builtin_writer_crypto_handle(dds_entity_t participant, unsigned entityid);
96 DDS_Security_DatawriterCryptoHandle get_writer_crypto_handle(dds_entity_t writer);
97
98 #define GET_SECURITY_PLUGIN_CONTEXT_DECL(name_) \
99 struct dds_security_##name_##_impl * get_##name_##_context(dds_entity_t participant);
100 GET_SECURITY_PLUGIN_CONTEXT_DECL(access_control)
101 GET_SECURITY_PLUGIN_CONTEXT_DECL(authentication)
102 GET_SECURITY_PLUGIN_CONTEXT_DECL(cryptography)
103
104
105 #endif /* SECURITY_CORE_TEST_UTILS_H_ */