make sure to properly update the sign count

This commit is contained in:
MiniDigger | Martin 2023-04-02 00:46:57 +02:00
parent 6697d7113a
commit 515ae82e68
2 changed files with 16 additions and 0 deletions

View File

@ -79,6 +79,8 @@ public class LoginController extends HangarComponent {
.response(pkc)
.build());
this.webAuthNService.updateCredential(userTable.getUserId(), result.getCredential().getCredentialId().getBase64(), result.getSignatureCount());
if (result.isSuccess()) {
return this.setAalAndLogin(userTable, 2);
}

View File

@ -115,6 +115,20 @@ public class WebAuthNService implements CredentialRepository {
return webAuthNCredential.pendingLogin();
}
public void updateCredential(final long userId, final String credentialId, final long signatureCount) {
final WebAuthNCredential webAuthNCredential = this.getWebAuthNCredential(userId);
final var any = webAuthNCredential.credentials().stream().filter(c -> c.id().equals(credentialId)).findAny();
if (any.isPresent()) {
final WebAuthNCredential.WebAuthNDevice oldDevice = any.get();
final WebAuthNCredential.Authenticator patchedAuthenticator = new WebAuthNCredential.Authenticator(oldDevice.authenticator().aaguid(), signatureCount, oldDevice.authenticator().cloneWarning());
final WebAuthNCredential.WebAuthNDevice patchedDevice = new WebAuthNCredential.WebAuthNDevice(oldDevice.id(), oldDevice.addedAt(), oldDevice.publicKey(), oldDevice.displayName(), patchedAuthenticator, oldDevice.isPasswordLess(), oldDevice.attestationType());
webAuthNCredential.credentials().remove(oldDevice);
webAuthNCredential.credentials().add(patchedDevice);
this.credentialsService.updateCredential(userId, webAuthNCredential);
}
}
private WebAuthNCredential getWebAuthNCredential(final long userId) {
final UserCredentialTable credential = this.credentialsService.getCredential(userId, CredentialType.WEBAUTHN);
if (credential == null) {