From dd4b1c60a413e807c41836191c9e63dabb45867e Mon Sep 17 00:00:00 2001 From: "Tony Arcieri (iqlusion)" Date: Mon, 17 Jan 2022 14:54:01 -0800 Subject: [PATCH] 2021 edition upgrade; MSRV 1.56 (#343) Changes the `edition` to 2021 in both the `yubikey` and `yubikey-cli` crates. Removes `TryFrom`/`TryInto` imports, now that they're in the prelude. --- .github/workflows/ci.yml | 8 ++++---- Cargo.lock | 4 ++-- Cargo.toml | 15 ++++++++------- README.md | 6 +++--- cli/Cargo.toml | 15 ++++++++------- src/cccid.rs | 1 - src/certificate.rs | 12 +++++------- src/chuid.rs | 1 - src/config.rs | 5 +---- src/mgm.rs | 5 ++--- src/mscmap.rs | 1 - src/msroots.rs | 4 ++-- src/piv.rs | 2 +- src/reader.rs | 2 +- src/setting.rs | 13 ++----------- src/transaction.rs | 1 - src/yubikey.rs | 1 - tests/integration.rs | 2 +- 18 files changed, 40 insertions(+), 58 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b086e66..85f165a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,13 +36,13 @@ jobs: toolchain: stable deps: true - platform: ubuntu-latest - toolchain: 1.51.0 # MSRV + toolchain: 1.56.0 # MSRV deps: sudo apt-get install libpcsclite-dev - platform: windows-latest - toolchain: 1.51.0 # MSRV + toolchain: 1.56.0 # MSRV deps: true - platform: macos-latest - toolchain: 1.51.0 # MSRV + toolchain: 1.56.0 # MSRV deps: true runs-on: ${{ matrix.platform }} steps: @@ -82,7 +82,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.51.0 # MSRV + toolchain: 1.56.0 # MSRV components: clippy override: true - run: sudo apt-get install libpcsclite-dev diff --git a/Cargo.lock b/Cargo.lock index 5644473..94ca9c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -894,7 +894,7 @@ dependencies = [ [[package]] name = "yubikey" -version = "0.5.0" +version = "0.6.0-pre" dependencies = [ "chrono", "cookie-factory", @@ -928,7 +928,7 @@ dependencies = [ [[package]] name = "yubikey-cli" -version = "0.5.0" +version = "0.6.0-pre" dependencies = [ "env_logger", "gumdrop", diff --git a/Cargo.toml b/Cargo.toml index 811ab08..49d7c1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,20 @@ [package] -name = "yubikey" -version = "0.5.0" # Also update html_root_url in lib.rs when bumping this +name = "yubikey" +version = "0.6.0-pre" # Also update html_root_url in lib.rs when bumping this description = """ Pure Rust cross-platform host-side driver for YubiKey devices from Yubico with support for hardware-backed public-key decryption and digital signatures using the Personal Identity Verification (PIV) application. Supports RSA (1024/2048) or ECC (NIST P-256/P-384) algorithms e.g, PKCS#1v1.5, ECDSA """ -authors = ["Tony Arcieri ", "Yubico AB"] -edition = "2018" -license = "BSD-2-Clause" +authors = ["Tony Arcieri ", "Yubico AB"] +license = "BSD-2-Clause" repository = "https://github.com/iqlusioninc/yubikey.rs" -readme = "README.md" +readme = "README.md" categories = ["api-bindings", "cryptography", "hardware-support"] -keywords = ["ecdsa", "encryption", "rsa", "piv", "signature"] +keywords = ["ecdsa", "encryption", "rsa", "piv", "signature"] +edition = "2021" +rust-version = "1.56" [workspace] members = [".", "cli"] diff --git a/README.md b/README.md index e2b7798..24dba8a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![crate][crate-image]][crate-link] [![Docs][docs-image]][docs-link] [![2-Clause BSD Licensed][license-image]][license-link] -![Rust Version][rustc-image] +![MSRV][msrv-image] [![Safety Dance][safety-image]][safety-link] [![Build Status][build-image]][build-link] [![dependency status][deps-image]][deps-link] @@ -36,7 +36,7 @@ endorsed by Yubico. ## Minimum Supported Rust Version -Rust **1.51** or newer. +Rust **1.56** or newer. ## Supported YubiKeys @@ -165,7 +165,7 @@ or conditions. [docs-link]: https://docs.rs/yubikey/ [license-image]: https://img.shields.io/badge/license-BSD-blue.svg [license-link]: https://github.com/iqlusioninc/yubikey.rs/blob/main/COPYING -[rustc-image]: https://img.shields.io/badge/rustc-1.51+-blue.svg +[msrv-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg [safety-image]: https://img.shields.io/badge/unsafe-forbidden-success.svg [safety-link]: https://github.com/rust-secure-code/safety-dance/ [build-image]: https://github.com/iqlusioninc/yubikey.rs/workflows/CI/badge.svg?branch=main&event=push diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 675b2fe..c58a825 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,17 +1,18 @@ [package] name = "yubikey-cli" -version = "0.5.0" +version = "0.6.0-pre" description = """ Command-line interface for performing encryption and signing using RSA/ECC keys stored on YubiKey devices. """ -authors = ["Tony Arcieri "] -edition = "2018" -license = "BSD-2-Clause" +authors = ["Tony Arcieri "] +license = "BSD-2-Clause" repository = "https://github.com/iqlusioninc/yubikey.rs" -readme = "README.md" +readme = "README.md" categories = ["command-line-utilities", "cryptography", "hardware-support"] -keywords = ["ecdsa", "rsa", "piv", "pcsc", "yubikey"] +keywords = ["ecdsa", "rsa", "piv", "pcsc", "yubikey"] +edition = "2021" +rust-version = "1.56" [dependencies] gumdrop = "0.8" @@ -22,4 +23,4 @@ sha2 = "0.9" subtle-encoding = "0.5" termcolor = "1" x509-parser = "0.12" -yubikey = { version = "0.5", path = ".." } +yubikey = { version = "=0.6.0-pre", path = ".." } diff --git a/src/cccid.rs b/src/cccid.rs index 15dc447..5a7f190 100644 --- a/src/cccid.rs +++ b/src/cccid.rs @@ -33,7 +33,6 @@ use crate::{Error, Result, YubiKey}; use rand_core::{OsRng, RngCore}; use std::{ - convert::TryInto, fmt::{self, Debug, Display}, str, }; diff --git a/src/certificate.rs b/src/certificate.rs index 78855b9..da69ea2 100644 --- a/src/certificate.rs +++ b/src/certificate.rs @@ -47,9 +47,7 @@ use p256::NistP256; use p384::NistP384; use rsa::{PublicKeyParts, RsaPublicKey}; use sha2::{Digest, Sha256}; -use std::convert::TryFrom; -use std::fmt; -use std::ops::DerefMut; +use std::{fmt, ops::DerefMut}; use x509::{der::Oid, RelativeDistinguishedName}; use x509_parser::{parse_x509_certificate, x509::SubjectPublicKeyInfo}; use zeroize::Zeroizing; @@ -85,7 +83,7 @@ impl TryFrom<&[u8]> for Serial { fn try_from(bytes: &[u8]) -> Result { if bytes.len() <= 20 { - Ok(Serial(BigUint::from_bytes_be(&bytes))) + Ok(Serial(BigUint::from_bytes_be(bytes))) } else { Err(Error::ParseError) } @@ -365,12 +363,12 @@ impl Certificate { &serial.to_bytes(), &signature_algorithm, // Issuer and subject are the same in self-signed certificates. - &subject, + subject, Utc::now(), not_after, - &subject, + subject, &subject_pki, - &extensions, + extensions, ), tbs_cert.deref_mut(), ) diff --git a/src/chuid.rs b/src/chuid.rs index 9baf7cb..77d98ba 100644 --- a/src/chuid.rs +++ b/src/chuid.rs @@ -32,7 +32,6 @@ use crate::{Error, Result, YubiKey}; use std::{ - convert::TryInto, fmt::{self, Debug, Display}, str, }; diff --git a/src/config.rs b/src/config.rs index c59d0c7..a6bb2e4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -41,10 +41,7 @@ use crate::{ Result, }; use log::error; -use std::{ - convert::TryInto, - time::{Duration, SystemTime, UNIX_EPOCH}, -}; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; const CB_ADMIN_TIMESTAMP: usize = 0x04; const PROTECTED_FLAGS_1_PUK_NOBLOCK: u8 = 0x01; diff --git a/src/mgm.rs b/src/mgm.rs index 369d3e5..cf2425f 100644 --- a/src/mgm.rs +++ b/src/mgm.rs @@ -33,7 +33,6 @@ use crate::{Error, Result}; use log::error; use rand_core::{OsRng, RngCore}; -use std::convert::{TryFrom, TryInto}; use zeroize::{Zeroize, Zeroizing}; #[cfg(feature = "untested")] @@ -138,7 +137,7 @@ impl MgmKey { } let mut mgm = [0u8; DES_LEN_3DES]; - pbkdf2::>(pin, &salt, ITER_MGM_PBKDF2, &mut mgm); + pbkdf2::>(pin, salt, ITER_MGM_PBKDF2, &mut mgm); MgmKey::from_bytes(mgm) } @@ -191,7 +190,7 @@ impl MgmKey { pub fn set_manual(&self, yubikey: &mut YubiKey, require_touch: bool) -> Result<()> { let txn = yubikey.begin_transaction()?; - txn.set_mgm_key(&self, require_touch).map_err(|e| { + txn.set_mgm_key(self, require_touch).map_err(|e| { // Log a warning, since the device mgm key is corrupt or we're in a state // where we can't set the mgm key. error!("could not set new derived mgm key, err = {}", e); diff --git a/src/mscmap.rs b/src/mscmap.rs index f37802f..e9ff3d9 100644 --- a/src/mscmap.rs +++ b/src/mscmap.rs @@ -32,7 +32,6 @@ use crate::{consts::CB_OBJ_MAX, piv::SlotId, serialization::*, Error, Result, YubiKey}; use log::error; -use std::convert::{TryFrom, TryInto}; const OBJ_MSCMAP: u32 = 0x005f_ff10; diff --git a/src/msroots.rs b/src/msroots.rs index 4ef3374..a15b0d0 100644 --- a/src/msroots.rs +++ b/src/msroots.rs @@ -111,7 +111,7 @@ impl MsRoots { let mut data_chunk: usize; let data = &self.0; let data_len = data.len(); - let n_objs: usize; + let txn = yubikey.begin_transaction()?; if data_len == 0 { @@ -119,7 +119,7 @@ impl MsRoots { } // Calculate number of objects required to store blob - n_objs = (data_len / (CB_OBJ_MAX - CB_OBJ_TAG_MAX)) + 1; + let n_objs: usize = (data_len / (CB_OBJ_MAX - CB_OBJ_TAG_MAX)) + 1; if n_objs > 5 { return Err(Error::SizeError); diff --git a/src/piv.rs b/src/piv.rs index 4183dd9..182cfb4 100644 --- a/src/piv.rs +++ b/src/piv.rs @@ -55,7 +55,7 @@ use crate::{ use elliptic_curve::sec1::EncodedPoint as EcPublicKey; use log::{debug, error, warn}; use rsa::{BigUint, RsaPublicKey}; -use std::{convert::TryFrom, str::FromStr}; +use std::str::FromStr; #[cfg(feature = "untested")] use { diff --git a/src/reader.rs b/src/reader.rs index 06897e3..b3bbee7 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -3,7 +3,6 @@ use crate::{Result, YubiKey}; use std::{ borrow::Cow, - convert::TryInto, ffi::CStr, sync::{Arc, Mutex}, }; @@ -45,6 +44,7 @@ impl Context { c.list_readers(reader_names)?.collect() }; + #[allow(clippy::needless_collect)] let readers: Vec<_> = reader_cstrs .iter() .map(|name| Reader::new(name, Arc::clone(ctx))) diff --git a/src/setting.rs b/src/setting.rs index 327cb98..7ac94a7 100644 --- a/src/setting.rs +++ b/src/setting.rs @@ -65,7 +65,7 @@ impl Default for SettingSource { /// These can be configured globally in `/etc/yubico/yubikeypiv.conf` by a /// system administrator, or by the local user via `YUBIKEY_PIV_*` environment /// variables. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Default)] pub struct Setting { /// Boolean value pub value: bool, @@ -99,7 +99,7 @@ impl Setting { } let (name, value) = { - let mut parts = line.splitn(1, '='); + let mut parts = line.splitn(2, '='); let name = parts.next(); let value = parts.next(); match (name, value, parts.next()) { @@ -130,12 +130,3 @@ impl Setting { }) } } - -impl Default for Setting { - fn default() -> Self { - Self { - value: false, - source: SettingSource::default(), - } - } -} diff --git a/src/transaction.rs b/src/transaction.rs index 07c66b4..5d961ac 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -11,7 +11,6 @@ use crate::{ Buffer, ObjectId, }; use log::{error, trace}; -use std::convert::TryInto; use zeroize::Zeroizing; #[cfg(feature = "untested")] diff --git a/src/yubikey.rs b/src/yubikey.rs index be96302..e043390 100644 --- a/src/yubikey.rs +++ b/src/yubikey.rs @@ -45,7 +45,6 @@ use log::{error, info}; use pcsc::Card; use rand_core::{OsRng, RngCore}; use std::{ - convert::{TryFrom, TryInto}, fmt::{self, Display}, str::FromStr, }; diff --git a/tests/integration.rs b/tests/integration.rs index 1c650d8..feb6da1 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -8,7 +8,7 @@ use log::trace; use rand_core::{OsRng, RngCore}; use rsa::{hash::Hash::SHA2_256, PaddingScheme, PublicKey}; use sha2::{Digest, Sha256}; -use std::{convert::TryInto, env, sync::Mutex}; +use std::{env, sync::Mutex}; use x509::RelativeDistinguishedName; use yubikey::{ certificate::{Certificate, PublicKeyInfo},