本文整理汇总了C++中SSLSocket::getPeerName方法的典型用法代码示例。如果您正苦于以下问题:C++ SSLSocket::getPeerName方法的具体用法?C++ SSLSocket::getPeerName怎么用?C++ SSLSocket::getPeerName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SSLSocket
的用法示例。
在下文中一共展示了SSLSocket::getPeerName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
//.........这里部分代码省略.........
ctx.setX509Certificate(&serverCert);
ctx.setCertificateAuthority(&ca);
ctx.enableVerification(require_cert); // TODO: Get a parameter to determine if client certificates are required
ctx.setSessionID(SAFMQ_SESSION_ID, sizeof(SAFMQ_SESSION_ID)-1);
if (port < 1)
port = 9001;
if (ap.addresses.size() == 0) {
try {
SSLServerSocket* svr = new SSLServerSocket(port,&ctx);
servers.push_back(svr);
Log::getLog()->Info("Starting SAFMQ Server at address safmqs://*:%ld", port);
} catch (tcpsocket::SocketException e) {
Log::getLog()->Info("Error:Binding Address: safmqs://*:%ld -- %s", port, e.what());
}
} else {
for(AddressParser::AddressList::size_type x=0;x<ap.addresses.size();x++) {
unsigned short tmpport;
try {
tmpport = (ap.addresses[x].port == 0xFFFF ) ? port : ap.addresses[x].port;
SSLServerSocket* svr = new SSLServerSocket(tmpport, &ctx, ap.addresses[x].address);
servers.push_back(svr);
Log::getLog()->Info("Starting SAFMQ Server at address safmqs://%s:%ld", ap.addresses[x].name.c_str(),tmpport);
} catch (tcpsocket::SocketException e) {
Log::getLog()->Info("Error:Binding Address: safmqs://%s:%ld -- %s", ap.addresses[x].name.c_str(),tmpport, e.what());
}
}
}
try {
std::list<SSLServerSocket*> avail;
tcpsocket::Selector<tcpsocket::SSLServerSocket> selector;
std::list<tcpsocket::SSLServerSocket*>::iterator i;
while (!m_bStop) {
trusted = false;
user = "";
avail.clear();
avail.assign(servers.begin(), servers.end());
selector.selectReaders(avail);
for(i = avail.begin(); !m_bStop && i != avail.end(); ++i) {
client = (*i)->acceptConnection();
Log::getLog()->Info("New conneciton accepted");
// Force the connection negotiation, this will call verify()
pcert = client.getPeerCertificate();
Log::getLog()->Info("Peer certificate obtained 0x%lx", pcert);
int res = client.getVerifyResult();
Log::getLog()->Info("Peer Verify Result: %ld", res);
if (pcert) {
Log::getLog()->Info("Client Cert Issuer: %s", pcert->getIssuerName().c_str());
Log::getLog()->Info("Client Cert Subject: %s", pcert->getSubjectName().c_str());
} else {
Log::getLog()->Info("SSLServerThread::run()-pcert: %p", pcert);
}
// determine if a trusted user certificate has been presented
if (res == X509_V_OK && pcert) {
trusted = (SecurityControl::getSecurityControl()->identifyUser(pcert->getSubjectName(), pcert->getIssuerName(), user) == SecurityControl::GRANTED);
}
Log::getLog()->Info("Certificate Trusted: %ld require_cert: %ld", trusted, require_cert);
if (require_cert && (res != X509_V_OK || !pcert) ) {
// reject the client certificate not allowed
// since valid certificates are required, enforce the requirement
struct sockaddr_in peername;
client.getPeerName(&peername);
Log::getLog()->SignOn(Log::error, "Digital Certificate", &peername, EC_Decode(EC_NOTAUTHORIZED));
if (pcert) {
Log::getLog()->Info("X509 Cert rejected, subject: %s -- reason: %s",
pcert->getSubjectName().c_str(), X509_verify_cert_error_string(res));
}
client.close();
} else {
Log::getLog()->Info("Establishing a connection with client user:%s", user.c_str());
// Establis a connection for the user
socstream *stm = new tcpsocket::socstream(client);
ServiceThread *thd = new ServiceThread(stm,trusted,user);
thd->start();
}
if (pcert) delete pcert;
}
}
} catch (tcpsocket::SocketException e) {
Log::getLog()->Info("SSLServer exception: %s", e.what());
}
return NULL;
}