Commit graph

1062 commits

Author SHA1 Message Date
Erik Boasson
f139dbcd5e MS C++ is troubled by C99 compound literals
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-18 17:31:20 +01:00
Erik Boasson
e1201e678d Minor cleanup of UDP, TCP support code
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-18 17:31:20 +01:00
Erik Boasson
0b9ab17018 Do not set DCPSParticipant listener too early
The participant listener creates a pong writer, setting a publication
matched listener on it.  That listener can be invoked immediately and as
it queries the subscriptions reader, it must not be enabled before the
latter reader has been created.

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-18 17:31:20 +01:00
Erik Boasson
4df38f5bf9 Move all socket creation stuff to transport code
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-18 17:31:20 +01:00
Erik Boasson
59459b9b8b Change PrismTech references to Adlink
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-18 17:31:20 +01:00
Erik Boasson
89001a0f6a Remove unused PrismTech/Adlink-specials
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-18 17:31:20 +01:00
Erik Boasson
77c3545f5e Move all time support to ddsrt
* Move wctime, mtime, etime types to ddsrt

* Add ddsrt_time_wallclock

* Change ddsrt_time_monontic, elapsed to use mtime, etime types

* Remove now, now_mt, now_et

* Rename X_to_sec_usec to ddsrt_X_to_sec_usec

* add_duration_to_X to ddsrt_X_add_duration (to be in line with the
  existing ddsrt_time_add_duration)

* elimination of ddsrt/timeconv.h, it added more in the way of
  complications than it did in making things more elegant

