Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSSL update broke stuff, fixed #106

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
language: c
compiler: clang
before_install:
- wget https://dist.libuv.org/dist/v1.22.0/libuv-v1.22.0.tar.gz
- tar -xzf libuv*.tar.gz
- pushd libuv*
- sh autogen.sh
- ./configure
- make
- sudo make install
- popd
script: make
8 changes: 2 additions & 6 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <stdbool.h>
#include <zlib.h>
#include <openssl/evp.h>
#include <pcap.h>
#include <stdio.h>


Expand Down Expand Up @@ -1110,9 +1109,6 @@ struct bot_agent {

int capture_enabled;
FILE *capture;
/* TODO: Use pcap to record traffic instead of custom binary format? */
pcap_dumper_t *pdumper;
char pcap_errorbuf[PCAP_ERRBUF_SIZE];

int mcc_status;

Expand All @@ -1130,8 +1126,8 @@ struct bot_agent {
unsigned char *verify_token;
unsigned char ss[SECRET_KEY_LENGTH];
uint32_t block_size;
EVP_CIPHER_CTX ctx_encrypt;
EVP_CIPHER_CTX ctx_decrypt;
EVP_CIPHER_CTX *ctx_encrypt;
EVP_CIPHER_CTX *ctx_decrypt;

int32_t packet_capacity;
int32_t packet_length;
Expand Down
12 changes: 6 additions & 6 deletions src/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int uv_write_encrypt(struct bot_agent *bot, char *data, size_t len) {
int32_t max_len = len + bot->block_size;
buf = uv_buf_init(malloc(max_len), max_len);
int32_t outl;
if (!EVP_EncryptUpdate(&bot->ctx_encrypt, (unsigned char *)buf.base, &outl, (const unsigned char *)data, len)) {
if (!EVP_EncryptUpdate(bot->ctx_encrypt, (unsigned char *)buf.base, &outl, (const unsigned char *)data, len)) {
fprintf(stderr, "Encryption error.\n");
assert(0);
}
Expand Down Expand Up @@ -1015,10 +1015,10 @@ void deserialize_clientbound_login_encryption_request(char *packet_data, struct
srand(time(NULL));
/* Generat 16-byte shared secret */
bot->block_size = EVP_CIPHER_block_size(EVP_aes_128_cfb8());
EVP_CIPHER_CTX_init(&bot->ctx_encrypt);
EVP_CIPHER_CTX_init(&bot->ctx_decrypt);
EVP_EncryptInit_ex(&bot->ctx_encrypt, EVP_aes_128_cfb8(), NULL, bot->ss, bot->ss);
EVP_DecryptInit_ex(&bot->ctx_decrypt, EVP_aes_128_cfb8(), NULL, bot->ss, bot->ss);
bot->ctx_encrypt = EVP_CIPHER_CTX_new();
bot->ctx_decrypt = EVP_CIPHER_CTX_new();
EVP_EncryptInit_ex(bot->ctx_encrypt, EVP_aes_128_cfb8(), NULL, bot->ss, bot->ss);
EVP_DecryptInit_ex(bot->ctx_decrypt, EVP_aes_128_cfb8(), NULL, bot->ss, bot->ss);
random_bytes(sizeof(bot->ss), bot->ss);
int ss_cipher_length = RSA_public_encrypt(sizeof(bot->ss), bot->ss, ss_cipher, r, RSA_PKCS1_PADDING);
int token_cipher_length = RSA_public_encrypt(verify_token_length, verify_token, token_cipher, r, RSA_PKCS1_PADDING);
Expand Down Expand Up @@ -3785,7 +3785,7 @@ void read_socket(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
/* decrypt packet if needed */
if (bot->encryption_enabled) {
stream_data_raw = malloc(nread + bot->block_size);
if(!EVP_DecryptUpdate(&bot->ctx_decrypt, (unsigned char *)stream_data_raw, &data_length, (const unsigned char *)buf->base, nread)) {
if(!EVP_DecryptUpdate(bot->ctx_decrypt, (unsigned char *)stream_data_raw, &data_length, (const unsigned char *)buf->base, nread)) {
fprintf(stderr, "Decryption error.\n");
assert(0);
}
Expand Down