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
50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
#ifndef RESPONSE_H
|
|
#define RESPONSE_H
|
|
|
|
#include <netinet/in.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdbool.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;
|
|
int statusCode;
|
|
char *statusMessage;
|
|
HeaderList *headers;
|
|
void *body;
|
|
unsigned int headerLength;
|
|
} Response;
|
|
|
|
Response* newResponse();
|
|
/*
|
|
* creates the minium viable valid response
|
|
*/
|
|
void responseBarebones(Response *rsp);
|
|
void connectionEstablished(Response *rsp);
|
|
char *responseToString(Response *rsp);
|
|
/* sets the body of a response to a string
|
|
* @param rsp the response
|
|
* @param string the string
|
|
* @param updateContentLength whether the content-length header should be auto-updated
|
|
* Note: if you want to set a binary body, use responseSetBodyRaw
|
|
*/
|
|
void responseSetBody(Response *rsp, char *string, bool updateContentLength);
|
|
// TODO:
|
|
//void responseSetBodyRaw(Response *rsp, void *body, size_t size, bool updateContentLength);
|
|
void responseAddHeader(Response *rsp, char header[]);
|
|
Response* newResponseFromSocket(int socket);
|
|
void responseFirstLine( Response *req, char line[] );
|
|
|
|
void freeResponse( Response *rsp );
|
|
|
|
|
|
#endif /* ifndef REQUEST_H */
|