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

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: Fixed nits 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..56e51678585e46c4437969668c6b9486f00dbcb4 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,19 @@ 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() == kAesBlockSize * 2 &&
+ video_config.aes_key.size() == kAesBlockSize * 2) {
+ iv_mask_ = ConvertFromBase16String(video_config.aes_iv_mask);
+ crypto::SymmetricKey* key = crypto::SymmetricKey::Import(
+ crypto::SymmetricKey::AES,
+ ConvertFromBase16String(video_config.aes_key));
Alpha Left Google 2013/11/07 01:10:11 Again don't do the conversion in this low level st
pwestin 2013/11/07 17:16:04 Done.
+ encryptor_.reset(new crypto::Encryptor());
+ encryptor_->Init(key, crypto::Encryptor::CTR, std::string());
+ } else if (video_config.aes_iv_mask.size() != 0 ||
+ video_config.aes_iv_mask.size() != 0) {
+ DCHECK(false) << "Invalid crypto configuration";
+ }
+
framer_.reset(new Framer(cast_environment->Clock(),
incoming_payload_feedback_.get(),
video_config.incoming_ssrc,
@@ -200,6 +215,23 @@ void VideoReceiver::DecodeVideoFrameThread(
}
}
+bool VideoReceiver::DecryptVideoFrame(
+ const EncodedVideoFrame* encrypted_frame,
+ EncodedVideoFrame* video_frame) {
+ DCHECK(encryptor_) << "Invalid state";
+
+ // TODO(pwestin): the frame id must be a 32 bit number.
+ encryptor_->SetCounter(GetAesNounce(encrypted_frame->frame_id, iv_mask_));
+
+ video_frame->codec = encrypted_frame->codec;
+ video_frame->key_frame = encrypted_frame->key_frame;
+ video_frame->frame_id = encrypted_frame->frame_id;
+ video_frame->last_referenced_frame_id =
+ encrypted_frame->last_referenced_frame_id;
+
+ return encryptor_->Decrypt(encrypted_frame->data, &video_frame->data);
+}
+
// Called from the main cast thread.
void VideoReceiver::GetEncodedVideoFrame(
const VideoFrameEncodedCallback& callback) {
@@ -213,6 +245,18 @@ void VideoReceiver::GetEncodedVideoFrame(
queued_encoded_callbacks_.push_back(callback);
return;
}
+
+ if (encryptor_) {
+ EncodedVideoFrame* decrypted_video_frame = new EncodedVideoFrame();
Alpha Left Google 2013/11/07 01:10:11 This should be a scoped_ptr<T>.
pwestin 2013/11/07 17:16:04 Done.
+
+ if (DecryptVideoFrame(encoded_frame.get(), decrypted_video_frame)) {
+ encoded_frame.reset(decrypted_video_frame);
+ } else {
+ DCHECK(false) << "Decryption error";
+ return;
+ }
+ }
+
base::TimeTicks render_time;
if (PullEncodedVideoFrame(rtp_timestamp, next_frame, &encoded_frame,
&render_time)) {
@@ -293,6 +337,18 @@ void VideoReceiver::PlayoutTimeout() {
VLOG(1) << "PlayoutTimeout retrieved frame "
<< static_cast<int>(encoded_frame->frame_id);
+ if (encryptor_) {
+ EncodedVideoFrame* decrypted_video_frame = new EncodedVideoFrame();
Alpha Left Google 2013/11/07 01:10:11 Same here, use scoped_ptr<T>.
pwestin 2013/11/07 17:16:04 Done.
+
+ if (DecryptVideoFrame(encoded_frame.get(), decrypted_video_frame)) {
+ encoded_frame.reset(decrypted_video_frame);
+ } else {
+ DCHECK(false) << "Decryption error";
+ delete decrypted_video_frame;
+ return;
+ }
+ }
+
base::TimeTicks render_time;
if (PullEncodedVideoFrame(rtp_timestamp, next_frame, &encoded_frame,
&render_time)) {

Powered by Google App Engine
This is Rietveld 408576698