The proxy can now sit between a client and a https web server. It does this by looking for a CONNECT request that conventional proxies use to open a tunnel between a client and an https server. Instead of opening an opaque tunnel, yaip immediately sends bacck a "connection established" response. This tells the client (browser normally) to proceed and initiate an HTTPS connection. I use the host that was send in the connect request to set up a fake SSL server. If we have seen the domain before, we re-use the certificate, otherwise we generate a new one and sign it using YAIP's built in certificate authority. I still need to do work on forwarding the request upstream. This is my next job. Currently, yaip responds with a valid response of "it worked". ``` $ curl https://example.com --cacert ~/.config/yaip/cert.pem It worked ``` Notice, we don't get any certificate errors because we are telling curl to trust the authority that yaip usesmaster
parent
1beca38af6
commit
dd71d26245
15 changed files with 337 additions and 116 deletions
@ -1,50 +0,0 @@ |
||||
// https://man7.org/tlpi/code/online/dist/sockets/read_line.c.html
|
||||
#include "readline.h" |
||||
|
||||
/* Read characters from 'fd' until a newline is encountered. If a newline
|
||||
character is not encountered in the first (n - 1) bytes, then the excess |
||||
characters are discarded. The returned string placed in 'buf' is |
||||
null-terminated and includes the newline character if it was read in the |
||||
first (n - 1) bytes. The function return value is the number of bytes |
||||
placed in buffer (which includes the newline character if encountered, |
||||
but excludes the terminating null byte). */ |
||||
ssize_t fdReadLine(int fd, void *buffer, size_t n) { |
||||
ssize_t numRead; /* # of bytes fetched by last read() */ |
||||
size_t totRead; /* Total bytes read so far */ |
||||
char *buf; |
||||
char ch; |
||||
if (n <= 0 || buffer == NULL) { |
||||
errno = EINVAL; |
||||
return -1; |
||||
} |
||||
buf = buffer; /* No pointer arithmetic on "void *" */ |
||||
totRead = 0; |
||||
for (;;) { |
||||
numRead = read(fd, &ch, 1); |
||||
if (numRead == -1) { |
||||
if (errno == EINTR) /* Interrupted --> restart read() */ |
||||
continue; |
||||
else |
||||
return -1; /* Some other error */ |
||||
|
||||
} else if (numRead == 0) { /* EOF */ |
||||
if (totRead == 0) /* No bytes read; return 0 */ |
||||
return 0; |
||||
else /* Some bytes read; add '\0' */ |
||||
break; |
||||
|
||||
} else { /* 'numRead' must be 1 if we get here */ |
||||
if (totRead < n - 1) { /* Discard > (n - 1) bytes */ |
||||
totRead++; |
||||
*buf++ = ch; |
||||
} |
||||
|
||||
if (ch == '\n') |
||||
break; |
||||
} |
||||
} |
||||
|
||||
*buf = '\0'; |
||||
return totRead; |
||||
} |
||||
|
@ -1,9 +0,0 @@ |
||||
#ifndef READLINE_H |
||||
#define READLINE_H |
||||
|
||||
#include <unistd.h> |
||||
#include <errno.h> |
||||
|
||||
ssize_t fdReadLine(int fd, void *buffer, size_t n); |
||||
|
||||
#endif /* ifndef READLINE_H */ |
Loading…
Reference in new issue