Skip to content

Commit fd74fc5

Browse files
New property to select preferred key agreement algorithm (#5413) (#5442) (#5444)
* New property to select preferred key agreement algorithm (#5413) * Refs #19921. Implement selection of key agreement. * Refs #19921. Change default to ECDH. * Refs #19921. Add unit test. * Refs #19921. Factor out duplicated publisher code on BB test. * Refs #19921. Factor out duplicated subscriber code on BB test. * Refs #19921. Add new parameter to BB test. * Refs #19921. Apply new parameter on publisher properties. * Refs #19921. Apply new parameter on subscriber properties. * Refs #19921. Improve emplace_back calls. * Refs #19921. Uncrustify. * Refs #22280. Use `DH` alias instead of `RSA`. * Refs #22280. Add new property to communication tests XML profiles. * Refs #22280. Fix unit test. * Refs #22280. Configure key agreement on BB test depending on process id. * Refs #19921. Add `AUTO` value to new option. * Refs #19921. Add `AUTO` value to blackbox test. * Refs #22280. Remove unused lambda capture. * Refs #22280. Fix failing blackbox tests. * Update versions.md --------- (cherry picked from commit 8a99a07) * Fix conflicts. * Change default value to `DH`. --------- Signed-off-by: Miguel Company <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Miguel Company <[email protected]>
1 parent cea1185 commit fd74fc5

12 files changed

+402
-929
lines changed

src/cpp/security/authentication/PKIDH.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
#include <cassert>
5656
#include <algorithm>
57+
#include <utility>
5758

5859
#define S1(x) #x
5960
#define S2(x) S1(x)
@@ -1117,6 +1118,37 @@ ValidationResult_t PKIDH::validate_local_identity(
11171118
password = &empty_password;
11181119
}
11191120

1121+
std::string key_agreement_algorithm = DH_2048_256;
1122+
std::string* key_agreement_property =
1123+
PropertyPolicyHelper::find_property(auth_properties, "preferred_key_agreement");
1124+
if (nullptr != key_agreement_property)
1125+
{
1126+
const std::pair<std::string, std::string> key_agreement_allowed_values[] = {
1127+
{DH_2048_256, DH_2048_256},
1128+
{ECDH_prime256v1, ECDH_prime256v1},
1129+
{"ECDH", ECDH_prime256v1},
1130+
{"DH", DH_2048_256},
1131+
{"AUTO", "AUTO"}
1132+
};
1133+
1134+
key_agreement_algorithm = "";
1135+
for (const auto& allowed_value : key_agreement_allowed_values)
1136+
{
1137+
if (key_agreement_property->compare(allowed_value.first) == 0)
1138+
{
1139+
key_agreement_algorithm = allowed_value.second;
1140+
break;
1141+
}
1142+
}
1143+
1144+
if (key_agreement_algorithm.empty())
1145+
{
1146+
exception = _SecurityException_("Invalid key agreement algorithm '" + *key_agreement_property + "'");
1147+
EMERGENCY_SECURITY_LOGGING("PKIDH", exception.what());
1148+
return ValidationResult_t::VALIDATION_FAILED;
1149+
}
1150+
}
1151+
11201152
PKIIdentityHandle* ih = &PKIIdentityHandle::narrow(*get_identity_handle(exception));
11211153

11221154
(*ih)->store_ = load_identity_ca(*identity_ca, (*ih)->there_are_crls_, (*ih)->sn, (*ih)->algo,
@@ -1126,6 +1158,20 @@ ValidationResult_t PKIDH::validate_local_identity(
11261158
{
11271159
ERR_clear_error();
11281160

1161+
if (key_agreement_algorithm == "AUTO")
1162+
{
1163+
if ((*ih)->algo == RSA_SHA256)
1164+
{
1165+
key_agreement_algorithm = DH_2048_256;
1166+
}
1167+
else
1168+
{
1169+
key_agreement_algorithm = ECDH_prime256v1;
1170+
}
1171+
}
1172+
1173+
(*ih)->kagree_alg_ = key_agreement_algorithm;
1174+
11291175
if (identity_crl != nullptr)
11301176
{
11311177
X509_CRL* crl = load_crl(*identity_crl, exception);
@@ -1332,7 +1378,6 @@ ValidationResult_t PKIDH::begin_handshake_request(
13321378
bproperty.propagate(true);
13331379
(*handshake_handle_aux)->handshake_message_.binary_properties().push_back(std::move(bproperty));
13341380

1335-
// TODO(Ricardo) Only support right now DH+MODP-2048-256
13361381
// c.kagree_algo.
13371382
bproperty.name("c.kagree_algo");
13381383
bproperty.value().assign(lih->kagree_alg_.begin(),
@@ -1702,7 +1747,6 @@ ValidationResult_t PKIDH::begin_handshake_reply(
17021747
bproperty.propagate(true);
17031748
(*handshake_handle_aux)->handshake_message_.binary_properties().push_back(std::move(bproperty));
17041749

1705-
// TODO(Ricardo) Only support right now DH+MODP-2048-256
17061750
// c.kagree_algo.
17071751
bproperty.name("c.kagree_algo");
17081752
bproperty.value().assign((*handshake_handle_aux)->kagree_alg_.begin(),

test/blackbox/common/BlackboxTestsSecurity.cpp

Lines changed: 256 additions & 927 deletions
Large diffs are not rendered by default.

test/dds/communication/security/secure_msg_crypto_besteffort_pub_profile.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
<name>dds.sec.auth.builtin.PKI-DH.private_key</name>
3535
<value>file://mainpubkey.pem</value>
3636
</property>
37+
<property>
38+
<name>dds.sec.auth.builtin.PKI-DH.preferred_key_agreement</name>
39+
<value>ECDH</value>
40+
</property>
3741
<!-- Activate DDS:Crypto:AES-GCM-GMAC plugin -->
3842
<property>
3943
<name>dds.sec.crypto.plugin</name>

test/dds/communication/security/secure_msg_submsg_crypto_besteffort_pub_profile.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
<name>dds.sec.auth.builtin.PKI-DH.private_key</name>
3434
<value>file://mainpubkey.pem</value>
3535
</property>
36+
<property>
37+
<name>dds.sec.auth.builtin.PKI-DH.preferred_key_agreement</name>
38+
<value>DH</value>
39+
</property>
3640
<!-- Activate DDS:Crypto:AES-GCM-GMAC plugin -->
3741
<property>
3842
<name>dds.sec.crypto.plugin</name>

test/dds/communication/security/secure_msg_submsg_crypto_besteffort_sub_profile.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
<name>dds.sec.auth.builtin.PKI-DH.private_key</name>
3434
<value>file://mainsubkey.pem</value>
3535
</property>
36+
<property>
37+
<name>dds.sec.auth.builtin.PKI-DH.preferred_key_agreement</name>
38+
<value>ECDH</value>
39+
</property>
3640
<!-- Activate DDS:Crypto:AES-GCM-GMAC plugin -->
3741
<property>
3842
<name>dds.sec.crypto.plugin</name>

test/dds/communication/security/secure_submsg_crypto_besteffort_pub_profile.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
<name>dds.sec.auth.builtin.PKI-DH.private_key</name>
3434
<value>file://mainpubkey.pem</value>
3535
</property>
36+
<property>
37+
<name>dds.sec.auth.builtin.PKI-DH.preferred_key_agreement</name>
38+
<value>ECDH</value>
39+
</property>
3640
<!-- Activate DDS:Crypto:AES-GCM-GMAC plugin -->
3741
<property>
3842
<name>dds.sec.crypto.plugin</name>

test/dds/communication/security/secure_submsg_crypto_besteffort_sub_profile.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
<name>dds.sec.auth.builtin.PKI-DH.private_key</name>
3434
<value>file://mainsubkey.pem</value>
3535
</property>
36+
<property>
37+
<name>dds.sec.auth.builtin.PKI-DH.preferred_key_agreement</name>
38+
<value>DH</value>
39+
</property>
3640
<!-- Activate DDS:Crypto:AES-GCM-GMAC plugin -->
3741
<property>
3842
<name>dds.sec.crypto.plugin</name>

test/dds/communication/security/simple_secure_besteffort_pub_profile.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<name>dds.sec.auth.builtin.PKI-DH.private_key</name>
2727
<value>file://mainpubkey.pem</value>
2828
</property>
29+
<property>
30+
<name>dds.sec.auth.builtin.PKI-DH.preferred_key_agreement</name>
31+
<value>ECDH</value>
32+
</property>
2933
<!-- Activate Access:Permissions plugin -->
3034
<property>
3135
<name>dds.sec.access.plugin</name>

test/dds/communication/security/simple_secure_besteffort_sub_profile.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<name>dds.sec.auth.builtin.PKI-DH.private_key</name>
2727
<value>file://mainsubkey.pem</value>
2828
</property>
29+
<property>
30+
<name>dds.sec.auth.builtin.PKI-DH.preferred_key_agreement</name>
31+
<value>DH</value>
32+
</property>
2933
<!-- Activate Access:Permissions plugin -->
3034
<property>
3135
<name>dds.sec.access.plugin</name>

test/unittest/security/authentication/AuthenticationPluginTests.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ TEST_F(AuthenticationPluginTest, handshake_process_ok)
166166
ValidationResult_t::VALIDATION_FAILED;
167167

168168
participant_attr.properties = get_valid_policy();
169+
participant_attr.properties.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.preferred_key_agreement", "DH");
169170

170171
result = plugin.validate_local_identity(&local_identity_handle1,
171172
adjusted_participant_key1,

0 commit comments

Comments
 (0)