| 2237 | } |
| 2238 | |
| 2239 | bool CryptoBuiltInImpl::decode_serialized_payload( |
| 2240 | DDS::OctetSeq& plain_buffer, |
| 2241 | const DDS::OctetSeq& encoded_buffer, |
| 2242 | const DDS::OctetSeq& /*inline_qos*/, |
| 2243 | DatareaderCryptoHandle receiving_datareader_crypto, |
| 2244 | DatawriterCryptoHandle sending_datawriter_crypto, |
| 2245 | SecurityException& ex) |
| 2246 | { |
| 2247 | // Not currently requring a reader handle here, origin authentication |
| 2248 | // for data payloads is not supported. |
| 2249 | // if (DDS::HANDLE_NIL == receiving_datareader_crypto) { |
| 2250 | // return CommonUtilities::set_security_error(ex, -1, 0, "Invalid Datareader handle"); |
| 2251 | // } |
| 2252 | if (DDS::HANDLE_NIL == sending_datawriter_crypto) { |
| 2253 | return CommonUtilities::set_security_error(ex, -1, 0, "Invalid Datawriter handle"); |
| 2254 | } |
| 2255 | |
| 2256 | if (security_debug.encdec_debug) { |
| 2257 | ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {encdec_debug} CryptoBuiltInImpl::decode_serialized_payload ") |
| 2258 | ACE_TEXT("Sending DWCH is %u, Receiving DRCH is %u\n"), |
| 2259 | sending_datawriter_crypto, receiving_datareader_crypto)); |
| 2260 | } |
| 2261 | |
| 2262 | ACE_Guard<ACE_Thread_Mutex> guard(mutex_); |
| 2263 | const KeyTable_t::const_iterator iter = keys_.find(sending_datawriter_crypto); |
| 2264 | if (iter == keys_.end()) { |
| 2265 | return CommonUtilities::set_security_error(ex, -1, 1, "No key for DataWriter crypto handle"); |
| 2266 | } |
| 2267 | const EncryptOptions_t::const_iterator eo_iter = encrypt_options_.find(sending_datawriter_crypto); |
| 2268 | if (eo_iter == encrypt_options_.end()) { |
| 2269 | return CommonUtilities::set_security_error(ex, -1, 0, "Datawriter handle lacks encrypt options"); |
| 2270 | } |
| 2271 | if (!eo_iter->second.payload_) { |
| 2272 | plain_buffer = encoded_buffer; |
| 2273 | if (security_debug.encdec_debug) { |
| 2274 | ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {encdec_debug} CryptoBuiltInImpl::decode_serialized_payload ") |
| 2275 | ACE_TEXT("Sending datawriter isn't encrypting as far as we know, returning input as plaintext\n"), |
| 2276 | sending_datawriter_crypto, receiving_datareader_crypto)); |
| 2277 | } |
| 2278 | return true; |
| 2279 | } |
| 2280 | |
| 2281 | ACE_Message_Block mb_in(to_mb(encoded_buffer.get_buffer()), |
| 2282 | encoded_buffer.length()); |
| 2283 | mb_in.wr_ptr(encoded_buffer.length()); |
| 2284 | Serializer de_ser(&mb_in, common_encoding); |
| 2285 | CryptoHeader ch = CryptoHeader(); |
| 2286 | if (!(de_ser >> ch)) { |
| 2287 | return CommonUtilities::set_security_error(ex, -3, 4, "Failed to deserialize CryptoHeader"); |
| 2288 | } |
| 2289 | |
| 2290 | const KeySeq& keyseq = iter->second; |
| 2291 | for (unsigned int i = 0; i < keyseq.length(); ++i) { |
| 2292 | if (matches(keyseq[i], ch)) { |
| 2293 | const KeyId_t sKey = std::make_pair(sending_datawriter_crypto, i); |
| 2294 | if (encrypts(keyseq[i])) { |
| 2295 | ACE_CDR::ULong n; |
| 2296 | if (!(de_ser >> n)) { |
no test coverage detected