Commit 3eec9765 authored by Gernot Tenchio's avatar Gernot Tenchio

Merge branch 'kanaka/websockets' into websockets

Conflicts:
	libvncserver/websockets.c
parents fd731867 7d1c1033
......@@ -193,6 +193,7 @@ if(LIBVNCSERVER_WITH_WEBSOCKETS)
${LIBVNCSERVER_DIR}/websockets.c
${LIBVNCSERVER_DIR}/${WSSRCS}
${COMMON_DIR}/md5.c
${COMMON_DIR}/sha1.c
)
endif(LIBVNCSERVER_WITH_WEBSOCKETS)
......
This diff is collapsed.
/*
* Copyright (C) The Internet Society (2001). All Rights Reserved.
*
* This document and translations of it may be copied and furnished to
* others, and derivative works that comment on or otherwise explain it
* or assist in its implementation may be prepared, copied, published
* and distributed, in whole or in part, without restriction of any
* kind, provided that the above copyright notice and this paragraph are
* included on all such copies and derivative works. However, this
* document itself may not be modified in any way, such as by removing
* the copyright notice or references to the Internet Society or other
* Internet organizations, except as needed for the purpose of
* developing Internet standards in which case the procedures for
* copyrights defined in the Internet Standards process must be
* followed, or as required to translate it into languages other than
* English.
*
* The limited permissions granted above are perpetual and will not be
* revoked by the Internet Society or its successors or assigns.
*
* This document and the information contained herein is provided on an
* "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
* TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
* HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* sha1.h
*
* Description:
* This is the header file for code which implements the Secure
* Hashing Algorithm 1 as defined in FIPS PUB 180-1 published
* April 17, 1995.
*
* Many of the variable names in this code, especially the
* single character names, were used because those were the names
* used in the publication.
*
* Please read the file sha1.c for more information.
*
*/
#ifndef _SHA1_H_
#define _SHA1_H_
#include <stdint.h>
/*
* If you do not have the ISO standard stdint.h header file, then you
* must typdef the following:
* name meaning
* uint32_t unsigned 32 bit integer
* uint8_t unsigned 8 bit integer (i.e., unsigned char)
* int_least16_t integer of >= 16 bits
*
*/
#ifndef _SHA_enum_
#define _SHA_enum_
enum
{
shaSuccess = 0,
shaNull, /* Null pointer parameter */
shaInputTooLong, /* input data too long */
shaStateError /* called Input after Result */
};
#endif
#define SHA1HashSize 20
/*
* This structure will hold context information for the SHA-1
* hashing operation
*/
typedef struct SHA1Context
{
uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */
uint32_t Length_Low; /* Message length in bits */
uint32_t Length_High; /* Message length in bits */
/* Index into message block array */
int_least16_t Message_Block_Index;
uint8_t Message_Block[64]; /* 512-bit message blocks */
int Computed; /* Is the digest computed? */
int Corrupted; /* Is the message digest corrupted? */
} SHA1Context;
/*
* Function Prototypes
*/
int SHA1Reset( SHA1Context *);
int SHA1Input( SHA1Context *,
const uint8_t *,
unsigned int);
int SHA1Result( SHA1Context *,
uint8_t Message_Digest[SHA1HashSize]);
#endif
......@@ -24,7 +24,7 @@ WEBSOCKETSSSLSRCS = rfbssl_none.c
#endif
endif
WEBSOCKETSSRCS = websockets.c ../common/md5.c $(WEBSOCKETSSSLSRCS)
WEBSOCKETSSRCS = websockets.c ../common/md5.c ../common/sha1.c $(WEBSOCKETSSSLSRCS)
endif
includedir=$(prefix)/include/rfb
......
......@@ -190,11 +190,8 @@ int rfbssl_write(rfbClientPtr cl, const char *buf, int bufsize)
return ret;
}
int rfbssl_peek(rfbClientPtr cl, char *buf, int bufsize)
static void rfbssl_gc_peekbuf(struct rfbssl_ctx *ctx, int bufsize)
{
int ret = -1;
struct rfbssl_ctx *ctx = (struct rfbssl_ctx *)cl->sslctx;
if (ctx->peekstart) {
int spaceleft = sizeof(ctx->peekbuf) - ctx->peeklen - ctx->peekstart;
if (spaceleft < bufsize) {
......@@ -202,44 +199,40 @@ int rfbssl_peek(rfbClientPtr cl, char *buf, int bufsize)
ctx->peekstart = 0;
}
}
}
static int __rfbssl_read(rfbClientPtr cl, char *buf, int bufsize, int peek)
{
int ret = 0;
struct rfbssl_ctx *ctx = (struct rfbssl_ctx *)cl->sslctx;
rfbssl_gc_peekbuf(ctx, bufsize);
/* If we have any peek data, simply return that. */
if (ctx->peeklen) {
if (bufsize > ctx->peeklen) {
/* more than we have, so we are trying to read the remaining
* bytes
**/
int required = bufsize - ctx->peeklen;
int total = ctx->peekstart + ctx->peeklen;
int n, avail = sizeof(ctx->peekbuf) - total;
if (required > avail)
required = avail;
if (!required) {
rfbErr("%s: no space left\n", __func__);
} else if ((n = rfbssl_do_read(cl, ctx->peekbuf + total, required)) < 0) {
rfbErr("%s: read error\n", __func__);
return n;
} else {
ctx->peeklen += n;
}
ret = ctx->peeklen;
} else {
/* simply return what we have */
ret = bufsize;
/* If we have any peek data, simply return that. */
ret = bufsize < ctx->peeklen ? bufsize : ctx->peeklen;
memcpy (buf, ctx->peekbuf + ctx->peekstart, ret);
if (!peek) {
ctx->peeklen -= ret;
if (ctx->peeklen != 0)
ctx->peekstart += ret;
else
ctx->peekstart = 0;
}
} else {
ret = bufsize;
if (ret > sizeof(ctx->peekbuf))
ret = sizeof(ctx->peekbuf);
if ((ret = rfbssl_do_read(cl, ctx->peekbuf, ret)) > 0)
ctx->peeklen = ret;
}
if (ret >= 0) {
memcpy(buf, ctx->peekbuf + ctx->peekstart, ret);
if (ret < bufsize) {
int n;
/* read the remaining data */
if ((n = rfbssl_do_read(cl, buf + ret, bufsize - ret)) <= 0) {
rfbErr("rfbssl_%s: %s error\n", __func__, peek ? "peek" : "read");
return n;
}
if (peek) {
memcpy(ctx->peekbuf + ctx->peekstart + ctx->peeklen, buf + ret, n);
ctx->peeklen += n;
}
ret += n;
}
return ret;
......@@ -247,23 +240,12 @@ int rfbssl_peek(rfbClientPtr cl, char *buf, int bufsize)
int rfbssl_read(rfbClientPtr cl, char *buf, int bufsize)
{
int ret;
struct rfbssl_ctx *ctx = (struct rfbssl_ctx *)cl->sslctx;
if (ctx->peeklen) {
/* If we have any peek data, simply return that. */
ret = bufsize < ctx->peeklen ? bufsize : ctx->peeklen;
memcpy (buf, ctx->peekbuf + ctx->peekstart, ret);
ctx->peeklen -= ret;
if (ctx->peeklen != 0)
ctx->peekstart += ret;
else
ctx->peekstart = 0;
} else {
ret = rfbssl_do_read(cl, buf, bufsize);
}
return __rfbssl_read(cl, buf, bufsize, 0);
}
return ret;
int rfbssl_peek(rfbClientPtr cl, char *buf, int bufsize)
{
return __rfbssl_read(cl, buf, bufsize, 1);
}
int rfbssl_pending(rfbClientPtr cl)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment