简体   繁体   English

当您尝试使用 PIV 卡的私钥和全局密码进行签名时,RSACryptoServiceProvider 是否有效?

[英]Does RSACryptoServiceProvider work when you try to sign using PIV card's private key and a global pin?

I am trying to use RSACryptoServiceProvider with CspParameters that point to a global pin.我正在尝试将 RSACryptoServiceProvider 与指向全局引脚的 CspParameters 一起使用。 It works correctly if I use an application pin but when I use the global pin it fails with: "The card cannot be accessed because the wrong PIN was presented."如果我使用应用程序 pin,它可以正常工作,但是当我使用全局 pin 时,它会失败:“无法访问卡,因为提供了错误的 PIN。”

Will it work when I use a global pin?当我使用全局引脚时它会起作用吗? Is there an option that tells it what type of pin to look for?是否有一个选项可以告诉它要寻找哪种类型的引脚?

Thanks in advance.提前致谢。

Update:更新:

I am retrieving the discovery object from the smart card if it exists.我正在从智能卡中检索发现 object(如果存在)。 This will tell me two things I want to know.这将告诉我两件我想知道的事情。

1). 1)。 If the card has both application and global pins.如果卡同时具有应用和全局引脚。 (first byte of pin usage >= 60) (引脚使用的第一个字节> = 60)

2). 2)。 Which pin is considered primary.哪个引脚被认为是主要的。 (second byte 0x10 = app, 0x20 = global) (第二个字节 0x10 = 应用程序,0x20 = 全局)

I have a card, the NIST Test Pivcard 3, which has both pins but the global pin is primary.我有一张卡,NIST Test Pivcard 3,它有两个引脚,但全局引脚是主要的。 For this card when I enter the global pin on my test form, I can do a verify against it and it validates the pin correctly.对于这张卡,当我在我的测试表上输入全局密码时,我可以对其进行验证,它会正确验证密码。 (CLA=0x00, INS=0x20, P1=0x00, P2=0x00, Lc=0x8) (CLA=0x00, INS=0x20, P1=0x00, P2=0x00, Lc=0x8)

I can do the same for this card if I enter the application pin instead (with P2 set to 0x80) and it verifies it correctly.如果我输入应用程序引脚(将 P2 设置为 0x80)并正确验证它,我可以对这张卡执行相同的操作。

After I verify the pin, set the AID and get some other x509 data from the card, I attempt to sign some hashed data using the card's private key.在我验证密码、设置 AID 并从卡中获取一些其他 x509 数据后,我尝试使用卡的私钥对一些散列数据进行签名。

Using RSACryptoServiceProvider and CspParameters it fails whenever I pass it the global pin.使用 RSACryptoServiceProvider 和 CspParameters 时,只要我将全局引脚传递给它,它就会失败。 I get "The card cannot be accessed because the wrong PIN was presented."我收到“无法访问该卡,因为提供了错误的 PIN。”

If I pass it a valid application pin, then it works fine.如果我向它传递一个有效的应用程序 pin,那么它工作正常。

My code looks like this:我的代码如下所示:

try
{
SecureString ss = new SecureString();
char[] PINs = PIN.ToCharArray();
foreach (char a in PINs)
{
    ss.AppendChar(a);
}
CspParameters csp = new CspParameters(1, "Microsoft Base Smart Card Crypto Provider");
csp.Flags = CspProviderFlags.UseDefaultKeyContainer;
csp.KeyPassword = ss;
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(csp);
byte[] data = File.ReadAllBytes(hashFile);
sig = rsa.SignHash(data, "SHA1");
bool verified = rsa.VerifyHash(data, CryptoConfig.MapNameToOID("SHA1"), sig);
}
catch (Exception ex)
{
  txt_msg.Text = ex.Message;
  etc...
}

Is there some flag I am missing here to say that the pin being used is a global pin?我在这里缺少一些标志来说明正在使用的引脚是全局引脚吗? Or are we not allowed to use a global pin?还是我们不允许使用全局引脚? Or am I missing some other thing here?还是我在这里错过了其他东西? This is my first attempt to use RSACryptoServiceProvider and I'm probably missing some fundamentals.这是我第一次尝试使用 RSACryptoServiceProvider,我可能缺少一些基础知识。

Any suggestions would be appreciated.任何建议,将不胜感激。

You seem to assume, that PINs are somewhat exchangeable in the sense, that a global PIN is an appropriate substitute for an application-specific one.您似乎假设 PIN 在某种意义上是可交换的,全局 PIN 是特定应用程序的适当替代品。 This is not true.这不是真的。

While a card could have been set up this way (accepting global PIN say #1 OR application specific PIN #2), your card is obviously not.虽然可以通过这种方式设置卡(接受全局 PIN,例如 #1应用程序特定 PIN #2),但您的卡显然不是。 If the card does not offer the choice, the service provider can't succeed.如果卡不提供选择,服务提供商就无法成功。 Even if the service provider uses the PIN you want and the comparison succeeds, the card will not allow usage of the private key.即使服务提供商使用您想要的 PIN 并且比对成功,该卡也不允许使用私钥。

And no, there is no way that you change the ID of the PIN required for signature according to your liking, since this path would then also be available for an attacker.不,您无法根据自己的喜好更改签名所需的 PIN 的 ID,因为攻击者也可以使用此路径。

(All of this answers assume, that you are not allowed to modify the card content, eg you are a normal card holder.) (所有这些答案都假设您不允许修改卡片内容,例如您是普通持卡人。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 PEM 私钥并使用 RSACryptoServiceProvider 和 SHA1 算法对文本进行签名 - Sign a text with PEM private key and using RSACryptoServiceProvider and SHA1 algorithm RSACryptoServiceProvider仅使用私钥解密 - RSACryptoServiceProvider decrypt using only private key RSACryptoServiceProvider使用自己的公钥和私钥加密和解密 - RSACryptoServiceProvider encrypt and decrypt using own public and private key 使用C#中的RSA私钥文件创建RSACryptoServiceProvider对象 - Create RSACryptoServiceProvider object using RSA private key file in C# 将私钥转换为 RSACryptoServiceProvider 不起作用 - Casting private key to RSACryptoServiceProvider not working RSACryptoServiceProvider使用自己的公钥和私钥进行初始化 - RSACryptoServiceProvider initialize with own public key and private key 在使用RSACryptoServiceProvider签名之前,请验证私钥保护 - Verify Private Key Protection before signing with RSACryptoServiceProvider Windows Phone API:使用RSACryptoServiceProvider签名数据 - Windows Phone API: using RSACryptoServiceProvider to sign data 使用私钥对JWT令牌进行签名 - Using private key to sign a JWT token 您可以在ppk文件中用私钥对字符串签名吗? - Can you sign a string with a private key in a ppk file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM