OpenSSL SSL Server
This sample demonstrates a SSL-encrypted server, using OpenSSL.
#include <iostream>
#include <RCF/RCF.hpp>
#include <RCF/PemCertificate.hpp>
#ifndef RCF_FEATURE_OPENSSL
#error Please define RCF_FEATURE_OPENSSL=1 to build this sample with OpenSSL support.
#endif
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V1(void, Print, const std::string &)
RCF_END(I_PrintService)
class PrintService
{
public:
void Print(const std::string & msg)
{
std::cout << "I_PrintService service: " << msg << std::endl;
}
};
int main()
{
try
{
PrintService printService;
server.
bind<I_PrintService>(printService);
"serverCert.pem",
"password"));
std::vector<RCF::TransportProtocol> supportedProtocols = {
RCF::Tp_Ssl };
std::cout << "Press Enter to exit..." << std::endl;
std::cin.get();
}
{
}
return 0;
}
OpenSSL SSL Client
This sample demonstrates a SSL-encrypted client, using OpenSSL.
#include <iostream>
#include <RCF/RCF.hpp>
#include <RCF/PemCertificate.hpp>
#ifndef RCF_FEATURE_OPENSSL
#error Please define RCF_FEATURE_OPENSSL=1 to build this sample with OpenSSL support.
#endif
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V1(void, Print, const std::string &)
RCF_END(I_PrintService)
bool validateServerCertificate(
RCF::Certificate * pCert)
{
if ( pX509Cert )
{
X509 * pX509 = pX509Cert->getX509();
std::cout << "Server certificate name: " << certName << std::endl;
std::cout << "Server certificate issuer: " << issuerName << std::endl;
}
return true;
}
int main()
{
try
{
client.getClientStub().setTransportProtocol(
RCF::Tp_Ssl);
bool useCertificateAuthority = false;
bool useCustomCallback = true;
if ( useCertificateAuthority )
{
"clientCaCertificate.pem",
"password"));
client.getClientStub().setCaCertificate(caCertPtr);
}
else if ( useCustomCallback )
{
client.getClientStub().setCertificateValidationCallback(&validateServerCertificate);
}
"clientCert.pem",
"password"));
client.getClientStub().setCertificate(clientCertPtr);
client.Print("Hello World");
}
{
}
return 0;
}
Schannel SSL Server
This sample demonstrates a SSL-encrypted server, using Schannel. This code will only run on Windows.
#include <iostream>
#include <RCF/RCF.hpp>
#include <RCF/Win32Certificate.hpp>
#ifndef RCF_WINDOWS
#error This sample requires Schannel and can only be built on Windows.
#endif
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V1(void, Print, const std::string &)
RCF_END(I_PrintService)
class PrintService
{
public:
void Print(const std::string & msg)
{
std::cout << "I_PrintService service: " << msg << std::endl;
}
};
int main()
{
try
{
PrintService printService;
server.
bind<I_PrintService>(printService);
bool loadCertFromFile = true;
bool loadCertFromStore = false;
if ( loadCertFromFile )
{
"serverCert.p12",
"password",
"CertificateName"));
}
else if ( loadCertFromStore )
{
"CertificateName"));
}
std::vector<RCF::TransportProtocol> supportedProtocols = {
RCF::Tp_Ssl };
std::cout << "Press Enter to exit..." << std::endl;
std::cin.get();
}
{
}
return 0;
}
Schannel SSL Client
This sample demonstrates a SSL-encrypted client, using Schannel. This code will only run on Windows.
#include <iostream>
#include <RCF/RCF.hpp>
#include <RCF/Win32Certificate.hpp>
#ifndef RCF_WINDOWS
#error This sample requires Schannel and can only be built on Windows.
#endif
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V1(void, Print, const std::string &)
RCF_END(I_PrintService)
#include <iostream>
#include <RCF/RCF.hpp>
{
if ( pWin32Cert )
{
PCCERT_CONTEXT pCertCtx = pWin32Cert->getWin32Context();
std::cout << "Server certificate name: " << certName << std::endl;
std::cout << "Server certificate issuer: " << issuerName << std::endl;
}
return true;
}
int main()
{
try
{
client.getClientStub().setTransportProtocol(
RCF::Tp_Ssl);
bool useCertificateAuthority = false;
bool useCustomCallback = true;
bool useSchannelValidation = false;
if ( useCertificateAuthority )
{
"C:\\clientCaCertificate.p12",
"password",
"CaCertificatename"));
client.getClientStub().setCaCertificate(caCertPtr);
}
else if ( useCustomCallback )
{
client.getClientStub().setCertificateValidationCallback(&validateServerCertificate);
}
else if ( useSchannelValidation )
{
client.getClientStub().setEnableSchannelCertificateValidation("CertificateName");
}
client.Print("Hello World");
}
{
}
return 0;
}
Kerberos and NTLM Server
This sample demonstrates a Kerberos and NTLM encrypted server. This code will only run on Windows.
#include <iostream>
#include <RCF/RCF.hpp>
#ifndef RCF_WINDOWS
#error This sample requires Kerberos and NTLM SSPI providers and can only be built on Windows.
#endif
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V1(void, Print, const std::string &)
RCF_END(I_PrintService)
class PrintService
{
public:
void Print(const std::string & msg)
{
std::cout << std::endl;
{
std::cout << "Client connection authenticated and encrypted using NTLM." << std::endl;
}
{
std::cout << "Client connection authenticated and encrypted using Kerberos." << std::endl;
}
{
std::cout << "Client connection authenticated and encrypted using Negotiate." << std::endl;
}
std::cout << "I_PrintService service: " << msg << std::endl;
}
};
int main()
{
try
{
PrintService printService;
server.
bind<I_PrintService>(printService);
std::cout << "Press Enter to exit..." << std::endl;
std::cin.get();
}
{
}
return 0;
}
Kerberos and NTLM Client
This sample demonstrates a Kerberos and NTLM encrypted client. This code will only run on Windows.
#include <iostream>
#include <RCF/RCF.hpp>
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V1(void, Print, const std::string &)
RCF_END(I_PrintService)
int main()
{
try
{
bool useExplicitCreds = false;
std::string explicitUserName = "Domain\\JoeBloggs";
std::string explicitPassword = "MyPassword";
if ( useExplicitCreds )
{
client.getClientStub().setUserName(explicitUserName);
client.getClientStub().setPassword(explicitPassword);
}
else
{
}
std::cout << "Connecting using NTLM." << std::endl;
client.Print("Hello World");
std::cout << "Connecting using Kerberos." << std::endl;
client.getClientStub().setKerberosSpn("Domain\\ServerAccount");
client.Print("Hello World");
std::cout << "Connecting using Negotiate." << std::endl;
client.getClientStub().setTransportProtocol(RCF::Tp_Negotiate);
client.getClientStub().setKerberosSpn("Domain\\ServerAccount");
client.Print("Hello World");
}
{
}
return 0;
}