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

Fix OpenSC compatibility for RSA #96

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/command/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ fn pw_status_bytes<const R: usize, T: trussed::Client>(
}

fn algo_info<const R: usize, T: trussed::Client>(mut ctx: Context<'_, R, T>) -> Result<(), Status> {
ctx.reply.expand(&[0xFA])?;
let offset = ctx.reply.len();
for alg in SignatureAlgorithm::iter_all() {
ctx.reply.expand(&[0xC1])?;
let offset = ctx.reply.len();
Expand All @@ -590,6 +592,7 @@ fn algo_info<const R: usize, T: trussed::Client>(mut ctx: Context<'_, R, T>) ->
ctx.reply.expand(alg.attributes())?;
ctx.reply.prepend_len(offset)?;
}
ctx.reply.prepend_len(offset)?;
Ok(())
}

Expand Down
29 changes: 23 additions & 6 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ const RSA_4K_ATTRIBUTES: &[u8] = hex!(
)
.as_slice();

// Accepted for key generation, but overridden to always set the import format to CRT
const RSA_2K_ATTRIBUTES_STANDARD_IMPORT: &[u8] = hex!("
01
0800 // Length modulus (in bit): 2048
0020 // Length exponent (in bit): 32
00 // import in standard format
").as_slice();
const RSA_4K_ATTRIBUTES_STANDARD_IMPORT: &[u8] = hex!(
"
01
1000 // Length modulus (in bit): 4096
0020 // Length exponent (in bit): 32
00 // import in standard format
"
)
.as_slice();

#[derive(Debug, Copy, Clone)]
pub struct AlgorithmFromAttributesError;

Expand Down Expand Up @@ -107,8 +124,8 @@ impl TryFrom<&[u8]> for SignatureAlgorithm {
match v {
ED255_ATTRIBUTES => Ok(Self::Ed255),
ECDSA_P256_ATTRIBUTES => Ok(Self::EcDsaP256),
RSA_2K_ATTRIBUTES => Ok(Self::Rsa2048),
RSA_4K_ATTRIBUTES => Ok(Self::Rsa4096),
RSA_2K_ATTRIBUTES | RSA_2K_ATTRIBUTES_STANDARD_IMPORT => Ok(Self::Rsa2048),
RSA_4K_ATTRIBUTES | RSA_4K_ATTRIBUTES_STANDARD_IMPORT => Ok(Self::Rsa4096),
_ => Err(AlgorithmFromAttributesError),
}
}
Expand Down Expand Up @@ -160,8 +177,8 @@ impl TryFrom<&[u8]> for DecryptionAlgorithm {
match v {
X255_ATTRIBUTES => Ok(Self::X255),
ECDH_P256_ATTRIBUTES => Ok(Self::EcDhP256),
RSA_2K_ATTRIBUTES => Ok(Self::Rsa2048),
RSA_4K_ATTRIBUTES => Ok(Self::Rsa4096),
RSA_2K_ATTRIBUTES | RSA_2K_ATTRIBUTES_STANDARD_IMPORT => Ok(Self::Rsa2048),
RSA_4K_ATTRIBUTES | RSA_4K_ATTRIBUTES_STANDARD_IMPORT => Ok(Self::Rsa4096),
_ => Err(AlgorithmFromAttributesError),
}
}
Expand Down Expand Up @@ -213,8 +230,8 @@ impl TryFrom<&[u8]> for AuthenticationAlgorithm {
match v {
ED255_ATTRIBUTES => Ok(Self::Ed255),
ECDSA_P256_ATTRIBUTES => Ok(Self::EcDsaP256),
RSA_2K_ATTRIBUTES => Ok(Self::Rsa2048),
RSA_4K_ATTRIBUTES => Ok(Self::Rsa4096),
RSA_2K_ATTRIBUTES | RSA_2K_ATTRIBUTES_STANDARD_IMPORT => Ok(Self::Rsa2048),
RSA_4K_ATTRIBUTES | RSA_4K_ATTRIBUTES_STANDARD_IMPORT => Ok(Self::Rsa4096),
_ => Err(AlgorithmFromAttributesError),
}
}
Expand Down