ssl - Client Certificate Authentication with Xamarin iOS -


i've managed use client certificates .net httpwebrequest class i'm trying update modernhttpclient support client certificates it's using more efficient ios libraries requests.

i've modified didreceivechallenge function in nsurlsessionhandler check clientcertificate challenges , attempted follow through information on https://developer.apple.com/library/ios/documentation/cocoa/conceptual/urlloadingsystem/articles/authenticationchallenges.html , convert work xamarin ios. code compiles correctly , stepping through causes no errors printed out still system.net.webexception thrown message 'the server "xxx.example.com" requires client certificate'.

my code below...

public override void didreceivechallenge(nsurlsession session, nsurlsessiontask task, nsurlauthenticationchallenge challenge, action<nsurlsessionauthchallengedisposition, nsurlcredential> completionhandler) {     ...snip...       if (challenge.protectionspace.authenticationmethod == nsurlprotectionspace.authenticationmethodclientcertificate)     {         console.writeline("client cert!");          var password = "xxxxx";         var options = nsdictionary.fromobjectandkey(nsobject.fromobject(password), secimportexport.passphrase);          var path = path.combine(nsbundle.mainbundle.bundlepath, "content", "client.p12");         var certdata = file.readallbytes(path);          nsdictionary[] importresult;          x509certificate cert = new x509certificate(certdata, password);          secstatuscode statuscode = secimportexport.importpkcs12(certdata, options, out importresult);         var identityhandle = importresult[0][secimportexport.identity];         var identity = new secidentity(identityhandle.classhandle);         var certificate = new seccertificate(cert.getrawcertdata());          seccertificate[] certificates = { certificate };         nsurlcredential credential = nsurlcredential.fromidentitycertificatespersistance(identity, certificates, nsurlcredentialpersistence.forsession);         completionhandler(nsurlsessionauthchallengedisposition.usecredential, credential);          return;     }      ...snip... } 

i've committed changes far github if want trial out (https://github.com/mrskensington/modernhttpclient). btw, test client certificate secured web server has absolutely nothing of value on (only 1 .txt file) , certificate , password unique web server, have no qualms sharing world.

thanks in advance help,

mrs kensington

shouldn't use handle instead of classhandle ?

var identity = new secidentity(identityhandle.handle); 

have made progress far? need similar code wkwebview app.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -