Browse Source

Fix UDP relay issue on Android

pull/1179/head
Max Lv 8 years ago
parent
commit
a906d0cfc8
3 changed files with 6 additions and 8 deletions
  1. 6
      src/aead.c
  2. 2
      src/local.c
  3. 6
      src/stream.c

6
src/aead.c

@ -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);
@ -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;

2
src/local.c

@ -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);
if (err != -1) {
remote = create_remote(server->listener, (struct sockaddr *)&storage);

6
src/stream.c

@ -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);
@ -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);

Loading…
Cancel
Save