I am trying to make a sample Android app with Xamarin implementing receiving notifications by the Azure Notification Hub.
I followed the tutorial from http://www.windowsazure.com/en-us/manage/services/notification-hubs/getting-started-xamarin-android/
The application works OK on Android 4 but on Android 2.2 it gives me this message and exception. I think the error appears due to a call in Xamarin.NotificationHub:
await client.UploadStringTaskAsync(serverUrl, "POST", registrationPayload);
where serverUrl is the endpoint in the Azure Notification Hub
The message is
12-05 23:44:25.727 I/mono-stdout( 642): Error getting response stream (Write: The authentication or decryption has failed.): SendFailure
Exception:
System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a\n
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.RemoteValidation (Mono.Security.Protocol.Tls.ClientContext context, AlertDescription description) [0x00000] in <filename unknown>:0 \n
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates) [0x00000] in <filename unknown>:0 \n
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () [0x00000] in <filename unknown>:0 \n at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0 \n
at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0 \n
at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 \n --- End of inner exception stack trace ---\n
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 \n --- End of inner exception stack trace ---\n at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 \n
at System.Threading.Tasks.TaskFactory`1[System.IO.Stream].InnerInvoke (System.Threading.Tasks.TaskCompletionSource`1 tcs, System.Func`2 endMethod, IAsyncResult l) [0x00000] in <filename unknown>:0 \n--- End of stack trace from previous location where exception was thrown ---\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.IO.Stream].GetResult () [0x00000] in <filename unknown>:0 \n
at System.Net.WebClient+<UploadDataTaskAsyncCore>c__asyncA.MoveNext () [0x00000] in <filename unknown>:0 \n--- End of stack trace from previous location where exception was thrown ---\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Byte[]].GetResult () [0x00000] in <filename unknown>:0 \n
at System.Net.WebClient+<UploadStringTaskAsync>c__asyncD.MoveNext () [0x00000] in <filename unknown>:0 \n--- End of stack trace from previous location where exception was thrown ---\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n
at System.Runtime.CompilerServices.TaskAwaiter`1[System.String].GetResult () [0x00000] in <filename unknown>:0 \n
at ByteSmith.WindowsAzure.Messaging.NotificationHub+<CreateRegistration>d__33.MoveNext () [0x0012c] in e:\\Projects\\Xamarin\\TestNotificationHub2\\Client\\TestNotificationHub2\\Xamarin.NotificationHub-master\\source\\ByteSmith.WindowsAzure.Messaging\\NotificationHub.cs:415 \n--- End of stack trace from previous location where exception was thrown ---\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n
at System.Runtime.CompilerServices.TaskAwaiter`1[ByteSmith.WindowsAzure.Messaging.Registration].GetResult () [0x00000] in <filename unknown>:0 \n
at ByteSmith.WindowsAzure.Messaging.NotificationHub+<Register>d__23.MoveNext () [0x00151] in e:\\Projects\\Xamarin\\TestNotificationHub2\\Client\\TestNotificationHub2\\Xamarin.NotificationHub-master\\source\\ByteSmith.WindowsAzure.Messaging\\NotificationHub.cs:314 \n--- End of stack trace from previous location where exception was thrown ---\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n
at System.Runtime.CompilerServices.TaskAwaiter`1[ByteSmith.WindowsAzure.Messaging.Registration].GetResult () [0x00000] in <filename unknown>:0 \n
I believe there's a problem maybe with https certificates in mono, not sure and no idea how to fix.
It appears I was right. The code from here solves the issue:
http://slodge.blogspot.ro/2012/11/ssl-problems-with-microsoft-azure.html
Thanks to Stuart for sharing the code.
I still don't know exactly what is the best way to handle this issue. x