WebAuthnArgs.h (4999B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_WebAuthnArgs_H_ 8 #define mozilla_dom_WebAuthnArgs_H_ 9 10 #include "mozilla/dom/WebAuthnTransactionChild.h" 11 #include "mozilla/ipc/BackgroundParent.h" 12 #include "nsIWebAuthnArgs.h" 13 14 namespace mozilla::dom { 15 16 class WebAuthnRegisterArgs final : public nsIWebAuthnRegisterArgs { 17 public: 18 NS_DECL_THREADSAFE_ISUPPORTS 19 NS_DECL_NSIWEBAUTHNREGISTERARGS 20 21 explicit WebAuthnRegisterArgs(const nsCString& aOrigin, 22 const nsCString& aClientDataJSON, 23 const bool aPrivateBrowsing, 24 const WebAuthnMakeCredentialInfo& aInfo) 25 : mOrigin(aOrigin), 26 mClientDataJSON(aClientDataJSON), 27 mPrivateBrowsing(aPrivateBrowsing), 28 mInfo(aInfo), 29 mEnforceCredentialProtectionPolicy(false), 30 mCredProps(false), 31 mHmacCreateSecret(false), 32 mLargeBlobSupportRequired(Nothing()), 33 mMinPinLength(false), 34 mPrf(false) { 35 for (const WebAuthnExtension& ext : mInfo.Extensions()) { 36 switch (ext.type()) { 37 case WebAuthnExtension::TWebAuthnExtensionCredProtect: 38 mCredentialProtectionPolicy.emplace( 39 ext.get_WebAuthnExtensionCredProtect().policy()); 40 mEnforceCredentialProtectionPolicy = 41 ext.get_WebAuthnExtensionCredProtect().required(); 42 break; 43 case WebAuthnExtension::TWebAuthnExtensionCredProps: 44 mCredProps = ext.get_WebAuthnExtensionCredProps().credProps(); 45 break; 46 case WebAuthnExtension::TWebAuthnExtensionHmacSecret: 47 mHmacCreateSecret = 48 ext.get_WebAuthnExtensionHmacSecret().hmacCreateSecret(); 49 break; 50 case WebAuthnExtension::TWebAuthnExtensionLargeBlob: 51 mLargeBlobSupportRequired = 52 ext.get_WebAuthnExtensionLargeBlob().flag(); 53 break; 54 case WebAuthnExtension::TWebAuthnExtensionMinPinLength: 55 mMinPinLength = 56 ext.get_WebAuthnExtensionMinPinLength().minPinLength(); 57 break; 58 case WebAuthnExtension::TWebAuthnExtensionPrf: 59 mPrf = true; 60 break; 61 case WebAuthnExtension::T__None: 62 break; 63 } 64 } 65 } 66 67 private: 68 ~WebAuthnRegisterArgs() = default; 69 70 const nsCString mOrigin; 71 const nsCString mClientDataJSON; 72 const bool mPrivateBrowsing; 73 const WebAuthnMakeCredentialInfo mInfo; 74 75 Maybe<CredentialProtectionPolicy> mCredentialProtectionPolicy; 76 bool mEnforceCredentialProtectionPolicy; 77 78 // Flags to indicate whether an extension is being requested. 79 bool mCredProps; 80 bool mHmacCreateSecret; 81 Maybe<bool> mLargeBlobSupportRequired; 82 bool mMinPinLength; 83 bool mPrf; 84 }; 85 86 class WebAuthnSignArgs final : public nsIWebAuthnSignArgs { 87 public: 88 NS_DECL_THREADSAFE_ISUPPORTS 89 NS_DECL_NSIWEBAUTHNSIGNARGS 90 91 explicit WebAuthnSignArgs(const nsCString& aOrigin, 92 const nsCString& aClientDataJSON, 93 const bool aPrivateBrowsing, 94 const WebAuthnGetAssertionInfo& aInfo) 95 : mOrigin(aOrigin), 96 mClientDataJSON(aClientDataJSON), 97 mPrivateBrowsing(aPrivateBrowsing), 98 mInfo(aInfo), 99 mPrf(false) { 100 for (const WebAuthnExtension& ext : mInfo.Extensions()) { 101 switch (ext.type()) { 102 case WebAuthnExtension::TWebAuthnExtensionCredProtect: 103 break; 104 case WebAuthnExtension::TWebAuthnExtensionCredProps: 105 break; 106 case WebAuthnExtension::TWebAuthnExtensionHmacSecret: 107 break; 108 case WebAuthnExtension::TWebAuthnExtensionMinPinLength: 109 break; 110 case WebAuthnExtension::TWebAuthnExtensionLargeBlob: 111 if (ext.get_WebAuthnExtensionLargeBlob().flag().isSome()) { 112 bool read = ext.get_WebAuthnExtensionLargeBlob().flag().ref(); 113 mLargeBlobRead.emplace(read); 114 if (!read) { 115 mLargeBlobWrite.AppendElements( 116 ext.get_WebAuthnExtensionLargeBlob().write()); 117 } 118 } 119 break; 120 case WebAuthnExtension::TWebAuthnExtensionPrf: 121 mPrf = ext.get_WebAuthnExtensionPrf().eval().isSome() || 122 ext.get_WebAuthnExtensionPrf().evalByCredentialMaybe(); 123 break; 124 case WebAuthnExtension::T__None: 125 break; 126 } 127 } 128 } 129 130 private: 131 ~WebAuthnSignArgs() = default; 132 133 const nsCString mOrigin; 134 const nsCString mClientDataJSON; 135 const bool mPrivateBrowsing; 136 const WebAuthnGetAssertionInfo mInfo; 137 Maybe<bool> mLargeBlobRead; 138 nsTArray<uint8_t> mLargeBlobWrite; 139 bool mPrf; 140 }; 141 142 } // namespace mozilla::dom 143 144 #endif // mozilla_dom_WebAuthnArgs_H_