ssl - Https with TLS 1.2 in Xamarin -
i'm using httpclient in xamarin request https tls 1.2 , got error below;
system.aggregateexception: 1 or more errors occurred ---> system.net.webexception: error writing headers ---> system.io.ioexception: authentication or decryption has failed. ---> mono.security.protocol.tls.tlsexception: authentication or decryption has failed. @ mono.security.protocol.tls.recordprotocol.processalert (alertlevel alertlevel, alertdescription alertdesc) [0x00013] in ///library/frameworks/xamarin.ios.framework/versions/8.9.1.3/src/mono/mcs/class/mono.security/mono.security.protocol.tls/recordprotocol.cs:574 @ mono.security.protocol.tls.recordprotocol.internalreceiverecordcallback (iasyncresult asyncresult) [0x000d0] in ///library/frameworks/xamarin.ios.framework/versions/8.9.1.3/src/mono/mcs/class/mono.security/mono.security.protocol.tls/recordprotocol.cs:376 --- end of inner exception stack trace --- @ mono.security.protocol.tls.sslclientstream.endnegotiatehandshake (iasyncresult result) [0x00035] in ///library/frameworks/xamarin.ios.framework/versions/8.9.1.3/src/mono/mcs/class/mono.security/mono.security.protocol.tls/sslclientstream.cs:425 @ mono.security.protocol.tls.sslstreambase.asynchandshakecallback (iasyncresult asyncresult) [0x0000c] in ///library/frameworks/xamarin.ios.framework/versions/8.9.1.3/src/mono/mcs/class/mono.security/mono.security.protocol.tls/sslstreambase.cs:99 --- end of inner exception stack trace --- @ system.net.httpwebrequest.endgetresponse (iasyncresult asyncresult) [0x0005e] in ///library/frameworks/xamarin.ios.framework/versions/8.9.1.3/src/mono/mcs/class/system/system.net/httpwebrequest.cs:969 @ system.threading.tasks.taskfactory`1[system.net.webresponse].innerinvoke (system.threading.tasks.taskcompletionsource`1 tcs, system.func`2 endmethod, iasyncresult l) [0x00000] in /developer/monotouch/source/mono/mcs/class/corlib/system.threading.tasks/taskfactory_t.cs:473 --- end of stack trace previous location exception thrown --- @ system.runtime.exceptionservices.exceptiondispatchinfo.throw () [0x0000b] in /developer/monotouch/source/mono/mcs/class/corlib/system.runtime.exceptionservices/exceptiondispatchinfo.cs:62 @ system.runtime.compilerservices.configuredtaskawaitable`1+configuredtaskawaiter[system.net.webresponse].getresult () [0x00034] in /developer/monotouch/source/mono/mcs/class/corlib/system.runtime.compilerservices/configuredtaskawaitable_t.cs:62 @ system.net.http.httpclienthandler+<sendasync>c__async0.movenext () [0x002d0] in /developer/monotouch/source/mono/mcs/class/system.net.http/system.net.http/httpclienthandler.cs:338 --- end of stack trace previous location exception thrown --- @ system.runtime.exceptionservices.exceptiondispatchinfo.throw () [0x0000b] in /developer/monotouch/source/mono/mcs/class/corlib/system.runtime.exceptionservices/exceptiondispatchinfo.cs:62 @ system.runtime.compilerservices.configuredtaskawaitable`1+configuredtaskawaiter[system.net.http.httpresponsemessage].getresult () [0x00034] in /developer/monotouch/source/mono/mcs/class/corlib/system.runtime.compilerservices/configuredtaskawaitable_t.cs:62 @ system.net.http.httpclient+<sendasyncworker>c__async0.movenext () [0x000a9] in /developer/monotouch/source/mono/mcs/class/system.net.http/system.net.http/httpclient.cs:273 --- end of inner exception stack trace --- @ system.threading.tasks.task.wait (int32 millisecondstimeout, cancellationtoken cancellationtoken) [0x00049] in /developer/monotouch/source/mono/mcs/class/corlib/system.threading.tasks/task.cs:709 @ system.threading.tasks.task.wait () [0x00000] in /developer/monotouch/source/mono/mcs/class/corlib/system.threading.tasks/task.cs:679 @ system.threading.tasks.task`1[system.net.http.httpresponsemessage].get_result () [0x0000b] in /developer/monotouch/source/mono/mcs/class/corlib/system.threading.tasks/task_t.cs:48 @ cucumber.viewmodels.loginviewmodel+<executelogincommand>c__async0.movenext () [0x00144] in /users/bachpx1/fsbprojects/fsoftinternalnews/cucumber/xamarin_form/cucumber/cucumber.shared/viewmodels/loginviewmodel.cs:94 --> (inner exception 0) system.net.webexception: error writing headers ---> system.io.ioexception: authentication or decryption has failed. ---> mono.security.protocol.tls.tlsexception: authentication or decryption has failed. @ mono.security.protocol.tls.recordprotocol.processalert (alertlevel alertlevel, alertdescription alertdesc) [0x00013] in ///library/frameworks/xamarin.ios.framework/versions/8.9.1.3/src/mono/mcs/class/mono.security/mono.security.protocol.tls/recordprotocol.cs:574 @ mono.security.protocol.tls.recordprotocol.internalreceiverecordcallback (iasyncresult asyncresult) [0x000d0] in ///library/frameworks/xamarin.ios.framework/versions/8.9.1.3/src/mono/mcs/class/mono.security/mono.security.protocol.tls/recordprotocol.cs:376 --- end of inner exception stack trace --- @ mono.security.protocol.tls.sslclientstream.endnegotiatehandshake (iasyncresult result) [0x00035] in ///library/frameworks/xamarin.ios.framework/versions/8.9.1.3/src/mono/mcs/class/mono.security/mono.security.protocol.tls/sslclientstream.cs:425 @ mono.security.protocol.tls.sslstreambase.asynchandshakecallback (iasyncresult asyncresult) [0x0000c] in ///library/frameworks/xamarin.ios.framework/versions/8.9.1.3/src/mono/mcs/class/mono.security/mono.security.protocol.tls/sslstreambase.cs:99 --- end of inner exception stack trace --- @ system.net.httpwebrequest.endgetresponse (iasyncresult asyncresult) [0x0005e] in ///library/frameworks/xamarin.ios.framework/versions/8.9.1.3/src/mono/mcs/class/system/system.net/httpwebrequest.cs:969 @ system.threading.tasks.taskfactory`1[system.net.webresponse].innerinvoke (system.threading.tasks.taskcompletionsource`1 tcs, system.func`2 endmethod, iasyncresult l) [0x00000] in /developer/monotouch/source/mono/mcs/class/corlib/system.threading.tasks/taskfactory_t.cs:473 --- end of stack trace previous location exception thrown --- @ system.runtime.exceptionservices.exceptiondispatchinfo.throw () [0x0000b] in /developer/monotouch/source/mono/mcs/class/corlib/system.runtime.exceptionservices/exceptiondispatchinfo.cs:62 @ system.runtime.compilerservices.configuredtaskawaitable`1+configuredtaskawaiter[system.net.webresponse].getresult () [0x00034] in /developer/monotouch/source/mono/mcs/class/corlib/system.runtime.compilerservices/configuredtaskawaitable_t.cs:62 @ system.net.http.httpclienthandler+<sendasync>c__async0.movenext () [0x002d0] in /developer/monotouch/source/mono/mcs/class/system.net.http/system.net.http/httpclienthandler.cs:338 --- end of stack trace previous location exception thrown --- @ system.runtime.exceptionservices.exceptiondispatchinfo.throw () [0x0000b] in /developer/monotouch/source/mono/mcs/class/corlib/system.runtime.exceptionservices/exceptiondispatchinfo.cs:62 @ system.runtime.compilerservices.configuredtaskawaitable`1+configuredtaskawaiter[system.net.http.httpresponsemessage].getresult () [0x00034] in /developer/monotouch/source/mono/mcs/class/corlib/system.runtime.compilerservices/configuredtaskawaitable_t.cs:62 @ system.net.http.httpclient+<sendasyncworker>c__async0.movenext () [0x000a9] in /developer/monotouch/source/mono/mcs/class/system.net.http/system.net.http/httpclient.cs:273
do know how fix issue. have heard xamarin errors tls in mono 2.0. many thanks
tls not yet implemented in mono. means https requests may fail not when running .net app on windows.
xamarin deployment
since using xamarin, can use modernhttpclient wrapper around native ios / android networking libraries.
android, mac , ios users can latest tls http workloads using modernhttpclient. mac/ios users can use built-in cfnetworkhandler well.
linux/mac deployment
if deploying mono on linux/mac (without xamarin), you'll need find workaround lack of tls support.
there 2 possible workarounds come mind:
use custom tls implementation
try using juhovh/aaltotls, implementation of ssl/tls network protocol written using c# , standard cryptographic libraries of .net relevant. take care of tls decryption/encryption , won't use built-in lacking mono implementation.
implement tls proxy
build tls proxy tls heavy-lifting -- you'll configure http proxy http requests in mono, receive them, , query target server via https, handling encryption , decryption mono app.
workflow:
mono app -> httpclient sends http request via tls proxy -> tls proxy converts http request https , sends target server -> tls proxy receives response -> tls proxy sends response httpclient in http format
example code in node.js tls proxy workaround using nodejitsu/node-http-proxy:
// modules var http = require('http'); var httpproxy = require('http-proxy'); // proxy server options var options = {secure: true}; // validate remote ssl certificates // create proxy server custom application logic var proxy = httpproxy.createproxyserver(options); // handle errors gracefully proxy.on('error', function(e) { // log console console.log(e); }); // create server , define custom logic var server = http.createserver(function(req, res) { // url provided? if (req.url) { // convert https req.url = req.url.replace('http://', 'https://'); } // remote host headers (and force https) var target = 'https://' + req.headers.host; // proxy request (target server pass request on to) proxy.web(req, res, { target: target }); }); // proxy port var port = 8080; // start listening requests clients server.listen(port); // log port number console.log('proxy.port: ' + port);