summaryrefslogtreecommitdiff
path: root/src/lib/dcp_video.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-04-16 23:35:02 +0200
committerCarl Hetherington <cth@carlh.net>2020-04-17 00:42:54 +0200
commit1201f316347d2ea8b09aa89b0c5edaebfaa64c93 (patch)
tree5339d7e78357ed48d72d4e48b3c83e6b8681958a /src/lib/dcp_video.cc
parent3f2bec7b6ee2f27b2de056cdc0137744d2e9e253 (diff)
Checksum network encode requests and replies to protect against
network corruption (#1381).
Diffstat (limited to 'src/lib/dcp_video.cc')
-rw-r--r--src/lib/dcp_video.cc22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/lib/dcp_video.cc b/src/lib/dcp_video.cc
index 9d7ccf565..5416f2ae7 100644
--- a/src/lib/dcp_video.cc
+++ b/src/lib/dcp_video.cc
@@ -165,23 +165,31 @@ DCPVideo::encode_remotely (EncodeServerDescription serv, int timeout)
LOG_DEBUG_ENCODE (N_("Sending frame %1 to remote"), _index);
- /* Send XML metadata */
- string xml = doc.write_to_string ("UTF-8");
- socket->write (xml.length() + 1);
- socket->write ((uint8_t *) xml.c_str(), xml.length() + 1);
+ {
+ Socket::WriteDigestScope ds (socket);
- /* Send binary data */
- LOG_TIMING("start-remote-send thread=%1", thread_id ());
- _frame->write_to_socket (socket);
+ /* Send XML metadata */
+ string xml = doc.write_to_string ("UTF-8");
+ socket->write (xml.length() + 1);
+ socket->write ((uint8_t *) xml.c_str(), xml.length() + 1);
+
+ /* Send binary data */
+ LOG_TIMING("start-remote-send thread=%1", thread_id ());
+ _frame->write_to_socket (socket);
+ }
/* Read the response (JPEG2000-encoded data); this blocks until the data
is ready and sent back.
*/
+ Socket::ReadDigestScope ds (socket);
LOG_TIMING("start-remote-encode thread=%1", thread_id ());
Data e (socket->read_uint32 ());
LOG_TIMING("start-remote-receive thread=%1", thread_id ());
socket->read (e.data().get(), e.size());
LOG_TIMING("finish-remote-receive thread=%1", thread_id ());
+ if (!ds.check()) {
+ throw NetworkError ("Checksums do not match");
+ }
LOG_DEBUG_ENCODE (N_("Finished remotely-encoded frame %1"), _index);