Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TLS 1.0 vs 1.2 error (Am I missing something?) #567

Closed
C0D3On3 opened this issue Aug 21, 2016 · 24 comments
Closed

TLS 1.0 vs 1.2 error (Am I missing something?) #567

C0D3On3 opened this issue Aug 21, 2016 · 24 comments

Comments

@C0D3On3
Copy link

C0D3On3 commented Aug 21, 2016

Jayme,

How are you? I have to start off by giving you props. Great library man! Saved me tons of time. Thank you! :)

I've searched your tickets and saw that the TLS 1.0 vs 1.2 has been resolved but I'm still getting the error for some reason. Below are the versions of everything I'm running. Could there be something else or a critical step I'm missing? Appreciate your time and sorry about bring this up once again.

Code:

`var token = await StripeClient.CreateToken(c, Stripe.StripeClient.DefaultPublishableKey);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var myCharge = new StripeChargeCreateOptions();
var session = Element.session;

myCharge.Amount = 6000;
myCharge.Currency = "usd";
myCharge.Description = "Services for guest";
myCharge.SourceTokenOrExistingSourceId = token.Id;
myCharge.Capture = true;

var chargeService = new StripeChargeService();
StripeCharge stripeCharge = chargeService.Create(myCharge);`

Versions:

.NET Framework 4.6.01038
Stripe.NET v6.4.0
Xamarin Forms v2.3.1.114

Error:

error

@jaymedavis
Copy link
Contributor

The service point manager stuff is already set if you are using the 4.5 version and not the PCL - it's probably your server. I'd search for setting your server up to use TLS1.2 - your findings and results are very welcome here for others to find!

@jaymedavis
Copy link
Contributor

And thanks much for the kind words :)

@C0D3On3
Copy link
Author

C0D3On3 commented Aug 21, 2016

You're most certainly welcome and thanks for the quick reply!

My confusion may very well lay in your response. What do you mean by server? The code referenced is in my Xamarin app itself. The only server involved at this point is Stripe's processing the data. I literally did nothing but install the Nugent in my Xamarin.Android project and call the code. Maybe that means Xamarin handles those calls natively with TLS1.0 regardless of the versions I'm using? Any guidance would be appreciated.

@jaymedavis
Copy link
Contributor

jaymedavis commented Aug 21, 2016

OH, Xamarin ... about that.... read the bottom here[1], where I start talking about Xamarin. Basically, Mono's implementation only supports 1.0 right now. You can read me whining about it to them here[2]. Long story short - nothing can be done right now. I hope to have a better solution soon, as all the PCL users will hit the same wall.

  1. https://github.com/jaymedavis/stripe.net/issues/544
  2. Project State / Clarification mono/mono-tls#2

@C0D3On3
Copy link
Author

C0D3On3 commented Aug 21, 2016

I'm with you now. Thanks for clarifying that. I'll see what I can come up with. If I do come up with an alternate solution, I'll be sure to reference it here.

@ExperimentsAndIdeas
Copy link

Just wanted to add this documentation link - Xamarins compiler has options on which implementation of TLS it uses (and subsequently, which TLS version it uses)

https://developer.xamarin.com/guides/cross-platform/transport-layer-security/

@C0D3On3
Copy link
Author

C0D3On3 commented Aug 25, 2016

Thank you @makerofthings7. I'll work on it this weekend and try the environment route. Will let you guys know the results!

@C0D3On3
Copy link
Author

C0D3On3 commented Aug 26, 2016

@jaymedavis and @makerofthings7, it was a heavy weight fight but I got it to work! Here's my findings. Hope this helps.

Notes:
Xamarin's suggested solution of using Xamarin.Android.Net.AndroidClientHandler doesn't work for this instance. It kept failing with an "unexpected end of stream" error. Researching that, I found ModernHttpClient was indeed the solution. Unfortunately, this means I didn't use the Stripe.net library but Jayme, this may help implement a solution for Xamarin. Here's how I implemented it:

  1. Add ModernHttpClient nugent package
  2. See code below for rest. The important stuff is in bold.

using ModernHttpClient;

var token = await StripeClient.CreateToken(cardHere, "pk_test_yourHaShHerE"); //public key

