1 #include "tinytls.h"
2 #include "errmsg.h"
3 #include "ip4.h"
4 #include "socket.h"
5 #include <stdio.h>
6 
7 
8 char pkt[]=
9 "\x16\x03\x01\x01\x4e\x01\x00\x01\x4a\x03\x03\x4f\x93\x81\xfb\x57"
10 "\x72\x4b\x79\x31\x35\x0f\x4e\xb6\xd5\x47\xb7\x0d\xb5\x54\x0e\xd1"
11 "\x71\xc1\xb6\x9b\x9f\xdb\xa5\xf0\xe4\x43\xac\x00\x00\xa0\xc0\x30"
12 "\xc0\x2c\xc0\x28\xc0\x24\xc0\x14\xc0\x0a\xc0\x22\xc0\x21\x00\xa3"
13 "\x00\x9f\x00\x6b\x00\x6a\x00\x39\x00\x38\x00\x88\x00\x87\xc0\x32"
14 "\xc0\x2e\xc0\x2a\xc0\x26\xc0\x0f\xc0\x05\x00\x9d\x00\x3d\x00\x35"
15 "\x00\x84\xc0\x12\xc0\x08\xc0\x1c\xc0\x1b\x00\x16\x00\x13\xc0\x0d"
16 "\xc0\x03\x00\x0a\xc0\x2f\xc0\x2b\xc0\x27\xc0\x23\xc0\x13\xc0\x09"
17 "\xc0\x1f\xc0\x1e\x00\xa2\x00\x9e\x00\x67\x00\x40\x00\x33\x00\x32"
18 "\x00\x9a\x00\x99\x00\x45\x00\x44\xc0\x31\xc0\x2d\xc0\x29\xc0\x25"
19 "\xc0\x0e\xc0\x04\x00\x9c\x00\x3c\x00\x2f\x00\x96\x00\x41\x00\x07"
20 "\xc0\x11\xc0\x07\xc0\x0c\xc0\x02\x00\x05\x00\x04\x00\x15\x00\x12"
21 "\x00\x09\x00\x14\x00\x11\x00\x08\x00\x06\x00\x03\x00\xff\x02\x01"
22 "\x00\x00\x80\x00\x00\x00\x11\x00\x0f\x00\x00\x0c\x62\x6c\x6f\x67"
23 "\x2e\x66\x65\x66\x65\x2e\x64\x65\x00\x0b\x00\x04\x03\x00\x01\x02"
24 "\x00\x0a\x00\x34\x00\x32\x00\x0e\x00\x0d\x00\x19\x00\x0b\x00\x0c"
25 "\x00\x18\x00\x09\x00\x0a\x00\x16\x00\x17\x00\x08\x00\x06\x00\x07"
26 "\x00\x14\x00\x15\x00\x04\x00\x05\x00\x12\x00\x13\x00\x01\x00\x02"
27 "\x00\x03\x00\x0f\x00\x10\x00\x11\x00\x0d\x00\x22\x00\x20\x06\x01"
28 "\x06\x02\x06\x03\x05\x01\x05\x02\x05\x03\x04\x01\x04\x02\x04\x03"
29 "\x03\x01\x03\x02\x03\x03\x02\x01\x02\x02\x02\x03\x01\x01\x00\x0f"
30 "\x00\x01\x01\x15\x03\x03\x00\x02\x02\x30";
31 
main()32 int main() {
33   struct ssl_context sc;
34   int fd;
35 
36   fd=socket_tcp4b();
37   if (fd==-1)
38     diesys(1,"socket");
39   if (socket_connect4(fd,ip4loopback,443)==-1)
40     if (socket_connect4(fd,ip4loopback,4433)==-1)
41       diesys(1,"connect");
42 
43 #if 0
44   size_t l;
45   char buf[200];
46   init_tls_context_norandom(&sc,NULL);
47   printf("%zu\n",fmt_tls_serverhello(NULL,pkt,sizeof(pkt),&sc));
48   init_tls_context_norandom(&sc,"blog.fefe.de");
49   l=fmt_tls_clienthello(buf,&sc);
50   printf("%zu\n",fmt_tls_serverhello(NULL,buf,l,&sc));
51 #endif
52 
53   init_tls_context(&sc,"localhost");
54   tls_connect(fd,&sc);
55   return 0;
56 }
57