Previous Thread:   Security issue running unmanaged code in a win form ctrl hosted in

3/29/2006 5:37:57 AM    Strange problem with X509Certificate2 on Windows 2003
Hi,  
  
I am loading a private .pfx key using the X509Certificate2 class by the  
  
following line  
  
X509Certificate2 x509 = new X509Certificate2(PrivateKeyFile,  
  
PrivateKeyPassword);  
  
where PrivateKeyFile and PrivateKeyPassword are strings.  
  
This perfectly works on my computer with windows XP home and Visual Web  
  
Developer Express.  
  
But, when I upload this code to the production Windows Server 2003  
  
Standart edition, the code throws the exception  
  
System.Security.Cryptography.CryptographicException: The system cannot  
  
find the file specified.  
  
I am sure the file path PrivateKeyFile is correct, though I try to use  
  
an alternative where I load the private key into a byte array and then  
  
calling the X509Certificate2 directly on this array.  
  
byte[] klic = File.ReadAllBytes(PrivateKeyFile);  
  
X509Certificate2 x509 = new X509Certificate2(klic, PrivateKeyPassword);  
  
The key file is read correctly, but the certificate construcotr throws  
  
the same exception  
  
System.Security.Cryptography.CryptographicException: The system cannot  
  
find the file specified.  
  
System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32  
  
hr) +33  
  
System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[]  
  
rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet,  
  
SafeCertContextHandle& pCertCtx) +0  
  
System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[]  
  
rawData, Object password, X509KeyStorageFlags keyStorageFlags) +194  
  
System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[]  
  
rawData, String password) +134  
  
Muzo.Sign(String text) in  
  
d:\weby\kvetiny-kytice.cz\3dplatba\App_Code\Muzo.cs:71  
  
Muzo.CreateOrder(Page page, String orderNumber, String amount,  
  
String depositFlag, String merOrderNum, String url, String description,  
  
String md) in d:\weby\kvetiny-kytice.cz\3dplatba\App_Code\Muzo.cs:42  
  
user_redirect_muzo.Page_Load(Object sender, EventArgs e) in  
  
d:\weby\kvetiny-kytice.cz\3dplatba\user-redirect-muzo.aspx.cs:16  
  
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object  
  
o, Object t, EventArgs e) +15  
  
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object  
  
sender, EventArgs e) +34  
  
System.Web.UI.Control.OnLoad(EventArgs e) +99  
  
System.Web.UI.Control.LoadRecursive() +47  
  
System.Web.UI.Page.ProcessRequestMain(Boolean  
  
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
  
+1061  
  
It is strange because there is no file to open in this case.  
  
The version of NET is 2.0.50727 on both computers.  
  
Any suggestions?  
  
Mirek.

7250599242


3/31/2006 7:06:52 AM    Re: Strange problem with X509Certificate2 on Windows 2003
We made some new experiments regarding this problem, and found out some  
  
new and very strange facts.  
  
When the website runs under some user account and this user is logged  
  
in through terminal service, the X509Certificate2 works well.  
  
But when this user logs out, it stops working even if the website  
  
webserver still runs under this user.  
  
A temporary solution is possible by running an arbitrary program  
  
(calc.exe) by the same user as the website webserver runs under. This  
  
program is started by the scheduler at the system startup.  
  
It seems to me like a bug in Windows 2003. Or am I wrong?  
  
Mirek.

3/31/2006 10:22:11 AM    Re: Strange problem with X509Certificate2 on Windows 2003
yes it sounds like an acl issue. Don't have WinServer 2003 so can't check.  
  
- Mitch  
  
<mira@utia.cas.cz> wrote in message news:1143817612.862493.161990@i40g2000cwc.googlegroups.com...

4/3/2006 2:56:24 AM    Re: Strange problem with X509Certificate2 on Windows 2003
If this is a bug, is there some email adress at Microsoft to report it?  
  
Mirek.


Search

search