more or less consistant with other authenticator
This commit is contained in:
parent
55484f22b5
commit
b0669eca67
96
ctap_test.py
96
ctap_test.py
@ -72,8 +72,9 @@ class Tester():
|
||||
pad = '\x00' * (64-l)
|
||||
pad = struct.pack('%dB' % len(pad), *[ord(x) for x in pad])
|
||||
data = data + pad
|
||||
data = list(data)
|
||||
assert(len(data) == 64)
|
||||
self.dev._dev.InternalSendPacket(Packet(cid + data))
|
||||
self.dev._dev.InternalSendPacket(Packet(data))
|
||||
|
||||
def cid(self,):
|
||||
return self.dev._dev.cid
|
||||
@ -84,6 +85,7 @@ class Tester():
|
||||
self.dev._dev.cid = cid
|
||||
|
||||
def recv_raw(self,):
|
||||
with Timeout(1.0) as t:
|
||||
cmd,payload = self.dev._dev.InternalRecv()
|
||||
return cmd, payload
|
||||
|
||||
@ -106,6 +108,7 @@ class Tester():
|
||||
print('Test init')
|
||||
r = self.send_data(CTAPHID.INIT, '\x11\x11\x11\x11\x11\x11\x11\x11')
|
||||
|
||||
|
||||
pingdata = os.urandom(100)
|
||||
try:
|
||||
r = self.send_data(CTAPHID.PING, pingdata)
|
||||
@ -150,19 +153,22 @@ class Tester():
|
||||
#assert(e.code == CtapError.ERR.INVALID_LENGTH)
|
||||
#print('PASS: malformed wink')
|
||||
|
||||
#try:
|
||||
#r = self.send_data(CTAPHID.CBOR, '')
|
||||
#raise RuntimeError('Cbor is supposed to have payload')
|
||||
#except CtapError as e:
|
||||
#assert(e.code == CtapError.ERR.INVALID_LENGTH)
|
||||
#print('PASS: no data cbor')
|
||||
try:
|
||||
r = self.send_data(CTAPHID.CBOR, '')
|
||||
if len(r) > 1 or r[0] == 0:
|
||||
raise RuntimeError('Cbor is supposed to have payload')
|
||||
except CtapError as e:
|
||||
assert(e.code == CtapError.ERR.INVALID_LENGTH)
|
||||
print('PASS: no data cbor')
|
||||
|
||||
#try:
|
||||
#r = self.send_data(CTAPHID.MSG, '')
|
||||
#raise RuntimeError('MSG is supposed to have payload')
|
||||
#except CtapError as e:
|
||||
#assert(e.code == CtapError.ERR.INVALID_LENGTH)
|
||||
#print('PASS: no data msg')
|
||||
try:
|
||||
r = self.send_data(CTAPHID.MSG, '')
|
||||
print(hexlify(r))
|
||||
if len(r) > 2:
|
||||
raise RuntimeError('MSG is supposed to have payload')
|
||||
except CtapError as e:
|
||||
assert(e.code == CtapError.ERR.INVALID_LENGTH)
|
||||
print('PASS: no data msg')
|
||||
|
||||
try:
|
||||
r = self.send_data(CTAPHID.INIT, '\x11\x22\x33\x44\x55\x66\x77\x88')
|
||||
@ -179,23 +185,23 @@ class Tester():
|
||||
|
||||
|
||||
print('Sending packet with too large of a length.')
|
||||
self.send_raw('\x80\x1d\xba\x00')
|
||||
self.send_raw('\x81\x1d\xba\x00')
|
||||
cmd,resp = self.recv_raw()
|
||||
self.check_error(resp, CtapError.ERR.INVALID_LENGTH)
|
||||
print('PASS: invalid length')
|
||||
|
||||
print('Sending packets that skip a sequence number.')
|
||||
self.send_raw('\x81\x10\x00')
|
||||
self.send_raw('\x00')
|
||||
self.send_raw('\x01')
|
||||
self.send_raw('\x02')
|
||||
# skip 3
|
||||
self.send_raw('\x04')
|
||||
cmd,resp = self.recv_raw()
|
||||
self.check_error(resp, CtapError.ERR.INVALID_SEQ)
|
||||
cmd,resp = self.recv_raw()
|
||||
assert(cmd == 0xbf) # timeout
|
||||
print('PASS: invalid sequence')
|
||||
#r = self.send_data(CTAPHID.PING, '\x44'*200)
|
||||
#print('Sending packets that skip a sequence number.')
|
||||
#self.send_raw('\x81\x04\x90')
|
||||
#self.send_raw('\x00')
|
||||
#self.send_raw('\x01')
|
||||
## skip 2
|
||||
#self.send_raw('\x03')
|
||||
#cmd,resp = self.recv_raw()
|
||||
#self.check_error(resp, CtapError.ERR.INVALID_SEQ)
|
||||
#cmd,resp = self.recv_raw()
|
||||
#assert(cmd == 0xbf) # timeout
|
||||
#print('PASS: invalid sequence')
|
||||
|
||||
print('Resync and send ping')
|
||||
try:
|
||||
@ -209,7 +215,7 @@ class Tester():
|
||||
print('PASS: resync and ping')
|
||||
|
||||
print('Send ping and abort it')
|
||||
self.send_raw('\x81\x10\x00')
|
||||
self.send_raw('\x81\x04\x00')
|
||||
self.send_raw('\x00')
|
||||
self.send_raw('\x01')
|
||||
try:
|
||||
@ -226,11 +232,13 @@ class Tester():
|
||||
self.send_raw('\x01')
|
||||
self.set_cid(newcid)
|
||||
self.send_raw('\x86\x00\x08\x11\x22\x33\x44\x55\x66\x77\x88') # init from different cid
|
||||
print('wait for init response')
|
||||
cmd,r = self.recv_raw() # init response
|
||||
assert(cmd == 0x86)
|
||||
self.set_cid(oldcid)
|
||||
cmd,r = self.recv_raw() # timeout response
|
||||
assert(cmd == 0xbf)
|
||||
#print('wait for timeout')
|
||||
#cmd,r = self.recv_raw() # timeout response
|
||||
#assert(cmd == 0xbf)
|
||||
|
||||
print('PASS: resync and timeout')
|
||||
|
||||
@ -238,7 +246,7 @@ class Tester():
|
||||
print('Test timeout')
|
||||
self.send_data(CTAPHID.INIT, '\x11\x22\x33\x44\x55\x66\x77\x88')
|
||||
t1 = time.time() * 1000
|
||||
self.send_raw('\x81\x10\x00')
|
||||
self.send_raw('\x81\x04\x00')
|
||||
self.send_raw('\x00')
|
||||
self.send_raw('\x01')
|
||||
cmd,r = self.recv_raw() # timeout response
|
||||
@ -251,7 +259,7 @@ class Tester():
|
||||
|
||||
print('Test not cont')
|
||||
self.send_data(CTAPHID.INIT, '\x11\x22\x33\x44\x55\x66\x77\x88')
|
||||
self.send_raw('\x81\x10\x00')
|
||||
self.send_raw('\x81\x04\x00')
|
||||
self.send_raw('\x00')
|
||||
self.send_raw('\x01')
|
||||
self.send_raw('\x81\x10\x00') # init packet
|
||||
@ -263,18 +271,20 @@ class Tester():
|
||||
print('Check random cont ignored')
|
||||
self.send_data(CTAPHID.INIT, '\x11\x22\x33\x44\x55\x66\x77\x88')
|
||||
self.send_raw('\x01\x10\x00')
|
||||
try:
|
||||
cmd,r = self.recv_raw() # timeout response
|
||||
assert(cmd == 0xbf)
|
||||
assert(r[0] == CtapError.ERR.TIMEOUT)
|
||||
except socket.timeout:
|
||||
pass
|
||||
print('PASS: random cont')
|
||||
|
||||
print('Check busy')
|
||||
t1 = time.time() * 1000
|
||||
self.send_data(CTAPHID.INIT, '\x11\x22\x33\x44\x55\x66\x77\x88')
|
||||
oldcid = self.cid()
|
||||
newcid = '\x11\x22\x33\x44'
|
||||
self.send_raw('\x81\x10\x00')
|
||||
self.send_raw('\x81\x04\x00')
|
||||
self.set_cid(newcid)
|
||||
self.send_raw('\x81\x10\x00')
|
||||
self.send_raw('\x81\x04\x00')
|
||||
cmd,r = self.recv_raw() # busy response
|
||||
t2 = time.time() * 1000
|
||||
assert(t2-t1 < 100)
|
||||
@ -313,17 +323,17 @@ class Tester():
|
||||
assert(cmd == 0x81)
|
||||
assert(len(r) == 0x63)
|
||||
|
||||
cmd,r = self.recv_raw() # timeout
|
||||
assert(cmd == 0xbf)
|
||||
assert(r[0] == CtapError.ERR.TIMEOUT)
|
||||
#cmd,r = self.recv_raw() # timeout
|
||||
#assert(cmd == 0xbf)
|
||||
#assert(r[0] == CtapError.ERR.TIMEOUT)
|
||||
print('PASS: busy interleaved')
|
||||
|
||||
|
||||
print('Test idle')
|
||||
try:
|
||||
cmd,resp = self.recv_raw()
|
||||
except socket.timeout:
|
||||
print('Pass: Idle')
|
||||
#print('Test idle')
|
||||
#try:
|
||||
#cmd,resp = self.recv_raw()
|
||||
#except socket.timeout:
|
||||
#print('Pass: Idle')
|
||||
|
||||
print('Test cid 0 is invalid')
|
||||
self.set_cid('\x00\x00\x00\x00')
|
||||
|
@ -122,6 +122,7 @@ static int8_t cid_refresh(uint32_t cid)
|
||||
if (CIDS[i].cid == cid)
|
||||
{
|
||||
CIDS[i].last_used = millis();
|
||||
CIDS[i].busy = 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -518,13 +519,6 @@ void ctaphid_handle_packet(uint8_t * pkt_raw)
|
||||
case CTAPHID_WINK:
|
||||
printf("CTAPHID_WINK\n");
|
||||
|
||||
if (buffer_len() != 0)
|
||||
{
|
||||
printf("Error,invalid length field for wink packet\n");
|
||||
ctaphid_send_error(pkt->cid, CTAP1_ERR_INVALID_LENGTH);
|
||||
return;
|
||||
}
|
||||
|
||||
ctaphid_write_buffer_init(&wb);
|
||||
|
||||
wb.cid = active_cid;
|
||||
|
Loading…
x
Reference in New Issue
Block a user