Closed jgannaway closed 5 years ago
There is a new certificate for www.howsmyssl.com. I've just updated the corresponding pin in the tests. Now the tests are running successfully on Android (at least with my own setup).
Now, you can try to pull this commit and test again, but I don't think this has anything to do with your issue.
One thing is sure: set_ServerCertificateCustomValidationCallback should not be called on Android, it's only supported on .Net. Which means for some weird reason, your code is not using the android assembly, but the netstandard one instead.
Could you please provide more information about your configuration, so I can try to reproduce your issue (VS and Xamarin versions ; Android SDK version ; emulator or device...) ? Also, the stack trace you copied is not from the test runner. Could you provide the real stacktrace (from the runner, not from your porject)? And one more thing, maybe you can share the code you're running in SecureHttpClientDemo ?
I was originally trying to setup a test with a new, empty Xamarin.Forms app, but I got the System.NotImplementedException
exception. So, then I thought I would just download this repo and try it. When I was able to get everything to build and deploy, I was testing using an emulator.
I had copy/pasted the wrong stack trace in my original post. Here's the one from the runner (as you mentioned, it's strange that it references the netstandard implementation):
at System.Net.Http.HttpClientHandler.set_ServerCertificateCustomValidationCallback (System.Func`5[T1,T2,T3,T4,TResult] value) [0x00000] in <25ebe1083eaf4329b5adfdd5bbb7aa57>:0
at SecureHttpClient.SecureHttpClientHandler.AddCertificatePinner (System.String hostname, System.String[] pins) [0x00014] in C:\p\secure-httpclient\SecureHttpClient\Platforms\Net\SecureHttpClientHandler.cs:48
at SecureHttpClient.Test.CertificatePinnerTest+<CertificatePinnerTest_OneHost_Success>d__8.MoveNext () [0x00023] in C:\p\secure-httpclient\SecureHttpClient.Test\CertificatePinnerTest.cs:26
I was having trouble getting this repo to build in VS 2017, so I adjusted the Android version to 8.1 and removed the global.json file, which allowed the build to succeed (but I got the error above).
I wasn't able to get this repo to build on VS for Mac (v7 or v8). I even changed the global.json file to target the versions I had installed.
I was curious about the global.json file and how it would impact projects that also have an Sdk value defined (i.e. <Project Sdk="MSBuild.Sdk.Extras/1.6.68">
), but I'm not really sure how all that works.
After installing VS 2019, I got the test runner to work on my PC, which has the following setup:
Microsoft Visual Studio Enterprise 2019
Version 16.0.1
VisualStudio.16.Release/16.0.1+28803.156
Microsoft .NET Framework
Version 4.7.03056
Installed Version: Enterprise
Mono Debugging for Visual Studio 16.0.300 (573eda3)
Support for debugging Mono processes with Visual Studio.
NuGet Package Manager 5.0.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.
VisualStudio.Mac 1.0
Mac Extension for Visual Studio
Xamarin 16.0.0.515 (d16-0@a3502d929)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 4.17.4.418 (remotes/origin/d16-0@3d086e814)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin Templates 16.1.47 (31f664d)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
Xamarin.Android SDK 9.2.0.5 (HEAD/292d27fa)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: mono/mono/2018-08-rc@5ad371dab1b
Java.Interop: xamarin/java.interop/d16-0@c987483
LibZipSharp: grendello/LibZipSharp/master@44de300
LibZip: nih-at/libzip/rel-1-5-1@b95cf3f
MXE: xamarin/mxe/xamarin@b9cbb535
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.26.0@325e91a
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-0@0a7edd6
Xamarin.iOS and Xamarin.Mac SDK 12.8.0.0 (0aa8452)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
In my VS 2019 setup, I'm getting a build error when trying to use the nuget package. Below are repro steps for the build error:
COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
I was able to resolve the com.android.dx.cf.code.SimException
error in VS 2019 and VS for Mac 8 by adding <AndroidDexTool>d8</AndroidDexTool>
to my Android csproj file. After resolving the build issue, my Xamarin.Forms test app did certificate pinning as expected.
I'm not sure why I was running into so many issues with VS 2017 and VS for Mac 7.
When running the test runner for Android, I get the following error for the Certificate pinning tests:
Exception: System.NotImplementedException The method or operation is not implemented.
Stacktrace:
Screenshot:
Should this be working?