From 82662e6d460eca62067f93b09a0df2b039845e9e Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Thu, 31 Aug 2023 13:00:49 +0200 Subject: [PATCH] openpgp-card: Remove algorithm setting from key generation Also entirely remove set_algorithm_attributes_simple. Callers should use AlgoSimple::matching_algorithm_attributes to determine the appropriate AlgorithmAttributes. --- openpgp-card-sequoia/src/lib.rs | 2 +- openpgp-card/src/lib.rs | 60 +-------------------------------- 2 files changed, 2 insertions(+), 60 deletions(-) diff --git a/openpgp-card-sequoia/src/lib.rs b/openpgp-card-sequoia/src/lib.rs index 355316a..5f45049 100644 --- a/openpgp-card-sequoia/src/lib.rs +++ b/openpgp-card-sequoia/src/lib.rs @@ -975,6 +975,6 @@ impl Card> { self.card().set_algorithm_attributes(key_type, &attr)?; } - self.card().generate_key(Self::ptf, key_type, None) + self.card().generate_key(Self::ptf, key_type) } } diff --git a/openpgp-card/src/lib.rs b/openpgp-card/src/lib.rs index b7c6e06..3073338 100644 --- a/openpgp-card/src/lib.rs +++ b/openpgp-card/src/lib.rs @@ -44,7 +44,7 @@ use std::convert::{TryFrom, TryInto}; use card_backend::{CardBackend, CardCaps, CardTransaction, PinType, SmartcardError}; use tags::{ShortTag, Tags}; -use crate::algorithm::{AlgoSimple, AlgorithmAttributes, AlgorithmInformation}; +use crate::algorithm::{AlgorithmAttributes, AlgorithmInformation}; use crate::apdu::command::Command; use crate::apdu::response::RawResponse; use crate::card_do::{ @@ -1303,13 +1303,6 @@ impl<'a> Transaction<'a> { /// Generate a key on the card. /// (7.2.14 GENERATE ASYMMETRIC KEY PAIR) - /// - /// If the `algorithm_attributes` parameter is Some, then that algorithm will be set on - /// the card for the `key_type` slot. - /// - /// Note: `algorithm_attributes` needs to precisely specify the RSA bit-size of e (if - /// applicable), and import format, with values that the current card - /// supports. pub fn generate_key( &mut self, fp_from_pub: fn( @@ -1318,30 +1311,7 @@ impl<'a> Transaction<'a> { KeyType, ) -> Result, key_type: KeyType, - algorithm_attributes: Option<&AlgorithmAttributes>, ) -> Result<(PublicKeyMaterial, KeyGenerationTime), Error> { - // Set algo on card if it's Some - if let Some(target_algo) = algorithm_attributes { - let ecap = self.extended_capabilities()?; - - // Only set algo if card supports setting of algo attr - if ecap.algo_attrs_changeable() { - self.set_algorithm_attributes(key_type, target_algo)?; - } else { - // Check if the current algo on the card is the one we want, if - // not we return an error. - - // NOTE: For RSA, the target algo shouldn't prescribe an - // Import-Format. The Import-Format should always depend on what - // the card supports. - - // let cur_algo = ard.get_algorithm_attributes(key_type)?; - // assert_eq!(&cur_algo, target_algo); - - // FIXME: return error? - } - } - // get current (possibly updated) state of algorithm_attributes let ard = self.application_related_data()?; // no caching, here! let cur_algo = ard.algorithm_attributes(key_type)?; @@ -1349,34 +1319,6 @@ impl<'a> Transaction<'a> { keys::gen_key_set_metadata(self, fp_from_pub, &cur_algo, key_type) } - /// Generate a key on the card. - /// (7.2.14 GENERATE ASYMMETRIC KEY PAIR) - /// - /// This is a wrapper around [`Self::generate_key`] which allows - /// using the simplified [`AlgoSimple`] algorithm selector enum. - /// - /// Note: AlgoSimple doesn't specify card specific details (such as - /// bitsize of e for RSA, and import format). This function determines - /// these values based on information from the card. - pub fn generate_key_simple( - &mut self, - fp_from_pub: fn( - &PublicKeyMaterial, - KeyGenerationTime, - KeyType, - ) -> Result, - key_type: KeyType, - simple: AlgoSimple, - ) -> Result<(PublicKeyMaterial, KeyGenerationTime), Error> { - let ard = self.application_related_data()?; - let algorithm_attributes = ard.algorithm_attributes(key_type)?; - - let algo_info = self.algorithm_information_cached().ok().flatten(); - - let algo = simple.determine_algo_attributes(key_type, algorithm_attributes, algo_info)?; - Self::generate_key(self, fp_from_pub, key_type, Some(&algo)) - } - /// Get public key material from the card. /// /// Note: this fn returns a set of raw public key data (not an