Source code

Revision control

Other Tools

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 "mozilla/dom/CryptoBuffer.h"
15
#include "mozilla/dom/WebAuthenticationBinding.h"
16
17
namespace mozilla {
18
namespace dom {
19
20
enum class U2FOperation { Register, Sign };
21
22
bool EvaluateAppID(nsPIDOMWindowInner* aParent, const nsString& aOrigin,
23
/* in/out */ nsString& aAppId);
24
25
nsresult AssembleAuthenticatorData(const CryptoBuffer& rpIdHashBuf,
26
const uint8_t flags,
27
const CryptoBuffer& counterBuf,
28
const CryptoBuffer& attestationDataBuf,
29
/* out */ CryptoBuffer& authDataBuf);
30
31
nsresult AssembleAttestationObject(const CryptoBuffer& aRpIdHash,
32
const CryptoBuffer& aPubKeyBuf,
33
const CryptoBuffer& aKeyHandleBuf,
34
const CryptoBuffer& aAttestationCertBuf,
35
const CryptoBuffer& aSignatureBuf,
36
bool aForceNoneAttestation,
37
/* out */ CryptoBuffer& aAttestationObjBuf);
38
39
nsresult U2FDecomposeSignResponse(const CryptoBuffer& aResponse,
40
/* out */ uint8_t& aFlags,
41
/* out */ CryptoBuffer& aCounterBuf,
42
/* out */ CryptoBuffer& aSignatureBuf);
43
44
nsresult U2FDecomposeRegistrationResponse(
45
const CryptoBuffer& aResponse,
46
/* out */ CryptoBuffer& aPubKeyBuf,
47
/* out */ CryptoBuffer& aKeyHandleBuf,
48
/* out */ CryptoBuffer& aAttestationCertBuf,
49
/* out */ CryptoBuffer& aSignatureBuf);
50
51
nsresult U2FDecomposeECKey(const CryptoBuffer& aPubKeyBuf,
52
/* out */ CryptoBuffer& aXcoord,
53
/* out */ CryptoBuffer& aYcoord);
54
55
nsresult HashCString(const nsACString& aIn, /* out */ CryptoBuffer& aOut);
56
57
nsresult BuildTransactionHashes(const nsCString& aRpId,
58
const nsCString& aClientDataJSON,
59
/* out */ CryptoBuffer& aRpIdHash,
60
/* out */ CryptoBuffer& aClientDataHash);
61
62
} // namespace dom
63
} // namespace mozilla
64
65
namespace IPC {
66
67
template <>
68
struct ParamTraits<mozilla::dom::AuthenticatorAttachment>
69
: public ContiguousEnumSerializer<
70
mozilla::dom::AuthenticatorAttachment,
71
mozilla::dom::AuthenticatorAttachment::Platform,
72
mozilla::dom::AuthenticatorAttachment::EndGuard_> {};
73
74
template <>
75
struct ParamTraits<mozilla::dom::UserVerificationRequirement>
76
: public ContiguousEnumSerializer<
77
mozilla::dom::UserVerificationRequirement,
78
mozilla::dom::UserVerificationRequirement::Required,
79
mozilla::dom::UserVerificationRequirement::EndGuard_> {};
80
81
template <>
82
struct ParamTraits<mozilla::dom::AttestationConveyancePreference>
83
: public ContiguousEnumSerializer<
84
mozilla::dom::AttestationConveyancePreference,
85
mozilla::dom::AttestationConveyancePreference::None,
86
mozilla::dom::AttestationConveyancePreference::EndGuard_> {};
87
88
} // namespace IPC
89
90
#endif // mozilla_dom_WebAuthnUtil_h