use of com.google.u2f.U2FException in project OpenUnison by TremoloSecurity.
the class U2FServerReferenceImpl method verifyBrowserData.
private void verifyBrowserData(JsonElement browserDataAsElement, String messageType, EnrollSessionData sessionData) throws U2FException {
if (!browserDataAsElement.isJsonObject()) {
throw new U2FException("browserdata has wrong format");
}
JsonObject browserData = browserDataAsElement.getAsJsonObject();
// check that the right "typ" parameter is present in the browserdata JSON
if (!browserData.has(TYPE_PARAM)) {
throw new U2FException("bad browserdata: missing 'typ' param");
}
String type = browserData.get(TYPE_PARAM).getAsString();
if (!messageType.equals(type)) {
throw new U2FException("bad browserdata: bad type " + type);
}
// check that the right challenge is in the browserdata
if (!browserData.has(CHALLENGE_PARAM)) {
throw new U2FException("bad browserdata: missing 'challenge' param");
}
if (browserData.has(ORIGIN_PARAM)) {
verifyOrigin(browserData.get(ORIGIN_PARAM).getAsString());
}
byte[] challengeFromBrowserData = Base64.decodeBase64(browserData.get(CHALLENGE_PARAM).getAsString());
if (!Arrays.equals(challengeFromBrowserData, sessionData.getChallenge())) {
throw new U2FException("wrong challenge signed in browserdata");
}
// TODO: Deal with ChannelID
}
Aggregations