w250697116 / apns-sharp

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

Windows 2003 #4

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Download binaries and place in bin directory
2. Setup NotificationService constructor as per the code below
3. Note the CryptographicException generated when you hit the page

What is the expected output? What do you see instead?
Appropriately instance of NotificationService

What version of the product are you using? On what operating system?
The Latest Download from your apns-sharp downloads on Windows Server 2003

Please provide any additional information below.
I get this exception:

CryptographicException: The system cannot find the path specified.
]

System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(I
nt32
hr) +33

System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(Strin
g
fileName) +0

System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFro
mFile(String
fileName, Object password, X509KeyStorageFlags keyStorageFlags) +94

System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String
fileName, String password) +128
   JdSoft.Apple.Apns.Notifications.NotificationConnection.start(String
p12File, String p12FilePassword) +274

JdSoft.Apple.Apns.Notifications.NotificationService.set_Connections(Int32
value) +109
   JdSoft.Apple.Apns.Notifications.NotificationService..ctor(Boolean
sandbox, String p12File, String p12FilePassword, Int32 connections) +186
   ASP.testapn_aspx.PushNotification(String DeviceUid, String Message) in
C:\Inetpub\vhosts\radarblast.com\httpdocs\testapn.aspx:40
   ASP.testapn_aspx.__Render__control1(HtmlTextWriter __w, Control
parameterContainer) in
C:\Inetpub\vhosts\radarblast.com\httpdocs\testapn.aspx:52
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
ICollection children) +98
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
   System.Web.UI.Page.Render(HtmlTextWriter writer) +26
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +121
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
   System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558

Source Code:

Dim sandbox As Boolean = True
Dim testDeviceToken As String = "123..sometoken..456"
Dim p12File As String = "apn_developer_identity.p12"
Dim p12FilePassword As String = "somepassword"
Dim count As Integer = 3
Dim sleepBetweenNotifications As Integer = 15000

Dim p12Filename As String =
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File)

Dim service As New
JdSoft.Apple.Apns.Notifications.NotificationService(sandbox, p12File,
p12FilePassword, 1)

If I change this line of code in NotificationConnection.cs;

certificate = new X509Certificate2(p12File, p12FilePassword);

to

certificate = new X509Certificate2(p12File, p12FilePassword,
X509KeyStorageFlags.MachineKeySet);

...it works.

Original issue reported on code.google.com by bernardb...@gmail.com on 7 Aug 2009 at 5:39

GoogleCodeExporter commented 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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
marcelogdl it was fixed, please get the latest code.

Original comment by jond...@gmail.com on 21 Jun 2010 at 3:45

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
Thanks.

Original comment by murat.erkara on 15 Feb 2011 at 10:28

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
@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