Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_CRYPTO_AES_DECRYPTOR_H_ | 5 #ifndef MEDIA_CRYPTO_AES_DECRYPTOR_H_ |
| 6 #define MEDIA_CRYPTO_AES_DECRYPTOR_H_ | 6 #define MEDIA_CRYPTO_AES_DECRYPTOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/hash_tables.h" | 11 #include "base/hash_tables.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 14 #include "media/base/decryptor.h" | 15 #include "media/base/decryptor.h" |
| 15 #include "media/base/media_export.h" | 16 #include "media/base/media_export.h" |
| 16 | 17 |
| 17 namespace crypto { | 18 namespace crypto { |
| 18 class SymmetricKey; | 19 class SymmetricKey; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| 22 | 23 |
| 23 class DecryptorClient; | 24 class DecryptorClient; |
| 24 | 25 |
| 25 // Decryptor implementation that decrypts AES-encrypted buffer. | 26 // Checks the integrity of the encrypted data and decrypts the AES encrypted |
|
ddorwin
2012/07/10 01:12:20
Eventually, this should be "Optionally..."
fgalligan1
2012/07/11 22:06:33
Done.
| |
| 27 // buffer into an unencrypted buffer. | |
| 26 class MEDIA_EXPORT AesDecryptor : public Decryptor { | 28 class MEDIA_EXPORT AesDecryptor : public Decryptor { |
| 27 public: | 29 public: |
| 30 // The size is from the WebM encrypted specification. Current WebM | |
| 31 // encrypted request for comments specification is here | |
| 32 // http://wiki.webmproject.org/encryption/webm-encryption-rfc | |
| 33 static const int kSha1DigestSize = 20; | |
|
ddorwin
2012/07/10 01:12:20
kWebMSha1DigestSize
Same for 35 and 36. Then 34 sh
fgalligan1
2012/07/11 22:06:33
Added Webm to the consts. Moved the Webm consts to
| |
| 34 static const int kKeySize = 16; | |
| 35 static const char kHmacSeed[]; | |
| 36 static const char kEncryptionSeed[]; | |
| 37 | |
| 28 // The AesDecryptor does not take ownership of the |client|. The |client| | 38 // The AesDecryptor does not take ownership of the |client|. The |client| |
| 29 // must be valid throughout the lifetime of the AesDecryptor. | 39 // must be valid throughout the lifetime of the AesDecryptor. |
| 30 explicit AesDecryptor(DecryptorClient* client); | 40 explicit AesDecryptor(DecryptorClient* client); |
| 31 virtual ~AesDecryptor(); | 41 virtual ~AesDecryptor(); |
| 32 | 42 |
| 33 // Decryptor implementation. | 43 // Decryptor implementation. |
| 34 virtual void GenerateKeyRequest(const std::string& key_system, | 44 virtual void GenerateKeyRequest(const std::string& key_system, |
| 35 const uint8* init_data, | 45 const uint8* init_data, |
| 36 int init_data_length) OVERRIDE; | 46 int init_data_length) OVERRIDE; |
| 37 virtual void AddKey(const std::string& key_system, | 47 virtual void AddKey(const std::string& key_system, |
| 38 const uint8* key, | 48 const uint8* key, |
| 39 int key_length, | 49 int key_length, |
| 40 const uint8* init_data, | 50 const uint8* init_data, |
| 41 int init_data_length, | 51 int init_data_length, |
| 42 const std::string& session_id) OVERRIDE; | 52 const std::string& session_id) OVERRIDE; |
| 43 virtual void CancelKeyRequest(const std::string& key_system, | 53 virtual void CancelKeyRequest(const std::string& key_system, |
| 44 const std::string& session_id) OVERRIDE; | 54 const std::string& session_id) OVERRIDE; |
| 55 | |
| 56 // Check and Decrypt |input| buffer. The |input| should not be NULL. | |
|
xhwang
2012/07/10 06:31:25
"Checks and Decrypts"
fgalligan1
2012/07/11 22:06:33
Done.
| |
| 57 // Return a DecoderBuffer with the decrypted data if the check and | |
|
ddorwin
2012/07/10 01:12:20
*integrity* check
fgalligan1
2012/07/11 22:06:33
Done.
| |
| 58 // decryption succeeded. Return NULL if check or decryption failed. | |
| 59 // TODO(fgalligan): Do we need to differentiate between a check failure | |
|
ddorwin
2012/07/10 01:12:20
Not to the application. There is no error to repor
fgalligan1
2012/07/11 22:06:33
Done.
| |
| 60 // and a decryption failure? | |
| 45 virtual scoped_refptr<DecoderBuffer> Decrypt( | 61 virtual scoped_refptr<DecoderBuffer> Decrypt( |
| 46 const scoped_refptr<DecoderBuffer>& input) OVERRIDE; | 62 const scoped_refptr<DecoderBuffer>& input) OVERRIDE; |
| 47 | 63 |
| 48 private: | 64 private: |
| 49 // KeyMap owns the crypto::SymmetricKey* and must delete them when they are | 65 // Helper class that manages the HMAC and encryption keys. |
|
ddorwin
2012/07/10 01:12:20
It's probably worth referring to the RFC here.
fgalligan1
2012/07/11 22:06:33
Done.
| |
| 66 class HmacEncryptionKeys { | |
|
ddorwin
2012/07/10 01:12:20
Since this uses WebM-specific constants, it should
fgalligan1
2012/07/11 22:06:33
Done.
| |
| 67 public: | |
| 68 explicit HmacEncryptionKeys(const std::string& secret); | |
| 69 ~HmacEncryptionKeys(); | |
| 70 | |
| 71 // Creates the HMAC and encryption key. | |
| 72 bool Init(); | |
| 73 | |
| 74 std::string hmac_key() { return hmac_key_; } | |
|
xhwang
2012/07/10 06:31:25
We can return StringPiece here. Also see the comme
fgalligan1
2012/07/11 22:06:33
Done.
| |
| 75 crypto::SymmetricKey* encryption_key() { return encryption_key_.get(); } | |
|
ddorwin
2012/07/10 01:12:20
decryption_key seems better.
fgalligan1
2012/07/11 22:06:33
Done.
| |
| 76 | |
| 77 private: | |
| 78 // The base secret that is used to derive the HMAC and encryption keys. | |
| 79 const std::string secret_; | |
| 80 | |
| 81 // The key used to perform the intergrity check. | |
|
xhwang
2012/07/10 06:31:25
s/intergrity/integrity
fgalligan1
2012/07/11 22:06:33
Done.
| |
| 82 std::string hmac_key_; | |
| 83 | |
| 84 // The key used to decrypt the data. | |
| 85 scoped_ptr<crypto::SymmetricKey> encryption_key_; | |
| 86 }; | |
|
ddorwin
2012/07/10 01:12:20
DISALLOW_COPY_AND_ASSIGN
fgalligan1
2012/07/11 22:06:33
Done.
| |
| 87 | |
| 88 // KeysMap owns the HmacEncryptionKeys* and must delete them when they are | |
| 50 // not needed any more. | 89 // not needed any more. |
| 51 typedef base::hash_map<std::string, crypto::SymmetricKey*> KeyMap; | 90 typedef base::hash_map<std::string, HmacEncryptionKeys*> KeysMap; |
| 52 | 91 |
| 53 // Since only Decrypt() is called off the renderer thread, we only need to | 92 // Since only Decrypt() is called off the renderer thread, we only need to |
| 54 // protect |key_map_|, the only member variable that is shared between | 93 // protect |keys_map_|, the only member variable that is shared between |
| 55 // Decrypt() and other methods. | 94 // Decrypt() and other methods. |
| 56 KeyMap key_map_; // Protected by the |key_map_lock_|. | 95 KeysMap keys_map_; // Protected by the |keys_map_lock_|. |
| 57 base::Lock key_map_lock_; // Protects the |key_map_|. | 96 base::Lock keys_map_lock_; // Protects the |keys_map_|. |
| 58 | 97 |
| 59 // Make session ID unique per renderer by making it static. | 98 // Make session ID unique per renderer by making it static. |
| 60 // TODO(xhwang): Make session ID more strictly defined if needed: | 99 // TODO(xhwang): Make session ID more strictly defined if needed: |
| 61 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16739#c0 | 100 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16739#c0 |
| 62 static uint32 next_session_id_; | 101 static uint32 next_session_id_; |
| 63 | 102 |
| 64 DecryptorClient* const client_; | 103 DecryptorClient* const client_; |
| 65 | 104 |
| 66 DISALLOW_COPY_AND_ASSIGN(AesDecryptor); | 105 DISALLOW_COPY_AND_ASSIGN(AesDecryptor); |
| 67 }; | 106 }; |
| 68 | 107 |
| 69 } // namespace media | 108 } // namespace media |
| 70 | 109 |
| 71 #endif // MEDIA_CRYPTO_AES_DECRYPTOR_H_ | 110 #endif // MEDIA_CRYPTO_HMAC_AES_DECRYPTOR_H_ |
| OLD | NEW |