001/* 002 * Copyright 2026 Revetware LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.revetsec.webauthn; 018 019import org.jspecify.annotations.NonNull; 020import javax.annotation.concurrent.Immutable; 021import static java.util.Objects.requireNonNull; 022 023/** Checked account-pinned, action-bound WebAuthn reauthentication after admitted commitment. 024 * The application still authorizes its current session and atomically consumes its own action. 025 * This fact is not a transferable permission and does not authorize replay or recovery. 026 * @since 1.0.0 */ 027@Immutable 028public final class WebAuthnReauthentication { 029 private final @NonNull String credentialNamespace; 030 private final @NonNull String relyingPartyId; 031 private final byte @NonNull [] userHandle; 032 private final byte @NonNull [] credentialId; 033 private final boolean backupEligible; 034 private final boolean backedUp; 035 private final @NonNull String actionPurpose; 036 private final @NonNull String ceremonyId; 037 038 WebAuthnReauthentication(@NonNull String credentialNamespace, @NonNull String relyingPartyId, 039 byte @NonNull [] userHandle, byte @NonNull [] credentialId, 040 boolean backupEligible, boolean backedUp, @NonNull String actionPurpose, 041 @NonNull String ceremonyId) { 042 this.credentialNamespace = requireNonNull(credentialNamespace); 043 this.relyingPartyId = requireNonNull(relyingPartyId); 044 this.userHandle = requireNonNull(userHandle).clone(); 045 this.credentialId = requireNonNull(credentialId).clone(); 046 if (backedUp && !backupEligible) 047 throw new IllegalArgumentException("Invalid WebAuthn backup state"); 048 this.backupEligible = backupEligible; 049 this.backedUp = backedUp; 050 this.actionPurpose = requireNonNull(actionPurpose); 051 this.ceremonyId = requireNonNull(ceremonyId); 052 } 053 /** Returns the configured namespace. 054 * @return namespace 055 * @since 1.0.0 */ 056 public @NonNull String getCredentialNamespace() { return this.credentialNamespace; } 057 /** Returns the configured RP ID. 058 * @return relying-party ID 059 * @since 1.0.0 */ 060 public @NonNull String getRelyingPartyId() { return this.relyingPartyId; } 061 /** Returns the authoritative account handle. 062 * @return defensive handle copy 063 * @since 1.0.0 */ 064 public byte @NonNull [] getUserHandle() { return this.userHandle.clone(); } 065 /** Returns the credential used to reauthenticate; it need not be a removal target. 066 * @return defensive credential ID copy 067 * @since 1.0.0 */ 068 public byte @NonNull [] getCredentialId() { return this.credentialId.clone(); } 069 /** Returns the credential's permanent backup eligibility. 070 * @return backup eligibility 071 * @since 1.0.0 */ 072 public @NonNull Boolean isBackupEligible() { return Boolean.valueOf(this.backupEligible); } 073 /** Returns the backup state stored by this successful reauthentication. 074 * @return current backed-up state 075 * @since 1.0.0 */ 076 public @NonNull Boolean isBackedUp() { return Boolean.valueOf(this.backedUp); } 077 /** Returns the exact checked action label. 078 * @return action purpose 079 * @since 1.0.0 */ 080 public @NonNull String getActionPurpose() { return this.actionPurpose; } 081 /** Returns the exact successfully completed ceremony handle. The application compares it 082 * with its original pending action as well as current session, account, scope and purpose. 083 * It is not a new correlation secret or permission, and must not be logged. 084 * @return completed ceremony ID 085 * @since 1.0.0 */ 086 public @NonNull String getCeremonyId() { return this.ceremonyId; } 087 /** Redacts account, credential, ceremony and action data. 088 * @return fixed description 089 * @since 1.0.0 */ 090 @Override public @NonNull String toString() { return "WebAuthnReauthentication{identity=<redacted>}"; } 091}