Skip to content

Commit bcc3d3d

Browse files
committed
Begin adding spc extension
1 parent c8a5523 commit bcc3d3d

File tree

5 files changed

+587
-2
lines changed

5 files changed

+587
-2
lines changed

webauthn-server-core/src/main/java/com/yubico/webauthn/data/AssertionExtensionInputs.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,20 @@ public class AssertionExtensionInputs implements ExtensionInputs {
5757
private final AppId appid;
5858
private final Extensions.LargeBlob.LargeBlobAuthenticationInput largeBlob;
5959
private final Extensions.Prf.PrfAuthenticationInput prf;
60+
private final Extensions.Spc.SpcAuthenticationInput spc;
6061
private final Boolean uvm;
6162

6263
@JsonCreator
6364
private AssertionExtensionInputs(
6465
@JsonProperty("appid") AppId appid,
6566
@JsonProperty("largeBlob") Extensions.LargeBlob.LargeBlobAuthenticationInput largeBlob,
6667
@JsonProperty("prf") Extensions.Prf.PrfAuthenticationInput prf,
68+
@JsonProperty("spc") Extensions.Spc.SpcAuthenticationInput spc,
6769
@JsonProperty("uvm") Boolean uvm) {
6870
this.appid = appid;
6971
this.largeBlob = largeBlob;
7072
this.prf = prf;
73+
this.spc = spc;
7174
this.uvm = (uvm != null && uvm) ? true : null;
7275
}
7376

@@ -83,6 +86,7 @@ public AssertionExtensionInputs merge(AssertionExtensionInputs other) {
8386
this.appid != null ? this.appid : other.appid,
8487
this.largeBlob != null ? this.largeBlob : other.largeBlob,
8588
this.prf != null ? this.prf : other.prf,
89+
this.spc != null ? this.spc : other.spc,
8690
this.uvm != null ? this.uvm : other.uvm);
8791
}
8892

@@ -103,6 +107,9 @@ public Set<String> getExtensionIds() {
103107
if (prf != null) {
104108
ids.add(Extensions.Prf.EXTENSION_ID);
105109
}
110+
if (spc != null) {
111+
ids.add(Extensions.Spc.EXTENSION_ID);
112+
}
106113
if (getUvm()) {
107114
ids.add(Extensions.Uvm.EXTENSION_ID);
108115
}
@@ -212,6 +219,21 @@ public AssertionExtensionInputsBuilder prf(Extensions.Prf.PrfAuthenticationInput
212219
return this;
213220
}
214221

222+
/**
223+
* Enable the Secure Payment Confirmation extension (<code>spc</code>).
224+
*
225+
* <p>This extension indicates that a credential is either being created for or used for Secure
226+
* Payment Confirmation, respectively.
227+
*
228+
* @see <a
229+
* href="https://www.w3.org/TR/secure-payment-confirmation/#sctn-payment-extension-registration">§5.
230+
* Secure Payment Confirmation extension (SPC)</a>
231+
*/
232+
public AssertionExtensionInputsBuilder spc(Extensions.Spc.SpcAuthenticationInput spc) {
233+
this.spc = spc;
234+
return this;
235+
}
236+
215237
/**
216238
* Enable the User Verification Method Extension (<code>uvm</code>).
217239
*
@@ -299,6 +321,37 @@ private Extensions.Prf.PrfAuthenticationInput getPrfJson() {
299321
: null;
300322
}
301323

324+
/**
325+
* The input to the Secure Payment Confirmation (<code>spc</code>) extension, if any.
326+
*
327+
* <p>This extension indicates that a credential is either being created for or used for Secure
328+
* Payment Confirmation, respectively.
329+
*
330+
* @see <a
331+
* href="https://www.w3.org/TR/secure-payment-confirmation/#sctn-payment-extension-registration">§5.
332+
* Secure Payment Confirmation extension (SPC)</a>
333+
*/
334+
public Optional<Extensions.Spc.SpcAuthenticationInput> getSpc() {
335+
return Optional.ofNullable(spc);
336+
}
337+
338+
/** For JSON serialization, to omit false and null values. */
339+
@JsonProperty("spc")
340+
private Extensions.Spc.SpcAuthenticationInput getSpcJson() {
341+
return spc != null
342+
&& (spc.getIsPayment()
343+
|| spc.getBrowserBoundPubKeyCredParams().isPresent()
344+
|| spc.getRpId().isPresent()
345+
|| spc.getTopOrigin().isPresent()
346+
|| spc.getPayeeName().isPresent()
347+
|| spc.getPayeeOrigin().isPresent()
348+
|| spc.getPaymentEntitiesLogos().isPresent()
349+
|| spc.getTotal().isPresent()
350+
|| spc.getInstrument().isPresent())
351+
? spc
352+
: null;
353+
}
354+
302355
/**
303356
* @return <code>true</code> if the User Verification Method Extension (<code>uvm</code>) is
304357
* enabled, <code>false</code> otherwise.

webauthn-server-core/src/main/java/com/yubico/webauthn/data/ClientAssertionExtensionOutputs.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ public class ClientAssertionExtensionOutputs implements ClientExtensionOutputs {
6868

6969
private final Extensions.Prf.PrfAuthenticationOutput prf;
7070

71+
private final Extensions.Spc.SpcAuthenticationOutput spc;
72+
7173
@JsonCreator
7274
private ClientAssertionExtensionOutputs(
7375
@JsonProperty("appid") Boolean appid,
7476
@JsonProperty("largeBlob") Extensions.LargeBlob.LargeBlobAuthenticationOutput largeBlob,
75-
@JsonProperty("prf") Extensions.Prf.PrfAuthenticationOutput prf) {
77+
@JsonProperty("prf") Extensions.Prf.PrfAuthenticationOutput prf,
78+
@JsonProperty("spc") Extensions.Spc.SpcAuthenticationOutput spc) {
7679
this.appid = appid;
7780
this.largeBlob = largeBlob;
7881
this.prf = prf;
82+
this.spc = spc;
7983
}
8084

8185
@Override
@@ -91,6 +95,9 @@ public Set<String> getExtensionIds() {
9195
if (prf != null) {
9296
ids.add(Extensions.Prf.EXTENSION_ID);
9397
}
98+
if (spc != null) {
99+
ids.add(Extensions.Spc.EXTENSION_ID);
100+
}
94101
return ids;
95102
}
96103

@@ -135,6 +142,20 @@ public Optional<Extensions.Prf.PrfAuthenticationOutput> getPrf() {
135142
return Optional.ofNullable(prf);
136143
}
137144

145+
/**
146+
* The extension output for the <a
147+
* href="https://www.w3.org/TR/secure-payment-confirmation/#sctn-payment-extension-registration">Secure
148+
* Payment Confirmation extension (<code>spc</code>)</a>, if any.
149+
*
150+
* @see com.yubico.webauthn.data.Extensions.Spc.SpcAuthenticationOutput
151+
* @see <a
152+
* href="https://www.w3.org/TR/secure-payment-confirmation/#sctn-payment-extension-registration">§5.
153+
* Secure Payment Confirmation extension (SPC)</a>
154+
*/
155+
public Optional<Extensions.Prf.PrfAuthenticationOutput> getSpc() {
156+
return Optional.ofNullable(prf);
157+
}
158+
138159
public static class ClientAssertionExtensionOutputsBuilder {
139160

140161
/**

webauthn-server-core/src/main/java/com/yubico/webauthn/data/ClientRegistrationExtensionOutputs.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,21 @@ public class ClientRegistrationExtensionOutputs implements ClientExtensionOutput
6060

6161
private final Extensions.Prf.PrfRegistrationOutput prf;
6262

63+
private final Extensions.Spc.SpcRegistrationOutput spc;
64+
6365
@JsonCreator
6466
private ClientRegistrationExtensionOutputs(
6567
@JsonProperty("appidExclude") Boolean appidExclude,
6668
@JsonProperty("credProps")
6769
Extensions.CredentialProperties.CredentialPropertiesOutput credProps,
6870
@JsonProperty("largeBlob") Extensions.LargeBlob.LargeBlobRegistrationOutput largeBlob,
69-
@JsonProperty("prf") Extensions.Prf.PrfRegistrationOutput prf) {
71+
@JsonProperty("prf") Extensions.Prf.PrfRegistrationOutput prf,
72+
@JsonProperty("spc") Extensions.Spc.SpcRegistrationOutput spc) {
7073
this.appidExclude = appidExclude;
7174
this.credProps = credProps;
7275
this.largeBlob = largeBlob;
7376
this.prf = prf;
77+
this.spc = spc;
7478
}
7579

7680
@Override
@@ -89,6 +93,9 @@ public Set<String> getExtensionIds() {
8993
if (prf != null) {
9094
ids.add(Extensions.Prf.EXTENSION_ID);
9195
}
96+
if (spc != null) {
97+
ids.add(Extensions.Spc.EXTENSION_ID);
98+
}
9299
return ids;
93100
}
94101

@@ -148,4 +155,18 @@ public Optional<Extensions.LargeBlob.LargeBlobRegistrationOutput> getLargeBlob()
148155
public Optional<Extensions.Prf.PrfRegistrationOutput> getPrf() {
149156
return Optional.ofNullable(prf);
150157
}
158+
159+
/**
160+
* The extension output for the <a
161+
* href="https://www.w3.org/TR/secure-payment-confirmation/#sctn-payment-extension-registration">Secure
162+
* Payment Confirmation (<code>spc</code>) extension</a>, if any.
163+
*
164+
* @see com.yubico.webauthn.data.Extensions.Spc.SpcRegistrationOutput
165+
* @see <a
166+
* href="https://www.w3.org/TR/secure-payment-confirmation/#sctn-payment-extension-registration">§5.
167+
* Secure Payment Confirmation extension (SPC)</a>
168+
*/
169+
public Optional<Extensions.Spc.SpcRegistrationOutput> getSpc() {
170+
return Optional.ofNullable(spc);
171+
}
151172
}

0 commit comments

Comments
 (0)