如何在mono中使用certmgr导入自签名证书的私钥

noz*_*man 5 mono openssl certificate-store x509certificate2

我遇到一个问题,无法使用内置工具将证书私钥导入到 monos 证书库/密钥对库中certmgr

使用以下命令将证书公共版本添加到商店可以正常工作

user@maschine:~certs$ certmgr -add -c My MyCert.crt
Mono Certificate Manager - version 2.10.8.1
Manage X.509 certificates and CRL from stores.
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.

1 certificate(s) added to store My.
Run Code Online (Sandbox Code Playgroud)

但是,尝试添加相应的私钥会导致异常

user@maschine:~certs$ certmgr -add -c My MyCert.p12
Mono Certificate Manager - version 2.10.8.1
Manage X.509 certificates and CRL from stores.
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.


Unhandled Exception: System.Security.Cryptography.CryptographicException: Invalid MAC - file may have been tampered!
Run Code Online (Sandbox Code Playgroud)

尝试先添加公共版本 ( .cer),然后从私有版本 ( ) 导入相应的私钥.p12失败,但有一个稍微不同的例外:

user@maschine:~certs$ certmgr -add -c My MyCert.crt
Mono Certificate Manager - version 2.10.8.1
Manage X.509 certificates and CRL from stores.
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.

1 certificate(s) added to store My.
user@maschine:~certs$ certmgr -importKey -c My MyCert.p12
Mono Certificate Manager - version 2.10.8.1
Manage X.509 certificates and CRL from stores.
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.

Unhandled Exception: System.Security.Cryptography.CryptographicException: Improperly protected user's key pairs in '/var/licapp/.config/.mono/keypairs'.
Run Code Online (Sandbox Code Playgroud)

使用密码保护证书(并将相应的参数添加到命令中)也没有帮助。

我在 Debian Wheezy 上使用 mono V 2.10.8.1。有谁知道如何在商店中添加处理证书并使用 certmgr 处理其密钥对?

我正在考虑一种解决方法,我只是将 p12 文件保留在我的应用程序下,而不使用商店,我想这将是一个更不干净的解决方案。但我无法将证书和密钥对都添加到存储中。

顺便说一句,证书似乎没问题。将它们添加到 Windows 下的应用商店效果很好。

Tra*_*mas 6

文档存在一些问题,并且该工具的行为在某些地方有点奇怪或错误......

  1. 程序创建密钥对目录时,其权限设置错误。chmod 700 ~/.config/.mono/keypairs 解决了您列出的异常。
  2. 当您使用该-importKey操作时,您仍然必须指定对象类型证书,即使手册页没有说您必须使用对象类型。而且,没有“私钥”对象类型,而是使用“证书”对象类型(-c)。前任。certmgr -importKey -c -v -p p12password My CertAndKeyPair.p12为我带来成功消息。
  3. 第 2 步之后,证书/密钥将仍然无法访问。导入P12后,导入DER编码的证书。前任。certmgr -add -c My Certificate.cer这将使证书/密钥可供您的 .NET 代码使用。
  4. 如果要将证书/密钥安装到机器存储 ( -m),则必须使用sudo.