snnagar / apns-sharp

Automatically exported from code.google.com/p/apns-sharp
0 stars 0 forks source link

System.Security.Cryptography.CryptographicException: An internal error occurred #47

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Run the source code of a production server.

It works fine in debug mode on localhost.

What is the expected output? What do you see instead?
System.Security.Cryptography.CryptographicException: An internal error occurred
NotificationService service = new NotificationService(sandbox, p12Filename, 
p12FilePassword, 1);

What version of the product are you using? On what operating system?
Windows 7 and the latest build of apns-sharp

Please provide any additional information below.
I'm brand new to apns-sharp and have seen other issue related to the error 
above... but i noticed something very odd.  My code works perfectly when i run 
it in debug mode from Visual Studio.  But when i run it directly from the 
server it fails with the message above.   So i suspect this is more of a 
configuration setting in Debug mode or perhaps something the application pool.

Any ideas?

Original issue reported on code.google.com by markfri...@gmail.com on 14 Feb 2011 at 4:35

GoogleCodeExporter commented 9 years ago
Is there an internal exception? 

Not really enough info to go off of here...

Original comment by jond...@gmail.com on 14 Feb 2011 at 7:40

GoogleCodeExporter commented 9 years ago

Original comment by jond...@gmail.com on 14 Feb 2011 at 7:45

GoogleCodeExporter commented 9 years ago
Yes the stack trace is below.   But i was able to determine that this issue 
ONLY occurs when you are running the site under and ApplicationPoolIdentity 
process model.  If I switch to run the site via built-in accounts: 
LocalService, LocalSystem, or NetworkService, then i works fine.  I hope others 
having this issue will find this helpful.

[CryptographicException: An internal error occurred.
]
   System.Security.Cryptography.CryptographicException.ThrowCryptographicException(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) +203
   System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password) +80
   System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password) +79
   JdSoft.Apple.Apns.Notifications.NotificationConnection.start(String p12File, String p12FilePassword) +224
   JdSoft.Apple.Apns.Notifications.NotificationService.set_Connections(Int32 value) +119
   JdSoft.Apple.Apns.Notifications.NotificationService..ctor(Boolean sandbox, String p12File, String p12FilePassword, Int32 connections) +211
   APN.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\iPhone\APN.aspx.cs:51
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

Original comment by markfri...@gmail.com on 14 Feb 2011 at 7:50

GoogleCodeExporter commented 9 years ago
Hi,

i've got the same problem. Have you find a workaround?

My production server is a Windows 2008 R2 64bits.

Thank you

Original comment by julie...@gmail.com on 24 Feb 2011 at 9:00

GoogleCodeExporter commented 9 years ago
yes, use next code  in NotificationConnection.cs file's start function

certificate = new X509Certificate2(System.IO.File.ReadAllBytes(p12File),
p12FilePassword
                    , X509KeyStorageFlags.MachineKeySet |
X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

Original comment by watc...@gmail.com on 24 Feb 2011 at 10:17

GoogleCodeExporter commented 9 years ago
I solved problem simply by switching the site's process model.   Under 
ApplicationPoolIdentity it fails for me but it works fine under  built-in 
accounts: LocalService, LocalSystem, or NetworkService

Original comment by markfri...@gmail.com on 24 Feb 2011 at 8:44

GoogleCodeExporter commented 9 years ago
Thanks,

I tried it with the LocalService account and it work find now.

Original comment by julie...@gmail.com on 28 Feb 2011 at 11:56

GoogleCodeExporter commented 9 years ago
Thanks a lot, it works for me.

certificate = new X509Certificate2(System.IO.File.ReadAllBytes(p12File),
p12FilePassword
                    , X509KeyStorageFlags.MachineKeySet |
X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

Thanks again.

Original comment by jacklin0...@gmail.com on 9 Mar 2011 at 4:20

GoogleCodeExporter commented 9 years ago
I'm typing in 

certificate = new X509Certificate2(System.IO.File.ReadAllBytes(p12File),
p12FilePassword
                    , X509KeyStorageFlags.MachineKeySet |
X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

in the start function but I don't know where the certificate variable is coming 
from? any help?

thanks
Adam

Original comment by TatZ...@gmail.com on 17 Jul 2011 at 9:10

GoogleCodeExporter commented 9 years ago
I was having this issue before but after using 

certificate = new X509Certificate2(System.IO.File.ReadAllBytes(p12File),
p12FilePassword
                    , X509KeyStorageFlags.MachineKeySet |
X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

the issue disappear but I am not receiving any local notification. I am hosting 
the server side code as a web service online and have no dedicated server for 
it. I guess the problem is not installing the .p12 on the server. Is there a 
way of dynamically loading the file at runtime. Also, how do you set the 
Application Pool Identity in the web.config file?

Thanks

Original comment by falo...@gmail.com on 22 Sep 2011 at 2:19

GoogleCodeExporter commented 9 years ago
i have the same problem i am not receiving any local notification
please help

Original comment by babitsk...@gmail.com on 5 Nov 2011 at 7:42

GoogleCodeExporter commented 9 years ago
Thanks.. Change to Local Service and it works for me..

Original comment by fingerte...@gmail.com on 9 Nov 2011 at 8:42

GoogleCodeExporter commented 9 years ago
Hi all,
I have following error what should i do please anyone help me..
_certificate = string.IsNullOrEmpty(p12FilePassword)? new 
X509Certificate2(File.ReadAllBytes(p12File)): new 
X509Certificate2(File.ReadAllBytes(p12File), p12FilePassword);

o/p:-{"The parameter is incorrect.\r\n"}

Thanks

Original comment by kiran.na...@gmail.com on 6 Feb 2012 at 1:55

GoogleCodeExporter commented 9 years ago
I'am using MoonAPNS and also have the same problem. 

Original comment by jaso...@healthcareoftoday.com on 14 Feb 2012 at 11:03

GoogleCodeExporter commented 9 years ago
Problems here also...

1. having the Cryptography error

2. replaced start function with certificate = new 
X509Certificate2(System.IO.File.ReadAllBytes(p12File), p12FilePassword          
          , X509KeyStorageFlags.MachineKeySet | 
X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

3. error is gone now but still no notifications

4. tried localsystem and localservice account for application pool but without 
succes

5. Also imported the certificate on the IIS-server

Did anybody solve this allready?

Original comment by GertjanC...@gmail.com on 21 Feb 2012 at 7:11

GoogleCodeExporter commented 9 years ago
I am having problems getting this to work with IIS.  The sample console app 
works find on the same server as my IIS.  What should I double check.

Original comment by vilasack...@gmail.com on 24 Feb 2012 at 3:50

GoogleCodeExporter commented 9 years ago
Change to LocalService and it works for me
thanks

Pablo Sanchez

Original comment by pablocsr...@gmail.com on 15 Mar 2012 at 7:49

GoogleCodeExporter commented 9 years ago
Hi,

I am also getting same problem-"An internal error occurred" in my web 
service(.Net).

Also, my server does not support SSL, so can anybody let me know how can i 
change 
built-in accounts: LocalService, LocalSystem, or NetworkService????

I have alraedy spent too much time but couldn't get any luck.

Original comment by arvind.a...@gmail.com on 16 Mar 2012 at 2:19

GoogleCodeExporter commented 9 years ago
This project site is no longer used.  Please use GitHub instead:

http://github.com/Redth/APNS-Sharp/

Original comment by jond...@gmail.com on 16 Mar 2012 at 2:41