【问题标题】:Change PIN of a Gemalto Smartcard through a script通过脚本更改金雅拓智能卡的 PIN
【发布时间】:2018-04-04 03:59:57
【问题描述】:

我们必须使用金雅拓 IDPrime .Net 卡智能卡。我们得到了这些 USB 加密狗,必须更改 PIN。

金雅拓通过 windows 说:

From the Start menu, choose Run and type PINTool.
Insert a IDPrime .Net card in the reader as prompted, and click OK. The change PIN interface appears
Enter the old PIN (the default PIN value is 0000), the new PIN and confirm the new PIN.
Click on Change Pin

http://support.gemalto.com/index.php?id=how_to_change_pin_in_a_idprime#.VWYTWUa8rV8

这可行,但我想通过 powershell 或 c# 设置一个新的 PIN/密码,即。 e.在程序的控制下。 怎么做或者是不可能的?

【问题讨论】:

    标签: smartcard gemalto


    【解决方案1】:

    您应该能够通过非托管 PKCS#11 API 更改 PIN,该 API 可以通过名为 Pkcs11Interop 的托管 .NET 包装器从 C# 轻松访问,我是该 API 的作者。

    以下是可以帮助您入门的代码示例:

    using Net.Pkcs11Interop.Common;
    using Net.Pkcs11Interop.HighLevelAPI;
    
    namespace ConsoleApplication
    {
        class Program
        {
            static void Main(string[] args)
            {
                // Load PKCS#11 library provided by Gemalto
                using (Pkcs11 pkcs11 = new Pkcs11("gtop11dotnet.dll", true))
                {
                    // Find first slot/reader with token/card present
                    Slot slot = pkcs11.GetSlotList(true)[0];
    
                    // Open RW session
                    using (Session session = slot.OpenSession(false))
                    {
                        // Login as normal user with current PIN
                        session.Login(CKU.CKU_USER, "0000");
    
                        // Set the new pin for the logged in user
                        session.SetPin("0000", "1111");
    
                        session.Logout();
                    }
                }
            }
        }
    }
    

    【讨论】:

    • 嗨,看起来不错。但我无法让它工作。 GetSlotList 返回 U 盘 - 但 OpenSession 返回 CKR_GENERAL_ERROR。
    • 我有两个插槽 - 我有一个带智能卡的戴尔键盘和 gemalto usb 加密狗。我使用正确的(在我的情况下是第二个)。是否可能没有正确的 gtop11dotnet.dll ?
    • AFAIK gtop11dotnet.dll 捆绑在较旧的 IDGo 500 中间件包中,并且在较新的 IDGo 800 中间件包中提供了 IDPrimePKCS11.dll。遗憾的是 IDGo 800 无法直接从金雅拓网站下载,但我相信您应该能够从您的卡供应商处获得它。
    • @Dominik 我忘了提到 gtop11dotnet.dll 返回的 CKR_GENERAL_ERROR 可以表示任何字面意思,因为它是 PKCS#11 规范中定义的最通用的错误代码。
    • 非常感谢。而已。我使用了错误的dll。没有按预期工作:-)
    【解决方案2】:

    使用为 C# 发布的答案 @jariq 我能够在 PowerShell 中使用以下内容来更改 Admin PIN

    注意:这专门针对正在被 IDPrime MD 产品线取代的金雅拓 IDPrime .NET 卡。有关更多信息,请参阅本文末尾。

    # www.pkcs11interop.net
    Add-Type -Path "C:\Somepath\Pkcs11Interop.4.0.0\lib\net45\Pkcs11Interop.dll"
    
    # Gemalto PKCS11 driver
    # 1 = single threaded
    $pkcs11 = New-Object Net.Pkcs11Interop.HighLevelAPI.Pkcs11("C:\somepath\gtop11dotnet64.dll",1)
    
    # 0 = SlotsType.WithTokenPresent
    $slots = $pkcs11.GetSlotList(0)
    
    $slot = $slots[0] # often its the first
    
    # create session
    # 1 = SessionType.ReadWrite
    $session = $slot.OpenSession(1)
    
    [byte[]]$defaultPIN = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    
    # 000000000000000000000001
    [byte[]]$newPIN = 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31
    
    # 0 = Security Officer a.k.a. Admin
    $session.Login(0, $defaultPIN)
    
    $session.SetPin($defaultPIN, $newPIN)
    
    $session.Dispose()
    $slot.CloseAllSessions()
    $pkcs11.Dispose()
    

    我发现将每个 PIN 转换为字节数组以用于登录和更改 PIN 是最成功的。为了将 48 位 Admin PIN 转换为 24 字节,创建了以下函数。

    Function Convert-AdminPinToByteArray([Validatepattern("^[0-9A-F]{48}$")][string]$AdminPIN)
    {
        $ReturnByte = New-Object byte[] 24
    
        $n = 0
    
        for($i=0;$i -lt $ReturnByte.Length;$i++)
        {
            $ReturnByte[$i] = [byte]"0x$($AdminPIN.SubString($n,2))"
            $n = $n + 2
        }
    
        return $ReturnByte
    
    } # End Function Convert-AdminPinToByteArray
    

    金雅拓卡类型

    以上示例基于即将退役的金雅拓 IDPrime .NET 卡。 End of Sale (EOS) announcement is here

    IDPrime .Net
    IDPrime .Net 生物
    
    关键日期:
    里程碑日期
    最后一次购买 (LTB) 2017 年 9 月 29 日
    终止销售 (EOS) 2017 年 9 月 30 日
    2018 年 9 月 30 日停产 (EOL)

    替换

    Per the EOS announcement PDF:

    产品 金雅拓的 IDPrime .NET 510/511 智能卡系列将被 IDPrime MD 83xIDPrime MD 84x 系列智能卡取代。

    对替换卡进行编程

    我已包含有关区分卡类型的信息,因为我有一个用于测试的金雅拓 IDPrime MD 830,但上述技术不起作用。事实上,使用上述技术,卡片甚至不会显示在读卡器中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 2013-07-29
      • 1970-01-01
      • 1970-01-01
      • 2020-12-12
      • 2023-03-21
      • 2017-11-10
      相关资源
      最近更新 更多