Skip to content

mikerains/xamarin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Xamarin Examples

echo "# xamarin" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/mikerains/xamarin.git
git push -u origin master

Configuration

Install Xamarin into Visual Studio 2017

Install Visual Studio Android Emulator

Debugging

Debugging with Local Android Device

Debugging with VS Android Emulator

Calling WebApi on my Local VStudio

App Crashes on phone, no Stack or Exception in VStudio Debugger

  • Command prompt in android-srd\platf0rm-tools> adb logcat AndroidRuntime:E *:S

App crashes, android doesn't trust the Local Service Fabric machine's Certificate

See: https://stackoverflow.com/questions/4926676/mono-https-webrequest-fails-with-the-authentication-or-decryption-has-failed

System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: TrustFailure (The authentication or decryption has failed.) ---> System.IO.IOException: The authentication or decryption has failed. ---> System.IO.IOException: Error while sending TLS Alert (Fatal:InternalError): System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010f at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (System.IAsyncResult asyncResult) [0x0000c] in :0 ---> System.IO.IOException: Unable to write data to the transport connection: Connection reset by peer. ---> System.Net.Sockets.SocketException: Connection reset by peer at System.Net.Sockets.Socket.EndSend (System.IAsyncResult asyncResult) [0x00012] in :0 ... --- End of inner exception stack trace --- at Mono.Net.Security.Private.LegacySslStream.AuthenticateAsClient (System.String targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) [0x0000e] in :0 ... at Hatcx.Services.UserManagement.Client.UserManagementOperations +d__10.MoveNext () [0x001b9] in :0 --- End of stack trace from previous location where exception was thrown --- at Hatcx.Services.UserManagement.Client.UserManagementOperationsExtensions+d__3.MoveNext () [0x00075] in :0 +d__10.MoveNext () [0x001b9] in :0 --- End of stack trace from previous location where exception was thrown --- ... at Hatcx.Mobile.Cost.Services.DataProvider+d__20.MoveNext () [0x00153] in C:\hatcxgit\HATCXCost\src\HatcxCost\Services\DataProvider.cs:263

Diagnosis: When .Net is running on a Windows machine, it has access to the certificate store, and knows about local certificates installed there. MONO does not have access to the store, so we need to handle untrusted certificates in the ServicePointManager callback.

https://stackoverflow.com/questions/4926676/mono-https-webrequest-fails-with-the-authentication-or-decryption-has-failed

In HatcxCostDroid's LaunchActivity.OnCreate:

//ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, policyErrors) =>
{
    string[] allowThumbprints = .....; //get from config somewhere
    if (errors == SslPolicyErrors.None) return true;

    // get the thumbprint of the certificate that is being validated
    var currentCertificateThumbprint = (certificate as X509Certificate2)?.Thumbprint;

    // determine if any of the allowed thumbprints matches the current thumbprint
    return !string.IsNullOrWhiteSpace(currentCertificateThumbprint) 
        && allowedThumbprints.Any(thumbprint => thumbprint.Equals(currentCertificateThumbprint, StringComparison.InvariantCultureIgnoreCase));
};

First of all, I got into these samples from working through Xamarin.com's "Application Fundamentals", and the first sample app is from https://developer.xamarin.com/guides/android/application_fundamentals/services/creating-a-service/bound-services/

Bound Service

Azure ADB2C Auth

Azure Storage

Azure Search

Grid Layout

JNI

Intro to Xamarin Forms

Master Detail Page

Media Browser

Multi-Touch Tracking

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages