p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   certificate pfx c# gives me an err ".forbidden 403 (http://p2p.wrox.com/showthread.php?t=59542)

kalchev June 28th, 2007 08:05 AM

certificate pfx c# gives me an err ".forbidden 403
 
Hello averyone,
I have a certificate file "cert.pfx" and I've tried to use it all those ways showed bellow in the code. All the time I recieve the err:

"{System.Net.WebException: The remote server returned an error: (403) Forbidden.
   at System.Net.HttpWebRequest.GetResponse()...}"
I've imported the certificate in all possible the Certificates in the mmc Local Computer and User and still the same. The certificate password is perfect working when I taste it with the software given me from the company I bought the service. So any help is really welcom. Here is the source (One of the idea is that migh have some diificultis in the part of handshaking or whatever they called it):

Code:

            try
            {
                HttpWebRequestC2D = (HttpWebRequest)HttpWebRequest.Create(sConnectStringUrl);
                HttpWebRequestC2D.Method = "POST";
                HttpWebRequestC2D.ContentType = "text/xml";
                //X509Certificate x509 = X509Certificate.CreateFromCertFile(sCertFileName);
                //X509Certificate x509_1 = new System.Security.Cryptography.X509Certificates.X509Certificate2(sCertFileName, @"*******");
                //X509Certificate x509_1 = new System.Security.Cryptography.X509Certificates.X509Certificate2(File.ReadAllBytes(sCertFileName), @"*********", X509KeyStorageFlags.MachineKeySet);
                X509Certificate x509_1 = new System.Security.Cryptography.X509Certificates.X509Certificate2(File.ReadAllBytes(sCertFileName), @"*******", X509KeyStorageFlags.MachineKeySet);

                X509Store storeMyUser = new X509Store(StoreName.My, StoreLocation.CurrentUser);
                X509Store storeMachine = new X509Store(StoreLocation.LocalMachine);

                storeMyUser.Open(OpenFlags.MaxAllowed);
                storeMachine.Open(OpenFlags.MaxAllowed);

                //HttpWebRequestC2D.Headers.Add();
                X509Certificate2Collection x509CertCollectUser = storeMyUser.Certificates.Find(X509FindType.FindBySerialNumber, @"17 84 75 4f f3 74 a4 4e ae 40 d5 1b d2 bd c2 5e", false);
                X509Certificate2Collection x509CertCollectMachine = storeMachine.Certificates.Find(X509FindType.FindBySerialNumber, @"17 84 75 4f f3 74 a4 4e ae 40 d5 1b d2 bd c2 5e", false);

                HttpWebRequestC2D.ClientCertificates.Add(x509_1);
                for (int i = 0; i < x509CertCollectUser.Count;i++)
                    HttpWebRequestC2D.ClientCertificates.Add(x509CertCollectUser[i]);
                for (int i = 0; i < x509CertCollectMachine.Count; i++)
                    HttpWebRequestC2D.ClientCertificates.Add(x509CertCollectMachine[i]);

                storeMyUser.Close();
                storeMachine.Close();
                //System.Security.Cryptography.X509Certificates.
                //PFXExportCertStore();

                StreamWriter StreamWriterC2D = new StreamWriter(HttpWebRequestC2D.GetRequestStream());

                XmlTextWriter XmlTextWriterRequest = new XmlTextWriter(StreamWriterC2D);

                XmlTextWriterRequest.WriteProcessingInstruction("xml", @"version=""1.0"" encoding=""utf-8""");
                //XmlTextWriterRequest.WriteDocType("REQUEST_GROUP", null, "C2DRequestv2.0.dtd", null);


                XmlTextWriterRequest.WriteStartElement("OFX");

                XmlTextWriterRequest.WriteStartElement("SIGNONMSGSRQV1");
                XmlTextWriterRequest.WriteStartElement("SONRQ");
                XmlTextWriterRequest.WriteElementString("DTCLIENT", "20020725092657");
                XmlTextWriterRequest.WriteElementString("USERID", sUser);
                XmlTextWriterRequest.WriteElementString("USERPASS", sPassword);
                XmlTextWriterRequest.WriteElementString("LANGUAGE", "ENG");
                XmlTextWriterRequest.WriteElementString("APPID", "11111111");
                XmlTextWriterRequest.WriteElementString("APPVER", "2");
                XmlTextWriterRequest.WriteEndElement();
                XmlTextWriterRequest.WriteEndElement();

                XmlTextWriterRequest.WriteStartElement("EIVVERMSGSRQV1");
                XmlTextWriterRequest.WriteStartElement("EIVEMPLOYMENTTRNRQ");
                XmlTextWriterRequest.WriteElementString("TRNUID", "1234567890");
                XmlTextWriterRequest.WriteStartElement("TRNPURPOSE");
                XmlTextWriterRequest.WriteElementString("CODE", "PPCREDIT");
                XmlTextWriterRequest.WriteEndElement(); //TRNPURPOSE
                XmlTextWriterRequest.WriteStartElement("EIVEMPLOYMENTRQ");
                XmlTextWriterRequest.WriteElementString("EMPLOYERCODE", "99999");
                XmlTextWriterRequest.WriteElementString("EIVEMPLOYEEID", "001012414");
                XmlTextWriterRequest.WriteEndElement(); //EIVEMPLOYMENTRQ
                XmlTextWriterRequest.WriteEndElement();////EIVEMPLOYMENTTRNRQ
                XmlTextWriterRequest.WriteEndElement();////EIVVERMSGSRQV1

                XmlTextWriterRequest.WriteEndElement();//root OFX

                XmlTextWriterRequest.Close();

                HttpWebResponseC2D = (HttpWebResponse)HttpWebRequestC2D.GetResponse();



Thank You,
G

jdenbrock April 21st, 2009 07:56 AM

Were you able to find a solution to this problem? I'm currently working on the same project that your code is for and I'm running into the same issue.

Thanks!


All times are GMT -4. The time now is 08:27 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.