Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certificate::generate_self_signed can't work reliably with yubikey::piv::generate #581

Open
str4d opened this issue Nov 3, 2024 · 2 comments

Comments

@str4d
Copy link
Contributor

str4d commented Nov 3, 2024

In yubikey 0.7, Certificate::generate_self_signed took a yubikey::certificate::PublicKeyInfo argument as the key to generate the certificate for. This was an enum that was obtained from yubikey::piv::generate after passing in an AlgorithmId enum, so algorithm information was inherently passed from one to the other.

In yubikey 0.8, yubikey::piv::generate and Certificate::generate_self_signed now communicate via a SubjectPublicKeyInfoOwned, which is an opaque type. As a side-effect, Certificate::generate_self_signed now requires a type argument to work. Failing to set the type argument causes obscure and confusing errors related to the extensions closure.

However, yubikey::piv::generate still takes an AlgorithmId enum. So the algorithm of the SubjectPublicKeyInfoOwned that yubikey::piv::generate returns may be determined at runtime, and yet Certificate::generate_self_signed requires it to be fixed at compile time. This is a confusing API, as to correctly handle runtime determination you need to embed four copies of Certificate::generate_self_signed.

  • We should either have the API use a runtime-specified or compile-time-specified algorithm, not both.
  • If we go with compile-time, yubikey::piv::generate should not return an opaque SubjectPublicKeyInfoOwned, but instead a type that carries the compile-time algorithm with it for Certificate::generate_self_signed to use.
@tony-iqlusion
Copy link
Member

cc @baloo

@baloo
Copy link
Contributor

baloo commented Nov 4, 2024

Yeah we can go the compile time road I guess.

Have generate look like:

pub fn generate<KT: KeyType>(
    yubikey: &mut YubiKey,
    slot: SlotId,
    pin_policy: PinPolicy,
    touch_policy: TouchPolicy,
) -> Result<KT::VerifyingKey> {

I think I can revisit this with the pre-release of x509-cert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants