Hi Brian,
I have discussed with some other security engineers on this issue, and so
far what we conclude is that if use STRONG_PROTECTION on your certificate,
the password dialog box will surely display and there is no programmatic
way to suppress it. Also, this STRONG_PROTECTION is available only for
certificate in current user store, for those certificates in machine
certificate store, there is no such STRONG_PROTECT setting(the security is
controlled by the access permssion to machine store). Therefore, they also
suggest that for server-side application, it is recommend that we put those
certificates in machine store (avoid such STRONG_PROTECT setting).
Here is the original comments from our security engineers for your
reference:
If you are referring to the smartcard PIN prompt while accessing the
private key in the smartcard, this can be accomplished using
CryptSetProvParam as Shawn explained below.
If you are referring to the password for the strong protection of private
key, there is no programmatic Crypto API to supply this password.
When strong protection is enabled for the RSA private key, the user is
notified through a dialog box when applications attempt to use the private
key.
One specifies that the RSA private key is enabled for strong protection
either during certificate request or when pfx is imported. Essentially this
is done when the RSA private key is generated/installed/imported etc.
With Medium strong protection, the user is notified. But there is no
password to enter.
With High strong protection, the user has to supply the password, every
time the key is used.
The dialog to choose "Security Level" comes from Protected Storage
component of Windows that allows the user to select either medium or high
protection on the RSA private key while the private key is
generated/installed/imported.
Later, when there is an attempt to access that RSA private key, the dialog
box is presented for security reasons and only the end user has control in
answering this dialog box.
There is no way to control this dialog box behavior from an application
silently when the private key is accessed. Also, there is no programmatic
Crypto API to supply the password. If the private key is not protected, you
will not get the prompt.
Please note that the "strong protection" feature for RSA private key is
available only for certificates installed in current user Certificate store
such as user's certificates where an end user is involved for answering
this dialog box.
However, this feature is not available for certificates generated/installed
in local machine certificate store. You will see that this option is
disabled no matter how the certificate/PFX is generated or installed in any
GUI. Also, the certificate generation requests fail when this mode is
selected programmatically.
If this is purely a server side application like ASP.NET, you cannot use
CurrentUser certificate store anyway as the user's profile (where the
certificates are stored) of the calling user account won't be loaded.
Server side components like IIS/ASP.NET or services running under well
known accounts can typically use only certificates in "Local computer"
certificate store.
So, if this certificate is for the server application component itself to
use, then the solution for server side involves installing and using
certificates in "Local Computer" certificate store as local administrator.
Please note that only local Administrators group (and NT AUTHORITY\SYSTEM)
will have access to the corresponding RSA private key container by default.
If access to the corresponding RSA private key container is required by
non-admins such as Network Service or some other account, local
administrator can configure access through winhttpcertcfg tool as
documented at:
http://msdn2.microsoft.com/en-us/library/aa384088.aspx
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.