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 uses
46 lines
853 B
C
46 lines
853 B
C
#ifndef REQUEST_H
|
|
#define REQUEST_H
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
#include <netinet/in.h>
|
|
#include <math.h>
|
|
|
|
#include "util.h"
|
|
#include "requestresponse.h"
|
|
|
|
|
|
|
|
/*
|
|
* A struct reperesenting an http request
|
|
*/
|
|
typedef struct {
|
|
// Common versions are: 0.9, 1.0, 1.1, 2.0
|
|
float version;
|
|
char *method;
|
|
char *protocol;
|
|
char *host;
|
|
char *path;
|
|
int port;
|
|
HeaderList *headers;
|
|
char *queryString;
|
|
void *body;
|
|
} Request;
|
|
|
|
Request* newRequest();
|
|
void requestFirstLine( Request *req, char line[] );
|
|
Request* newRequestFromSocket(int socket);
|
|
Request* newRequestFromString(char *string);
|
|
/*
|
|
* requestToString
|
|
* @prarm req the request to convert
|
|
*/
|
|
char* requestToString( Request *req );
|
|
void requestAddHeader( Request *req, char header[] );
|
|
|
|
void freeRequest( Request *req );
|
|
|
|
|
|
#endif /* ifndef REQUEST_H */
|