Fix desktop tests for bugfix and stable (#395)
* fix build and lint problems * fix coveralls workflow by setting a working toolchain
This commit is contained in:
1
.github/workflows/coveralls.yml
vendored
1
.github/workflows/coveralls.yml
vendored
@@ -37,6 +37,7 @@ jobs:
|
|||||||
- uses: actions-rs/cargo@v1
|
- uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
|
toolchain: nightly-2020-06-10
|
||||||
args: --features "with_ctap1,with_nfc,std" --no-fail-fast
|
args: --features "with_ctap1,with_nfc,std" --no-fail-fast
|
||||||
env:
|
env:
|
||||||
CARGO_INCREMENTAL: '0'
|
CARGO_INCREMENTAL: '0'
|
||||||
|
|||||||
11
deploy.py
11
deploy.py
@@ -302,7 +302,16 @@ class OpenSKInstaller:
|
|||||||
def update_rustc_if_needed(self):
|
def update_rustc_if_needed(self):
|
||||||
target_toolchain_fullstring = "stable"
|
target_toolchain_fullstring = "stable"
|
||||||
with open("rust-toolchain", "r", encoding="utf-8") as f:
|
with open("rust-toolchain", "r", encoding="utf-8") as f:
|
||||||
target_toolchain_fullstring = f.readline().strip()
|
content = f.readlines()
|
||||||
|
if len(content) == 1:
|
||||||
|
# Old format, only the build is stored
|
||||||
|
target_toolchain_fullstring = content[0].strip()
|
||||||
|
else:
|
||||||
|
# New format
|
||||||
|
for line in content:
|
||||||
|
if line.startswith("channel"):
|
||||||
|
channel = line.strip().split("=", maxsplit=1)[1].strip()
|
||||||
|
target_toolchain_fullstring = channel.strip('"')
|
||||||
target_toolchain = target_toolchain_fullstring.split("-", maxsplit=1)
|
target_toolchain = target_toolchain_fullstring.split("-", maxsplit=1)
|
||||||
if len(target_toolchain) == 1:
|
if len(target_toolchain) == 1:
|
||||||
# If we target the stable version of rust, we won't have a date
|
# If we target the stable version of rust, we won't have a date
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ mod example {
|
|||||||
use libtock_drivers::timer::Timestamp;
|
use libtock_drivers::timer::Timestamp;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
|
// The actual lint upper_case_acronyms is not supported in all toolchains.
|
||||||
|
#[allow(clippy::all)]
|
||||||
enum ReturnCode {
|
enum ReturnCode {
|
||||||
/// Operation completed successfully
|
/// Operation completed successfully
|
||||||
SUCCESS,
|
SUCCESS,
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ impl From<&[u8; APDU_HEADER_LEN]> for ApduHeader {
|
|||||||
|
|
||||||
#[cfg_attr(test, derive(Clone, Debug))]
|
#[cfg_attr(test, derive(Clone, Debug))]
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
/// The APDU cases
|
/// The Apdu cases
|
||||||
pub enum Case {
|
pub enum Case {
|
||||||
Le1,
|
Le1,
|
||||||
Lc1Data,
|
Lc1Data,
|
||||||
@@ -97,7 +97,7 @@ pub enum ApduType {
|
|||||||
#[cfg_attr(test, derive(Clone, Debug))]
|
#[cfg_attr(test, derive(Clone, Debug))]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub struct APDU {
|
pub struct Apdu {
|
||||||
pub header: ApduHeader,
|
pub header: ApduHeader,
|
||||||
pub lc: u16,
|
pub lc: u16,
|
||||||
pub data: Vec<u8>,
|
pub data: Vec<u8>,
|
||||||
@@ -105,7 +105,7 @@ pub struct APDU {
|
|||||||
pub case_type: ApduType,
|
pub case_type: ApduType,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&[u8]> for APDU {
|
impl TryFrom<&[u8]> for Apdu {
|
||||||
type Error = ApduStatusCode;
|
type Error = ApduStatusCode;
|
||||||
|
|
||||||
fn try_from(frame: &[u8]) -> Result<Self, ApduStatusCode> {
|
fn try_from(frame: &[u8]) -> Result<Self, ApduStatusCode> {
|
||||||
@@ -119,7 +119,7 @@ impl TryFrom<&[u8]> for APDU {
|
|||||||
|
|
||||||
if payload.is_empty() {
|
if payload.is_empty() {
|
||||||
// Lc is zero-bytes in length
|
// Lc is zero-bytes in length
|
||||||
return Ok(APDU {
|
return Ok(Apdu {
|
||||||
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
|
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
|
||||||
lc: 0x00,
|
lc: 0x00,
|
||||||
data: Vec::new(),
|
data: Vec::new(),
|
||||||
@@ -132,7 +132,7 @@ impl TryFrom<&[u8]> for APDU {
|
|||||||
if payload.len() == 1 {
|
if payload.len() == 1 {
|
||||||
// There is only one byte in the payload, that byte cannot be Lc because that would
|
// There is only one byte in the payload, that byte cannot be Lc because that would
|
||||||
// entail at *least* one another byte in the payload (for the command data)
|
// entail at *least* one another byte in the payload (for the command data)
|
||||||
return Ok(APDU {
|
return Ok(Apdu {
|
||||||
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
|
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
|
||||||
lc: 0x00,
|
lc: 0x00,
|
||||||
data: Vec::new(),
|
data: Vec::new(),
|
||||||
@@ -148,7 +148,7 @@ impl TryFrom<&[u8]> for APDU {
|
|||||||
if payload.len() == 1 + (byte_0 as usize) && byte_0 != 0 {
|
if payload.len() == 1 + (byte_0 as usize) && byte_0 != 0 {
|
||||||
// Lc is one-byte long and since the size specified by Lc covers the rest of the
|
// Lc is one-byte long and since the size specified by Lc covers the rest of the
|
||||||
// payload there's no Le at the end
|
// payload there's no Le at the end
|
||||||
return Ok(APDU {
|
return Ok(Apdu {
|
||||||
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
|
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
|
||||||
lc: byte_0.into(),
|
lc: byte_0.into(),
|
||||||
data: payload[1..].to_vec(),
|
data: payload[1..].to_vec(),
|
||||||
@@ -160,7 +160,7 @@ impl TryFrom<&[u8]> for APDU {
|
|||||||
// Lc is one-byte long and since the size specified by Lc covers the rest of the
|
// Lc is one-byte long and since the size specified by Lc covers the rest of the
|
||||||
// payload with ONE additional byte that byte must be Le
|
// payload with ONE additional byte that byte must be Le
|
||||||
let last_byte: u32 = (*payload.last().unwrap()).into();
|
let last_byte: u32 = (*payload.last().unwrap()).into();
|
||||||
return Ok(APDU {
|
return Ok(Apdu {
|
||||||
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
|
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
|
||||||
lc: byte_0.into(),
|
lc: byte_0.into(),
|
||||||
data: payload[1..(payload.len() - 1)].to_vec(),
|
data: payload[1..(payload.len() - 1)].to_vec(),
|
||||||
@@ -186,9 +186,9 @@ impl TryFrom<&[u8]> for APDU {
|
|||||||
if byte_0 == 0 && extended_apdu_le_len <= 3 {
|
if byte_0 == 0 && extended_apdu_le_len <= 3 {
|
||||||
// If first byte is zero AND the next two bytes can be parsed as a big-endian
|
// If first byte is zero AND the next two bytes can be parsed as a big-endian
|
||||||
// length that covers the rest of the block (plus few additional bytes for Le), we
|
// length that covers the rest of the block (plus few additional bytes for Le), we
|
||||||
// have an extended-length APDU
|
// have an extended-length Apdu
|
||||||
let last_byte: u32 = (*payload.last().unwrap()).into();
|
let last_byte: u32 = (*payload.last().unwrap()).into();
|
||||||
return Ok(APDU {
|
return Ok(Apdu {
|
||||||
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
|
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
|
||||||
lc: extended_apdu_lc as u16,
|
lc: extended_apdu_lc as u16,
|
||||||
data: payload[3..(payload.len() - extended_apdu_le_len)].to_vec(),
|
data: payload[3..(payload.len() - extended_apdu_le_len)].to_vec(),
|
||||||
@@ -243,8 +243,8 @@ impl TryFrom<&[u8]> for APDU {
|
|||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn pass_frame(frame: &[u8]) -> Result<APDU, ApduStatusCode> {
|
fn pass_frame(frame: &[u8]) -> Result<Apdu, ApduStatusCode> {
|
||||||
APDU::try_from(frame)
|
Apdu::try_from(frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -252,7 +252,7 @@ mod test {
|
|||||||
let frame: [u8; 4] = [0x00, 0x12, 0x00, 0x80];
|
let frame: [u8; 4] = [0x00, 0x12, 0x00, 0x80];
|
||||||
let response = pass_frame(&frame);
|
let response = pass_frame(&frame);
|
||||||
assert!(response.is_ok());
|
assert!(response.is_ok());
|
||||||
let expected = APDU {
|
let expected = Apdu {
|
||||||
header: ApduHeader {
|
header: ApduHeader {
|
||||||
cla: 0x00,
|
cla: 0x00,
|
||||||
ins: 0x12,
|
ins: 0x12,
|
||||||
@@ -271,7 +271,7 @@ mod test {
|
|||||||
fn test_case_type_2_short() {
|
fn test_case_type_2_short() {
|
||||||
let frame: [u8; 5] = [0x00, 0xb0, 0x00, 0x00, 0x0f];
|
let frame: [u8; 5] = [0x00, 0xb0, 0x00, 0x00, 0x0f];
|
||||||
let response = pass_frame(&frame);
|
let response = pass_frame(&frame);
|
||||||
let expected = APDU {
|
let expected = Apdu {
|
||||||
header: ApduHeader {
|
header: ApduHeader {
|
||||||
cla: 0x00,
|
cla: 0x00,
|
||||||
ins: 0xb0,
|
ins: 0xb0,
|
||||||
@@ -290,7 +290,7 @@ mod test {
|
|||||||
fn test_case_type_2_short_le() {
|
fn test_case_type_2_short_le() {
|
||||||
let frame: [u8; 5] = [0x00, 0xb0, 0x00, 0x00, 0x00];
|
let frame: [u8; 5] = [0x00, 0xb0, 0x00, 0x00, 0x00];
|
||||||
let response = pass_frame(&frame);
|
let response = pass_frame(&frame);
|
||||||
let expected = APDU {
|
let expected = Apdu {
|
||||||
header: ApduHeader {
|
header: ApduHeader {
|
||||||
cla: 0x00,
|
cla: 0x00,
|
||||||
ins: 0xb0,
|
ins: 0xb0,
|
||||||
@@ -310,7 +310,7 @@ mod test {
|
|||||||
let frame: [u8; 7] = [0x00, 0xa4, 0x00, 0x0c, 0x02, 0xe1, 0x04];
|
let frame: [u8; 7] = [0x00, 0xa4, 0x00, 0x0c, 0x02, 0xe1, 0x04];
|
||||||
let payload = [0xe1, 0x04];
|
let payload = [0xe1, 0x04];
|
||||||
let response = pass_frame(&frame);
|
let response = pass_frame(&frame);
|
||||||
let expected = APDU {
|
let expected = Apdu {
|
||||||
header: ApduHeader {
|
header: ApduHeader {
|
||||||
cla: 0x00,
|
cla: 0x00,
|
||||||
ins: 0xa4,
|
ins: 0xa4,
|
||||||
@@ -332,7 +332,7 @@ mod test {
|
|||||||
];
|
];
|
||||||
let payload = [0xd2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01];
|
let payload = [0xd2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01];
|
||||||
let response = pass_frame(&frame);
|
let response = pass_frame(&frame);
|
||||||
let expected = APDU {
|
let expected = Apdu {
|
||||||
header: ApduHeader {
|
header: ApduHeader {
|
||||||
cla: 0x00,
|
cla: 0x00,
|
||||||
ins: 0xa4,
|
ins: 0xa4,
|
||||||
@@ -354,7 +354,7 @@ mod test {
|
|||||||
];
|
];
|
||||||
let payload = [0xd2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01];
|
let payload = [0xd2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01];
|
||||||
let response = pass_frame(&frame);
|
let response = pass_frame(&frame);
|
||||||
let expected = APDU {
|
let expected = Apdu {
|
||||||
header: ApduHeader {
|
header: ApduHeader {
|
||||||
cla: 0x00,
|
cla: 0x00,
|
||||||
ins: 0xa4,
|
ins: 0xa4,
|
||||||
@@ -396,7 +396,7 @@ mod test {
|
|||||||
];
|
];
|
||||||
let payload: &[u8] = &frame[7..frame.len() - 2];
|
let payload: &[u8] = &frame[7..frame.len() - 2];
|
||||||
let response = pass_frame(&frame);
|
let response = pass_frame(&frame);
|
||||||
let expected = APDU {
|
let expected = Apdu {
|
||||||
header: ApduHeader {
|
header: ApduHeader {
|
||||||
cla: 0x00,
|
cla: 0x00,
|
||||||
ins: 0x02,
|
ins: 0x02,
|
||||||
@@ -423,7 +423,7 @@ mod test {
|
|||||||
];
|
];
|
||||||
let payload: &[u8] = &frame[7..frame.len() - 2];
|
let payload: &[u8] = &frame[7..frame.len() - 2];
|
||||||
let response = pass_frame(&frame);
|
let response = pass_frame(&frame);
|
||||||
let expected = APDU {
|
let expected = Apdu {
|
||||||
header: ApduHeader {
|
header: ApduHeader {
|
||||||
cla: 0x00,
|
cla: 0x00,
|
||||||
ins: 0x01,
|
ins: 0x01,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use super::apdu::{ApduStatusCode, APDU};
|
use super::apdu::{Apdu, ApduStatusCode};
|
||||||
use super::hid::ChannelID;
|
use super::hid::ChannelID;
|
||||||
use super::status_code::Ctap2StatusCode;
|
use super::status_code::Ctap2StatusCode;
|
||||||
use super::CtapState;
|
use super::CtapState;
|
||||||
@@ -82,7 +82,7 @@ impl TryFrom<&[u8]> for U2fCommand {
|
|||||||
type Error = Ctap1StatusCode;
|
type Error = Ctap1StatusCode;
|
||||||
|
|
||||||
fn try_from(message: &[u8]) -> Result<Self, Ctap1StatusCode> {
|
fn try_from(message: &[u8]) -> Result<Self, Ctap1StatusCode> {
|
||||||
let apdu: APDU = match APDU::try_from(message) {
|
let apdu: Apdu = match Apdu::try_from(message) {
|
||||||
Ok(apdu) => apdu,
|
Ok(apdu) => apdu,
|
||||||
Err(apdu_status_code) => {
|
Err(apdu_status_code) => {
|
||||||
return Err(Ctap1StatusCode::try_from(apdu_status_code).unwrap())
|
return Err(Ctap1StatusCode::try_from(apdu_status_code).unwrap())
|
||||||
@@ -91,7 +91,7 @@ impl TryFrom<&[u8]> for U2fCommand {
|
|||||||
|
|
||||||
let lc = apdu.lc as usize;
|
let lc = apdu.lc as usize;
|
||||||
|
|
||||||
// ISO7816 APDU Header format. Each cell is 1 byte. Note that the CTAP flavor always
|
// ISO7816 Apdu Header format. Each cell is 1 byte. Note that the CTAP flavor always
|
||||||
// encodes the length on 3 bytes and doesn't use the field "Le" (Length Expected).
|
// encodes the length on 3 bytes and doesn't use the field "Le" (Length Expected).
|
||||||
// We keep the 2 byte of "Le" for the packet length in mind, but always ignore its value.
|
// We keep the 2 byte of "Le" for the packet length in mind, but always ignore its value.
|
||||||
// Lc is using big-endian encoding
|
// Lc is using big-endian encoding
|
||||||
|
|||||||
@@ -227,6 +227,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::eq_op)]
|
||||||
fn test_hid_packet_iterator_max_packets() {
|
fn test_hid_packet_iterator_max_packets() {
|
||||||
let mut payload = vec![0xFF; 64 - 7];
|
let mut payload = vec![0xFF; 64 - 7];
|
||||||
for i in 0..128 {
|
for i in 0..128 {
|
||||||
@@ -244,14 +245,13 @@ mod test {
|
|||||||
payload,
|
payload,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut expected_packets = Vec::new();
|
let mut expected_packets = vec![[
|
||||||
expected_packets.push([
|
|
||||||
0x12, 0x34, 0x56, 0x78, 0xAB, 0x1D, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
0x12, 0x34, 0x56, 0x78, 0xAB, 0x1D, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
]);
|
]];
|
||||||
for i in 0..128 {
|
for i in 0..128 {
|
||||||
let mut packet: HidPacket = [0; 64];
|
let mut packet: HidPacket = [0; 64];
|
||||||
packet[0] = 0x12;
|
packet[0] = 0x12;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ license = "Apache-2.0"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.33.1"
|
clap = "~2.27.*"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
ncurses = "5.99.0"
|
ncurses = "5.99.0"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
|
|||||||
Reference in New Issue
Block a user