* rename of q_time.[ch] to ddsi_time.[ch]: that now only deals with DDSI
  timestamps and durations on the wire

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-18 17:31:20 +01:00
Erik Boasson
1611adc20a Replace T_SECOND etc. by DDS_ equivalents
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-18 17:31:20 +01:00
Erik Boasson
763ed67958 Replace T_NEVER by DDS_NEVER, DDS_INFINITY
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-18 17:31:20 +01:00
Erik Boasson
39c7997c67 Remove unused dds_sleepuntil
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-18 17:31:20 +01:00
Dennis Potman
3ea2cea318
Code formatting fixes and clean-up authentication plugin (#439)
* Fix code formatting, fix for memory leak in validate_handshake_reply_token and
make error handling and return values more consistent with the other two
plugins.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Processed review comments: fixed memory leaks and more consistent error handling and function returns

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Fix trusted ca dir max exceeded

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-18 10:01:20 +01:00
Erik Boasson
0354b42cdc Check for permissions handle by testing for != 0
The test gates access-control plugin invocation and with the inverted
condition all remote readers/writers requiring access control are
blocked eiter because of the permissions handle, or because a NIL handle
is passed to the access control plugin.

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-16 09:24:20 +01:00
Erik Boasson
4a6b134126 Fix passing of "relay_only" in check/register reader
* access-control check_remote_datareader has "relay_only" as an out
  parameter, so should pass in an address instead of "false";

* value of "relay_only" returned by check_remote_datareader must be
  passed to crypto register_matched_remote_datareader

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-16 09:24:20 +01:00
Marcel Jordense
6507859f36 Correct handling of identity certificates with EC key
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-03-13 19:24:03 +01:00
Marcel Jordense
f11dd50810 Set volatile secure reader initially out-of-sync
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-03-13 19:24:03 +01:00
Thijs Sassen
269f18e98a Updated version for ros2 package
Signed-off-by: Thijs Sassen <thijs.sassen@adlinktech.com>
2020-03-12 09:37:02 +01:00
Sid Faber
9fe51ef3fb Install security plugins
Security plugins are built but not installed.  Add target to CMakeLists.txt
for three security plugins.

Signed-off-by: Sid Faber <sid.faber@canonical.com>
2020-03-10 15:19:50 +01:00
Dan Rose
2c16dfa23e Don't link winsock1
wsock32.lib is only needed for the legacy version of Winsock and is not needed with Winsock2 (the current version).
This appears to be a root cause of the multicast issue on Win10 and may allow us to reverse #404

Signed-off-by: Dan Rose <dan@digilabs.io>
2020-03-10 10:07:58 +01:00
Erik Boasson
d1ed8df9f3 Create a separate socket for transmitting data
This is a workaround for interoperability issues, ultimately driven by a
Windows quirk that makes multicast delivery within a machine utterly
unreliable if the transmitting socket is bound to 0.0.0.0 (despite all
sockets having multicast interfaces set correctly) when there are also
sockets transmitting to the same multicast group that have been bound to
non-0.0.0.0.  (Note: there may be other factors at play, but this is
what it looks like after experimentation.)

At least Fast-RTPS in some versions binds the socket it uses for
transmitting multicasts to non-0.0.0.0, so interoperability with
Fast-RTPS on Windows requires us to bind the socket we use for
transmitting multicasts (which was the same as the one we use for
receiving unicast data) also to non-0.0.0.0 or our multicasts get
dropped often.

This would work fine if other implementations honoured the set of
advertised addresses.  However, at least Fast-RTPS and Connext (in some
versions) fail to do this and happily substitute 127.0.0.1 for the
advertised IP address.  If we bind to, e.g., 192.168.1.1, then suddenly
those packets won't arrive anymore, breaking interoperability.

The only work around is to use a separate socket for sending.

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-09 20:49:47 +01:00
Erik Boasson
e58f4dc344 Fix macro for checking serdata has get_keyhash
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-05 16:25:36 +01:00
Erik Boasson
ea91e17a62 Rename nn_keyhash to ddsi_keyhash
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-05 16:25:36 +01:00
Erik Boasson
9e673769ce Add "deaf/mute" to pubsub
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-05 16:10:46 +01:00
Erik Boasson
0845337f47 Test interface dropping incoming/outgoing packets
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-05 16:10:46 +01:00
Erik Boasson
9c272c98b8 decode-trace IPv6 support + some minor fixes in it
* IPv6 extensions to patterns
* use full GUID prefix for Cyclone
* pattern fixes to deal with small changes in the formatting of QoS
* suppressinof local built-in topic publications
* asymmetrical disconnect detection improvements (better chance of
  detecting it, plus better suppression of spurious notifications)

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-05 16:10:46 +01:00
Dennis Potman
0a9d391c64 Fixed logging in find_own_ip
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:25:16 +01:00
Marcel Jordense
8ca1780538 Correct problem with cleanup of security handshake
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-03-05 15:25:16 +01:00
Dennis Potman
b8537c0d09 Add test in secure_communication suite to validate that payload/submsg/rtps-msg does not contain secret when using encryption protection kind
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:25:16 +01:00
Dennis Potman
9cc128c295 Remove setting the tracing verbosity in tests and make configs in security core tests more consistent
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:25:16 +01:00
Dennis Potman
e7f5ae354c Fix security handshake test
Isolate domains by using unique tags when running tests that are using security handshake.
And updated coding style and some minor refactoring in fsm and timed_cb tests.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:25:16 +01:00
Dennis Potman
ea10dbd8e1 Fixes in security core tests: add check that all provided vars are used in variable expansion for test configs, add note on concurrency in authentication wrapper, replace assert by cunit assert in crypto wrapper
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:25:16 +01:00
Dennis Potman
8f464e0c99 Fix writer-reader sync in secure_communication tests
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:25:16 +01:00
Dennis Potman
28aa06915e Fixed bug in handshake happy-day test
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:25:16 +01:00
Dennis Potman
6c9e50cf3a Fix for empty trusted CA dir
Trusted CA dir in security configuration is optional, but participant
creation currently fails if no or empty dir is provided. This commit
fixes this issue and adds some tests for various trusted_ca_dir values.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:25:16 +01:00
Dennis Potman
1cf472ea06 Refactored tests for security core: introduced generic wrappers for security plugins and
updated plugin loading tests to use these instead of specific wrappers per test. Added
test for securing communication ad handshake fail (using different identity CAs)

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:25:16 +01:00
Dennis Potman
323de40cba Moved add_definitions in cmake files to /src/ so that all components and tests use the same definitions when compiling sources
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:25:16 +01:00
Dennis Potman
b3c5a8d4fc Refactored expand_vars so that a custom lookup function can be used, which makes it usable for replacing tags by values other than environment variables
Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:25:16 +01:00
eboasson
e412f6fab2
Fix issue in dds_create_topic_arbitrary (#422)
* Fix issue in dds_create_topic_arbitrary

Changed the behaviour of dds_create_topic_arbitrary with respect to the
sertopic parameter: the existing function dds_create_topic_arbitrary is
marked deprecated and replaced by dds_create_topic_generic, which returns
the sertopic that is actually used in as an out parameter. This can be eiter
the provided sertopic (if this sertopic was not yet known in the domain) or an
existing sertopic if the sertopic was registered earlier.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

* Fix memory leaks in case topic creation fails.

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-05 15:21:02 +01:00
eboasson
24e42fd658 Fix a few typos in security documentation
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-03 16:51:16 +01:00
Dennis Potman
7049469289 Update security documentation
An update for the security documentation that is part of the CycloneDDS
manual:
- added openssl commands for creating a set of CA and identity certificates
- code fragment for setting security by qos and example of xml security config
- commands for signing governance and permissions documents using openssl

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>
2020-03-03 16:51:16 +01:00
Erik Boasson
a0b4245600 Fix FSM timeout test race
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-03-03 13:32:38 +01:00
Marcel Jordense
1dad535bc0 Correct misplaced lock
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-03-03 13:32:38 +01:00
Marcel Jordense
4960fbf94c Add security authentication handshake and encoding and decoding
Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
2020-03-03 13:32:38 +01:00
Christophe Bedard
dc57685ac3 Make sure USE_SANITIZER is not empty before foreach
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
2020-02-29 18:18:47 +01:00
Dan Rose
ca4b5a368f Fix undefined behavior when hash function given null pointer
[test_subscriber-12] /opt/ros/master/src/eclipse-cyclonedds/cyclonedds/src/ddsrt/src/mh3.c:28:53: runtime error: applying zero offset to null pointer
[test_subscriber-12] SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /opt/ros/master/src/eclipse-cyclonedds/cyclonedds/src/ddsrt/src/mh3.c:28:53 in
Signed-off-by: Dan Rose <dan@digilabs.io>
2020-02-29 08:48:46 +01:00
Dan Rose
e8b0931798
Don't turn on sanitizers for debug builds by default (#408)
Also, allow multiple sanitizers.
Signed-off-by: Dan Rose <dan@digilabs.io>
2020-02-29 08:38:40 +01:00
Dan Rose
d72ebb0ed3
Don't pass null to memcmp (#413)
* Don't pass null to memcmp

```
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /opt/ros/master/src/ros2/rmw_cyclonedds/rmw_cyclonedds_cpp/include/rmw_cyclonedds_cpp/serdes.hpp:135:3 in
/opt/ros/master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsi/src/ddsi_sertopic_default.c:41:15: runtime error: null pointer passed as argument 1, which is declared to never be null
/usr/include/string.h:64:33: note: nonnull attribute specified here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /opt/ros/master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsi/src/ddsi_sertopic_default.c:41:15 in
/opt/ros/master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsi/src/ddsi_sertopic_default.c:41:31: runtime error: null pointer passed as argument 2, which is declared to never be null
/usr/include/string.h:64:33: note: nonnull attribute specified here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /opt/ros/master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsi/src/ddsi_sertopic_default.c:41:31 in
/opt/ros/master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsi/src/ddsi_sertopic_default.c:45:15: runtime error: null pointer passed as argument 1, which is declared to never be null
/usr/include/string.h:64:33: note: nonnull attribute specified here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /opt/ros/master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsi/src/ddsi_sertopic_default.c:45:15 in
/opt/ros/master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsi/src/ddsi_sertopic_default.c:45:30: runtime error: null pointer passed as argument 2, which is declared to never be null
/usr/include/string.h:64:33: note: nonnull attribute specified here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /opt/ros/master/src/eclipse-cyclonedds/cyclonedds/src/core/ddsi/src/ddsi_sertopic_default.c:45:30 in
```
Signed-off-by: Dan Rose <dan@digilabs.io>

* clearer non-null check

Signed-off-by: Dan Rose <dan@digilabs.io>
2020-02-29 08:32:02 +01:00
Erik Boasson
1ee2dfe08f Avoid race causing thread-state pointer aliasing
The thread_states array resets the "state" to ZERO on thread termination
to indicate that the slot was unused, but it leaves the thread id
unchanged because some platforms don't have a defined value that will
never be used as a thread id.  A consequence is that a newly created
thread may result in multiple slots containing their own thread id, but
generally there will only be one that is not in state ZERO.

However, the code for create_thread used to set the state to ALIVE prior
to creating the thread, and so if the events get scheduled like:

1. thread A: X.state = ALIVE
2. create new thread B, storing tid in X.tid
3. thread A: Y.state = ALIVE
4. new thread B: lookup self (and cache pointer)
5. create new thread C, storing tid in Y.tid
6. new thread C: lookup self (and cache pointer)

Then B will observe two slots in the ALIVE state, with X.tid certain to
match and Y.tid undefined (and hence possibly matching).  It may
therefore pick Y.  C will (in this schedule) of course always choose Y.
They cache the pointer and never look at X and Y again, except for
updating their virtual clocks.

These virtual clocks are updated non-atomically (by design it is private
to the thread) and so if both B & C use Y they can end up racing each
other in updating the virtual clock and cause the nesting level of the
"awake" state controlling garbage collection to get stuck (or wrap
around, or do other horrible things).  The consequence can be anything,
from a somewhat benign variant where GC effectively stops and some
operations (deleting readers and writers and shutting down) block
forever, to use-after-free and the undefined behaviour that implies.

This commit avoids looking up the slot in the newly created threads,
instead passing the correct address in the argument.  It also adds an
intermediate state INIT that serves to reserve the slot until the new
thread is actually running.  It does make the look-up safe (if one were
to do it), and as it is essentially free and gives more insight in the
state of the system when viewed from a debugger, it appears a useful
addition.

Signed-off-by: Erik Boasson <eb@ilities.com>
2020-02-28 08:13:31 +01:00
Dan Rose
6e0faae196 Fix warning -Wimplicit-int-float-conversion
```
/opt/ros/master/src/eclipse-cyclonedds/cyclonedds/src/tools/pubsub/common.c:586:28: warning: implicit conversion from 'long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-int-float-conversion]
    if(nanosec > nextafter(INT64_MAX, 0)) {
                 ~~~~~~~~~ ^~~~~~~~~
/usr/include/stdint.h:134:22: note: expanded from macro 'INT64_MAX'
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/stdint.h:116:24: note: expanded from macro '__INT64_C'
                        ^~~~~~
<scratch space>:345:1: note: expanded from here
9223372036854775807L
^~~~~~~~~~~~~~~~~~~~
1 warning generated.
```

Signed-off-by: Dan Rose <dan@digilabs.io>
2020-02-25 19:20:33 +01:00
Erik Boasson
1c77aad39c Fix Clang static analyzer warnings
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-02-24 15:59:00 +01:00
Erik Boasson
0d5a8bf461 Remove built-in crypto plugin unused variables
Signed-off-by: Erik Boasson <eb@ilities.com>
2020-02-24 15:59:00 +01:00