30 #define TCP_CLOSE(_sck) closesocket(_sck) 31 #define TCP_STRERROR "tcp error" 32 #define TCP_SLEEP(_n) Sleep(_n) 33 #define TCP_BLOCKS (WSAGetLastError() == WSAEWOULDBLOCK) 35 #define TCP_CLOSE(_sck) close(_sck) 36 #define TCP_STRERROR strerror(errno) 37 #define TCP_SLEEP(_n) sleep(_n) 38 #define TCP_BLOCKS (errno == EWOULDBLOCK) 42 #define INADDR_NONE ((unsigned long) -1) 46 #define STREAM_COUNT 8 48 #define STREAM_COUNT 1 64 static char * g_ssl_server =
NULL;
84 static int cur_stream_id = 0;
125 error(
"EncryptMessage failed: %d\n",
res);
190 bufs[0].cbBuffer = buf_len;
226 error(
"DecryptMessage failed: %d\n",
res);
346 uint32 new_length, end_offset, p_offset;
366 new_length = (
s->end -
s->data) +
length;
367 if (new_length >
s->size)
369 p_offset =
s->p -
s->data;
370 end_offset =
s->end -
s->data;
372 s->size = new_length;
373 s->p =
s->data + p_offset;
374 s->end =
s->data + end_offset;
459 error(
"Connection closed\n");
504 error(
"ensure_cred_handle failed: %ld\n",
res);
518 SIZE_T read_buf_size = 2048;
545 &
ctx, &out_desc, &attrs,
NULL);
564 out_buf.pvBuffer =
NULL;
572 memmove(
read_buf, (
BYTE*)in_bufs[0].pvBuffer+in_bufs[0].cbBuffer-in_bufs[1].cbBuffer, in_bufs[1].cbBuffer);
573 in_bufs[0].cbBuffer = in_bufs[1].cbBuffer;
576 in_bufs[1].cbBuffer = 0;
577 in_bufs[1].pvBuffer =
NULL;
583 if (in_bufs[0].cbBuffer + 1024 > read_buf_size)
592 in_bufs[0].pvBuffer =
read_buf = new_read_buf;
593 read_buf_size += 1024;
604 in_bufs[0].cbBuffer +=
size;
640 error(
"Failed to establish SSL connection: %08x (%u)\n",
status,
res);
654 char tcp_port_rdp_s[10];
656 if (!g_ssl_initialized)
661 g_ssl_initialized =
True;
692 error(
"tcp_tls_get_server_pubkey: QueryContextAttributesW() failed %ld\n",
status);
696 s->size =
cert->cbCertEncoded;
699 error(
"tcp_tls_get_server_pubkey: cert->cbCertEncoded = %ld\n",
cert->cbCertEncoded);
703 s->data =
s->p = (
unsigned char *)
xmalloc(
s->size);
706 s->end =
s->p +
s->size;
711 return (
s->size != 0);
727 char tcp_port_rdp_s[10];
800 option_len =
sizeof(option_value);
805 if (option_value < (1024 * 16))
807 option_value = 1024 * 16;
808 option_len =
sizeof(option_value);
858 g_ssl_initialized =
False;
868 static char ipaddr[32];
877 strcpy(ipaddr,
"127.0.0.1");
#define ISC_REQ_SEQUENCE_DETECT
namespace GUID const ADDRINFOEXW * hints
#define SECPKG_ATTR_SUPPORTED_PROTOCOLS
#define memmove(s1, s2, n)
#define SECPKG_CRED_OUTBOUND
static rfbScreenInfoPtr server
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
RD_BOOL tcp_tls_connect(void)
#define SECBUFFER_STREAM_HEADER
SECURITY_STATUS WINAPI AcquireCredentialsHandleW(SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialsUse, PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn, PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
ACPI_SIZE strlen(const char *String)
SECURITY_STATUS WINAPI FreeContextBuffer(PVOID pv)
#define SEC_I_CONTEXT_EXPIRED
#define SecIsValidHandle(x)
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
#define SECPKG_ATTR_REMOTE_CERT_CONTEXT
STREAM tcp_init(uint32 maxlen)
static SecHandle cred_handle
#define ERROR_NOT_ENOUGH_MEMORY
DWORD WINAPI GetLastError(VOID)
SECURITY_STATUS WINAPI FreeCredentialsHandle(PCredHandle phCredential)
INT WSAAPI connect(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size)
STREAM tcp_recv(STREAM s, uint32 length)
static struct stream g_out[STREAM_COUNT]
#define ISC_REQ_MANUAL_CRED_VALIDATION
#define sprintf(buf, format,...)
#define SecInvalidateHandle(x)
GLenum GLuint GLenum GLsizei const GLchar * buf
static BOOL cred_handle_initialized
SECURITY_STATUS WINAPI QueryCredentialsAttributesA(PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
static BOOL ensure_cred_handle(struct request *request)
void * xrealloc(void *oldmem, size_t size)
RD_BOOL tcp_connect(char *server)
GLenum GLuint GLenum GLsizei length
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
#define SCHANNEL_CRED_VERSION
static BOOL read_ssl_chunk(struct netconn *conn, void *buf, SIZE_T buf_size, SIZE_T *ret_size, BOOL *eof)
DWORD grbitEnabledProtocols
#define SEC_I_CONTINUE_NEEDED
INT WSAAPI getpeername(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
void tcp_reset_state(void)
static SecHandle compat_cred_handle
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
SECURITY_STATUS WINAPI InitializeSecurityContextA(PCredHandle phCredential, PCtxtHandle phContext, SEC_CHAR *pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
void scard_unlock(int lock)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
static BOOL send_ssl_chunk(struct netconn *conn, const void *msg, size_t size)
#define ISC_REQ_USE_SESSION_KEY
#define SECPKG_ATTR_STREAM_SIZES
#define SECBUFFER_STREAM_TRAILER
#define ISC_REQ_ALLOCATE_MEMORY
#define memcpy(s1, s2, n)
SECURITY_STATUS WINAPI QueryContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute, void *pBuffer)
_Check_return_ _CRTIMP int __cdecl __cdecl eof(_In_ int _FileHandle)
void tcp_disconnect(void)
INT WSAAPI getsockopt(IN SOCKET s, IN INT level, IN INT optname, OUT CHAR FAR *optval, IN OUT INT FAR *optlen)
int ui_select(int rdp_socket)
#define SP_PROT_TLS1_1PLUS_CLIENT
void scard_lock(int lock)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define SECBUFFER_VERSION
SECURITY_STATUS WINAPI DecryptMessage(PCtxtHandle phContext, PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
static struct stream g_in
char * strcpy(char *DstString, const char *SrcString)
#define ISC_REQ_CONFIDENTIALITY
#define ISC_REQ_REPLAY_DETECT
RD_BOOL tcp_tls_get_server_pubkey(STREAM s)
static SERVICE_STATUS status
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
INT WSAAPI getsockname(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
SecPkgContext_StreamSizes ssl_sizes
#define SEC_E_INCOMPLETE_MESSAGE
SECURITY_STATUS WINAPI EncryptMessage(PCtxtHandle phContext, ULONG fQOP, PSecBufferDesc pMessage, ULONG MessageSeqNo)
RD_BOOL tcp_is_connected()
SECURITY_STATUS WINAPI DeleteSecurityContext(PCtxtHandle phContext)
static BOOL have_compat_cred_handle