| 1394 | } |
| 1395 | |
| 1396 | bool CryptoBuiltInImpl::encode_submessage( |
| 1397 | DDS::OctetSeq& encoded_rtps_submessage, |
| 1398 | const DDS::OctetSeq& plain_rtps_submessage, |
| 1399 | NativeCryptoHandle sender_handle, |
| 1400 | SecurityException& ex) |
| 1401 | { |
| 1402 | const KeyTable_t::const_iterator iter = keys_.find(sender_handle); |
| 1403 | if (iter == keys_.end()) { |
| 1404 | encoded_rtps_submessage = plain_rtps_submessage; |
| 1405 | return true; |
| 1406 | } |
| 1407 | |
| 1408 | const KeySeq& keyseq = iter->second; |
| 1409 | if (!keyseq.length()) { |
| 1410 | encoded_rtps_submessage = plain_rtps_submessage; |
| 1411 | return true; |
| 1412 | } |
| 1413 | |
| 1414 | bool ok; |
| 1415 | CryptoHeader header; |
| 1416 | CryptoFooter footer; |
| 1417 | DDS::OctetSeq out; |
| 1418 | const DDS::OctetSeq* pOut = &plain_rtps_submessage; |
| 1419 | const KeyId_t sKey = std::make_pair(sender_handle, submessage_key_index); |
| 1420 | bool authOnly = false; |
| 1421 | |
| 1422 | if (encrypts(keyseq[submessage_key_index])) { |
| 1423 | ok = encrypt(keyseq[submessage_key_index], sessions_[sKey], plain_rtps_submessage, |
| 1424 | header, footer, out, ex); |
| 1425 | pOut = &out; |
| 1426 | |
| 1427 | } else if (authenticates(keyseq[submessage_key_index])) { |
| 1428 | // the original submessage may have octetsToNextHeader = 0 which isn't |
| 1429 | // legal when appending SEC_POSTFIX, patch in the actual submsg length |
| 1430 | if (setOctetsToNextHeader(out, plain_rtps_submessage)) { |
| 1431 | pOut = &out; |
| 1432 | } |
| 1433 | ok = authtag(keyseq[submessage_key_index], sessions_[sKey], *pOut, |
| 1434 | header, footer, ex); |
| 1435 | authOnly = true; |
| 1436 | |
| 1437 | } else { |
| 1438 | return CommonUtilities::set_security_error(ex, -1, 0, "Key transform kind unrecognized"); |
| 1439 | } |
| 1440 | |
| 1441 | if (!ok) { |
| 1442 | return false; // either encrypt() or authtag() already set 'ex' |
| 1443 | } |
| 1444 | |
| 1445 | size_t size = 0; |
| 1446 | |
| 1447 | size += RTPS::SMHDR_SZ; // prefix submessage header |
| 1448 | serialized_size(common_encoding, size, header); |
| 1449 | const ACE_UINT16 hdrLen = static_cast<ACE_UINT16>(size - RTPS::SMHDR_SZ); |
| 1450 | |
| 1451 | if (!authOnly) { |
| 1452 | size += RTPS::SMHDR_SZ + SEQLEN_SZ; |
| 1453 | } |
nothing calls this directly
no test coverage detected