-
Notifications
You must be signed in to change notification settings - Fork 142
/
WebAuthnServer.java
666 lines (605 loc) · 25.4 KB
/
WebAuthnServer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
// Copyright (c) 2018, Yubico AB
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package demo.webauthn;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.yubico.fido.metadata.FidoMetadataDownloader;
import com.yubico.fido.metadata.FidoMetadataDownloaderException;
import com.yubico.fido.metadata.FidoMetadataService;
import com.yubico.fido.metadata.UnexpectedLegalHeader;
import com.yubico.internal.util.CertificateParser;
import com.yubico.internal.util.JacksonCodecs;
import com.yubico.util.Either;
import com.yubico.webauthn.AssertionResultV2;
import com.yubico.webauthn.FinishAssertionOptions;
import com.yubico.webauthn.FinishRegistrationOptions;
import com.yubico.webauthn.RegisteredCredential;
import com.yubico.webauthn.RegistrationResult;
import com.yubico.webauthn.RelyingParty;
import com.yubico.webauthn.RelyingPartyV2;
import com.yubico.webauthn.StartAssertionOptions;
import com.yubico.webauthn.StartRegistrationOptions;
import com.yubico.webauthn.attestation.YubicoJsonMetadataService;
import com.yubico.webauthn.data.AttestationConveyancePreference;
import com.yubico.webauthn.data.AuthenticatorData;
import com.yubico.webauthn.data.AuthenticatorSelectionCriteria;
import com.yubico.webauthn.data.AuthenticatorTransport;
import com.yubico.webauthn.data.ByteArray;
import com.yubico.webauthn.data.RelyingPartyIdentity;
import com.yubico.webauthn.data.ResidentKeyRequirement;
import com.yubico.webauthn.data.UserIdentity;
import com.yubico.webauthn.data.exception.Base64UrlException;
import com.yubico.webauthn.exception.AssertionFailedException;
import com.yubico.webauthn.exception.RegistrationFailedException;
import demo.webauthn.data.AssertionRequestWrapper;
import demo.webauthn.data.AssertionResponse;
import demo.webauthn.data.CredentialRegistration;
import demo.webauthn.data.RegistrationRequest;
import demo.webauthn.data.RegistrationResponse;
import java.io.File;
import java.io.IOException;
import java.security.DigestException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.SignatureException;
import java.security.cert.CertPathValidatorException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.time.Clock;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WebAuthnServer {
private static final Logger logger = LoggerFactory.getLogger(WebAuthnServer.class);
private static final SecureRandom random = new SecureRandom();
private final Cache<ByteArray, AssertionRequestWrapper> assertRequestStorage;
private final Cache<ByteArray, RegistrationRequest> registerRequestStorage;
private final InMemoryRegistrationStorage userStorage;
private final SessionManager sessions = new SessionManager();
private final MetadataService metadataService = getMetadataService();
private static MetadataService getMetadataService()
throws CertPathValidatorException,
InvalidAlgorithmParameterException,
Base64UrlException,
DigestException,
FidoMetadataDownloaderException,
CertificateException,
UnexpectedLegalHeader,
IOException,
NoSuchAlgorithmException,
SignatureException,
InvalidKeyException {
if (Config.useFidoMds()) {
logger.info("Using combination of Yubico JSON file and FIDO MDS for attestation metadata.");
return new CompositeMetadataService(
new YubicoJsonMetadataService(),
new FidoMetadataServiceAdapter(
FidoMetadataService.builder()
.useBlob(
FidoMetadataDownloader.builder()
.expectLegalHeader(
"Retrieval and use of this BLOB indicates acceptance of the appropriate agreement located at https://fidoalliance.org/metadata/metadata-legal-terms/")
.useDefaultTrustRoot()
.useTrustRootCacheFile(
new File("webauthn-server-demo-fido-mds-trust-root-cache.bin"))
.useDefaultBlob()
.useBlobCacheFile(
new File("webauthn-server-demo-fido-mds-blob-cache.bin"))
.build()
.loadCachedBlob())
.build()));
} else {
logger.info("Using only Yubico JSON file for attestation metadata.");
return new YubicoJsonMetadataService();
}
}
private final Clock clock = Clock.systemDefaultZone();
private final ObjectMapper jsonMapper = JacksonCodecs.json();
private final RelyingPartyV2<CredentialRegistration> rp;
public WebAuthnServer()
throws CertificateException,
CertPathValidatorException,
InvalidAlgorithmParameterException,
Base64UrlException,
DigestException,
FidoMetadataDownloaderException,
UnexpectedLegalHeader,
IOException,
NoSuchAlgorithmException,
SignatureException,
InvalidKeyException {
this(
new InMemoryRegistrationStorage(),
newCache(),
newCache(),
Config.getRpIdentity(),
Config.getOrigins());
}
public WebAuthnServer(
InMemoryRegistrationStorage userStorage,
Cache<ByteArray, RegistrationRequest> registerRequestStorage,
Cache<ByteArray, AssertionRequestWrapper> assertRequestStorage,
RelyingPartyIdentity rpIdentity,
Set<String> origins)
throws CertificateException,
CertPathValidatorException,
InvalidAlgorithmParameterException,
Base64UrlException,
DigestException,
FidoMetadataDownloaderException,
UnexpectedLegalHeader,
IOException,
NoSuchAlgorithmException,
SignatureException,
InvalidKeyException {
this.userStorage = userStorage;
this.registerRequestStorage = registerRequestStorage;
this.assertRequestStorage = assertRequestStorage;
rp =
RelyingParty.builder()
.identity(rpIdentity)
.credentialRepositoryV2(this.userStorage)
.usernameRepository(this.userStorage)
.origins(origins)
.attestationConveyancePreference(Optional.of(AttestationConveyancePreference.DIRECT))
.attestationTrustSource(metadataService)
.allowOriginPort(false)
.allowOriginSubdomain(false)
.allowUntrustedAttestation(true)
.validateSignatureCounter(true)
.build();
}
private static ByteArray generateRandom(int length) {
byte[] bytes = new byte[length];
random.nextBytes(bytes);
return new ByteArray(bytes);
}
private static <K, V> Cache<K, V> newCache() {
return CacheBuilder.newBuilder()
.maximumSize(100)
.expireAfterAccess(10, TimeUnit.MINUTES)
.build();
}
public Either<String, RegistrationRequest> startRegistration(
@NonNull String username,
@NonNull String displayName,
Optional<String> credentialNickname,
ResidentKeyRequirement residentKeyRequirement,
Optional<ByteArray> sessionToken)
throws ExecutionException {
logger.trace(
"startRegistration username: {}, credentialNickname: {}", username, credentialNickname);
final Collection<CredentialRegistration> registrations =
userStorage.getRegistrationsByUsername(username);
final Optional<UserIdentity> existingUser =
registrations.stream().findAny().map(CredentialRegistration::getUserIdentity);
final boolean permissionGranted =
existingUser
.map(userIdentity -> sessions.isSessionForUser(userIdentity.getId(), sessionToken))
.orElse(true);
if (permissionGranted) {
final UserIdentity registrationUserId =
existingUser.orElseGet(
() ->
UserIdentity.builder()
.name(username)
.displayName(displayName)
.id(generateRandom(32))
.build());
RegistrationRequest request =
new RegistrationRequest(
username,
credentialNickname,
generateRandom(32),
rp.startRegistration(
StartRegistrationOptions.builder()
.user(registrationUserId)
.authenticatorSelection(
AuthenticatorSelectionCriteria.builder()
.residentKey(residentKeyRequirement)
.build())
.build()),
Optional.of(sessions.createSession(registrationUserId.getId())));
registerRequestStorage.put(request.getRequestId(), request);
return Either.right(request);
} else {
return Either.left("The username \"" + username + "\" is already registered.");
}
}
@Value
public static class SuccessfulRegistrationResult {
final boolean success = true;
RegistrationRequest request;
RegistrationResponse response;
CredentialRegistration registration;
boolean attestationTrusted;
Optional<AttestationCertInfo> attestationCert;
@JsonSerialize(using = AuthDataSerializer.class)
AuthenticatorData authData;
String username;
ByteArray sessionToken;
public SuccessfulRegistrationResult(
RegistrationRequest request,
RegistrationResponse response,
CredentialRegistration registration,
boolean attestationTrusted,
ByteArray sessionToken) {
this.request = request;
this.response = response;
this.registration = registration;
this.attestationTrusted = attestationTrusted;
attestationCert =
Optional.ofNullable(
response
.getCredential()
.getResponse()
.getAttestation()
.getAttestationStatement()
.get("x5c"))
.map(certs -> certs.get(0))
.flatMap(
(JsonNode certDer) -> {
try {
return Optional.of(new ByteArray(certDer.binaryValue()));
} catch (IOException e) {
logger.error("Failed to get binary value from x5c element: {}", certDer, e);
return Optional.empty();
}
})
.map(AttestationCertInfo::new);
this.authData = response.getCredential().getResponse().getParsedAuthenticatorData();
this.username = request.getUsername();
this.sessionToken = sessionToken;
}
}
@Value
public static class AttestationCertInfo {
final ByteArray der;
final String text;
public AttestationCertInfo(ByteArray certDer) {
der = certDer;
X509Certificate cert = null;
try {
cert = CertificateParser.parseDer(certDer.getBytes());
} catch (CertificateException e) {
logger.error("Failed to parse attestation certificate");
}
if (cert == null) {
text = null;
} else {
text = cert.toString();
}
}
}
public Either<List<String>, SuccessfulRegistrationResult> finishRegistration(
String responseJson) {
logger.trace("finishRegistration responseJson: {}", responseJson);
RegistrationResponse response = null;
try {
response = jsonMapper.readValue(responseJson, RegistrationResponse.class);
} catch (IOException e) {
logger.error("JSON error in finishRegistration; responseJson: {}", responseJson, e);
return Either.left(
Arrays.asList(
"Registration failed!", "Failed to decode response object.", e.getMessage()));
}
RegistrationRequest request = registerRequestStorage.getIfPresent(response.getRequestId());
registerRequestStorage.invalidate(response.getRequestId());
if (request == null) {
logger.debug("fail finishRegistration responseJson: {}", responseJson);
return Either.left(
Arrays.asList("Registration failed!", "No such registration in progress."));
} else {
try {
com.yubico.webauthn.RegistrationResult registration =
rp.finishRegistration(
FinishRegistrationOptions.builder()
.request(request.getPublicKeyCredentialCreationOptions())
.response(response.getCredential())
.build());
if (userStorage.userExists(request.getUsername())) {
boolean permissionGranted = false;
final boolean isValidSession =
request
.getSessionToken()
.map(
token ->
sessions.isSessionForUser(
request.getPublicKeyCredentialCreationOptions().getUser().getId(),
token))
.orElse(false);
logger.debug("Session token: {}", request.getSessionToken());
logger.debug("Valid session: {}", isValidSession);
if (isValidSession) {
permissionGranted = true;
logger.info(
"Session token accepted for user {}",
request.getPublicKeyCredentialCreationOptions().getUser().getId());
}
logger.debug("permissionGranted: {}", permissionGranted);
if (!permissionGranted) {
throw new RegistrationFailedException(
new IllegalArgumentException(
String.format("User %s already exists", request.getUsername())));
}
}
return Either.right(
new SuccessfulRegistrationResult(
request,
response,
addRegistration(
request.getPublicKeyCredentialCreationOptions().getUser(),
request.getCredentialNickname(),
registration),
registration.isAttestationTrusted(),
sessions.createSession(
request.getPublicKeyCredentialCreationOptions().getUser().getId())));
} catch (RegistrationFailedException e) {
logger.debug("fail finishRegistration responseJson: {}", responseJson, e);
return Either.left(Arrays.asList("Registration failed!", e.getMessage()));
} catch (Exception e) {
logger.error("fail finishRegistration responseJson: {}", responseJson, e);
return Either.left(
Arrays.asList(
"Registration failed unexpectedly; this is likely a bug.", e.getMessage()));
}
}
}
public Either<List<String>, AssertionRequestWrapper> startAuthentication(
Optional<String> username) {
logger.trace("startAuthentication username: {}", username);
if (username.isPresent() && !userStorage.userExists(username.get())) {
return Either.left(
Collections.singletonList("The username \"" + username.get() + "\" is not registered."));
} else {
AssertionRequestWrapper request =
new AssertionRequestWrapper(
generateRandom(32),
rp.startAssertion(StartAssertionOptions.builder().username(username).build()));
assertRequestStorage.put(request.getRequestId(), request);
return Either.right(request);
}
}
@Value
@AllArgsConstructor
public static final class SuccessfulAuthenticationResult {
private final boolean success = true;
private final AssertionRequestWrapper request;
private final AssertionResponse response;
private final Collection<CredentialRegistration> registrations;
@JsonSerialize(using = AuthDataSerializer.class)
AuthenticatorData authData;
private final String username;
private final ByteArray sessionToken;
public SuccessfulAuthenticationResult(
AssertionRequestWrapper request,
AssertionResponse response,
Collection<CredentialRegistration> registrations,
String username,
ByteArray sessionToken) {
this(
request,
response,
registrations,
response.getCredential().getResponse().getParsedAuthenticatorData(),
username,
sessionToken);
}
}
public Either<List<String>, SuccessfulAuthenticationResult> finishAuthentication(
String responseJson) {
logger.trace("finishAuthentication responseJson: {}", responseJson);
final AssertionResponse response;
try {
response = jsonMapper.readValue(responseJson, AssertionResponse.class);
} catch (IOException e) {
logger.debug("Failed to decode response object", e);
return Either.left(
Arrays.asList("Assertion failed!", "Failed to decode response object.", e.getMessage()));
}
AssertionRequestWrapper request = assertRequestStorage.getIfPresent(response.getRequestId());
assertRequestStorage.invalidate(response.getRequestId());
if (request == null) {
return Either.left(Arrays.asList("Assertion failed!", "No such assertion in progress."));
} else {
try {
AssertionResultV2<CredentialRegistration> result =
rp.finishAssertion(
FinishAssertionOptions.builder()
.request(request.getRequest())
.response(response.getCredential())
.build());
if (result.isSuccess()) {
try {
userStorage.updateSignatureCount(result);
} catch (Exception e) {
logger.error(
"Failed to update signature count for user \"{}\", credential \"{}\"",
result.getCredential().getUsername(),
response.getCredential().getId(),
e);
}
return Either.right(
new SuccessfulAuthenticationResult(
request,
response,
userStorage.getRegistrationsByUsername(result.getCredential().getUsername()),
result.getCredential().getUsername(),
sessions.createSession(result.getCredential().getUserHandle())));
} else {
return Either.left(Collections.singletonList("Assertion failed: Invalid assertion."));
}
} catch (AssertionFailedException e) {
logger.debug("Assertion failed", e);
return Either.left(Arrays.asList("Assertion failed!", e.getMessage()));
} catch (Exception e) {
logger.error("Assertion failed", e);
return Either.left(
Arrays.asList("Assertion failed unexpectedly; this is likely a bug.", e.getMessage()));
}
}
}
@Value
public static final class DeregisterCredentialResult {
boolean success = true;
CredentialRegistration droppedRegistration;
boolean accountDeleted;
}
public Either<List<String>, DeregisterCredentialResult> deregisterCredential(
@NonNull ByteArray sessionToken, ByteArray credentialId) {
logger.trace("deregisterCredential session: {}, credentialId: {}", sessionToken, credentialId);
if (credentialId == null || credentialId.getBytes().length == 0) {
return Either.left(Collections.singletonList("Credential ID must not be empty."));
}
Optional<ByteArray> session = sessions.getSession(sessionToken);
if (session.isPresent()) {
ByteArray userHandle = session.get();
Optional<String> username = userStorage.getUsernameForUserHandle(userHandle);
if (username.isPresent()) {
Optional<CredentialRegistration> credReg =
userStorage.getRegistrationByUsernameAndCredentialId(username.get(), credentialId);
if (credReg.isPresent()) {
userStorage.removeRegistrationByUsername(username.get(), credReg.get());
return Either.right(
new DeregisterCredentialResult(
credReg.get(), !userStorage.userExists(username.get())));
} else {
return Either.left(
Collections.singletonList("Credential ID not registered:" + credentialId));
}
} else {
return Either.left(Collections.singletonList("Invalid user handle"));
}
} else {
return Either.left(Collections.singletonList("Invalid session"));
}
}
public <T> Either<List<String>, T> deleteAccount(String username, Supplier<T> onSuccess) {
logger.trace("deleteAccount username: {}", username);
if (username == null || username.isEmpty()) {
return Either.left(Collections.singletonList("Username must not be empty."));
}
boolean removed = userStorage.removeAllRegistrations(username);
if (removed) {
return Either.right(onSuccess.get());
} else {
return Either.left(Collections.singletonList("Username not registered:" + username));
}
}
private CredentialRegistration addRegistration(
UserIdentity userIdentity, Optional<String> nickname, RegistrationResult result) {
return addRegistration(
userIdentity,
nickname,
RegisteredCredential.builder()
.credentialId(result.getKeyId().getId())
.userHandle(userIdentity.getId())
.publicKeyCose(result.getPublicKeyCose())
.signatureCount(result.getSignatureCount())
.build(),
result.getKeyId().getTransports().orElseGet(TreeSet::new),
metadataService.findEntries(result).stream().findAny());
}
private CredentialRegistration addRegistration(
UserIdentity userIdentity,
Optional<String> nickname,
RegisteredCredential credential,
SortedSet<AuthenticatorTransport> transports,
Optional<Object> attestationMetadata) {
CredentialRegistration reg =
CredentialRegistration.builder()
.userIdentity(userIdentity)
.credentialNickname(nickname)
.registrationTime(clock.instant())
.credential(credential)
.transports(transports)
.attestationMetadata(attestationMetadata)
.build();
logger.debug(
"Adding registration: user: {}, nickname: {}, credential: {}",
userIdentity,
nickname,
credential);
userStorage.addRegistrationByUsername(userIdentity.getName(), reg);
return reg;
}
private static class AuthDataSerializer extends JsonSerializer<AuthenticatorData> {
@Override
public void serialize(
AuthenticatorData value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeStringField("rpIdHash", value.getRpIdHash().getHex());
gen.writeObjectField("flags", value.getFlags());
gen.writeNumberField("signatureCounter", value.getSignatureCounter());
value
.getAttestedCredentialData()
.ifPresent(
acd -> {
try {
gen.writeObjectFieldStart("attestedCredentialData");
gen.writeStringField("aaguid", acd.getAaguid().getHex());
gen.writeStringField("credentialId", acd.getCredentialId().getHex());
gen.writeStringField("publicKey", acd.getCredentialPublicKey().getHex());
gen.writeEndObject();
} catch (IOException e) {
throw new RuntimeException(e);
}
});
value
.getExtensions()
.ifPresent(
extensions -> {
try {
gen.writeObjectField(
"extensions", JacksonCodecs.cbor().readTree(extensions.EncodeToBytes()));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
gen.writeEndObject();
}
}
}