| 1485 | } |
| 1486 | |
| 1487 | bool CryptoBuiltInImpl::encode_datawriter_submessage( |
| 1488 | DDS::OctetSeq& encoded_rtps_submessage, |
| 1489 | const DDS::OctetSeq& plain_rtps_submessage, |
| 1490 | DatawriterCryptoHandle sending_datawriter_crypto, |
| 1491 | const DatareaderCryptoHandleSeq& receiving_datareader_crypto_list, |
| 1492 | CORBA::Long& receiving_datareader_crypto_list_index, |
| 1493 | SecurityException& ex) |
| 1494 | { |
| 1495 | if (DDS::HANDLE_NIL == sending_datawriter_crypto) { |
| 1496 | return CommonUtilities::set_security_error(ex, -1, 0, "Invalid DataWriter handle"); |
| 1497 | } |
| 1498 | |
| 1499 | if (receiving_datareader_crypto_list_index < 0) { |
| 1500 | return CommonUtilities::set_security_error(ex, -1, 0, "Negative list index"); |
| 1501 | } |
| 1502 | |
| 1503 | const int len = static_cast<int>(receiving_datareader_crypto_list.length()); |
| 1504 | // NOTE: as an extension to the spec, this plugin allows an empty list in the |
| 1505 | // case where the writer is sending to all associated readers. |
| 1506 | if (len && receiving_datareader_crypto_list_index >= len) { |
| 1507 | return CommonUtilities::set_security_error(ex, -1, 0, "List index too large"); |
| 1508 | } |
| 1509 | |
| 1510 | for (unsigned int i = 0; i < receiving_datareader_crypto_list.length(); ++i) { |
| 1511 | if (receiving_datareader_crypto_list[i] == DDS::HANDLE_NIL) { |
| 1512 | return CommonUtilities::set_security_error(ex, -1, 0, "Invalid DataReader handle in list"); |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | NativeCryptoHandle encode_handle = sending_datawriter_crypto; |
| 1517 | ACE_Guard<ACE_Thread_Mutex> guard(mutex_); |
| 1518 | const EncryptOptions_t::const_iterator eo_iter = encrypt_options_.find(encode_handle); |
| 1519 | if (eo_iter == encrypt_options_.end()) { |
| 1520 | return CommonUtilities::set_security_error(ex, -1, 0, "Datawriter handle lacks encrypt options"); |
| 1521 | } |
| 1522 | |
| 1523 | if (!eo_iter->second.submessage_) { |
| 1524 | encoded_rtps_submessage = plain_rtps_submessage; |
| 1525 | receiving_datareader_crypto_list_index = len; |
| 1526 | return true; |
| 1527 | } |
| 1528 | |
| 1529 | if (receiving_datareader_crypto_list.length() == 1) { |
| 1530 | const KeyTable_t::const_iterator iter = keys_.find(encode_handle); |
| 1531 | if (iter != keys_.end()) { |
| 1532 | const KeySeq& dw_keys = iter->second; |
| 1533 | if (dw_keys.length() == 1 && is_volatile_placeholder(dw_keys[0])) { |
| 1534 | encode_handle = receiving_datareader_crypto_list[0]; |
| 1535 | } |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | const bool ok = encode_submessage(encoded_rtps_submessage, |
| 1540 | plain_rtps_submessage, encode_handle, ex); |
| 1541 | if (ok) { |
| 1542 | receiving_datareader_crypto_list_index = len; |
| 1543 | } |
| 1544 | return ok; |
no test coverage detected