1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=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_WebAuthnUtil_h 8 #define mozilla_dom_WebAuthnUtil_h 9 10 /* 11 * Utility functions used by both WebAuthnManager and U2FTokenManager. 12 */ 13 14 #include "ipc/EnumSerializer.h" 15 #include "mozilla/dom/CryptoBuffer.h" 16 #include "mozilla/dom/WebAuthenticationBinding.h" 17 #include "ipc/IPCMessageUtils.h" 18 19 namespace mozilla { 20 namespace dom { 21 22 enum class U2FOperation { Register, Sign }; 23 24 bool EvaluateAppID(nsPIDOMWindowInner* aParent, const nsString& aOrigin, 25 /* in/out */ nsString& aAppId); 26 27 nsresult AssembleAuthenticatorData(const CryptoBuffer& rpIdHashBuf, 28 const uint8_t flags, 29 const CryptoBuffer& counterBuf, 30 const CryptoBuffer& attestationDataBuf, 31 /* out */ CryptoBuffer& authDataBuf); 32 33 nsresult AssembleAttestationObject(const CryptoBuffer& aRpIdHash, 34 const CryptoBuffer& aPubKeyBuf, 35 const CryptoBuffer& aKeyHandleBuf, 36 const CryptoBuffer& aAttestationCertBuf, 37 const CryptoBuffer& aSignatureBuf, 38 bool aForceNoneAttestation, 39 /* out */ CryptoBuffer& aAttestationObjBuf); 40 41 nsresult U2FDecomposeSignResponse(const CryptoBuffer& aResponse, 42 /* out */ uint8_t& aFlags, 43 /* out */ CryptoBuffer& aCounterBuf, 44 /* out */ CryptoBuffer& aSignatureBuf); 45 46 nsresult U2FDecomposeRegistrationResponse( 47 const CryptoBuffer& aResponse, 48 /* out */ CryptoBuffer& aPubKeyBuf, 49 /* out */ CryptoBuffer& aKeyHandleBuf, 50 /* out */ CryptoBuffer& aAttestationCertBuf, 51 /* out */ CryptoBuffer& aSignatureBuf); 52 53 nsresult U2FDecomposeECKey(const CryptoBuffer& aPubKeyBuf, 54 /* out */ CryptoBuffer& aXcoord, 55 /* out */ CryptoBuffer& aYcoord); 56 57 nsresult HashCString(const nsACString& aIn, /* out */ CryptoBuffer& aOut); 58 59 nsresult BuildTransactionHashes(const nsCString& aRpId, 60 const nsCString& aClientDataJSON, 61 /* out */ CryptoBuffer& aRpIdHash, 62 /* out */ CryptoBuffer& aClientDataHash); 63 64 } // namespace dom 65 } // namespace mozilla 66 67 namespace IPC { 68 69 template <> 70 struct ParamTraits<mozilla::dom::AuthenticatorAttachment> 71 : public ContiguousEnumSerializer< 72 mozilla::dom::AuthenticatorAttachment, 73 mozilla::dom::AuthenticatorAttachment::Platform, 74 mozilla::dom::AuthenticatorAttachment::EndGuard_> {}; 75 76 template <> 77 struct ParamTraits<mozilla::dom::UserVerificationRequirement> 78 : public ContiguousEnumSerializer< 79 mozilla::dom::UserVerificationRequirement, 80 mozilla::dom::UserVerificationRequirement::Required, 81 mozilla::dom::UserVerificationRequirement::EndGuard_> {}; 82 83 template <> 84 struct ParamTraits<mozilla::dom::AttestationConveyancePreference> 85 : public ContiguousEnumSerializer< 86 mozilla::dom::AttestationConveyancePreference, 87 mozilla::dom::AttestationConveyancePreference::None, 88 mozilla::dom::AttestationConveyancePreference::EndGuard_> {}; 89 90 } // namespace IPC 91 92 #endif // mozilla_dom_WebAuthnUtil_h 93