Skip to content

Commit 5283afc

Browse files
committed
Rename assure to assertTrue
1 parent 8dce8bb commit 5283afc

File tree

11 files changed

+91
-89
lines changed

11 files changed

+91
-89
lines changed

webauthn-server-attestation/src/main/java/com/yubico/fido/metadata/AAGUID.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class AAGUID {
5050
* @param value a {@link ByteArray} of length exactly 16.
5151
*/
5252
public AAGUID(ByteArray value) {
53-
ExceptionUtil.assure(
53+
ExceptionUtil.assertTrue(
5454
value.size() == 16,
5555
"AAGUID as bytes must be exactly 16 bytes long, was %d: %s",
5656
value.size(),

webauthn-server-core/src/main/java/com/yubico/webauthn/AndroidSafetynetAttestationStatementVerifier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ public boolean verifyAttestationSignature(
7070
attestationObject.getAuthenticatorData().getBytes().concat(clientDataJsonHash);
7171
ByteArray hashSignedData = Crypto.sha256(signedData);
7272
ByteArray nonceByteArray = ByteArray.fromBase64(payload.get("nonce").textValue());
73-
ExceptionUtil.assure(
73+
ExceptionUtil.assertTrue(
7474
hashSignedData.equals(nonceByteArray),
7575
"Nonce does not equal authenticator data + client data. Expected nonce: %s, was nonce: %s",
7676
hashSignedData.getBase64Url(),
7777
nonceByteArray.getBase64Url());
7878

79-
ExceptionUtil.assure(
79+
ExceptionUtil.assertTrue(
8080
payload.get("ctsProfileMatch").booleanValue(),
8181
"Expected ctsProfileMatch to be true, was: %s",
8282
payload.get("ctsProfileMatch"));
@@ -133,7 +133,7 @@ private boolean verifySignature(JsonWebSignatureCustom jws) {
133133
}
134134

135135
// Verify the hostname of the certificate.
136-
ExceptionUtil.assure(
136+
ExceptionUtil.assertTrue(
137137
verifyHostname(attestationCertificate),
138138
"Certificate isn't issued for the hostname attest.android.com: %s",
139139
attestationCertificate);

webauthn-server-core/src/main/java/com/yubico/webauthn/FinishAssertionSteps.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
package com.yubico.webauthn;
2626

27-
import static com.yubico.internal.util.ExceptionUtil.assure;
27+
import static com.yubico.internal.util.ExceptionUtil.assertTrue;
2828

2929
import COSE.CoseException;
3030
import com.yubico.webauthn.data.AuthenticatorAssertionResponse;
@@ -112,7 +112,7 @@ public void validate() {
112112
.getAllowCredentials()
113113
.ifPresent(
114114
allowed -> {
115-
assure(
115+
assertTrue(
116116
allowed.stream().anyMatch(allow -> allow.getId().equals(response.getId())),
117117
"Unrequested credential ID: %s",
118118
response.getId());
@@ -153,25 +153,25 @@ public Step7 nextStep() {
153153

154154
@Override
155155
public void validate() {
156-
assure(
156+
assertTrue(
157157
request.getUsername().isPresent() || response.getResponse().getUserHandle().isPresent(),
158158
"At least one of username and user handle must be given; none was.");
159159

160-
assure(
160+
assertTrue(
161161
userHandle.isPresent(),
162162
"User handle not found for username: %s",
163163
request.getUsername(),
164164
response.getResponse().getUserHandle());
165165

166-
assure(
166+
assertTrue(
167167
username.isPresent(),
168168
"Username not found for userHandle: %s",
169169
request.getUsername(),
170170
response.getResponse().getUserHandle());
171171

172-
assure(registration.isPresent(), "Unknown credential: %s", response.getId());
172+
assertTrue(registration.isPresent(), "Unknown credential: %s", response.getId());
173173

174-
assure(
174+
assertTrue(
175175
userHandle.get().equals(registration.get().getUserHandle()),
176176
"User handle %s does not own credential %s",
177177
userHandle.get(),
@@ -180,7 +180,7 @@ public void validate() {
180180
final Optional<String> usernameFromRequest = request.getUsername();
181181
final Optional<ByteArray> userHandleFromResponse = response.getResponse().getUserHandle();
182182
if (usernameFromRequest.isPresent() && userHandleFromResponse.isPresent()) {
183-
assure(
183+
assertTrue(
184184
userHandleFromResponse.equals(
185185
credentialRepository.getUserHandleForUsername(usernameFromRequest.get())),
186186
"User handle %s in response does not match username %s in request",
@@ -203,7 +203,7 @@ public Step8 nextStep() {
203203

204204
@Override
205205
public void validate() {
206-
assure(
206+
assertTrue(
207207
credential.isPresent(),
208208
"Unknown credential. Credential ID: %s, user handle: %s",
209209
response.getId(),
@@ -219,9 +219,9 @@ class Step8 implements Step<Step10> {
219219

220220
@Override
221221
public void validate() {
222-
assure(clientData() != null, "Missing client data.");
223-
assure(authenticatorData() != null, "Missing authenticator data.");
224-
assure(signature() != null, "Missing signature.");
222+
assertTrue(clientData() != null, "Missing client data.");
223+
assertTrue(authenticatorData() != null, "Missing authenticator data.");
224+
assertTrue(signature() != null, "Missing signature.");
225225
}
226226

227227
@Override
@@ -251,7 +251,7 @@ class Step10 implements Step<Step11> {
251251

252252
@Override
253253
public void validate() {
254-
assure(clientData() != null, "Missing client data.");
254+
assertTrue(clientData() != null, "Missing client data.");
255255
}
256256

257257
@Override
@@ -272,7 +272,7 @@ class Step11 implements Step<Step12> {
272272

273273
@Override
274274
public void validate() {
275-
assure(
275+
assertTrue(
276276
CLIENT_DATA_TYPE.equals(clientData.getType()),
277277
"The \"type\" in the client data must be exactly \"%s\", was: %s",
278278
CLIENT_DATA_TYPE,
@@ -292,7 +292,7 @@ class Step12 implements Step<Step13> {
292292

293293
@Override
294294
public void validate() {
295-
assure(
295+
assertTrue(
296296
request
297297
.getPublicKeyCredentialRequestOptions()
298298
.getChallenge()
@@ -314,7 +314,7 @@ class Step13 implements Step<Step14> {
314314
@Override
315315
public void validate() {
316316
final String responseOrigin = response.getResponse().getClientData().getOrigin();
317-
assure(
317+
assertTrue(
318318
OriginMatcher.isAllowed(responseOrigin, origins, allowOriginPort, allowOriginSubdomain),
319319
"Incorrect origin: " + responseOrigin);
320320
}
@@ -350,15 +350,15 @@ class Step15 implements Step<Step16> {
350350
@Override
351351
public void validate() {
352352
try {
353-
assure(
353+
assertTrue(
354354
Crypto.sha256(rpId)
355355
.equals(response.getResponse().getParsedAuthenticatorData().getRpIdHash()),
356356
"Wrong RP ID hash.");
357357
} catch (IllegalArgumentException e) {
358358
Optional<AppId> appid =
359359
request.getPublicKeyCredentialRequestOptions().getExtensions().getAppid();
360360
if (appid.isPresent()) {
361-
assure(
361+
assertTrue(
362362
Crypto.sha256(appid.get().getId())
363363
.equals(response.getResponse().getParsedAuthenticatorData().getRpIdHash()),
364364
"Wrong RP ID hash.");
@@ -381,7 +381,7 @@ class Step16 implements Step<Step17> {
381381

382382
@Override
383383
public void validate() {
384-
assure(
384+
assertTrue(
385385
response.getResponse().getParsedAuthenticatorData().getFlags().UP,
386386
"User Presence is required.");
387387
}
@@ -403,7 +403,7 @@ public void validate() {
403403
.getPublicKeyCredentialRequestOptions()
404404
.getUserVerification()
405405
.equals(Optional.of(UserVerificationRequirement.REQUIRED))) {
406-
assure(
406+
assertTrue(
407407
response.getResponse().getParsedAuthenticatorData().getFlags().UV,
408408
"User Verification is required.");
409409
}
@@ -424,7 +424,7 @@ class PendingStep16 implements Step<Step18> {
424424

425425
@Override
426426
public void validate() {
427-
assure(
427+
assertTrue(
428428
!credential.isBackupEligible().isPresent()
429429
|| response.getResponse().getParsedAuthenticatorData().getFlags().BE
430430
== credential.isBackupEligible().get(),
@@ -461,7 +461,7 @@ class Step19 implements Step<Step20> {
461461

462462
@Override
463463
public void validate() {
464-
assure(clientDataJsonHash().size() == 32, "Failed to compute hash of client data");
464+
assertTrue(clientDataJsonHash().size() == 32, "Failed to compute hash of client data");
465465
}
466466

467467
@Override

webauthn-server-core/src/main/java/com/yubico/webauthn/FinishRegistrationSteps.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
package com.yubico.webauthn;
2626

27-
import static com.yubico.internal.util.ExceptionUtil.assure;
27+
import static com.yubico.internal.util.ExceptionUtil.assertTrue;
2828
import static com.yubico.internal.util.ExceptionUtil.wrapAndLog;
2929

3030
import COSE.CoseException;
@@ -129,7 +129,7 @@ default RegistrationResult run() {
129129
class Step6 implements Step<Step7> {
130130
@Override
131131
public void validate() {
132-
assure(clientData() != null, "Client data must not be null.");
132+
assertTrue(clientData() != null, "Client data must not be null.");
133133
}
134134

135135
@Override
@@ -148,7 +148,7 @@ class Step7 implements Step<Step8> {
148148

149149
@Override
150150
public void validate() {
151-
assure(
151+
assertTrue(
152152
CLIENT_DATA_TYPE.equals(clientData.getType()),
153153
"The \"type\" in the client data must be exactly \"%s\", was: %s",
154154
CLIENT_DATA_TYPE,
@@ -167,7 +167,7 @@ class Step8 implements Step<Step9> {
167167

168168
@Override
169169
public void validate() {
170-
assure(request.getChallenge().equals(clientData.getChallenge()), "Incorrect challenge.");
170+
assertTrue(request.getChallenge().equals(clientData.getChallenge()), "Incorrect challenge.");
171171
}
172172

173173
@Override
@@ -183,7 +183,7 @@ class Step9 implements Step<Step10> {
183183
@Override
184184
public void validate() {
185185
final String responseOrigin = clientData.getOrigin();
186-
assure(
186+
assertTrue(
187187
OriginMatcher.isAllowed(responseOrigin, origins, allowOriginPort, allowOriginSubdomain),
188188
"Incorrect origin: " + responseOrigin);
189189
}
@@ -213,7 +213,7 @@ public Step11 nextStep() {
213213
class Step11 implements Step<Step12> {
214214
@Override
215215
public void validate() {
216-
assure(clientDataJsonHash().size() == 32, "Failed to compute hash of client data");
216+
assertTrue(clientDataJsonHash().size() == 32, "Failed to compute hash of client data");
217217
}
218218

219219
@Override
@@ -232,7 +232,7 @@ class Step12 implements Step<Step13> {
232232

233233
@Override
234234
public void validate() {
235-
assure(attestation() != null, "Malformed attestation object.");
235+
assertTrue(attestation() != null, "Malformed attestation object.");
236236
}
237237

238238
@Override
@@ -252,7 +252,7 @@ class Step13 implements Step<Step14> {
252252

253253
@Override
254254
public void validate() {
255-
assure(
255+
assertTrue(
256256
Crypto.sha256(rpId)
257257
.equals(response.getResponse().getAttestation().getAuthenticatorData().getRpIdHash()),
258258
"Wrong RP ID hash.");
@@ -271,7 +271,7 @@ class Step14 implements Step<Step15> {
271271

272272
@Override
273273
public void validate() {
274-
assure(
274+
assertTrue(
275275
response.getResponse().getParsedAuthenticatorData().getFlags().UP,
276276
"User Presence is required.");
277277
}
@@ -294,7 +294,7 @@ public void validate() {
294294
.flatMap(AuthenticatorSelectionCriteria::getUserVerification)
295295
.orElse(UserVerificationRequirement.PREFERRED)
296296
== UserVerificationRequirement.REQUIRED) {
297-
assure(
297+
assertTrue(
298298
response.getResponse().getParsedAuthenticatorData().getFlags().UV,
299299
"User Verification is required.");
300300
}
@@ -323,7 +323,7 @@ public void validate() {
323323
.getCredentialPublicKey();
324324
CBORObject publicKeyCbor = CBORObject.DecodeFromBytes(publicKeyCose.getBytes());
325325
final int alg = publicKeyCbor.get(CBORObject.FromObject(3)).AsInt32();
326-
assure(
326+
assertTrue(
327327
request.getPubKeyCredParams().stream()
328328
.anyMatch(pkcparam -> pkcparam.getAlg().getId() == alg),
329329
"Unrequested credential key algorithm: got %d, expected one of: %s",
@@ -393,12 +393,12 @@ class Step19 implements Step<Step20> {
393393
public void validate() {
394394
attestationStatementVerifier.ifPresent(
395395
verifier -> {
396-
assure(
396+
assertTrue(
397397
verifier.verifyAttestationSignature(attestation, clientDataJsonHash),
398398
"Invalid attestation signature.");
399399
});
400400

401-
assure(attestationType() != null, "Failed to determine attestation type");
401+
assertTrue(attestationType() != null, "Failed to determine attestation type");
402402
}
403403

404404
@Override
@@ -522,7 +522,7 @@ public Step21(
522522

523523
@Override
524524
public void validate() {
525-
assure(
525+
assertTrue(
526526
allowUntrustedAttestation || attestationTrusted,
527527
"Failed to derive trust for attestation key.");
528528
}
@@ -617,7 +617,7 @@ class Step22 implements Step<Finished> {
617617

618618
@Override
619619
public void validate() {
620-
assure(
620+
assertTrue(
621621
credentialRepository.lookupAll(response.getId()).isEmpty(),
622622
"Credential ID is already registered: %s",
623623
response.getId());

webauthn-server-core/src/main/java/com/yubico/webauthn/PackedAttestationStatementVerifier.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private boolean verifyX5cSignature(
189189
throw new IllegalArgumentException(
190190
"Packed attestation statement must have field \"alg\".");
191191
}
192-
ExceptionUtil.assure(
192+
ExceptionUtil.assertTrue(
193193
algNode.isIntegralNumber(),
194194
"Field \"alg\" in packed attestation statement must be a COSEAlgorithmIdentifier.");
195195
final Long sigAlgId = algNode.asLong();
@@ -276,16 +276,16 @@ public boolean verifyX5cRequirements(X509Certificate cert, ByteArray aaguid) {
276276
final Set<String> countries =
277277
CollectionUtil.immutableSet(new HashSet<>(Arrays.asList(Locale.getISOCountries())));
278278

279-
ExceptionUtil.assure(
279+
ExceptionUtil.assertTrue(
280280
getDnField("C", cert).filter(countries::contains).isPresent(),
281281
"Invalid attestation certificate country code: %s",
282282
getDnField("C", cert));
283283

284-
ExceptionUtil.assure(
284+
ExceptionUtil.assertTrue(
285285
getDnField("O", cert).filter(o -> !((String) o).isEmpty()).isPresent(),
286286
"Organization (O) field of attestation certificate DN must be present.");
287287

288-
ExceptionUtil.assure(
288+
ExceptionUtil.assertTrue(
289289
getDnField("OU", cert).filter(ouValue::equals).isPresent(),
290290
"Organization Unit (OU) field of attestation certificate DN must be exactly \"%s\", was: %s",
291291
ouValue,
@@ -294,12 +294,12 @@ public boolean verifyX5cRequirements(X509Certificate cert, ByteArray aaguid) {
294294
CertificateParser.parseFidoAaguidExtension(cert)
295295
.ifPresent(
296296
extensionAaguid -> {
297-
ExceptionUtil.assure(
297+
ExceptionUtil.assertTrue(
298298
Arrays.equals(aaguid.getBytes(), extensionAaguid),
299299
"X.509 extension \"id-fido-gen-ce-aaguid\" is present but does not match the authenticator AAGUID.");
300300
});
301301

302-
ExceptionUtil.assure(
302+
ExceptionUtil.assertTrue(
303303
cert.getBasicConstraints() == -1, "Attestation certificate must not be a CA certificate.");
304304

305305
return true;

0 commit comments

Comments
 (0)