use of com.yubico.webauthn.data.ByteArray in project java-webauthn-server by Yubico.
the class ThisShouldCompile method getByteArray.
public ByteArray getByteArray() {
ByteArray a = new ByteArray(new byte[] { 1, 2, 3, 4 });
byte[] b = a.getBytes();
return a;
}
use of com.yubico.webauthn.data.ByteArray in project java-webauthn-server by Yubico.
the class WebAuthnRestResource method deregisterCredential.
@Path("action/deregister")
@POST
public Response deregisterCredential(@NonNull @FormParam("sessionToken") String sessionTokenBase64, @NonNull @FormParam("credentialId") String credentialIdBase64) throws MalformedURLException, Base64UrlException {
logger.trace("deregisterCredential sesion: {}, credentialId: {}", sessionTokenBase64, credentialIdBase64);
final ByteArray credentialId;
try {
credentialId = ByteArray.fromBase64Url(credentialIdBase64);
} catch (Base64UrlException e) {
return messagesJson(Response.status(Status.BAD_REQUEST), "Credential ID is not valid Base64Url data: " + credentialIdBase64);
}
Either<List<String>, DeregisterCredentialResult> result = server.deregisterCredential(ByteArray.fromBase64Url(sessionTokenBase64), credentialId);
if (result.isRight()) {
return finishResponse(result, "Failed to deregister credential; further error message(s) were unfortunately lost to an internal server error.", "deregisterCredential", "");
} else {
return messagesJson(Response.status(Status.BAD_REQUEST), result.left().get());
}
}
use of com.yubico.webauthn.data.ByteArray in project java-webauthn-server by Yubico.
the class ExtensionMatcher method matchHex.
private boolean matchHex(String matchKey, JsonNode matchValue, ASN1Primitive value) {
final String matchValueString = matchValue.get(EXTENSION_VALUE_VALUE).textValue();
final ByteArray matchBytes;
try {
matchBytes = ByteArray.fromHex(matchValueString);
} catch (HexException e) {
throw new IllegalArgumentException(String.format("Bad hex value in extension %s: %s", matchKey, matchValueString));
}
final ASN1Primitive innerValue;
if (value instanceof DEROctetString) {
try {
innerValue = ASN1Primitive.fromByteArray(((DEROctetString) value).getOctets());
} catch (IOException e) {
log.debug("Failed to parse {} extension value as ASN1: {}", matchKey, value);
return false;
}
} else {
log.debug("Expected nested bit string value for extension {}, was: {}", matchKey, value);
return false;
}
if (innerValue instanceof DEROctetString) {
final ByteArray readBytes = new ByteArray(((DEROctetString) innerValue).getOctets());
return matchBytes.equals(readBytes);
} else {
log.debug("Expected nested bit string value for extension {}, was: {}", matchKey, value);
return false;
}
}
use of com.yubico.webauthn.data.ByteArray in project java-webauthn-server by Yubico.
the class PackedAttestationStatementVerifier method verifySelfAttestationSignature.
private boolean verifySelfAttestationSignature(AttestationObject attestationObject, ByteArray clientDataJsonHash) {
final PublicKey pubkey;
try {
pubkey = WebAuthnCodecs.importCosePublicKey(attestationObject.getAuthenticatorData().getAttestedCredentialData().get().getCredentialPublicKey());
} catch (IOException | CoseException | InvalidKeySpecException e) {
throw ExceptionUtil.wrapAndLog(log, String.format("Failed to parse public key from attestation data %s", attestationObject.getAuthenticatorData().getAttestedCredentialData()), e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
final Long keyAlgId = CBORObject.DecodeFromBytes(attestationObject.getAuthenticatorData().getAttestedCredentialData().get().getCredentialPublicKey().getBytes()).get(CBORObject.FromObject(3)).AsInt64();
final COSEAlgorithmIdentifier keyAlg = COSEAlgorithmIdentifier.fromId(keyAlgId).orElseThrow(() -> new IllegalArgumentException("Unsupported COSE algorithm identifier: " + keyAlgId));
final Long sigAlgId = attestationObject.getAttestationStatement().get("alg").asLong();
final COSEAlgorithmIdentifier sigAlg = COSEAlgorithmIdentifier.fromId(sigAlgId).orElseThrow(() -> new IllegalArgumentException("Unsupported COSE algorithm identifier: " + sigAlgId));
if (!Objects.equals(keyAlg, sigAlg)) {
throw new IllegalArgumentException(String.format("Key algorithm and signature algorithm must be equal, was: Key: %s, Sig: %s", keyAlg, sigAlg));
}
ByteArray signedData = attestationObject.getAuthenticatorData().getBytes().concat(clientDataJsonHash);
ByteArray signature;
try {
signature = new ByteArray(attestationObject.getAttestationStatement().get("sig").binaryValue());
} catch (IOException e) {
throw ExceptionUtil.wrapAndLog(log, ".binaryValue() of \"sig\" failed", e);
}
return Crypto.verifySignature(pubkey, signedData, signature, keyAlg);
}
use of com.yubico.webauthn.data.ByteArray in project java-webauthn-server by Yubico.
the class AndroidSafetynetAttestationStatementVerifier method verifyAttestationSignature.
@Override
public boolean verifyAttestationSignature(AttestationObject attestationObject, ByteArray clientDataJsonHash) {
final JsonNode ver = attestationObject.getAttestationStatement().get("ver");
if (ver == null || !ver.isTextual()) {
throw new IllegalArgumentException("Property \"ver\" of android-safetynet attestation statement must be a string, was: " + ver);
}
JsonWebSignatureCustom jws = parseJws(attestationObject);
if (!verifySignature(jws)) {
return false;
}
JsonNode payload = jws.getPayload();
ByteArray signedData = attestationObject.getAuthenticatorData().getBytes().concat(clientDataJsonHash);
ByteArray hashSignedData = Crypto.sha256(signedData);
ByteArray nonceByteArray = ByteArray.fromBase64(payload.get("nonce").textValue());
ExceptionUtil.assure(hashSignedData.equals(nonceByteArray), "Nonce does not equal authenticator data + client data. Expected nonce: %s, was nonce: %s", hashSignedData.getBase64Url(), nonceByteArray.getBase64Url());
ExceptionUtil.assure(payload.get("ctsProfileMatch").booleanValue(), "Expected ctsProfileMatch to be true, was: %s", payload.get("ctsProfileMatch"));
return true;
}
Aggregations