Commit Graph
34 Commits
Author SHA1 Message Date
Syrone Wong 7df4178db8 update entropy info based on libsodium documentation 2017-11-13 08:21:51 +08:00
Syrone Wong 836d2f3859 fix header
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2017-03-19 17:37:07 +08:00
Syrone Wong 1e91b6a1f6 On Linux, warn when we are running low on entropy
Based on https://github.com/jedisct1/dnscrypt-proxy/commit/a255d2908305739b54dafb01ae0285f6016869ab

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2017-03-19 17:16:19 +08:00
Syrone Wong b74108db09 drop redundant sodium_init() call
It is done in crypto.c

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2017-03-19 17:16:19 +08:00
Syrone Wong 80ca9469e6 Output error log when repeat IV/salt detected
This is useful when checking connection issues, and can be used to
check broken random number generator and replay attacks.

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2017-02-14 19:41:46 +08:00
Syrone Wong 637f207934 mbedtls: Make rc4, camellia, blowfish cipher checks optional
Per Felix Fietkau's request in https://github.com/lede-project/source/pull/657

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2017-01-06 22:26:14 -06:00
Syrone Wong e6c0780435 memset zero before using
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-12-10 21:37:56 -06:00
Syrone Wong 9db8c3abe8 zeroize some structs before using
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-12-08 04:11:43 -06:00
Syrone Wong cbe12c30fe Update uthash to latest
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-12-08 04:10:52 -06:00
Syrone Wong baff29e970 Fix issues found by cppcheck
- GNU treats void* as char* when doing pointer arithmetic, so let's make it clear
- Fix memory leak, save copy from malloc() and pass the original pointer to free()
- minor type mismatches

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-12-07 22:30:47 -06:00
Syrone Wong 43a236d3ca Clarify calculation precedence for '&' and '?' (#986) 2016-12-07 20:05:36 -06:00
Syrone Wong 5ac0e410e9 Switch random generator to libsodium's (#896)
to get rid of self written code and make it clean.

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-21 14:44:07 +08:00
Syrone Wong e0d6dd8f3c libcork: use API where supported (#860)
- The usage of `pthread_setname_np` is not supported on versions of
  glibc earlier than 2.12. This patch checks the glibc MINOR version and
  only uses that API where supported.
- This will suppress undeclared function warning when compiling
  with uClibc/musl-libc.

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-09-30 18:33:26 -05:00
Syrone Wong dbad716c3d Update libcork to 0.15.0 (#856)
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-09-29 18:00:15 -05:00
Syrone Wong b5c64b925f Add AES-CTR ciphers info (#820)
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-09-10 14:03:16 +08:00
Syrone Wong 84cc109743 openwrt: disable documentation build by default (#760)
Debloating asciidoc and xmlto makes life easier on OpenWrt/LEDE.

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-08-04 20:24:28 -05:00
Syrone Wong b1f5c68650 Fix typo (found by codespell) (#753)
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-08-03 06:50:43 -05:00
Syrone Wong 7bc66eca3f fix disable-documentation option (#700)
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-07-04 08:04:57 -05:00
Syrone Wong 7481ffffc7 clarify encrypt method info
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-04-24 21:25:26 +08:00
Syrone Wong 0bbf6c36a7 use sodium_memzero() to clear sensitive data
Close #603

After use, sensitive data should be overwritten, but memset() and hand-written code can be silently stripped out by an optimizing compiler or by the linker.

The sodium_memzero() function tries to effectively zero len bytes starting at pnt, even if optimizations are being applied to the code.

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-04-22 18:00:19 +08:00
Syrone Wong ebe79bbbd8 Refine memory management (#579)
- Added one macro to avoid dangling pointers
- Added two functions to perform NULL pointer check
  since the allocation is not guaranteed by C library, although it
  is a rare case, just for sanity
- Add NULL pointer check to brealloc() and bfree() and for sanity as well

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-04-15 09:16:38 -07:00
Syrone Wong 446e570b7d libudns: add definition to enable IPv6 support
This is an option in the origin configure script, add this to configure.ac to generate
config.h since submodules are sharing the same file.

All checks needed are guaranteed, thus simply add it to the ending of file.

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-04-15 08:36:29 -07:00
Syrone Wong 53c6a09b93 Reset errno to 0 before checking it
errno is never set to zero by any system call or library function,
and it's programmer's resposibility to reset it before doing checks.
Otherwise the error might be misleading.

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-04-15 08:35:16 -07:00
Syrone Wong 06d92c923c compare port as well
The whole remote_ctx is inserted into the cache and sockaddr_storage contains
both address and port.

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-04-15 08:34:35 -07:00
Syrone Wong a17d2f19ac Fix sockaddr comparison (#575)
This may fix #565

It is not recommended to compare two structs via memcmp although they have been
memset to 0.
Added two helper functions to compare sockaddr_storage, one for address only and
the other one takes port into account.

These two functions are based on Unbound version in util/net_help.c, and
comform needs of shadowsocks-libev.

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-04-08 17:26:11 -07:00
Syrone Wong 58264c77fc Polish code
code issues found by Clang with
CFLAGS="-Os -Wall -Wextra -Werror=unused-const-variable -Wno-error=unused-parameter"
enabled

The details as follows:
- variable initialization issue, modified them as Clang suggested
- data type mismatch when comparing, fix them either by casting or changing
  the data type of index of iterator
- get_sockaddr() in netutils may return -1 thus changed returning type from
  size_t to ssize_t, which makes Clang happier
- recvfrom() in udprelay is identical, fix this by creating local variable
  for comparison  and assign back to buf->len when returning value is acceptable

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-04-07 21:28:23 -07:00
Syrone Wong 5c3ed5c9c1 add IETF-compatible Chacha20 cipher support
Note:
- ChaCha20 with an extended (96 bit) nonce and a 32-bit counter has
been implemented as crypto_stream_chacha20_ietf() from LibSodium 1.0.4
- The name of new cipher is "chacha20-ietf"

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2015-12-13 19:30:41 +08:00
Syrone Wong 06eef7fdd1 use sha1_hmac function directly for PolarSSL
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2015-12-08 11:46:54 +08:00
Syrone Wong 0f4db65e23 use mbed TLS provided sha1-hmac function
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2015-12-06 12:28:41 +08:00
Syrone Wong a8059f4e6f Fix typo in encrypt.c
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2015-08-10 19:26:01 +08:00
Syrone Wong a135d9c41e libsodium: Fix _FORTIFY_SOURCE redefined issue
If we already defined `CFLAGS=-D_FORTIFY_SOURCE=1`, it will still check `-D_FORTIFY_SOURCE=2` and
add it to CPPFLAGS. In this case, we redefine `_FORTIFY_SOURCE` to both 1 and 2 if compiler accepts `-D_FORTIFY_SOURCE=2`.

Fix this issue by checking whether `_FORTIFY_SOURCE` was defined or not.
If defined, do nothing. If not, then check `-D_FORTIFY_SOURCE=2`.

BTW, OpenWrt's buildroot uses `-D_FORTIFY_SOURCE=1` for most targets by default.
2015-08-02 10:21:42 +08:00
Syrone Wong b232d3bbb6 generate config.h.in for mbed TLS support 2015-08-01 20:46:30 +08:00
Syrone Wong 56daf99944 Add more mbed TLS cipher check
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2015-08-01 11:16:33 +08:00
Syrone Wong e81b205e61 Add mbed TLS support for shadowsocks-libev
Notes:
- Test cipher CFB support just in case (i.e. OpenWrt disabled it)
- Added some inline notes, please feel free to modify or remove them.
- Sorry for my bad English
- If you want to compile for OpenWrt, please make sure this hunk[1] not exists.
- Only tested on ARM mamba (Linksys WRT1900AC v1), it works.

[1] https://github.com/openwrt-mirror/openwrt/blob/master/package/libs/mbedtls/patches/200-config.patch#L12-L20

Have fun!

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2015-08-01 07:52:04 +08:00