-
Notifications
You must be signed in to change notification settings - Fork 0
/
SslServer.cpp
89 lines (80 loc) · 1.98 KB
/
SslServer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Edgar A. Cobos
* CSULB Fall 2015
* CECS 476 - Computer Security
*
* Forked from https://github.com/GuiTeK/Qt-SslServer/
*/
#include "SslServer.h"
SslServer::SslServer(QObject * parent) : QTcpServer(parent)
{ /*\ 0_0 \*/}
/**
* Called when a new connection is available. The newConnection()
* signal is emitted when the connection is added to the pending
* connections queue
*
* @brief SslServer::incomingConnection
* @param socketDescriptor
*
* Ref: http://doc.qt.io/qt-5/qtcpserver.html#incomingConnection
*/
void SslServer::incomingConnection(qintptr socketDescriptor)
{
QSslSocket *mSslSocket = new QSslSocket(this);
if(mSslSocket->setSocketDescriptor(socketDescriptor))
{
mSslSocket->setProtocol(mProtocol);
mSslSocket->setLocalCertificate(mLocalCertificate);
mSslSocket->setPrivateKey(mPrivateKey);
this->addPendingConnection(mSslSocket);
}
else
{
delete mSslSocket;
qDebug() << "QSslSocket pointer deleted";
}
}
/**
* Sets the server's certificate.
*
* @brief SslServer::setSslLocalCertificate
* @param certificate
*/
void SslServer::setSslLocalCertificate(const QSslCertificate &certificate)
{
this->mLocalCertificate = certificate;
}
/**
* Sets the server's private asymmetric key.
*
* @brief SslServer::setSslPrivateKey
* @param key
*/
void SslServer::setSslPrivateKey(const QSslKey &key)
{
this->mPrivateKey = key;
}
/**
* Set the allowed/supported protocols.
*
* Default: TLSv1 and SSLv3 but forces client to use TLS
*
* @brief SslServer::setSslProtocol
* @param protocol
*/
void SslServer::setSslProtocol(QSsl::SslProtocol protocol)
{
this->mProtocol = protocol;
}
/**
* Set the checking of the peer's (server) certificate validity.
*
* Default: Verify that the server's certificate is valid
*
* @brief SslServer::setSslPeerVerifyMode
* @param verifyMode
*/
void SslServer::setSslPeerVerifyMode(QSslSocket::PeerVerifyMode verifyMode)
{
this->mPeerMode = verifyMode;
}