Debian Codegraph @

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

raw
1 /*
2 * Copyright(c) 2006 to 2020 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_CRYPTO_WRAPPER_H_
13 #define SECURITY_CORE_TEST_CRYPTO_WRAPPER_H_
14
15 #include "dds/ddsrt/circlist.h"
16 #include "dds/ddsi/ddsi_domaingv.h"
17 #include "dds/security/dds_security_api.h"
18 #include "dds/security/dds_security_api_defs.h"
19 #include "dds/security/cryptography_wrapper_export.h"
20
21 #define CRYPTO_TOKEN_MAXCOUNT 10
22 #define CRYPTO_TOKEN_SIZE 256
23
24 struct dds_security_cryptography_impl;
25
26 enum crypto_tokens_type {
27 LOCAL_PARTICIPANT_TOKENS,
28 LOCAL_WRITER_TOKENS,
29 LOCAL_READER_TOKENS,
30 REMOTE_PARTICIPANT_TOKENS,
31 REMOTE_WRITER_TOKENS,
32 REMOTE_READER_TOKENS,
33 TOKEN_TYPE_INVALID
34 };
35
36 struct crypto_token_data {
37 struct ddsrt_circlist_elem e;
38 enum crypto_tokens_type type;
39 DDS_Security_ParticipantCryptoHandle local_handle;
40 DDS_Security_ParticipantCryptoHandle remote_handle;
41 uint32_t n_tokens;
42 unsigned char data[CRYPTO_TOKEN_MAXCOUNT][CRYPTO_TOKEN_SIZE];
43 size_t data_len[CRYPTO_TOKEN_MAXCOUNT];
44 };
45
46 enum crypto_encode_decode_fn {
47 ENCODE_DATAWRITER_SUBMESSAGE,
48 ENCODE_DATAREADER_SUBMESSAGE,
49 DECODE_DATAWRITER_SUBMESSAGE,
50 DECODE_DATAREADER_SUBMESSAGE
51 };
52
53 struct crypto_encode_decode_data {
54 struct ddsrt_circlist_elem e;
55 enum crypto_encode_decode_fn function;
56 DDS_Security_long_long handle;
57 uint32_t count;
58 };
59
60 SECURITY_EXPORT void set_protection_kinds(
61 struct dds_security_cryptography_impl * impl,
62 DDS_Security_ProtectionKind rtps_protection_kind,
63 DDS_Security_ProtectionKind metadata_protection_kind,
64 DDS_Security_BasicProtectionKind payload_protection_kind);
65 SECURITY_EXPORT void set_encrypted_secret(struct dds_security_cryptography_impl * impl, const char * secret);
66 SECURITY_EXPORT void set_disc_protection_kinds(
67 struct dds_security_cryptography_impl * impl,
68 DDS_Security_ProtectionKind disc_protection_kind,
69 DDS_Security_ProtectionKind liveliness_protection_kind);
70 SECURITY_EXPORT void set_entity_data_secret(struct dds_security_cryptography_impl * impl, const char * pp_secret, const char * groupdata_secret, const char * ep_secret);
71 SECURITY_EXPORT void set_force_plain_data(struct dds_security_cryptography_impl * impl, DDS_Security_DatawriterCryptoHandle wr_handle, bool plain_rtps, bool plain_submsg, bool plain_payload);
72
73 SECURITY_EXPORT const char *get_crypto_token_type_str (enum crypto_tokens_type type);
74 SECURITY_EXPORT struct ddsrt_circlist * get_crypto_tokens (struct dds_security_cryptography_impl * impl);
75 SECURITY_EXPORT struct crypto_token_data * find_crypto_token (struct dds_security_cryptography_impl * impl, enum crypto_tokens_type type, unsigned char * data, size_t data_len);
76 SECURITY_EXPORT struct crypto_encode_decode_data * get_encode_decode_log (struct dds_security_cryptography_impl * impl, enum crypto_encode_decode_fn function, DDS_Security_long_long handle);
77
78 /* Init in all-ok mode: all functions return success without calling the actual plugin */
79 SECURITY_EXPORT int init_test_cryptography_all_ok(const char *argument, void **context, struct ddsi_domaingv *gv);
80 SECURITY_EXPORT int finalize_test_cryptography_all_ok(void *context);
81
82 /* Init in missing function mode: one of the function pointers is null */
83 SECURITY_EXPORT int init_test_cryptography_missing_func(const char *argument, void **context, struct ddsi_domaingv *gv);
84 SECURITY_EXPORT int finalize_test_cryptography_missing_func(void *context);
85
86 /* Init in wrapper mode */
87 SECURITY_EXPORT int init_test_cryptography_wrapped(const char *argument, void **context, struct ddsi_domaingv *gv);
88 SECURITY_EXPORT int finalize_test_cryptography_wrapped(void *context);
89
90 /* Init in store-token mode (stores all exchanged security tokens) */
91 SECURITY_EXPORT int32_t init_test_cryptography_store_tokens(const char *argument, void **context, struct ddsi_domaingv *gv);
92 SECURITY_EXPORT int32_t finalize_test_cryptography_store_tokens(void *context);
93
94 /* Init in plain-data mode (force plain data for payload, submsg and/or rtps) */
95 SECURITY_EXPORT int init_test_cryptography_plain_data(const char *argument, void **context, struct ddsi_domaingv *gv);
96 SECURITY_EXPORT int finalize_test_cryptography_plain_data(void *context);
97
98 #endif /* SECURITY_CORE_TEST_CRYPTO_WRAPPER_H_ */