test/blackbox/BlackboxTestsSecurity.cpp
TEST(BlackBox, BuiltinAuthenticationAndCryptoPlugin_user_data)
{
    PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
    PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

    PropertyPolicy pub_part_property_policy, sub_part_property_policy,
        pub_property_policy, sub_property_policy;

    pub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.plugin",
        "builtin.PKI-DH"));
    pub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.identity_ca",
        "file://" + std::string(certs_path) + "/maincacert.pem"));
    pub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.identity_certificate",
        "file://" + std::string(certs_path) + "/mainpubcert.pem"));
    pub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.private_key",
        "file://" + std::string(certs_path) + "/mainpubkey.pem"));
    pub_part_property_policy.properties().emplace_back(Property("dds.sec.crypto.plugin",
        "builtin.AES-GCM-GMAC"));
    pub_part_property_policy.properties().emplace_back("rtps.participant.rtps_protection_kind", "ENCRYPT");
    pub_property_policy.properties().emplace_back("rtps.endpoint.submessage_protection_kind", "ENCRYPT");
    pub_property_policy.properties().emplace_back("rtps.endpoint.payload_protection_kind", "ENCRYPT");

    writer.history_depth(100).
        userData({ 'a','b','c','d','e' }).
        property_policy(pub_part_property_policy).
        entity_property_policy(pub_property_policy).init();

    ASSERT_TRUE(writer.isInitialized());

    sub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.plugin",
        "builtin.PKI-DH"));
    sub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.identity_ca",
        "file://" + std::string(certs_path) + "/maincacert.pem"));
    sub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.identity_certificate",
        "file://" + std::string(certs_path) + "/mainsubcert.pem"));
    sub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.private_key",
        "file://" + std::string(certs_path) + "/mainsubkey.pem"));
    sub_part_property_policy.properties().emplace_back(Property("dds.sec.crypto.plugin",
        "builtin.AES-GCM-GMAC"));
    sub_part_property_policy.properties().emplace_back("rtps.participant.rtps_protection_kind", "ENCRYPT");
    sub_property_policy.properties().emplace_back("rtps.endpoint.submessage_protection_kind", "ENCRYPT");
    sub_property_policy.properties().emplace_back("rtps.endpoint.payload_protection_kind", "ENCRYPT");

    reader.setOnDiscoveryFunction([&writer](const ParticipantDiscoveryInfo& info) -> bool
    {
        if (info.info.m_guid == writer.participant_guid())
        {
            std::cout << "Received USER_DATA from the writer: ";
            for (auto i : info.info.m_userData) std::cout << i << ' ';
            return info.info.m_userData == std::vector<octet>({ 'a','b','c','d','e' });
        }

        return false;
    });

    reader.history_depth(100).
        reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS).
        property_policy(sub_part_property_policy).
        entity_property_policy(sub_property_policy).init();

    ASSERT_TRUE(reader.isInitialized());

    // Wait for authorization
    reader.waitAuthorized();
    writer.waitAuthorized();

    reader.wait_discovery();
    writer.wait_discovery();

    reader.wait_discovery_result();
}
// Regression test of Refs #2457, Github ros2 #438.
Regression test of Refs #2457, Github ros2 #438.
Regression test of Refs #2457 Github ros2 #438 .
TEST(BlackBox, BuiltinAuthenticationAndCryptoPlugin_user_data)
{
    PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
    PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);
    PropertyPolicy pub_part_property_policy, sub_part_property_policy,
        pub_property_policy, sub_property_policy;
    pub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.plugin",
        "builtin.PKI-DH"));
    pub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.identity_ca",
        "file://" + std::string(certs_path) + "/maincacert.pem"));
    pub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.identity_certificate",
        "file://" + std::string(certs_path) + "/mainpubcert.pem"));
    pub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.private_key",
        "file://" + std::string(certs_path) + "/mainpubkey.pem"));
    pub_part_property_policy.properties().emplace_back(Property("dds.sec.crypto.plugin",
        "builtin.AES-GCM-GMAC"));
    pub_part_property_policy.properties().emplace_back("rtps.participant.rtps_protection_kind", "ENCRYPT");
    pub_property_policy.properties().emplace_back("rtps.endpoint.submessage_protection_kind", "ENCRYPT");
    pub_property_policy.properties().emplace_back("rtps.endpoint.payload_protection_kind", "ENCRYPT");
    writer.history_depth(100).
        userData({ 'a','b','c','d','e' }).
        property_policy(pub_part_property_policy).
        entity_property_policy(pub_property_policy).init();
    ASSERT_TRUE(writer.isInitialized());
    sub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.plugin",
        "builtin.PKI-DH"));
    sub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.identity_ca",
        "file://" + std::string(certs_path) + "/maincacert.pem"));
    sub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.identity_certificate",
        "file://" + std::string(certs_path) + "/mainsubcert.pem"));
    sub_part_property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.private_key",
        "file://" + std::string(certs_path) + "/mainsubkey.pem"));
    sub_part_property_policy.properties().emplace_back(Property("dds.sec.crypto.plugin",
        "builtin.AES-GCM-GMAC"));
    sub_part_property_policy.properties().emplace_back("rtps.participant.rtps_protection_kind", "ENCRYPT");
    sub_property_policy.properties().emplace_back("rtps.endpoint.submessage_protection_kind", "ENCRYPT");
    sub_property_policy.properties().emplace_back("rtps.endpoint.payload_protection_kind", "ENCRYPT");
    reader.setOnDiscoveryFunction([&writer](const ParticipantDiscoveryInfo& info) -> bool
    {
        if (info.info.m_guid == writer.participant_guid())
        {
            std::cout << "Received USER_DATA from the writer: ";
            for (auto i : info.info.m_userData) std::cout << i << ' ';
            return info.info.m_userData == std::vector<octet>({ 'a','b','c','d','e' });
        }
        return false;
    });
    reader.history_depth(100).
        reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS).
        property_policy(sub_part_property_policy).
        entity_property_policy(sub_property_policy).init();
    ASSERT_TRUE(reader.isInitialized());
    reader.waitAuthorized();
    writer.waitAuthorized();
    reader.wait_discovery();
    writer.wait_discovery();
    reader.wait_discovery_result();
}
TEST ( BlackBox , BuiltinAuthenticationAndCryptoPlugin_user_data ) { PubSubReader < HelloWorldType > reader ( TEST_TOPIC_NAME ) ; PubSubWriter < HelloWorldType > writer ( TEST_TOPIC_NAME ) ; PropertyPolicy pub_part_property_policy , sub_part_property_policy , pub_property_policy , sub_property_policy ; pub_part_property_policy . properties ( ) . emplace_back ( Property ( " " , " " ) ) ; pub_part_property_policy . properties ( ) . emplace_back ( Property ( " " , " " + std :: string ( certs_path ) + " " ) ) ; pub_part_property_policy . properties ( ) . emplace_back ( Property ( " " , " " + std :: string ( certs_path ) + " " ) ) ; pub_part_property_policy . properties ( ) . emplace_back ( Property ( " " , " " + std :: string ( certs_path ) + " " ) ) ; pub_part_property_policy . properties ( ) . emplace_back ( Property ( " " , " " ) ) ; pub_part_property_policy . properties ( ) . emplace_back ( " " , " " ) ; pub_property_policy . properties ( ) . emplace_back ( " " , " " ) ; pub_property_policy . properties ( ) . emplace_back ( " " , " " ) ; writer . history_depth ( 100 ) . userData ( { ' ' , ' ' , ' ' , ' ' , ' ' } ) . property_policy ( pub_part_property_policy ) . entity_property_policy ( pub_property_policy ) . init ( ) ; ASSERT_TRUE ( writer . isInitialized ( ) ) ; sub_part_property_policy . properties ( ) . emplace_back ( Property ( " " , " " ) ) ; sub_part_property_policy . properties ( ) . emplace_back ( Property ( " " , " " + std :: string ( certs_path ) + " " ) ) ; sub_part_property_policy . properties ( ) . emplace_back ( Property ( " " , " " + std :: string ( certs_path ) + " " ) ) ; sub_part_property_policy . properties ( ) . emplace_back ( Property ( " " , " " + std :: string ( certs_path ) + " " ) ) ; sub_part_property_policy . properties ( ) . emplace_back ( Property ( " " , " " ) ) ; sub_part_property_policy . properties ( ) . emplace_back ( " " , " " ) ; sub_property_policy . properties ( ) . emplace_back ( " " , " " ) ; sub_property_policy . properties ( ) . emplace_back ( " " , " " ) ; reader . setOnDiscoveryFunction ( [ & writer ] ( const ParticipantDiscoveryInfo & info ) -> bool { if ( info . info . m_guid == writer . participant_guid ( ) ) { std :: cout << " " ; for ( auto i : info . info . m_userData ) std :: cout << i << ' ' ; return info . info . m_userData == std :: vector < octet > ( { ' ' , ' ' , ' ' , ' ' , ' ' } ) ; } return false ; } ) ; reader . history_depth ( 100 ) . reliability ( eprosima :: fastrtps :: RELIABLE_RELIABILITY_QOS ) . property_policy ( sub_part_property_policy ) . entity_property_policy ( sub_property_policy ) . init ( ) ; ASSERT_TRUE ( reader . isInitialized ( ) ) ; reader . waitAuthorized ( ) ; writer . waitAuthorized ( ) ; reader . wait_discovery ( ) ; writer . wait_discovery ( ) ; reader . wait_discovery_result ( ) ; }
Regression test of Refs #2457, Github ros2 #438.
Regression test of Refs #2457 Github ros2 #438 .
// Wait for authorization