| 1947 | } |
| 1948 | |
| 1949 | bool CryptoBuiltInImpl::decode_rtps_message( |
| 1950 | DDS::OctetSeq& plain_buffer, |
| 1951 | const DDS::OctetSeq& encoded_buffer, |
| 1952 | ParticipantCryptoHandle receiving_participant_crypto, |
| 1953 | ParticipantCryptoHandle sending_participant_crypto, |
| 1954 | SecurityException& ex) |
| 1955 | { |
| 1956 | if (DDS::HANDLE_NIL == receiving_participant_crypto) { |
| 1957 | return CommonUtilities::set_security_error(ex, -1, 0, "No Receiving Participant handle"); |
| 1958 | } |
| 1959 | if (DDS::HANDLE_NIL == sending_participant_crypto) { |
| 1960 | return CommonUtilities::set_security_error(ex, -1, 1, "No Sending Participant handle"); |
| 1961 | } |
| 1962 | |
| 1963 | RTPS::MessageParser parser(encoded_buffer); |
| 1964 | |
| 1965 | if (!parser.parseHeader()) { |
| 1966 | return CommonUtilities::set_security_error(ex, -2, 0, "Failed to deserialize Header"); |
| 1967 | } |
| 1968 | |
| 1969 | CryptoHeader ch = CryptoHeader(); |
| 1970 | CryptoFooter cf; |
| 1971 | bool haveCryptoHeader = false, haveCryptoFooter = false; |
| 1972 | const char* afterSrtpsPrefix = 0; |
| 1973 | unsigned int sizeOfAuthenticated = 0, sizeOfEncrypted = 0; |
| 1974 | const char* encrypted = 0; |
| 1975 | |
| 1976 | for (int i = 0; parser.remaining(); ++i) { |
| 1977 | if (parser.remaining() < RTPS::SMHDR_SZ || !parser.parseSubmessageHeader()) { |
| 1978 | return CommonUtilities::set_security_error(ex, -3, i, "Failed to deserialize SubmessageHeader"); |
| 1979 | } |
| 1980 | |
| 1981 | parser.serializer().endianness(ENDIAN_BIG); |
| 1982 | const int type = parser.submessageHeader().submessageId; |
| 1983 | |
| 1984 | if (i == 0 && type == RTPS::SRTPS_PREFIX) { |
| 1985 | if (!(parser >> ch)) { |
| 1986 | return CommonUtilities::set_security_error(ex, -4, i, "Failed to deserialize CryptoHeader"); |
| 1987 | } |
| 1988 | haveCryptoHeader = true; |
| 1989 | if (!parser.skipToNextSubmessage()) { |
| 1990 | return CommonUtilities::set_security_error(ex, -5, i, "Failed to find submessage after SRTPS_PREFIX"); |
| 1991 | } |
| 1992 | afterSrtpsPrefix = parser.current(); |
| 1993 | |
| 1994 | } else if (haveCryptoHeader && type == RTPS::SEC_BODY) { |
| 1995 | if (!(parser >> sizeOfEncrypted)) { |
| 1996 | return CommonUtilities::set_security_error(ex, -13, i, "Failed to deserialize CryptoContent length"); |
| 1997 | } |
| 1998 | const unsigned short sz = |
| 1999 | static_cast<unsigned short>(DCPS::uint32_cdr_size); |
| 2000 | if (sizeOfEncrypted + sz > parser.submessageHeader().submessageLength) { |
| 2001 | return CommonUtilities::set_security_error(ex, -14, i, "CryptoContent length out of bounds"); |
| 2002 | } |
| 2003 | encrypted = parser.current(); |
| 2004 | if (!parser.skipToNextSubmessage()) { |
| 2005 | return CommonUtilities::set_security_error(ex, -15, i, "Failed to find submessage after SEC_BODY"); |
| 2006 | } |
no test coverage detected