2525package com .yubico .webauthn .data ;
2626
2727import com .fasterxml .jackson .annotation .JsonCreator ;
28+ import com .fasterxml .jackson .annotation .JsonIgnore ;
2829import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
2930import com .fasterxml .jackson .annotation .JsonProperty ;
3031import com .yubico .webauthn .RelyingParty ;
@@ -60,15 +61,13 @@ public final class RegistrationExtensionInputs implements ExtensionInputs {
6061 private final Extensions .Prf .PrfRegistrationInput prf ;
6162 private final Boolean uvm ;
6263
63- @ JsonCreator
6464 private RegistrationExtensionInputs (
65- @ JsonProperty ("appidExclude" ) AppId appidExclude ,
66- @ JsonProperty ("credProps" ) Boolean credProps ,
67- @ JsonProperty ("credProtect" )
68- Extensions .CredentialProtection .CredentialProtectionInput credProtect ,
69- @ JsonProperty ("largeBlob" ) Extensions .LargeBlob .LargeBlobRegistrationInput largeBlob ,
70- @ JsonProperty ("prf" ) Extensions .Prf .PrfRegistrationInput prf ,
71- @ JsonProperty ("uvm" ) Boolean uvm ) {
65+ AppId appidExclude ,
66+ Boolean credProps ,
67+ Extensions .CredentialProtection .CredentialProtectionInput credProtect ,
68+ Extensions .LargeBlob .LargeBlobRegistrationInput largeBlob ,
69+ Extensions .Prf .PrfRegistrationInput prf ,
70+ Boolean uvm ) {
7271 this .appidExclude = appidExclude ;
7372 this .credProps = credProps ;
7473 this .credProtect = credProtect ;
@@ -77,6 +76,32 @@ private RegistrationExtensionInputs(
7776 this .uvm = uvm ;
7877 }
7978
79+ @ JsonCreator
80+ private RegistrationExtensionInputs (
81+ @ JsonProperty ("appidExclude" ) AppId appidExclude ,
82+ @ JsonProperty ("credProps" ) Boolean credProps ,
83+ @ JsonProperty ("credentialProtectionPolicy" )
84+ Extensions .CredentialProtection .CredentialProtectionPolicy credProtectPolicy ,
85+ @ JsonProperty ("enforceCredentialProtectionPolicy" ) Boolean enforceCredProtectPolicy ,
86+ @ JsonProperty ("largeBlob" ) Extensions .LargeBlob .LargeBlobRegistrationInput largeBlob ,
87+ @ JsonProperty ("prf" ) Extensions .Prf .PrfRegistrationInput prf ,
88+ @ JsonProperty ("uvm" ) Boolean uvm ) {
89+ this (
90+ appidExclude ,
91+ credProps ,
92+ Optional .ofNullable (credProtectPolicy )
93+ .map (
94+ policy -> {
95+ return enforceCredProtectPolicy != null && enforceCredProtectPolicy
96+ ? Extensions .CredentialProtection .CredentialProtectionInput .require (policy )
97+ : Extensions .CredentialProtection .CredentialProtectionInput .prefer (policy );
98+ })
99+ .orElse (null ),
100+ largeBlob ,
101+ prf ,
102+ uvm );
103+ }
104+
80105 /**
81106 * Merge <code>other</code> into <code>this</code>. Non-null field values from <code>this</code>
82107 * take precedence.
@@ -133,10 +158,36 @@ private Boolean getCredPropsJson() {
133158 * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#sctn-authenticator-credential-properties-extension">§10.4.
134159 * Credential Properties Extension (credProps)</a>
135160 */
161+ @ JsonIgnore
136162 public Optional <Extensions .CredentialProtection .CredentialProtectionInput > getCredProtect () {
137163 return Optional .ofNullable (credProtect );
138164 }
139165
166+ /**
167+ * For JSON serialization, because credProtect does not group all inputs under the "credProtect"
168+ * key.
169+ */
170+ @ JsonProperty ("credentialProtectionPolicy" )
171+ private Optional <Extensions .CredentialProtection .CredentialProtectionPolicy >
172+ getCredProtectPolicy () {
173+ return getCredProtect ()
174+ .map (
175+ Extensions .CredentialProtection .CredentialProtectionInput
176+ ::getCredentialProtectionPolicy );
177+ }
178+
179+ /**
180+ * For JSON serialization, because credProtect does not group all inputs under the "credProtect"
181+ * key.
182+ */
183+ @ JsonProperty ("enforceCredentialProtectionPolicy" )
184+ private Optional <Boolean > getEnforceCredProtectPolicy () {
185+ return getCredProtect ()
186+ .map (
187+ Extensions .CredentialProtection .CredentialProtectionInput
188+ ::isEnforceCredentialProtectionPolicy );
189+ }
190+
140191 /**
141192 * @return The value of the Large blob storage extension (<code>largeBlob</code>) input if
142193 * configured, empty otherwise.
0 commit comments