mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2026-11-21 19:27:09 +01:00
Update libraries and make it build on windows.
Still gets some warnings because compilers have changed. But should work.
This commit is contained in:
1 parent
520a5eacc5
commit
f2b7499f85
3038 files changed
+251668
-273857
No files matched your search
+108
-37
@@ -18,6 +18,10 @@
|
||||
#define NetSSL_SecureSocketImpl_INCLUDED
|
||||
|
||||
|
||||
// Temporary debugging aid, to be removed
|
||||
// #define ENABLE_PRINT_STATE
|
||||
|
||||
|
||||
#include "Poco/Net/SocketImpl.h"
|
||||
#include "Poco/Net/NetSSL.h"
|
||||
#include "Poco/Net/Context.h"
|
||||
@@ -35,6 +39,14 @@
|
||||
#include <sspi.h>
|
||||
|
||||
|
||||
|
||||
#ifdef ENABLE_PRINT_STATE
|
||||
#define PRINT_STATE(m) printState(m)
|
||||
#else
|
||||
#define PRINT_STATE(m)
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
@@ -154,10 +166,11 @@ public:
|
||||
/// number of connections that can be queued
|
||||
/// for this socket.
|
||||
|
||||
void shutdown();
|
||||
int shutdown();
|
||||
/// Shuts down the connection by attempting
|
||||
/// an orderly SSL shutdown, then actually
|
||||
/// shutting down the TCP connection.
|
||||
/// shutting down the TCP connection in the
|
||||
/// send direction.
|
||||
|
||||
void close();
|
||||
/// Close the socket.
|
||||
@@ -207,6 +220,12 @@ public:
|
||||
int available() const;
|
||||
/// Returns the number of bytes available in the buffer.
|
||||
|
||||
SocketImpl* socket();
|
||||
/// Returns the underlying SocketImpl.
|
||||
|
||||
const SocketImpl* socket() const;
|
||||
/// Returns the underlying SocketImpl.
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
@@ -218,60 +237,96 @@ protected:
|
||||
{
|
||||
ST_INITIAL = 0,
|
||||
ST_CONNECTING,
|
||||
ST_CLIENTHANDSHAKESTART,
|
||||
ST_CLIENTHANDSHAKECONDREAD,
|
||||
ST_CLIENTHANDSHAKEINCOMPLETE,
|
||||
ST_CLIENTHANDSHAKEOK,
|
||||
ST_CLIENTHANDSHAKEEXTERROR,
|
||||
ST_CLIENTHANDSHAKECONTINUE,
|
||||
ST_VERIFY,
|
||||
ST_CLIENT_HSK_START,
|
||||
ST_CLIENT_HSK_SEND_TOKEN,
|
||||
ST_CLIENT_HSK_LOOP_INIT,
|
||||
ST_CLIENT_HSK_LOOP_RECV,
|
||||
ST_CLIENT_HSK_LOOP_PROCESS,
|
||||
ST_CLIENT_HSK_LOOP_SEND,
|
||||
ST_CLIENT_HSK_LOOP_DONE,
|
||||
ST_CLIENT_HSK_SEND_FINAL,
|
||||
ST_CLIENT_HSK_SEND_ERROR,
|
||||
ST_CLIENT_VERIFY,
|
||||
ST_ACCEPTING,
|
||||
ST_SERVER_HSK_START,
|
||||
ST_SERVER_HSK_LOOP_INIT,
|
||||
ST_SERVER_HSK_LOOP_RECV,
|
||||
ST_SERVER_HSK_LOOP_PROCESS,
|
||||
ST_SERVER_HSK_LOOP_SEND,
|
||||
ST_SERVER_HSK_LOOP_DONE,
|
||||
ST_SERVER_VERIFY,
|
||||
ST_DONE,
|
||||
ST_ERROR
|
||||
ST_ERROR,
|
||||
ST_MAX
|
||||
};
|
||||
|
||||
enum TLSShutdown
|
||||
{
|
||||
TLS_SHUTDOWN_SENT = 1,
|
||||
TLS_SHUTDOWN_RECEIVED = 2
|
||||
};
|
||||
|
||||
int sendRawBytes(const void* buffer, int length, int flags = 0);
|
||||
int receiveRawBytes(void* buffer, int length, int flags = 0);
|
||||
void clientConnectVerify();
|
||||
void sendInitialTokenOutBuffer();
|
||||
void performServerHandshake();
|
||||
bool serverHandshakeLoop(PCtxtHandle phContext, PCredHandle phCred, bool requireClientAuth, bool doInitialRead, bool newContext);
|
||||
void clientVerifyCertificate(const std::string& hostName);
|
||||
void verifyCertificateChainClient(PCCERT_CONTEXT pServerCert);
|
||||
void serverVerifyCertificate();
|
||||
LONG serverDisconnect(PCredHandle phCreds, CtxtHandle* phContext);
|
||||
LONG clientDisconnect(PCredHandle phCreds, CtxtHandle* phContext);
|
||||
bool loadSecurityLibrary();
|
||||
void initClientContext();
|
||||
void initServerContext();
|
||||
int serverShutdown(PCredHandle phCreds, CtxtHandle* phContext);
|
||||
int clientShutdown(PCredHandle phCreds, CtxtHandle* phContext);
|
||||
PCCERT_CONTEXT loadCertificate(bool mustFindCertificate);
|
||||
void initCommon();
|
||||
void cleanup();
|
||||
void performClientHandshake();
|
||||
void performInitialClientHandshake();
|
||||
SECURITY_STATUS performClientHandshakeLoop();
|
||||
void performClientHandshakeLoopIncompleteMessage();
|
||||
void performClientHandshakeLoopCondReceive();
|
||||
void performClientHandshakeLoopReceive();
|
||||
void performClientHandshakeLoopOK();
|
||||
void performClientHandshakeLoopInit();
|
||||
void performClientHandshakeExtraBuffer();
|
||||
void performClientHandshakeSendOutBuffer();
|
||||
void performClientHandshakeLoopContinueNeeded();
|
||||
void performClientHandshakeLoopError();
|
||||
void performClientHandshakeLoopExtError();
|
||||
|
||||
void stateIllegal();
|
||||
void stateError();
|
||||
|
||||
void stateClientConnected();
|
||||
void stateClientHandshakeStart();
|
||||
void stateClientHandshakeSendToken();
|
||||
void stateClientHandshakeLoopInit();
|
||||
void stateClientHandshakeLoopRecv();
|
||||
void stateClientHandshakeLoopProcess();
|
||||
void stateClientHandshakeLoopSend();
|
||||
void stateClientHandshakeLoopDone();
|
||||
void stateClientHandshakeSendFinal();
|
||||
void stateClientHandshakeSendError();
|
||||
void stateClientVerify();
|
||||
|
||||
void stateServerAccepted();
|
||||
void stateServerHandshakeStart();
|
||||
void stateServerHandshakeLoopInit();
|
||||
void stateServerHandshakeLoopRecv();
|
||||
void stateServerHandshakeLoopProcess();
|
||||
void stateServerHandshakeLoopSend();
|
||||
void stateServerHandshakeLoopDone();
|
||||
void stateServerHandshakeVerify();
|
||||
|
||||
void sendOutSecBufferAndAdvanceState(State state);
|
||||
void drainExtraBuffer();
|
||||
static int getRecordLength(const BYTE* pBuffer, int length);
|
||||
static bool bufferHasCompleteRecords(const BYTE* pBuffer, int length);
|
||||
|
||||
void initClientCredentials();
|
||||
void initServerCredentials();
|
||||
SECURITY_STATUS doHandshake();
|
||||
int completeHandshake();
|
||||
|
||||
SECURITY_STATUS decodeMessage(BYTE* pBuffer, DWORD bufSize, AutoSecBufferDesc<4>& msg, SecBuffer*& pData, SecBuffer*& pExtra);
|
||||
SECURITY_STATUS decodeBufferFull(BYTE* pBuffer, DWORD bufSize, char* pOutBuffer, int outLength, int& bytesDecoded);
|
||||
void stateIllegal();
|
||||
void stateConnected();
|
||||
|
||||
void acceptSSL();
|
||||
void connectSSL(bool completeHandshake);
|
||||
void completeHandshake();
|
||||
static int lastError();
|
||||
void stateMachine();
|
||||
bool stateMachine();
|
||||
State getState() const;
|
||||
void setState(State st);
|
||||
static int stateToReturnValue(State state);
|
||||
static bool isLocalHost(const std::string& hostName);
|
||||
|
||||
#ifdef ENABLE_PRINT_STATE
|
||||
void printState(const std::string& msg);
|
||||
#endif
|
||||
|
||||
private:
|
||||
SecureSocketImpl(const SecureSocketImpl&);
|
||||
SecureSocketImpl& operator = (const SecureSocketImpl&);
|
||||
@@ -279,6 +334,7 @@ private:
|
||||
Poco::AutoPtr<SocketImpl> _pSocket;
|
||||
Context::Ptr _pContext;
|
||||
Mode _mode;
|
||||
int _shutdownFlags;
|
||||
std::string _peerHostName;
|
||||
bool _useMachineStore;
|
||||
bool _clientAuthRequired;
|
||||
@@ -294,6 +350,8 @@ private:
|
||||
|
||||
Poco::Buffer<BYTE> _overflowBuffer;
|
||||
Poco::Buffer<BYTE> _sendBuffer;
|
||||
DWORD _sendBufferOffset;
|
||||
DWORD _sendBufferPending;
|
||||
Poco::Buffer<BYTE> _recvBuffer;
|
||||
DWORD _recvBufferOffset;
|
||||
DWORD _ioBufferSize;
|
||||
@@ -304,9 +362,9 @@ private:
|
||||
SecBuffer _extraSecBuffer;
|
||||
SECURITY_STATUS _securityStatus;
|
||||
State _state;
|
||||
DWORD _outFlags;
|
||||
bool _needData;
|
||||
bool _needHandshake;
|
||||
bool _initServerContext = false;
|
||||
|
||||
friend class SecureStreamSocketImpl;
|
||||
friend class StateMachine;
|
||||
@@ -316,6 +374,18 @@ private:
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline SocketImpl* SecureSocketImpl::socket()
|
||||
{
|
||||
return _pSocket.get();
|
||||
}
|
||||
|
||||
|
||||
inline const SocketImpl* SecureSocketImpl::socket() const
|
||||
{
|
||||
return _pSocket.get();
|
||||
}
|
||||
|
||||
|
||||
inline poco_socket_t SecureSocketImpl::sockfd()
|
||||
{
|
||||
return _pSocket->sockfd();
|
||||
@@ -337,6 +407,7 @@ inline SecureSocketImpl::State SecureSocketImpl::getState() const
|
||||
inline void SecureSocketImpl::setState(SecureSocketImpl::State st)
|
||||
{
|
||||
_state = st;
|
||||
PRINT_STATE("setState: ");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -53,8 +53,9 @@ class NetSSL_Win_API SecureStreamSocket: public StreamSocket
|
||||
public:
|
||||
enum
|
||||
{
|
||||
ERR_SSL_WANT_READ = -1,
|
||||
ERR_SSL_WANT_WRITE = -2
|
||||
ERR_SSL_WOULD_BLOCK = -1,
|
||||
ERR_SSL_WANT_READ = -2,
|
||||
ERR_SSL_WANT_WRITE = -3
|
||||
};
|
||||
|
||||
SecureStreamSocket();
|
||||
|
||||
@@ -117,14 +117,25 @@ public:
|
||||
/// Since SSL does not support a half shutdown, this does
|
||||
/// nothing.
|
||||
|
||||
void shutdownSend();
|
||||
int shutdownSend();
|
||||
/// Shuts down the receiving part of the socket connection.
|
||||
///
|
||||
/// Since SSL does not support a half shutdown, this does
|
||||
/// nothing.
|
||||
/// Sends a close notify shutdown alert message to the peer
|
||||
/// (if not sent yet), then calls shutdownSend() on the
|
||||
/// underlying socket.
|
||||
///
|
||||
/// Returns 0 if the message has been sent.
|
||||
/// Returns 1 if the message has been sent, but the peer
|
||||
/// has not yet sent its shutdown alert message.
|
||||
/// In case of a non-blocking socket, returns < 0 if the
|
||||
/// message cannot be sent at the moment. In this case,
|
||||
/// the call to shutdownSend() must be retried after the
|
||||
/// underlying socket becomes writable again.
|
||||
|
||||
void shutdown();
|
||||
int shutdown();
|
||||
/// Shuts down the SSL connection.
|
||||
///
|
||||
/// Same as shutdownSend().
|
||||
|
||||
void abort();
|
||||
/// Aborts the connection by closing the underlying
|
||||
@@ -197,6 +208,12 @@ public:
|
||||
/// Returns true iff a reused session was negotiated during
|
||||
/// the handshake.
|
||||
|
||||
// SocketImpl
|
||||
virtual void setBlocking(bool flag) override;
|
||||
virtual bool getBlocking() const override;
|
||||
virtual void setRawOption(int level, int option, const void* value, poco_socklen_t length) override;
|
||||
virtual void getRawOption(int level, int option, void* value, poco_socklen_t& length) override;
|
||||
|
||||
protected:
|
||||
void acceptSSL();
|
||||
/// Performs a SSL server-side handshake.
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public:
|
||||
/// Non-case sensitive conversion of a string to a VerificationMode enum.
|
||||
/// If verMode is illegal an OptionException is thrown.
|
||||
|
||||
static const std::string& formatError(long errCode);
|
||||
static std::string formatError(long errCode);
|
||||
/// Converts an winerror.h code into human readable form.
|
||||
|
||||
private:
|
||||
|
||||
Reference in new issue
Block a user