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

Unified Diff: media/cast/audio_receiver/audio_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/audio_receiver/audio_receiver.cc
diff --git a/media/cast/audio_receiver/audio_receiver.cc b/media/cast/audio_receiver/audio_receiver.cc
index c3dc3937b9acf176364fcc8aa5dbe3a16461da3a..98b897ff929cefd3c88474c10e7c8f5788bfc881 100644
--- a/media/cast/audio_receiver/audio_receiver.cc
+++ b/media/cast/audio_receiver/audio_receiver.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "crypto/symmetric_key.h"
#include "media/cast/audio_receiver/audio_decoder.h"
#include "media/cast/framer/framer.h"
#include "media/cast/rtcp/rtcp.h"
@@ -99,6 +100,18 @@ AudioReceiver::AudioReceiver(scoped_refptr<CastEnvironment> cast_environment,
} else {
audio_decoder_ = new AudioDecoder(audio_config);
}
+ if (audio_config.aes_iv_mask.size() == kAesKeySize &&
+ audio_config.aes_key.size() == kAesKeySize) {
+ iv_mask_ = audio_config.aes_iv_mask;
+ crypto::SymmetricKey* key = crypto::SymmetricKey::Import(
+ crypto::SymmetricKey::AES, audio_config.aes_key);
+ decryptor_.reset(new crypto::Encryptor());
+ decryptor_->Init(key, crypto::Encryptor::CTR, std::string());
+ } else if (audio_config.aes_iv_mask.size() != 0 ||
+ audio_config.aes_iv_mask.size() != 0) {
Alpha Left Google 2013/11/08 22:40:02 Do you mean audio_config.aes_key.size() here?
pwestin 2013/11/12 22:07:23 Done.
+ DCHECK(false) << "Invalid crypto configuration";
+ }
+
rtp_receiver_.reset(new RtpReceiver(cast_environment->Clock(),
&audio_config,
NULL,
@@ -135,8 +148,24 @@ void AudioReceiver::IncomingParsedRtpPacket(const uint8* payload_data,
if (audio_decoder_) {
DCHECK(!audio_buffer_) << "Invalid internal state";
- audio_decoder_->IncomingParsedRtpPacket(payload_data, payload_size,
- rtp_header);
+ if (decryptor_) {
+ // TODO(pwestin): we need to change to 32 bits frame id.
+ decryptor_->SetCounter(GetAesNounce(rtp_header.frame_id, iv_mask_));
+ std::string plaintext;
+ if (decryptor_->Decrypt(
+ base::StringPiece(reinterpret_cast<const char*>(payload_data),
Alpha Left Google 2013/11/08 22:40:02 nit: this should be indented by 4 spaces.
pwestin 2013/11/12 22:07:23 Done.
+ payload_size), &plaintext)) {
Alpha Left Google 2013/11/08 22:40:02 payload_size should align with reinterpret_cast ab
pwestin 2013/11/12 22:07:23 Done.
+ audio_decoder_->IncomingParsedRtpPacket(
+ reinterpret_cast<const uint8*>(plaintext.data()), plaintext.size(),
Alpha Left Google 2013/11/08 22:40:02 Can you add a new method to AudioDecoder takes a s
pwestin 2013/11/12 22:07:23 Dont think that is a good idea it will only move o
+ rtp_header);
+ } else {
+ DCHECK(false) << "Decryption error";
+ return;
+ }
+ } else {
+ audio_decoder_->IncomingParsedRtpPacket(payload_data, payload_size,
+ rtp_header);
+ }
return;
}
DCHECK(audio_buffer_) << "Invalid internal state";
@@ -209,6 +238,14 @@ void AudioReceiver::PlayoutTimeout() {
VLOG(1) << "Failed to retrieved a complete frame at this point in time";
return;
}
+
+ if (decryptor_) {
+ if (!DecryptAudioFrame(&encoded_frame)) {
+ DCHECK(false) << "Decryption error";
+ return;
+ }
+ }
+
if (PostEncodedAudioFrame(queued_encoded_callbacks_.front(), rtp_timestamp,
next_frame, &encoded_frame)) {
// Call succeed remove callback from list.
@@ -231,6 +268,12 @@ void AudioReceiver::GetEncodedAudioFrame(
queued_encoded_callbacks_.push_back(callback);
return;
}
+ if (decryptor_) {
+ if (!DecryptAudioFrame(&encoded_frame)) {
+ DCHECK(false) << "Decryption error";
+ return;
+ }
+ }
if (!PostEncodedAudioFrame(callback, rtp_timestamp, next_frame,
&encoded_frame)) {
// We have an audio frame; however we are missing packets and we have time
@@ -314,6 +357,27 @@ base::TimeTicks AudioReceiver::GetPlayoutTime(base::TimeTicks now,
now;
}
+bool AudioReceiver::DecryptAudioFrame(
+ scoped_ptr<EncodedAudioFrame>* audio_frame) {
+ DCHECK(decryptor_) << "Invalid state";
+
+ scoped_ptr<EncodedAudioFrame> decrypted_audio_frame(
+ new EncodedAudioFrame());
+
+ // TODO(pwestin): the frame id must be a 32 bit number.
+ decryptor_->SetCounter(GetAesNounce((*audio_frame)->frame_id, iv_mask_));
+
+ if (!decryptor_->Decrypt((*audio_frame)->data,
+ &decrypted_audio_frame->data)) {
+ return false;
+ }
+ decrypted_audio_frame->codec = (*audio_frame)->codec;
+ decrypted_audio_frame->frame_id = (*audio_frame)->frame_id;
+
+ audio_frame->swap(decrypted_audio_frame);
+ return true;
+}
+
void AudioReceiver::ScheduleNextRtcpReport() {
base::TimeDelta time_to_send = rtcp_->TimeToSendNextRtcpReport() -
cast_environment_->Clock()->NowTicks();

Powered by Google App Engine
This is Rietveld 408576698