c# - .NET Mutual SSL handshake 'Client Authentication' -
i working on problem last couple of days , not able anywhere.
the scenario ios app in field call rest service (.net). rest service call apache web service using mutual ssl handshake. whatever data receive have pass data ios devices in field.
the issue 2nd part of communication between rest service , apache web service.
client certificates has been signed using key usages of client authentication, digital certificate, key encipherment. root singers of certificate has been placed on apache server. if try using web browser can perform handshake without issues.
sample code using perform authentication using sslstream. using method error stating "the message received unexpected or badly formatted" , guys manage apache web server says can see request coming in according them not receiving , certificate this.
var certificate = @“certificate.cer”; var hostaddress = “hostaddress"; var certificates = new x509certificate2collection(new x509certificate2(certificate)); runclient(hostaddress, 1316, certificates); static void runclient(string hostname, int port, x509certificate2collection certificates) { tcpclient client = new tcpclient(hostname, port); sslstream sslstream = new sslstream(client.getstream(), false, validateservercertificate); try { sslstream.authenticateasclient(hostname, certificates, sslprotocols.ssl3, true); write("authenticated."); } catch (authenticationexception ex) { write("inner: " + ex.innerexception.message); } catch (exception ex) { write(ex.message); } } sample code using perform authentication using httpwebrequest. using method gives me following issue "the request aborted: not create ssl/tls secure channel."
var certificate = @“certificate.cer”; var hostaddress = “hostaddress"; var certificates = new x509certificate2collection(new x509certificate2(certificate)); public static t post(string url, string body, x509certificate2 cert) { var webrequest = fbjsonrequestservice.createrequest(url, cert, webrequestmethods.http.post, body); using (var webresponse = webrequest.getresponse()) { return createresponse(webresponse); } } var webrequest = (httpwebrequest) webrequest.create(url); webrequest.clientcertificates.add(cert); //webrequest.authenticationlevel = authenticationlevel.mutualauthrequested; webrequest.credentials = credentialcache.defaultnetworkcredentials; webrequest.method = method; webrequest.contenttype = "application/json; charset=utf-8"; if (body != null) { using (var streamwriter = new streamwriter(webrequest.getrequeststream())) { streamwriter.write(body); } } return webrequest; hope makes sense want know if whatever doing right or doing wrong.
i think content of file certificate.cer incorrect. extension .cer in opinion contains certificate not private key.
you have use certificate.p12 or certificate.pfx contains private key. these extensions represent pkcs#12 standard. there can whole certificate chain included in these files.
you can load p12 file using different constructor of x509certificate2 class. please @ this documentation.
Comments
Post a Comment