11

アプリケーションのユーザーが、個人の USB セキュリティ トークンを使用して承認に署名できるようにする必要があります。

データに署名することはできましたが、署名に誰のトークンが使用されたかという情報を取得できませんでした。

これが私がこれまでに持っているコードです:

CspParameters csp = new CspParameters(1, "SafeNet RSA CSP");
csp.Flags = CspProviderFlags.UseDefaultKeyContainer;            
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(csp);
// Create some data to sign. 
byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };
Console.WriteLine("Data         : " + BitConverter.ToString(data));
// Sign the data using the Smart Card CryptoGraphic Provider.            
byte[] sig = rsa.SignData(data, "SHA1");            
Console.WriteLine("Signature    : " + BitConverter.ToString(sig));

トークンの情報には「トークン名」というフィールドがあります。どのトークンが承認の署名に使用されたかを検証するために、そのフィールドにアクセスするにはどうすればよいですか?

ここに画像の説明を入力

追加情報と更新:

  • 「トークン名」は常に所有者の名前 (usb トークンを所有するユーザー) と一致します。
  • 認証局から直接情報を取得するために、Web サービスまたは何かを呼び出す必要がある可能性があります。
4

1 に答える 1

8

私が最初に質問したとき、デジタル証明書についての私の理解は非常に基本的であったため、適切に質問されていませんでした。これで、スマート カード デバイスから証明書にアクセスし、その属性を照会して、ユーザーが正しい PIN を入力できるかどうかをテストする必要があることがわかりました。

これが私がそうするために使用したコードです:

//Prompt the user with the list of certificates on the local store.
//The user have to select the certificate he wants to use for signing.
//Note: All certificates form the USB device are automatically copied to the local store as soon the device is plugged in.
X509Store store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509CertificateCollection certificates = X509Certificate2UI.SelectFromCollection(store.Certificates,
                                                                                "Certificados conocidos",
                                                                                "Por favor seleccione el certificado con el cual desea firmar",
                                                                                X509SelectionFlag.SingleSelection
                                                                                );
store.Close();
X509Certificate2 certificate = null;
if (certificates.Count != 0)
{
    //The selected certificate
    certificate = (X509Certificate2)certificates[0];
}
else
{
    //The user didn't select a certificate
    return "El usuario canceló la selección de un certificado";
}
//Check certificate's atributes to identify the type of certificate (censored)
if (certificate.Issuer != "CN=............................., OU=................., O=..., C=US")
{
    //The selected certificate is not of the needed type
    return "El certificado seleccionado no corresponde a un token ...";
}
//Check if the certificate is issued to the current user
if (!certificate.Subject.ToUpper().Contains(("E=" + pUserADLogin + "@censoreddomain.com").ToUpper()))
{
    return "El certificado seleccionado no corresponde al usuario actual";
}
//Check if the token is currently plugged in
XmlDocument xmlDoc = new XmlDocument();
XmlElement element = xmlDoc.CreateElement("Content", SignedXml.XmlDsigNamespaceUrl.ToString());
element.InnerText = "comodin";
xmlDoc.AppendChild(element);
SignedXml signedXml = new SignedXml();
try
{
    signedXml.SigningKey = certificate.PrivateKey;
}
catch
{
    //USB Token is not plugged in
    return "El token no se encuentra conectado al equipo";
}
DataObject dataObject = new DataObject();
dataObject.Data = xmlDoc.ChildNodes;
dataObject.Id = "CONTENT";
signedXml.AddObject(dataObject);
Reference reference = new Reference();
reference.Uri = "#CONTENT";
signedXml.AddReference(reference);
//Attempt to sign the data. The user will be prompted to enter his PIN
try
{
    signedXml.ComputeSignature();
}
catch
{
    //User didn't enter the correct PIN
    return "Hubo un error confirmando la identidad del usuario";
}
//The user has signed with the correct token
return String.Format("El usuario {0} ha firmado exitosamente usando el token con serial {1}", pUserADLogin, certificate.SerialNumber);

ソース:

http://stormimon.developpez.com/dotnet/signature-electronique/ ( フランス語) https://www.simple-talk.com/content/print.aspx?article=1713 (英語)

于 2013-03-05T20:27:19.287 に答える