feat: update RegistrationTest

This commit is contained in:
2022-09-13 00:03:11 +08:00
parent e819351318
commit db6967954f

View File

@@ -4,49 +4,39 @@ import com.webauthn4j.WebAuthnManager;
import com.webauthn4j.authenticator.Authenticator; import com.webauthn4j.authenticator.Authenticator;
import com.webauthn4j.authenticator.AuthenticatorImpl; import com.webauthn4j.authenticator.AuthenticatorImpl;
import com.webauthn4j.converter.exception.DataConversionException; import com.webauthn4j.converter.exception.DataConversionException;
import com.webauthn4j.converter.util.ObjectConverter;
import com.webauthn4j.data.RegistrationData; import com.webauthn4j.data.RegistrationData;
import com.webauthn4j.data.RegistrationParameters; import com.webauthn4j.data.RegistrationParameters;
import com.webauthn4j.data.RegistrationRequest; import com.webauthn4j.data.RegistrationRequest;
import com.webauthn4j.data.client.Origin; import com.webauthn4j.data.client.Origin;
import com.webauthn4j.data.client.challenge.Challenge; import com.webauthn4j.data.client.challenge.Challenge;
import com.webauthn4j.data.client.challenge.DefaultChallenge;
import com.webauthn4j.server.ServerProperty; import com.webauthn4j.server.ServerProperty;
import com.webauthn4j.validator.attestation.statement.androidkey.AndroidKeyAttestationStatementValidator;
import com.webauthn4j.validator.attestation.statement.none.NoneAttestationStatementValidator;
import com.webauthn4j.validator.attestation.statement.packed.PackedAttestationStatementValidator;
import com.webauthn4j.validator.attestation.statement.u2f.FIDOU2FAttestationStatementValidator;
import com.webauthn4j.validator.attestation.trustworthiness.certpath.NullCertPathTrustworthinessValidator;
import com.webauthn4j.validator.attestation.trustworthiness.self.DefaultSelfAttestationTrustworthinessValidator;
import com.webauthn4j.validator.exception.ValidationException; import com.webauthn4j.validator.exception.ValidationException;
import java.util.Arrays; import java.util.Base64;
import java.util.Set; import java.util.Set;
public class RegistrationTest { public class RegistrationTest {
public static void main(String[] args) { public static void main(String[] args) {
NoneAttestationStatementValidator noneAttestationStatementValidator = new NoneAttestationStatementValidator(); final WebAuthnManager webAuthnManager = WebAuthnManager.createNonStrictWebAuthnManager();
PackedAttestationStatementValidator packedAttestationStatementValidator = new PackedAttestationStatementValidator();
FIDOU2FAttestationStatementValidator fidoU2FAttestationStatementValidator = new FIDOU2FAttestationStatementValidator();
AndroidKeyAttestationStatementValidator androidKeyAttestationStatementValidator = new AndroidKeyAttestationStatementValidator();
WebAuthnManager webAuthnManager = new WebAuthnManager(
Arrays.asList(
noneAttestationStatementValidator,
packedAttestationStatementValidator,
fidoU2FAttestationStatementValidator,
androidKeyAttestationStatementValidator),
new NullCertPathTrustworthinessValidator(),
new DefaultSelfAttestationTrustworthinessValidator()
);
// Client properties // Client properties
byte[] attestationObject = null /* set attestationObject */; byte[] attestationObject = Base64.getDecoder().decode(
byte[] clientDataJSON = null /* set clientDataJSON */; "o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YVjEpsgt0bu+R+ByQyBUetbRm6lpnGs1J+xG0aiPibAecetBAAAAAAAAAAAAAA" +
"AAAAAAAAAAAAAAQNTx6PTk9brwl1jiBcAbGsn3V2L1XU+6+JDg4a8IsJx2mg6oO+14WViasOGaNoxr45fQWF4hHutwlK4e" +
"SUX0KXulAQIDJiABIVgg3gWp1uy1VCG4f+0Ridi9JMNkVt+7sqxAG0tHvRLiCiYiWCBDBj1vuGo2LQO0m+vnybhMpKQFgh" +
"I7POhdVphXBRVfxA==");
byte[] clientDataJSON = Base64.getDecoder().decode(
"eyJ0eXBlIjoid2ViYXV0aG4uY3JlYXRlIiwiY2hhbGxlbmdlIjoiUVYya2hLNUNDQnVIdXZseDdLcG5yUV9FeVhFIiwib3JpZ2" +
"luIjoiaHR0cHM6Ly9oYXR0ZXIuaW5rIiwiY3Jvc3NPcmlnaW4iOmZhbHNlfQ==");
String clientExtensionJSON = null; /* set clientExtensionJSON */ String clientExtensionJSON = null; /* set clientExtensionJSON */
Set<String> transports = null /* set transports */; Set<String> transports = null /* set transports */;
// Server properties // Server properties
Origin origin = null /* set origin */; Origin origin = new Origin("https://hatter.ink") /* set origin */;
String rpId = null /* set rpId */; String rpId = "hatter.ink" /* set rpId */;
Challenge challenge = null /* set challenge */; Challenge challenge = new DefaultChallenge(Base64.getUrlDecoder().decode("QV2khK5CCBuHuvlx7KpnrQ_EyXE"));
byte[] tokenBindingId = null /* set tokenBindingId */; byte[] tokenBindingId = null /* set tokenBindingId */;
ServerProperty serverProperty = new ServerProperty(origin, rpId, challenge, tokenBindingId); ServerProperty serverProperty = new ServerProperty(origin, rpId, challenge, tokenBindingId);
@@ -83,5 +73,9 @@ public class RegistrationTest {
registrationData.getAttestationObject().getAttestationStatement(), registrationData.getAttestationObject().getAttestationStatement(),
registrationData.getAttestationObject().getAuthenticatorData().getSignCount() registrationData.getAttestationObject().getAuthenticatorData().getSignCount()
); );
final ObjectConverter objectConverter = new ObjectConverter();
String a = objectConverter.getJsonConverter().writeValueAsString(authenticator);
System.out.println(a);
} }
} }