mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 01:00:44 +02:00
allow setting of expected DTLS cert hostname from AC
This commit is contained in:
parent
86a0b715f3
commit
02e2135a2e
5 changed files with 43 additions and 36 deletions
|
@ -31,7 +31,8 @@ int hifiSockAddrMeta = qRegisterMetaType<HifiSockAddr>("HifiSockAddr");
|
||||||
|
|
||||||
AssignmentClient::AssignmentClient(int &argc, char **argv) :
|
AssignmentClient::AssignmentClient(int &argc, char **argv) :
|
||||||
QCoreApplication(argc, argv),
|
QCoreApplication(argc, argv),
|
||||||
_currentAssignment()
|
_currentAssignment(),
|
||||||
|
_assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME)
|
||||||
{
|
{
|
||||||
DTLSClientSession::globalInit();
|
DTLSClientSession::globalInit();
|
||||||
|
|
||||||
|
@ -40,57 +41,48 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) :
|
||||||
setApplicationName("assignment-client");
|
setApplicationName("assignment-client");
|
||||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||||
|
|
||||||
|
QStringList argumentList = arguments();
|
||||||
|
|
||||||
// register meta type is required for queued invoke method on Assignment subclasses
|
// register meta type is required for queued invoke method on Assignment subclasses
|
||||||
|
|
||||||
// set the logging target to the the CHILD_TARGET_NAME
|
// set the logging target to the the CHILD_TARGET_NAME
|
||||||
Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
|
Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
|
||||||
|
|
||||||
const char ASSIGNMENT_TYPE_OVVERIDE_OPTION[] = "-t";
|
const QString ASSIGNMENT_TYPE_OVVERIDE_OPTION = "-t";
|
||||||
const char* assignmentTypeString = getCmdOption(argc, (const char**)argv, ASSIGNMENT_TYPE_OVVERIDE_OPTION);
|
int argumentIndex = argumentList.indexOf(ASSIGNMENT_TYPE_OVVERIDE_OPTION);
|
||||||
|
|
||||||
Assignment::Type requestAssignmentType = Assignment::AllTypes;
|
Assignment::Type requestAssignmentType = Assignment::AllTypes;
|
||||||
|
|
||||||
if (assignmentTypeString) {
|
if (argumentIndex != -1) {
|
||||||
// the user is asking to only be assigned to a particular type of assignment
|
requestAssignmentType = (Assignment::Type) argumentList[argumentIndex + 1].toInt();
|
||||||
// so set that as the ::overridenAssignmentType to be used in requests
|
|
||||||
requestAssignmentType = (Assignment::Type) atoi(assignmentTypeString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char ASSIGNMENT_POOL_OPTION[] = "--pool";
|
const QString ASSIGNMENT_POOL_OPTION = "--pool";
|
||||||
const char* requestAssignmentPool = getCmdOption(argc, (const char**) argv, ASSIGNMENT_POOL_OPTION);
|
|
||||||
|
|
||||||
|
argumentIndex = argumentList.indexOf(ASSIGNMENT_POOL_OPTION);
|
||||||
|
|
||||||
|
QString assignmentPool;
|
||||||
|
|
||||||
|
if (argumentIndex != -1) {
|
||||||
|
assignmentPool = argumentList[argumentIndex + 1];
|
||||||
|
}
|
||||||
// setup our _requestAssignment member variable from the passed arguments
|
// setup our _requestAssignment member variable from the passed arguments
|
||||||
_requestAssignment = Assignment(Assignment::RequestCommand, requestAssignmentType, requestAssignmentPool);
|
_requestAssignment = Assignment(Assignment::RequestCommand, requestAssignmentType, assignmentPool);
|
||||||
|
|
||||||
// create a NodeList as an unassigned client
|
// create a NodeList as an unassigned client
|
||||||
NodeList* nodeList = NodeList::createInstance(NodeType::Unassigned);
|
NodeList* nodeList = NodeList::createInstance(NodeType::Unassigned);
|
||||||
|
|
||||||
const char CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION[] = "-a";
|
// check for an overriden assignment server hostname
|
||||||
const char CUSTOM_ASSIGNMENT_SERVER_PORT_OPTION[] = "-p";
|
const QString CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION = "-a";
|
||||||
|
|
||||||
// grab the overriden assignment-server hostname from argv, if it exists
|
argumentIndex = argumentList.indexOf(CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION);
|
||||||
const char* customAssignmentServerHostname = getCmdOption(argc, (const char**)argv, CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION);
|
|
||||||
const char* customAssignmentServerPortString = getCmdOption(argc,(const char**)argv, CUSTOM_ASSIGNMENT_SERVER_PORT_OPTION);
|
|
||||||
|
|
||||||
HifiSockAddr customAssignmentSocket;
|
if (argumentIndex != -1) {
|
||||||
|
_assignmentServerHostname = argumentList[argumentIndex + 1];
|
||||||
|
|
||||||
if (customAssignmentServerHostname || customAssignmentServerPortString) {
|
// set the custom assignment socket on our NodeList
|
||||||
|
HifiSockAddr customAssignmentSocket = HifiSockAddr(_assignmentServerHostname, DEFAULT_DOMAIN_SERVER_PORT);
|
||||||
|
|
||||||
// set the custom port or default if it wasn't passed
|
|
||||||
unsigned short assignmentServerPort = customAssignmentServerPortString
|
|
||||||
? atoi(customAssignmentServerPortString) : DEFAULT_DOMAIN_SERVER_PORT;
|
|
||||||
|
|
||||||
// set the custom hostname or default if it wasn't passed
|
|
||||||
if (!customAssignmentServerHostname) {
|
|
||||||
customAssignmentServerHostname = DEFAULT_ASSIGNMENT_SERVER_HOSTNAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
customAssignmentSocket = HifiSockAddr(customAssignmentServerHostname, assignmentServerPort);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the custom assignment socket if we have it
|
|
||||||
if (!customAssignmentSocket.isNull()) {
|
|
||||||
nodeList->setAssignmentServerSocket(customAssignmentSocket);
|
nodeList->setAssignmentServerSocket(customAssignmentSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,9 +130,9 @@ void AssignmentClient::readPendingDatagrams() {
|
||||||
if (_currentAssignment) {
|
if (_currentAssignment) {
|
||||||
qDebug() << "Received an assignment -" << *_currentAssignment;
|
qDebug() << "Received an assignment -" << *_currentAssignment;
|
||||||
|
|
||||||
// switch our nodelist domain IP and port to whoever sent us the assignment
|
// switch our DomainHandler hostname and port to whoever sent us the assignment
|
||||||
|
|
||||||
nodeList->getDomainHandler().setSockAddr(senderSockAddr);
|
nodeList->getDomainHandler().setSockAddr(senderSockAddr, _assignmentServerHostname);
|
||||||
nodeList->getDomainHandler().setAssignmentUUID(_currentAssignment->getUUID());
|
nodeList->getDomainHandler().setAssignmentUUID(_currentAssignment->getUUID());
|
||||||
|
|
||||||
qDebug() << "Destination IP for assignment is" << nodeList->getDomainHandler().getIP().toString();
|
qDebug() << "Destination IP for assignment is" << nodeList->getDomainHandler().getIP().toString();
|
||||||
|
|
|
@ -26,6 +26,7 @@ private slots:
|
||||||
private:
|
private:
|
||||||
Assignment _requestAssignment;
|
Assignment _requestAssignment;
|
||||||
SharedAssignmentPointer _currentAssignment;
|
SharedAssignmentPointer _currentAssignment;
|
||||||
|
QString _assignmentServerHostname;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__AssignmentClient__) */
|
#endif /* defined(__hifi__AssignmentClient__) */
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include "DomainHandler.h"
|
||||||
|
|
||||||
#include "DTLSClientSession.h"
|
#include "DTLSClientSession.h"
|
||||||
|
|
||||||
gnutls_certificate_credentials_t DTLSClientSession::_x509CACredentials;
|
gnutls_certificate_credentials_t DTLSClientSession::_x509CACredentials;
|
||||||
|
@ -30,7 +32,14 @@ void DTLSClientSession::globalDeinit() {
|
||||||
|
|
||||||
int DTLSClientSession::verifyServerCertificate(gnutls_session_t session) {
|
int DTLSClientSession::verifyServerCertificate(gnutls_session_t session) {
|
||||||
unsigned int verifyStatus = 0;
|
unsigned int verifyStatus = 0;
|
||||||
int certReturn = gnutls_certificate_verify_peers3(session, NULL, &verifyStatus);
|
|
||||||
|
// grab the hostname from the domain handler that this session is associated with
|
||||||
|
DomainHandler* domainHandler = reinterpret_cast<DomainHandler*>(gnutls_session_get_ptr(session));
|
||||||
|
qDebug() << "Checking for" << domainHandler->getHostname() << "from cert.";
|
||||||
|
|
||||||
|
int certReturn = gnutls_certificate_verify_peers3(session,
|
||||||
|
domainHandler->getHostname().toLocal8Bit().constData(),
|
||||||
|
&verifyStatus);
|
||||||
|
|
||||||
if (certReturn < 0) {
|
if (certReturn < 0) {
|
||||||
return GNUTLS_E_CERTIFICATE_ERROR;
|
return GNUTLS_E_CERTIFICATE_ERROR;
|
||||||
|
|
|
@ -58,6 +58,8 @@ void DomainHandler::initializeDTLSSession() {
|
||||||
if (!_dtlsSession) {
|
if (!_dtlsSession) {
|
||||||
_dtlsSession = new DTLSClientSession(NodeList::getInstance()->getDTLSSocket(), _sockAddr);
|
_dtlsSession = new DTLSClientSession(NodeList::getInstance()->getDTLSSocket(), _sockAddr);
|
||||||
|
|
||||||
|
gnutls_session_set_ptr(*_dtlsSession->getGnuTLSSession(), this);
|
||||||
|
|
||||||
// start a timer to complete the handshake process
|
// start a timer to complete the handshake process
|
||||||
_handshakeTimer = new QTimer(this);
|
_handshakeTimer = new QTimer(this);
|
||||||
connect(_handshakeTimer, &QTimer::timeout, this, &DomainHandler::completeDTLSHandshake);
|
connect(_handshakeTimer, &QTimer::timeout, this, &DomainHandler::completeDTLSHandshake);
|
||||||
|
@ -70,13 +72,16 @@ void DomainHandler::initializeDTLSSession() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainHandler::setSockAddr(const HifiSockAddr& sockAddr) {
|
void DomainHandler::setSockAddr(const HifiSockAddr& sockAddr, const QString& hostname) {
|
||||||
if (_sockAddr != sockAddr) {
|
if (_sockAddr != sockAddr) {
|
||||||
// we should reset on a sockAddr change
|
// we should reset on a sockAddr change
|
||||||
reset();
|
reset();
|
||||||
// change the sockAddr
|
// change the sockAddr
|
||||||
_sockAddr = sockAddr;
|
_sockAddr = sockAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// some callers may pass a hostname, this is not to be used for lookup but for DTLS certificate verification
|
||||||
|
_hostname = hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainHandler::setHostname(const QString& hostname) {
|
void DomainHandler::setHostname(const QString& hostname) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
void setIPToLocalhost() { _sockAddr.setAddress(QHostAddress(QHostAddress::LocalHost)); }
|
void setIPToLocalhost() { _sockAddr.setAddress(QHostAddress(QHostAddress::LocalHost)); }
|
||||||
|
|
||||||
const HifiSockAddr& getSockAddr() { return _sockAddr; }
|
const HifiSockAddr& getSockAddr() { return _sockAddr; }
|
||||||
void setSockAddr(const HifiSockAddr& sockAddr);
|
void setSockAddr(const HifiSockAddr& sockAddr, const QString& hostname);
|
||||||
|
|
||||||
unsigned short getPort() const { return _sockAddr.getPort(); }
|
unsigned short getPort() const { return _sockAddr.getPort(); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue