Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Unified Diff: media/cast/video_receiver/video_receiver.cc

Issue 62843002: Cast: Added support for AES-CTR crypto. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/cast/video_receiver/video_receiver.cc
diff --git a/media/cast/video_receiver/video_receiver.cc b/media/cast/video_receiver/video_receiver.cc
index 03ec0ea9565519fb4fbce52c552fa6b33246537e..d398331339f7a936f51e1cde0676639a5ee758e7 100644
--- a/media/cast/video_receiver/video_receiver.cc
+++ b/media/cast/video_receiver/video_receiver.cc
@@ -5,9 +5,11 @@
#include "media/cast/video_receiver/video_receiver.h"
#include <algorithm>
+
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "crypto/symmetric_key.h"
#include "media/cast/cast_defines.h"
#include "media/cast/framer/framer.h"
#include "media/cast/video_receiver/video_decoder.h"
@@ -125,6 +127,18 @@ VideoReceiver::VideoReceiver(scoped_refptr<CastEnvironment> cast_environment,
video_config.max_frame_rate / 1000;
DCHECK(max_unacked_frames) << "Invalid argument";
+ if (video_config.aes_iv_mask.size() == kAesKeySize &&
+ video_config.aes_key.size() == kAesKeySize) {
+ iv_mask_ = video_config.aes_iv_mask;
+ crypto::SymmetricKey* key = crypto::SymmetricKey::Import(
+ crypto::SymmetricKey::AES, video_config.aes_key);
+ decryptor_.reset(new crypto::Encryptor());
+ decryptor_->Init(key, crypto::Encryptor::CTR, std::string());
+ } else if (video_config.aes_iv_mask.size() != 0 ||
+ video_config.aes_key.size() != 0) {
+ DCHECK(false) << "Invalid crypto configuration";
+ }
+
framer_.reset(new Framer(cast_environment->Clock(),
incoming_payload_feedback_.get(),
video_config.incoming_ssrc,
@@ -200,6 +214,30 @@ void VideoReceiver::DecodeVideoFrameThread(
}
}
+bool VideoReceiver::DecryptVideoFrame(
+ scoped_ptr<EncodedVideoFrame>* video_frame) {
+ DCHECK(decryptor_) << "Invalid state";
+
+ scoped_ptr<EncodedVideoFrame> decrypted_video_frame(
+ new EncodedVideoFrame());
+
+ // TODO(pwestin): the frame id must be a 32 bit number.
+ decryptor_->SetCounter(GetAesNounce((*video_frame)->frame_id, iv_mask_));
+
+ if (!decryptor_->Decrypt((*video_frame)->data,
+ &decrypted_video_frame->data)) {
+ return false;
+ }
+ decrypted_video_frame->codec = (*video_frame)->codec;
+ decrypted_video_frame->key_frame = (*video_frame)->key_frame;
+ decrypted_video_frame->frame_id = (*video_frame)->frame_id;
+ decrypted_video_frame->last_referenced_frame_id =
+ (*video_frame)->last_referenced_frame_id;
+
+ video_frame->swap(decrypted_video_frame);
+ return true;
+}
+
// Called from the main cast thread.
void VideoReceiver::GetEncodedVideoFrame(
const VideoFrameEncodedCallback& callback) {
@@ -213,6 +251,14 @@ void VideoReceiver::GetEncodedVideoFrame(
queued_encoded_callbacks_.push_back(callback);
return;
}
+
+ if (decryptor_) {
+ if (!DecryptVideoFrame(&encoded_frame)) {
+ DCHECK(false) << "Decryption error";
+ return;
+ }
+ }
+
base::TimeTicks render_time;
if (PullEncodedVideoFrame(rtp_timestamp, next_frame, &encoded_frame,
&render_time)) {
@@ -293,6 +339,13 @@ void VideoReceiver::PlayoutTimeout() {
VLOG(1) << "PlayoutTimeout retrieved frame "
<< static_cast<int>(encoded_frame->frame_id);
+ if (decryptor_) {
+ if (!DecryptVideoFrame(&encoded_frame)) {
+ DCHECK(false) << "Decryption error";
+ return;
+ }
+ }
+
base::TimeTicks render_time;
if (PullEncodedVideoFrame(rtp_timestamp, next_frame, &encoded_frame,
&render_time)) {

Powered by Google App Engine
This is Rietveld 408576698