Commit 42ed93d4 authored by nanamicat's avatar nanamicat

encrypt

parent 648d0b93
......@@ -15,6 +15,18 @@
in_addr_t remote;
auto cipher = "Mathematics is the art of giving the same name to different things";
void encrypt(char *buffer, size_t length) {
for (auto i = 0; i < length; i++) {
buffer[i] ^= cipher[i];
}
}
void decrypt(char *buffer, size_t length) {
encrypt(buffer, length);
}
// internet -> tun
void inbound(int raw, int tun) {
char buf[ETH_DATA_LEN];
......@@ -25,7 +37,10 @@ void inbound(int raw, int tun) {
// std::cout << "received " << packet_length << " bytes from " << inet_ntoa(address.sin_addr) << std::endl;
auto *packet = (iphdr *) buf;
auto overhead = packet->ihl * 4;
if (write(tun, buf + overhead, packet_length - overhead) < 0) {
auto payload = buf + overhead;
auto payload_length = packet_length - overhead;
decrypt(payload, payload_length);
if (write(tun, payload, payload_length) < 0) {
perror("inbound write");
}
}
......@@ -39,6 +54,7 @@ void outbound(int raw, int tun) {
address.sin_addr.s_addr = remote;
size_t packet_length;
while ((packet_length = read(tun, buf, sizeof(buf))) >= 0) {
encrypt(buf, packet_length);
if (sendto(raw, buf, packet_length, 0, (sockaddr *) &address, sizeof(address)) < 0) {
perror("outbound write");
}
......@@ -46,6 +62,7 @@ void outbound(int raw, int tun) {
perror("outbound read");
}
namespace po = boost::program_options;
int main(int argc, char *argv[]) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment