You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

options.go 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package protocol
  2. import (
  3. "github.com/duo-labs/webauthn/protocol/webauthncose"
  4. )
  5. type CredentialCreation struct {
  6. Response PublicKeyCredentialCreationOptions `json:"publicKey"`
  7. }
  8. type CredentialAssertion struct {
  9. Response PublicKeyCredentialRequestOptions `json:"publicKey"`
  10. }
  11. // In order to create a Credential via create(), the caller specifies a few parameters in a CredentialCreationOptions object.
  12. // See §5.4. Options for Credential Creation https://www.w3.org/TR/webauthn/#dictionary-makecredentialoptions
  13. type PublicKeyCredentialCreationOptions struct {
  14. Challenge Challenge `json:"challenge"`
  15. RelyingParty RelyingPartyEntity `json:"rp"`
  16. User UserEntity `json:"user"`
  17. Parameters []CredentialParameter `json:"pubKeyCredParams,omitempty"`
  18. AuthenticatorSelection AuthenticatorSelection `json:"authenticatorSelection,omitempty"`
  19. Timeout int `json:"timeout,omitempty"`
  20. CredentialExcludeList []CredentialDescriptor `json:"excludeCredentials,omitempty"`
  21. Extensions AuthenticationExtensions `json:"extensions,omitempty"`
  22. Attestation ConveyancePreference `json:"attestation,omitempty"`
  23. }
  24. // The PublicKeyCredentialRequestOptions dictionary supplies get() with the data it needs to generate an assertion.
  25. // Its challenge member MUST be present, while its other members are OPTIONAL.
  26. // See §5.5. Options for Assertion Generation https://www.w3.org/TR/webauthn/#assertion-options
  27. type PublicKeyCredentialRequestOptions struct {
  28. Challenge Challenge `json:"challenge"`
  29. Timeout int `json:"timeout,omitempty"`
  30. RelyingPartyID string `json:"rpId,omitempty"`
  31. AllowedCredentials []CredentialDescriptor `json:"allowCredentials,omitempty"`
  32. UserVerification UserVerificationRequirement `json:"userVerification,omitempty"` // Default is "preferred"
  33. Extensions AuthenticationExtensions `json:"extensions,omitempty"`
  34. }
  35. // This dictionary contains the attributes that are specified by a caller when referring to a public
  36. // key credential as an input parameter to the create() or get() methods. It mirrors the fields of
  37. // the PublicKeyCredential object returned by the latter methods.
  38. // See §5.10.3. Credential Descriptor https://www.w3.org/TR/webauthn/#credential-dictionary
  39. type CredentialDescriptor struct {
  40. // The valid credential types.
  41. Type CredentialType `json:"type"`
  42. // CredentialID The ID of a credential to allow/disallow
  43. CredentialID []byte `json:"id"`
  44. // The authenticator transports that can be used
  45. Transport []AuthenticatorTransport `json:"transports,omitempty"`
  46. }
  47. // CredentialParameter is the credential type and algorithm
  48. // that the relying party wants the authenticator to create
  49. type CredentialParameter struct {
  50. Type CredentialType `json:"type"`
  51. Algorithm webauthncose.COSEAlgorithmIdentifier `json:"alg"`
  52. }
  53. // This enumeration defines the valid credential types.
  54. // It is an extension point; values can be added to it in the future, as
  55. // more credential types are defined. The values of this enumeration are used
  56. // for versioning the Authentication Assertion and attestation structures according
  57. // to the type of the authenticator.
  58. // See §5.10.3. Credential Descriptor https://www.w3.org/TR/webauthn/#credentialType
  59. type CredentialType string
  60. const (
  61. // PublicKeyCredentialType - Currently one credential type is defined, namely "public-key".
  62. PublicKeyCredentialType CredentialType = "public-key"
  63. )
  64. // AuthenticationExtensions - referred to as AuthenticationExtensionsClientInputs in the
  65. // spec document, this member contains additional parameters requesting additional processing
  66. // by the client and authenticator.
  67. // This is currently under development
  68. type AuthenticationExtensions map[string]interface{}
  69. // WebAuthn Relying Parties may use the AuthenticatorSelectionCriteria dictionary to specify their requirements
  70. // regarding authenticator attributes. See §5.4.4. Authenticator Selection Criteria
  71. // https://www.w3.org/TR/webauthn/#authenticatorSelection
  72. type AuthenticatorSelection struct {
  73. // AuthenticatorAttachment If this member is present, eligible authenticators are filtered to only
  74. // authenticators attached with the specified AuthenticatorAttachment enum
  75. AuthenticatorAttachment AuthenticatorAttachment `json:"authenticatorAttachment,omitempty"`
  76. // RequireResidentKey this member describes the Relying Party's requirements regarding resident
  77. // credentials. If the parameter is set to true, the authenticator MUST create a client-side-resident
  78. // public key credential source when creating a public key credential.
  79. RequireResidentKey *bool `json:"requireResidentKey,omitempty"`
  80. // UserVerification This member describes the Relying Party's requirements regarding user verification for
  81. // the create() operation. Eligible authenticators are filtered to only those capable of satisfying this
  82. // requirement.
  83. UserVerification UserVerificationRequirement `json:"userVerification,omitempty"`
  84. }
  85. // WebAuthn Relying Parties may use AttestationConveyancePreference to specify their preference regarding
  86. // attestation conveyance during credential generation. See §5.4.6. https://www.w3.org/TR/webauthn/#attestation-convey
  87. type ConveyancePreference string
  88. const (
  89. // The default value. This value indicates that the Relying Party is not interested in authenticator attestation. For example,
  90. // in order to potentially avoid having to obtain user consent to relay identifying information to the Relying Party, or to
  91. // save a roundtrip to an Attestation CA.
  92. PreferNoAttestation ConveyancePreference = "none"
  93. // This value indicates that the Relying Party prefers an attestation conveyance yielding verifiable attestation
  94. // statements, but allows the client to decide how to obtain such attestation statements. The client MAY replace
  95. // the authenticator-generated attestation statements with attestation statements generated by an Anonymization
  96. // CA, in order to protect the user’s privacy, or to assist Relying Parties with attestation verification in a
  97. // heterogeneous ecosystem.
  98. PreferIndirectAttestation ConveyancePreference = "indirect"
  99. // This value indicates that the Relying Party wants to receive the attestation statement as generated by the authenticator.
  100. PreferDirectAttestation ConveyancePreference = "direct"
  101. )
  102. func (a *PublicKeyCredentialRequestOptions) GetAllowedCredentialIDs() [][]byte {
  103. var allowedCredentialIDs = make([][]byte, len(a.AllowedCredentials))
  104. for i, credential := range a.AllowedCredentials {
  105. allowedCredentialIDs[i] = credential.CredentialID
  106. }
  107. return allowedCredentialIDs
  108. }
  109. type Extensions interface{}
  110. type ServerResponse struct {
  111. Status ServerResponseStatus `json:"status"`
  112. Message string `json:"errorMessage"`
  113. }
  114. type ServerResponseStatus string
  115. const (
  116. StatusOk ServerResponseStatus = "ok"
  117. StatusFailed ServerResponseStatus = "failed"
  118. )