From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/gmp/CDMStorageIdProvider.cpp | 68 ++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 dom/media/gmp/CDMStorageIdProvider.cpp (limited to 'dom/media/gmp/CDMStorageIdProvider.cpp') diff --git a/dom/media/gmp/CDMStorageIdProvider.cpp b/dom/media/gmp/CDMStorageIdProvider.cpp new file mode 100644 index 0000000000..52255879b3 --- /dev/null +++ b/dom/media/gmp/CDMStorageIdProvider.cpp @@ -0,0 +1,68 @@ +/* -*- 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 ""_ns; +#else + GMP_LOG_DEBUG("CDMStorageIdProvider::ComputeStorageId"); + + std::string machineId; + if (!rlz_lib::GetMachineId(&machineId)) { + GMP_LOG_DEBUG( + "CDMStorageIdProvider::ComputeStorageId: get machineId failed."); + return ""_ns; + } + + std::string originSalt(aOriginSalt.BeginReading(), aOriginSalt.Length()); + std::string input = + machineId + originSalt + CDMStorageIdProvider::kBrowserIdentifier; + nsCOMPtr hasher; + nsresult rv = NS_NewCryptoHash(nsICryptoHash::SHA256, getter_AddRefs(hasher)); + if (NS_WARN_IF(NS_FAILED(rv))) { + GMP_LOG_DEBUG( + "CDMStorageIdProvider::ComputeStorageId: failed to initialize " + "hash(0x%08" PRIx32 ")", + static_cast(rv)); + return ""_ns; + } + + rv = hasher->Update(reinterpret_cast(input.c_str()), + input.size()); + if (NS_WARN_IF(NS_FAILED(rv))) { + GMP_LOG_DEBUG( + "CDMStorageIdProvider::ComputeStorageId: failed to update " + "hash(0x%08" PRIx32 ")", + static_cast(rv)); + return ""_ns; + } + + nsCString storageId; + rv = hasher->Finish(false, storageId); + if (NS_WARN_IF(NS_FAILED(rv))) { + GMP_LOG_DEBUG( + "CDMStorageIdProvider::ComputeStorageId: failed to get the final hash " + "result(0x%08" PRIx32 ")", + static_cast(rv)); + return ""_ns; + } + return storageId; +#endif +} + +} // namespace mozilla -- cgit v1.2.3