OFTP Code Example: Secure authentication

Both the OFTPClient and OFTPServer components support secure authentication. To support secure authentication both your certificate with private key and your partner's public certificate must be specified. Please see the examples below for more details.

OFTPClient
To perform secure authentication when connecting specify the your private key and the server's public certificate and set SecureAuthentication to true. client.ClientSSIDCode = "CLIENT_ID"; client.ClientSFIDCode = "CLIENT_ID"; client.ClientPassword = "CLIENT"; client.ServerSSIDCode = "SERVER_ID"; client.ServerSFIDCode = "SERVER_ID"; client.ServerPassword = "SERVER"; client.RemoteHost = "oftpserver.com"; client.RemotePort = 3305; client.Version = OftpclientVersions.oftpVer20; client.Certificate = new Certificate(); client.Certificate.StoreType = CertStoreTypes.cstPFXFile; client.Certificate.Store = "C:\\client.pfx"; client.Certificate.StorePassword = "test"; client.Certificate.Subject = "*"; client.RecipientCert = new Certificate(); client.RecipientCert.StoreType = CertStoreTypes.cstPublicKeyFile; client.RecipientCert.Store = "C:\\server.cer"; client.RecipientCert.Subject = "*"; client.SecureAuthentication = true; client.Logon();

OFTPServer
In OFTPServer the client's public certificate must be specified on a per connection basis. This can be done inside the AcceptConnection event so that secure authentication can proceed. server.ServerSSIDCode = "SERVER_ID"; server.ServerSFIDCode = "SERVER_ID"; server.ServerPassword = "SERVER"; server.Certificate = new Certificate(); server.Certificate.StoreType = CertStoreTypes.cstPFXFile; server.Certificate.Store = "C:\\server.pfx"; server.Certificate.StorePassword = "test"; server.Certificate.Subject = "*"; server.OnAcceptConnection +=new Oftpserver.OnAcceptConnectionHandler(delegate(object sender, OftpserverAcceptConnectionEventArgs e){ OFTPConnection conn = server.Connections[e.ConnectionId]; conn.RecipientCertStoreType = CertStoreTypes.cstPublicKeyFile; conn.RecipientCertStore = "C:\\client.cer"; conn.RecipientCertSubject = "*"; }); server.Listening = true;

We appreciate your feedback.  If you have any questions, comments, or suggestions about this article please contact our support team at kb@nsoftware.com.