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