forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Storage Id for encrypted media
Adds code to compute Storage Id for encrypted media. It uses a new profile setting ("media.storage_id_salt"). On Chromium this is not supported, so the empty string is returned. Chrome implementation pending. BUG=478960 TEST=StorageId browser_tests pass Change-Id: I566e1cfbd1d44a2be809dd51c8418b922126cccc Reviewed-on: https://chromium-review.googlesource.com/587828 Reviewed-by: Brett Wilson <[email protected]> Reviewed-by: Daniel Cheng <[email protected]> Reviewed-by: Bill Budge <[email protected]> Reviewed-by: Thomas Guilbert <[email protected]> Reviewed-by: Bernhard Bauer <[email protected]> Commit-Queue: John Rummell <[email protected]> Cr-Commit-Position: refs/heads/master@{#498600}
- Loading branch information
1 parent
6b47b44
commit 36e5b80
Showing
17 changed files
with
256 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/media/cdm_storage_id.h" | ||
|
||
#include "base/callback.h" | ||
|
||
namespace cdm_storage_id { | ||
|
||
void ComputeStorageId(const std::vector<uint8_t>& salt, | ||
const url::Origin& origin, | ||
CdmStorageIdCallback callback) { | ||
// Not implemented by default. | ||
std::move(callback).Run(std::vector<uint8_t>()); | ||
} | ||
|
||
} // namespace cdm_storage_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_MEDIA_CDM_STORAGE_ID_H_ | ||
#define CHROME_BROWSER_MEDIA_CDM_STORAGE_ID_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#include <vector> | ||
|
||
#include "base/callback_forward.h" | ||
#include "url/origin.h" | ||
|
||
// This handles computing the Storage Id for platform verification. | ||
namespace cdm_storage_id { | ||
|
||
using CdmStorageIdCallback = | ||
base::OnceCallback<void(const std::vector<uint8_t>& storage_id)>; | ||
|
||
// Compute the Storage Id based on |salt| and |origin|. This may be | ||
// asynchronous, so call |callback| with the result. If Storage Id is not | ||
// supported on the current platform, an empty string will be passed to | ||
// |callback|. | ||
void ComputeStorageId(const std::vector<uint8_t>& salt, | ||
const url::Origin& origin, | ||
CdmStorageIdCallback callback); | ||
|
||
} // namespace cdm_storage_id | ||
|
||
#endif // CHROME_BROWSER_MEDIA_CDM_STORAGE_ID_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/media/media_storage_id_salt.h" | ||
|
||
#include <string> | ||
|
||
#include "base/logging.h" | ||
#include "base/strings/string_number_conversions.h" | ||
#include "components/prefs/pref_registry_simple.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "crypto/random.h" | ||
|
||
namespace { | ||
|
||
const char kMediaStorageIdSalt[] = "media.storage_id_salt"; | ||
|
||
} // namespace | ||
|
||
std::vector<uint8_t> MediaStorageIdSalt::GetSalt(PrefService* pref_service) { | ||
// Salt is stored as hex-encoded string. | ||
std::string encoded_salt = pref_service->GetString(kMediaStorageIdSalt); | ||
std::vector<uint8_t> salt; | ||
if (encoded_salt.length() != kSaltLength * 2 || | ||
!base::HexStringToBytes(encoded_salt, &salt)) { | ||
// If the salt is not the proper format log an error. | ||
if (encoded_salt.length() > 0) { | ||
DLOG(ERROR) << "Saved value for " << kMediaStorageIdSalt | ||
<< " is not valid: " << encoded_salt; | ||
// Continue on to generate a new one. | ||
} | ||
|
||
// If the salt doesn't exist, generate a new one. | ||
salt.resize(kSaltLength); | ||
crypto::RandBytes(salt.data(), salt.size()); | ||
encoded_salt = base::HexEncode(salt.data(), salt.size()); | ||
pref_service->SetString(kMediaStorageIdSalt, encoded_salt); | ||
} | ||
|
||
return salt; | ||
} | ||
|
||
void MediaStorageIdSalt::RegisterProfilePrefs(PrefRegistrySimple* registry) { | ||
registry->RegisterStringPref(kMediaStorageIdSalt, std::string()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_MEDIA_MEDIA_STORAGE_ID_SALT_H_ | ||
#define CHROME_BROWSER_MEDIA_MEDIA_STORAGE_ID_SALT_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#include <vector> | ||
|
||
#include "base/macros.h" | ||
|
||
class PrefRegistrySimple; | ||
class PrefService; | ||
|
||
// MediaStorageIDSalt is responsible for creating and retrieving a salt string | ||
// that is used when creating Storage IDs. | ||
class MediaStorageIdSalt { | ||
public: | ||
enum { kSaltLength = 32 }; | ||
|
||
// Retrieves the current salt. If one does not currently exist it is created. | ||
static std::vector<uint8_t> GetSalt(PrefService* pref_service); | ||
|
||
static void RegisterProfilePrefs(PrefRegistrySimple* registry); | ||
|
||
private: | ||
DISALLOW_IMPLICIT_CONSTRUCTORS(MediaStorageIdSalt); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_MEDIA_MEDIA_STORAGE_ID_SALT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/media/media_storage_id_salt.h" | ||
|
||
#include "components/prefs/testing_pref_service.h" | ||
#include "testing/gmock/include/gmock/gmock.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
const char kPrefsName[] = "media.storage_id_salt"; | ||
|
||
TEST(MediaStorageIdSalt, Register) { | ||
TestingPrefServiceSimple prefs; | ||
|
||
MediaStorageIdSalt::RegisterProfilePrefs(prefs.registry()); | ||
} | ||
|
||
TEST(MediaStorageIdSalt, Create) { | ||
TestingPrefServiceSimple prefs; | ||
|
||
MediaStorageIdSalt::RegisterProfilePrefs(prefs.registry()); | ||
std::vector<uint8_t> salt = MediaStorageIdSalt::GetSalt(&prefs); | ||
EXPECT_EQ(MediaStorageIdSalt::kSaltLength, salt.size()); | ||
} | ||
|
||
TEST(MediaStorageIdSalt, Recreate) { | ||
TestingPrefServiceSimple prefs; | ||
|
||
MediaStorageIdSalt::RegisterProfilePrefs(prefs.registry()); | ||
std::vector<uint8_t> original_salt = MediaStorageIdSalt::GetSalt(&prefs); | ||
EXPECT_EQ(MediaStorageIdSalt::kSaltLength, original_salt.size()); | ||
|
||
// Now that the salt is created, mess it up and then try fetching it again | ||
// (should generate a new salt and log an error). | ||
prefs.SetString(kPrefsName, "123"); | ||
std::vector<uint8_t> new_salt = MediaStorageIdSalt::GetSalt(&prefs); | ||
EXPECT_EQ(MediaStorageIdSalt::kSaltLength, new_salt.size()); | ||
EXPECT_NE(original_salt, new_salt); | ||
} | ||
|
||
TEST(MediaStorageIdSalt, FetchTwice) { | ||
TestingPrefServiceSimple prefs; | ||
|
||
MediaStorageIdSalt::RegisterProfilePrefs(prefs.registry()); | ||
std::vector<uint8_t> salt1 = MediaStorageIdSalt::GetSalt(&prefs); | ||
EXPECT_EQ(MediaStorageIdSalt::kSaltLength, salt1.size()); | ||
|
||
// Fetch the salt again. Should be the same value. | ||
std::vector<uint8_t> salt2 = MediaStorageIdSalt::GetSalt(&prefs); | ||
EXPECT_EQ(MediaStorageIdSalt::kSaltLength, salt2.size()); | ||
EXPECT_EQ(salt1, salt2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.