mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 23:05:42 +00:00
Bug 1420836 - Part1 - Provide a utility function to compute the storage id. r=cpearce
The CDM on Mac and Windows will ask the host for storage id. We compute the storage id by hashing machine id, origin salt and browser id. MozReview-Commit-ID: 4fTCaOKgSIe --HG-- extra : rebase_source : 20fe8ab93966bb74b46eebbfbddc8486ceea4705
This commit is contained in:
parent
1192c9ff4d
commit
c99cb87836
67
dom/media/gmp/CDMStorageIdProvider.cpp
Normal file
67
dom/media/gmp/CDMStorageIdProvider.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "CDMStorageIdProvider.h"
|
||||
#include "GMPLog.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsICryptoHash.h"
|
||||
|
||||
#ifdef SUPPORT_STORAGE_ID
|
||||
#include "rlz/lib/machine_id.h"
|
||||
#endif
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
/*static*/ nsCString
|
||||
CDMStorageIdProvider::ComputeStorageId(const nsCString& aOriginSalt)
|
||||
{
|
||||
#ifndef SUPPORT_STORAGE_ID
|
||||
return EmptyCString();
|
||||
#else
|
||||
GMP_LOG("CDMStorageIdProvider::ComputeStorageId");
|
||||
|
||||
std::string machineId;
|
||||
if (!rlz_lib::GetMachineId(&machineId)) {
|
||||
GMP_LOG("CDMStorageIdProvider::ComputeStorageId: get machineId failed.");
|
||||
return EmptyCString();
|
||||
}
|
||||
|
||||
std::string originSalt(aOriginSalt.BeginReading(), aOriginSalt.Length());
|
||||
std::string input = machineId + originSalt + CDMStorageIdProvider::kBrowserIdentifier;
|
||||
nsAutoCString storageId;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICryptoHash> hasher = do_CreateInstance("@mozilla.org/security/hash;1", &rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
GMP_LOG("CDMStorageIdProvider::ComputeStorageId: no crypto hash(0x%08" PRIx32 ")",
|
||||
static_cast<uint32_t>(rv));
|
||||
return EmptyCString();
|
||||
}
|
||||
|
||||
rv = hasher->Init(nsICryptoHash::SHA256);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
GMP_LOG("CDMStorageIdProvider::ComputeStorageId: failed to initialize hash(0x%08" PRIx32 ")",
|
||||
static_cast<uint32_t>(rv));
|
||||
return EmptyCString();
|
||||
}
|
||||
|
||||
rv = hasher->Update(reinterpret_cast<const uint8_t*>(input.c_str()), input.size());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
GMP_LOG("CDMStorageIdProvider::ComputeStorageId: failed to update hash(0x%08" PRIx32 ")",
|
||||
static_cast<uint32_t>(rv));
|
||||
return EmptyCString();
|
||||
}
|
||||
|
||||
rv = hasher->Finish(false, storageId);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
GMP_LOG("CDMStorageIdProvider::ComputeStorageId: failed to get the final hash result(0x%08" PRIx32 ")",
|
||||
static_cast<uint32_t>(rv));
|
||||
return EmptyCString();
|
||||
}
|
||||
return storageId;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
43
dom/media/gmp/CDMStorageIdProvider.h
Normal file
43
dom/media/gmp/CDMStorageIdProvider.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef CDMStorageIdProvider_h_
|
||||
#define CDMStorageIdProvider_h_
|
||||
|
||||
/**
|
||||
* CDM will try to request a latest version(0) of storage id.
|
||||
* If the storage id computation algorithm changed, we should increase the kCurrentVersion.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class CDMStorageIdProvider
|
||||
{
|
||||
static constexpr const char* kBrowserIdentifier =
|
||||
"mozilla_firefox_gecko";
|
||||
|
||||
public:
|
||||
// Should increase the value when the storage id algorithm changed.
|
||||
static constexpr int kCurrentVersion = 1;
|
||||
static constexpr int kCDMRequestLatestVersion = 0;
|
||||
|
||||
// Return empty string when
|
||||
// 1. Call on unsupported storageid platform.
|
||||
// 2. Failed to compute the storage id.
|
||||
// This function only provide the storage id for kCurrentVersion=1.
|
||||
// If you want to change the algorithm or output of storageid,
|
||||
// you should keep the version 1 storage id and consider to provide
|
||||
// higher version storage id in another function.
|
||||
static nsCString ComputeStorageId(const nsCString& aOriginSalt);
|
||||
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // CDMStorageIdProvider_h_
|
@ -66,6 +66,7 @@ EXPORTS += [
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'CDMStorageIdProvider.cpp',
|
||||
'ChromiumCDMAdapter.cpp',
|
||||
'ChromiumCDMCallbackProxy.cpp',
|
||||
'ChromiumCDMChild.cpp',
|
||||
@ -120,6 +121,9 @@ IPDL_SOURCES += [
|
||||
'PGMPVideoEncoder.ipdl',
|
||||
]
|
||||
|
||||
if CONFIG['OS_TARGET'] in ['WINNT', 'Darwin']:
|
||||
DEFINES['SUPPORT_STORAGE_ID'] = 1;
|
||||
|
||||
# comment this out to use Unsafe Shmem for more performance
|
||||
DEFINES['GMP_SAFE_SHMEM'] = True
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user