1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 // 5 // Media device IDs come in two flavors: The machine-wide unique ID of 6 // the device, which is what we use on the browser side, and one-way 7 // hashes over the unique ID and a security origin, which we provide 8 // to code on the renderer side as per-security-origin IDs. 9 10 #ifndef CONTENT_PUBLIC_BROWSER_MEDIA_DEVICE_ID_H_ 11 #define CONTENT_PUBLIC_BROWSER_MEDIA_DEVICE_ID_H_ 12 13 #include <string> 14 15 #include "content/common/content_export.h" 16 #include "content/public/browser/resource_context.h" 17 #include "third_party/blink/public/common/mediastream/media_stream_request.h" 18 #include "url/origin.h" 19 20 namespace content { 21 22 // Generates a one-way hash of a device's unique ID usable by one 23 // particular security origin. 24 CONTENT_EXPORT std::string GetHMACForMediaDeviceID( 25 const std::string& salt, 26 const url::Origin& security_origin, 27 const std::string& raw_unique_id); 28 29 // Convenience method to check if |device_guid| is an HMAC of 30 // |raw_device_id| for |security_origin|. 31 CONTENT_EXPORT bool DoesMediaDeviceIDMatchHMAC( 32 const std::string& salt, 33 const url::Origin& security_origin, 34 const std::string& device_guid, 35 const std::string& raw_unique_id); 36 37 // This function is deprecated. Use the callback version below instead. 38 CONTENT_EXPORT bool GetMediaDeviceIDForHMAC( 39 blink::mojom::MediaStreamType stream_type, 40 const std::string& salt, 41 const url::Origin& security_origin, 42 const std::string& source_id, 43 std::string* device_id); 44 45 // Returns the raw device ID for the given HMAC |hmac_device_id| for the given 46 // |security_origin| and |salt|. The result is passed via |callback| on the 47 // task runner where this function is called. If |hmac_device_id| is not a 48 // valid device ID nullopt is returned. 49 CONTENT_EXPORT void GetMediaDeviceIDForHMAC( 50 blink::mojom::MediaStreamType stream_type, 51 std::string salt, 52 url::Origin security_origin, 53 std::string hmac_device_id, 54 base::OnceCallback<void(const base::Optional<std::string>&)> callback); 55 56 CONTENT_EXPORT bool IsValidDeviceId(const std::string& device_id); 57 58 } // namespace content 59 60 #endif // CONTENT_PUBLIC_BROWSER_MEDIA_DEVICE_ID_H_ 61