Skip to content

Commit cbc7bed

Browse files
U-VASCO\jovU-VASCO\jov
authored andcommitted
Add lowlevel BLE tracing.
1 parent 958a3f6 commit cbc7bed

12 files changed

Lines changed: 95 additions & 51 deletions

File tree

u2f-tests/BLE/BLETest/BLETest.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ bool arg_u2f = true;
1717
bool arg_transport = true;
1818
bool arg_iso7816 = false;
1919
bool arg_encryption = true;
20+
bool arg_tracing = false;
2021

2122
#define REPLY_BUFFER_LENGTH 256
2223
static unsigned char reply[REPLY_BUFFER_LENGTH];
@@ -101,8 +102,7 @@ ReturnValue BLETransportTests(pBleDevice dev)
101102

102103
ReturnValue U2FISO7816EncodingTests(pBleDevice dev)
103104
{
104-
std::
105-
cout << std::endl << "==== BLE ISO7816-4 Encoding tests ====" <<
105+
std::cout << std::endl << "==== BLE ISO7816-4 Encoding tests ====" <<
106106
std::endl;
107107
WaitForUserPresence(dev, arg_hasButton);
108108

@@ -128,8 +128,8 @@ ReturnValue U2FISO7816EncodingTests(pBleDevice dev)
128128

129129
ReturnValue U2FTests(pBleDevice dev)
130130
{
131-
std::cout << std::
132-
endl << "==== U2F Raw Message tests ====" << std::endl;
131+
std::cout << std::endl << "==== U2F Raw Message tests ====" << std::
132+
endl;
133133
WaitForUserPresence(dev, arg_hasButton);
134134

135135
PASS(BleApiTest_GetU2FProtocolVersion(dev));
@@ -201,7 +201,8 @@ void Usage(char *name)
201201
<< " -x : Disable encrypted connection requirement." << std::endl
202202
<< " -c : Toggle ANSI colors." << std::endl
203203
<< " -l : Show all known FIDO BLE devices and exit." << std::endl
204-
<< " -d : Select specific FIDO BLE device." << std::endl;
204+
<< " -d : Select specific FIDO BLE device." << std::endl
205+
<< " -T : turn on BLE level tracing." << std::endl;
205206
exit(-1);
206207
}
207208

@@ -260,6 +261,10 @@ int __cdecl main(int argc, char *argv[])
260261
// treat warnings as errors
261262
arg_ShowDevices = true;
262263
}
264+
if (!strncmp(argv[count], "-T", 2)) {
265+
// treat warnings as errors
266+
arg_tracing = true;
267+
}
263268
if (!strncmp(argv[count], "-d", 2)) {
264269
// treat warnings as errors
265270
++count;
@@ -282,7 +287,7 @@ int __cdecl main(int argc, char *argv[])
282287
}
283288

284289
try {
285-
pBleApi api = BleApi::CreateAPI(arg_encryption);
290+
pBleApi api = BleApi::CreateAPI(arg_encryption, arg_tracing);
286291

287292
/* find U2F Devices */
288293
std::vector < pBleDevice > devices = api->findDevices();
@@ -297,8 +302,8 @@ int __cdecl main(int argc, char *argv[])
297302

298303
std::cout << "All valid FIDO BLE devices:" << std::endl;
299304
for (i = devices.begin(); i != devices.end(); i++) {
300-
std::cout << " " << (*i)->
301-
Identifier() << std::endl;
305+
std::cout << " " << (*i)->Identifier() << std::
306+
endl;
302307
}
303308
exit(0);
304309
}

u2f-tests/BLE/BLETest/U2FTests.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ReturnValue BleApiTest_UnknownINS(pBleDevice dev)
8181

8282
/* check reply */
8383
CHECK_EQ(replyLength, 2);
84-
CHECK_EQ(FIDO_RESP_INVALID_INSTRUCTION, b2s(reply, 0));
84+
CHECK_EQ(FIDO_RESP_INVALID_INSTRUCTION, bytes2short(reply, 0));
8585

8686
return BLEAPI_ERROR_SUCCESS;
8787
}
@@ -104,7 +104,7 @@ ReturnValue BleApiTest_BadCLA(pBleDevice dev)
104104

105105
/* check reply */
106106
CHECK_EQ(replyLength, 2);
107-
CHECK_EQ(FIDO_RESP_CLA_NOT_SUPPORTED, b2s(reply, 0));
107+
CHECK_EQ(FIDO_RESP_CLA_NOT_SUPPORTED, bytes2short(reply, 0));
108108

109109
return BLEAPI_ERROR_SUCCESS;
110110
}
@@ -127,7 +127,7 @@ ReturnValue BleApiTest_VersionWrongLength(pBleDevice dev)
127127

128128
/* check reply */
129129
CHECK_EQ(replyLength, 2);
130-
CHECK_EQ(FIDO_RESP_WRONG_LENGTH, b2s(reply, 0));
130+
CHECK_EQ(FIDO_RESP_WRONG_LENGTH, bytes2short(reply, 0));
131131

132132
return BLEAPI_ERROR_SUCCESS;
133133
}
@@ -152,7 +152,7 @@ ReturnValue BleApiTest_RegisterWrongLength(pBleDevice dev)
152152

153153
/* check reply */
154154
CHECK_EQ(replyLength, 2);
155-
CHECK_EQ(FIDO_RESP_WRONG_LENGTH, b2s(reply, 0));
155+
CHECK_EQ(FIDO_RESP_WRONG_LENGTH, bytes2short(reply, 0));
156156

157157
return BLEAPI_ERROR_SUCCESS;
158158
}
@@ -202,14 +202,14 @@ ReturnValue BleApiTest_Enroll(pBleDevice dev, int expectedSW12)
202202
CHECK_EQ(retval, BLEAPI_ERROR_SUCCESS);
203203

204204
if (expectedSW12 != FIDO_RESP_SUCCESS) {
205-
CHECK_EQ(expectedSW12, b2s(reply, replyLength - 2));
205+
CHECK_EQ(expectedSW12, bytes2short(reply, replyLength - 2));
206206
CHECK_EQ(replyLength, 2);
207207
return BLEAPI_ERROR_SUCCESS;
208208
}
209209

210210
/* check reply */
211211
CHECK_EQ(replyCmd, FIDO_BLE_CMD_MSG);
212-
CHECK_EQ(FIDO_RESP_SUCCESS, b2s(reply, replyLength - 2));
212+
CHECK_EQ(FIDO_RESP_SUCCESS, bytes2short(reply, replyLength - 2));
213213
CHECK_NE(replyLength, 2);
214214

215215
CHECK_LE(replyLength - 2, sizeof(U2F_REGISTER_RESP));
@@ -227,15 +227,15 @@ ReturnValue BleApiTest_Enroll(pBleDevice dev, int expectedSW12)
227227
// Check crypto of enroll response.
228228
std::string cert;
229229
CHECK_EQ(getCertificate(regRsp, &cert), true);
230-
INFO << "cert: " << b2a(cert);
230+
INFO << "cert: " << bytes2ascii(cert);
231231

232232
std::string pk;
233233
CHECK_EQ(getSubjectPublicKey(cert, &pk), true);
234-
INFO << "pk : " << b2a(pk);
234+
INFO << "pk : " << bytes2ascii(pk);
235235

236236
std::string sig;
237-
CHECK_EQ(getSignature(regRsp, &sig), true);
238-
INFO << "sig : " << b2a(sig);
237+
CHECK_EQ(getSignature(regRsp, cert.size(), &sig), true);
238+
INFO << "sig : " << bytes2ascii(sig);
239239

240240
// Parse signature into two integers.
241241
p256_int sig_r, sig_s;
@@ -256,7 +256,7 @@ ReturnValue BleApiTest_Enroll(pBleDevice dev, int expectedSW12)
256256
hash = SHA256_final(&sha);
257257
p256_from_bin(hash, &h);
258258

259-
INFO << "hash : " << b2a(hash, 32);
259+
INFO << "hash : " << bytes2ascii((char *)hash, 32);
260260

261261
// Parse subject public key into two integers.
262262
CHECK_EQ(pk.size(), P256_POINT_SIZE);
@@ -317,13 +317,13 @@ uint32_t BleApiTest_Sign(pBleDevice dev, int expectedSW12, bool checkOnly,
317317
CHECK_EQ(retval, BLEAPI_ERROR_SUCCESS);
318318

319319
if (expectedSW12 != FIDO_RESP_SUCCESS) {
320-
CHECK_EQ(expectedSW12, b2s(reply, replyLength - 2));
320+
CHECK_EQ(expectedSW12, bytes2short(reply, replyLength - 2));
321321
CHECK_EQ(replyLength, 2);
322322
return BLEAPI_ERROR_SUCCESS;
323323
}
324324

325325
CHECK_EQ(replyCmd, FIDO_BLE_CMD_MSG);
326-
CHECK_EQ(FIDO_RESP_SUCCESS, b2s(reply, replyLength - 2));
326+
CHECK_EQ(FIDO_RESP_SUCCESS, bytes2short(reply, replyLength - 2));
327327
CHECK_NE(replyLength, 2);
328328
CHECK_LE(replyLength - 2, sizeof(U2F_AUTHENTICATE_RESP));
329329

@@ -379,7 +379,7 @@ ReturnValue BleApiTest_TestEncodingShortAnyLength(pBleDevice dev)
379379
if (retval != BLEAPI_ERROR_SUCCESS)
380380
return retval;
381381

382-
CHECK_EQ(FIDO_RESP_SUCCESS, b2s(reply, replyLength - 2));
382+
CHECK_EQ(FIDO_RESP_SUCCESS, bytes2short(reply, replyLength - 2));
383383

384384
/* drop reply status code. */
385385
reply[replyLength - 2] = '\0';
@@ -408,7 +408,7 @@ ReturnValue BleApiTest_TestEncodingShortExactLength(pBleDevice dev)
408408
if (retval != BLEAPI_ERROR_SUCCESS)
409409
return retval;
410410

411-
CHECK_EQ(FIDO_RESP_SUCCESS, b2s(reply, replyLength - 2));
411+
CHECK_EQ(FIDO_RESP_SUCCESS, bytes2short(reply, replyLength - 2));
412412

413413
/* drop reply status code. */
414414
reply[replyLength - 2] = '\0';
@@ -439,7 +439,7 @@ ReturnValue BleApiTest_TestEncodingShortWrongLength(pBleDevice dev)
439439

440440
/* check U2F Protocol version */
441441
CHECK_EQ(replyLength, 2);
442-
CHECK_EQ(FIDO_RESP_WRONG_LENGTH, b2s(reply, 0));
442+
CHECK_EQ(FIDO_RESP_WRONG_LENGTH, bytes2short(reply, 0));
443443

444444
return BLEAPI_ERROR_SUCCESS;
445445
}
@@ -461,7 +461,7 @@ ReturnValue BleApiTest_TestEncodingLongAnyLength(pBleDevice dev)
461461
if (retval != BLEAPI_ERROR_SUCCESS)
462462
return retval;
463463

464-
CHECK_EQ(FIDO_RESP_SUCCESS, b2s(reply, replyLength - 2));
464+
CHECK_EQ(FIDO_RESP_SUCCESS, bytes2short(reply, replyLength - 2));
465465

466466
/* drop reply status code. */
467467
reply[replyLength - 2] = '\0';
@@ -490,7 +490,7 @@ ReturnValue BleApiTest_TestEncodingLongExactLength(pBleDevice dev)
490490
if (retval != BLEAPI_ERROR_SUCCESS)
491491
return retval;
492492

493-
CHECK_EQ(FIDO_RESP_SUCCESS, b2s(reply, replyLength - 2));
493+
CHECK_EQ(FIDO_RESP_SUCCESS, bytes2short(reply, replyLength - 2));
494494

495495
/* drop reply status code. */
496496
reply[replyLength - 2] = '\0';
@@ -521,7 +521,7 @@ ReturnValue BleApiTest_TestEncodingLongWrongLength(pBleDevice dev)
521521

522522
/* check U2F Protocol version */
523523
CHECK_EQ(replyLength, 2);
524-
CHECK_EQ(FIDO_RESP_WRONG_LENGTH, b2s(reply, 0));
524+
CHECK_EQ(FIDO_RESP_WRONG_LENGTH, bytes2short(reply, 0));
525525

526526
return BLEAPI_ERROR_SUCCESS;
527527
}
@@ -567,7 +567,7 @@ ReturnValue BleApiTest_TestEncodingLongDataAnyLength(pBleDevice dev)
567567
CHECK_EQ(retval, BLEAPI_ERROR_SUCCESS);
568568

569569
CHECK_EQ(replyCmd, FIDO_BLE_CMD_MSG);
570-
CHECK_EQ(FIDO_RESP_SUCCESS, b2s(reply, replyLength - 2));
570+
CHECK_EQ(FIDO_RESP_SUCCESS, bytes2short(reply, replyLength - 2));
571571
CHECK_NE(replyLength, 2);
572572
CHECK_LE(replyLength - 2, sizeof(U2F_AUTHENTICATE_RESP));
573573

@@ -616,7 +616,7 @@ ReturnValue BleApiTest_TestEncodingLongDataExactLength(pBleDevice dev)
616616
CHECK_EQ(retval, BLEAPI_ERROR_SUCCESS);
617617

618618
CHECK_EQ(replyCmd, FIDO_BLE_CMD_MSG);
619-
CHECK_EQ(FIDO_RESP_SUCCESS, b2s(reply, replyLength - 2));
619+
CHECK_EQ(FIDO_RESP_SUCCESS, bytes2short(reply, replyLength - 2));
620620
CHECK_NE(replyLength, 2);
621621
CHECK_LE(replyLength - 2, sizeof(U2F_AUTHENTICATE_RESP));
622622

@@ -665,7 +665,7 @@ ReturnValue BleApiTest_TestEncodingLongDataWrongLength(pBleDevice dev)
665665

666666
/* check U2F Protocol version */
667667
CHECK_EQ(replyLength, 2);
668-
CHECK_EQ(FIDO_RESP_WRONG_LENGTH, b2s(reply, 0));
668+
CHECK_EQ(FIDO_RESP_WRONG_LENGTH, bytes2short(reply, 0));
669669

670670
return BLEAPI_ERROR_SUCCESS;
671671
}

u2f-tests/BLE/BleApi/BleApi.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
#include <guiddef.h>
2828

29-
BleApi::BleApi(bool encryption):
30-
mEncryption(encryption)
29+
BleApi::BleApi(bool encryption, bool logging):
30+
mEncryption(encryption), mLogging(logging)
3131
{
3232
}
3333

@@ -48,10 +48,10 @@ std::vector < BleDevice * >BleApi::findDevices()
4848
return empty;
4949
}
5050

51-
BleApi *BleApi::CreateAPI(bool encryption)
51+
BleApi *BleApi::CreateAPI(bool encryption, bool logging)
5252
{
5353
#ifdef PLATFORM_WINDOWS
54-
return (pBleApi) new BleApiWindows(encryption);
54+
return (pBleApi) new BleApiWindows(encryption, logging);
5555
#else
5656
return NULL;
5757
#endif

u2f-tests/BLE/BleApi/BleApi.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@
2626

2727
typedef class BleApi {
2828
protected:
29-
BleApi(bool encryption = true);
29+
BleApi(bool encryption = true, bool logging = false);
3030
~BleApi(void);
3131

3232
public:
3333
virtual std::vector < pBleDevice > findDevices();
3434

35-
static BleApi *CreateAPI(bool encryption = true);
35+
static BleApi *CreateAPI(bool encryption = true, bool logging = false);
3636

3737
protected:
3838
bool mEncryption;
39+
bool mLogging;
3940
std::vector < pBleDevice > mDeviceList;
4041
} *pBleApi;
4142

42-
#endif /* _BLEAPI_BLEAPI_H_ */
43+
#endif /* _BLEAPI_BLEAPI_H_ */

u2f-tests/BLE/BleApi/BleApiError.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ typedef enum {
3333
BLEAPI_ERROR_TIMEOUT,
3434
} ReturnValue;
3535

36-
#endif /* _BLEAPI_BLEAPIERROR_H_ */
36+
#endif /* _BLEAPI_BLEAPIERROR_H_ */

u2f-tests/BLE/BleApi/BleApiWindows.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ int GetServiceHandle(IN string p_DevInstanceId, OUT HANDLE & p_hService)
180180
return BLEAPI_ERROR_NOT_FOUND;
181181
}
182182

183-
BleApiWindows::BleApiWindows(bool encryption):
184-
BleApi(encryption)
183+
BleApiWindows::BleApiWindows(bool encryption, bool logging):
184+
BleApi(encryption, logging)
185185
{
186186
};
187187

@@ -266,7 +266,8 @@ std::vector < BleDevice * >BleApiWindows::findDevices()
266266
(BleDevice *) new BleDeviceWindows(this, deviceInstanceId,
267267
devHandle,
268268
serviceHandle,
269-
mEncryption);
269+
mEncryption,
270+
mLogging);
270271
list.push_back(dev);
271272
mDeviceList.push_back(dev);
272273
}

u2f-tests/BLE/BleApi/BleApiWindows.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727
typedef class BleApiWindows:BleApi {
2828
public:
29-
BleApiWindows(bool encryption = true);
29+
BleApiWindows(bool encryption = true, bool logging = false);
3030
~BleApiWindows(void);
3131

3232
public:
3333
virtual std::vector < BleDevice * >findDevices();
3434
} *pBleApiWindows;
3535

36-
#endif /* _BLEAPI_BLEAPIWINDOWS_H_ */
36+
#endif /* _BLEAPI_BLEAPIWINDOWS_H_ */

0 commit comments

Comments
 (0)