Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

fix(sign): explain 0xC0000225 when a token's key provider can't find the key (#1535)

mtlcl4105b813ce9857c
diff --git a/crates/sign/src/windows.rs b/crates/sign/src/windows.rs
index b63d49cd0..cea93715f 100644
--- a/crates/sign/src/windows.rs
+++ b/crates/sign/src/windows.rs
@@ -209,6 +209,8 @@ const NTE_DEVICE_NOT_READY: u32 = 0x8009_0030;
const NTE_DEVICE_NOT_FOUND: u32 = 0x8009_0035;
const NTE_USER_CANCELLED: u32 = 0x8009_0036;
const CRYPT_E_NO_KEY_PROPERTY: u32 = 0x8009_200B;
+// An NTSTATUS (ntstatus.h) that some key providers pass through unchanged.
+const STATUS_NOT_FOUND: u32 = 0xC000_0225;
/// A CNG error with the Windows code and, for the usual ones, what it means.
fn describe(e: &CngError) -> String {
@@ -224,6 +226,10 @@ fn describe(e: &CngError) -> String {
NTE_PROVIDER_DLL_FAIL => {
"its key provider's software failed to load (a smart card or token driver that is missing or broken, or a 32-bit-only provider)"
}
+ // #1535: an A3 certificate (key on a token) whose provider can't find the key.
+ STATUS_NOT_FOUND => {
+ "its key provider can't find the key (the smart card or token holding it isn't connected, or its driver doesn't see the key)"
+ }
NTE_NOT_SUPPORTED => "its key provider doesn't support the operation",
NTE_DEVICE_NOT_READY | NTE_DEVICE_NOT_FOUND => "the smart card or token isn't available",
NTE_USER_CANCELLED => "the request was cancelled",
@@ -251,6 +257,11 @@ mod tests {
"its key provider's software failed to load (a smart card or token driver that is missing or broken, or a 32-bit-only provider) (Windows error 0x8009001D)",
"#2207"
);
+ assert_eq!(
+ describe(&CngError::WindowsError(0xC000_0225)),
+ "its key provider can't find the key (the smart card or token holding it isn't connected, or its driver doesn't see the key) (Windows error 0xC0000225)",
+ "#1535"
+ );
assert_eq!(describe(&CngError::WindowsError(0x57)), "Windows error 0x00000057");
assert_eq!(describe(&CngError::InvalidHashLength), "Invalid hash length");
}