var client = new HttpClient(new NativeMessageHandler());
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "sk_test_yourHaShHere"); //secret key, don't store here
client.BaseAddress = new Uri("https://api.stripe.com/v1/");

var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("amount", "7899"),
new KeyValuePair<string, string>("currency", "usd"),
new KeyValuePair<string, string>("source", token.Id),
new KeyValuePair<string, string>("description", "Some elaborate Description"),
});

HttpResponseMessage response = await client.PostAsync("charges", formContent);

@jaymedavis
Copy link
Contributor

Thanks for the research @rastapapolis, and thanks @makerofthings7 for the links. I did have ModernHttpHandler in Stripe.net for a long time, until users started contacting me about it not working. I have not checked out how @paulcbetts implemented his handlers, but if mono-tls doesn't come up with a solution sometime soon, I might take his advice and offer an injection point (probably StripeConfiguration.HttpHandler) for users. I am just hesitant about this because I would prefer the library keep with no configuration. This could just be my misunderstanding on how this works. I would love for ModernHttpClient to just work with all implementations so it is just the handler again in Stripe.net. It would help to find the original issue where the user had to have ModernHttpClient removed. If we could fix that, we could submit a PR to Paul to fix this - then viola, no configuration. It's the easiest library in the world to use, so it would be great if it just worked everywhere. :)

@jaymedavis
Copy link
Contributor

Im also surprised Xamarin's documentation sent you down a path for something that didn't work. In the meantime @rastapapolis, you should be able to tell Stripe to turn this off for you and point them to this issue. It's certainly not your fault this problem isn't solved. Let me know if you would like to try this, I might be able to help.

@jaymedavis jaymedavis reopened this Aug 28, 2016
@C0D3On3
Copy link
Author

C0D3On3 commented Aug 28, 2016

I agree with your assessment @jaymedavis. Please let me know if you go back down the Modern route as your library will save me work moving forward when I need to use other stripe features. I'd be interested to know which use case didn't work with modern. I've had no problems since using it. I've never submitted to Xamarin. Can you point me to a link so I can tell them about it? Thx!

@ExperimentsAndIdeas
Copy link

Send me a concise write up and lmk your email address. I have enterprise licensing so I can email the developers vs stack overflow 

On Sun, Aug 28, 2016 at 4:09 PM -0400, "rastapapolis" notifications@github.com wrote:

I agree with your assessment @jaymedavis. Please let me know if you go back down the Modern route as your library will save me work moving forward when I need to use other stripe features. I'd be interested to know which use case didn't work with modern. I've had no problems since using it. I've never submitted to Xamarin. Can you point me to a link so I can tell them about it? Thx!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@C0D3On3
Copy link
Author

C0D3On3 commented Aug 29, 2016

@makerofthings7 Here's the details:

Platforms/Versions:

Microsoft Visual Studio v. 14.0.25123.00 Update 2
Microsoft .NET Framework v. 4.6.01038
Xamarin.Android 6.1.1

What I did:

Created EnvironmentVariables.txt file and made sure the BuildAction is AndroidEnvironment. The entry in that file is: XA_HTTP_CLIENT_HANDLER_TYPE=Xamarin.Android.Net.AndroidClientHandler

Tried using Stripe.net plug-in and also HttpClient constructing it as: new HttpClient(). I also tried constructing it like: new HttpClient(new Xamarin.Android.Net.AndroidClientHandler())

Here's the Visual Studio Output:

