Skip to content

Commit

Permalink
add auth_chain_a
Browse files Browse the repository at this point in the history
  • Loading branch information
breakwa11 committed May 13, 2017
1 parent f1f70c4 commit 2439532
Show file tree
Hide file tree
Showing 13 changed files with 643 additions and 33 deletions.
38 changes: 36 additions & 2 deletions src/encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ static const CCMode supported_modes_applecc[CIPHER_NUM] = {
#endif

static const int supported_ciphers_iv_size[CIPHER_NUM] = {
0, 0, 0, 6, 16, 16, 16, 16, 16, 16, 16, 8, 16, 16, 16, 8, 8, 8, 8, 16, 8, 8, 12
0 , 0, 0, 6, 16, 16, 16, 16, 16, 16, 16, 8, 16, 16, 16, 8, 8, 8, 8, 16, 8, 8, 12
};

static const int supported_ciphers_key_size[CIPHER_NUM] = {
0, 0, 16, 16, 16, 16, 24, 32, 16, 24, 32, 16, 16, 24, 32, 16, 8, 16, 16, 16, 32, 32, 32
16, 16, 16, 16, 16, 16, 24, 32, 16, 24, 32, 16, 16, 24, 32, 16, 8, 16, 16, 16, 32, 32, 32
};

int
Expand Down Expand Up @@ -1318,6 +1318,40 @@ ss_decrypt(cipher_env_t* env, buffer_t *cipher, enc_ctx_t *ctx, size_t capacity)
}
}

int
ss_encrypt_buffer(cipher_env_t *env, enc_ctx_t *ctx, char *in, size_t in_size, char *out, size_t *out_size)
{
buffer_t cipher;
memset(&cipher, 0, sizeof(buffer_t));
balloc(&cipher, in_size + 32);
cipher.len = in_size;
memcpy(cipher.array, in, in_size);
int s = ss_encrypt(env, &cipher, ctx, in_size + 32);
if (s == 0) {
*out_size = cipher.len;
memcpy(out, cipher.array, cipher.len);
}
bfree(&cipher);
return s;
}

int
ss_decrypt_buffer(cipher_env_t *env, enc_ctx_t *ctx, char *in, size_t in_size, char *out, size_t *out_size)
{
buffer_t cipher;
memset(&cipher, 0, sizeof(buffer_t));
balloc(&cipher, in_size + 32);
cipher.len = in_size;
memcpy(cipher.array, in, in_size);
int s = ss_decrypt(env, &cipher, ctx, in_size + 32);
if (s == 0) {
*out_size = cipher.len;
memcpy(out, cipher.array, cipher.len);
}
bfree(&cipher);
return s;
}

void
enc_ctx_init(cipher_env_t *env, enc_ctx_t *ctx, int enc)
{
Expand Down
2 changes: 2 additions & 0 deletions src/encrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ int ss_md5_hash_func(char *auth, char *msg, int msg_len);
int ss_sha1_hmac_with_key(char *auth, char *msg, int msg_len, uint8_t *auth_key, int key_len);
int ss_sha1_hash_func(char *auth, char *msg, int msg_len);
int ss_aes_128_cbc(char *encrypt, char *out_data, char *key);
int ss_encrypt_buffer(cipher_env_t *env, enc_ctx_t *ctx, char *in, size_t in_size, char *out, size_t *out_size);
int ss_decrypt_buffer(cipher_env_t *env, enc_ctx_t *ctx, char *in, size_t in_size, char *out, size_t *out_size);

int balloc(buffer_t *ptr, size_t capacity);
int brealloc(buffer_t *ptr, size_t len, size_t capacity);
Expand Down
1 change: 1 addition & 0 deletions src/includeobfs.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _INCLUDEOBFSOBFS_H
#define _INCLUDEOBFSOBFS_H

#include "obfs/auth_chain.c"
#include "obfs/auth.c"
#include "obfs/tls1.2_ticket.c"
#include "obfs/verify.c"
Expand Down
4 changes: 3 additions & 1 deletion src/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
_server_info.iv_len = enc_get_iv_len(&server_env->cipher);
_server_info.key = enc_get_key(&server_env->cipher);
_server_info.key_len = enc_get_key_len(&server_env->cipher);
_server_info.tcp_mss = 1448;
_server_info.tcp_mss = 1452;
_server_info.buffer_size = BUF_SIZE;
_server_info.cipher_env = &server_env->cipher;

Expand All @@ -807,6 +807,8 @@ server_recv_cb(EV_P_ ev_io *w, int revents)

if (server_env->protocol_plugin) {
server->protocol = server_env->protocol_plugin->new_obfs();
_server_info.overhead = server_env->protocol_plugin->get_overhead(server->protocol)
+ (server_env->obfs_plugin ? server_env->obfs_plugin->get_overhead(server->obfs) : 0);
server_env->protocol_plugin->set_server_info(server->protocol, &_server_info);
}
// SSR end
Expand Down
13 changes: 2 additions & 11 deletions src/obfs/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ int auth_simple_pack_data(char *data, int datalength, char *outdata) {
return out_size;
}

void memintcopy_lt(void *mem, uint32_t val) {
((uint8_t *)mem)[0] = (uint8_t)(val);
((uint8_t *)mem)[1] = (uint8_t)(val >> 8);
((uint8_t *)mem)[2] = (uint8_t)(val >> 16);
((uint8_t *)mem)[3] = (uint8_t)(val >> 24);
}

int auth_simple_pack_auth_data(auth_simple_global_data *global, char *data, int datalength, char *outdata) {
unsigned char rand_len = (xorshift128plus() & 0xF) + 1;
int out_size = rand_len + datalength + 6 + 12;
Expand Down Expand Up @@ -796,11 +789,9 @@ int auth_aes128_sha1_pack_auth_data(auth_simple_global_data *global, server_info
}

{
uint8_t rnd[1];
rand_bytes(rnd, 1);
memcpy(outdata, rnd, 1);
rand_bytes(outdata, 1);
char hash[20];
local->hmac(hash, (char *)rnd, 1, key, key_len);
local->hmac(hash, (char *)outdata, 1, key, key_len);
memcpy(outdata + 1, hash, 6);
}

Expand Down
Loading

0 comments on commit 2439532

Please sign in to comment.