예제 #1
0
/*
 * Some browsers use a hybrid SSLv2 "client hello"
 */
int process_sslv23_client_hello(SSL *ssl) {
	uint8_t *buf = ssl->bm_data;
	int bytes_needed = ((buf[0] & 0x7f) << 8) + buf[1];
	int ret = SSL_OK;

	/* we have already read 3 extra bytes so far */
//    int read_len = SOCKET_READ(ssl->client_fd, buf, bytes_needed-3);
	int read_len = pbuf_copy_partial(ssl->ssl_pbuf, buf, bytes_needed - 3, 0);
	int cs_len = buf[1];
	int id_len = buf[3];
	int ch_len = buf[5];
	int i, j, offset = 8;   /* start at first cipher */
	int random_offset = 0;

	DISPLAY_BYTES(ssl, "received %d bytes", buf, read_len, read_len);

	add_packet(ssl, buf, read_len);

	/* connection has gone, so die */
	if (bytes_needed < 0) {
		return SSL_ERROR_CONN_LOST;
	}

	/* now work out what cipher suite we are going to use */
	for (j = 0; j < NUM_PROTOCOLS; j++) {
		for (i = 0; i < cs_len; i += 3) {
			if (ssl_prot_prefs[j] == buf[offset + i]) {
				ssl->cipher = ssl_prot_prefs[j];
				goto server_hello;
			}
		}
	}

	/* ouch! protocol is not supported */
	ret = SSL_ERROR_NO_CIPHER;
	goto error;

server_hello:
	/* get the session id */
	offset += cs_len - 2;   /* we've gone 2 bytes past the end */
#ifndef CONFIG_SSL_SKELETON_MODE
	ssl->session = ssl_session_update(ssl->ssl_ctx->num_sessions,
									  ssl->ssl_ctx->ssl_sessions, ssl, id_len ? &buf[offset] : NULL);
#endif

	/* get the client random data */
	offset += id_len;

	/* random can be anywhere between 16 and 32 bytes long - so it is padded
	 * with 0's to the left */
	if (ch_len == 0x10) {
		random_offset += 0x10;
	}

	memcpy(&ssl->dc->client_random[random_offset], &buf[offset], ch_len);
	ret = send_server_hello_sequence(ssl);

error:
	return ret;
}
예제 #2
0
파일: cgfree.c 프로젝트: HengWang/cgsysstat
/*
 * Write the memory statistic information.
 *
 * IN:
 * @mem_stats:                    The memory statistics information.
 * @flag:                         The display flag.
 */
void write_mem_stats(cg_mem_stats* mem_stats, int flag) {

	unsigned long long unit = 1024;
	unsigned long long temp = 0;
	printf(
			"              total          used          free        shared       buffers        cached\n");
	if (DISPLAY_BYTES(flag))
		unit = 1;
	else if (DISPLAY_MEGABYTES(flag))
		unit = 1024 * 1024;
	else if (DISPLAY_GIGABYTES(flag))
		unit = 1024 * 1024 * 1024;
	printf("Mem:   %12.0f  %12.0f  %12.0f  %12.0f  %12.0f  %12.0f\n",
			((double) mem_stats->limit) / unit,
			((double) mem_stats->usage) / unit,
			((double) (mem_stats->limit - mem_stats->usage)) / unit, (double) 0,
			(double) 0, ((double) mem_stats->stats->cache) / unit);
	if (!DISPLAY_OLD(flag))
		printf("-/+ buffers/cache:   %12.0f  %12.0f\n",
				((double) (mem_stats->usage - mem_stats->stats->cache
						- mem_stats->stats->inactive_anon
						- mem_stats->stats->inactive_file)) / unit,
				((double) (mem_stats->limit - mem_stats->usage
						+ mem_stats->stats->cache)) / unit);
	temp = mem_stats->mem_swap_limit - mem_stats->limit;
	printf("Swap:  %12.0f  %12.0f  %12.0f\n", ((double) (temp)) / unit,
			((double) (mem_stats->mem_swap_usage - mem_stats->usage)) / unit,
			temp ? ((double) (temp - mem_stats->mem_swap_usage
					+ mem_stats->usage) / unit) :
					0);
	if (DISPLAY_TOTAL(flag))
		printf("Total: %12.0f  %12.0f  %12.0f\n",
				((double) mem_stats->mem_swap_limit) / unit,
				((double) mem_stats->mem_swap_usage) / unit,
				((double) (mem_stats->mem_swap_limit - mem_stats->mem_swap_usage))
						/ unit);

}