Commit graph

87 commits

Author SHA1 Message Date
Jeroen Koekkoek
b25f10ff33 Add ddsconf to generate md, rnc and xsd configuration documentation
Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
2020-06-25 14:10:11 +02:00
Erik Boasson
ece3a78211 Help clang static analyzer in security tests
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-06-08 15:31:32 +02:00
Erik Boasson
8a748e1868 Fix incorrect cast of size_t* to uint32_t*
CID 304509 - it does not affect behaviour because the called function
uses it as an out parameter and the result is never inspected.

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-06-08 15:31:32 +02:00
Erik Boasson
3705744681 Fix va_end arg in formatting security exception
CID 304494

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-06-08 15:31:32 +02:00
Erik Boasson
ca79eeb7b9 Fix error handling in generating test signatures
Failure to generate a signature for in handshake tests attempted to free
the address of the pointer, instead of the pointed-to memory (CID
304462).

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-06-08 15:31:32 +02:00
Erik Boasson
5588edb33e Move auth plug-in invalid parameter returns forward
Triggered by CID 304462, 304471, 304517: dereference before null check.
Note that it is a second-order problem because it would require the
plug-in functions to be called with a null pointer for the plug-in
instance.

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-06-08 15:31:32 +02:00
Erik Boasson
9c31f48bea Build OpenSSL dependent parts only if present
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-06-05 09:18:46 +02:00
Erik Boasson
6a9ebf88eb OpenSSL 1.0.2 compatibility
This addresses a number of issues with building Cyclone DDS including
DDS Security while using OpenSSL 1.0.2. Compatibility with 1.0.2 is a
courtesy towards those who are unable to move to 1.1.x or later because
of other libraries.

* On Windows, one must include Winsock2.h prior to including the OpenSSL
  header files, or it'll pull in incompatible definitions from Winsock.h
  and that breaks some of the files.

* OpenSSL 1.0.2 requires initializing the library (or more particular,
  loading all the required algorithms) but this is no longer needed in
  OpenSSL 1.1.x. It ends up being needed in a few places and having tons
  of essentially dead initialization code lying around is unpleasant.
  Hence this has been consolidated in a single function and protected
  with ddsrt_once().

* One ought to undo the above initialization on 1.0.2g and older, but it
  is impossible to know whether that can safely be done from a library.
  This is also the reason OpenSSL deprecated all the initialization and
  cleanup interfaces. So if one insists on trying it with such an old
  version, let there be some leaks.

* Thread state cleanup is sort-of required prior 1.1.0, but that suffers
  from the same problems; we'd have to do per-thread cleanup code for
  OpenSSL for any thread that could call into it (which is pretty much
  any thread). So once again, people should just use 1.1.0 or newer.

* There are some interfaces added in 1.1.0 that we use, but a few small
  workarounds those can be made to work on 1.0.2 as well. These also
  were replicated in a number of places and consolidated by this commit.

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-05-25 14:44:24 +02:00
Dennis Potman
cc8308819d Refactor access control test permissions_expiry_multiple to reduce timing issues in test runs on travis
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-20 15:59:15 +02:00
Erik Boasson
2aa70548cc Tweak timeouts in secure communication tests
* Increase the matching timeout to 5s (there are some hints the failures
  on Travis are timing related)
* Replace the relative timeout in the waitset by a timestamp so that it
  gives up after the specified timeout regardless of the number of
  events that occur

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-05-16 11:38:05 +02:00
Erik Boasson
be7f7af741 Tweak timeout handling of authentication tests
* Compute the time at which the handshake must have completed from the
  initial timeout specification, rather than using it as a timeout for
  the individual steps of the handshake
* If the handshake fails because an expected message is not present,
  print this, including whether the timeout occured because the message
  queue was empty or because the expected message could not be found in
  a non-empty queue.
