*/
#include <string.h>
+#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <gnutls/gnutls.h>
+#include <zlib.h>
+#include <resp.c>
#define DH_BITS 1024
static void * get_creds(char *certfile, char *keyfile)
}
#undef DH_BITS
+static int buildRecord(char *buffer, size_t len, char **out, size_t *olen)
+{
+ *olen = len + 4;
+ *out = malloc(*olen);
+ (*out)[0] = 0x0;
+ (*out)[1] = (len >> 8);
+ (*out)[2] = (len & 0xff);
+ (*out)[3] = 0x1;
+ memcpy(*out + 4, buffer, len);
+ return 0;
+}
+
+static int deflateRecord(char *buffer, size_t len, char **out, size_t *olen)
+{
+ z_stream zstrm;
+ int r;
+ zstrm.zalloc = Z_NULL;
+ zstrm.zfree = Z_NULL;
+ zstrm.opaque = Z_NULL;
+ if ((r = deflateInit(&zstrm, Z_DEFAULT_COMPRESSION)) != Z_OK)
+ return -1;
+ *out = malloc(len * 2 + 36);
+ if (!out) {
+ deflateEnd(&zstrm);
+ return -1;
+ }
+ zstrm.next_in = buffer;
+ zstrm.avail_in = len;
+ zstrm.next_out = *out + 6;
+ zstrm.avail_out = len * 2 + 30;
+ while ((r = deflate(&zstrm, Z_FINISH)) != Z_STREAM_END &&
+ zstrm.avail_out > 0);
+ if ((r = deflate(&zstrm, Z_FINISH)) != Z_STREAM_END) {
+ deflateEnd(&zstrm);
+ free(*out);
+ return -1;
+ }
+ *olen = zstrm.avail_out + 6;
+ (*out)[0] = 0x1;
+ (*out)[1] = (zstrm.avail_out >> 8);
+ (*out)[2] = (zstrm.avail_out & 0xff);
+ (*out)[3] = (len >> 8);
+ (*out)[4] = (len & 0xff);
+ (*out)[5] = 0x1;
+ deflateEnd(&zstrm);
+ return 0;
+}
+
-static char response[65536];
+static char *response;
+static char *def_response;
int main(int argc, char **argv)
{
struct sockaddr_in saddr;
int c;
int r;
- char buffer[256];
+ char buffer[8192];
int resp_size;
+ int def_resp_size;
int count = 0;
int val = 1;
gnutls_session_t session;
write(c, "E", 1);
r = read(c, buffer, 14);
if (r == 14 && !memcmp(buffer, "00000000000000", 14))
- write(c, "08082012225300", 14);
+ write(c, "08082013225300", 14);
if ((r = gnutls_handshake(session)) < 0)
fprintf(stderr, "error in handshake: %s\n",
gnutls_strerror(r));
else
fprintf(stderr, "handshake ok\n");
while ((r = gnutls_record_recv(session, buffer, sizeof(buffer))) > 0) {
- write(1, buffer, r);
count++;
- if (count == 3) {
- resp_size = read(0, response, sizeof(response));
- gnutls_record_send(session, response, resp_size);
+ if (count >= 2)
+ write(1, buffer, r);
+ if (count > 1) {
+ resp_size = resp(&response);
+ buildRecord(response, resp_size, &def_response, &def_resp_size);
+ gnutls_record_send(session, def_response, def_resp_size);
}
}
close(c);