Commit 35392d90 authored by Adam Langley's avatar Adam Langley Committed by Commit Bot

device/fido: log CBOR error descriptions

This change causes the human-readable form of the CBOR errors to be
included in log messages and also logs messages from parse errors in
GetInfo requests (which are handled differently).

This would have been helpful when figuring out why the Solo Key wasn't
working as a CTAP2 device.

Change-Id: I11f241a740a50a4f0b1edb45e4d535a193561a93
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1565088
Commit-Queue: Adam Langley <agl@chromium.org>
Reviewed-by: default avatarMartin Kreichgauer <martinkr@google.com>
Cr-Commit-Position: refs/heads/master@{#650640}
parent 8bfa2be9
......@@ -134,8 +134,9 @@ class Ctap2DeviceOperation : public DeviceOperation<Request, Response> {
cbor::Reader::DecoderError error;
cbor = cbor::Reader::Read(cbor_bytes, &error);
if (!cbor) {
FIDO_LOG(ERROR) << "-> (CBOR parse error " << static_cast<int>(error)
<< " from "
FIDO_LOG(ERROR) << "-> (CBOR parse error '"
<< cbor::Reader::ErrorCodeToString(error)
<< "' from raw message "
<< base::HexEncode(device_response->data(),
device_response->size())
<< ")";
......
......@@ -12,6 +12,7 @@
#include "base/numerics/safe_conversions.h"
#include "base/optional.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "components/cbor/diagnostic_writer.h"
#include "components/cbor/reader.h"
#include "components/cbor/writer.h"
......@@ -142,9 +143,19 @@ base::Optional<AuthenticatorGetInfoResponse> ReadCTAPGetInfoResponse(
GetResponseCode(buffer) != CtapDeviceResponseCode::kSuccess)
return base::nullopt;
base::Optional<CBOR> decoded_response = cbor::Reader::Read(buffer.subspan(1));
cbor::Reader::DecoderError error;
base::Optional<CBOR> decoded_response =
cbor::Reader::Read(buffer.subspan(1), &error);
if (!decoded_response || !decoded_response->is_map())
if (!decoded_response) {
FIDO_LOG(ERROR) << "-> (CBOR parse error from GetInfo response '"
<< cbor::Reader::ErrorCodeToString(error)
<< "' from raw message "
<< base::HexEncode(buffer.data(), buffer.size()) << ")";
return base::nullopt;
}
if (!decoded_response->is_map())
return base::nullopt;
FIDO_LOG(DEBUG) << "-> " << cbor::DiagnosticWriter::Write(*decoded_response);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment