1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
use crate::{
messages::submessages::{
elements::parameter_list::ParameterList, secure_postfix::SecurePostfix,
secure_prefix::SecurePrefix,
},
rtps::{Message, Submessage},
security::{
access_control::types::*, authentication::types::*, cryptographic::types::*, types::*,
},
};
// Imports for doc references
#[cfg(doc)]
use crate::{messages::submessages::submessage::SecuritySubmessage, rtps::SubmessageBody};
/// CryptoKeyFactory: section 8.5.1.7 of the Security specification (v. 1.1)
pub trait CryptoKeyFactory: Send {
/// register_local_participant: section 8.5.1.7.1 of the Security
/// specification (v. 1.1)
fn register_local_participant(
&mut self,
participant_identity: IdentityHandle,
participant_permissions: PermissionsHandle,
participant_properties: &[Property],
participant_security_attributes: ParticipantSecurityAttributes,
) -> SecurityResult<ParticipantCryptoHandle>;
/// register_matched_remote_participant: section 8.5.1.7.2 of the Security
/// specification (v. 1.1)
fn register_matched_remote_participant(
&mut self,
local_participant_crypto_handle: ParticipantCryptoHandle,
remote_participant_identity: IdentityHandle,
remote_participant_permissions: PermissionsHandle,
shared_secret: SharedSecretHandle,
) -> SecurityResult<ParticipantCryptoHandle>;
/// register_local_datawriter: section 8.5.1.7.3 of the Security specification
/// (v. 1.1)
fn register_local_datawriter(
&mut self,
local_participant_crypto_handle: ParticipantCryptoHandle,
datawriter_properties: &[Property],
datawriter_security_attributes: EndpointSecurityAttributes,
) -> SecurityResult<DatawriterCryptoHandle>;
/// register_matched_remote_datareader: section 8.5.1.7.4 of the Security
/// specification (v. 1.1)
fn register_matched_remote_datareader(
&mut self,
local_datawriter_crypto_handle: DatawriterCryptoHandle,
remote_participant_crypto_handle: ParticipantCryptoHandle,
shared_secret: SharedSecretHandle,
relay_only: bool,
) -> SecurityResult<DatareaderCryptoHandle>;
/// register_local_datareader: section 8.5.1.7.5 of the Security specification
/// (v. 1.1)
fn register_local_datareader(
&mut self,
local_participant_crypto_handle: ParticipantCryptoHandle,
datareader_properties: &[Property],
datareader_security_attributes: EndpointSecurityAttributes,
) -> SecurityResult<DatareaderCryptoHandle>;
/// register_matched_remote_datawriter: section 8.5.1.7.6 of the Security
/// specification (v. 1.1)
fn register_matched_remote_datawriter(
&mut self,
local_datareader_crypto_handle: DatareaderCryptoHandle,
remote_participant_crypto_handle: ParticipantCryptoHandle,
shared_secret: SharedSecretHandle,
) -> SecurityResult<DatawriterCryptoHandle>;
/// unregister_participant: section 8.5.1.7.7 of the Security specification
/// (v. 1.1)
fn unregister_participant(
&mut self,
participant_crypto_handle: ParticipantCryptoHandle,
) -> SecurityResult<()>;
/// unregister_datawriter: section 8.5.1.7.8 of the Security specification (v.
/// 1.1)
fn unregister_datawriter(
&mut self,
datawriter_crypto_handle: DatawriterCryptoHandle,
) -> SecurityResult<()>;
/// unregister_datareader: section 8.5.1.7.9 of the Security specification (v.
/// 1.1)
fn unregister_datareader(
&mut self,
datareader_crypto_handle: DatareaderCryptoHandle,
) -> SecurityResult<()>;
}
/// CryptoKeyExchange: section 8.5.1.8 of the Security specification (v. 1.1)
pub trait CryptoKeyExchange {
/// create_local_participant_crypto_tokens: section 8.5.1.8.1 of the Security
/// specification (v. 1.1)
///
/// In a vector, return the tokens that would be written in
/// `local_participant_crypto_tokens`.
fn create_local_participant_crypto_tokens(
&mut self,
local_participant_crypto_handle: ParticipantCryptoHandle,
remote_participant_crypto_handle: ParticipantCryptoHandle,
) -> SecurityResult<Vec<ParticipantCryptoToken>>;
/// set_remote_participant_crypto_tokens: section 8.5.1.8.2 of the Security
/// specification (v. 1.1)
fn set_remote_participant_crypto_tokens(
&mut self,
local_participant_crypto_handle: ParticipantCryptoHandle,
remote_participant_crypto_handle: ParticipantCryptoHandle,
remote_participant_tokens: Vec<ParticipantCryptoToken>,
) -> SecurityResult<()>;
/// create_local_datawriter_crypto_tokens: section 8.5.1.8.3 of the Security
/// specification (v. 1.1)
///
/// In a vector, return the tokens that would be written in
/// `local_datawriter_crypto_tokens`.
fn create_local_datawriter_crypto_tokens(
&mut self,
local_datawriter_crypto_handle: DatawriterCryptoHandle,
remote_datareader_crypto_handle: DatareaderCryptoHandle,
) -> SecurityResult<Vec<DatawriterCryptoToken>>;
/// set_remote_datawriter_crypto_tokens: section 8.5.1.8.4 of the Security
/// specification (v. 1.1)
fn set_remote_datawriter_crypto_tokens(
&mut self,
local_datareader_crypto_handle: DatareaderCryptoHandle,
remote_datawriter_crypto_handle: DatawriterCryptoHandle,
remote_datawriter_tokens: Vec<DatawriterCryptoToken>,
) -> SecurityResult<()>;
/// create_local_datareader_crypto_tokens: section 8.5.1.8.5 of the Security
/// specification (v. 1.1)
///
/// In a vector, return the tokens that would be written in
/// `local_datareader_crypto_tokens`.
fn create_local_datareader_crypto_tokens(
&mut self,
local_datareader_crypto_handle: DatareaderCryptoHandle,
remote_datawriter_crypto_handle: DatawriterCryptoHandle,
) -> SecurityResult<Vec<DatareaderCryptoToken>>;
/// set_remote_datareader_crypto_tokens: section 8.5.1.8.6 of the Security
/// specification (v. 1.1)
fn set_remote_datareader_crypto_tokens(
&mut self,
local_datawriter_crypto_handle: DatawriterCryptoHandle,
remote_datareader_crypto_handle: DatareaderCryptoHandle,
remote_datareader_tokens: Vec<DatareaderCryptoToken>,
) -> SecurityResult<()>;
/// return_crypto_tokens: section 8.5.1.8.7 of the Security specification (v.
/// 1.1)
fn return_crypto_tokens(&mut self, crypto_tokens: Vec<CryptoToken>) -> SecurityResult<()>;
}
/// CryptoTransform: section 8.5.1.9 of the Security specification (v. 1.1)
///
/// Differs from the specification by returning the results instead of writing
/// them to provided buffers.
pub trait CryptoTransform: Send {
/// encode_serialized_payload: section 8.5.1.9.1 of the Security specification
/// (v. 1.1)
///
/// In a tuple, return the results that would be written in `encoded_buffer`,
/// which is as bytes a serialized payload containing (a fragment of) the
/// encoded data, and `extra_inline_qos`.
fn encode_serialized_payload(
&self,
plain_buffer: Vec<u8>, // (a fragment of) serialized `SerializedPayload`
sending_datawriter_crypto_handle: DatawriterCryptoHandle,
) -> SecurityResult<(Vec<u8>, ParameterList)>;
/// encode_datawriter_submessage: section 8.5.1.9.2 of the Security
/// specification (v. 1.1)
///
/// Return the submessages that would be written in
/// `encoded_rtps_submessage`.
/// `receiving_datareader_crypto_list_index` is dropped.
///
/// NOTE! [crate::security::security_plugins::SecurityPlugins::is_rtps_protection_special_case] relies on the assumption that
/// in the topic DCPSParticipantVolatileMessageSecure
/// the CryptoTransformIdentifier has transformation_key_id=0 like it does in
/// the builtin plugin. If a custom plugin that does not adhere to this is
/// used, that check needs to also be modified.
///
/// # Panics
/// The function may panic if `plain_rtps_submessage.body` is not
/// [SubmessageBody::Writer].
fn encode_datawriter_submessage(
&self,
plain_rtps_submessage: Submessage,
sending_datawriter_crypto_handle: DatawriterCryptoHandle,
receiving_datareader_crypto_handle_list: Vec<DatareaderCryptoHandle>,
) -> SecurityResult<EncodedSubmessage>;
/// encode_datareader_submessage: section 8.5.1.9.3 of the Security
/// specification (v. 1.1)
///
/// Return the submessages that would be written in
/// `encoded_rtps_submessage`.
///
/// NOTE! [crate::security::security_plugins::SecurityPlugins::is_rtps_protection_special_case] relies on the assumption that
/// in the topic DCPSParticipantVolatileMessageSecure
/// the CryptoTransformIdentifier has transformation_key_id=0 like it does in
/// the builtin plugin. If a custom plugin that does not adhere to this is
/// used, that check needs to also be modified.
///
/// # Panics
/// The function may panic if `plain_rtps_submessage.body` is not
/// [SubmessageBody::Reader].
fn encode_datareader_submessage(
&self,
plain_rtps_submessage: Submessage,
sending_datareader_crypto_handle: DatareaderCryptoHandle,
receiving_datawriter_crypto_handle_list: Vec<DatawriterCryptoHandle>,
) -> SecurityResult<EncodedSubmessage>;
/// encode_rtps_message: section 8.5.1.9.4 of the Security specification (v.
/// 1.1)
///
/// Return the message that would be written in
/// `encoded_rtps_message`.
/// in the case that no transformation is performed and the plain message
/// should be sent, the plain message shall be returned (instead of returning
/// false, see the spec). `receiving_participant_crypto_list_index` is
/// dropped.
fn encode_rtps_message(
&self,
plain_rtps_message: Message,
sending_participant_crypto_handle: ParticipantCryptoHandle,
receiving_participant_crypto_handle_list: Vec<ParticipantCryptoHandle>,
) -> SecurityResult<Message>;
/// decode_rtps_message: section 8.5.1.9.5 of the Security specification (v.
/// 1.1)
///
/// Return the message that would be written in `plain_buffer`.
fn decode_rtps_message(
&self,
encoded_message: Message,
receiving_participant_crypto_handle: ParticipantCryptoHandle,
sending_participant_crypto_handle: ParticipantCryptoHandle,
) -> SecurityResult<DecodeOutcome<Message>>;
// Combines the functionality of preprocess_secure_submsg and the subsequent
// call of decode_datawriter_submessage or decode_datareader_submessage from
// sections 8.5.1.9.6–8 of the Security specification
/// (v. 1.1)
///
/// Return the body of the submessage that would be written in
/// `plain_rtps_submessage` of the appropriate decode method, and a list of
/// endpoint crypto handles, the decode keys of which match the one used for
/// decoding, i.e. which are approved to receive the submessage by access
/// control.
fn decode_submessage(
&self,
encoded_rtps_submessage: (SecurePrefix, Submessage, SecurePostfix),
receiving_local_participant_crypto_handle: ParticipantCryptoHandle,
sending_remote_participant_crypto_handle: ParticipantCryptoHandle,
) -> SecurityResult<DecodeOutcome<DecodedSubmessage>>;
/// decode_serialized_payload: section 8.5.1.9.9 of the Security specification
/// (v. 1.1)
///
/// Return the (fragment of the) serialized payload that would be written in
/// `plain_buffer`
fn decode_serialized_payload(
&self,
encoded_buffer: Vec<u8>,
inline_qos: ParameterList,
receiving_datareader_crypto_handle: DatareaderCryptoHandle,
sending_datawriter_crypto_handle: DatawriterCryptoHandle,
) -> SecurityResult<Vec<u8>>;
}