Skip to content

Commit

Permalink
Fix UDP relay issue on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
madeye committed Feb 3, 2017
1 parent 7ef88b1 commit a906d0c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,7 @@ aead_encrypt_all(buffer_t *plaintext, cipher_t *cipher, size_t capacity)
ciphertext->len = tag_len + plaintext->len;

// generate nonce
uint8_t nonce[MAX_NONCE_LENGTH];
rand_bytes(nonce, nonce_len);

uint8_t *nonce = cipher_ctx.nonce;
/* copy nonce to first pos */
memcpy(ciphertext->data, nonce, nonce_len);

Expand Down Expand Up @@ -460,7 +458,7 @@ aead_decrypt_all(buffer_t *ciphertext, cipher_t *cipher, size_t capacity)
plaintext->len = ciphertext->len - nonce_len - tag_len;

/* get nonce */
uint8_t nonce[MAX_NONCE_LENGTH];
uint8_t *nonce = cipher_ctx.nonce;
memcpy(nonce, ciphertext->data, nonce_len);

size_t plen = plaintext->len;
Expand Down
2 changes: 2 additions & 0 deletions src/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,11 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
int err;
struct sockaddr_storage storage;
memset(&storage, 0, sizeof(struct sockaddr_storage));
#ifndef ANDROID
if (sni_detected || atyp == 3)
err = get_sockaddr(host, port, &storage, 0, ipv6first);
else
#endif
err = get_sockaddr(ip, port, &storage, 0, ipv6first);

This comment has been minimized.

Copy link
@Mygod

Mygod Jul 30, 2018

Actually this also causes the problem of ip not initialized. This code is terrible. 😓

if (err != -1) {
remote = create_remote(server->listener, (struct sockaddr *)&storage);
Expand Down
6 changes: 2 additions & 4 deletions src/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ stream_encrypt_all(buffer_t *plaintext, cipher_t *cipher, size_t capacity)
buffer_t *ciphertext = &tmp;
ciphertext->len = plaintext->len;

uint8_t nonce[MAX_NONCE_LENGTH];

rand_bytes(nonce, nonce_len);
uint8_t *nonce = cipher_ctx.nonce;
cipher_ctx_set_nonce(&cipher_ctx, nonce, nonce_len, 1);
memcpy(ciphertext->data, nonce, nonce_len);

Expand Down Expand Up @@ -449,7 +447,7 @@ stream_decrypt_all(buffer_t *ciphertext, cipher_t *cipher, size_t capacity)
buffer_t *plaintext = &tmp;
plaintext->len = ciphertext->len - nonce_len;

uint8_t nonce[MAX_NONCE_LENGTH];
uint8_t *nonce = cipher_ctx.nonce;
memcpy(nonce, ciphertext->data, nonce_len);
cipher_ctx_set_nonce(&cipher_ctx, nonce, nonce_len, 0);

Expand Down

0 comments on commit a906d0c

Please sign in to comment.