* Replace the 0.5s per-step timeout to a single 2s timeout.

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-05-16 11:38:05 +02:00
Erik Boasson
8fea8d5673 Use C99 flex array member instead of length-1 array
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-05-16 11:38:05 +02:00
Erik Boasson
fa7999c5d8 Vet lengths of property lists in crypto deserialization
The memory allocation in deserializing property lists within the crypto
code should not trust the deserialized length and try to allocate that
much memory but should first verify that the length is consistent with
the number of bytes remaining in the input.  (Noted by Coverity as use
of tainted data.)

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-05-16 11:38:05 +02:00
Erik Boasson
59a2b9d273 Fix double free if local identity validation fails on certificate expiry
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-05-16 11:38:05 +02:00
Erik Boasson
fa6dbe6c3d Memory leak reading access control configuration
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-05-16 11:38:05 +02:00
Dennis Potman
a151c5f184 Processed review comments: added missing return topic_sec_attr in function is_topic_discovery_protected, moved returns-logging in access plugin to wrapper mode and removed specific test for this (as it will be tested in other access control tests now). Some cleanup in circular list usage in crypto and access control plugins
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
32bba389c8 Add test descriptions as code comment in security core tests
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
48e411bb76 Fix rd-wr synchronization in access control expiry_multiple test
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
24594f68fb Add access control test for testing that communication for an allowed topic keeps working when a writer for a denied topic is created
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
edcbe1b22e Add a test that checks if all tokens and attributes are returned to the access control plugin
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
cf75263d1d Add a test that validates that a plain message is not read by a remote reader in case payload/submsg/rtps encryption or signing is enabled
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
6185a5ab2a Add a test to validate that a non-secure participant can connect with a secure participant that allows unauthenticated participants. The non-secure pp should only be able to read data for a topic that is not secured
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
155f8c059d Add read-write protection tests
Introduced a test that checks for the correct matching behavious for  combinations
of the read/write access control settings in the governance xml (enable read/write
access control in the topic rules) and in the permissions xml (the publish/subscribe
grants for a topic).

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
45adb6f0c7 Extend access-control tests with validate_local_permissions
Add validate_local_permissions to the set of access control plugin
hooks tests, and add discovery_protection_enabled as an additional
parameter for the access control hook tests.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
0348bb2741 Security liveliness protection tests
Add testing liveness protection to the existing discovery protection
test. The test checks if the P2P_BUILTIN_PARTICIPANT_MESSAGE_SECURE_WRITER
is using the encode_decode_submessage function of the crypto plugin
to secure liveliness messages.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
231d820052 Add security encoding-mismatch test
A test that checks that the security handshake fails in case of non-matching
encoding settings in the governance xml. All combinations of values for
rtps, discovery and liveliness protection are checked. For meta-data and
payload encoding, this test checks that a reader and writer do not connect
in case of non-matching values.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
9f261423e3 Add tests for discovery protection
Adding a test that checks the effects of using different configuration settings
for discovery protection. This test set uses the cryptography wrapper to count
the number of invocations of the encode and decode functions during a session
and checks the counts with the expected values.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Dennis Potman
fd27604a26 Add crypto token exchange test
Introduced a test that checks if all crypto tokens send by a node are
received correctly by the remote node. To support this test, the crypto
wrapper plugin is extended with a token_log mode, that stores all tokens
that are exchanged after the security handshake is finished.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-05-15 15:35:31 +02:00
Marcel Jordense
e1899df62d Fix incorrect type of include_optional_fields config parameter
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-05-11 15:03:20 +02:00
Marcel Jordense
860f261dc6 Correct generation of the crypto key
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-05-11 15:03:20 +02:00
Marcel Jordense
720c8f8fbf Correct security (de)serialization of QosProperty contained in c.data field of handshake token
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-05-11 15:03:20 +02:00
Marcel Jordense
623a5c02bd Correct handshake tokens verification w.r.t. optional fields
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-05-11 15:03:20 +02:00
Dennis Potman
e8c349f96d Fix condition for setting identity subject in remote rights
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-04-22 17:41:27 +02:00
Dennis Potman
19bc6f33cc Access control tests
Add test cases for the join_access_control governance setting and for
the access control plugin check_create_ and check_remote_ hooks,
using a wrapper plugin that simulates failure for each of these,
to test the DDSI integration with the access control plugin.
This commit also contains fixes for:
- an assert on DDS_RETCODE_OK in dds_create_reader and
dds_create_writer that cased the application to terminate in case
creation of a reader or writer is not allowed by security
- do not match a proxy reader that has the 'relay_only' set to
true, which is currently unsupported

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-04-22 17:41:27 +02:00
Dennis Potman
e8dfbabd0c Add locking when intializing remote key material
The initialization of remote participant's key material was not protected
by the remote_participant_crypto lock, which could result in using partially
initialized remote key material. This caused intermittent test failures
with assertions on key_size in crypto_cipher_decrypt_data. This commit fixes
this issue by adding locking for the remote key material.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-04-16 18:05:06 +02:00
Dennis Potman
dae562c602 Improve delays/timing in permissions_expiry_multiple test
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-04-16 15:30:08 +02:00
Dennis Potman
5e721c99e5 Change test timing and time-outs in access-control and authentication
expiry tests and add timestamps to test logging to get more stable
test results on Travis and enable analysing timeing issues.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-04-16 15:30:08 +02:00
Dennis Potman
e3056402fc Implement on_revoke_identity_cb
Impement the revoke identity callback in ddsi that is called when
the identity certificate of a participant expires. In case the
identity handle that expires is from a local participant, all
proxy pp connections will be dropped for this participant. In case
the identity that expires is from a remote participant, the
corresponding proxy participant is deleted.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-04-16 15:30:08 +02:00
Dennis Potman
736d0a027a Add access control tests for permissions expiry and move some reused test
functions to common utils file.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-04-16 15:30:08 +02:00
Dennis Potman
d53cdce8fe Access Control on_revoke_permissions implementation in DDSI
Implement handler for access control on_revoke_permissions. This callback
function disconnects and deletes all proxy participant that are using the
revoked permissions handle (in case of remote permissions expire) and
proxy participant that are connected with a participant for which the
permissions expire (local permissions expire).

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-04-16 15:30:08 +02:00
Dennis Potman
e6500b6528 Add domaingv pointer to security plugins, as a preparation for supporting the permissions_expiry callback (which needs the gv to enumerate participants.
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-04-16 15:30:08 +02:00
Dennis Potman
a6a9d1f7c1 Security core tests: new tests and refactoring
Refactoring security core tests and adding more tests:
- Dynamically generate ca and identity certificates in authentication tests, so that certificate expiry is tested.
Added writing/reading samples to these tests to ensure that nodes can (or cannot) communicate in a specific test case
- Secure communication tests: improved the validation of encryption in wrapper
- Added test for access control plugin settings
- Replaced the in-code test identities (and included ca private keys), added an additional identity

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-04-16 15:30:08 +02:00
Erik Boasson
1fd4ab290f Do not build security tests if BUILD_IDLC=NO
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-04-10 09:51:35 +02:00
Erik Boasson
eb7e5e3a87 Disallow junk after optional terminator in string/binprop compare
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-04-07 11:40:14 +02:00
Erik Boasson
9c09eca2e9 Do not assume string in algo binary property
Interpretation of the c.dsign_algo and c.kagree_algo properties must not
assume the binary property to be a null-terminated string.

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-04-07 11:40:14 +02:00
Marcel Jordense
b6640d86b0 Correct length of encrypted submessage body
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-04-07 11:39:57 +02:00
Erik Boasson
99df0956e7 Crypto endpoint relation compare routines cleanup
* Trying not to assume an int is at least 32 bits.

* Technically speaking, comparing "unrelated" addresses is undefined
  behaviour which can be avoided by a cast to uintptr_t.

* The early out if either local_crypto == 0 does work in context,
  provided the nodes in tree never have local_crypto == 0.  That implies
  crypto_insert_endpoint_relation must never have a 0 in there, which I
  think the callers do respect.  Still I think it is better to not hide
  these assumptions in the compare function and address the problem in
  the lookup function instead.

These changes likely make the code fractionally slower, but I do think
they improve clarity.

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-04-01 09:39:11 +02:00
Marcel Jordense
9175f44273 Send crypto tokens after handshake is completely finished
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-03-27 16:31:08 +01:00
Marcel Jordense
a77fe10a04 Add index on receiver specific key to improve verification of origin authentication signing
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-03-27 16:31:08 +01:00
Dennis Potman
d03587fcea Add identity bob to default test permissions xml
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-25 10:46:17 +01:00