08-29 03:35:19.073 D/Mono ( 2960): Assembly Ref addref myPT.Droid[0xad97ad80] -> System.Net.Http[0x9c567360]: 3
08-29 03:35:19.074 D/Mono ( 2960): Assembly Ref addref System.Net.Http[0x9c567360] -> System[0xad97c520]: 10
08-29 03:35:19.115 D/Mono ( 2960): Assembly Ref addref Stripe[0xad97b620] -> System.Net.Http[0x9c567360]: 4
08-29 03:35:19.138 D/Mono ( 2960): Assembly Ref addref Mono.Android[0xad97c400] -> System.Net.Http[0x9c567360]: 5
08-29 03:35:19.139 D/Mono ( 2960): Assembly Ref addref Mono.Android[0xad97c400] -> System[0xad97c520]: 11
08-29 03:35:19.145 D/Mono ( 2960): Image addref System.Json[0x99293820] -> System.Json.dll[0x99ac6400]: 1
08-29 03:35:19.146 D/Mono ( 2960): Assembly System.Json[0x99293820] added to domain RootDomain, ref_count=1
08-29 03:35:19.147 D/Mono ( 2960): AOT module 'System.Json.dll.so' not found: dlopen failed: library "/data/app/myPT.Droid-1/lib/x86/libaot-System.Json.dll.so" not found
08-29 03:35:19.147 D/Mono ( 2960): AOT module '/Users/builder/data/lanes/3415/7db2aac3/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/System.Json.dll.so' not found: dlopen failed: library "/data/app/myPT.Droid-1/lib/x86/libaot-System.Json.dll.so" not found
08-29 03:35:19.147 D/Mono ( 2960): Config attempting to parse: 'System.Json.dll.config'.
08-29 03:35:19.147 D/Mono ( 2960): Config attempting to parse: '/Users/builder/data/lanes/3415/7db2aac3/source/monodroid/builds/install/mono-x86/etc/mono/assemblies/System.Json/System.Json.config'.
08-29 03:35:19.148 D/Mono ( 2960): Assembly Ref addref Stripe[0xad97b620] -> System.Json[0x99293820]: 2
08-29 03:35:19.148 D/Mono ( 2960): Assembly Ref addref System.Json[0x99293820] -> mscorlib[0xad97ad20]: 39
08-29 03:35:19.148 D/Mono ( 2960): Assembly Ref addref System.Json[0x99293820] -> System[0xad97c520]: 12
Loaded assembly: System.Json.dll [External]
Thread started: #7
Thread started: #8
08-29 03:35:19.414 D/Mono ( 2960): [0x98cff930] worker starting
08-29 03:35:19.422 I/art ( 2960): Starting a blocking GC Explicit
08-29 03:35:19.435 I/art ( 2960): Explicit concurrent mark sweep GC freed 7216(326KB) AllocSpace objects, 0(0B) LOS objects, 17% free, 18MB/22MB, paused 388us total 10.719ms
08-29 03:35:19.436 D/Mono ( 2960): GC_OLD_BRIDGE num-objects 85 num_hash_entries 85 sccs size 85 init 0.00ms df1 0.04ms sort 0.03ms dfs2 0.16ms setup-cb 0.02ms free-data 0.02ms links 0/0/0/0 dfs passes 170/85
08-29 03:35:19.436 D/Mono ( 2960): GC_MINOR: (Nursery full) pause 1.79ms, total 2.14ms, bridge 0.01ms promoted 64K major 2336K los 104K
08-29 03:35:20.115 D/Mono ( 2960): [0x98cff930] hill climbing, change max number of threads 3
08-29 03:35:20.258 W/EGL_emulation( 2960): eglSurfaceAttrib not implemented
08-29 03:35:20.258 W/OpenGLRenderer( 2960): Failed to set EGL_SWAP_BEHAVIOR on surface 0x98d84ce0, error=EGL_SUCCESS
08-29 03:35:20.326 V/RenderScript( 2960): 0x98d3e000 Launching thread(s), CPUs 2
08-29 03:35:22.180 E/Surface ( 2960): getSlotFromBufferLocked: unknown buffer: 0x98ec5950
08-29 03:35:31.432 D/Mono ( 2960): [0x9c27f930] worker finishing
Thread finished: #4
The thread 'Unknown' (0x4) has exited with code 0 (0x0).
Thread finished: #2
The thread 'Unknown' (0x2) has exited with code 0 (0x0).
08-29 03:36:04.891 D/Mono ( 2960): [0x98cff930] worker finishing
Thread finished: #8
The thread 'Unknown' (0x8) has exited with code 0 (0x0).

Stacktrace:

{Java.Net.ProtocolException: unexpected end of stream
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at Java.Interop.JniEnvironment+InstanceMethods.CallIntMethod (JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00085] in /Users/builder/data/lanes/3415/7db2aac3/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11484
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualInt32Method (System.String encodedMember, IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00031] in /Users/builder/data/lanes/3415/7db2aac3/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:206
at Java.Net.HttpURLConnection.get_ResponseCode () [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Java.Net.HttpURLConnection.cs:505
at Xamarin.Android.Net.AndroidClientHandler.DoProcessRequest (System.Net.Http.HttpRequestMessage request, Java.Net.HttpURLConnection httpConnection, CancellationToken cancellationToken) [0x000a0] in /Users/builder/data/lanes/3415/7db2aac3/source/monodroid/src/Mono.Android/src/Xamarin.Android.Net/AndroidClientHandler.cs:228
at Xamarin.Android.Net.AndroidClientHandler+c__async1+c__AnonStorey2.<>m__0 () [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/monodroid/src/Mono.Android/src/Xamarin.Android.Net/AndroidClientHandler.cs:207
at System.Threading.Tasks.Task1[TResult].InnerInvoke () [0x00012] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Future.cs:680 at System.Threading.Tasks.Task.Execute () [0x00016] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:2502 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535
at Xamarin.Android.Net.AndroidClientHandler+c__async1.MoveNext () [0x000b3] in /Users/builder/data/lanes/3415/7db2aac3/source/monodroid/src/Mono.Android/src/Xamarin.Android.Net/AndroidClientHandler.cs:207
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357 at Xamarin.Android.Net.AndroidClientHandler+<SendAsync>c__async0.MoveNext () [0x000c4] in /Users/builder/data/lanes/3415/7db2aac3/source/monodroid/src/Mono.Android/src/Xamarin.Android.Net/AndroidClientHandler.cs:195 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535
at System.Net.Http.HttpClient+c__async0.MoveNext () [0x000a9] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:276
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357 at Stripe.StripeClient+<requestToken>c__async2.MoveNext () [0x00085] in <filename unknown>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
at Stripe.StripeClient+c__async0.MoveNext () [0x001c4] in :0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
at myPT.Droid.Renderers.PaymentRenderer+d__5.MoveNext () [0x00269] in C:\Users\Ryan J\Documents\Visual Studio 2015\Projects\myPT\myPT\myPT.Droid\Renderers\PaymentRenderer.cs:77
--- End of managed exception stack trace ---
java.net.ProtocolException: unexpected end of stream
at com.android.okhttp.internal.http.HttpConnection$FixedLengthSink.close(HttpConnection.java:314)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:781)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:439)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:384)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java)
}

Screenshot:

end of stream error

@jaymedavis
Copy link
Contributor

Nice write-up @rastapapolis. If you have their ear, @makerofthings7, I would love to know what the status of mono-tls[1] is. This would solve our problems.

  1. Project State / Clarification mono/mono-tls#2

@C0D3On3
Copy link
Author

C0D3On3 commented Aug 29, 2016

You got it @jaymedavis !

@duckwaffle
Copy link
Contributor

Hey guys, just wanted to throw in that I've also run into this exact problem as well re: TLS issuse on Android.

Just like @rastapapolis I attempted to solve the issue by including the Environment variable of XA_HTTP_CLIENT_HANDLER_TYPE=Xamarin.Android.Net.AndroidClientHandler with no dice.

What I ended up doing was modifying the Requestor class to accept an injected HttpMessageHandler so that I could get Stripe to accept my requests.

Like you said @jaymedavis it would be preferable to not have to do any configuration, but if you want I can open a PR for what I've done with injecting the HttpMessageHandler.

@C0D3On3
Copy link
Author

C0D3On3 commented Aug 30, 2016

Thx for the info @duckwaffle! As a result of your solution, were you able to use the stripe.net library? If so, can you post some code so I can try it plz? Unfortunately as part of my solution, I'm not using the library but I'd love to.

@duckwaffle
Copy link
Contributor

duckwaffle commented Aug 30, 2016

No worries @rastapapolis . If you want to have a look at what I did to modify the Stripe.net library, you can check out duckwaffle@286d1bf .

Using those modifications, you can put the following code anywhere in your application before calling Stripe services (probably in MainActivity.OnCreated or something like that):

// Enable Tls1.2 for Stripe calls
// This value is used to pass down the Android HttpMessageHandler to enable Tls1.2 on Android devices
StripeConfiguration.SetHttpMessageHandler(new AndroidClientHandler());

@C0D3On3
Copy link
Author

C0D3On3 commented Aug 30, 2016

Nice! Thanks for sharing @duckwaffle. Did you create a package or just include the source for the library within your workspace? I like that solution but I see the configuration concerns you and @jaymedavis have now. Here's a thought. Would it be possible to tell at compile time whether it's Android and just set the handler? That would take care of the config issue.

@ExperimentsAndIdeas
Copy link

Hope you don't mind me doing much more than acting as a passive middleman, but this is Xamarin's response (2 parts). Feel free to take this offline if you want at my name at Gmail, and I can loop you into the reply

Hey,

Ah okay. Well TLS 1.2 is in a transition period right now. As you have stated, HTTPClient based calls are compatible with TLS 1.2 via the native handler. However, there are some caveats to this configuration. We are working on adding full TLS 1.2 support, however that is still being planned. To fully understand the situation and hopefully get a solution, I need to know where you are with the steps you have taken. It seems that the Stripe.net does not allow you to pass in an HTTPClient, and it will use the default with no overloads (https://github.com/jaymedavis/stripe.net/blob/6ae20e088d5ca2d74776f092b29438dd4bbe8620/src/Stripe/Infrastructure/Requestor.cs#L18).

Are you using the binary distribution of Stripe.net, or are you adding the source to the project and building from there?

If you are using the NuGet package, then adding the environment variable will not, in my understanding, change much. However, if you are building Stripe.net with your project, then the changes should take effect and the native handler should be being used. Based upon the native stacktrace:

at com.android.okhttp.internal.http.HttpConnection$FixedLengthSink.close(HttpConnection.java:314)

It seems you are calling the native handler.

With all of this in mind, it seems that there is some bug between the native handler, and Stripe.net. Are you able to provide a test project to debug with? I can work on creating one as well, but as of right now I do not have a Stripe account to test with :)

Thanks!

------ Previous message ----

Hope you are well! Just to get a better understanding of what is happening, and what the desires are. You are attempting to use the Stripe.Net binding on an Android project. Stripe is about to disable TLS 1.0, so you are attempting to use the native handler in HTTPClient on Android. It is at this point that you get the above error.

Is that all correct?

@C0D3On3
Copy link
Author

C0D3On3 commented Aug 30, 2016

@makerofthings7, thank you and I absolutely don't mind you being a passive middleman. It's definitely a Xamarin bug as I get the same error without using the stripe.net package. I think the issue may be in their statement, "We are working on adding full TLS 1.2 support, however that is still being planned." My guess is, what we're hitting is a direct result of it not being full featured TLS 1.2. Please point them to this post if possible.

As for a test project they can debug, they can literally take the snippet of code below verbatim, create a stripe account so they can replace the "test" keys and try it. They'll get the error and as you can see, stripe.net isn't implemented as part of the solution. Replacing Xamarin.Android.Net.AndroidClientHandler() with NativeMessageHandler() which is provided by "using ModernHttpClient" does work however. So there's something going on with their handler.

var token = await StripeClient.CreateToken(cardHere, "pk_test_yourHaShHerE"); //public key

var client = new HttpClient(new Xamarin.Android.Net.AndroidClientHandler())
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "sk_test_yourHaShHere"); //secret key, don't store here
client.BaseAddress = new Uri("https://api.stripe.com/v1/");

var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair("amount", "7899"),
new KeyValuePair("currency", "usd"),
new KeyValuePair("source", token.Id),
new KeyValuePair("description", "Some elaborate Description"),
});

HttpResponseMessage response = await client.PostAsync("charges", formContent);

@jaymedavis
Copy link
Contributor

Thanks @makerofthings7 for getting this information. It sounds like for now, the best bet is just to let users pass in their own handler. I will add this before the next release. I viewed your code @duckwaffle - it's easy enough to add in - thanks.

I don't think this is ideal at all, but I don't really see another way around it.

@kpronz
Copy link

kpronz commented May 18, 2017

For the Xamarin stuff, it seems that the Stripe documentation recommends that we don't make actual charges from the Android/iOS code as that requires that we put our private key in the deployed (to iOS and Android) code. However, the first code sample in this thread seems to go against that thinking, and I'm assuming somewhere in that code the developer had to have their private Stripe key in the Android/iOS code.. So, am I missing something there, or are people putting their private Stripe key directly in the Android/iOS Xamarin code?

@C0D3On3
Copy link
Author

C0D3On3 commented May 18, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants