Closed GoogleCodeExporter closed 8 years ago
Hmm, so you don't have the public and private key pairs both in the p12 file
then? If you're telling it to check
the machinekeyset that seems like it would be the case. I'm not sure this is a
bug really, maybe a feature
enhancement to allow the ability to use the machine key store instead of just a
file...
Original comment by jond...@gmail.com
on 7 Aug 2009 at 11:13
I included the certificate and key from my keychain. The dev cert from Apple.
Do I need to include more?
Original comment by bernardb...@gmail.com
on 8 Aug 2009 at 4:21
Hi Jon,
I am also having the same issue with Windows Server 2003. I run your sample,
apns.Notification.test on the same server. Everything worked as expected.
After
that I did the following:
1. Place and add reference binaries in Bin folder
2. Also place "apns_dev_cert.p12.cert" in the root folder of the project
3. run this code in VB.net:
Imports System.xml.Linq
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports JdSoft.Apple.Apns.Notifications
Imports System.xml
Partial Class test_pushIt
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Button1.Click
'Variables you may need to edit:
'---------------------------------
'True if you are using sandbox certificate, or false if using production
Dim sandbox As Boolean = True
'Put your device token in here
Dim testDeviceToken As String = "xxxxafbb0d9d74bcd385ac75bxxxxxx......"
'Put your PKCS12 .p12 or .pfx filename here.
' Assumes it is in the same directory as your app
Dim p12File As String = "apns_dev_cert.p12"
'This is the password that you protected your p12File
' If you did not use a password, set it as null or an empty string
Dim p12FilePassword As String = "password"
'Number of notifications to send
Dim count As Integer = 2
'Number of milliseconds to wait in between sending notifications in the loop
' This is just to demonstrate that the APNS connection stays alive between
messages
Dim sleepBetweenNotifications As Integer = 15000
'Dim p12Filename As String =
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File)
Dim service As NotificationService = New NotificationService(sandbox,
p12File, p12FilePassword, 1)
service.SendRetries = 5 '5 retries before generating notificationfailed event
service.ReconnectDelay = 5000 '5 seconds
'service.Error += New NotificationService.OnError(AddressOf service_Error)
'service.NotificationTooLong += New
NotificationService.OnNotificationTooLong(AddressOf service_NotificationTooLong)
'service.NotificationFailed += New
NotificationService.OnNotificationFailed(AddressOf service_NotificationFailed)
'service.NotificationSuccess += New
NotificationService.OnNotificationSuccess(AddressOf service_NotificationSuccess)
'The notifications will be sent like this:
' Testing: 1...
' Testing: 2...
' Testing: 3!
' etc...
Dim i As Integer = 1
For i = 1 To count Step 1
'Create a new notification to send
Dim alertNotification As Notification = New Notification
alertNotification.DeviceToken = testDeviceToken
'We only set the body so this is a 'simple' alert notification type
alertNotification.Alert.Body = String.Format("Testing: {0}{1}", i, "...!")
'We set a badge number here, or could just as easily not set it.
alertNotification.Badge = i
'Queue the notification to be sent
If (service.QueueNotification(alertNotification)) Then
'Console.WriteLine("Notification Queued!")
Else
Console.WriteLine("Notification Failed to be Queued!")
'Sleep in between each message
If (i < count) Then
'Console.WriteLine("Sleeping " + sleepBetweenNotifications + "
milliseconds before next Notification...")
System.Threading.Thread.Sleep(sleepBetweenNotifications)
End If
' Console.WriteLine("Cleaning Up...")
'First, close the service.
'This ensures any queued notifications get sent befor the connections
are closed
service.Close()
'Clean up
service.Dispose()
Console.WriteLine("Done!")
Console.WriteLine("Press enter to exit...")
Console.ReadLine()
End If
Next
End Sub
'Overloads Shared Sub service_NotificationTooLong(ByVal sender As Object, ByVal
ex As NotificationLengthException)
' 'Console.WriteLine(String.Format("Notification Too Long: {0}",
ex.Notification.ToString()))
'End Sub
'Overloads Shared Sub service_NotificationSuccess(ByVal sender As Object, ByVal
Notification As Notification)
' Console.WriteLine(String.Format("Notification Success: {0}",
Notification.ToString()))
'End Sub
'Overloads Shared Sub service_NotificationFailed(ByVal sender As Object, ByVal
Notification As Notification)
' Console.WriteLine(String.Format("Notification Failed: {0}",
Notification.ToString()))
'End Sub
'Overloads Shared Sub service_Error(ByVal sender As Object, ByVal ex As Exception)
' Console.WriteLine(String.Format("Error: {0}", ex.Message))
'End Sub
End Class
3. I am getting the same file missing error at this line
Dim service As NotificationService = New NotificationService(sandbox, p12File,
p12FilePassword, 1)
Error below:
Server Error in '/ASPX' Application.
The system cannot find the path specified.
Description: An unhandled exception occurred during the execution of the
current web
request. Please review the stack trace for more information about the error and
where
it originated in the code.
Exception Details: System.Security.Cryptography.CryptographicException: The
system
cannot find the path specified.
Source Error:
Line 40: 'Dim p12Filename As String =
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File)
Line 41:
Line 42: Dim service As NotificationService = New
NotificationService(sandbox, p12File, p12FilePassword, 1)
Line 43:
Line 44: service.SendRetries = 5 '5 retries before generating
notificationfailed event
Source File: C:\Documents and
Settings\Administrator\Desktop\MM360DeskTop\mobile360\ASPX\test_pushIt.aspx.vb
Line: 42
Stack Trace:
[CryptographicException: The system cannot find the path specified.
]
System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(I
nt32
hr) +33
System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String
fileName) +0
System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFro
mFile(String
fileName, Object password, X509KeyStorageFlags keyStorageFlags) +105
System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String
fileName, String password) +78
System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String
fileName, String password) +68
JdSoft.Apple.Apns.Notifications.NotificationConnection.start(String p12File,
String p12FilePassword) +308
JdSoft.Apple.Apns.Notifications.NotificationConnection..ctor(String host, Int32
port, String p12File, String p12FilePassword) +72
JdSoft.Apple.Apns.Notifications.NotificationService.set_Connections(Int32 value) +187
JdSoft.Apple.Apns.Notifications.NotificationService..ctor(Boolean sandbox, String
p12File, String p12FilePassword, Int32 connections) +299
test_pushIt.Button1_Click(Object sender, EventArgs e) in C:\Documents and
Settings\Administrator\Desktop\MM360DeskTop\mobile360\ASPX\test_pushIt.aspx.vb:4
2
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +126
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +136
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBa
ckEvent(String
eventArgument) +39
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String
eventArgument) +37
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +87
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint) +4177
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET
Version:2.0.50727.3082
Thanks,
Moe
Original comment by mtun...@gmail.com
on 15 Aug 2009 at 8:38
Hi,
I have the same problem. When I upload this to my hosting provider I get this
error. When I change the
NotificationConnection.cs it doesn't run, it just shows you a loading bar on
the bottom of IE and it isn't
working. How can I solve this?
Best Regards,
Kenneth
Original comment by vucades...@gmail.com
on 17 Oct 2009 at 2:24
Fixed, the sample was using p12File for the constructor of NotificationService
instead of p12Filename
Original comment by jond...@gmail.com
on 22 Dec 2009 at 5:51
Anybody could solve this error? I have exactly the same behavior reported by
vucadesign, Oct 17, 2009. Please I need help.
Regards
Original comment by marcelo...@gmail.com
on 10 Jun 2010 at 9:17
[deleted comment]
marcelogdl it was fixed, please get the latest code.
Original comment by jond...@gmail.com
on 21 Jun 2010 at 3:45
I am having Mocha as my web hoster hosting my application & iam indeed using
the latest Apns-Sharp-1.0.3.0 but I see this issue still exists.
this is my constructor
string p12Filename =
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File);
NotificationService service = new NotificationService(sandbox, p12Filename, p12FilePassword, 1);
I do not have any issues on trying to send a message from my dev/build box or
for that matter from my staging server.I see this issue after I upload a copy
from my staging to production(mocha).
System.Web.Services.Protocols.SoapException: Server was unable to process
request. ---> System.Security.Cryptography.CryptographicException: An internal
error occurred. at
System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(I
nt32 hr) at
System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[]
rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet,
SafeCertContextHandle& pCertCtx) at
System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFro
mBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags) at
System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[]
rawData, String password) at
JdSoft.Apple.Apns.Notifications.NotificationConnection.start(String p12File,
String p12FilePassword) at
JdSoft.Apple.Apns.Notifications.NotificationService.set_Connections(Int32
value) at JdSoft.Apple.Apns.Notifications.NotificationService..ctor(Boolean
sandbox, String p12File, String p12FilePassword, Int32 connections) at
APNS.SendNotification() at Services.SendMessage(MessageInfo Message) --- End of
inner exception stack trace ---
help appreciated.
- unni
Original comment by uknamboo...@gmail.com
on 30 Jun 2010 at 9:50
I just ran into the same problem with the latest version of the code, like
others. The code was running perfectly fine both on my local machine (a Windows
7 box) and on our dev server at work (a Windows 2003 box). However, as soon as
I deployed the code to our production server (a Windows 2008 virtual machine on
Amazon EC2), it started failing with a similar CryptographicException with the
message "Object not found".
After numerous searches, I found similar references to the use of
"X509KeyStorageFlags.MachineKeySet" as one is constructing the X509Certificate2
object (for example, see the first reply here: http://goo.gl/b6t2 ). Lo and
behold, I changed the library code (as the original poster did) to use this and
the problem went away on the production server.
I should note that, I don't have any imported certificates, that I am actually
trying to import the certificate from the .p12 file. I guess the problem arises
when a web project is trying to perform a cryptographic operation, but the
operation somehow tries to find the private key in the current user set (which
seems to be the default). However, for such cases, it seems the MachineKeySet
can manage to load it fine. The MSDN documentation also states that
MachineKeySet implies "Private keys are stored in the local computer store
rather than the current user store." (See: http://goo.gl/f2z3 )
Original comment by paracy...@gmail.com
on 13 Jul 2010 at 5:34
Thank you very much, paracycle. Your comment saved my day. To be specific, this
constructor in NotificationChannel.cs needed to be changed to:
public NotificationChannel(string host, int port, byte[] p12FileBytes, string p12FilePassword)
{
Host = host;
Port = port;
connected = false;
firstConnect = true;
ReconnectDelay = 3000;
ConnectRetries = 6;
//Need to load the private key seperately from apple
if (string.IsNullOrEmpty(p12FilePassword))
certificate = new X509Certificate2(p12FileBytes, "", X509KeyStorageFlags.MachineKeySet);
else
certificate = new X509Certificate2(p12FileBytes, p12FilePassword, X509KeyStorageFlags.MachineKeySet);
certificates = new X509CertificateCollection();
certificates.Add(certificate);
}
This is running on Rackspace Cloud Sites (used to be Mosso).
Original comment by allara.s...@gmail.com
on 31 Dec 2010 at 8:54
Greetings,
Thank you allara.starmist for your contribution. We changed our local source of
the apns library and now it works.
@APNS Team
It would be great if you could change the code into the original source
binaries you provide for downloading.
Best regards from Austria,
Mario Fraiß
Original comment by mario.fr...@gmail.com
on 9 Jan 2011 at 6:39
Just checked the code and this is still there. I wasted 2 hours trying to
track this down. Could someone please update the source?
Original comment by shanehen...@gmail.com
on 18 Jan 2011 at 2:38
This is solution for "CryptographicException: The system cannot find the path
specified." issue,
"certificate = new X509Certificate2(p12FileBytes, p12FilePassword,
X509KeyStorageFlags.MachineKeySet);"
Thanks to all.....
Original comment by brijesh....@gmail.com
on 14 Feb 2011 at 9:02
Thanks.
Original comment by murat.erkara
on 15 Feb 2011 at 10:28
hmm, i solved this by setting the user for the application pool to be system.
In IIS > (machine) > Application Pools> 'YourAppPool' > properties > choose
identity then set this to local system.
Original comment by burrows1...@gmail.com
on 5 Apr 2011 at 3:27
This Fixed it for us! 2 hours spent looking for this.
X509KeyStorageFlags.MachineKeySet
is the ticket to solve your problems
Original comment by shanemen...@gmail.com
on 16 Aug 2011 at 5:09
I changed my iis App Pool as suggested but problem stil exists. No erors but
no notifications. I placed the console app on the same server and it works. My
IIS website/app does not work. Any idea what to check next?
Original comment by vilasack...@gmail.com
on 24 Feb 2012 at 3:54
@vilasack: did you find your answer? I'm seeing the same thing.
Original comment by bobw...@gmail.com
on 22 Jun 2012 at 12:02
Original issue reported on code.google.com by
bernardb...@gmail.com
on 7 Aug 2009 at 5:39