summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.appveyor.yml62
-rw-r--r--.editorconfig33
-rw-r--r--.gitignore41
-rw-r--r--.travis.yml5
-rw-r--r--CONTRIBUTING39
-rw-r--r--ChangeLog1310
-rw-r--r--LICENSE2
-rw-r--r--Makefile.am99
-rw-r--r--ReleaseNotes977
-rw-r--r--acinclude.m42
-rw-r--r--changes/181054
-rw-r--r--changes/243788
-rw-r--r--changes/258573
-rw-r--r--changes/bug189186
-rw-r--r--changes/bug208874
-rw-r--r--changes/bug221563
-rw-r--r--changes/bug230944
-rw-r--r--changes/bug231076
-rw-r--r--changes/bug23693.14
-rw-r--r--changes/bug239094
-rw-r--r--changes/bug2403113
-rw-r--r--changes/bug244844
-rw-r--r--changes/bug246883
-rw-r--r--changes/bug248914
-rw-r--r--changes/bug249107
-rw-r--r--changes/bug249143
-rw-r--r--changes/bug249693
-rw-r--r--changes/bug249775
-rw-r--r--changes/bug252264
-rw-r--r--changes/bug253737
-rw-r--r--changes/bug253985
-rw-r--r--changes/bug253995
-rw-r--r--changes/bug254005
-rw-r--r--changes/bug2540912
-rw-r--r--changes/bug254154
-rw-r--r--changes/bug254254
-rw-r--r--changes/bug254773
-rw-r--r--changes/bug255125
-rw-r--r--changes/bug256754
-rw-r--r--changes/bug25686_diagnostic4
-rw-r--r--changes/bug25691_again6
-rw-r--r--changes/bug257055
-rw-r--r--changes/bug257877
-rw-r--r--changes/bug258287
-rw-r--r--changes/bug258433
-rw-r--r--changes/bug258867
-rw-r--r--changes/bug259013
-rw-r--r--changes/bug260075
-rw-r--r--changes/bug261524
-rw-r--r--changes/bug261585
-rw-r--r--changes/bug261967
-rw-r--r--changes/bug262143
-rw-r--r--changes/bug262453
-rw-r--r--changes/bug26258_0334
-rw-r--r--changes/bug262824
-rw-r--r--changes/bug264024
-rw-r--r--changes/bug264153
-rw-r--r--changes/bug264355
-rw-r--r--changes/coveralls3
-rw-r--r--changes/feature194295
-rw-r--r--changes/feature251504
-rw-r--r--changes/feature26372_0294
-rw-r--r--changes/feature83233
-rw-r--r--changes/full_include_paths3
-rw-r--r--changes/isolate_libevent5
-rw-r--r--changes/split_or_h5
-rw-r--r--changes/ticket199793
-rw-r--r--changes/ticket205226
-rw-r--r--changes/ticket233546
-rw-r--r--changes/ticket238736
-rw-r--r--changes/ticket247146
-rw-r--r--changes/ticket247346
-rw-r--r--changes/ticket247405
-rw-r--r--changes/ticket250244
-rw-r--r--changes/ticket250815
-rw-r--r--changes/ticket251626
-rw-r--r--changes/ticket252613
-rw-r--r--changes/ticket252687
-rw-r--r--changes/ticket252905
-rw-r--r--changes/ticket253746
-rw-r--r--changes/ticket25376_2576210
-rw-r--r--changes/ticket254096
-rw-r--r--changes/ticket254326
-rw-r--r--changes/ticket255115
-rw-r--r--changes/ticket256105
-rw-r--r--changes/ticket256454
-rw-r--r--changes/ticket257605
-rw-r--r--changes/ticket257663
-rw-r--r--changes/ticket25927.16
-rw-r--r--changes/ticket25927.25
-rw-r--r--changes/ticket259319
-rw-r--r--changes/ticket259329
-rw-r--r--changes/ticket259379
-rw-r--r--changes/ticket259474
-rw-r--r--changes/ticket259489
-rw-r--r--changes/ticket259499
-rw-r--r--changes/ticket259519
-rw-r--r--changes/ticket259529
-rw-r--r--changes/ticket259605
-rw-r--r--changes/ticket259955
-rw-r--r--changes/ticket259965
-rw-r--r--changes/ticket259975
-rw-r--r--changes/ticket260144
-rw-r--r--changes/ticket264264
-rw-r--r--changes/ticket264276
-rw-r--r--changes/ticket41873
-rw-r--r--changes/ticket62364
-rw-r--r--changes/travis_distcheck4
-rw-r--r--config.rust.in22
-rw-r--r--configure.ac84
-rw-r--r--contrib/win32build/tor-mingw.nsi.in2
-rw-r--r--doc/HACKING/CodingStandards.md21
-rw-r--r--doc/HACKING/HelpfulTools.md10
-rw-r--r--doc/tor.1.txt18
-rw-r--r--link_rust.sh.in10
-rwxr-xr-xscripts/codegen/gen_server_ciphers.py2
-rwxr-xr-xscripts/codegen/get_mozilla_ciphers.py2
-rw-r--r--scripts/codegen/makedesc.py2
-rwxr-xr-xscripts/maint/checkIncludes.py72
-rwxr-xr-xscripts/maint/checkSpace.pl16
-rwxr-xr-xscripts/maint/format_changelog.py2
-rwxr-xr-xscripts/maint/rectify_include_paths.py60
-rwxr-xr-xscripts/maint/redox.py2
-rwxr-xr-xscripts/maint/sortChanges.py2
-rwxr-xr-xscripts/maint/updateCopyright.pl4
-rw-r--r--scripts/test/appveyor-irc-notify.py192
-rwxr-xr-xscripts/test/cov-diff6
-rw-r--r--src/common/.may_include11
-rw-r--r--src/common/address.c19
-rw-r--r--src/common/address.h32
-rw-r--r--src/common/address_set.c15
-rw-r--r--src/common/address_set.h4
-rw-r--r--src/common/aes.c (renamed from src/lib/crypt_ops/aes.c)18
-rw-r--r--src/common/aes.h (renamed from src/lib/crypt_ops/aes.h)2
-rw-r--r--src/common/backtrace.c (renamed from src/lib/err/backtrace.c)104
-rw-r--r--src/common/backtrace.h (renamed from src/lib/err/backtrace.h)14
-rw-r--r--src/common/buffers.c14
-rw-r--r--src/common/buffers.h8
-rw-r--r--src/common/buffers_tls.c (renamed from src/lib/tls/buffers_tls.c)18
-rw-r--r--src/common/buffers_tls.h (renamed from src/lib/tls/buffers_tls.h)2
-rw-r--r--src/common/ciphers.inc (renamed from src/lib/tls/ciphers.inc)0
-rw-r--r--src/common/compat.c499
-rw-r--r--src/common/compat.h319
-rw-r--r--src/common/compat_libevent.c43
-rw-r--r--src/common/compat_libevent.h6
-rw-r--r--src/common/compat_openssl.h (renamed from src/lib/crypt_ops/compat_openssl.h)10
-rw-r--r--src/common/compat_pthreads.c94
-rw-r--r--src/common/compat_threads.c38
-rw-r--r--src/common/compat_threads.h48
-rw-r--r--src/common/compat_time.c65
-rw-r--r--src/common/compat_time.h7
-rw-r--r--src/common/compat_winthreads.c37
-rw-r--r--src/common/compress.c (renamed from src/lib/compress/compress.c)19
-rw-r--r--src/common/compress.h (renamed from src/lib/compress/compress.h)2
-rw-r--r--src/common/compress_lzma.c (renamed from src/lib/compress/compress_lzma.c)10
-rw-r--r--src/common/compress_lzma.h (renamed from src/lib/compress/compress_lzma.h)2
-rw-r--r--src/common/compress_none.c (renamed from src/lib/compress/compress_none.c)10
-rw-r--r--src/common/compress_none.h (renamed from src/lib/compress/compress_none.h)2
-rw-r--r--src/common/compress_zlib.c (renamed from src/lib/compress/compress_zlib.c)10
-rw-r--r--src/common/compress_zlib.h (renamed from src/lib/compress/compress_zlib.h)2
-rw-r--r--src/common/compress_zstd.c (renamed from src/lib/compress/compress_zstd.c)12
-rw-r--r--src/common/compress_zstd.h (renamed from src/lib/compress/compress_zstd.h)2
-rw-r--r--src/common/confline.c13
-rw-r--r--src/common/confline.h7
-rw-r--r--src/common/container.c (renamed from src/lib/container/smartlist.c)518
-rw-r--r--src/common/container.h742
-rw-r--r--src/common/crypto.c1124
-rw-r--r--src/common/crypto.h (renamed from src/lib/crypt_ops/crypto.h)48
-rw-r--r--src/common/crypto_curve25519.c (renamed from src/lib/crypt_ops/crypto_curve25519.c)17
-rw-r--r--src/common/crypto_curve25519.h (renamed from src/lib/crypt_ops/crypto_curve25519.h)10
-rw-r--r--src/common/crypto_digest.c (renamed from src/lib/crypt_ops/crypto_digest.c)28
-rw-r--r--src/common/crypto_digest.h (renamed from src/lib/crypt_ops/crypto_digest.h)20
-rw-r--r--src/common/crypto_ed25519.c (renamed from src/lib/crypt_ops/crypto_ed25519.c)20
-rw-r--r--src/common/crypto_ed25519.h (renamed from src/lib/crypt_ops/crypto_ed25519.h)10
-rw-r--r--src/common/crypto_format.c (renamed from src/lib/crypt_ops/crypto_format.c)22
-rw-r--r--src/common/crypto_format.h (renamed from src/lib/crypt_ops/crypto_format.h)8
-rw-r--r--src/common/crypto_openssl_mgt.c (renamed from src/lib/crypt_ops/crypto_openssl_mgt.c)8
-rw-r--r--src/common/crypto_openssl_mgt.h (renamed from src/lib/crypt_ops/crypto_openssl_mgt.h)4
-rw-r--r--src/common/crypto_pwbox.c (renamed from src/lib/crypt_ops/crypto_pwbox.c)22
-rw-r--r--src/common/crypto_pwbox.h (renamed from src/lib/crypt_ops/crypto_pwbox.h)4
-rw-r--r--src/common/crypto_rand.c (renamed from src/lib/crypt_ops/crypto_rand.c)27
-rw-r--r--src/common/crypto_rand.h (renamed from src/lib/crypt_ops/crypto_rand.h)6
-rw-r--r--src/common/crypto_rsa.c (renamed from src/lib/crypt_ops/crypto_rsa.c)47
-rw-r--r--src/common/crypto_rsa.h (renamed from src/lib/crypt_ops/crypto_rsa.h)14
-rw-r--r--src/common/crypto_s2k.c (renamed from src/lib/crypt_ops/crypto_s2k.c)17
-rw-r--r--src/common/crypto_s2k.h (renamed from src/lib/crypt_ops/crypto_s2k.h)4
-rw-r--r--src/common/crypto_util.c (renamed from src/lib/crypt_ops/crypto_util.c)27
-rw-r--r--src/common/crypto_util.h (renamed from src/lib/crypt_ops/crypto_util.h)5
-rw-r--r--src/common/di_ops.c (renamed from src/lib/ctime/di_ops.c)23
-rw-r--r--src/common/di_ops.h (renamed from src/lib/ctime/di_ops.h)4
-rw-r--r--src/common/handles.h4
-rw-r--r--src/common/include.am113
-rw-r--r--src/common/log.c (renamed from src/lib/log/torlog.c)161
-rw-r--r--src/common/memarea.c11
-rw-r--r--src/common/memarea.h2
-rw-r--r--src/common/procmon.c6
-rw-r--r--src/common/procmon.h8
-rw-r--r--src/common/pubsub.c129
-rw-r--r--src/common/pubsub.h179
-rw-r--r--src/common/sandbox.c20
-rw-r--r--src/common/sandbox.h4
-rw-r--r--src/common/storagedir.c19
-rw-r--r--src/common/storagedir.h2
-rw-r--r--src/common/testsupport.h (renamed from src/lib/testsupport/testsupport.h)2
-rw-r--r--src/common/timers.c12
-rw-r--r--src/common/timers.h4
-rw-r--r--src/common/token_bucket.c8
-rw-r--r--src/common/token_bucket.h6
-rw-r--r--src/common/torint.h (renamed from src/lib/cc/torint.h)2
-rw-r--r--src/common/torlog.h (renamed from src/lib/log/torlog.h)17
-rw-r--r--src/common/tortls.c (renamed from src/lib/tls/tortls.c)25
-rw-r--r--src/common/tortls.h (renamed from src/lib/tls/tortls.h)10
-rw-r--r--src/common/util.c1273
-rw-r--r--src/common/util.h246
-rw-r--r--src/common/util_bug.c (renamed from src/lib/log/util_bug.c)41
-rw-r--r--src/common/util_bug.h (renamed from src/lib/log/util_bug.h)16
-rw-r--r--src/common/util_format.c49
-rw-r--r--src/common/util_format.h8
-rw-r--r--src/common/util_process.c10
-rw-r--r--src/common/util_process.h2
-rw-r--r--src/common/workqueue.c14
-rw-r--r--src/common/workqueue.h4
-rw-r--r--src/config/geoip10557
-rw-r--r--src/config/geoip61757
-rw-r--r--src/ext/OpenBSD_malloc_Linux.c2
-rw-r--r--src/ext/csiphash.c4
-rw-r--r--src/ext/curve25519_donna/curve25519-donna-c64.c2
-rw-r--r--src/ext/curve25519_donna/curve25519-donna.c2
-rw-r--r--src/ext/ed25519/donna/ed25519-hash-custom.h2
-rw-r--r--src/ext/ed25519/donna/ed25519-randombytes-custom.h2
-rw-r--r--src/ext/ed25519/donna/ed25519_donna_tor.h2
-rw-r--r--src/ext/ed25519/donna/ed25519_tor.c2
-rw-r--r--src/ext/ed25519/ref10/blinding.c2
-rw-r--r--src/ext/ed25519/ref10/crypto_hash_sha512.h2
-rw-r--r--src/ext/ed25519/ref10/crypto_int32.h2
-rw-r--r--src/ext/ed25519/ref10/crypto_int64.h2
-rw-r--r--src/ext/ed25519/ref10/crypto_uint32.h2
-rw-r--r--src/ext/ed25519/ref10/crypto_uint64.h2
-rw-r--r--src/ext/ed25519/ref10/crypto_verify_32.h3
-rw-r--r--src/ext/ed25519/ref10/ed25519_ref10.h2
-rw-r--r--src/ext/ed25519/ref10/keypair.c5
-rw-r--r--src/ext/ed25519/ref10/randombytes.h2
-rw-r--r--src/ext/ht.h2
-rw-r--r--src/ext/keccak-tiny/keccak-tiny-unrolled.c2
-rw-r--r--src/ext/keccak-tiny/keccak-tiny.h2
-rw-r--r--src/ext/mulodi/mulodi4.c2
m---------src/ext/rust0
-rw-r--r--src/include.am21
-rw-r--r--src/lib/cc/.may_include1
-rw-r--r--src/lib/cc/compat_compiler.h259
-rw-r--r--src/lib/cc/include.am4
-rw-r--r--src/lib/compress/.may_include7
-rw-r--r--src/lib/compress/include.am25
-rw-r--r--src/lib/container/.may_include16
-rw-r--r--src/lib/container/bitarray.h80
-rw-r--r--src/lib/container/bloomfilt.c46
-rw-r--r--src/lib/container/bloomfilt.h58
-rw-r--r--src/lib/container/include.am24
-rw-r--r--src/lib/container/map.c412
-rw-r--r--src/lib/container/map.h255
-rw-r--r--src/lib/container/order.c48
-rw-r--r--src/lib/container/order.h54
-rw-r--r--src/lib/container/smartlist.h360
-rw-r--r--src/lib/crypt_ops/.may_include22
-rw-r--r--src/lib/crypt_ops/crypto.c509
-rw-r--r--src/lib/crypt_ops/crypto_dh.c510
-rw-r--r--src/lib/crypt_ops/crypto_dh.h49
-rw-r--r--src/lib/crypt_ops/crypto_hkdf.c193
-rw-r--r--src/lib/crypt_ops/crypto_hkdf.h28
-rw-r--r--src/lib/crypt_ops/include.am44
-rw-r--r--src/lib/ctime/.may_include5
-rw-r--r--src/lib/ctime/include.am25
-rw-r--r--src/lib/defs/.may_include1
-rw-r--r--src/lib/defs/digest_sizes.h18
-rw-r--r--src/lib/defs/include.am3
-rw-r--r--src/lib/err/.may_include3
-rw-r--r--src/lib/err/include.am19
-rw-r--r--src/lib/err/torerr.c230
-rw-r--r--src/lib/err/torerr.h47
-rw-r--r--src/lib/fdio/.may_include4
-rw-r--r--src/lib/fdio/fdio.c109
-rw-r--r--src/lib/fdio/fdio.h17
-rw-r--r--src/lib/fdio/include.am17
-rw-r--r--src/lib/include.libdonna.am24
-rw-r--r--src/lib/intmath/.may_include4
-rw-r--r--src/lib/intmath/addsub.c20
-rw-r--r--src/lib/intmath/addsub.h13
-rw-r--r--src/lib/intmath/bits.c88
-rw-r--r--src/lib/intmath/bits.h16
-rw-r--r--src/lib/intmath/cmp.h20
-rw-r--r--src/lib/intmath/include.am22
-rw-r--r--src/lib/intmath/muldiv.c75
-rw-r--r--src/lib/intmath/muldiv.h22
-rw-r--r--src/lib/lock/.may_include5
-rw-r--r--src/lib/lock/compat_mutex.c34
-rw-r--r--src/lib/lock/compat_mutex.h60
-rw-r--r--src/lib/lock/compat_mutex_pthreads.c97
-rw-r--r--src/lib/lock/compat_mutex_winthreads.c40
-rw-r--r--src/lib/lock/include.am24
-rw-r--r--src/lib/log/.may_include15
-rw-r--r--src/lib/log/include.am24
-rw-r--r--src/lib/log/ratelim.c55
-rw-r--r--src/lib/log/ratelim.h48
-rw-r--r--src/lib/malloc/.may_include6
-rw-r--r--src/lib/malloc/include.am17
-rw-r--r--src/lib/malloc/util_malloc.c230
-rw-r--r--src/lib/malloc/util_malloc.h92
-rw-r--r--src/lib/string/.may_include9
-rw-r--r--src/lib/string/compat_ctype.c67
-rw-r--r--src/lib/string/compat_ctype.h62
-rw-r--r--src/lib/string/compat_string.c14
-rw-r--r--src/lib/string/compat_string.h39
-rw-r--r--src/lib/string/include.am25
-rw-r--r--src/lib/string/printf.c152
-rw-r--r--src/lib/string/printf.h25
-rw-r--r--src/lib/string/scanf.c312
-rw-r--r--src/lib/string/scanf.h19
-rw-r--r--src/lib/string/util_string.c340
-rw-r--r--src/lib/string/util_string.h42
-rw-r--r--src/lib/testsupport/include.am3
-rw-r--r--src/lib/tls/.may_include13
-rw-r--r--src/lib/tls/include.am20
-rw-r--r--src/lib/trace/.may_include3
-rw-r--r--src/lib/trace/include.am18
-rw-r--r--src/lib/wallclock/.may_include6
-rw-r--r--src/lib/wallclock/approx_time.c38
-rw-r--r--src/lib/wallclock/approx_time.h20
-rw-r--r--src/lib/wallclock/include.am21
-rw-r--r--src/lib/wallclock/tm_cvt.c195
-rw-r--r--src/lib/wallclock/tm_cvt.h17
-rw-r--r--src/lib/wallclock/tor_gettimeofday.c82
-rw-r--r--src/lib/wallclock/tor_gettimeofday.h15
-rw-r--r--src/or/addressmap.c28
-rw-r--r--src/or/addressmap.h4
-rw-r--r--src/or/auth_dirs.inc1
-rw-r--r--src/or/authority_cert_st.h32
-rw-r--r--src/or/bridges.c33
-rw-r--r--src/or/bridges.h2
-rw-r--r--src/or/cached_dir_st.h25
-rw-r--r--src/or/cell_queue_st.h28
-rw-r--r--src/or/cell_st.h20
-rw-r--r--src/or/channel.c48
-rw-r--r--src/or/channel.h10
-rw-r--r--src/or/channelpadding.c33
-rw-r--r--src/or/channelpadding.h4
-rw-r--r--src/or/channeltls.c53
-rw-r--r--src/or/channeltls.h6
-rw-r--r--src/or/circpathbias.c34
-rw-r--r--src/or/circpathbias.h2
-rw-r--r--src/or/circuit_st.h172
-rw-r--r--src/or/circuitbuild.c225
-rw-r--r--src/or/circuitbuild.h11
-rw-r--r--src/or/circuitlist.c110
-rw-r--r--src/or/circuitlist.h15
-rw-r--r--src/or/circuitmux.c16
-rw-r--r--src/or/circuitmux.h6
-rw-r--r--src/or/circuitmux_ewma.c12
-rw-r--r--src/or/circuitmux_ewma.h6
-rw-r--r--src/or/circuitstats.c70
-rw-r--r--src/or/circuitstats.h17
-rw-r--r--src/or/circuituse.c105
-rw-r--r--src/or/circuituse.h4
-rw-r--r--src/or/command.c45
-rw-r--r--src/or/command.h4
-rw-r--r--src/or/config.c148
-rw-r--r--src/or/config.h11
-rw-r--r--src/or/confparse.c12
-rw-r--r--src/or/confparse.h2
-rw-r--r--src/or/connection.c160
-rw-r--r--src/or/connection.h58
-rw-r--r--src/or/connection_edge.c128
-rw-r--r--src/or/connection_edge.h10
-rw-r--r--src/or/connection_or.c87
-rw-r--r--src/or/connection_or.h4
-rw-r--r--src/or/connection_st.h131
-rw-r--r--src/or/conscache.c12
-rw-r--r--src/or/conscache.h4
-rw-r--r--src/or/consdiff.c11
-rw-r--r--src/or/consdiff.h7
-rw-r--r--src/or/consdiffmgr.c23
-rw-r--r--src/or/consdiffmgr.h2
-rw-r--r--src/or/control.c270
-rw-r--r--src/or/control.h7
-rw-r--r--src/or/control_connection_st.h46
-rw-r--r--src/or/cpath_build_state_st.h38
-rw-r--r--src/or/cpuworker.c32
-rw-r--r--src/or/cpuworker.h2
-rw-r--r--src/or/crypt_path_reference_st.h23
-rw-r--r--src/or/crypt_path_st.h56
-rw-r--r--src/or/desc_store_st.h34
-rw-r--r--src/or/destroy_cell_queue_st.h27
-rw-r--r--src/or/dir_connection_st.h66
-rw-r--r--src/or/dir_server_st.h54
-rw-r--r--src/or/dirauth/dircollate.c9
-rw-r--r--src/or/dirauth/dircollate.h6
-rw-r--r--src/or/dirauth/dirvote.c82
-rw-r--r--src/or/dirauth/dirvote.h6
-rw-r--r--src/or/dirauth/mode.h4
-rw-r--r--src/or/dirauth/shared_random.c39
-rw-r--r--src/or/dirauth/shared_random.h4
-rw-r--r--src/or/dirauth/shared_random_state.c24
-rw-r--r--src/or/dirauth/shared_random_state.h4
-rw-r--r--src/or/directory.c128
-rw-r--r--src/or/directory.h31
-rw-r--r--src/or/dirserv.c126
-rw-r--r--src/or/dirserv.h15
-rw-r--r--src/or/dns.c34
-rw-r--r--src/or/dns.h4
-rw-r--r--src/or/dns_structs.h2
-rw-r--r--src/or/dnsserv.c24
-rw-r--r--src/or/dnsserv.h2
-rw-r--r--src/or/document_signature_st.h29
-rw-r--r--src/or/dos.c29
-rw-r--r--src/or/dos.h2
-rw-r--r--src/or/download_status_st.h65
-rw-r--r--src/or/edge_connection_st.h77
-rw-r--r--src/or/entry_connection_st.h100
-rw-r--r--src/or/entry_port_cfg_st.h54
-rw-r--r--src/or/entrynodes.c69
-rw-r--r--src/or/entrynodes.h5
-rw-r--r--src/or/ext_orport.c26
-rw-r--r--src/or/ext_orport.h2
-rw-r--r--src/or/extend_info_st.h28
-rw-r--r--src/or/extrainfo_st.h30
-rw-r--r--src/or/fp_pair.c6
-rw-r--r--src/or/fp_pair.h8
-rw-r--r--src/or/geoip.c23
-rw-r--r--src/or/geoip.h6
-rw-r--r--src/or/git_revision.c4
-rw-r--r--src/or/git_revision.h2
-rw-r--r--src/or/hibernate.c120
-rw-r--r--src/or/hibernate.h6
-rw-r--r--src/or/hs_cache.c26
-rw-r--r--src/or/hs_cache.h12
-rw-r--r--src/or/hs_cell.c30
-rw-r--r--src/or/hs_cell.h6
-rw-r--r--src/or/hs_circuit.c53
-rw-r--r--src/or/hs_circuit.h8
-rw-r--r--src/or/hs_circuitmap.c13
-rw-r--r--src/or/hs_circuitmap.h2
-rw-r--r--src/or/hs_client.c59
-rw-r--r--src/or/hs_client.h8
-rw-r--r--src/or/hs_common.c69
-rw-r--r--src/or/hs_common.h6
-rw-r--r--src/or/hs_config.c10
-rw-r--r--src/or/hs_config.h4
-rw-r--r--src/or/hs_control.c21
-rw-r--r--src/or/hs_control.h4
-rw-r--r--src/or/hs_descriptor.c28
-rw-r--r--src/or/hs_descriptor.h15
-rw-r--r--src/or/hs_ident.c6
-rw-r--r--src/or/hs_ident.h6
-rw-r--r--src/or/hs_intropoint.c36
-rw-r--r--src/or/hs_intropoint.h10
-rw-r--r--src/or/hs_ntor.c8
-rw-r--r--src/or/hs_ntor.h4
-rw-r--r--src/or/hs_service.c95
-rw-r--r--src/or/hs_service.h18
-rw-r--r--src/or/hs_stats.c12
-rw-r--r--src/or/hsdir_index_st.h24
-rw-r--r--src/or/include.am95
-rw-r--r--src/or/keypin.c22
-rw-r--r--src/or/keypin.h4
-rw-r--r--src/or/listener_connection_st.h25
-rw-r--r--src/or/main.c375
-rw-r--r--src/or/main.h7
-rw-r--r--src/or/microdesc.c37
-rw-r--r--src/or/microdesc.h2
-rw-r--r--src/or/microdesc_st.h71
-rw-r--r--src/or/networkstatus.c185
-rw-r--r--src/or/networkstatus.h8
-rw-r--r--src/or/networkstatus_sr_info_st.h23
-rw-r--r--src/or/networkstatus_st.h95
-rw-r--r--src/or/networkstatus_voter_info_st.h30
-rw-r--r--src/or/node_st.h102
-rw-r--r--src/or/nodelist.c113
-rw-r--r--src/or/nodelist.h4
-rw-r--r--src/or/ns_detached_signatures_st.h22
-rw-r--r--src/or/ntmain.c10
-rw-r--r--src/or/ntmain.h2
-rw-r--r--src/or/onion.c36
-rw-r--r--src/or/onion.h2
-rw-r--r--src/or/onion_fast.c10
-rw-r--r--src/or/onion_fast.h2
-rw-r--r--src/or/onion_ntor.c15
-rw-r--r--src/or/onion_ntor.h8
-rw-r--r--src/or/onion_tap.c14
-rw-r--r--src/or/onion_tap.h2
-rw-r--r--src/or/or.h2341
-rw-r--r--src/or/or_circuit_st.h80
-rw-r--r--src/or/or_connection_st.h90
-rw-r--r--src/or/or_handshake_certs_st.h39
-rw-r--r--src/or/or_handshake_state_st.h78
-rw-r--r--src/or/origin_circuit_st.h235
-rw-r--r--src/or/parsecommon.c10
-rw-r--r--src/or/parsecommon.h19
-rw-r--r--src/or/periodic.c12
-rw-r--r--src/or/periodic.h2
-rw-r--r--src/or/policies.c57
-rw-r--r--src/or/policies.h2
-rw-r--r--src/or/port_cfg_st.h35
-rw-r--r--src/or/proto_cell.c12
-rw-r--r--src/or/proto_cell.h2
-rw-r--r--src/or/proto_control0.c8
-rw-r--r--src/or/proto_control0.h2
-rw-r--r--src/or/proto_ext_or.c10
-rw-r--r--src/or/proto_ext_or.h2
-rw-r--r--src/or/proto_http.c8
-rw-r--r--src/or/proto_http.h2
-rw-r--r--src/or/proto_socks.c22
-rw-r--r--src/or/proto_socks.h2
-rw-r--r--src/or/protover.c58
-rw-r--r--src/or/protover.h14
-rw-r--r--src/or/protover_rust.c23
-rw-r--r--src/or/reasons.c8
-rw-r--r--src/or/reasons.h2
-rw-r--r--src/or/relay.c159
-rw-r--r--src/or/relay.h6
-rw-r--r--src/or/relay_crypto.c17
-rw-r--r--src/or/relay_crypto.h2
-rw-r--r--src/or/relay_crypto_st.h27
-rw-r--r--src/or/rend_authorized_client_st.h18
-rw-r--r--src/or/rend_encoded_v2_service_descriptor_st.h17
-rw-r--r--src/or/rend_intro_point_st.h74
-rw-r--r--src/or/rend_service_descriptor_st.h34
-rw-r--r--src/or/rendcache.c22
-rw-r--r--src/or/rendcache.h6
-rw-r--r--src/or/rendclient.c62
-rw-r--r--src/or/rendclient.h4
-rw-r--r--src/or/rendcommon.c55
-rw-r--r--src/or/rendcommon.h2
-rw-r--r--src/or/rendmid.c28
-rw-r--r--src/or/rendmid.h2
-rw-r--r--src/or/rendservice.c72
-rw-r--r--src/or/rendservice.h6
-rw-r--r--src/or/rephist.c35
-rw-r--r--src/or/rephist.h2
-rw-r--r--src/or/replaycache.c6
-rw-r--r--src/or/replaycache.h2
-rw-r--r--src/or/router.c205
-rw-r--r--src/or/router.h16
-rw-r--r--src/or/routerinfo_st.h107
-rw-r--r--src/or/routerkeys.c16
-rw-r--r--src/or/routerkeys.h4
-rw-r--r--src/or/routerlist.c98
-rw-r--r--src/or/routerlist.h7
-rw-r--r--src/or/routerlist_st.h40
-rw-r--r--src/or/routerparse.c72
-rw-r--r--src/or/routerparse.h3
-rw-r--r--src/or/routerset.c26
-rw-r--r--src/or/routerset.h5
-rw-r--r--src/or/routerstatus_st.h80
-rw-r--r--src/or/scheduler.c18
-rw-r--r--src/or/scheduler.h8
-rw-r--r--src/or/scheduler_kist.c20
-rw-r--r--src/or/scheduler_vanilla.c10
-rw-r--r--src/or/server_port_cfg_st.h20
-rw-r--r--src/or/shared_random_client.c16
-rw-r--r--src/or/shared_random_client.h4
-rw-r--r--src/or/signed_descriptor_st.h61
-rw-r--r--src/or/socks_request_st.h59
-rw-r--r--src/or/statefile.c28
-rw-r--r--src/or/statefile.h2
-rw-r--r--src/or/status.c42
-rw-r--r--src/or/status.h4
-rw-r--r--src/or/tor_api.c6
-rw-r--r--src/or/tor_api.h2
-rw-r--r--src/or/tor_api_internal.h2
-rw-r--r--src/or/tor_main.c2
-rw-r--r--src/or/tor_version_st.h32
-rw-r--r--src/or/torcert.c22
-rw-r--r--src/or/torcert.h4
-rw-r--r--src/or/transports.c24
-rw-r--r--src/or/transports.h2
-rw-r--r--src/or/var_cell_st.h23
-rw-r--r--src/or/vote_microdesc_hash_st.h22
-rw-r--r--src/or/vote_routerstatus_st.h41
-rw-r--r--src/or/vote_timing_st.h24
-rw-r--r--src/or/voting_schedule.c38
-rw-r--r--src/or/voting_schedule.h8
-rw-r--r--src/rust/.cargo/config.in3
-rw-r--r--src/rust/Cargo.lock58
-rw-r--r--src/rust/Cargo.toml12
-rw-r--r--src/rust/build.rs187
-rw-r--r--src/rust/crypto/Cargo.toml28
-rw-r--r--src/rust/crypto/digests/mod.rs7
-rw-r--r--src/rust/crypto/digests/sha2.rs222
-rw-r--r--src/rust/crypto/lib.rs45
-rw-r--r--src/rust/external/Cargo.toml3
-rw-r--r--src/rust/external/crypto_digest.rs406
-rw-r--r--src/rust/external/external.rs2
-rw-r--r--src/rust/external/lib.rs3
-rw-r--r--src/rust/include.am11
-rw-r--r--src/rust/protover/Cargo.toml1
-rw-r--r--src/rust/protover/ffi.rs42
-rw-r--r--src/rust/protover/lib.rs2
-rw-r--r--src/rust/protover/protover.rs95
-rw-r--r--src/rust/protover/tests/protover.rs2
-rw-r--r--src/rust/rand/Cargo.toml27
-rw-r--r--src/rust/rand/lib.rs (renamed from src/rust/crypto/rand/mod.rs)10
-rw-r--r--src/rust/rand/rng.rs (renamed from src/rust/crypto/rand/rng.rs)8
-rw-r--r--src/rust/smartlist/lib.rs2
-rw-r--r--src/rust/smartlist/smartlist.rs2
-rw-r--r--src/rust/tor_allocate/lib.rs2
-rw-r--r--src/rust/tor_allocate/tor_allocate.rs2
-rw-r--r--src/rust/tor_log/Cargo.toml1
-rw-r--r--src/rust/tor_log/lib.rs2
-rw-r--r--src/rust/tor_log/tor_log.rs6
-rw-r--r--src/rust/tor_util/ffi.rs2
-rw-r--r--src/rust/tor_util/lib.rs2
-rw-r--r--src/rust/tor_util/strings.rs2
-rw-r--r--src/test/bench.c26
-rwxr-xr-xsrc/test/bt_test.py2
-rw-r--r--src/test/ed25519_exts_ref.py2
-rw-r--r--src/test/fakechans.h2
-rw-r--r--src/test/fuzz/dict/http2
-rw-r--r--src/test/fuzz/fuzz_consensus.c10
-rw-r--r--src/test/fuzz/fuzz_descriptor.c12
-rw-r--r--src/test/fuzz/fuzz_diff.c8
-rw-r--r--src/test/fuzz/fuzz_diff_apply.c8
-rw-r--r--src/test/fuzz/fuzz_extrainfo.c12
-rw-r--r--src/test/fuzz/fuzz_hsdescv2.c10
-rw-r--r--src/test/fuzz/fuzz_hsdescv3.c16
-rw-r--r--src/test/fuzz/fuzz_http.c20
-rw-r--r--src/test/fuzz/fuzz_http_connect.c23
-rw-r--r--src/test/fuzz/fuzz_iptsv2.c13
-rw-r--r--src/test/fuzz/fuzz_microdesc.c10
-rw-r--r--src/test/fuzz/fuzz_vrs.c18
-rw-r--r--src/test/fuzz/fuzzing.h2
-rw-r--r--src/test/fuzz/fuzzing_common.c14
-rw-r--r--src/test/fuzz/include.am18
-rwxr-xr-xsrc/test/fuzz_static_testcases.sh2
-rw-r--r--src/test/geoip_dummy (renamed from src/lib/testsupport/.may_include)0
-rw-r--r--src/test/hs_ntor_ref.py2
-rw-r--r--src/test/hs_test_helpers.c14
-rw-r--r--src/test/hs_test_helpers.h6
-rw-r--r--src/test/include.am83
-rw-r--r--src/test/log_test_helpers.c6
-rw-r--r--src/test/log_test_helpers.h8
-rwxr-xr-xsrc/test/ntor_ref.py2
-rw-r--r--src/test/rend_test_helpers.c16
-rw-r--r--src/test/rend_test_helpers.h4
-rw-r--r--src/test/rust_supp.txt1
-rw-r--r--src/test/test-child.c2
-rw-r--r--src/test/test-memwipe.c8
-rw-r--r--src/test/test-timers.c12
-rw-r--r--src/test/test.c57
-rw-r--r--src/test/test.h9
-rw-r--r--src/test/test_accounting.c12
-rw-r--r--src/test/test_addr.c163
-rw-r--r--src/test/test_address.c10
-rw-r--r--src/test/test_address_set.c27
-rw-r--r--src/test/test_bridges.c21
-rw-r--r--src/test/test_bt_cl.c10
-rw-r--r--src/test/test_buffers.c16
-rw-r--r--src/test/test_bwmgt.c6
-rw-r--r--src/test/test_cell_formats.c31
-rw-r--r--src/test/test_cell_queue.c15
-rw-r--r--src/test/test_channel.c40
-rw-r--r--src/test/test_channelpadding.c35
-rw-r--r--src/test/test_channeltls.c26
-rw-r--r--src/test/test_checkdir.c10
-rw-r--r--src/test/test_circuitbuild.c16
-rw-r--r--src/test/test_circuitlist.c24
-rw-r--r--src/test/test_circuitmux.c18
-rw-r--r--src/test/test_circuitstats.c27
-rw-r--r--src/test/test_circuituse.c21
-rw-r--r--src/test/test_compat_libevent.c10
-rw-r--r--src/test/test_config.c76
-rw-r--r--src/test/test_connection.c40
-rw-r--r--src/test/test_connection.h2
-rw-r--r--src/test/test_conscache.c10
-rw-r--r--src/test/test_consdiff.c12
-rw-r--r--src/test/test_consdiffmgr.c30
-rw-r--r--src/test/test_containers.c15
-rw-r--r--src/test/test_controller.c105
-rw-r--r--src/test/test_controller_events.c17
-rw-r--r--src/test/test_crypto.c75
-rw-r--r--src/test/test_crypto_openssl.c14
-rw-r--r--src/test/test_crypto_slow.c12
-rw-r--r--src/test/test_data.c4
-rw-r--r--src/test/test_dir.c230
-rw-r--r--src/test/test_dir_common.c24
-rw-r--r--src/test/test_dir_common.h8
-rw-r--r--src/test/test_dir_handle_get.c57
-rw-r--r--src/test/test_dns.c15
-rw-r--r--src/test/test_dos.c29
-rw-r--r--src/test/test_entryconn.c25
-rw-r--r--src/test/test_entrynodes.c258
-rw-r--r--src/test/test_extorport.c25
-rw-r--r--src/test/test_geoip.c91
-rw-r--r--src/test/test_guardfraction.c29
-rw-r--r--src/test/test_handles.c8
-rw-r--r--src/test/test_helpers.c40
-rw-r--r--src/test/test_helpers.h4
-rw-r--r--src/test/test_hs.c28
-rw-r--r--src/test/test_hs_cache.c27
-rw-r--r--src/test/test_hs_cell.c20
-rw-r--r--src/test/test_hs_client.c55
-rw-r--r--src/test/test_hs_common.c50
-rw-r--r--src/test/test_hs_config.c18
-rw-r--r--src/test/test_hs_control.c32
-rw-r--r--src/test/test_hs_descriptor.c26
-rw-r--r--src/test/test_hs_intropoint.c36
-rw-r--r--src/test/test_hs_ntor.c10
-rw-r--r--src/test/test_hs_ntor_cl.c16
-rw-r--r--src/test/test_hs_service.c71
-rw-r--r--src/test/test_introduce.c10
-rw-r--r--src/test/test_keypin.c10
-rw-r--r--src/test/test_link_handshake.c37
-rw-r--r--src/test/test_logging.c15
-rw-r--r--src/test/test_mainloop.c142
-rw-r--r--src/test/test_microdesc.c27
-rw-r--r--src/test/test_nodelist.c21
-rw-r--r--src/test/test_ntor_cl.c14
-rw-r--r--src/test/test_oom.c27
-rw-r--r--src/test/test_oos.c17
-rw-r--r--src/test/test_options.c28
-rw-r--r--src/test/test_periodic_event.c18
-rw-r--r--src/test/test_policy.c85
-rw-r--r--src/test/test_procmon.c10
-rw-r--r--src/test/test_proto_http.c12
-rw-r--r--src/test/test_proto_misc.c20
-rw-r--r--src/test/test_protover.c37
-rw-r--r--src/test/test_pt.c20
-rw-r--r--src/test/test_pubsub.c85
-rw-r--r--src/test/test_relay.c17
-rw-r--r--src/test/test_relaycell.c281
-rw-r--r--src/test/test_relaycrypt.c19
-rw-r--r--src/test/test_rendcache.c27
-rw-r--r--src/test/test_replay.c8
-rw-r--r--src/test/test_router.c18
-rw-r--r--src/test/test_routerkeys.c18
-rw-r--r--src/test/test_routerlist.c231
-rw-r--r--src/test/test_routerset.c22
-rwxr-xr-xsrc/test/test_rust.sh23
-rw-r--r--src/test/test_scheduler.c22
-rw-r--r--src/test/test_shared_random.c35
-rw-r--r--src/test/test_slow.c6
-rw-r--r--src/test/test_socks.c15
-rw-r--r--src/test/test_status.c32
-rw-r--r--src/test/test_storagedir.c10
-rw-r--r--src/test/test_switch_id.c4
-rw-r--r--src/test/test_threads.c8
-rw-r--r--src/test/test_tortls.c74
-rw-r--r--src/test/test_util.c25
-rw-r--r--src/test/test_util_format.c10
-rw-r--r--src/test/test_util_process.c10
-rw-r--r--src/test/test_util_slow.c12
-rw-r--r--src/test/test_voting_schedule.c6
-rw-r--r--src/test/test_workqueue.c28
-rw-r--r--src/test/testing_common.c38
-rw-r--r--src/test/testing_rsakeys.c8
-rw-r--r--src/tools/include.am25
-rw-r--r--src/tools/tor-gencert.c44
-rw-r--r--src/tools/tor-resolve.c13
-rw-r--r--src/tools/tor_runner.c6
-rw-r--r--src/trace/debug.h (renamed from src/lib/trace/debug.h)4
-rw-r--r--src/trace/events.h (renamed from src/lib/trace/events.h)4
-rw-r--r--src/trace/include.am22
-rw-r--r--src/trace/trace.c (renamed from src/lib/trace/trace.c)4
-rw-r--r--src/trace/trace.h (renamed from src/lib/trace/trace.h)2
-rw-r--r--src/trunnel/include.am11
-rw-r--r--src/trunnel/trunnel-local.h6
-rw-r--r--src/win32/orconfig.h2
765 files changed, 16774 insertions, 28507 deletions
diff --git a/.appveyor.yml b/.appveyor.yml
deleted file mode 100644
index 197097d1fd..0000000000
--- a/.appveyor.yml
+++ /dev/null
@@ -1,62 +0,0 @@
-version: 1.0.{build}
-
-clone_depth: 50
-
-environment:
- compiler: mingw
-
- matrix:
- - target: i686-w64-mingw32
- compiler_path: mingw32
- openssl_path: /c/OpenSSL-Win32
- - target: x86_64-w64-mingw32
- compiler_path: mingw64
- openssl_path: /c/OpenSSL-Win64
-
-install:
-- ps: >-
- Function Execute-Command ($commandPath)
- {
- & $commandPath $args 2>&1
- if ( $LastExitCode -ne 0 ) {
- $host.SetShouldExit( $LastExitCode )
- }
- }
- Function Execute-Bash ()
- {
- Execute-Command 'c:\msys64\usr\bin\bash' '-e' '-c' $args
- }
- Execute-Command "C:\msys64\usr\bin\pacman" -Sy --noconfirm openssl-devel openssl libevent-devel libevent mingw-w64-i686-libevent mingw-w64-x86_64-libevent mingw-w64-i686-openssl mingw-w64-x86_64-openssl mingw-w64-i686-zstd mingw-w64-x86_64-zstd
-
-build_script:
-- ps: >-
- if ($env:compiler -eq "mingw") {
- $oldpath = ${env:Path} -split ';'
- $buildpath = @("C:\msys64\${env:compiler_path}\bin", "C:\msys64\usr\bin") + $oldpath
- $env:Path = @($buildpath) -join ';'
- $env:build = @("${env:APPVEYOR_BUILD_FOLDER}", $env:target) -join '\'
- Set-Location "${env:APPVEYOR_BUILD_FOLDER}"
- Execute-Bash 'autoreconf -i'
- mkdir "${env:build}"
- Set-Location "${env:build}"
- Execute-Bash "../configure --prefix=/${env:compiler_path} --build=${env:target} --host=${env:target} --disable-asciidoc --enable-fatal-warnings --with-openssl-dir=${env:openssl_path}"
- Execute-Bash "V=1 make -j2"
- Execute-Bash "V=1 make -j2 install"
- }
-
-test_script:
-- ps: >-
- if ($env:compiler -eq "mingw") {
- $oldpath = ${env:Path} -split ';'
- $buildpath = @("C:\msys64\${env:compiler_path}\bin") + $oldpath
- $env:Path = $buildpath -join ';'
- Set-Location "${env:build}"
- Execute-Bash "VERBOSE=1 make -j2 check"
- }
-
-on_success:
-- cmd: C:\Python27\python.exe %APPVEYOR_BUILD_FOLDER%\scripts\test\appveyor-irc-notify.py irc.oftc.net:6697 tor-ci success
-
-on_failure:
-- cmd: C:\Python27\python.exe %APPVEYOR_BUILD_FOLDER%\scripts\test\appveyor-irc-notify.py irc.oftc.net:6697 tor-ci failure
-
diff --git a/.editorconfig b/.editorconfig
deleted file mode 100644
index 27ed90fafd..0000000000
--- a/.editorconfig
+++ /dev/null
@@ -1,33 +0,0 @@
-# this should work for all editors that support .editorconfig!
-#
-# on debian, emacs users should install elpa-editorconfig and vim
-# users should install vim-editorconfig.
-
-root = true
-
-[*]
-indent_style = space
-# this remove final newline in some editors, instead of inserting it
-# insert_final_newline = true
-trim_trailing_whitespace = true
-end_of_line = lf
-charset = utf-8
-max_line_length = 79
-
-[*.py]
-indent_size = 4
-# to do not have final newline in python code
-insert_final_newline = true
-
-[*.c, *.h]
-# done in tests and other cases do not use 2 spaces identations, so this
-# should be commented on those cases
-indent_size = 2
-trim_trailing_whitespace = true
-
-[Makefile, *.am]
-indent_style = tab
-
-[*-spec.txt]
-# specs seem to have 76 chars max per lines as RFCs
-max_line_length = 76 \ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 025d7202d1..c00fbe97e1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -45,7 +45,6 @@ uptime-*.json
/autom4te.cache
/build-stamp
/compile
-/config.rust
/configure
/Doxyfile
/orconfig.h
@@ -56,7 +55,6 @@ uptime-*.json
/config.guess
/config.sub
/conftest*
-/link_rust.sh
/micro-revision.*
/patch-stamp
/stamp-h
@@ -141,9 +139,14 @@ uptime-*.json
/src/common/libor-ctime.a
/src/common/libor-ctime-testing.a
/src/common/libor-ctime.lib
+/src/common/libor-crypto.a
+/src/common/libor-crypto-testing.a
+/src/common/libor-crypto.lib
/src/common/libor-event.a
/src/common/libor-event-testing.a
/src/common/libor-event.lib
+/src/common/libcurve25519_donna.a
+/src/common/libcurve25519_donna.lib
# /src/config/
/src/config/Makefile
@@ -161,36 +164,6 @@ uptime-*.json
/src/ext/keccak-tiny/libkeccak-tiny.a
/src/ext/keccak-tiny/libkeccak-tiny.lib
-# /src/lib
-/src/lib/libcurve25519_donna.a
-/src/lib/libtor-compress.a
-/src/lib/libtor-compress-testing.a
-/src/lib/libtor-container.a
-/src/lib/libtor-container-testing.a
-/src/lib/libtor-crypt-ops.a
-/src/lib/libtor-crypt-ops-testing.a
-/src/lib/libtor-ctime.a
-/src/lib/libtor-ctime-testing.a
-/src/lib/libtor-err.a
-/src/lib/libtor-err-testing.a
-/src/lib/libtor-fdio.a
-/src/lib/libtor-fdio-testing.a
-/src/lib/libtor-intmath.a
-/src/lib/libtor-intmath-testing.a
-/src/lib/libtor-lock.a
-/src/lib/libtor-lock-testing.a
-/src/lib/libtor-log.a
-/src/lib/libtor-log-testing.a
-/src/lib/libtor-malloc.a
-/src/lib/libtor-malloc-testing.a
-/src/lib/libtor-string.a
-/src/lib/libtor-string-testing.a
-/src/lib/libtor-tls.a
-/src/lib/libtor-tls-testing.a
-/src/lib/libtor-trace.a
-/src/lib/libtor-wallclock.a
-/src/lib/libtor-wallclock-testing.a
-
# /src/or/
/src/or/Makefile
/src/or/Makefile.in
@@ -198,8 +171,8 @@ uptime-*.json
/src/or/tor.exe
/src/or/tor-cov
/src/or/tor-cov.exe
-/src/or/libtor-app.a
-/src/or/libtor-app-testing.a
+/src/or/libtor.a
+/src/or/libtor-testing.a
/src/or/libtor.lib
# /src/rust
diff --git a/.travis.yml b/.travis.yml
index f37f9a23ff..aab6f6b3d5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -87,9 +87,8 @@ matrix:
## branches and build history pages. See
## https://github.com/travis-ci/travis-ci/issues/8716
allow_failures:
- - env: RUST_OPTIONS="--enable-rust" TOR_RUST_DEPENDENCIES=true
- - env: RUST_OPTIONS="--enable-rust --enable-cargo-online-mode"
- - env: DISTCHECK="yes" RUST_OPTIONS="--enable-rust --enable-cargo-online-mode"
+ # - env: RUST_OPTIONS="--enable-rust" TOR_RUST_DEPENDENCIES=true
+ # - env: RUST_OPTIONS="--enable-rust --enable-cargo-online-mode
# - compiler: clang
## Create explicit matrix entries to work around a Travis CI
diff --git a/CONTRIBUTING b/CONTRIBUTING
deleted file mode 100644
index 3569f45a88..0000000000
--- a/CONTRIBUTING
+++ /dev/null
@@ -1,39 +0,0 @@
-Contributing to Tor
--------------------
-
-### Getting started
-
-Welcome!
-
-We have a bunch of documentation about how to develop Tor in the
-doc/HACKING/ directory. We recommend that you start with
-doc/HACKING/README.1st.md , and then go from there. It will tell
-you how to find your way around the source code, how to get
-involved with the Tor community, how to write patches, and much
-more!
-
-You don't have to be a C developer to help with Tor: have a look
-at https://www.torproject.org/getinvolved/volunteer !
-
-The Tor Project is committed to fostering a inclusive community
-where people feel safe to engage, share their points of view, and
-participate. For the latest version of our Code of Conduct, please
-see
-
-https://gitweb.torproject.org/community/policies.git/plain/code_of_conduct.txt
-
-
-
-### License issues
-
-Tor is distributed under the license terms in the LICENSE -- in
-brief, the "3-clause BSD license". If you send us code to
-distribute with Tor, it needs to be code that we can distribute
-under those terms. Please don't send us patches unless you agree
-to allow this.
-
-Some compatible licenses include:
-
- - 3-clause BSD
- - 2-clause BSD
- - CC0 Public Domain Dedication
diff --git a/ChangeLog b/ChangeLog
index 5d2c6e6ec8..8789b215d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,728 +1,3 @@
-Changes in version 0.3.4.3-alpha - 2018-06-26
- Tor 0.3.4.3-alpha fixes several bugs in earlier versions, including
- one that was causing stability issues on directory authorities.
-
- o Major bugfixes (directory authority):
- - Stop leaking memory on directory authorities when planning to
- vote. This bug was crashing authorities by exhausting their
- memory. Fixes bug 26435; bugfix on 0.3.3.6.
-
- o Major bugfixes (rust, testing):
- - Make sure that failing tests in Rust will actually cause the build
- to fail: previously, they were ignored. Fixes bug 26258; bugfix
- on 0.3.3.4-alpha.
-
- o Minor feature (directory authorities):
- - Stop warning about incomplete bw lines before the first complete
- bw line has been found, so that additional header lines can be
- ignored. Fixes bug 25960; bugfix on 0.2.2.1-alpha
-
- o Minor features (relay, diagnostic):
- - Add several checks to detect whether Tor relays are uploading
- their descriptors without specifying why they regenerated them.
- Diagnostic for ticket 25686.
-
- o Minor features (unit tests):
- - Test complete bandwidth measurements files, and test that
- incomplete bandwidth lines only give warnings when the end of the
- header has not been detected. Fixes bug 25947; bugfix
- on 0.2.2.1-alpha
-
- o Minor bugfixes (compilation):
- - Refrain from compiling unit testing related object files when
- --disable-unittests is set to configure script. Fixes bug 24891;
- bugfix on 0.2.5.1-alpha.
- - When linking the libtor_testing.a library, only include the
- dirauth object files once. Previously, they were getting added
- twice. Fixes bug 26402; bugfix on 0.3.4.1-alpha.
- - The --enable-fatal-warnings flag now affects Rust code as well.
- Closes ticket 26245.
-
- o Minor bugfixes (onion services):
- - Recompute some consensus information after detecting a clock jump,
- or after transitioning from a non-live consensus to a live
- consensus. We do this to avoid having an outdated state, and
- miscalculating the index for next-generation onion services. Fixes
- bug 24977; bugfix on 0.3.2.1-alpha.
-
- o Minor bugfixes (relay):
- - Relays now correctly block attempts to re-extend to the previous
- relay by Ed25519 identity. Previously they would warn in this
- case, but not actually reject the attempt. Fixes bug 26158; bugfix
- on 0.3.0.1-alpha.
-
- o Minor bugfixes (testing):
- - Fix compilation of the doctests in the Rust crypto crate. Fixes
- bug 26415; bugfix on 0.3.4.1-alpha.
- - Instead of trying to read the geoip configuration files from
- within the unit tests, instead create our own ersatz files with
- just enough geoip data in the format we expect. Trying to read
- from the source directory created problems on Windows with mingw,
- where the build system's paths are not the same as the platform's
- paths. Fixes bug 25787; bugfix on 0.3.4.1-alpha.
- - Refrain from trying to get an item from an empty smartlist in
- test_bridges_clear_bridge_list. Set DEBUG_SMARTLIST in unit tests
- to catch improper smartlist usage. Furthermore, enable
- DEBUG_SMARTLIST globally when build is configured with fragile
- hardening. Fixes bug 26196; bugfix on 0.3.4.1-alpha.
-
-
-Changes in version 0.3.3.7 - 2018-06-12
- Tor 0.3.3.7 backports several changes from the 0.3.4.x series, including
- fixes for bugs affecting compatibility and stability.
-
- o Directory authority changes:
- - Add an IPv6 address for the "dannenberg" directory authority.
- Closes ticket 26343.
-
- o Minor features (geoip):
- - Update geoip and geoip6 to the June 7 2018 Maxmind GeoLite2
- Country database. Closes ticket 26351.
-
- o Minor bugfixes (compatibility, openssl, backport from 0.3.4.2-alpha):
- - Work around a change in OpenSSL 1.1.1 where return values that
- would previously indicate "no password" now indicate an empty
- password. Without this workaround, Tor instances running with
- OpenSSL 1.1.1 would accept descriptors that other Tor instances
- would reject. Fixes bug 26116; bugfix on 0.2.5.16.
-
- o Minor bugfixes (compilation, backport from 0.3.4.2-alpha):
- - Silence unused-const-variable warnings in zstd.h with some GCC
- versions. Fixes bug 26272; bugfix on 0.3.1.1-alpha.
-
- o Minor bugfixes (controller, backport from 0.3.4.2-alpha):
- - Improve accuracy of the BUILDTIMEOUT_SET control port event's
- TIMEOUT_RATE and CLOSE_RATE fields. (We were previously
- miscounting the total number of circuits for these field values.)
- Fixes bug 26121; bugfix on 0.3.3.1-alpha.
-
- o Minor bugfixes (hardening, backport from 0.3.4.2-alpha):
- - Prevent a possible out-of-bounds smartlist read in
- protover_compute_vote(). Fixes bug 26196; bugfix on 0.2.9.4-alpha.
-
- o Minor bugfixes (path selection, backport from 0.3.4.1-alpha):
- - Only select relays when they have the descriptors we prefer to use
- for them. This change fixes a bug where we could select a relay
- because it had _some_ descriptor, but reject it later with a
- nonfatal assertion error because it didn't have the exact one we
- wanted. Fixes bugs 25691 and 25692; bugfix on 0.3.3.4-alpha.
-
-
-Changes in version 0.3.4.2-alpha - 2018-06-12
- Tor 0.3.4.2-alpha fixes several minor bugs in the previous alpha
- release, and forward-ports an authority-only security fix from 0.3.3.6.
-
- o Directory authority changes:
- - Add an IPv6 address for the "dannenberg" directory authority.
- Closes ticket 26343.
-
- o Major bugfixes (security, directory authority, denial-of-service, also in 0.3.3.6):
- - Fix a bug that could have allowed an attacker to force a directory
- authority to use up all its RAM by passing it a maliciously
- crafted protocol versions string. Fixes bug 25517; bugfix on
- 0.2.9.4-alpha. This issue is also tracked as TROVE-2018-005.
-
- o Minor features (continuous integration):
- - Add the necessary configuration files for continuous integration
- testing on Windows, via the Appveyor platform. Closes ticket
- 25549. Patches from Marcin Cieślak and Isis Lovecruft.
-
- o Minor features (geoip):
- - Update geoip and geoip6 to the June 7 2018 Maxmind GeoLite2
- Country database. Closes ticket 26351.
-
- o Minor bugfixes (compatibility, openssl):
- - Work around a change in OpenSSL 1.1.1 where return values that
- would previously indicate "no password" now indicate an empty
- password. Without this workaround, Tor instances running with
- OpenSSL 1.1.1 would accept descriptors that other Tor instances
- would reject. Fixes bug 26116; bugfix on 0.2.5.16.
-
- o Minor bugfixes (compilation):
- - Silence unused-const-variable warnings in zstd.h with some GCC
- versions. Fixes bug 26272; bugfix on 0.3.1.1-alpha.
- - Fix compilation when using OpenSSL 1.1.0 with the "no-deprecated"
- flag enabled. Fixes bug 26156; bugfix on 0.3.4.1-alpha.
- - Avoid a compiler warning when casting the return value of
- smartlist_len() to double with DEBUG_SMARTLIST enabled. Fixes bug
- 26283; bugfix on 0.2.4.10-alpha.
-
- o Minor bugfixes (control port):
- - Do not count 0-length RELAY_COMMAND_DATA cells as valid data in
- CIRC_BW events. Previously, such cells were counted entirely in
- the OVERHEAD field. Now they are not. Fixes bug 26259; bugfix
- on 0.3.4.1-alpha.
-
- o Minor bugfixes (controller):
- - Improve accuracy of the BUILDTIMEOUT_SET control port event's
- TIMEOUT_RATE and CLOSE_RATE fields. (We were previously
- miscounting the total number of circuits for these field values.)
- Fixes bug 26121; bugfix on 0.3.3.1-alpha.
-
- o Minor bugfixes (hardening):
- - Prevent a possible out-of-bounds smartlist read in
- protover_compute_vote(). Fixes bug 26196; bugfix on 0.2.9.4-alpha.
-
- o Minor bugfixes (onion services):
- - Fix a bug that blocked the creation of ephemeral v3 onion
- services. Fixes bug 25939; bugfix on 0.3.4.1-alpha.
-
- o Minor bugfixes (test coverage tools):
- - Update our "cov-diff" script to handle output from the latest
- version of gcov, and to remove extraneous timestamp information
- from its output. Fixes bugs 26101 and 26102; bugfix
- on 0.2.5.1-alpha.
-
-
-Changes in version 0.3.3.6 - 2018-05-22
- Tor 0.3.3.6 is the first stable release in the 0.3.3 series. It
- backports several important fixes from the 0.3.4.1-alpha.
-
- The Tor 0.3.3 series includes controller support and other
- improvements for v3 onion services, official support for embedding Tor
- within other applications, and our first non-trivial module written in
- the Rust programming language. (Rust is still not enabled by default
- when building Tor.) And as usual, there are numerous other smaller
- bugfixes, features, and improvements.
-
- Below are the changes since 0.3.3.5-rc. For a list of all changes
- since 0.3.2.10, see the ReleaseNotes file.
-
- o Major bugfixes (directory authorities, security, backport from 0.3.4.1-alpha):
- - When directory authorities read a zero-byte bandwidth file, they
- would previously log a warning with the contents of an
- uninitialised buffer. They now log a warning about the empty file
- instead. Fixes bug 26007; bugfix on 0.2.2.1-alpha.
-
- o Major bugfixes (security, directory authority, denial-of-service):
- - Fix a bug that could have allowed an attacker to force a directory
- authority to use up all its RAM by passing it a maliciously
- crafted protocol versions string. Fixes bug 25517; bugfix on
- 0.2.9.4-alpha. This issue is also tracked as TROVE-2018-005.
-
- o Major bugfixes (crash, backport from 0.3.4.1-alpha):
- - Avoid a rare assertion failure in the circuit build timeout code
- if we fail to allow any circuits to actually complete. Fixes bug
- 25733; bugfix on 0.2.2.2-alpha.
-
- o Major bugfixes (directory authorities, backport from 0.3.4.1-alpha):
- - Avoid a crash when testing router reachability on a router that
- could have an ed25519 ID, but which does not. Fixes bug 25415;
- bugfix on 0.3.3.2-alpha.
-
- o Major bugfixes (onion service, backport from 0.3.4.1-alpha):
- - Correctly detect when onion services get disabled after HUP. Fixes
- bug 25761; bugfix on 0.3.2.1.
-
- o Major bugfixes (relay, denial of service, backport from 0.3.4.1-alpha):
- - Impose a limit on circuit cell queue size. The limit can be
- controlled by a consensus parameter. Fixes bug 25226; bugfix
- on 0.2.4.14-alpha.
-
- o Minor features (compatibility, backport from 0.3.4.1-alpha):
- - Avoid some compilation warnings with recent versions of LibreSSL.
- Closes ticket 26006.
-
- o Minor features (continuous integration, backport from 0.3.4.1-alpha):
- - Our .travis.yml configuration now includes support for testing the
- results of "make distcheck". (It's not uncommon for "make check"
- to pass but "make distcheck" to fail.) Closes ticket 25814.
- - Our Travis CI configuration now integrates with the Coveralls
- coverage analysis tool. Closes ticket 25818.
-
- o Minor features (geoip):
- - Update geoip and geoip6 to the May 1 2018 Maxmind GeoLite2 Country
- database. Closes ticket 26104.
-
- o Minor bugfixes (client, backport from 0.3.4.1-alpha):
- - Don't consider Tor running as a client if the ControlPort is open,
- but no actual client ports are open. Fixes bug 26062; bugfix
- on 0.2.9.4-alpha.
-
- o Minor bugfixes (correctness, client, backport from 0.3.4.1-alpha):
- - Upon receiving a malformed connected cell, stop processing the
- cell immediately. Previously we would mark the connection for
- close, but continue processing the cell as if the connection were
- open. Fixes bug 26072; bugfix on 0.2.4.7-alpha.
-
- o Minor bugfixes (documentation, backport from 0.3.4.1-alpha):
- - Stop saying in the manual that clients cache ipv4 dns answers from
- exit relays. We haven't used them since 0.2.6.3-alpha, and in
- ticket 24050 we stopped even caching them as of 0.3.2.6-alpha, but
- we forgot to say so in the man page. Fixes bug 26052; bugfix
- on 0.3.2.6-alpha.
-
- o Minor bugfixes (Linux seccomp2 sandbox, backport from 0.3.4.1-alpha):
- - Allow the nanosleep() system call, which glibc uses to implement
- sleep() and usleep(). Fixes bug 24969; bugfix on 0.2.5.1-alpha.
-
- o Minor bugfixes (onion service, backport from 0.3.4.1-alpha):
- - Fix a memory leak when a v3 onion service is configured and gets a
- SIGHUP signal. Fixes bug 25901; bugfix on 0.3.2.1-alpha.
- - When parsing the descriptor signature, look for the token plus an
- extra white-space at the end. This is more correct but also will
- allow us to support new fields that might start with "signature".
- Fixes bug 26069; bugfix on 0.3.0.1-alpha.
-
- o Minor bugfixes (relay, crash, backport from 0.3.4.1-alpha):
- - Avoid a crash when running with DirPort set but ORPort tuned off.
- Fixes a case of bug 23693; bugfix on 0.3.1.1-alpha.
-
- o Documentation (backport from 0.3.4.1-alpha):
- - Correct an IPv6 error in the documentation for ExitPolicy. Closes
- ticket 25857. Patch from "CTassisF".
-
-
-Changes in version 0.3.4.1-alpha - 2018-05-17
- Tor 0.3.4.1-alpha is the first release in the 0.3.4.x series. It
- includes refactoring to begin reducing Tor's binary size and idle CPU
- usage on mobile, along with prep work for new bandwidth scanners,
- improvements to the experimental "vanguards" feature, and numerous
- other small features and bugfixes.
-
- o New system requirements:
- - Tor no longer tries to support old operating systems without
- mmap() or some local equivalent. Apparently, compilation on such
- systems has been broken for some time, without anybody noticing or
- complaining. Closes ticket 25398.
-
- o Major feature (directory authority, modularization):
- - The directory authority subsystem has been modularized. The code
- is now located in src/or/dirauth/, and is compiled in by default.
- To disable the module, the configure option
- --disable-module-dirauth has been added. This module may be
- disabled by default in some future release. Closes ticket 25610.
-
- o Major features (main loop, CPU usage):
- - When Tor is disabled (via DisableNetwork or via hibernation), it
- no longer needs to run any per-second events. This change should
- make it easier for mobile applications to disable Tor while the
- device is sleeping, or Tor is not running. Closes ticket 26063.
- - Tor no longer enables all of its periodic events by default.
- Previously, Tor would enable all possible main loop events,
- regardless of whether it needed them. Furthermore, many of these
- events are now disabled with Tor is hibernating or DisableNetwork
- is set. This is a big step towards reducing client CPU usage by
- reducing the amount of wake-ups the daemon does. Closes ticket
- 25376 and 25762.
- - The bandwidth-limitation logic has been refactored so that
- bandwidth calculations are performed on-demand, rather than every
- TokenBucketRefillInterval milliseconds. This change should improve
- the granularity of our bandwidth calculations, and limit the
- number of times that the Tor process needs to wake up when it is
- idle. Closes ticket 25373.
- - Move responsibility for many operations from a once-per-second
- callback to a callback that is only scheduled as needed. Moving
- this functionality has allowed us to disable the callback when
- Tor's network is disabled. Once enough items are removed from our
- once-per-second callback, we can eliminate it entirely to conserve
- CPU when idle. The functionality removed includes: closing
- connections, circuits, and channels (ticket 25932); consensus
- voting (25937); flushing log callbacks (25951); honoring delayed
- SIGNEWNYM requests (25949); rescanning the consensus cache
- (25931); saving the state file to disk (25948); warning relay
- operators about unreachable ports (25952); and keeping track of
- Tor's uptime (26009).
-
- o Major bugfixes (directory authorities, security):
- - When directory authorities read a zero-byte bandwidth file, they
- would previously log a warning with the contents of an
- uninitialised buffer. They now log a warning about the empty file
- instead. Fixes bug 26007; bugfix on 0.2.2.1-alpha.
-
- o Major bugfixes (crash):
- - Avoid a rare assertion failure in the circuit build timeout code
- if we fail to allow any circuits to actually complete. Fixes bug
- 25733; bugfix on 0.2.2.2-alpha.
-
- o Major bugfixes (directory authority):
- - Avoid a crash when testing router reachability on a router that
- could have an ed25519 ID, but which does not. Fixes bug 25415;
- bugfix on 0.3.3.2-alpha.
-
- o Major bugfixes (onion service):
- - Correctly detect when onion services get disabled after HUP. Fixes
- bug 25761; bugfix on 0.3.2.1.
-
- o Major bugfixes (protover, voting):
- - Revise Rust implementation of protover to use a more memory-
- efficient voting algorithm and corresponding data structures, thus
- avoiding a potential (but small impact) DoS attack where specially
- crafted protocol strings would expand to several potential
- megabytes in memory. In the process, several portions of code were
- revised to be methods on new, custom types, rather than functions
- taking interchangeable types, thus increasing type safety of the
- module. Custom error types and handling were added as well, in
- order to facilitate better error dismissal/handling in outside
- crates and avoid mistakenly passing an internal error string to C
- over the FFI boundary. Many tests were added, and some previous
- differences between the C and Rust implementations have been
- remedied. Fixes bug 24031; bugfix on 0.3.3.1-alpha.
-
- o Major bugfixes (relay, denial of service):
- - Impose a limit on circuit cell queue size. The limit can be
- controlled by a consensus parameter. Fixes bug 25226; bugfix
- on 0.2.4.14-alpha.
-
- o Minor features (accounting):
- - When Tor becomes dormant, it now uses a scheduled event to wake up
- at the right time. Previously, we would use the per-second timer
- to check whether to wake up, but we no longer have any per-second
- timers enabled when the network is disabled. Closes ticket 26064.
-
- o Minor features (code quality):
- - Add optional spell-checking for the Tor codebase, using the
- "misspell" program. To use this feature, run "make check-typos".
- Closes ticket 25024.
-
- o Minor features (compatibility):
- - Tor now detects versions of OpenSSL 1.1.0 and later compiled with
- the no-deprecated option, and builds correctly with them. Closes
- tickets 19429, 19981, and 25353.
- - Avoid some compilation warnings with recent versions of LibreSSL.
- Closes ticket 26006.
-
- o Minor features (compression, zstd):
- - When running with zstd, Tor now considers using advanced functions
- that the zstd maintainers have labeled as potentially unstable. To
- prevent breakage, Tor will only use this functionality when the
- runtime version of the zstd library matches the version with which
- Tor was compiled. Closes ticket 25162.
-
- o Minor features (configuration):
- - The "DownloadSchedule" options have been renamed to end with
- "DownloadInitialDelay". The old names are still allowed, but will
- produce a warning. Comma-separated lists are still permitted for
- these options, but all values after the first are ignored (as they
- have been since 0.2.9). Closes ticket 23354.
-
- o Minor features (continuous integration):
- - Our .travis.yml configuration now includes support for testing the
- results of "make distcheck". (It's not uncommon for "make check"
- to pass but "make distcheck" to fail.) Closes ticket 25814.
- - Our Travis CI configuration now integrates with the Coveralls
- coverage analysis tool. Closes ticket 25818.
-
- o Minor features (control port):
- - Introduce GETINFO "current-time/{local,utc}" to return the local
- and UTC times respectively in ISO format. This helps a controller
- like Tor Browser detect a time-related error. Closes ticket 25511.
- Patch by Neel Chauhan.
- - Introduce new fields to the CIRC_BW event. There are two new
- fields in each of the read and written directions. The DELIVERED
- fields report the total valid data on the circuit, as measured by
- the payload sizes of verified and error-checked relay command
- cells. The OVERHEAD fields report the total unused bytes in each
- of these cells. Closes ticket 25903.
-
- o Minor features (directory authority):
- - Directory authorities now open their key-pinning files as O_SYNC,
- to limit their chances of accidentally writing partial lines.
- Closes ticket 23909.
-
- o Minor features (directory authority, forward compatibility):
- - Make the lines of the measured bandwidth file able to contain
- their entries in any order. Previously, the node_id entry needed
- to come first. Closes ticket 26004.
-
- o Minor features (entry guards):
- - Introduce a new torrc option NumPrimaryGuards for controlling the
- number of primary guards. Closes ticket 25843.
-
- o Minor features (geoip):
- - Update geoip and geoip6 to the May 1 2018 Maxmind GeoLite2 Country
- database. Closes ticket 26104.
-
- o Minor features (performance):
- - Avoid a needless call to malloc() when processing an incoming
- relay cell. Closes ticket 24914.
- - Make our timing-wheel code run a tiny bit faster on 32-bit
- platforms, by preferring 32-bit math to 64-bit. Closes
- ticket 24688.
- - Avoid a needless malloc()/free() pair every time we handle an ntor
- handshake. Closes ticket 25150.
-
- o Minor features (testing):
- - Add a unit test for voting_schedule_get_start_of_next_interval().
- Closes ticket 26014, and helps make unit test coverage
- more deterministic.
- - A new unittests module specifically for testing the functions in
- the (new-ish) bridges.c module has been created with new
- unittests, raising the code coverage percentages. Closes 25425.
- - We now have improved testing for addressmap_get_virtual_address()
- function. This should improve our test coverage, and make our test
- coverage more deterministic. Closes ticket 25993.
-
- o Minor features (timekeeping, circuit scheduling):
- - When keeping track of how busy each circuit have been recently on
- a given connection, use coarse-grained monotonic timers rather
- than gettimeofday(). This change should marginally increase
- accuracy and performance. Implements part of ticket 25927.
-
- o Minor bugfixes (bandwidth management):
- - Consider ourselves "low on write bandwidth" if we have exhausted
- our write bandwidth some time in the last second. This was the
- documented behavior before, but the actual behavior was to change
- this value every TokenBucketRefillInterval. Fixes bug 25828;
- bugfix on 0.2.3.5-alpha.
-
- o Minor bugfixes (C correctness):
- - Add a missing lock acquisition in the shutdown code of the control
- subsystem. Fixes bug 25675; bugfix on 0.2.7.3-rc. Found by
- Coverity; this is CID 1433643.
-
- o Minor bugfixes (circuit path selection):
- - Don't count path selection failures as circuit build failures.
- This change should eliminate cases where Tor blames its guard or
- the network for situations like insufficient microdescriptors
- and/or overly restrictive torrc settings. Fixes bug 25705; bugfix
- on 0.3.3.1-alpha.
-
- o Minor bugfixes (client):
- - Don't consider Tor running as a client if the ControlPort is open,
- but no actual client ports are open. Fixes bug 26062; bugfix
- on 0.2.9.4-alpha.
-
- o Minor bugfixes (code style):
- - Fixed multiple includes of transports.h in src/or/connection.c
- Fixes bug 25261; bugfix on 0.2.5.1-alpha.
- - Remove the unused variable n_possible from the function
- channel_get_for_extend(). Fixes bug 25645; bugfix on 0.2.4.4-alpha
-
- o Minor bugfixes (control interface):
- - Respond with more human-readable error messages to GETINFO exit-
- policy/* requests. Also, let controller know if an error is
- transient (response code 551) or not (response code 552). Fixes
- bug 25852; bugfix on 0.2.8.1-alpha.
-
- o Minor bugfixes (controller):
- - Make CIRC_BW event reflect the total of all data sent on a
- circuit, including padding and dropped cells. Also fix a mis-
- counting bug when STREAM_BW events were enabled. Fixes bug 25400;
- bugfix on 0.2.5.2-alpha.
-
- o Minor bugfixes (correctness, client):
- - Upon receiving a malformed connected cell, stop processing the cell
- immediately. Previously we would mark the connection for close, but
- continue processing the cell as if the connection were open. Fixes bug
- 26072; bugfix on 0.2.4.7-alpha.
-
- o Minor bugfixes (directory client):
- - When unverified-consensus is verified, rename it to cached-
- consenus. Fixes bug 4187; bugfix on 0.2.0.3-alpha.
- - Fixed launching a certificate fetch always during the scheduled
- periodic consensus fetch by fetching only in those cases when
- consensus are waiting for certs. Fixes bug 24740; bugfix
- on 0.2.9.1-alpha.
-
- o Minor bugfixes (documentation):
- - Stop saying in the manual that clients cache ipv4 dns answers from
- exit relays. We haven't used them since 0.2.6.3-alpha, and in
- ticket 24050 we stopped even caching them as of 0.3.2.6-alpha, but
- we forgot to say so in the man page. Fixes bug 26052; bugfix
- on 0.3.2.6-alpha.
-
- o Minor bugfixes (error reporting):
- - Improve tolerance for directory authorities with skewed clocks.
- Previously, an authority with a clock more than 60 seconds ahead
- could cause a client with a correct clock to warn that the
- client's clock was behind. Now the clocks of a majority of
- directory authorities have to be ahead of the client before this
- warning will occur. Fixes bug 25756; bugfix on 0.2.2.25-alpha.
-
- o Minor bugfixes (Linux seccomp2 sandbox):
- - Allow the nanosleep() system call, which glibc uses to implement
- sleep() and usleep(). Fixes bug 24969; bugfix on 0.2.5.1-alpha.
-
- o Minor bugfixes (onion service):
- - Fix a memory leak when a v3 onion service is configured and gets a
- SIGHUP signal. Fixes bug 25901; bugfix on 0.3.2.1-alpha.
- - When parsing the descriptor signature, look for the token plus an
- extra white-space at the end. This is more correct but also will
- allow us to support new fields that might start with "signature".
- Fixes bug 26069; bugfix on 0.3.0.1-alpha.
-
- o Minor bugfixes (path selection):
- - Only select relays when they have the descriptors we prefer to use
- for them. This change fixes a bug where we could select a relay
- because it had _some_ descriptor, but reject it later with a
- nonfatal assertion error because it didn't have the exact one we
- wanted. Fixes bugs 25691 and 25692; bugfix on 0.3.3.4-alpha.
-
- o Minor bugfixes (portability):
- - Do not align mmap length, as it is not required by POSIX, and the
- getpagesize function is deprecated. Fixes bug 25399; bugfix
- on 0.1.1.23.
-
- o Minor bugfixes (portability, FreeBSD):
- - In have_enough_mem_for_dircache(), the variable DIRCACHE_MIN_MEM_MB
- does not stringify on FreeBSD, so we switch to tor_asprintf().
- Fixes bug 20887; bugfix on 0.2.8.1-alpha. Patch by Neel Chauhan.
-
- o Minor bugfixes (relay statistics):
- - When a relay is collecting internal statistics about how many
- create cell requests it has seen of each type, accurately count
- the requests from relays that temporarily fall out of the
- consensus. (To be extra conservative, we were already ignoring
- requests from clients in our counts, and we continue ignoring them
- here.) Fixes bug 24910; bugfix on 0.2.4.17-rc.
-
- o Minor bugfixes (relay, crash):
- - Avoid a crash when running with DirPort set but ORPort tuned off.
- Fixes a case of bug 23693; bugfix on 0.3.1.1-alpha.
-
- o Minor bugfixes (restart-in-process):
- - When shutting down, Tor now clears all the flags in the control.c
- module. This should prevent a bug where authentication cookies are
- not generated on restart. Fixes bug 25512; bugfix on 0.3.3.1-alpha.
-
- o Minor bugfixes (testing):
- - When testing workqueue event-cancellation, make sure that we
- actually cancel an event, and that cancel each event with equal
- probability. (It was previously possible, though extremely
- unlikely, for our event-canceling test not to cancel any events.)
- Fixes bug 26008; bugfix on 0.2.6.3-alpha.
- - Repeat part of the test in test_client_pick_intro() a number of
- times, to give it consistent coverage. Fixes bug 25996; bugfix
- on 0.3.2.1-alpha.
- - Remove randomness from the hs_common/responsible_hsdirs test, so
- that it always takes the same path through the function it tests.
- Fixes bug 25997; bugfix on 0.3.2.1-alpha.
- - Change the behavior of the "channel/outbound" test so that it
- never causes a 10-second rollover for the EWMA circuitmux code.
- Previously, this behavior would happen randomly, and result in
- fluctuating test coverage. Fixes bug 25994; bugfix
- on 0.3.3.1-alpha.
- - Use X509_new() to allocate certificates that will be freed later
- with X509_free(). Previously, some parts of the unit tests had
- used tor_malloc_zero(), which is incorrect, and which caused test
- failures on Windows when they were built with extra hardening.
- Fixes bugs 25943 and 25944; bugfix on 0.2.8.1-alpha. Patch by
- Marcin Cieślak.
- - While running the circuit_timeout test, fix the PRNG to a
- deterministic AES stream, so that the test coverage from this test
- will itself be deterministic. Fixes bug 25995; bugfix
- on 0.2.2.2-alpha.
-
- o Minor bugfixes (vanguards):
- - Allow the last hop in a vanguard circuit to be the same as our
- first, to prevent the adversary from influencing guard node choice
- by choice of last hop. Also prevent the creation of A - B - A
- paths, or A - A paths, which are forbidden by relays. Fixes bug
- 25870; bugfix on 0.3.3.1-alpha.
-
- o Code simplification and refactoring:
- - Remove duplicate code in parse_{c,s}method_line and bootstrap
- their functionalities into a single function. Fixes bug 6236;
- bugfix on 0.2.3.6-alpha.
- - We remove the PortForwsrding and PortForwardingHelper options,
- related functions, and the port_forwarding tests. These options
- were used by the now-deprecated Vidalia to help ordinary users
- become Tor relays or bridges. Closes ticket 25409. Patch by
- Neel Chauhan.
- - In order to make the OR and dir checking function in router.c less
- confusing we renamed some functions and
- consider_testing_reachability() has been split into
- router_should_check_reachability() and
- router_do_reachability_checks(). Also we improved the documentation
- in some functions. Closes ticket 18918.
- - Initial work to isolate Libevent usage to a handful of modules in
- our codebase, to simplify our call structure, and so that we can
- more easily change event loops in the future if needed. Closes
- ticket 23750.
- - Introduce a function to call getsockname() and return tor_addr_t,
- to save a little complexity throughout the codebase. Closes
- ticket 18105.
- - Make hsdir_index in node_t a hsdir_index_t rather than a pointer
- as hsdir_index is always present. Also, we move hsdir_index_t into
- or.h. Closes ticket 23094. Patch by Neel Chauhan.
- - Merge functions used for describing nodes and suppress the
- functions that do not allocate memory for the output buffer
- string. NODE_DESC_BUF_LEN constant and format_node_description()
- function cannot be used externally from router.c module anymore.
- Closes ticket 25432. Patch by valentecaio.
- - Our main loop has been simplified so that all important operations
- happen inside events. Previously, some operations had to happen
- outside the event loop, to prevent infinite sequences of event
- activations. Closes ticket 25374.
- - Put a SHA1 public key digest in hs_service_intro_point_t, and use
- it in register_intro_circ() and service_intro_point_new(). This
- prevents the digest from being re-calculated each time. Closes
- ticket 23107. Patch by Neel Chauhan.
- - Refactor token-bucket implementations to use a common backend.
- Closes ticket 25766.
- - Remove extern declaration of stats_n_seconds_working variable from
- main, protecting its accesses with get_uptime() and reset_uptime()
- functions. Closes ticket 25081, patch by “valentecaio”.
- - Remove our previous logic for "cached gettimeofday()" -- our
- coarse monotonic timers are fast enough for this purpose, and far
- less error-prone. Implements part of ticket 25927.
- - Remove the return value for fascist_firewall_choose_address_base(),
- and sister functions such as fascist_firewall_choose_address_node()
- and fascist_firewall_choose_address_rs(). Also, while we're here,
- initialize the ap argument as leaving it uninitialized can pose a
- security hazard. Closes ticket 24734. Patch by Neel Chauhan.
- - Rename two fields of connection_t struct. timestamp_lastwritten is
- renamed to timestamp_last_write_allowed and timestamp_lastread is
- renamed to timestamp_last_read_allowed. Closes ticket 24714, patch
- by "valentecaio".
- - Since Tor requires C99, remove our old workaround code for libc
- implementations where free(NULL) doesn't work. Closes ticket 24484.
- - Use our standard rate-limiting code to deal with excessive
- libevent failures, rather than the hand-rolled logic we had
- before. Closes ticket 26016.
- - We remove the return value of node_get_prim_orport() and
- node_get_prim_dirport(), and introduce node_get_prim_orport() in
- node_ipv6_or_preferred() and node_ipv6_dir_preferred() in order to
- check for a null address. Closes ticket 23873. Patch by
- Neel Chauhan.
- - We switch to should_record_bridge_info() in
- geoip_note_client_seen() and options_need_geoip_info() instead of
- accessing the configuration values directly. Fixes bug 25290;
- bugfix on 0.2.1.6-alpha. Patch by Neel Chauhan.
-
- o Deprecated features:
- - As we are not recommending 0.2.5 anymore, we require relays that
- once had an ed25519 key associated with their RSA key to always
- have that key, instead of allowing them to drop back to a version
- that didn't support ed25519. This means they need to use a new RSA
- key if the want to downgrade to an older version of tor without
- ed25519. Closes ticket 20522.
-
- o Documentation:
- - Correct an IPv6 error in the documentation for ExitPolicy. Closes
- ticket 25857. Patch from "CTassisF".
-
- o Removed features:
- - Directory authorities will no longer support voting according to
- any consensus method before consensus method 25. This keeps
- authorities compatible with all authorities running 0.2.9.8 and
- later, and does not break any clients or relays. Implements ticket
- 24378 and proposal 290.
- - The PortForwarding and PortForwardingHelper features have been
- removed. The reasoning is, given that implementations of NAT
- traversal protocols within common consumer grade routers are
- frequently buggy, and that the target audience for a NAT punching
- feature is a perhaps less-technically-inclined relay operator,
- when the helper fails to setup traversal the problems are usually
- deep, ugly, and very router specific, making them horrendously
- impossible for technical support to reliable assist with, and thus
- resulting in frustration all around. Unfortunately, relay
- operators who would like to run relays behind NATs will need to
- become more familiar with the port forwarding configurations on
- their local router. Closes 25409.
- - The TestingEnableTbEmptyEvent option has been removed. It was used
- in testing simulations to measure how often connection buckets
- were emptied, in order to improve our scheduling, but it has not
- been actively used in years. Closes ticket 25760.
- - The old "round-robin" circuit multiplexer (circuitmux)
- implementation has been removed, along with a fairly large set of
- code that existed to support it. It has not been the default
- circuitmux since we introduced the "EWMA" circuitmux in 0.2.4.x,
- but it still required an unreasonable amount of memory and CPU.
- Closes ticket 25268.
-
-
Changes in version 0.3.3.5-rc - 2018-04-15
Tor 0.3.3.5-rc fixes various bugs in earlier versions of Tor,
including some that could affect reliability or correctness.
@@ -788,7 +63,7 @@ Changes in version 0.3.3.5-rc - 2018-04-15
- Revert a misformatting issue in the ExitPolicy documentation.
Fixes bug 25582; bugfix on 0.3.3.1-alpha.
- o Minor bugfixes (exit relay DNS retries):
+ o Minor bugfixes (exit node DNS retries):
- Re-attempt timed-out DNS queries 3 times before failure, since our
timeout is 5 seconds for them, but clients wait 10-15. Also allow
slightly more timeouts per resolver when an exit has multiple
@@ -815,7 +90,7 @@ Changes in version 0.3.3.5-rc - 2018-04-15
Changes in version 0.3.3.4-alpha - 2018-03-29
Tor 0.3.3.4-alpha includes various bugfixes for issues found during
the alpha testing of earlier releases in its series. We are
- approaching a stable 0.3.3.4-alpha release: more testing is welcome!
+ approaching a stable 0.3.3 release: more testing is welcome!
o New system requirements:
- When built with Rust, Tor now depends on version 0.2.39 of the
@@ -860,17 +135,15 @@ Changes in version 0.3.3.4-alpha - 2018-03-29
circuit from the controller to become a multihop circuit. Fixes
bug 24903; bugfix on 0.2.5.2-alpha.
- o Major bugfixes (networking):
- - Tor will no longer reject IPv6 address strings from Tor Browser
+ o Minor bugfixes (networking):
+ - Tor will no longer reject IPv6 address strings from TorBrowser
when they are passed as hostnames in SOCKS5 requests. Fixes bug
25036, bugfix on Tor 0.3.1.2.
-
- o Minor bugfixes (networking):
- string_is_valid_hostname() will not consider IP strings to be
valid hostnames. Fixes bug 25055; bugfix on Tor 0.2.5.5.
o Minor bugfixes (onion service v3):
- - Avoid an assertion failure when the next onion service
+ - Avoid an assertion failure when the next the next onion service
descriptor rotation type is out of sync with the consensus's
valid-after time. Instead, log a warning message with extra
information, so we can better hunt down the cause of this
@@ -910,6 +183,265 @@ Changes in version 0.3.3.4-alpha - 2018-03-29
logging domains. Closes ticket 25378.
+Changes in version 0.3.3.3-alpha - 2018-03-03
+ Tor 0.3.3.3-alpha is the third alpha release for the 0.3.3.x series.
+ It includes an important security fix for a remote crash attack
+ against directory authorities tracked as TROVE-2018-001.
+
+ Additionally, with this release, we are upgrading the severity of a
+ bug fixed in 0.3.3.2-alpha. Bug 24700, which was fixed in
+ 0.3.3.2-alpha, can be remotely triggered in order to crash relays with
+ a use-after-free pattern. As such, we are now tracking that bug as
+ TROVE-2018-002 and CVE-2018-0491. This bug affected versions
+ 0.3.2.1-alpha through 0.3.2.9, as well as 0.3.3.1-alpha.
+
+ This release also fixes several minor bugs and annoyances from
+ earlier releases.
+
+ Relays running 0.3.2.x should upgrade to one of the versions released
+ today, for the fix to TROVE-2018-002. Directory authorities should
+ also upgrade. (Relays on earlier versions might want to update too for
+ the DoS mitigations.)
+
+ o Major bugfixes (denial-of-service, directory authority):
+ - Fix a protocol-list handling bug that could be used to remotely crash
+ directory authorities with a null-pointer exception. Fixes bug 25074;
+ bugfix on 0.2.9.4-alpha. Also tracked as TROVE-2018-001 and
+ CVE-2018-0490.
+
+ o Minor features (compatibility, OpenSSL):
+ - Tor will now support TLS1.3 once OpenSSL 1.1.1 is released.
+ Previous versions of Tor would not have worked with OpenSSL 1.1.1,
+ since they neither disabled TLS 1.3 nor enabled any of the
+ ciphersuites it requires. Now we enable the TLS 1.3 ciphersuites.
+ Closes ticket 24978.
+
+ o Minor features (logging):
+ - Clarify the log messages produced when getrandom() or a related
+ entropy-generation mechanism gives an error. Closes ticket 25120.
+
+ o Minor features (testing):
+ - Add a "make test-rust" target to run the rust tests only. Closes
+ ticket 25071.
+
+ o Minor bugfixes (denial-of-service):
+ - Fix a possible crash on malformed consensus. If a consensus had
+ contained an unparseable protocol line, it could have made clients
+ and relays crash with a null-pointer exception. To exploit this
+ issue, however, an attacker would need to be able to subvert the
+ directory authority system. Fixes bug 25251; bugfix on
+ 0.2.9.4-alpha. Also tracked as TROVE-2018-004.
+
+ o Minor bugfixes (DoS mitigation):
+ - Add extra safety checks when refilling the circuit creation bucket
+ to ensure we never set a value above the allowed maximum burst.
+ Fixes bug 25202; bugfix on 0.3.3.2-alpha.
+ - When a new consensus arrives, don't update our DoS-mitigation
+ parameters if we aren't a public relay. Fixes bug 25223; bugfix
+ on 0.3.3.2-alpha.
+
+ o Minor bugfixes (man page, SocksPort):
+ - Remove dead code from the old "SocksSocket" option, and rename
+ SocksSocketsGroupWritable to UnixSocksGroupWritable. The old option
+ still works, but is deprecated. Fixes bug 24343; bugfix on 0.2.6.3.
+
+ o Minor bugfixes (performance):
+ - Reduce the number of circuits that will be opened at once during
+ the circuit build timeout phase. This is done by increasing the
+ idle timeout to 3 minutes, and lowering the maximum number of
+ concurrent learning circuits to 10. Fixes bug 24769; bugfix
+ on 0.3.1.1-alpha.
+
+ o Minor bugfixes (spec conformance):
+ - Forbid "-0" as a protocol version. Fixes part of bug 25249; bugfix on
+ 0.2.9.4-alpha.
+ - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
+ bugfix on 0.2.9.4-alpha.
+
+ o Minor bugfixes (spec conformance, rust):
+ - Resolve a denial-of-service issue caused by an infinite loop in
+ the rust protover code. Fixes bug 25250, bugfix on 0.3.3.1-alpha.
+ Also tracked as TROVE-2018-003.
+
+ o Code simplification and refactoring:
+ - Update the "rust dependencies" submodule to be a project-level
+ repository, rather than a user repository. Closes ticket 25323.
+
+
+Changes in version 0.3.2.10 - 2018-03-03
+ Tor 0.3.2.10 is the second stable release in the 0.3.2 series. It
+ backports a number of bugfixes, including important fixes for security
+ issues.
+
+ It includes an important security fix for a remote crash attack
+ against directory authorities, tracked as TROVE-2018-001.
+
+ Additionally, it backports a fix for a bug whose severity we have
+ upgraded: Bug 24700, which was fixed in 0.3.3.2-alpha, can be remotely
+ triggered in order to crash relays with a use-after-free pattern. As
+ such, we are now tracking that bug as TROVE-2018-002 and
+ CVE-2018-0491, and backporting it to earlier releases. This bug
+ affected versions 0.3.2.1-alpha through 0.3.2.9, as well as version
+ 0.3.3.1-alpha.
+
+ This release also backports our new system for improved resistance to
+ denial-of-service attacks against relays.
+
+ This release also fixes several minor bugs and annoyances from
+ earlier releases.
+
+ Relays running 0.3.2.x SHOULD upgrade to one of the versions released
+ today, for the fix to TROVE-2018-002. Directory authorities should
+ also upgrade. (Relays on earlier versions might want to update too for
+ the DoS mitigations.)
+
+ o Major bugfixes (denial-of-service, directory authority, backport from 0.3.3.3-alpha):
+ - Fix a protocol-list handling bug that could be used to remotely crash
+ directory authorities with a null-pointer exception. Fixes bug 25074;
+ bugfix on 0.2.9.4-alpha. Also tracked as TROVE-2018-001 and
+ CVE-2018-0490.
+
+ o Major bugfixes (scheduler, KIST, denial-of-service, backport from 0.3.3.2-alpha):
+ - Avoid adding the same channel twice in the KIST scheduler pending
+ list, which could lead to remote denial-of-service use-after-free
+ attacks against relays. Fixes bug 24700; bugfix on 0.3.2.1-alpha.
+
+ o Major features (denial-of-service mitigation, backport from 0.3.3.2-alpha):
+ - Give relays some defenses against the recent network overload. We
+ start with three defenses (default parameters in parentheses).
+ First: if a single client address makes too many concurrent
+ connections (>100), hang up on further connections. Second: if a
+ single client address makes circuits too quickly (more than 3 per
+ second, with an allowed burst of 90) while also having too many
+ connections open (3), refuse new create cells for the next while
+ (1-2 hours). Third: if a client asks to establish a rendezvous
+ point to you directly, ignore the request. These defenses can be
+ manually controlled by new torrc options, but relays will also
+ take guidance from consensus parameters, so there's no need to
+ configure anything manually. Implements ticket 24902.
+
+ o Major bugfixes (onion services, retry behavior, backport from 0.3.3.1-alpha):
+ - Fix an "off by 2" error in counting rendezvous failures on the
+ onion service side. While we thought we would stop the rendezvous
+ attempt after one failed circuit, we were actually making three
+ circuit attempts before giving up. Now switch to a default of 2,
+ and allow the consensus parameter "hs_service_max_rdv_failures" to
+ override. Fixes bug 24895; bugfix on 0.0.6.
+ - New-style (v3) onion services now obey the "max rendezvous circuit
+ attempts" logic. Previously they would make as many rendezvous
+ circuit attempts as they could fit in the MAX_REND_TIMEOUT second
+ window before giving up. Fixes bug 24894; bugfix on 0.3.2.1-alpha.
+
+ o Major bugfixes (protocol versions, backport from 0.3.3.2-alpha):
+ - Add Link protocol version 5 to the supported protocols list. Fixes
+ bug 25070; bugfix on 0.3.1.1-alpha.
+
+ o Major bugfixes (relay, backport from 0.3.3.1-alpha):
+ - Fix a set of false positives where relays would consider
+ connections to other relays as being client-only connections (and
+ thus e.g. deserving different link padding schemes) if those
+ relays fell out of the consensus briefly. Now we look only at the
+ initial handshake and whether the connection authenticated as a
+ relay. Fixes bug 24898; bugfix on 0.3.1.1-alpha.
+
+ o Major bugfixes (scheduler, consensus, backport from 0.3.3.2-alpha):
+ - The scheduler subsystem was failing to promptly notice changes in
+ consensus parameters, making it harder to switch schedulers
+ network-wide. Fixes bug 24975; bugfix on 0.3.2.1-alpha.
+
+ o Minor features (denial-of-service avoidance, backport from 0.3.3.2-alpha):
+ - Make our OOM handler aware of the geoip client history cache so it
+ doesn't fill up the memory. This check is important for IPv6 and
+ our DoS mitigation subsystem. Closes ticket 25122.
+
+ o Minor features (compatibility, OpenSSL, backport from 0.3.3.3-alpha):
+ - Tor will now support TLS1.3 once OpenSSL 1.1.1 is released.
+ Previous versions of Tor would not have worked with OpenSSL 1.1.1,
+ since they neither disabled TLS 1.3 nor enabled any of the
+ ciphersuites it requires. Now we enable the TLS 1.3 ciphersuites.
+ Closes ticket 24978.
+
+ o Minor features (geoip):
+ - Update geoip and geoip6 to the February 7 2018 Maxmind GeoLite2
+ Country database.
+
+ o Minor features (logging, diagnostic, backport from 0.3.3.2-alpha):
+ - When logging a failure to check a hidden service's certificate,
+ also log what the problem with the certificate was. Diagnostic
+ for ticket 24972.
+
+ o Minor bugfix (channel connection, backport from 0.3.3.2-alpha):
+ - Use the actual observed address of an incoming relay connection,
+ not the canonical address of the relay from its descriptor, when
+ making decisions about how to handle the incoming connection.
+ Fixes bug 24952; bugfix on 0.2.4.11-alpha. Patch by "ffmancera".
+
+ o Minor bugfixes (denial-of-service, backport from 0.3.3.3-alpha):
+ - Fix a possible crash on malformed consensus. If a consensus had
+ contained an unparseable protocol line, it could have made clients
+ and relays crash with a null-pointer exception. To exploit this
+ issue, however, an attacker would need to be able to subvert the
+ directory authority system. Fixes bug 25251; bugfix on
+ 0.2.9.4-alpha. Also tracked as TROVE-2018-004.
+
+ o Minor bugfix (directory authority, backport from 0.3.3.2-alpha):
+ - Directory authorities, when refusing a descriptor from a rejected
+ relay, now explicitly tell the relay (in its logs) to set a valid
+ ContactInfo address and contact the bad-relays@ mailing list.
+ Fixes bug 25170; bugfix on 0.2.9.1.
+
+ o Minor bugfixes (build, rust, backport from 0.3.3.1-alpha):
+ - When building with Rust on OSX, link against libresolv, to work
+ around the issue at https://github.com/rust-lang/rust/issues/46797.
+ Fixes bug 24652; bugfix on 0.3.1.1-alpha.
+
+ o Minor bugfixes (onion services, backport from 0.3.3.2-alpha):
+ - Remove a BUG() statement when a client fetches an onion descriptor
+ that has a lower revision counter than the one in its cache. This
+ can happen in normal circumstances due to HSDir desync. Fixes bug
+ 24976; bugfix on 0.3.2.1-alpha.
+
+ o Minor bugfixes (logging, backport from 0.3.3.2-alpha):
+ - Don't treat inability to store a cached consensus object as a bug:
+ it can happen normally when we are out of disk space. Fixes bug
+ 24859; bugfix on 0.3.1.1-alpha.
+
+ o Minor bugfixes (performance, fragile-hardening, backport from 0.3.3.1-alpha):
+ - Improve the performance of our consensus-diff application code
+ when Tor is built with the --enable-fragile-hardening option set.
+ Fixes bug 24826; bugfix on 0.3.1.1-alpha.
+
+ o Minor bugfixes (OSX, backport from 0.3.3.1-alpha):
+ - Don't exit the Tor process if setrlimit() fails to change the file
+ limit (which can happen sometimes on some versions of OSX). Fixes
+ bug 21074; bugfix on 0.0.9pre5.
+
+ o Minor bugfixes (spec conformance, backport from 0.3.3.3-alpha):
+ - Forbid "-0" as a protocol version. Fixes part of bug 25249; bugfix on
+ 0.2.9.4-alpha.
+ - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
+ bugfix on 0.2.9.4-alpha.
+
+ o Minor bugfixes (testing, backport from 0.3.3.1-alpha):
+ - Fix a memory leak in the scheduler/loop_kist unit test. Fixes bug
+ 25005; bugfix on 0.3.2.7-rc.
+
+ o Minor bugfixes (v3 onion services, backport from 0.3.3.2-alpha):
+ - Look at the "HSRend" protocol version, not the "HSDir" protocol
+ version, when deciding whether a consensus entry can support the
+ v3 onion service protocol as a rendezvous point. Fixes bug 25105;
+ bugfix on 0.3.2.1-alpha.
+
+ o Code simplification and refactoring (backport from 0.3.3.3-alpha):
+ - Update the "rust dependencies" submodule to be a project-level
+ repository, rather than a user repository. Closes ticket 25323.
+
+ o Documentation (backport from 0.3.3.1-alpha)
+ - Document that operators who run more than one relay or bridge are
+ expected to set MyFamily and ContactInfo correctly. Closes
+ ticket 24526.
+
+
Changes in version 0.3.1.10 - 2018-03-03
Tor 0.3.1.10 backports a number of bugfixes, including important fixes for
security issues.
@@ -924,11 +456,11 @@ Changes in version 0.3.1.10 - 2018-03-03
earlier releases.
All directory authorities should upgrade to one of the versions
- released today. Relays running 0.3.1.x may wish to update to one of
+ released today. Relays running 0.3.1.x may wish to update to one of
the versions released today, for the DoS mitigations.
Please note: according to our release calendar, Tor 0.3.1 will no
- longer be supported after 1 July 2018. If you will be running Tor
+ longer be supported after 1 July 2018. If you will be running Tor
after that date, you should make sure to plan to upgrade to the latest
stable version, or downgrade to 0.2.9 (which will receive long-term
support).
@@ -1132,7 +664,7 @@ Changes in version 0.3.1.10 - 2018-03-03
o Minor bugfixes (spec conformance, backport from 0.3.3.3-alpha):
- Forbid "-0" as a protocol version. Fixes part of bug 25249; bugfix on
0.2.9.4-alpha.
- - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
+ - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
bugfix on 0.2.9.4-alpha.
o Code simplification and refactoring (backport from 0.3.3.3-alpha):
@@ -1154,7 +686,7 @@ Changes in version 0.2.9.15 - 2018-03-03
earlier releases.
All directory authorities should upgrade to one of the versions
- released today. Relays running 0.2.9.x may wish to update to one of
+ released today. Relays running 0.2.9.x may wish to update to one of
the versions released today, for the DoS mitigations.
o Major bugfixes (denial-of-service, directory authority, backport from 0.3.3.3-alpha):
@@ -1313,269 +845,10 @@ Changes in version 0.2.9.15 - 2018-03-03
o Minor bugfixes (spec conformance, backport from 0.3.3.3-alpha):
- Forbid "-0" as a protocol version. Fixes part of bug 25249; bugfix on
0.2.9.4-alpha.
- - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
+ - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
bugfix on 0.2.9.4-alpha.
-Changes in version 0.3.2.10 - 2018-03-03
- Tor 0.3.2.10 is the second stable release in the 0.3.2 series. It
- backports a number of bugfixes, including important fixes for security
- issues.
-
- It includes an important security fix for a remote crash attack
- against directory authorities, tracked as TROVE-2018-001.
-
- Additionally, it backports a fix for a bug whose severity we have
- upgraded: Bug 24700, which was fixed in 0.3.3.2-alpha, can be remotely
- triggered in order to crash relays with a use-after-free pattern. As
- such, we are now tracking that bug as TROVE-2018-002 and
- CVE-2018-0491, and backporting it to earlier releases. This bug
- affected versions 0.3.2.1-alpha through 0.3.2.9, as well as version
- 0.3.3.1-alpha.
-
- This release also backports our new system for improved resistance to
- denial-of-service attacks against relays.
-
- This release also fixes several minor bugs and annoyances from
- earlier releases.
-
- Relays running 0.3.2.x SHOULD upgrade to one of the versions released
- today, for the fix to TROVE-2018-002. Directory authorities should
- also upgrade. (Relays on earlier versions might want to update too for
- the DoS mitigations.)
-
- o Major bugfixes (denial-of-service, directory authority, backport from 0.3.3.3-alpha):
- - Fix a protocol-list handling bug that could be used to remotely crash
- directory authorities with a null-pointer exception. Fixes bug 25074;
- bugfix on 0.2.9.4-alpha. Also tracked as TROVE-2018-001 and
- CVE-2018-0490.
-
- o Major bugfixes (scheduler, KIST, denial-of-service, backport from 0.3.3.2-alpha):
- - Avoid adding the same channel twice in the KIST scheduler pending
- list, which could lead to remote denial-of-service use-after-free
- attacks against relays. Fixes bug 24700; bugfix on 0.3.2.1-alpha.
-
- o Major features (denial-of-service mitigation, backport from 0.3.3.2-alpha):
- - Give relays some defenses against the recent network overload. We
- start with three defenses (default parameters in parentheses).
- First: if a single client address makes too many concurrent
- connections (>100), hang up on further connections. Second: if a
- single client address makes circuits too quickly (more than 3 per
- second, with an allowed burst of 90) while also having too many
- connections open (3), refuse new create cells for the next while
- (1-2 hours). Third: if a client asks to establish a rendezvous
- point to you directly, ignore the request. These defenses can be
- manually controlled by new torrc options, but relays will also
- take guidance from consensus parameters, so there's no need to
- configure anything manually. Implements ticket 24902.
-
- o Major bugfixes (onion services, retry behavior, backport from 0.3.3.1-alpha):
- - Fix an "off by 2" error in counting rendezvous failures on the
- onion service side. While we thought we would stop the rendezvous
- attempt after one failed circuit, we were actually making three
- circuit attempts before giving up. Now switch to a default of 2,
- and allow the consensus parameter "hs_service_max_rdv_failures" to
- override. Fixes bug 24895; bugfix on 0.0.6.
- - New-style (v3) onion services now obey the "max rendezvous circuit
- attempts" logic. Previously they would make as many rendezvous
- circuit attempts as they could fit in the MAX_REND_TIMEOUT second
- window before giving up. Fixes bug 24894; bugfix on 0.3.2.1-alpha.
-
- o Major bugfixes (protocol versions, backport from 0.3.3.2-alpha):
- - Add Link protocol version 5 to the supported protocols list. Fixes
- bug 25070; bugfix on 0.3.1.1-alpha.
-
- o Major bugfixes (relay, backport from 0.3.3.1-alpha):
- - Fix a set of false positives where relays would consider
- connections to other relays as being client-only connections (and
- thus e.g. deserving different link padding schemes) if those
- relays fell out of the consensus briefly. Now we look only at the
- initial handshake and whether the connection authenticated as a
- relay. Fixes bug 24898; bugfix on 0.3.1.1-alpha.
-
- o Major bugfixes (scheduler, consensus, backport from 0.3.3.2-alpha):
- - The scheduler subsystem was failing to promptly notice changes in
- consensus parameters, making it harder to switch schedulers
- network-wide. Fixes bug 24975; bugfix on 0.3.2.1-alpha.
-
- o Minor features (denial-of-service avoidance, backport from 0.3.3.2-alpha):
- - Make our OOM handler aware of the geoip client history cache so it
- doesn't fill up the memory. This check is important for IPv6 and
- our DoS mitigation subsystem. Closes ticket 25122.
-
- o Minor features (compatibility, OpenSSL, backport from 0.3.3.3-alpha):
- - Tor will now support TLS1.3 once OpenSSL 1.1.1 is released.
- Previous versions of Tor would not have worked with OpenSSL 1.1.1,
- since they neither disabled TLS 1.3 nor enabled any of the
- ciphersuites it requires. Now we enable the TLS 1.3 ciphersuites.
- Closes ticket 24978.
-
- o Minor features (geoip):
- - Update geoip and geoip6 to the February 7 2018 Maxmind GeoLite2
- Country database.
-
- o Minor features (logging, diagnostic, backport from 0.3.3.2-alpha):
- - When logging a failure to create an onion service's descriptor,
- also log what the problem with the descriptor was. Diagnostic
- for ticket 24972.
-
- o Minor bugfix (channel connection, backport from 0.3.3.2-alpha):
- - Use the actual observed address of an incoming relay connection,
- not the canonical address of the relay from its descriptor, when
- making decisions about how to handle the incoming connection.
- Fixes bug 24952; bugfix on 0.2.4.11-alpha. Patch by "ffmancera".
-
- o Minor bugfixes (denial-of-service, backport from 0.3.3.3-alpha):
- - Fix a possible crash on malformed consensus. If a consensus had
- contained an unparseable protocol line, it could have made clients
- and relays crash with a null-pointer exception. To exploit this
- issue, however, an attacker would need to be able to subvert the
- directory authority system. Fixes bug 25251; bugfix on
- 0.2.9.4-alpha. Also tracked as TROVE-2018-004.
-
- o Minor bugfix (directory authority, backport from 0.3.3.2-alpha):
- - Directory authorities, when refusing a descriptor from a rejected
- relay, now explicitly tell the relay (in its logs) to set a valid
- ContactInfo address and contact the bad-relays@ mailing list.
- Fixes bug 25170; bugfix on 0.2.9.1.
-
- o Minor bugfixes (build, rust, backport from 0.3.3.1-alpha):
- - When building with Rust on OSX, link against libresolv, to work
- around the issue at https://github.com/rust-lang/rust/issues/46797.
- Fixes bug 24652; bugfix on 0.3.1.1-alpha.
-
- o Minor bugfixes (onion services, backport from 0.3.3.2-alpha):
- - Remove a BUG() statement when a client fetches an onion descriptor
- that has a lower revision counter than the one in its cache. This
- can happen in normal circumstances due to HSDir desync. Fixes bug
- 24976; bugfix on 0.3.2.1-alpha.
-
- o Minor bugfixes (logging, backport from 0.3.3.2-alpha):
- - Don't treat inability to store a cached consensus object as a bug:
- it can happen normally when we are out of disk space. Fixes bug
- 24859; bugfix on 0.3.1.1-alpha.
-
- o Minor bugfixes (performance, fragile-hardening, backport from 0.3.3.1-alpha):
- - Improve the performance of our consensus-diff application code
- when Tor is built with the --enable-fragile-hardening option set.
- Fixes bug 24826; bugfix on 0.3.1.1-alpha.
-
- o Minor bugfixes (OSX, backport from 0.3.3.1-alpha):
- - Don't exit the Tor process if setrlimit() fails to change the file
- limit (which can happen sometimes on some versions of OSX). Fixes
- bug 21074; bugfix on 0.0.9pre5.
-
- o Minor bugfixes (spec conformance, backport from 0.3.3.3-alpha):
- - Forbid "-0" as a protocol version. Fixes part of bug 25249; bugfix on
- 0.2.9.4-alpha.
- - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
- bugfix on 0.2.9.4-alpha.
-
- o Minor bugfixes (testing, backport from 0.3.3.1-alpha):
- - Fix a memory leak in the scheduler/loop_kist unit test. Fixes bug
- 25005; bugfix on 0.3.2.7-rc.
-
- o Minor bugfixes (v3 onion services, backport from 0.3.3.2-alpha):
- - Look at the "HSRend" protocol version, not the "HSDir" protocol
- version, when deciding whether a consensus entry can support the
- v3 onion service protocol as a rendezvous point. Fixes bug 25105;
- bugfix on 0.3.2.1-alpha.
-
- o Code simplification and refactoring (backport from 0.3.3.3-alpha):
- - Update the "rust dependencies" submodule to be a project-level
- repository, rather than a user repository. Closes ticket 25323.
-
- o Documentation (backport from 0.3.3.1-alpha)
- - Document that operators who run more than one relay or bridge are
- expected to set MyFamily and ContactInfo correctly. Closes
- ticket 24526.
-
-
-Changes in version 0.3.3.3-alpha - 2018-03-03
- Tor 0.3.3.3-alpha is the third alpha release for the 0.3.3.x series.
- It includes an important security fix for a remote crash attack
- against directory authorities tracked as TROVE-2018-001.
-
- Additionally, with this release, we are upgrading the severity of a
- bug fixed in 0.3.3.2-alpha. Bug 24700, which was fixed in
- 0.3.3.2-alpha, can be remotely triggered in order to crash relays with
- a use-after-free pattern. As such, we are now tracking that bug as
- TROVE-2018-002 and CVE-2018-0491. This bug affected versions
- 0.3.2.1-alpha through 0.3.2.9, as well as 0.3.3.1-alpha.
-
- This release also fixes several minor bugs and annoyances from
- earlier releases.
-
- Relays running 0.3.2.x should upgrade to one of the versions released
- today, for the fix to TROVE-2018-002. Directory authorities should
- also upgrade. (Relays on earlier versions might want to update too for
- the DoS mitigations.)
-
- o Major bugfixes (denial-of-service, directory authority):
- - Fix a protocol-list handling bug that could be used to remotely crash
- directory authorities with a null-pointer exception. Fixes bug 25074;
- bugfix on 0.2.9.4-alpha. Also tracked as TROVE-2018-001 and
- CVE-2018-0490.
-
- o Minor features (compatibility, OpenSSL):
- - Tor will now support TLS1.3 once OpenSSL 1.1.1 is released.
- Previous versions of Tor would not have worked with OpenSSL 1.1.1,
- since they neither disabled TLS 1.3 nor enabled any of the
- ciphersuites it requires. Now we enable the TLS 1.3 ciphersuites.
- Closes ticket 24978.
-
- o Minor features (logging):
- - Clarify the log messages produced when getrandom() or a related
- entropy-generation mechanism gives an error. Closes ticket 25120.
-
- o Minor features (testing):
- - Add a "make test-rust" target to run the rust tests only. Closes
- ticket 25071.
-
- o Minor bugfixes (denial-of-service):
- - Fix a possible crash on malformed consensus. If a consensus had
- contained an unparseable protocol line, it could have made clients
- and relays crash with a null-pointer exception. To exploit this
- issue, however, an attacker would need to be able to subvert the
- directory authority system. Fixes bug 25251; bugfix on
- 0.2.9.4-alpha. Also tracked as TROVE-2018-004.
-
- o Minor bugfixes (DoS mitigation):
- - Add extra safety checks when refilling the circuit creation bucket
- to ensure we never set a value above the allowed maximum burst.
- Fixes bug 25202; bugfix on 0.3.3.2-alpha.
- - When a new consensus arrives, don't update our DoS-mitigation
- parameters if we aren't a public relay. Fixes bug 25223; bugfix
- on 0.3.3.2-alpha.
-
- o Minor bugfixes (man page, SocksPort):
- - Remove dead code from the old "SocksSocket" option, and rename
- SocksSocketsGroupWritable to UnixSocksGroupWritable. The old option
- still works, but is deprecated. Fixes bug 24343; bugfix on 0.2.6.3.
-
- o Minor bugfixes (performance):
- - Reduce the number of circuits that will be opened at once during
- the circuit build timeout phase. This is done by increasing the
- idle timeout to 3 minutes, and lowering the maximum number of
- concurrent learning circuits to 10. Fixes bug 24769; bugfix
- on 0.3.1.1-alpha.
-
- o Minor bugfixes (spec conformance):
- - Forbid "-0" as a protocol version. Fixes part of bug 25249; bugfix on
- 0.2.9.4-alpha.
- - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
- bugfix on 0.2.9.4-alpha.
-
- o Minor bugfixes (spec conformance, rust):
- - Resolve a denial-of-service issue caused by an infinite loop in
- the rust protover code. Fixes bug 25250, bugfix on 0.3.3.1-alpha.
- Also tracked as TROVE-2018-003.
-
- o Code simplification and refactoring:
- - Update the "rust dependencies" submodule to be a project-level
- repository, rather than a user repository. Closes ticket 25323.
-
-
Changes in version 0.3.3.2-alpha - 2018-02-10
Tor 0.3.3.2-alpha is the second alpha in the 0.3.3.x series. It
introduces a mechanism to handle the high loads that many relay
@@ -1749,12 +1022,12 @@ Changes in version 0.3.3.1-alpha - 2018-01-25
o Major features (IPv6, directory documents):
- Add consensus method 27, which adds IPv6 ORPorts to the microdesc
consensus. This information makes it easier for IPv6 clients to
- bootstrap and choose reachable entry guards. Implements ticket 23826.
+ bootstrap and choose reachable entry guards. Implements 23826.
- Add consensus method 28, which removes IPv6 ORPorts from
- microdescriptors. Now that the consensus contains IPv6 ORPorts, they
- are redundant in microdescs. This change will be used by Tor clients
- on 0.2.8.x and later. (That is to say, with all Tor clients that
- have IPv6 bootstrap and guard support.) Implements ticket 23828.
+ microdescriptors. Now that the consensus contains IPv6 ORPorts,
+ they are redundant in microdescs. This change will be used by Tor
+ clients on 0.2.8.x and later. (That is to say, with all Tor
+ clients having IPv6 bootstrap and guard support.) Implements 23828.
- Expand the documentation for AuthDirHasIPv6Connectivity when it is
set by different numbers of authorities. Fixes 23870
on 0.2.4.1-alpha.
@@ -1784,7 +1057,7 @@ Changes in version 0.3.3.1-alpha - 2018-01-25
experience with Rust, and plan future Rust integration work.
Implementation by Chelsea Komlo. Closes ticket 22840.
- o Minor features (storage, configuration):
+ o Major features (storage, configuration):
- Users can store cached directory documents somewhere other than
the DataDirectory by using the CacheDirectory option. Similarly,
the storage location for relay's keys can be overridden with the
@@ -1821,10 +1094,10 @@ Changes in version 0.3.3.1-alpha - 2018-01-25
o Minor feature (IPv6):
- Make IPv6-only clients wait for microdescs for relays, even if we
were previously using descriptors (or were using them as a bridge)
- and have a cached descriptor for them. Implements ticket 23827.
+ and have a cached descriptor for them. Implements 23827.
- When a consensus has IPv6 ORPorts, make IPv6-only clients use
them, rather than waiting to download microdescriptors.
- Implements ticket 23827.
+ Implements 23827.
o Minor features (cleanup):
- Tor now deletes the CookieAuthFile and ExtORPortCookieAuthFile
@@ -1838,8 +1111,14 @@ Changes in version 0.3.3.1-alpha - 2018-01-25
- Where possible, the tor_free() macro now only evaluates its input
once. Part of ticket 24337.
- Check that microdesc ed25519 ids are non-zero in
- node_get_ed25519_id() before returning them. Implements ticket
- 24001, patch by "aruna1234".
+ node_get_ed25519_id() before returning them. Implements 24001,
+ patch by "aruna1234".
+
+ o Minor features (directory authority):
+ - Make the "Exit" flag assignment only depend on whether the exit
+ policy allows connections to ports 80 and 443. Previously relays
+ would get the Exit flag if they allowed connections to one of
+ these ports and also port 6667. Resolves ticket 23637.
o Minor features (embedding):
- Tor can now start with a preauthenticated control connection
@@ -1851,7 +1130,7 @@ Changes in version 0.3.3.1-alpha - 2018-01-25
- On most errors that would cause Tor to exit, it now tries to
return from the tor_main() function, rather than calling the
system exit() function. Most users won't notice a difference here,
- but it should be significant for programs that run Tor inside
+ but it should make a significant for programs that run Tor inside
a separate thread: they should now be able to survive Tor's exit
conditions rather than having Tor shut down the entire process.
Closes ticket 23848.
@@ -1951,7 +1230,7 @@ Changes in version 0.3.3.1-alpha - 2018-01-25
SIO_IDEAL_SEND_BACKLOG_QUERY. Closes ticket 22798. Patch
from Vort.
- o Major features (relay):
+ o Minor features (relay):
- Implement an option, ReducedExitPolicy, to allow an Tor exit relay
operator to use a more reasonable ("reduced") exit policy, rather
than the default one. If you want to run an exit node without
@@ -2111,7 +1390,7 @@ Changes in version 0.3.3.1-alpha - 2018-01-25
adding very little except for unit test.
o Code simplification and refactoring (circuit rendezvous):
- - Split the client-side rendezvous circuit lookup into two
+ - Split the client-size rendezvous circuit lookup into two
functions: one that returns only established circuits and another
that returns all kinds of circuits. Closes ticket 23459.
@@ -3312,7 +2591,7 @@ Changes in version 0.3.2.2-alpha - 2017-09-29
include better testing and logging.
The following comprises the complete list of changes included
- in 0.3.2.2-alpha:
+ in tor-0.3.2.2-alpha:
o Major bugfixes (relay, crash, assertion failure):
- Fix a timing-based assertion failure that could occur when the
@@ -5920,7 +5199,7 @@ Changes in version 0.3.0.4-rc - 2017-03-01
o Major bugfixes (hidden service directory v3):
- Stop crashing on a failed v3 hidden service descriptor lookup
- failure. Fixes bug 21471; bugfixes on 0.3.0.1-alpha.
+ failure. Fixes bug 21471; bugfixes on tor-0.3.0.1-alpha.
o Major bugfixes (parsing):
- When parsing a malformed content-length field from an HTTP
@@ -6005,7 +5284,7 @@ Changes in version 0.3.0.4-rc - 2017-03-01
o Minor bugfixes (testing):
- Fix Raspbian build issues related to missing socket errno in
- test_util.c. Fixes bug 21116; bugfix on 0.2.8.2. Patch
+ test_util.c. Fixes bug 21116; bugfix on tor-0.2.8.2. Patch
by "hein".
- Rename "make fuzz" to "make test-fuzz-corpora", since it doesn't
actually fuzz anything. Fixes bug 21447; bugfix on 0.3.0.3-alpha.
@@ -6639,7 +5918,7 @@ Changes in version 0.3.0.1-alpha - 2016-12-19
- When finishing writing a file to disk, if we were about to replace
the file with the temporary file created before and we fail to
replace it, remove the temporary file so it doesn't stay on disk.
- Fixes bug 20646; bugfix on 0.2.0.7-alpha. Patch by fk.
+ Fixes bug 20646; bugfix on tor-0.2.0.7-alpha. Patch by fk.
o Minor bugfixes (Windows):
- Check for getpagesize before using it to mmap files. This fixes
@@ -6675,13 +5954,13 @@ Changes in version 0.3.0.1-alpha - 2016-12-19
o Documentation:
- Include the "TBits" unit in Tor's man page. Fixes part of bug
- 20622; bugfix on 0.2.5.1-alpha.
+ 20622; bugfix on tor-0.2.5.1-alpha.
- Change '1' to 'weight_scale' in consensus bw weights calculation
comments, as that is reality. Closes ticket 20273. Patch
from pastly.
- Correct the value for AuthDirGuardBWGuarantee in the manpage, from
250 KBytes to 2 MBytes. Fixes bug 20435; bugfix
- on 0.2.5.6-alpha.
+ on tor-0.2.5.6-alpha.
- Stop the man page from incorrectly stating that HiddenServiceDir
must already exist. Fixes 20486.
- Clarify that when ClientRejectInternalAddresses is enabled (which
@@ -28545,3 +27824,4 @@ Changes in version 0.0.2pre13 - 2003-10-19
- If --DebugLogFile is specified, log to it at -l debug
- If --LogFile is specified, use it instead of commandline
- If --RunAsDaemon is set, tor forks and backgrounds on startup
+
diff --git a/LICENSE b/LICENSE
index 057ae57652..3d0f8c121b 100644
--- a/LICENSE
+++ b/LICENSE
@@ -13,7 +13,7 @@ Tor is distributed under this license:
Copyright (c) 2001-2004, Roger Dingledine
Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
-Copyright (c) 2007-2018, The Tor Project, Inc.
+Copyright (c) 2007-2017, The Tor Project, Inc.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
diff --git a/Makefile.am b/Makefile.am
index 61451ed264..97a39031a9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
# Copyright (c) 2001-2004, Roger Dingledine
# Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
-# Copyright (c) 2007-2018, The Tor Project, Inc.
+# Copyright (c) 2007-2017, The Tor Project, Inc.
# See LICENSE for licensing information
ACLOCAL_AMFLAGS = -I m4
@@ -15,12 +15,7 @@ TESTS=
noinst_PROGRAMS=
DISTCLEANFILES=
bin_SCRIPTS=
-AM_CPPFLAGS=\
- -I$(top_srcdir)/src \
- -I$(top_srcdir)/src/ext \
- -I$(top_srcdir)/src/ext/trunnel \
- -I$(top_srcdir)/src/trunnel
-
+AM_CPPFLAGS=
AM_CFLAGS=@TOR_SYSTEMD_CFLAGS@ @CFLAGS_BUGTRAP@ @TOR_LZMA_CFLAGS@ @TOR_ZSTD_CFLAGS@
SHELL=@SHELL@
@@ -37,86 +32,17 @@ else
rust_ldadd=
endif
-# "Common" libraries used to link tor's utility code.
-TOR_UTIL_LIBS = \
- src/common/libor.a \
- src/lib/libtor-log.a \
- src/lib/libtor-lock.a \
- src/lib/libtor-fdio.a \
- src/lib/libtor-container.a \
- src/lib/libtor-string.a \
- src/lib/libtor-malloc.a \
- src/lib/libtor-wallclock.a \
- src/lib/libtor-err.a \
- src/lib/libtor-intmath.a \
- src/lib/libtor-ctime.a
-
-# Variants of the above for linking the testing variant of tor (for coverage
-# and tests)
-TOR_UTIL_TESTING_LIBS = \
- src/common/libor-testing.a \
- src/lib/libtor-log-testing.a \
- src/lib/libtor-lock-testing.a \
- src/lib/libtor-fdio-testing.a \
- src/lib/libtor-container-testing.a \
- src/lib/libtor-string-testing.a \
- src/lib/libtor-malloc-testing.a \
- src/lib/libtor-wallclock-testing.a \
- src/lib/libtor-err-testing.a \
- src/lib/libtor-intmath.a \
- src/lib/libtor-ctime-testing.a
-
-# Internal crypto libraries used in Tor
-TOR_CRYPTO_LIBS = \
- src/lib/libtor-tls.a \
- src/lib/libtor-crypt-ops.a \
- $(LIBKECCAK_TINY) \
- $(LIBDONNA)
-
-# Variants of the above for linking the testing variant of tor (for coverage
-# and tests)
-TOR_CRYPTO_TESTING_LIBS = \
- src/lib/libtor-tls-testing.a \
- src/lib/libtor-crypt-ops-testing.a \
- $(LIBKECCAK_TINY) \
- $(LIBDONNA)
-
-# All static libraries used to link tor.
-TOR_INTERNAL_LIBS = \
- src/or/libtor-app.a \
- src/lib/libtor-compress.a \
- $(TOR_CRYPTO_LIBS) \
- $(TOR_UTIL_LIBS) \
- src/common/libor-event.a \
- src/trunnel/libor-trunnel.a \
- src/lib/libtor-trace.a
-
-# Variants of the above for linking the testing variant of tor (for coverage
-# and tests)
-TOR_INTERNAL_TESTING_LIBS = \
- src/or/libtor-app-testing.a \
- src/lib/libtor-compress-testing.a \
- $(TOR_CRYPTO_TESTING_LIBS) \
- $(TOR_UTIL_TESTING_LIBS) \
- src/common/libor-event-testing.a \
- src/trunnel/libor-trunnel-testing.a \
- src/lib/libtor-trace.a
-
-# All libraries used to link tor-cov
-
include src/include.am
include doc/include.am
include contrib/include.am
EXTRA_DIST+= \
ChangeLog \
- CONTRIBUTING \
INSTALL \
LICENSE \
Makefile.nmake \
README \
ReleaseNotes \
- scripts/maint/checkIncludes.py \
scripts/maint/checkSpace.pl
## This tells etags how to find mockable function definitions.
@@ -278,19 +204,12 @@ check-spaces:
if USE_PERL
$(PERL) $(top_srcdir)/scripts/maint/checkSpace.pl -C \
$(top_srcdir)/src/common/*.[ch] \
- $(top_srcdir)/src/lib/*/*.[ch] \
$(top_srcdir)/src/or/*.[ch] \
- $(top_srcdir)/src/or/*/*.[ch] \
$(top_srcdir)/src/test/*.[ch] \
$(top_srcdir)/src/test/*/*.[ch] \
$(top_srcdir)/src/tools/*.[ch]
endif
-check-includes:
-if USEPYTHON
- $(top_srcdir)/scripts/maint/checkIncludes.py
-endif
-
check-docs: all
$(PERL) $(top_builddir)/scripts/maint/checkOptionDocs.pl
@@ -318,20 +237,6 @@ check-typos:
echo "You can install the latest version of misspell here: https://github.com/client9/misspell#install"; \
fi
-.PHONY: clippy
-clippy:
-if USE_RUST
- @if test -x "`which cargo-clippy 2>&1;true`"; then \
- echo "Running cargo clippy ..."; \
- echo "Prepare yourself for the onslaught of suggestions ..."; \
- (cd "$(top_srcdir)/src/rust" && cargo clippy); \
- else \
- echo "Tor can use clippy to lint Rust code."; \
- echo "However, it seems that you don't have clippy installed."; \
- echo "You can install the latest version of clippy by following the directions here: https://github.com/rust-lang-nursery/rust-clippy"; \
- fi
-endif
-
.PHONY: check-changes
check-changes:
if USEPYTHON
diff --git a/ReleaseNotes b/ReleaseNotes
index 8a38289c2c..93ff6d6ff6 100644
--- a/ReleaseNotes
+++ b/ReleaseNotes
@@ -1,681 +1,179 @@
-This document summarizes new features and bugfixes in each stable
-release of Tor. If you want to see more detailed descriptions of the
-changes in each development snapshot, see the ChangeLog file.
+This document summarizes new features and bugfixes in each stable release
+of Tor. If you want to see more detailed descriptions of the changes in
+each development snapshot, see the ChangeLog file.
-Changes in version 0.3.3.7 - 2018-06-12
- Tor 0.3.3.7 backports several changes from the 0.3.4.x series, including
- fixes for bugs affecting compatibility and stability.
-
- o Directory authority changes:
- - Add an IPv6 address for the "dannenberg" directory authority.
- Closes ticket 26343.
-
- o Minor features (geoip):
- - Update geoip and geoip6 to the June 7 2018 Maxmind GeoLite2
- Country database. Closes ticket 26351.
-
- o Minor bugfixes (compatibility, openssl, backport from 0.3.4.2-alpha):
- - Work around a change in OpenSSL 1.1.1 where return values that
- would previously indicate "no password" now indicate an empty
- password. Without this workaround, Tor instances running with
- OpenSSL 1.1.1 would accept descriptors that other Tor instances
- would reject. Fixes bug 26116; bugfix on 0.2.5.16.
-
- o Minor bugfixes (compilation, backport from 0.3.4.2-alpha):
- - Silence unused-const-variable warnings in zstd.h with some GCC
- versions. Fixes bug 26272; bugfix on 0.3.1.1-alpha.
-
- o Minor bugfixes (controller, backport from 0.3.4.2-alpha):
- - Improve accuracy of the BUILDTIMEOUT_SET control port event's
- TIMEOUT_RATE and CLOSE_RATE fields. (We were previously
- miscounting the total number of circuits for these field values.)
- Fixes bug 26121; bugfix on 0.3.3.1-alpha.
-
- o Minor bugfixes (hardening, backport from 0.3.4.2-alpha):
- - Prevent a possible out-of-bounds smartlist read in
- protover_compute_vote(). Fixes bug 26196; bugfix on 0.2.9.4-alpha.
-
- o Minor bugfixes (path selection, backport from 0.3.4.1-alpha):
- - Only select relays when they have the descriptors we prefer to use
- for them. This change fixes a bug where we could select a relay
- because it had _some_ descriptor, but reject it later with a
- nonfatal assertion error because it didn't have the exact one we
- wanted. Fixes bugs 25691 and 25692; bugfix on 0.3.3.4-alpha.
-
-
-Changes in version 0.3.3.6 - 2018-05-22
- Tor 0.3.3.6 is the first stable release in the 0.3.3 series. It
- backports several important fixes from the 0.3.4.1-alpha.
-
- The Tor 0.3.3 series includes controller support and other
- improvements for v3 onion services, official support for embedding Tor
- within other applications, and our first non-trivial module written in
- the Rust programming language. (Rust is still not enabled by default
- when building Tor.) And as usual, there are numerous other smaller
- bugfixes, features, and improvements.
-
- Below are the changes since 0.3.2.10. For a list of only the changes
- since 0.3.3.5-rc, see the ChangeLog file.
-
- o New system requirements:
- - When built with Rust, Tor now depends on version 0.2.39 of the
- libc crate. Closes tickets 25310 and 25664.
-
- o Major features (embedding):
- - There is now a documented stable API for programs that need to
- embed Tor. See tor_api.h for full documentation and known bugs.
- Closes ticket 23684.
- - Tor now has support for restarting in the same process.
- Controllers that run Tor using the "tor_api.h" interface can now
- restart Tor after Tor has exited. This support is incomplete,
- however: we fixed crash bugs that prevented it from working at
- all, but many bugs probably remain, including a possibility of
- security issues. Implements ticket 24581.
-
- o Major features (IPv6, directory documents):
- - Add consensus method 27, which adds IPv6 ORPorts to the microdesc
- consensus. This information makes it easier for IPv6 clients to
- bootstrap and choose reachable entry guards. Implements
- ticket 23826.
- - Add consensus method 28, which removes IPv6 ORPorts from
- microdescriptors. Now that the consensus contains IPv6 ORPorts,
- they are redundant in microdescs. This change will be used by Tor
- clients on 0.2.8.x and later. (That is to say, with all Tor
- clients that have IPv6 bootstrap and guard support.) Implements
- ticket 23828.
- - Expand the documentation for AuthDirHasIPv6Connectivity when it is
- set by different numbers of authorities. Fixes 23870
- on 0.2.4.1-alpha.
-
- o Major features (onion service v3, control port):
- - The control port now supports commands and events for v3 onion
- services. It is now possible to create ephemeral v3 services using
- ADD_ONION. Additionally, several events (HS_DESC, HS_DESC_CONTENT,
- CIRC and CIRC_MINOR) and commands (GETINFO, HSPOST, ADD_ONION and
- DEL_ONION) have been extended to support v3 onion services. Closes
- ticket 20699; implements proposal 284.
-
- o Major features (onion services):
- - Provide torrc options to pin the second and third hops of onion
- service circuits to a list of nodes. The option HSLayer2Guards
- pins the second hop, and the option HSLayer3Guards pins the third
- hop. These options are for use in conjunction with experiments
- with "vanguards" for preventing guard enumeration attacks. Closes
- ticket 13837.
- - When v3 onion service clients send introduce cells, they now
- include the IPv6 address of the rendezvous point, if it has one.
- Current v3 onion services running 0.3.2 ignore IPv6 addresses, but
- in future Tor versions, IPv6-only v3 single onion services will be
- able to use IPv6 addresses to connect directly to the rendezvous
- point. Closes ticket 23577. Patch by Neel Chauhan.
-
- o Major features (relay):
- - Implement an option, ReducedExitPolicy, to allow an Tor exit relay
- operator to use a more reasonable ("reduced") exit policy, rather
- than the default one. If you want to run an exit node without
- thinking too hard about which ports to allow, this one is for you.
- Closes ticket 13605. Patch from Neel Chauhan.
-
- o Major features (rust, portability, experimental):
- - Tor now ships with an optional implementation of one of its
- smaller modules (protover.c) in the Rust programming language. To
- try it out, install a Rust build environment, and configure Tor
- with "--enable-rust --enable-cargo-online-mode". This should not
- cause any user-visible changes, but should help us gain more
- experience with Rust, and plan future Rust integration work.
- Implementation by Chelsea Komlo. Closes ticket 22840.
-
- o Major bugfixes (directory authorities, security, backport from 0.3.4.1-alpha):
- - When directory authorities read a zero-byte bandwidth file, they
- would previously log a warning with the contents of an
- uninitialised buffer. They now log a warning about the empty file
- instead. Fixes bug 26007; bugfix on 0.2.2.1-alpha.
-
- o Major bugfixes (security, directory authority, denial-of-service):
- - Fix a bug that could have allowed an attacker to force a directory
- authority to use up all its RAM by passing it a maliciously
- crafted protocol versions string. Fixes bug 25517; bugfix on
- 0.2.9.4-alpha. This issue is also tracked as TROVE-2018-005.
-
- o Major bugfixes (crash, backport from 0.3.4.1-alpha):
- - Avoid a rare assertion failure in the circuit build timeout code
- if we fail to allow any circuits to actually complete. Fixes bug
- 25733; bugfix on 0.2.2.2-alpha.
-
- o Major bugfixes (netflow padding):
- - Stop adding unneeded channel padding right after we finish
- flushing to a connection that has been trying to flush for many
- seconds. Instead, treat all partial or complete flushes as
- activity on the channel, which will defer the time until we need
- to add padding. This fix should resolve confusing and scary log
- messages like "Channel padding timeout scheduled 221453ms in the
- past." Fixes bug 22212; bugfix on 0.3.1.1-alpha.
-
- o Major bugfixes (networking):
- - Tor will no longer reject IPv6 address strings from Tor Browser
- when they are passed as hostnames in SOCKS5 requests. Fixes bug
- 25036, bugfix on Tor 0.3.1.2.
-
- o Major bugfixes (onion service, backport from 0.3.4.1-alpha):
- - Correctly detect when onion services get disabled after HUP. Fixes
- bug 25761; bugfix on 0.3.2.1.
-
- o Major bugfixes (performance, load balancing):
- - Directory authorities no longer vote in favor of the Guard flag
- for relays without directory support. Starting in Tor
- 0.3.0.1-alpha, clients have been avoiding using such relays in the
- Guard position, leading to increasingly broken load balancing for
- the 5%-or-so of Guards that don't advertise directory support.
- Fixes bug 22310; bugfix on 0.3.0.6.
-
- o Major bugfixes (relay):
- - If we have failed to connect to a relay and received a connection
- refused, timeout, or similar error (at the TCP level), do not try
- that same address/port again for 60 seconds after the failure has
- occurred. Fixes bug 24767; bugfix on 0.0.6.
-
- o Major bugfixes (relay, denial of service, backport from 0.3.4.1-alpha):
- - Impose a limit on circuit cell queue size. The limit can be
- controlled by a consensus parameter. Fixes bug 25226; bugfix
- on 0.2.4.14-alpha.
-
- o Minor features (cleanup):
- - Tor now deletes the CookieAuthFile and ExtORPortCookieAuthFile
- when it stops. Closes ticket 23271.
-
- o Minor features (compatibility, backport from 0.3.4.1-alpha):
- - Avoid some compilation warnings with recent versions of LibreSSL.
- Closes ticket 26006.
-
- o Minor features (config options):
- - Change the way the default value for MaxMemInQueues is calculated.
- We now use 40% of the hardware RAM if the system has 8 GB RAM or
- more. Otherwise we use the former value of 75%. Closes
- ticket 24782.
-
- o Minor features (continuous integration):
- - Update the Travis CI configuration to use the stable Rust channel,
- now that we have decided to require that. Closes ticket 25714.
-
- o Minor features (continuous integration, backport from 0.3.4.1-alpha):
- - Our .travis.yml configuration now includes support for testing the
- results of "make distcheck". (It's not uncommon for "make check"
- to pass but "make distcheck" to fail.) Closes ticket 25814.
- - Our Travis CI configuration now integrates with the Coveralls
- coverage analysis tool. Closes ticket 25818.
+Changes in version 0.3.2.10 - 2018-03-03
+ Tor 0.3.2.10 is the second stable release in the 0.3.2 series. It
+ backports a number of bugfixes, including important fixes for security
+ issues.
- o Minor features (defensive programming):
- - Most of the functions in Tor that free objects have been replaced
- with macros that free the objects and set the corresponding
- pointers to NULL. This change should help prevent a large class of
- dangling pointer bugs. Closes ticket 24337.
- - Where possible, the tor_free() macro now only evaluates its input
- once. Part of ticket 24337.
- - Check that microdesc ed25519 ids are non-zero in
- node_get_ed25519_id() before returning them. Implements ticket
- 24001, patch by "aruna1234".
+ It includes an important security fix for a remote crash attack
+ against directory authorities, tracked as TROVE-2018-001.
- o Minor features (directory authority):
- - When directory authorities are unable to add signatures to a
- pending consensus, log the reason why. Closes ticket 24849.
-
- o Minor features (embedding):
- - Tor can now start with a preauthenticated control connection
- created by the process that launched it. This feature is meant for
- use by programs that want to launch and manage a Tor process
- without allowing other programs to manage it as well. For more
- information, see the __OwningControllerFD option documented in
- control-spec.txt. Closes ticket 23900.
- - On most errors that would cause Tor to exit, it now tries to
- return from the tor_main() function, rather than calling the
- system exit() function. Most users won't notice a difference here,
- but it should be significant for programs that run Tor inside a
- separate thread: they should now be able to survive Tor's exit
- conditions rather than having Tor shut down the entire process.
- Closes ticket 23848.
- - Applications that want to embed Tor can now tell Tor not to
- register any of its own POSIX signal handlers, using the
- __DisableSignalHandlers option. Closes ticket 24588.
+ Additionally, it backports a fix for a bug whose severity we have
+ upgraded: Bug 24700, which was fixed in 0.3.3.2-alpha, can be remotely
+ triggered in order to crash relays with a use-after-free pattern. As
+ such, we are now tracking that bug as TROVE-2018-002 and
+ CVE-2018-0491, and backporting it to earlier releases. This bug
+ affected versions 0.3.2.1-alpha through 0.3.2.9, as well as version
+ 0.3.3.1-alpha.
- o Minor features (fallback directory list):
- - Avoid selecting fallbacks that change their IP addresses too
- often. Select more fallbacks by ignoring the Guard flag, and
- allowing lower cutoffs for the Running and V2Dir flags. Also allow
- a lower bandwidth, and a higher number of fallbacks per operator
- (5% of the list). Implements ticket 24785.
- - Update the fallback whitelist and blacklist based on opt-ins and
- relay changes. Closes tickets 22321, 24678, 22527, 24135,
- and 24695.
-
- o Minor features (fallback directory mirror configuration):
- - Add a nickname to each fallback in a C comment. This makes it
- easier for operators to find their relays, and allows stem to use
- nicknames to identify fallbacks. Implements ticket 24600.
- - Add a type and version header to the fallback directory mirror
- file. Also add a delimiter to the end of each fallback entry. This
- helps external parsers like stem and Relay Search. Implements
- ticket 24725.
- - Add an extrainfo cache flag for each fallback in a C comment. This
- allows stem to use fallbacks to fetch extra-info documents, rather
- than using authorities. Implements ticket 22759.
- - Add the generateFallbackDirLine.py script for automatically
- generating fallback directory mirror lines from relay fingerprints.
- No more typos! Add the lookupFallbackDirContact.py script for
- automatically looking up operator contact info from relay
- fingerprints. Implements ticket 24706, patch by teor and atagar.
- - Reject any fallback directory mirror that serves an expired
- consensus. Implements ticket 20942, patch by "minik".
- - Remove commas and equals signs from external string inputs to the
- fallback list. This avoids format confusion attacks. Implements
- ticket 24726.
- - Remove the "weight=10" line from fallback directory mirror
- entries. Ticket 24681 will maintain the current fallback weights
- by changing Tor's default fallback weight to 10. Implements
- ticket 24679.
- - Stop logging excessive information about fallback netblocks.
- Implements ticket 24791.
-
- o Minor features (forward-compatibility):
- - If a relay supports some link authentication protocol that we do
- not recognize, then include that relay's ed25519 key when telling
- other relays to extend to it. Previously, we treated future
- versions as if they were too old to support ed25519 link
- authentication. Closes ticket 20895.
+ This release also backports our new system for improved resistance to
+ denial-of-service attacks against relays.
- o Minor features (geoip):
- - Update geoip and geoip6 to the May 1 2018 Maxmind GeoLite2 Country
- database. Closes ticket 26104.
+ This release also fixes several minor bugs and annoyances from
+ earlier releases.
- o Minor features (heartbeat):
- - Add onion service information to our heartbeat logs, displaying
- stats about the activity of configured onion services. Closes
- ticket 24896.
+ Relays running 0.3.2.x SHOULD upgrade to one of the versions released
+ today, for the fix to TROVE-2018-002. Directory authorities should
+ also upgrade. (Relays on earlier versions might want to update too for
+ the DoS mitigations.)
- o Minor features (instrumentation, development):
- - Add the MainloopStats option to allow developers to get
- instrumentation information from the main event loop via the
- heartbeat messages. We hope to use this to improve Tor's behavior
- when it's trying to sleep. Closes ticket 24605.
+ o Major bugfixes (denial-of-service, directory authority, backport from 0.3.3.3-alpha):
+ - Fix a protocol-list handling bug that could be used to remotely crash
+ directory authorities with a null-pointer exception. Fixes bug 25074;
+ bugfix on 0.2.9.4-alpha. Also tracked as TROVE-2018-001 and
+ CVE-2018-0490.
- o Minor features (IPv6):
- - Make IPv6-only clients wait for microdescs for relays, even if we
- were previously using descriptors (or were using them as a bridge)
- and have a cached descriptor for them. Implements ticket 23827.
- - When a consensus has IPv6 ORPorts, make IPv6-only clients use
- them, rather than waiting to download microdescriptors. Implements
- ticket 23827.
+ o Major bugfixes (scheduler, KIST, denial-of-service, backport from 0.3.3.2-alpha):
+ - Avoid adding the same channel twice in the KIST scheduler pending
+ list, which could lead to remote denial-of-service use-after-free
+ attacks against relays. Fixes bug 24700; bugfix on 0.3.2.1-alpha.
- o Minor features (log messages):
- - Improve log message in the out-of-memory handler to include
- information about memory usage from the different compression
- backends. Closes ticket 25372.
- - Improve a warning message that happens when we fail to re-parse an
- old router because of an expired certificate. Closes ticket 20020.
- - Make the log more quantitative when we hit MaxMemInQueues
- threshold exposing some values. Closes ticket 24501.
+ o Major features (denial-of-service mitigation, backport from 0.3.3.2-alpha):
+ - Give relays some defenses against the recent network overload. We
+ start with three defenses (default parameters in parentheses).
+ First: if a single client address makes too many concurrent
+ connections (>100), hang up on further connections. Second: if a
+ single client address makes circuits too quickly (more than 3 per
+ second, with an allowed burst of 90) while also having too many
+ connections open (3), refuse new create cells for the next while
+ (1-2 hours). Third: if a client asks to establish a rendezvous
+ point to you directly, ignore the request. These defenses can be
+ manually controlled by new torrc options, but relays will also
+ take guidance from consensus parameters, so there's no need to
+ configure anything manually. Implements ticket 24902.
- o Minor features (logging):
- - Clarify the log messages produced when getrandom() or a related
- entropy-generation mechanism gives an error. Closes ticket 25120.
- - Added support for the Android logging subsystem. Closes
- ticket 24362.
+ o Major bugfixes (onion services, retry behavior, backport from 0.3.3.1-alpha):
+ - Fix an "off by 2" error in counting rendezvous failures on the
+ onion service side. While we thought we would stop the rendezvous
+ attempt after one failed circuit, we were actually making three
+ circuit attempts before giving up. Now switch to a default of 2,
+ and allow the consensus parameter "hs_service_max_rdv_failures" to
+ override. Fixes bug 24895; bugfix on 0.0.6.
+ - New-style (v3) onion services now obey the "max rendezvous circuit
+ attempts" logic. Previously they would make as many rendezvous
+ circuit attempts as they could fit in the MAX_REND_TIMEOUT second
+ window before giving up. Fixes bug 24894; bugfix on 0.3.2.1-alpha.
- o Minor features (performance):
- - Support predictive circuit building for onion service circuits
- with multiple layers of guards. Closes ticket 23101.
- - Use stdatomic.h where available, rather than mutexes, to implement
- atomic_counter_t. Closes ticket 23953.
-
- o Minor features (performance, 32-bit):
- - Improve performance on 32-bit systems by avoiding 64-bit division
- when calculating the timestamp in milliseconds for channel padding
- computations. Implements ticket 24613.
- - Improve performance on 32-bit systems by avoiding 64-bit division
- when timestamping cells and buffer chunks for OOM calculations.
- Implements ticket 24374.
-
- o Minor features (performance, OSX, iOS):
- - Use the mach_approximate_time() function (when available) to
- implement coarse monotonic time. Having a coarse time function
- should avoid a large number of system calls, and improve
- performance slightly, especially under load. Closes ticket 24427.
-
- o Minor features (performance, windows):
- - Improve performance on Windows Vista and Windows 7 by adjusting
- TCP send window size according to the recommendation from
- SIO_IDEAL_SEND_BACKLOG_QUERY. Closes ticket 22798. Patch
- from Vort.
-
- o Minor features (sandbox):
- - Explicitly permit the poll() system call when the Linux
- seccomp2-based sandbox is enabled: apparently, some versions of
- libc use poll() when calling getpwnam(). Closes ticket 25313.
-
- o Minor features (storage, configuration):
- - Users can store cached directory documents somewhere other than
- the DataDirectory by using the CacheDirectory option. Similarly,
- the storage location for relay's keys can be overridden with the
- KeyDirectory option. Closes ticket 22703.
+ o Major bugfixes (protocol versions, backport from 0.3.3.2-alpha):
+ - Add Link protocol version 5 to the supported protocols list. Fixes
+ bug 25070; bugfix on 0.3.1.1-alpha.
- o Minor features (testing):
- - Add a "make test-rust" target to run the rust tests only. Closes
- ticket 25071.
-
- o Minor features (testing, debugging, embedding):
- - For development purposes, Tor now has a mode in which it runs for
- a few seconds, then stops, and starts again without exiting the
- process. This mode is meant to help us debug various issues with
- ticket 23847. To use this feature, compile with
- --enable-restart-debugging, and set the TOR_DEBUG_RESTART
- environment variable. This is expected to crash a lot, and is
- really meant for developers only. It will likely be removed in a
- future release. Implements ticket 24583.
-
- o Minor bugfixes (build, rust):
- - Fix output of autoconf checks to display success messages for Rust
- dependencies and a suitable rustc compiler version. Fixes bug
- 24612; bugfix on 0.3.1.3-alpha.
- - Don't pass the --quiet option to cargo: it seems to suppress some
- errors, which is not what we want to do when building. Fixes bug
- 24518; bugfix on 0.3.1.7.
- - Build correctly when building from outside Tor's source tree with
- the TOR_RUST_DEPENDENCIES option set. Fixes bug 22768; bugfix
- on 0.3.1.7.
+ o Major bugfixes (relay, backport from 0.3.3.1-alpha):
+ - Fix a set of false positives where relays would consider
+ connections to other relays as being client-only connections (and
+ thus e.g. deserving different link padding schemes) if those
+ relays fell out of the consensus briefly. Now we look only at the
+ initial handshake and whether the connection authenticated as a
+ relay. Fixes bug 24898; bugfix on 0.3.1.1-alpha.
- o Minor bugfixes (C correctness):
- - Fix a very unlikely (impossible, we believe) null pointer
- dereference. Fixes bug 25629; bugfix on 0.2.9.15. Found by
- Coverity; this is CID 1430932.
+ o Major bugfixes (scheduler, consensus, backport from 0.3.3.2-alpha):
+ - The scheduler subsystem was failing to promptly notice changes in
+ consensus parameters, making it harder to switch schedulers
+ network-wide. Fixes bug 24975; bugfix on 0.3.2.1-alpha.
- o Minor bugfixes (channel, client):
- - Better identify client connection when reporting to the geoip
- client cache. Fixes bug 24904; bugfix on 0.3.1.7.
+ o Minor features (denial-of-service avoidance, backport from 0.3.3.2-alpha):
+ - Make our OOM handler aware of the geoip client history cache so it
+ doesn't fill up the memory. This check is important for IPv6 and
+ our DoS mitigation subsystem. Closes ticket 25122.
- o Minor bugfixes (circuit, cannibalization):
- - Don't cannibalize preemptively-built circuits if we no longer
- recognize their first hop. This situation can happen if our Guard
- relay went off the consensus after the circuit was created. Fixes
- bug 24469; bugfix on 0.0.6.
+ o Minor features (compatibility, OpenSSL, backport from 0.3.3.3-alpha):
+ - Tor will now support TLS1.3 once OpenSSL 1.1.1 is released.
+ Previous versions of Tor would not have worked with OpenSSL 1.1.1,
+ since they neither disabled TLS 1.3 nor enabled any of the
+ ciphersuites it requires. Now we enable the TLS 1.3 ciphersuites.
+ Closes ticket 24978.
- o Minor bugfixes (client, backport from 0.3.4.1-alpha):
- - Don't consider Tor running as a client if the ControlPort is open,
- but no actual client ports are open. Fixes bug 26062; bugfix
- on 0.2.9.4-alpha.
+ o Minor features (geoip):
+ - Update geoip and geoip6 to the February 7 2018 Maxmind GeoLite2
+ Country database.
- o Minor bugfixes (compilation):
- - Fix a C99 compliance issue in our configuration script that caused
- compilation issues when compiling Tor with certain versions of
- xtools. Fixes bug 25474; bugfix on 0.3.2.5-alpha.
+ o Minor features (logging, diagnostic, backport from 0.3.3.2-alpha):
+ - When logging a failure to check a hidden service's certificate,
+ also log what the problem with the certificate was. Diagnostic
+ for ticket 24972.
- o Minor bugfixes (controller):
- - Restore the correct operation of the RESOLVE command, which had
- been broken since we added the ability to enable/disable DNS on
- specific listener ports. Fixes bug 25617; bugfix on 0.2.9.3-alpha.
- - Avoid a (nonfatal) assertion failure when extending a one-hop
- circuit from the controller to become a multihop circuit. Fixes
- bug 24903; bugfix on 0.2.5.2-alpha.
+ o Minor bugfix (channel connection, backport from 0.3.3.2-alpha):
+ - Use the actual observed address of an incoming relay connection,
+ not the canonical address of the relay from its descriptor, when
+ making decisions about how to handle the incoming connection.
+ Fixes bug 24952; bugfix on 0.2.4.11-alpha. Patch by "ffmancera".
- o Minor bugfixes (correctness):
- - Remove a nonworking, unnecessary check to see whether a circuit
- hop's identity digest was set when the circuit failed. Fixes bug
- 24927; bugfix on 0.2.4.4-alpha.
-
- o Minor bugfixes (correctness, client, backport from 0.3.4.1-alpha):
- - Upon receiving a malformed connected cell, stop processing the
- cell immediately. Previously we would mark the connection for
- close, but continue processing the cell as if the connection were
- open. Fixes bug 26072; bugfix on 0.2.4.7-alpha.
-
- o Minor bugfixes (directory authorities, IPv6):
- - When creating a routerstatus (vote) from a routerinfo (descriptor),
- set the IPv6 address to the unspecified IPv6 address, and
- explicitly initialize the port to zero. Fixes bug 24488; bugfix
- on 0.2.4.1-alpha.
+ o Minor bugfixes (denial-of-service, backport from 0.3.3.3-alpha):
+ - Fix a possible crash on malformed consensus. If a consensus had
+ contained an unparseable protocol line, it could have made clients
+ and relays crash with a null-pointer exception. To exploit this
+ issue, however, an attacker would need to be able to subvert the
+ directory authority system. Fixes bug 25251; bugfix on
+ 0.2.9.4-alpha. Also tracked as TROVE-2018-004.
- o Minor bugfixes (documentation):
- - Document that the PerConnBW{Rate,Burst} options will fall back to
- their corresponding consensus parameters only if those parameters
- are set. Previously we had claimed that these values would always
- be set in the consensus. Fixes bug 25296; bugfix on 0.2.2.7-alpha.
-
- o Minor bugfixes (documentation, backport from 0.3.4.1-alpha):
- - Stop saying in the manual that clients cache ipv4 dns answers from
- exit relays. We haven't used them since 0.2.6.3-alpha, and in
- ticket 24050 we stopped even caching them as of 0.3.2.6-alpha, but
- we forgot to say so in the man page. Fixes bug 26052; bugfix
- on 0.3.2.6-alpha.
-
- o Minor bugfixes (exit relay DNS retries):
- - Re-attempt timed-out DNS queries 3 times before failure, since our
- timeout is 5 seconds for them, but clients wait 10-15. Also allow
- slightly more timeouts per resolver when an exit has multiple
- resolvers configured. Fixes bug 21394; bugfix on 0.3.1.9.
-
- o Minor bugfixes (fallback directory mirrors):
- - Make updateFallbackDirs.py search harder for python. (Some OSs
- don't put it in /usr/bin.) Fixes bug 24708; bugfix
- on 0.2.8.1-alpha.
+ o Minor bugfix (directory authority, backport from 0.3.3.2-alpha):
+ - Directory authorities, when refusing a descriptor from a rejected
+ relay, now explicitly tell the relay (in its logs) to set a valid
+ ContactInfo address and contact the bad-relays@ mailing list.
+ Fixes bug 25170; bugfix on 0.2.9.1.
- o Minor bugfixes (hibernation, bandwidth accounting, shutdown):
- - When hibernating, close connections normally and allow them to
- flush. Fixes bug 23571; bugfix on 0.2.4.7-alpha. Also fixes
- bug 7267.
- - Do not attempt to launch self-reachability tests when entering
- hibernation. Fixes a case of bug 12062; bugfix on 0.0.9pre5.
- - Resolve several bugs related to descriptor fetching on bridge
- clients with bandwidth accounting enabled. (This combination is
- not recommended!) Fixes a case of bug 12062; bugfix
- on 0.2.0.3-alpha.
- - When hibernating, do not attempt to launch DNS checks. Fixes a
- case of bug 12062; bugfix on 0.1.2.2-alpha.
- - When hibernating, do not try to upload or download descriptors.
- Fixes a case of bug 12062; bugfix on 0.0.9pre5.
-
- o Minor bugfixes (IPv6, bridges):
- - Tor now always sets IPv6 preferences for bridges. Fixes bug 24573;
- bugfix on 0.2.8.2-alpha.
- - Tor now sets IPv6 address in the routerstatus as well as in the
- router descriptors when updating addresses for a bridge. Closes
- ticket 24572; bugfix on 0.2.4.5-alpha. Patch by "ffmancera".
+ o Minor bugfixes (build, rust, backport from 0.3.3.1-alpha):
+ - When building with Rust on OSX, link against libresolv, to work
+ around the issue at https://github.com/rust-lang/rust/issues/46797.
+ Fixes bug 24652; bugfix on 0.3.1.1-alpha.
- o Minor bugfixes (Linux seccomp2 sandbox):
- - When running with the sandbox enabled, reload configuration files
- correctly even when %include was used. Previously we would crash.
- Fixes bug 22605; bugfix on 0.3.1. Patch from Daniel Pinto.
+ o Minor bugfixes (onion services, backport from 0.3.3.2-alpha):
+ - Remove a BUG() statement when a client fetches an onion descriptor
+ that has a lower revision counter than the one in its cache. This
+ can happen in normal circumstances due to HSDir desync. Fixes bug
+ 24976; bugfix on 0.3.2.1-alpha.
- o Minor bugfixes (Linux seccomp2 sandbox, backport from 0.3.4.1-alpha):
- - Allow the nanosleep() system call, which glibc uses to implement
- sleep() and usleep(). Fixes bug 24969; bugfix on 0.2.5.1-alpha.
+ o Minor bugfixes (logging, backport from 0.3.3.2-alpha):
+ - Don't treat inability to store a cached consensus object as a bug:
+ it can happen normally when we are out of disk space. Fixes bug
+ 24859; bugfix on 0.3.1.1-alpha.
- o Minor bugfixes (logging):
- - Fix a (mostly harmless) race condition when invoking
- LOG_PROTOCOL_WARN message from a subthread while the torrc options
- are changing. Fixes bug 23954; bugfix on 0.1.1.9-alpha.
+ o Minor bugfixes (performance, fragile-hardening, backport from 0.3.3.1-alpha):
+ - Improve the performance of our consensus-diff application code
+ when Tor is built with the --enable-fragile-hardening option set.
+ Fixes bug 24826; bugfix on 0.3.1.1-alpha.
- o Minor bugfixes (man page, SocksPort):
- - Remove dead code from the old "SocksSocket" option, and rename
- SocksSocketsGroupWritable to UnixSocksGroupWritable. The old
- option still works, but is deprecated. Fixes bug 24343; bugfix
- on 0.2.6.3.
+ o Minor bugfixes (OSX, backport from 0.3.3.1-alpha):
+ - Don't exit the Tor process if setrlimit() fails to change the file
+ limit (which can happen sometimes on some versions of OSX). Fixes
+ bug 21074; bugfix on 0.0.9pre5.
- o Minor bugfixes (memory leaks):
- - Avoid possible at-exit memory leaks related to use of Libevent's
- event_base_once() function. (This function tends to leak memory if
- the event_base is closed before the event fires.) Fixes bug 24584;
- bugfix on 0.2.8.1-alpha.
- - Fix a harmless memory leak in tor-resolve. Fixes bug 24582; bugfix
- on 0.2.1.1-alpha.
+ o Minor bugfixes (spec conformance, backport from 0.3.3.3-alpha):
+ - Forbid "-0" as a protocol version. Fixes part of bug 25249; bugfix on
+ 0.2.9.4-alpha.
+ - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
+ bugfix on 0.2.9.4-alpha.
- o Minor bugfixes (network IPv6 test):
- - Tor's test scripts now check if "ping -6 ::1" works when the user
- runs "make test-network-all". Fixes bug 24677; bugfix on
- 0.2.9.3-alpha. Patch by "ffmancera".
+ o Minor bugfixes (testing, backport from 0.3.3.1-alpha):
+ - Fix a memory leak in the scheduler/loop_kist unit test. Fixes bug
+ 25005; bugfix on 0.3.2.7-rc.
- o Minor bugfixes (networking):
- - string_is_valid_hostname() will not consider IP strings to be
- valid hostnames. Fixes bug 25055; bugfix on Tor 0.2.5.5.
-
- o Minor bugfixes (onion service v3):
- - Avoid an assertion failure when the next onion service descriptor
- rotation type is out of sync with the consensus's valid-after
- time. Instead, log a warning message with extra information, so we
- can better hunt down the cause of this assertion. Fixes bug 25306;
+ o Minor bugfixes (v3 onion services, backport from 0.3.3.2-alpha):
+ - Look at the "HSRend" protocol version, not the "HSDir" protocol
+ version, when deciding whether a consensus entry can support the
+ v3 onion service protocol as a rendezvous point. Fixes bug 25105;
bugfix on 0.3.2.1-alpha.
- o Minor bugfixes (onion service, backport from 0.3.4.1-alpha):
- - Fix a memory leak when a v3 onion service is configured and gets a
- SIGHUP signal. Fixes bug 25901; bugfix on 0.3.2.1-alpha.
- - When parsing the descriptor signature, look for the token plus an
- extra white-space at the end. This is more correct but also will
- allow us to support new fields that might start with "signature".
- Fixes bug 26069; bugfix on 0.3.0.1-alpha.
-
- o Minor bugfixes (onion services):
- - If we are configured to offer a single onion service, don't log
- long-term established one hop rendezvous points in the heartbeat.
- Fixes bug 25116; bugfix on 0.2.9.6-rc.
-
- o Minor bugfixes (performance):
- - Reduce the number of circuits that will be opened at once during
- the circuit build timeout phase. This is done by increasing the
- idle timeout to 3 minutes, and lowering the maximum number of
- concurrent learning circuits to 10. Fixes bug 24769; bugfix
- on 0.3.1.1-alpha.
- - Avoid calling protocol_list_supports_protocol() from inside tight
- loops when running with cached routerinfo_t objects. Instead,
- summarize the relevant protocols as flags in the routerinfo_t, as
- we do for routerstatus_t objects. This change simplifies our code
- a little, and saves a large amount of short-term memory allocation
- operations. Fixes bug 25008; bugfix on 0.2.9.4-alpha.
-
- o Minor bugfixes (performance, timeouts):
- - Consider circuits for timeout as soon as they complete a hop. This
- is more accurate than applying the timeout in
- circuit_expire_building() because that function is only called
- once per second, which is now too slow for typical timeouts on the
- current network. Fixes bug 23114; bugfix on 0.2.2.2-alpha.
- - Use onion service circuits (and other circuits longer than 3 hops)
- to calculate a circuit build timeout. Previously, Tor only
- calculated its build timeout based on circuits that planned to be
- exactly 3 hops long. With this change, we include measurements
- from all circuits at the point where they complete their third
- hop. Fixes bug 23100; bugfix on 0.2.2.2-alpha.
-
- o Minor bugfixes (relay, crash, backport from 0.3.4.1-alpha):
- - Avoid a crash when running with DirPort set but ORPort tuned off.
- Fixes a case of bug 23693; bugfix on 0.3.1.1-alpha.
-
- o Minor bugfixes (Rust FFI):
- - Fix a minor memory leak which would happen whenever the C code
- would call the Rust implementation of
- protover_get_supported_protocols(). This was due to the C version
- returning a static string, whereas the Rust version newly allocated
- a CString to pass across the FFI boundary. Consequently, the C
- code was not expecting to need to free() what it was given. Fixes
- bug 25127; bugfix on 0.3.2.1-alpha.
-
- o Minor bugfixes (spelling):
- - Use the "misspell" tool to detect and fix typos throughout the
- source code. Fixes bug 23650; bugfix on various versions of Tor.
- Patch from Deepesh Pathak.
-
- o Minor bugfixes (testing):
- - Avoid intermittent test failures due to a test that had relied on
- onion service introduction point creation finishing within 5
- seconds of real clock time. Fixes bug 25450; bugfix
- on 0.3.1.3-alpha.
- - Give out Exit flags in bootstrapping networks. Fixes bug 24137;
- bugfix on 0.2.3.1-alpha.
-
- o Minor bugfixes (unit test, monotonic time):
- - Increase a constant (1msec to 10msec) in the monotonic time test
- that makes sure the nsec/usec/msec times read are synchronized.
- This change was needed to accommodate slow systems like armel or
- when the clock_gettime() is not a VDSO on the running kernel.
- Fixes bug 25113; bugfix on 0.2.9.1.
-
- o Code simplification and refactoring:
- - Move the list of default directory authorities to its own file.
- Closes ticket 24854. Patch by "beastr0".
- - Remove the old (deterministic) directory retry logic entirely:
- We've used exponential backoff exclusively for some time. Closes
- ticket 23814.
- - Remove the unused nodelist_recompute_all_hsdir_indices(). Closes
- ticket 25108.
- - Remove a series of counters used to track circuit extend attempts
- and connection status but that in reality we aren't using for
- anything other than stats logged by a SIGUSR1 signal. Closes
- ticket 25163.
- - Remove /usr/athena from search path in configure.ac. Closes
- ticket 24363.
- - Remove duplicate code in node_has_curve25519_onion_key() and
- node_get_curve25519_onion_key(), and add a check for a zero
- microdesc curve25519 onion key. Closes ticket 23966, patch by
- "aruna1234" and teor.
- - Rewrite channel_rsa_id_group_set_badness to reduce temporary
- memory allocations with large numbers of OR connections (e.g.
- relays). Closes ticket 24119.
- - Separate the function that deletes ephemeral files when Tor
- stops gracefully.
- - Small changes to Tor's buf_t API to make it suitable for use as a
- general-purpose safe string constructor. Closes ticket 22342.
- - Switch -Wnormalized=id to -Wnormalized=nfkc in configure.ac to
- avoid source code identifier confusion. Closes ticket 24467.
- - The tor_git_revision[] constant no longer needs to be redeclared
- by everything that links against the rest of Tor. Done as part of
- ticket 23845, to simplify our external API.
- - We make extend_info_from_node() use node_get_curve25519_onion_key()
- introduced in ticket 23577 to access the curve25519 public keys
- rather than accessing it directly. Closes ticket 23760. Patch by
- Neel Chauhan.
- - Add a function to log channels' scheduler state changes to aid
- debugging efforts. Closes ticket 24531.
-
- o Documentation:
- - Improved the documentation of AccountingStart parameter. Closes
- ticket 23635.
- - Update the documentation for "Log" to include the current list of
- logging domains. Closes ticket 25378.
- - Add documentation on how to build tor with Rust dependencies
- without having to be online. Closes ticket 22907; bugfix
- on 0.3.0.3-alpha.
- - Clarify the behavior of RelayBandwidth{Rate,Burst} with client
- traffic. Closes ticket 24318.
- - Document that OutboundBindAddress doesn't apply to DNS requests.
- Closes ticket 22145. Patch from Aruna Maurya.
-
- o Code simplification and refactoring (channels):
- - Remove the incoming and outgoing channel queues. These were never
- used, but still took up a step in our fast path.
- - The majority of the channel unit tests have been rewritten and the
- code coverage has now been raised to 83.6% for channel.c. Closes
- ticket 23709.
- - Remove other dead code from the channel subsystem: All together,
- this cleanup has removed more than 1500 lines of code overall and
- adding very little except for unit test.
-
- o Code simplification and refactoring (circuit rendezvous):
- - Split the client-side rendezvous circuit lookup into two
- functions: one that returns only established circuits and another
- that returns all kinds of circuits. Closes ticket 23459.
-
- o Code simplification and refactoring (controller):
- - Make most of the variables in networkstatus_getinfo_by_purpose()
- const. Implements ticket 24489.
-
- o Documentation (backport from 0.3.4.1-alpha):
- - Correct an IPv6 error in the documentation for ExitPolicy. Closes
- ticket 25857. Patch from "CTassisF".
-
- o Documentation (man page):
- - The HiddenServiceVersion torrc option accepts only one number:
- either version 2 or 3. Closes ticket 25026; bugfix
- on 0.3.2.2-alpha.
+ o Code simplification and refactoring (backport from 0.3.3.3-alpha):
+ - Update the "rust dependencies" submodule to be a project-level
+ repository, rather than a user repository. Closes ticket 25323.
- o Documentation (manpage, denial of service):
- - Provide more detail about the denial-of-service options, by
- listing each mitigation and explaining how they relate. Closes
- ticket 25248.
+ o Documentation (backport from 0.3.3.1-alpha)
+ - Document that operators who run more than one relay or bridge are
+ expected to set MyFamily and ContactInfo correctly. Closes
+ ticket 24526.
Changes in version 0.3.1.10 - 2018-03-03
@@ -692,11 +190,11 @@ Changes in version 0.3.1.10 - 2018-03-03
earlier releases.
All directory authorities should upgrade to one of the versions
- released today. Relays running 0.3.1.x may wish to update to one of
+ released today. Relays running 0.3.1.x may wish to update to one of
the versions released today, for the DoS mitigations.
Please note: according to our release calendar, Tor 0.3.1 will no
- longer be supported after 1 July 2018. If you will be running Tor
+ longer be supported after 1 July 2018. If you will be running Tor
after that date, you should make sure to plan to upgrade to the latest
stable version, or downgrade to 0.2.9 (which will receive long-term
support).
@@ -900,14 +398,13 @@ Changes in version 0.3.1.10 - 2018-03-03
o Minor bugfixes (spec conformance, backport from 0.3.3.3-alpha):
- Forbid "-0" as a protocol version. Fixes part of bug 25249; bugfix on
0.2.9.4-alpha.
- - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
+ - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
bugfix on 0.2.9.4-alpha.
o Code simplification and refactoring (backport from 0.3.3.3-alpha):
- Update the "rust dependencies" submodule to be a project-level
repository, rather than a user repository. Closes ticket 25323.
-
Changes in version 0.2.9.15 - 2018-03-03
Tor 0.2.9.15 backports important security and stability bugfixes from
later Tor releases.
@@ -922,7 +419,7 @@ Changes in version 0.2.9.15 - 2018-03-03
earlier releases.
All directory authorities should upgrade to one of the versions
- released today. Relays running 0.2.9.x may wish to update to one of
+ released today. Relays running 0.2.9.x may wish to update to one of
the versions released today, for the DoS mitigations.
o Major bugfixes (denial-of-service, directory authority, backport from 0.3.3.3-alpha):
@@ -1081,183 +578,9 @@ Changes in version 0.2.9.15 - 2018-03-03
o Minor bugfixes (spec conformance, backport from 0.3.3.3-alpha):
- Forbid "-0" as a protocol version. Fixes part of bug 25249; bugfix on
0.2.9.4-alpha.
- - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
- bugfix on 0.2.9.4-alpha.
-
-
-Changes in version 0.3.2.10 - 2018-03-03
- Tor 0.3.2.10 is the second stable release in the 0.3.2 series. It
- backports a number of bugfixes, including important fixes for security
- issues.
-
- It includes an important security fix for a remote crash attack
- against directory authorities, tracked as TROVE-2018-001.
-
- Additionally, it backports a fix for a bug whose severity we have
- upgraded: Bug 24700, which was fixed in 0.3.3.2-alpha, can be remotely
- triggered in order to crash relays with a use-after-free pattern. As
- such, we are now tracking that bug as TROVE-2018-002 and
- CVE-2018-0491, and backporting it to earlier releases. This bug
- affected versions 0.3.2.1-alpha through 0.3.2.9, as well as version
- 0.3.3.1-alpha.
-
- This release also backports our new system for improved resistance to
- denial-of-service attacks against relays.
-
- This release also fixes several minor bugs and annoyances from
- earlier releases.
-
- Relays running 0.3.2.x SHOULD upgrade to one of the versions released
- today, for the fix to TROVE-2018-002. Directory authorities should
- also upgrade. (Relays on earlier versions might want to update too for
- the DoS mitigations.)
-
- o Major bugfixes (denial-of-service, directory authority, backport from 0.3.3.3-alpha):
- - Fix a protocol-list handling bug that could be used to remotely crash
- directory authorities with a null-pointer exception. Fixes bug 25074;
- bugfix on 0.2.9.4-alpha. Also tracked as TROVE-2018-001 and
- CVE-2018-0490.
-
- o Major bugfixes (scheduler, KIST, denial-of-service, backport from 0.3.3.2-alpha):
- - Avoid adding the same channel twice in the KIST scheduler pending
- list, which could lead to remote denial-of-service use-after-free
- attacks against relays. Fixes bug 24700; bugfix on 0.3.2.1-alpha.
-
- o Major features (denial-of-service mitigation, backport from 0.3.3.2-alpha):
- - Give relays some defenses against the recent network overload. We
- start with three defenses (default parameters in parentheses).
- First: if a single client address makes too many concurrent
- connections (>100), hang up on further connections. Second: if a
- single client address makes circuits too quickly (more than 3 per
- second, with an allowed burst of 90) while also having too many
- connections open (3), refuse new create cells for the next while
- (1-2 hours). Third: if a client asks to establish a rendezvous
- point to you directly, ignore the request. These defenses can be
- manually controlled by new torrc options, but relays will also
- take guidance from consensus parameters, so there's no need to
- configure anything manually. Implements ticket 24902.
-
- o Major bugfixes (onion services, retry behavior, backport from 0.3.3.1-alpha):
- - Fix an "off by 2" error in counting rendezvous failures on the
- onion service side. While we thought we would stop the rendezvous
- attempt after one failed circuit, we were actually making three
- circuit attempts before giving up. Now switch to a default of 2,
- and allow the consensus parameter "hs_service_max_rdv_failures" to
- override. Fixes bug 24895; bugfix on 0.0.6.
- - New-style (v3) onion services now obey the "max rendezvous circuit
- attempts" logic. Previously they would make as many rendezvous
- circuit attempts as they could fit in the MAX_REND_TIMEOUT second
- window before giving up. Fixes bug 24894; bugfix on 0.3.2.1-alpha.
-
- o Major bugfixes (protocol versions, backport from 0.3.3.2-alpha):
- - Add Link protocol version 5 to the supported protocols list. Fixes
- bug 25070; bugfix on 0.3.1.1-alpha.
-
- o Major bugfixes (relay, backport from 0.3.3.1-alpha):
- - Fix a set of false positives where relays would consider
- connections to other relays as being client-only connections (and
- thus e.g. deserving different link padding schemes) if those
- relays fell out of the consensus briefly. Now we look only at the
- initial handshake and whether the connection authenticated as a
- relay. Fixes bug 24898; bugfix on 0.3.1.1-alpha.
-
- o Major bugfixes (scheduler, consensus, backport from 0.3.3.2-alpha):
- - The scheduler subsystem was failing to promptly notice changes in
- consensus parameters, making it harder to switch schedulers
- network-wide. Fixes bug 24975; bugfix on 0.3.2.1-alpha.
-
- o Minor features (denial-of-service avoidance, backport from 0.3.3.2-alpha):
- - Make our OOM handler aware of the geoip client history cache so it
- doesn't fill up the memory. This check is important for IPv6 and
- our DoS mitigation subsystem. Closes ticket 25122.
-
- o Minor features (compatibility, OpenSSL, backport from 0.3.3.3-alpha):
- - Tor will now support TLS1.3 once OpenSSL 1.1.1 is released.
- Previous versions of Tor would not have worked with OpenSSL 1.1.1,
- since they neither disabled TLS 1.3 nor enabled any of the
- ciphersuites it requires. Now we enable the TLS 1.3 ciphersuites.
- Closes ticket 24978.
-
- o Minor features (geoip):
- - Update geoip and geoip6 to the February 7 2018 Maxmind GeoLite2
- Country database.
-
- o Minor features (logging, diagnostic, backport from 0.3.3.2-alpha):
- - When logging a failure to create an onion service's descriptor,
- also log what the problem with the descriptor was. Diagnostic
- for ticket 24972.
-
- o Minor bugfix (channel connection, backport from 0.3.3.2-alpha):
- - Use the actual observed address of an incoming relay connection,
- not the canonical address of the relay from its descriptor, when
- making decisions about how to handle the incoming connection.
- Fixes bug 24952; bugfix on 0.2.4.11-alpha. Patch by "ffmancera".
-
- o Minor bugfixes (denial-of-service, backport from 0.3.3.3-alpha):
- - Fix a possible crash on malformed consensus. If a consensus had
- contained an unparseable protocol line, it could have made clients
- and relays crash with a null-pointer exception. To exploit this
- issue, however, an attacker would need to be able to subvert the
- directory authority system. Fixes bug 25251; bugfix on
- 0.2.9.4-alpha. Also tracked as TROVE-2018-004.
-
- o Minor bugfix (directory authority, backport from 0.3.3.2-alpha):
- - Directory authorities, when refusing a descriptor from a rejected
- relay, now explicitly tell the relay (in its logs) to set a valid
- ContactInfo address and contact the bad-relays@ mailing list.
- Fixes bug 25170; bugfix on 0.2.9.1.
-
- o Minor bugfixes (build, rust, backport from 0.3.3.1-alpha):
- - When building with Rust on OSX, link against libresolv, to work
- around the issue at https://github.com/rust-lang/rust/issues/46797.
- Fixes bug 24652; bugfix on 0.3.1.1-alpha.
-
- o Minor bugfixes (onion services, backport from 0.3.3.2-alpha):
- - Remove a BUG() statement when a client fetches an onion descriptor
- that has a lower revision counter than the one in its cache. This
- can happen in normal circumstances due to HSDir desync. Fixes bug
- 24976; bugfix on 0.3.2.1-alpha.
-
- o Minor bugfixes (logging, backport from 0.3.3.2-alpha):
- - Don't treat inability to store a cached consensus object as a bug:
- it can happen normally when we are out of disk space. Fixes bug
- 24859; bugfix on 0.3.1.1-alpha.
-
- o Minor bugfixes (performance, fragile-hardening, backport from 0.3.3.1-alpha):
- - Improve the performance of our consensus-diff application code
- when Tor is built with the --enable-fragile-hardening option set.
- Fixes bug 24826; bugfix on 0.3.1.1-alpha.
-
- o Minor bugfixes (OSX, backport from 0.3.3.1-alpha):
- - Don't exit the Tor process if setrlimit() fails to change the file
- limit (which can happen sometimes on some versions of OSX). Fixes
- bug 21074; bugfix on 0.0.9pre5.
-
- o Minor bugfixes (spec conformance, backport from 0.3.3.3-alpha):
- - Forbid "-0" as a protocol version. Fixes part of bug 25249; bugfix on
- 0.2.9.4-alpha.
- - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
+ - Forbid UINT32_MAX as a protocol version. Fixes part of bug 25249;
bugfix on 0.2.9.4-alpha.
- o Minor bugfixes (testing, backport from 0.3.3.1-alpha):
- - Fix a memory leak in the scheduler/loop_kist unit test. Fixes bug
- 25005; bugfix on 0.3.2.7-rc.
-
- o Minor bugfixes (v3 onion services, backport from 0.3.3.2-alpha):
- - Look at the "HSRend" protocol version, not the "HSDir" protocol
- version, when deciding whether a consensus entry can support the
- v3 onion service protocol as a rendezvous point. Fixes bug 25105;
- bugfix on 0.3.2.1-alpha.
-
- o Code simplification and refactoring (backport from 0.3.3.3-alpha):
- - Update the "rust dependencies" submodule to be a project-level
- repository, rather than a user repository. Closes ticket 25323.
-
- o Documentation (backport from 0.3.3.1-alpha)
- - Document that operators who run more than one relay or bridge are
- expected to set MyFamily and ContactInfo correctly. Closes
- ticket 24526.
-
Changes in version 0.3.2.9 - 2018-01-09
Tor 0.3.2.9 is the first stable release in the 0.3.2 series.
diff --git a/acinclude.m4 b/acinclude.m4
index c9cfc3f014..49d4f14471 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -2,7 +2,7 @@ dnl Helper macros for Tor configure.ac
dnl Copyright (c) 2001-2004, Roger Dingledine
dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
dnl Copyright (c) 2007-2008, Roger Dingledine, Nick Mathewson
-dnl Copyright (c) 2007-2018, The Tor Project, Inc.
+dnl Copyright (c) 2007-2017, The Tor Project, Inc.
dnl See LICENSE for licensing information
AC_DEFUN([TOR_EXTEND_CODEPATH],
diff --git a/changes/18105 b/changes/18105
new file mode 100644
index 0000000000..87e6e61d2f
--- /dev/null
+++ b/changes/18105
@@ -0,0 +1,4 @@
+ o Code simplification and refactoring:
+ - Introduce a function to call getsockname() and return
+ tor_addr_t, to save a little complexity throughout the codebase.
+ Closes ticket 18105.
diff --git a/changes/24378 b/changes/24378
new file mode 100644
index 0000000000..663d27e969
--- /dev/null
+++ b/changes/24378
@@ -0,0 +1,8 @@
+ o Removed features:
+
+ - Directory authorities will no longer support voting according to any
+ consensus method before consensus method 25. This keeps authorities
+ compatible with all authorities running 0.2.9.8 and later, and does
+ not break any clients or relays. Implements ticket 24378 and
+ proposal 290.
+
diff --git a/changes/25857 b/changes/25857
new file mode 100644
index 0000000000..e457af2f82
--- /dev/null
+++ b/changes/25857
@@ -0,0 +1,3 @@
+ o Documentation:
+ - Correct an IPv6 error in the documentation for ExitPolicy.
+ Closes ticket 25857. Patch from "CTassisF".
diff --git a/changes/bug18918 b/changes/bug18918
new file mode 100644
index 0000000000..c939168f49
--- /dev/null
+++ b/changes/bug18918
@@ -0,0 +1,6 @@
+ o Code simplification and refactoring:
+ - In order to make the OR and dir checking function in router.c less
+ confusing we renamed some functions and consider_testing_reachability()
+ has been splitted into router_should_check_reachability() and
+ router_do_reachability_checks(). Also we improved the documentation in
+ some functions. Closes ticket 18918.
diff --git a/changes/bug20887 b/changes/bug20887
new file mode 100644
index 0000000000..5d4e4ed233
--- /dev/null
+++ b/changes/bug20887
@@ -0,0 +1,4 @@
+ o Minor bugfixes (freebsd):
+ - In have_enough_mem_for_dircache(), the variable DIRCACHE_MIN_MEM_MB
+ does not stringify on FreeBSD, so we switch to tor_asprintf(). Fixes
+ bug 20887; bugfix on 0.2.8.1-alpha. Patch by Neel Chauhan.
diff --git a/changes/bug22156 b/changes/bug22156
deleted file mode 100644
index 685f2a551b..0000000000
--- a/changes/bug22156
+++ /dev/null
@@ -1,3 +0,0 @@
- o Minor features (development):
- - Tor's makefile now supports running the "clippy" Rust style tool
- on our Rust code. Closes ticket 22156.
diff --git a/changes/bug23094 b/changes/bug23094
new file mode 100644
index 0000000000..5040ab4e71
--- /dev/null
+++ b/changes/bug23094
@@ -0,0 +1,4 @@
+ o Code simplification and refactoring:
+ - Make hsdir_index in node_t a hsdir_index_t rather than a pointer
+ as hsdir_index is always present. Also, we move hsdir_index_t into
+ or.h. Closes ticket 23094. Patch by Neel Chauhan.
diff --git a/changes/bug23107 b/changes/bug23107
new file mode 100644
index 0000000000..55885e10fd
--- /dev/null
+++ b/changes/bug23107
@@ -0,0 +1,6 @@
+ o Code simplification and refactoring:
+ - Put a SHA1 public key digest in hs_service_intro_point_t, and use it in
+ register_intro_circ() and service_intro_point_new(). This prevents the
+ digest from being re-calculated each time. Closes ticket 23107. Patch by
+ Neel Chauhan.
+
diff --git a/changes/bug23693.1 b/changes/bug23693.1
new file mode 100644
index 0000000000..4b16788814
--- /dev/null
+++ b/changes/bug23693.1
@@ -0,0 +1,4 @@
+ o Minor bugfixes (relay, crash):
+ - Avoid a crash when running with DirPort set but ORPort tuned off.
+ Fixes a case of bug 23693; bugfix on 0.3.1.1-alpha.
+
diff --git a/changes/bug23909 b/changes/bug23909
new file mode 100644
index 0000000000..6b84e711e7
--- /dev/null
+++ b/changes/bug23909
@@ -0,0 +1,4 @@
+ o Minor features (directory authority):
+ - Directory authorities now open their key-pinning files as O_SYNC,
+ to prevent themselves from accidentally writing partial lines.
+ Closes ticket 23909.
diff --git a/changes/bug24031 b/changes/bug24031
new file mode 100644
index 0000000000..2bb0e83091
--- /dev/null
+++ b/changes/bug24031
@@ -0,0 +1,13 @@
+ o Major bugfixes (protover, voting):
+ - Revise Rust implementation of protover to use a more memory-efficient
+ voting algorithm and corresponding data structures, thus avoiding a
+ potential (but small impact) DoS attack where specially crafted protocol
+ strings would expand to several potential megabytes in memory. In the
+ process, several portions of code were revised to be methods on new,
+ custom types, rather than functions taking interchangeable types, thus
+ increasing type safety of the module. Custom error types and handling
+ were added as well, in order to facilitate better error dismissal/handling
+ in outside crates and avoid mistakenly passing an internal error string to
+ C over the FFI boundary. Many tests were added, and some previous
+ differences between the C and Rust implementations have been
+ remedied. Fixes bug 24031; bugfix on 0.3.3.1-alpha.
diff --git a/changes/bug24484 b/changes/bug24484
new file mode 100644
index 0000000000..35a2044923
--- /dev/null
+++ b/changes/bug24484
@@ -0,0 +1,4 @@
+ o Code simplification and refactoring:
+ - Since Tor requires C99, remove our old workaround code for libc
+ implementations where free(NULL) doesn't work. Closes ticket 24484.
+
diff --git a/changes/bug24688 b/changes/bug24688
new file mode 100644
index 0000000000..c376fe6a03
--- /dev/null
+++ b/changes/bug24688
@@ -0,0 +1,3 @@
+ o Minor features (performance, 32-bit):
+ - Make our timing-wheel code run a tiny bit faster on 32-bit platforms,
+ by preferring 32-bit math to 64-bit. Closes ticket 24688.
diff --git a/changes/bug24891 b/changes/bug24891
deleted file mode 100644
index 403b2b1123..0000000000
--- a/changes/bug24891
+++ /dev/null
@@ -1,4 +0,0 @@
- o Minor bugfixes (compilation):
- - Refrain from compiling unit testing related object files
- when --disable-unittests is set to configure script.
- Fixes bug 24891; bugfix on 0.2.5.1-alpha.
diff --git a/changes/bug24910 b/changes/bug24910
new file mode 100644
index 0000000000..58574c0069
--- /dev/null
+++ b/changes/bug24910
@@ -0,0 +1,7 @@
+ o Minor bugfixes (relay statistics):
+ - When a relay is collecting internal statistics about how many
+ create cell requests it has seen of each type, accurately count the
+ requests from relays that temporarily fall out of the consensus. (To
+ be extra conservative, we were already ignoring requests from
+ clients in our counts, and we continue ignoring them here.) Fixes
+ bug 24910; bugfix on 0.2.4.17-rc.
diff --git a/changes/bug24914 b/changes/bug24914
new file mode 100644
index 0000000000..ea441fd38c
--- /dev/null
+++ b/changes/bug24914
@@ -0,0 +1,3 @@
+ o Minor features (performance):
+ - Avoid a needless call to malloc() when processing an incoming
+ relay cell. Closes ticket 24914.
diff --git a/changes/bug24969 b/changes/bug24969
new file mode 100644
index 0000000000..46b2bae6f4
--- /dev/null
+++ b/changes/bug24969
@@ -0,0 +1,3 @@
+ o Minor bugfixes (Linux seccomp2 sandbox):
+ - Allow the nanosleep() system call, which glibc uses to implement
+ sleep() and usleep(). Fixes bug 24969; bugfix on 0.2.5.1-alpha.
diff --git a/changes/bug24977 b/changes/bug24977
deleted file mode 100644
index f8127a2a73..0000000000
--- a/changes/bug24977
+++ /dev/null
@@ -1,5 +0,0 @@
- o Minor bugfixes (onion services):
- - Recompute some consensus information after clock skews or when we
- transition from a non-live consensus to a live consensus. We do this to
- avoid having an outdated state which could impact next-generation onion
- services. Fixes bug 24977; bugfix on 0.3.2.1-alpha.
diff --git a/changes/bug25226 b/changes/bug25226
new file mode 100644
index 0000000000..b594a7a424
--- /dev/null
+++ b/changes/bug25226
@@ -0,0 +1,4 @@
+ o Major bugfixes (relay, denial of service):
+ - Impose a limit on circuit cell queue size. The limit can be controlled by
+ a consensus parameter. Fixes bug 25226; bugfix on 0.2.4.14-alpha.
+
diff --git a/changes/bug25373 b/changes/bug25373
new file mode 100644
index 0000000000..03e870e692
--- /dev/null
+++ b/changes/bug25373
@@ -0,0 +1,7 @@
+ o Major features (main loop, CPU wakeup):
+ - The bandwidth-limitation logic has been refactored so that
+ bandwidth calculations are performed on-demand, rather than
+ every TokenBucketRefillInterval milliseconds.
+ This change should improve the granularity of our bandwidth
+ calculations, and limit the number of times that the Tor process needs
+ to wake up when it is idle. Closes ticket 25373.
diff --git a/changes/bug25398 b/changes/bug25398
new file mode 100644
index 0000000000..227a95d21a
--- /dev/null
+++ b/changes/bug25398
@@ -0,0 +1,5 @@
+ o New system requirements:
+ - Tor no longer tries to support systems without mmap() or some local
+ equivalent. Apparently, compilation on such systems has been broken for
+ some time, without anybody noticing or complaining. Closes ticket
+ 25398.
diff --git a/changes/bug25399 b/changes/bug25399
new file mode 100644
index 0000000000..4554574939
--- /dev/null
+++ b/changes/bug25399
@@ -0,0 +1,5 @@
+ o Minor bugfixes (portability):
+ - Do not align mmap length, as it is not required by POSIX, and the
+ getpagesize function is deprecated. Fixes bug 25399; bugfix on
+ 0.1.1.23.
+
diff --git a/changes/bug25400 b/changes/bug25400
new file mode 100644
index 0000000000..cee7ea83b0
--- /dev/null
+++ b/changes/bug25400
@@ -0,0 +1,5 @@
+ o Minor bugfix (controler):
+ - Make CIRC_BW event reflect the total of all data sent on a circuit,
+ including padding and dropped cells. Also fix a mis-counting bug
+ when STREAM_BW events were enabled. Fixes bug 25400; bugfix on
+ 0.2.5.2-alpha.
diff --git a/changes/bug25409 b/changes/bug25409
new file mode 100644
index 0000000000..093d8f58bd
--- /dev/null
+++ b/changes/bug25409
@@ -0,0 +1,12 @@
+ o Removed features:
+ - The PortForwarding and PortForwardingHelper features have been
+ removed. The reasoning is, given that implementations of NAT traversal
+ protocols within common consumer grade routers are frequently buggy, and
+ that the target audience for a NAT punching feature is a perhaps
+ less-technically-inclined relay operator, when the helper fails to setup
+ traversal the problems are usually deep, ugly, and very router specific,
+ making them horrendously impossible for technical support to reliable
+ assist with, and thus resulting in frustration all around. Unfortunately,
+ relay operators who would like to run relays behind NATs will need to
+ become more familiar with the port forwarding configurations on their
+ local router. Closes 25409.
diff --git a/changes/bug25415 b/changes/bug25415
new file mode 100644
index 0000000000..ec851aee8d
--- /dev/null
+++ b/changes/bug25415
@@ -0,0 +1,4 @@
+ o Major bugfixes (directory authority):
+ - Avoid a crash when testing router reachability on a router that could
+ have an ed25519 ID, but which does not. Fixes bug 25415; bugfix on
+ 0.3.3.2-alpha.
diff --git a/changes/bug25425 b/changes/bug25425
new file mode 100644
index 0000000000..41f1a47b15
--- /dev/null
+++ b/changes/bug25425
@@ -0,0 +1,4 @@
+ o Minor features (testing):
+ - A new unittests module specifically for testing the functions in the
+ (new-ish) bridges.c module has been created with new unittests, raising
+ the code coverage percentages. Closes 25425.
diff --git a/changes/bug25477 b/changes/bug25477
deleted file mode 100644
index 0eac06137f..0000000000
--- a/changes/bug25477
+++ /dev/null
@@ -1,3 +0,0 @@
- o Minor bugfixes (logging):
- - Refrain from mentioning bug 21018, as it is already fixed.
- Fixes bug 25477; bugfix on 0.2.9.8.
diff --git a/changes/bug25512 b/changes/bug25512
new file mode 100644
index 0000000000..4b6491867e
--- /dev/null
+++ b/changes/bug25512
@@ -0,0 +1,5 @@
+ o Minor bugfixes (restart-in-process):
+ - When shutting down, Tor now clears all the flags in the control.c
+ module. This should prevent a bug where authentication cookies
+ are not generated on restart. Fixes bug 25512; bugfix on 0.3.3.1-alpha.
+
diff --git a/changes/bug25675 b/changes/bug25675
new file mode 100644
index 0000000000..d0f0287b59
--- /dev/null
+++ b/changes/bug25675
@@ -0,0 +1,4 @@
+ o Minor bugfixes (C correctness):
+ - Add a missing lock acquisition in the shutdown code of the
+ control subsystem. Fixes bug 25675; bugfix on 0.2.7.3-rc. Found
+ by Coverity; this is CID 1433643.
diff --git a/changes/bug25686_diagnostic b/changes/bug25686_diagnostic
deleted file mode 100644
index 96323145d8..0000000000
--- a/changes/bug25686_diagnostic
+++ /dev/null
@@ -1,4 +0,0 @@
- o Minor features (relay, diagnostic):
- - Add several checks to detect whether Tor relays are uploading their
- descriptors without specifying why they regenerated. Diagnostic for
- ticket 25686.
diff --git a/changes/bug25691_again b/changes/bug25691_again
new file mode 100644
index 0000000000..3d0d91bfd3
--- /dev/null
+++ b/changes/bug25691_again
@@ -0,0 +1,6 @@
+ o Minor bugfixes (path selection):
+ - Only select relays when they have the descriptors we prefer to
+ use for them. This change fixes a bug where we could select
+ a relay because it had _some_ descriptor, but reject it later with
+ a nonfatal assertion error because it didn't have the exact one we
+ wanted. Fixes bugs 25691 and 25692; bugfix on 0.3.3.4-alpha.
diff --git a/changes/bug25705 b/changes/bug25705
new file mode 100644
index 0000000000..360d96d4c6
--- /dev/null
+++ b/changes/bug25705
@@ -0,0 +1,5 @@
+ o Minor bugfixes (circuit path selection):
+ - Don't count path selection failures as circuit build failures. This
+ should eliminate cases where Tor blames its guard or the network
+ for situations like insufficient microdescriptors and/or overly
+ restrictive torrc settings. Fixes bug 25705; bugfix on 0.3.3.1-alpha.
diff --git a/changes/bug25787 b/changes/bug25787
deleted file mode 100644
index 3041e8a603..0000000000
--- a/changes/bug25787
+++ /dev/null
@@ -1,7 +0,0 @@
- o Minor bugfixes (testing):
- - Instead of trying to read the geoip configuration files from within the
- unit tests, instead create our own ersatz files with just enough
- geoip data in the format we expect. Trying to read from the source
- directory created problems on Windows with mingw, where the
- build system's paths are not the same as the platform's paths.
- Fixes bug 25787; bugfix on 0.3.4.1-alpha.
diff --git a/changes/bug25828 b/changes/bug25828
new file mode 100644
index 0000000000..45cd1f4ae8
--- /dev/null
+++ b/changes/bug25828
@@ -0,0 +1,7 @@
+ o Minor bugfixes (bandwidth management):
+ - Consider ourselves "low on write bandwidth" if we have exhausted our
+ write bandwidth some time in the last second. This was the
+ documented behavior before, but the actual behavior was to change
+ this value every TokenBucketRefillInterval. Fixes bug 25828; bugfix on
+ 0.2.3.5-alpha.
+
diff --git a/changes/bug25843 b/changes/bug25843
new file mode 100644
index 0000000000..ddbbbef787
--- /dev/null
+++ b/changes/bug25843
@@ -0,0 +1,3 @@
+ o Minor feature (entry guards):
+ - Introduce torrc option NumPrimaryGuards for controlling the number of
+ primary guards. Closes ticket 25843. \ No newline at end of file
diff --git a/changes/bug25886 b/changes/bug25886
deleted file mode 100644
index 45f9a54069..0000000000
--- a/changes/bug25886
+++ /dev/null
@@ -1,7 +0,0 @@
- o Minor bugfixes (relay):
- - In frac_nodes_with_descriptors(), add for_direct_connect, and replace
- node_has_any_descriptor() with node_has_preferred_descriptor(). Also,
- if we are using bridges and there is at least one bridge with a full
- descriptor, set f_guard in compute_frac_paths_available() to 1.0.
- Fixes bug 25886; bugfix on 0.3.5.1-alpha. Patch by Neel Chauhan.
-
diff --git a/changes/bug25901 b/changes/bug25901
new file mode 100644
index 0000000000..3ad30c7676
--- /dev/null
+++ b/changes/bug25901
@@ -0,0 +1,3 @@
+ o Minor bugfixes (hidden service v3):
+ - Fix a memory leak when an hidden service v3 is configured and gets a
+ SIGHUP signal. Fixes bug 25901; bugfix on 0.3.2.1-alpha.
diff --git a/changes/bug26007 b/changes/bug26007
new file mode 100644
index 0000000000..efcd15084d
--- /dev/null
+++ b/changes/bug26007
@@ -0,0 +1,5 @@
+ o Major bugfixes (directory authorities, security):
+ - When directory authorities read a zero-byte bandwidth file, they log
+ a warning with the contents of an uninitialised buffer. Log a warning
+ about the empty file instead.
+ Fixes bug 26007; bugfix on 0.2.2.1-alpha.
diff --git a/changes/bug26152 b/changes/bug26152
deleted file mode 100644
index 34fda09b25..0000000000
--- a/changes/bug26152
+++ /dev/null
@@ -1,4 +0,0 @@
- o Minor bugfixes (testing):
- - When logging a version mismatch in our openssl_version tests,
- report the actual offending version strings. Fixes bug 26152; bugfix on
- 0.2.9.1-alpha.
diff --git a/changes/bug26158 b/changes/bug26158
deleted file mode 100644
index 0d74cf1167..0000000000
--- a/changes/bug26158
+++ /dev/null
@@ -1,5 +0,0 @@
- o Minor bugfixes (relay):
- - Relays now correctly block attempts to re-extend to the previous
- relay by Ed25519 identity. Previously they would warn in this case,
- but not actually reject the attempt. Fixes bug 26158; bugfix on
- 0.3.0.1-alpha.
diff --git a/changes/bug26196 b/changes/bug26196
deleted file mode 100644
index e63f09a2d6..0000000000
--- a/changes/bug26196
+++ /dev/null
@@ -1,7 +0,0 @@
- o Minor bugfixes (testing, compilation):
- - Refrain from trying to get an item from empty smartlist in
- test_bridges_clear_bridge_list. Set DEBUG_SMARTLIST in unit
- tests to catch improper smartlist usage. Furthermore,
- enable DEBUG_SMARTLIST globally when build is configured
- with fragile hardening. Fixes bug 26196; bugfix on
- 0.3.4.1-alpha.
diff --git a/changes/bug26214 b/changes/bug26214
deleted file mode 100644
index 4277b9c6ec..0000000000
--- a/changes/bug26214
+++ /dev/null
@@ -1,3 +0,0 @@
- o Minor bugfixes (correctness, flow control):
- - Upon receiving a stream-level SENDME cell, verify that our window has
- not grown too large. Fixes bug 26214; bugfix on svn r54 (pre-0.0.1)
diff --git a/changes/bug26245 b/changes/bug26245
deleted file mode 100644
index 7a14cea0bc..0000000000
--- a/changes/bug26245
+++ /dev/null
@@ -1,3 +0,0 @@
- o Minor features (compilation):
- o The --enable-fatal-warnings flag now affects Rust code as well.
- Closes ticket 26245.
diff --git a/changes/bug26258_033 b/changes/bug26258_033
deleted file mode 100644
index ceca383335..0000000000
--- a/changes/bug26258_033
+++ /dev/null
@@ -1,4 +0,0 @@
- o Major bugfixes (rust, testing):
- - Fix a bug where a failure in the rust unit tests would not actually
- cause the build to fail. Fixes bug 26258; bugfix on 0.3.3.4-alpha.
-
diff --git a/changes/bug26282 b/changes/bug26282
deleted file mode 100644
index c278f0b60a..0000000000
--- a/changes/bug26282
+++ /dev/null
@@ -1,4 +0,0 @@
- o Minor bugfixes (C correctness):
- - Avoid casting smartlist index to int implicitly, as it may trigger
- a warning (-Wshorten-64-to-32). Fixes bug 26282; bugfix on
- 0.2.3.13-alpha, 0.2.7.1-alpha and 0.2.1.1-alpha.
diff --git a/changes/bug26402 b/changes/bug26402
deleted file mode 100644
index b21283a2d2..0000000000
--- a/changes/bug26402
+++ /dev/null
@@ -1,4 +0,0 @@
- o Minor bugfixes (compilation):
- - When linking the libtor_testing.a library, only include the dirauth
- object files once. Previously, they were getting added twice.
- Fixes bug 26402; bugfix on 0.3.4.1-alpha.
diff --git a/changes/bug26415 b/changes/bug26415
deleted file mode 100644
index 497fbb7365..0000000000
--- a/changes/bug26415
+++ /dev/null
@@ -1,3 +0,0 @@
- o Minor bugfixes (testing):
- - Fix compilation of the doctests in the Rust crypto crate. Fixes
- bug 26415; bugfix on 0.3.4.1-alpha.
diff --git a/changes/bug26435 b/changes/bug26435
deleted file mode 100644
index f66c503dd5..0000000000
--- a/changes/bug26435
+++ /dev/null
@@ -1,5 +0,0 @@
- o Major bugfixes (directory authority):
- - Fix a memory leak where directory authorities would leak a chunk
- of memory for every router descriptor every time they considered
- voting. This bug was taking down directory authorities due to
- out-of-memory issues. Fixes bug 26435; bugfix on 0.3.3.6.
diff --git a/changes/coveralls b/changes/coveralls
new file mode 100644
index 0000000000..7fa69bb2b4
--- /dev/null
+++ b/changes/coveralls
@@ -0,0 +1,3 @@
+ o Minor features (continuous integration):
+ - Our Travis CI configuration now integrates with the Coveralls coverage
+ analysis tool. Closes ticket 25818.
diff --git a/changes/feature19429 b/changes/feature19429
new file mode 100644
index 0000000000..0faa6e84e1
--- /dev/null
+++ b/changes/feature19429
@@ -0,0 +1,5 @@
+ o Minor features (compatibility):
+ - Tor now detects versions of OpenSSL 1.1.0 and later compiled with the
+ no-deprecated option, and builds correctly with them. Closes
+ tickets 19429, 19981, and 25353.
+
diff --git a/changes/feature25150 b/changes/feature25150
new file mode 100644
index 0000000000..eb65327a8d
--- /dev/null
+++ b/changes/feature25150
@@ -0,0 +1,4 @@
+ o Minor features (performance, allocation):
+ - Avoid a needless malloc()/free() pair every time we handle an ntor
+ handshake. Closes ticket 25150.
+
diff --git a/changes/feature26372_029 b/changes/feature26372_029
deleted file mode 100644
index 150ac30555..0000000000
--- a/changes/feature26372_029
+++ /dev/null
@@ -1,4 +0,0 @@
- o Minor features (compilation):
-
- - When building Tor, prefer to use Python 3 over Python 2, and more
- recent (contemplated) versions over older ones. Closes ticket 26372.
diff --git a/changes/feature8323 b/changes/feature8323
deleted file mode 100644
index 6fbc972d26..0000000000
--- a/changes/feature8323
+++ /dev/null
@@ -1,3 +0,0 @@
- o Minor features (controller):
- - Implement 'GETINFO md/all' controller command to enable
- getting all known microdesriptors. Closes ticket 8323.
diff --git a/changes/full_include_paths b/changes/full_include_paths
deleted file mode 100644
index c0ac0a05d3..0000000000
--- a/changes/full_include_paths
+++ /dev/null
@@ -1,3 +0,0 @@
- o Code simplification and refactoring:
- - Include paths to header files within Tor are now qualified by directory
- within the top-level src directory.
diff --git a/changes/isolate_libevent b/changes/isolate_libevent
new file mode 100644
index 0000000000..852e533fd3
--- /dev/null
+++ b/changes/isolate_libevent
@@ -0,0 +1,5 @@
+ o Code simplification and refactoring:
+ - Initial work to isolate Libevent usage to a handful of modules in our
+ codebase, to simplify our call structure, and so that we can more
+ easily change event loops in the future if needed. Closes ticket
+ 23750.
diff --git a/changes/split_or_h b/changes/split_or_h
deleted file mode 100644
index 53d54ca6dd..0000000000
--- a/changes/split_or_h
+++ /dev/null
@@ -1,5 +0,0 @@
- o Code simplification and refactoring:
- - Many structures have been removed from the centralized "or.h" header,
- and moved into their own headers. This will allow us to reduce
- the number of places in the code that rely on each structure's
- contents and layout. Closes ticket 26383.
diff --git a/changes/ticket19979 b/changes/ticket19979
deleted file mode 100644
index a6bf93f1a4..0000000000
--- a/changes/ticket19979
+++ /dev/null
@@ -1,3 +0,0 @@
- o Minor features (openssl):
- - When possible, use RFC5869 HKDF implementation from OpenSSL.
- Resolves ticket 19979.
diff --git a/changes/ticket20522 b/changes/ticket20522
new file mode 100644
index 0000000000..a5e6718e1e
--- /dev/null
+++ b/changes/ticket20522
@@ -0,0 +1,6 @@
+ o Deprecated features:
+ - As we are not recommending 0.2.5 anymore we require relays that once had
+ an ed25519 key associated with their RSA key to always have that key
+ instead of allowing them to drop back to a version that didn't support
+ ed25519. This means they need to use a new RSA key if the want to
+ downgrade to an older version of tor without ed25519. Closes ticket 20522.
diff --git a/changes/ticket23354 b/changes/ticket23354
new file mode 100644
index 0000000000..f79dfd96ae
--- /dev/null
+++ b/changes/ticket23354
@@ -0,0 +1,6 @@
+ o Minor features (configuration):
+ - The "DownloadSchedule" options have been renamed to end with
+ "DownloadInitialDelay". The old names are still allowed, but will
+ produce a warning. Comma-separated lists are still permitted for
+ these options, but all values after the first are ignored (as they have
+ been since 0.2.9). Closes ticket 23354.
diff --git a/changes/ticket23873 b/changes/ticket23873
new file mode 100644
index 0000000000..ffe65e5ed4
--- /dev/null
+++ b/changes/ticket23873
@@ -0,0 +1,6 @@
+ o Code simplification and refactoring:
+ - We remove the return value of node_get_prim_orport() and
+ node_get_prim_dirport(), and introduce node_get_prim_orport()
+ in node_ipv6_or_preferred() and node_ipv6_dir_preferred() in
+ order to check for a null address. Closes ticket 23873. Patch
+ by Neel Chauhan.
diff --git a/changes/ticket24714 b/changes/ticket24714
new file mode 100644
index 0000000000..60353abec9
--- /dev/null
+++ b/changes/ticket24714
@@ -0,0 +1,6 @@
+ o Code simplification and refactoring:
+ - Rename two fields of connection_t struct.
+ timestamp_lastwritten is renamed to timestamp_last_write_allowed and
+ timestamp_lastread is renamed to timestamp_last_read_allowed.
+ Closes ticket 24714, patch by "valentecaio".
+
diff --git a/changes/ticket24734 b/changes/ticket24734
new file mode 100644
index 0000000000..00029ce578
--- /dev/null
+++ b/changes/ticket24734
@@ -0,0 +1,6 @@
+ o Code simplification and refactoring:
+ - Remove the return value for fascist_firewall_choose_address_base(),
+ and sister functions such as fascist_firewall_choose_address_node()
+ and fascist_firewall_choose_address_rs(). Also, while we're here,
+ initialize the ap argument as leaving it uninitialized can pose a
+ security hazard. Closes ticket 24734. Patch by Neel Chauhan.
diff --git a/changes/ticket24740 b/changes/ticket24740
new file mode 100644
index 0000000000..253cdb65e2
--- /dev/null
+++ b/changes/ticket24740
@@ -0,0 +1,5 @@
+ o Minor bugfixes (directory server cert fetch):
+ - Fixed launching a certificate fetch always during the scheduled
+ periodic consensus fetch by fetching only in those cases when
+ consensus are waiting for certs.
+ Fixes bug 24740; bugfix on 0.2.9.1-alpha.
diff --git a/changes/ticket25024 b/changes/ticket25024
new file mode 100644
index 0000000000..0e5069cf81
--- /dev/null
+++ b/changes/ticket25024
@@ -0,0 +1,4 @@
+ o Minor features (code quality):
+ - Add optional spell-checking for the Tor codebase, using the "misspell"
+ program. To use this feature, run "make check-typos".
+ Closes ticket 25024.
diff --git a/changes/ticket25081 b/changes/ticket25081
new file mode 100644
index 0000000000..b6e6c2a5a6
--- /dev/null
+++ b/changes/ticket25081
@@ -0,0 +1,5 @@
+ o Code simplification and refactoring:
+ - Remove extern declaration of stats_n_seconds_working variable from main,
+ protecting its accesses with get_uptime() and reset_uptime() functions.
+ Closes ticket 25081, patch by “valentecaio”.
+
diff --git a/changes/ticket25162 b/changes/ticket25162
new file mode 100644
index 0000000000..37019a7f8f
--- /dev/null
+++ b/changes/ticket25162
@@ -0,0 +1,6 @@
+ o Minor features (compression, zstd):
+ - When running with zstd, Tor now considers using advanced functions that
+ the zstd maintainers have labeled as potentially unstable. To
+ prevent breakage, Tor will only use this functionality when
+ the runtime version of the zstd library matches the version
+ with which it were compiled. Closes ticket 25162.
diff --git a/changes/ticket25261 b/changes/ticket25261
new file mode 100644
index 0000000000..604a09d975
--- /dev/null
+++ b/changes/ticket25261
@@ -0,0 +1,3 @@
+ o Minor bugfix (Multiple includes):
+ - Fixed multiple includes of trasports.h in src/or/connection.c
+ Fixes bug 25261; bugfix on 0.2.5.1-alpha.
diff --git a/changes/ticket25268 b/changes/ticket25268
new file mode 100644
index 0000000000..e444984dc4
--- /dev/null
+++ b/changes/ticket25268
@@ -0,0 +1,7 @@
+ o Removed features:
+ - The old "round-robin" circuit multiplexer (circuitmux)
+ implementation has been removed, along with a fairly large set of
+ code that existed to support it. It has not been the default
+ circuitmux since we introduced the "EWMA" circuitmux in 0.2.4.x,
+ but it still required an unreasonable amount of memory and CPU.
+ Closes ticket 25268.
diff --git a/changes/ticket25290 b/changes/ticket25290
new file mode 100644
index 0000000000..5e44f5e05c
--- /dev/null
+++ b/changes/ticket25290
@@ -0,0 +1,5 @@
+ o Code simplification and refactoring:
+ - We switch to should_record_bridge_info() in geoip_note_client_seen() and
+ options_need_geoip_info() instead of accessing the configuration values
+ directly. Fixes bug 25290; bugfix on 0.2.1.6-alpha. Patch by Neel
+ Chauhan.
diff --git a/changes/ticket25374 b/changes/ticket25374
new file mode 100644
index 0000000000..5fc59d1589
--- /dev/null
+++ b/changes/ticket25374
@@ -0,0 +1,6 @@
+ o Code simplification and refactoring:
+ - Our main loop has been simplified so that all important operations
+ happen inside events. Previously, some operations had to happen
+ outside the event loop, to prevent infinite sequences of event
+ activations. Closes ticket 25374.
+
diff --git a/changes/ticket25376_25762 b/changes/ticket25376_25762
new file mode 100644
index 0000000000..b3ebf56d3b
--- /dev/null
+++ b/changes/ticket25376_25762
@@ -0,0 +1,10 @@
+ o Major feature (main loop, CPU usage):
+ - Previously, tor would enable at startup all possible main loop event
+ regardless if it needed them. For instance, directory authorities
+ callbacks were fired up even for client only. We have now refactored this
+ whole interface to only enable the appropriate callbacks depending on what
+ are tor roles (client only, relay, hidden service, etc.). Furthermore,
+ these events now depend on DisableNetwork or the hibernation state in
+ order to enable them. This is a big step towards reducing client CPU usage
+ by reducing the amount of wake ups the daemon does. Closes ticket 25376
+ and 25762.
diff --git a/changes/ticket25409 b/changes/ticket25409
new file mode 100644
index 0000000000..f0006fbc5d
--- /dev/null
+++ b/changes/ticket25409
@@ -0,0 +1,6 @@
+ o Code simplification and refactoring:
+ We remove the PortForwsrding and PortForwardingHelper options, related
+ functions, and the port_forwarding tests. These options were used by
+ the now-deprecated Vidalia to help ordinary users become Tor relays or
+ bridges. Closes ticket 25409. Patch by Neel Chauhan.
+
diff --git a/changes/ticket25432 b/changes/ticket25432
new file mode 100644
index 0000000000..21ca201343
--- /dev/null
+++ b/changes/ticket25432
@@ -0,0 +1,6 @@
+ o Code simplification and refactoring:
+ - Merge functions used for describing nodes and suppress the functions
+ that do not allocate memory for the output buffer string.
+ NODE_DESC_BUF_LEN constant and format_node_description() function
+ cannot be used externally from router.c module anymore.
+ Closes ticket 25432. Patch by valentecaio.
diff --git a/changes/ticket25511 b/changes/ticket25511
new file mode 100644
index 0000000000..0a24e265ca
--- /dev/null
+++ b/changes/ticket25511
@@ -0,0 +1,5 @@
+ o Minor features (control port):
+ - Introduce GETINFO "current-time/{local,utc}" to return the local
+ and UTC times respectively in ISO format. This helps a controller
+ like Tor Browser detect a time-related error. Closes ticket 25511.
+ Patch by Neel Chauhan.
diff --git a/changes/ticket25610 b/changes/ticket25610
new file mode 100644
index 0000000000..887770e6ac
--- /dev/null
+++ b/changes/ticket25610
@@ -0,0 +1,5 @@
+ o Major feature (directory authority, modularization):
+ - The directory authority subsystem has been modularized. The code is now
+ located in src/or/dirauth/ which is compiled in by default. To disable the
+ module, the configure option --disable-module-dirauth has been added.
+ Closes ticket 25610;
diff --git a/changes/ticket25645 b/changes/ticket25645
new file mode 100644
index 0000000000..ab20a5ca4c
--- /dev/null
+++ b/changes/ticket25645
@@ -0,0 +1,4 @@
+ o Minor bugfixes (channel_get_for_extend()):
+ - Remove the unused variable n_possible from the function
+ Fixes bug 25645; bugfix on 0.2.4.4-alpha
+
diff --git a/changes/ticket25760 b/changes/ticket25760
new file mode 100644
index 0000000000..504fd60de6
--- /dev/null
+++ b/changes/ticket25760
@@ -0,0 +1,5 @@
+ o Removed features:
+ - The TestingEnableTbEmptyEvent option has been removed. It was used
+ in testing simulations to measure how often connection buckets were
+ emptied, in order to improve our scheduling, but it has not
+ been actively used in years. Closes ticket 25760.
diff --git a/changes/ticket25766 b/changes/ticket25766
new file mode 100644
index 0000000000..6382b6215e
--- /dev/null
+++ b/changes/ticket25766
@@ -0,0 +1,3 @@
+ o Code simplification and refactoring:
+ - Refactor token-bucket implementations to use a common backend.
+ Closes ticket 25766.
diff --git a/changes/ticket25927.1 b/changes/ticket25927.1
new file mode 100644
index 0000000000..84ac86e187
--- /dev/null
+++ b/changes/ticket25927.1
@@ -0,0 +1,6 @@
+ o Minor features (timekeeping, circuit scheduling):
+ - When keeping track of how busy each circuit have been recently on
+ a given connection, use coarse-grained monotonic timers rather than
+ gettimeofday(). This change should marginally increase accuracy
+ and performance. Implements part of ticket 25927.
+
diff --git a/changes/ticket25927.2 b/changes/ticket25927.2
new file mode 100644
index 0000000000..9acb4aaf6f
--- /dev/null
+++ b/changes/ticket25927.2
@@ -0,0 +1,5 @@
+ o Code simplification and refactoring:
+ - Remove our previous logic for "cached gettimeofday()" -- our coarse
+ monotonic timers are fast enough for this purpose, and far less
+ error-prone. Implements part of ticket 25927.
+
diff --git a/changes/ticket25931 b/changes/ticket25931
new file mode 100644
index 0000000000..20ce761883
--- /dev/null
+++ b/changes/ticket25931
@@ -0,0 +1,9 @@
+ o Minor features (mainloop):
+ - Move responsibility for
+ rescanning the consensus cache
+ from a once-per-second callback to a callback that is only scheduled as
+ needed. Once enough items are removed from our once-per-second
+ callback, we can eliminate it entirely to conserve CPU when idle.
+ Closes ticket:
+ 25931.
+
diff --git a/changes/ticket25932 b/changes/ticket25932
new file mode 100644
index 0000000000..67f56f7cc0
--- /dev/null
+++ b/changes/ticket25932
@@ -0,0 +1,9 @@
+ o Minor features (mainloop):
+ - Move responsibility for
+ closing connections, circuits, and channels
+ from a once-per-second callback to a callback that is only scheduled as
+ needed. Once enough items are removed from our once-per-second
+ callback, we can eliminate it entirely to conserve CPU when idle.
+ Closes ticket
+ 25932.
+
diff --git a/changes/ticket25937 b/changes/ticket25937
new file mode 100644
index 0000000000..7c49fac708
--- /dev/null
+++ b/changes/ticket25937
@@ -0,0 +1,9 @@
+ o Minor features (mainloop):
+ - Move responsibility for
+ consensus voting
+ from a once-per-second callback to a callback that is only scheduled as
+ needed. Once enough items are removed from our once-per-second
+ callback, we can eliminate it entirely to conserve CPU when idle.
+ Closes ticket
+ 25937.
+
diff --git a/changes/ticket25947 b/changes/ticket25947
deleted file mode 100644
index 68559a73f8..0000000000
--- a/changes/ticket25947
+++ /dev/null
@@ -1,4 +0,0 @@
- o Minor feature (unit tests):
- - Test complete bandwidth measurements files and test that incomplete lines
- only give warnings when the end of the header has not been
- detected. Fixes bug 25947; bugfix on 0.2.2.1-alpha
diff --git a/changes/ticket25948 b/changes/ticket25948
new file mode 100644
index 0000000000..7851d0b65b
--- /dev/null
+++ b/changes/ticket25948
@@ -0,0 +1,9 @@
+ o Minor features (mainloop):
+ - Move responsibility for
+ saving the state file to disk
+ from a once-per-second callback to a callback that is only scheduled as
+ needed. Once enough items are removed from our once-per-second
+ callback, we can eliminate it entirely to conserve CPU when idle.
+ Closes ticket
+ 25948.
+
diff --git a/changes/ticket25949 b/changes/ticket25949
new file mode 100644
index 0000000000..fd87373418
--- /dev/null
+++ b/changes/ticket25949
@@ -0,0 +1,9 @@
+ o Minor features (mainloop):
+ - Move responsibility for
+ honoring delayed SIGNEWNYM requests
+ from a once-per-second callback to a callback that is only scheduled as
+ needed. Once enough items are removed from our once-per-second
+ callback, we can eliminate it entirely to conserve CPU when idle.
+ Closes ticket
+ 25949.
+
diff --git a/changes/ticket25951 b/changes/ticket25951
new file mode 100644
index 0000000000..b6cfc2091c
--- /dev/null
+++ b/changes/ticket25951
@@ -0,0 +1,9 @@
+ o Minor features (mainloop):
+ - Move responsibility for
+ flushing log callbacks
+ from a once-per-second callback to a callback that is only scheduled as
+ needed. Once enough items are removed from our once-per-second
+ callback, we can eliminate it entirely to conserve CPU when idle.
+ Closes ticket
+ 25951.
+
diff --git a/changes/ticket25952 b/changes/ticket25952
new file mode 100644
index 0000000000..e4dd56df06
--- /dev/null
+++ b/changes/ticket25952
@@ -0,0 +1,9 @@
+ o Minor features (mainloop):
+ - Move responsibility for
+ warning relay operators about unreachable ports
+ from a once-per-second callback to a callback that is only scheduled as
+ needed. Once enough items are removed from our once-per-second
+ callback, we can eliminate it entirely to conserve CPU when idle.
+ Closes ticket
+ 25952.
+
diff --git a/changes/ticket25960 b/changes/ticket25960
deleted file mode 100644
index 0d1be2119b..0000000000
--- a/changes/ticket25960
+++ /dev/null
@@ -1,5 +0,0 @@
- o Minor feature (directory authorities):
- - Stop warning about incomplete bw lines before the first complete bw line
- has been found, so that additional header lines can be ignored.
- Fixes bug 25960; bugfix on 0.2.2.1-alpha
-
diff --git a/changes/ticket25995 b/changes/ticket25995
new file mode 100644
index 0000000000..855020bd39
--- /dev/null
+++ b/changes/ticket25995
@@ -0,0 +1,5 @@
+ o Minor bugfixes (tests):
+ - While running the circuit_timeout test, fix the PRNG to a deterministic
+ AES stream, so that the test coverage from this test will itself be
+ deterministic. Fixes bug 25995; bugfix on 0.2.2.2-alpha.
+
diff --git a/changes/ticket25996 b/changes/ticket25996
new file mode 100644
index 0000000000..f523bc6304
--- /dev/null
+++ b/changes/ticket25996
@@ -0,0 +1,5 @@
+ o Minor bugfixes (testing):
+ - Repeat part of the test in test_client_pick_intro() a number of times,
+ to give it consistent coverage. Fixes bug 25996; bugfix on
+ 0.3.2.1-alpha.
+
diff --git a/changes/ticket25997 b/changes/ticket25997
new file mode 100644
index 0000000000..2c802c856b
--- /dev/null
+++ b/changes/ticket25997
@@ -0,0 +1,5 @@
+ o Minor bugfixes (testing, coverage):
+ - Remove randomness from the hs_common/responsible_hsdirs test,
+ so that it always takes the same path through the function it tests.
+ Fixes bug 25997; bugfix on 0.3.2.1-alpha.
+
diff --git a/changes/ticket26014 b/changes/ticket26014
new file mode 100644
index 0000000000..9d62ddbba9
--- /dev/null
+++ b/changes/ticket26014
@@ -0,0 +1,4 @@
+ o Minor features (Testing):
+ - Add a unit test for voting_schedule_get_start_of_next_interval().
+ Closes ticket 26014, and helps make unit test coverage more
+ deterministic.
diff --git a/changes/ticket26426 b/changes/ticket26426
deleted file mode 100644
index 05fa974943..0000000000
--- a/changes/ticket26426
+++ /dev/null
@@ -1,4 +0,0 @@
- o Removed features:
- - Tor no longer supports building with the dmalloc library. For debugging
- memory issues, we suggest using gperftools or msan instead.
- Closes ticket 26426.
diff --git a/changes/ticket26427 b/changes/ticket26427
deleted file mode 100644
index ff33f7bd4c..0000000000
--- a/changes/ticket26427
+++ /dev/null
@@ -1,6 +0,0 @@
- o Minor features (code layout):
- - Make a new lowest-level error-handling API for use by code invoked
- from within the logging module. This interface it makes it so
- the logging code is no longer at risk of calling into itself if
- a failure occurs while trying to log something.
- Closes ticket 26427.
diff --git a/changes/ticket4187 b/changes/ticket4187
new file mode 100644
index 0000000000..c5f795b1a6
--- /dev/null
+++ b/changes/ticket4187
@@ -0,0 +1,3 @@
+ o Minor bugfixes (directory client):
+ - When unverified-consensus is verified, rename it to cached-consenus.
+ Fixes bug 4187; bugfix on 0.2.0.3-alpha.
diff --git a/changes/ticket6236 b/changes/ticket6236
new file mode 100644
index 0000000000..9dea07e696
--- /dev/null
+++ b/changes/ticket6236
@@ -0,0 +1,4 @@
+ o Minor bugfixes (Duplicate code):
+ - Remove duplicate code in parse_{c,s}method_line and bootstrap
+ their functionalities into a single function. Fixes
+ bug 6236; bugfix on 0.2.3.6-alpha.
diff --git a/changes/travis_distcheck b/changes/travis_distcheck
new file mode 100644
index 0000000000..0f278fe7ee
--- /dev/null
+++ b/changes/travis_distcheck
@@ -0,0 +1,4 @@
+ o Minor features (continuous integration):
+ - Our .travis.yml configuration now includes support for testing
+ the results of "make distcheck". (It's not uncommon for "make check" to
+ pass but "make distcheck" to fail.) Closes ticket 25814.
diff --git a/config.rust.in b/config.rust.in
deleted file mode 100644
index 4ca5351aec..0000000000
--- a/config.rust.in
+++ /dev/null
@@ -1,22 +0,0 @@
-# Used by our cargo build.rs script to get variables from autoconf.
-#
-# The "configure" script will generate "config.rust" from "config.rust.in",
-# and then build.rs will read "config.rust".
-
-BUILDDIR=@BUILDDIR@
-TOR_LDFLAGS_zlib=@TOR_LDFLAGS_zlib@
-TOR_LDFLAGS_openssl=@TOR_LDFLAGS_openssl@
-TOR_LDFLAGS_libevent=@TOR_LDFLAGS_libevent@
-TOR_ZLIB_LIBS=@TOR_ZLIB_LIBS@
-TOR_LIB_MATH=@TOR_LIB_MATH@
-TOR_LIBEVENT_LIBS=@TOR_LIBEVENT_LIBS@
-TOR_OPENSSL_LIBS=@TOR_OPENSSL_LIBS@
-TOR_LIB_WS32=@TOR_LIB_WS32@
-TOR_LIB_GDI=@TOR_LIB_GDI@
-TOR_LIB_USERENV=@TOR_LIB_USERENV@
-CURVE25519_LIBS=@CURVE25519_LIBS@
-TOR_SYSTEMD_LIBS=@TOR_SYSTEMD_LIBS@
-TOR_LZMA_LIBS=@TOR_LZMA_LIBS@
-TOR_ZSTD_LIBS=@TOR_ZSTD_LIBS@
-LIBS=@LIBS@
-LDFLAGS=@LDFLAGS@
diff --git a/configure.ac b/configure.ac
index 116a51f7a3..387fc6fbeb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,10 +1,10 @@
dnl Copyright (c) 2001-2004, Roger Dingledine
dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
-dnl Copyright (c) 2007-2018, The Tor Project, Inc.
+dnl Copyright (c) 2007-2017, The Tor Project, Inc.
dnl See LICENSE for licensing information
AC_PREREQ([2.63])
-AC_INIT([tor],[0.3.5.0-alpha-dev])
+AC_INIT([tor],[0.3.4.0-alpha-dev])
AC_CONFIG_SRCDIR([src/or/main.c])
AC_CONFIG_MACRO_DIR([m4])
@@ -21,6 +21,16 @@ AC_CANONICAL_HOST
PKG_PROG_PKG_CONFIG
+if test -f "/etc/redhat-release"; then
+ if test -f "/usr/kerberos/include"; then
+ CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
+ fi
+fi
+
+# Not a no-op; we want to make sure that CPPFLAGS is set before we use
+# the += operator on it in src/or/Makefile.am
+CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
+
AC_ARG_ENABLE(openbsd-malloc,
AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD. Linux only]))
AC_ARG_ENABLE(static-openssl,
@@ -166,7 +176,6 @@ AC_ARG_ENABLE(fragile-hardening,
AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
fragile_hardening="yes"
- AC_DEFINE(DEBUG_SMARTLIST, 1, [Enable smartlist debugging])
fi
dnl Linker hardening options
@@ -290,21 +299,14 @@ AM_PROG_CC_C_O
AC_PROG_CC_C99
AC_ARG_VAR([PYTHON], [path to Python binary])
-AC_CHECK_PROGS(PYTHON, [ \
- python3 \
- python3.8 python3.7 python3.6 python3.5 python3.4 \
- python \
- python2 python2.7])
+AC_CHECK_PROGS(PYTHON, [python python2 python2.7 python3 python3.3])
if test "x$PYTHON" = "x"; then
AC_MSG_WARN([Python unavailable; some tests will not be run.])
fi
AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
dnl List all external rust crates we depend on here. Include the version
-rust_crates=" \
- digest-0.7.2 \
- libc-0.2.39 \
-"
+rust_crates="libc-0.2.39"
AC_SUBST(rust_crates)
ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
@@ -457,11 +459,6 @@ if test "x$enable_rust" = "xyes"; then
fi
AC_DEFINE([HAVE_RUST], 1, [have Rust])
- if test "x$enable_fatal_warnings" = "xyes"; then
- RUST_WARN=
- else
- RUST_WARN=#
- fi
if test "x$enable_cargo_online_mode" = "xyes"; then
CARGO_ONLINE=
RUST_DL=#
@@ -515,7 +512,6 @@ if test "x$enable_rust" = "xyes"; then
AC_SUBST(TOR_RUST_STATIC_NAME)
AC_SUBST(CARGO_ONLINE)
- AC_SUBST(RUST_WARN)
AC_SUBST(RUST_DL)
dnl Let's check the rustc version, too
@@ -1112,33 +1108,6 @@ if test "$fragile_hardening" = "yes"; then
TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
fi
-dnl Find the correct libraries to add in order to use the sanitizers.
-dnl
-dnl When building Rust, Cargo will run the linker with the -nodefaultlibs
-dnl option, which will prevent the compiler from linking the sanitizer
-dnl libraries it needs. We need to specify them manually.
-dnl
-dnl What's more, we need to specify them in a linker script rather than
-dnl from build.rs: these options aren't allowed in the cargo:rustc-flags
-dnl variable.
-RUST_LINKER_OPTIONS=""
-if test "x$have_clang" = "xyes"; then
- if test "x$CFLAGS_ASAN" != "x"; then
- RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS $CFLAGS_ASAN"
- fi
- if test "x$CFLAGS_UBSAN" != "x"; then
- RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS $CFLAGS_UBSAN"
- fi
-else
- if test "x$CFLAGS_ASAN" != "x"; then
- RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -lasan"
- fi
- if test "x$CFLAGS_UBSAN" != "x"; then
- RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -lubsan"
- fi
-fi
-AC_SUBST(RUST_LINKER_OPTIONS)
-
CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
@@ -1343,7 +1312,8 @@ AC_SUBST(CURVE25519_LIBS)
dnl Make sure to enable support for large off_t if available.
AC_SYS_LARGEFILE
-AC_CHECK_HEADERS([errno.h \
+AC_CHECK_HEADERS([assert.h \
+ errno.h \
fcntl.h \
signal.h \
string.h \
@@ -1756,6 +1726,26 @@ if test "$tor_cv_uint8_uchar" = "no"; then
AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
fi
+# Whether we should use the dmalloc memory allocation debugging library.
+AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
+AC_ARG_WITH(dmalloc,
+AS_HELP_STRING(--with-dmalloc, [use debug memory allocation library]),
+[if [[ "$withval" = "yes" ]]; then
+ dmalloc=1
+ AC_MSG_RESULT(yes)
+else
+ dmalloc=1
+ AC_MSG_RESULT(no)
+fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
+)
+
+if [[ $dmalloc -eq 1 ]]; then
+ AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
+ AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
+ AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
+ AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
+fi
+
AC_ARG_WITH(tcmalloc,
AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library]),
[ tcmalloc=yes ], [ tcmalloc=no ])
@@ -2267,8 +2257,6 @@ CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_z
AC_CONFIG_FILES([
Doxyfile
Makefile
- config.rust
- link_rust.sh
contrib/dist/suse/tor.sh
contrib/operator-tools/tor.logrotate
contrib/dist/tor.sh
diff --git a/contrib/win32build/tor-mingw.nsi.in b/contrib/win32build/tor-mingw.nsi.in
index c9822790bb..dfcb0644dc 100644
--- a/contrib/win32build/tor-mingw.nsi.in
+++ b/contrib/win32build/tor-mingw.nsi.in
@@ -8,7 +8,7 @@
!include "LogicLib.nsh"
!include "FileFunc.nsh"
!insertmacro GetParameters
-!define VERSION "0.3.5.0-alpha-dev"
+!define VERSION "0.3.4.0-alpha-dev"
!define INSTALLER "tor-${VERSION}-win32.exe"
!define WEBSITE "https://www.torproject.org/"
!define LICENSE "LICENSE"
diff --git a/doc/HACKING/CodingStandards.md b/doc/HACKING/CodingStandards.md
index b830ecea93..79a6a9f0ce 100644
--- a/doc/HACKING/CodingStandards.md
+++ b/doc/HACKING/CodingStandards.md
@@ -42,23 +42,6 @@ If you have changed build system components:
- For example, if you have changed Makefiles, autoconf files, or anything
else that affects the build system.
-License issues
-==============
-
-Tor is distributed under the license terms in the LICENSE -- in
-brief, the "3-clause BSD license". If you send us code to
-distribute with Tor, it needs to be code that we can distribute
-under those terms. Please don't send us patches unless you agree
-to allow this.
-
-Some compatible licenses include:
-
- - 3-clause BSD
- - 2-clause BSD
- - CC0 Public Domain Dedication
-
-
-
How we use Git branches
=======================
@@ -172,6 +155,7 @@ deviations from our C whitespace style. Generally, we use:
- Unix-style line endings
- K&R-style indentation
- No space before newlines
+ - A blank line at the end of each file
- Never more than one blank line in a row
- Always spaces, never tabs
- No more than 79-columns per line.
@@ -184,9 +168,6 @@ deviations from our C whitespace style. Generally, we use:
`puts (x)`.
- Function declarations at the start of the line.
-If you use an editor that has plugins for editorconfig.org, the file
-`.editorconfig` will help you to conform this coding style.
-
We try hard to build without warnings everywhere. In particular, if
you're using gcc, you should invoke the configure script with the
option `--enable-fatal-warnings`. This will tell the compiler
diff --git a/doc/HACKING/HelpfulTools.md b/doc/HACKING/HelpfulTools.md
index eb068a91f3..a0795076e0 100644
--- a/doc/HACKING/HelpfulTools.md
+++ b/doc/HACKING/HelpfulTools.md
@@ -25,6 +25,16 @@ Jenkins
https://jenkins.torproject.org
+Dmalloc
+-------
+
+The dmalloc library will keep track of memory allocation, so you can find out
+if we're leaking memory, doing any double-frees, or so on.
+
+ dmalloc -l -/dmalloc.log
+ (run the commands it tells you)
+ ./configure --with-dmalloc
+
Valgrind
--------
diff --git a/doc/tor.1.txt b/doc/tor.1.txt
index f42ad0dd3c..dc0eaba283 100644
--- a/doc/tor.1.txt
+++ b/doc/tor.1.txt
@@ -1237,7 +1237,7 @@ The following options are useful only for clients (that is, if
flag is not supported.
**CacheIPv4DNS**;;
Tells the client to remember IPv4 DNS answers we receive from exit
- nodes via this connection.
+ nodes via this connection. (On by default.)
**CacheIPv6DNS**;;
Tells the client to remember IPv6 DNS answers we receive from exit
nodes via this connection.
@@ -1592,14 +1592,6 @@ The following options are useful only for clients (that is, if
which means that nodes specified in ExcludeNodes will not be
picked.
+
- When either this option or HSLayer3Nodes are set, the /16 subnet
- and node family restrictions are removed for hidden service
- circuits. Additionally, we allow the guard node to be present
- as the Rend, HSDir, and IP node, and as the hop before it. This
- is done to prevent the adversary from inferring information
- about our guard, layer2, and layer3 node choices at later points
- in the path.
- +
This option is meant to be managed by a Tor controller such as
https://github.com/mikeperry-tor/vanguards that selects and
updates this set of nodes for you. Hence it does not do load
@@ -1645,14 +1637,6 @@ The following options are useful only for clients (that is, if
ExcludeNodes have higher priority than HSLayer3Nodes,
which means that nodes specified in ExcludeNodes will not be
picked.
- +
- When either this option or HSLayer2Nodes are set, the /16 subnet
- and node family restrictions are removed for hidden service
- circuits. Additionally, we allow the guard node to be present
- as the Rend, HSDir, and IP node, and as the hop before it. This
- is done to prevent the adversary from inferring information
- about our guard, layer2, and layer3 node choices at later points
- in the path.
+
This option is meant to be managed by a Tor controller such as
https://github.com/mikeperry-tor/vanguards that selects and
diff --git a/link_rust.sh.in b/link_rust.sh.in
deleted file mode 100644
index 59f4142baa..0000000000
--- a/link_rust.sh.in
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-#
-# A linker script used when building Rust tests. Autoconf makes link_rust.sh
-# from link_rust_sh.in, and uses it to pass extra options to the linker
-# when linking Rust stuff.
-#
-# We'd like to remove the need for this, but build.rs doesn't let us pass
-# -static-libasan and -static-libubsan to the linker.
-
-$CCLD @RUST_LINKER_OPTIONS@ "$@"
diff --git a/scripts/codegen/gen_server_ciphers.py b/scripts/codegen/gen_server_ciphers.py
index 5b2eef07ef..7ea39c540d 100755
--- a/scripts/codegen/gen_server_ciphers.py
+++ b/scripts/codegen/gen_server_ciphers.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-# Copyright 2014-2018, The Tor Project, Inc
+# Copyright 2014-2017, The Tor Project, Inc
# See LICENSE for licensing information
# This script parses openssl headers to find ciphersuite names, determines
diff --git a/scripts/codegen/get_mozilla_ciphers.py b/scripts/codegen/get_mozilla_ciphers.py
index 4f986daba9..946957ac77 100755
--- a/scripts/codegen/get_mozilla_ciphers.py
+++ b/scripts/codegen/get_mozilla_ciphers.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
# coding=utf-8
-# Copyright 2011-2018, The Tor Project, Inc
+# Copyright 2011-2017, The Tor Project, Inc
# original version by Arturo Filastò
# See LICENSE for licensing information
diff --git a/scripts/codegen/makedesc.py b/scripts/codegen/makedesc.py
index 4ee8106f03..8d9d4edaaf 100644
--- a/scripts/codegen/makedesc.py
+++ b/scripts/codegen/makedesc.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-# Copyright 2014-2018, The Tor Project, Inc.
+# Copyright 2014-2017, The Tor Project, Inc.
# See LICENSE for license information
# This is a kludgey python script that uses ctypes and openssl to sign
diff --git a/scripts/maint/checkIncludes.py b/scripts/maint/checkIncludes.py
deleted file mode 100755
index 3c611675e4..0000000000
--- a/scripts/maint/checkIncludes.py
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/usr/bin/python3
-# Copyright 2018 The Tor Project, Inc. See LICENSE file for licensing info.
-
-import fnmatch
-import os
-import re
-import sys
-
-trouble = False
-
-def err(msg):
- global trouble
- trouble = True
- print(msg, file=sys.stderr)
-
-def fname_is_c(fname):
- return fname.endswith(".h") or fname.endswith(".c")
-
-INCLUDE_PATTERN = re.compile(r'\s*#\s*include\s+"([^"]*)"')
-RULES_FNAME = ".may_include"
-
-class Rules(object):
- def __init__(self):
- self.patterns = []
-
- def addPattern(self, pattern):
- self.patterns.append(pattern)
-
- def includeOk(self, path):
- for pattern in self.patterns:
- if fnmatch.fnmatchcase(path, pattern):
- return True
- return False
-
- def applyToLines(self, lines, context=""):
- lineno = 0
- for line in lines:
- lineno += 1
- m = INCLUDE_PATTERN.match(line)
- if m:
- include = m.group(1)
- if not self.includeOk(include):
- err("Forbidden include of {} on line {}{}".format(
- include, lineno, context))
-
- def applyToFile(self, fname):
- with open(fname, 'r') as f:
- #print(fname)
- self.applyToLines(iter(f), " of {}".format(fname))
-
-def load_include_rules(fname):
- result = Rules()
- with open(fname, 'r') as f:
- for line in f:
- line = line.strip()
- if line.startswith("#") or not line:
- continue
- result.addPattern(line)
- return result
-
-for dirpath, dirnames, fnames in os.walk("src"):
- if ".may_include" in fnames:
- rules = load_include_rules(os.path.join(dirpath, RULES_FNAME))
- for fname in fnames:
- if fname_is_c(fname):
- rules.applyToFile(os.path.join(dirpath,fname))
-
-if trouble:
- err(
-"""To change which includes are allowed in a C file, edit the {} files in its
-enclosing directory.""".format(RULES_FNAME))
- sys.exit(1)
diff --git a/scripts/maint/checkSpace.pl b/scripts/maint/checkSpace.pl
index 633b47e314..9929932cc5 100755
--- a/scripts/maint/checkSpace.pl
+++ b/scripts/maint/checkSpace.pl
@@ -16,21 +16,12 @@ if ($ARGV[0] =~ /^-/) {
$C = ($lang eq '-C');
}
-our %basenames = ();
-
for my $fn (@ARGV) {
open(F, "$fn");
my $lastnil = 0;
my $lastline = "";
my $incomment = 0;
my $in_func_head = 0;
- my $basename = $fn;
- $basename =~ s#.*/##;
- if ($basenames{$basename}) {
- msg "Duplicate fnames: $fn and $basenames{$basename}.\n";
- } else {
- $basenames{$basename} = $fn;
- }
while (<F>) {
## Warn about windows-style newlines.
# (We insist on lines that end with a single LF character, not
@@ -135,7 +126,7 @@ for my $fn (@ARGV) {
## Warn about double semi-colons at the end of a line.
if (/;;$/) {
msg " double semi-colons at the end of $. in $fn\n"
- }
+ }
## Warn about multiple internal spaces.
#if (/[^\s,:]\s{2,}[^\s\\=]/) {
# msg " X X:$fn:$.\n";
@@ -201,6 +192,11 @@ for my $fn (@ARGV) {
}
}
}
+ ## Warn if the file doesn't end with a blank line.
+ # (End each file with a single blank line.)
+ if (! $lastnil) {
+ msg " EOL\@EOF:$fn:$.\n";
+ }
close(F);
}
diff --git a/scripts/maint/format_changelog.py b/scripts/maint/format_changelog.py
index 98fbbfb516..c5a0cfc81b 100755
--- a/scripts/maint/format_changelog.py
+++ b/scripts/maint/format_changelog.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-# Copyright (c) 2014-2018, The Tor Project, Inc.
+# Copyright (c) 2014-2017, The Tor Project, Inc.
# See LICENSE for licensing information
#
# This script reformats a section of the changelog to wrap everything to
diff --git a/scripts/maint/rectify_include_paths.py b/scripts/maint/rectify_include_paths.py
deleted file mode 100755
index 401fadae6d..0000000000
--- a/scripts/maint/rectify_include_paths.py
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/usr/bin/python3
-
-import os
-import os.path
-import re
-
-# Find all the include files, map them to their real names.
-
-def exclude(paths, dirnames):
- for p in paths:
- if p in dirnames:
- dirnames.remove(p)
-
-def get_include_map():
- includes = { }
-
- for dirpath,dirnames,fnames in os.walk("src"):
- exclude(["ext", "win32"], dirnames)
-
- for fname in fnames:
- if fname.endswith(".h"):
- assert fname not in includes
- include = os.path.join(dirpath, fname)
- assert include.startswith("src/")
- includes[fname] = include[4:]
-
- return includes
-
-INCLUDE_PAT = re.compile(r'( *# *include +")([^"]+)(".*)')
-
-def get_base_header_name(hdr):
- return os.path.split(hdr)[1]
-
-def fix_includes(inp, out, mapping):
- for line in inp:
- m = INCLUDE_PAT.match(line)
- if m:
- include,hdr,rest = m.groups()
- basehdr = get_base_header_name(hdr)
- if basehdr in mapping:
- out.write('{}{}{}\n'.format(include,mapping[basehdr],rest))
- continue
-
- out.write(line)
-
-incs = get_include_map()
-
-for dirpath,dirnames,fnames in os.walk("src"):
- exclude(["trunnel"], dirnames)
-
- for fname in fnames:
- if fname.endswith(".c") or fname.endswith(".h"):
- fname = os.path.join(dirpath, fname)
- tmpfile = fname+".tmp"
- f_in = open(fname, 'r')
- f_out = open(tmpfile, 'w')
- fix_includes(f_in, f_out, incs)
- f_in.close()
- f_out.close()
- os.rename(tmpfile, fname)
diff --git a/scripts/maint/redox.py b/scripts/maint/redox.py
index e8b2622ab9..53d3d902eb 100755
--- a/scripts/maint/redox.py
+++ b/scripts/maint/redox.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
-# Copyright (c) 2008-2018, The Tor Project, Inc.
+# Copyright (c) 2008-2017, The Tor Project, Inc.
# See LICENSE for licensing information.
#
# Hi!
diff --git a/scripts/maint/sortChanges.py b/scripts/maint/sortChanges.py
index c85e6563b8..22e40fd369 100755
--- a/scripts/maint/sortChanges.py
+++ b/scripts/maint/sortChanges.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-# Copyright (c) 2014-2018, The Tor Project, Inc.
+# Copyright (c) 2014-2017, The Tor Project, Inc.
# See LICENSE for licensing information
"""This script sorts a bunch of changes files listed on its command
diff --git a/scripts/maint/updateCopyright.pl b/scripts/maint/updateCopyright.pl
index bd24377d38..beb0b8f26e 100755
--- a/scripts/maint/updateCopyright.pl
+++ b/scripts/maint/updateCopyright.pl
@@ -1,7 +1,7 @@
#!/usr/bin/perl -i -w -p
-$NEWYEAR=2018;
+$NEWYEAR=2017;
-s/Copyright(.*) (201[^8]), The Tor Project/Copyright$1 $2-${NEWYEAR}, The Tor Project/;
+s/Copyright(.*) (201[^7]), The Tor Project/Copyright$1 $2-${NEWYEAR}, The Tor Project/;
s/Copyright(.*)-(20..), The Tor Project/Copyright$1-${NEWYEAR}, The Tor Project/;
diff --git a/scripts/test/appveyor-irc-notify.py b/scripts/test/appveyor-irc-notify.py
deleted file mode 100644
index 4ffea52684..0000000000
--- a/scripts/test/appveyor-irc-notify.py
+++ /dev/null
@@ -1,192 +0,0 @@
-# coding=utf8
-# Copyright (C) 2015-2016 Christopher R. Wood
-# Copyright (c) 2018 The Tor Project
-# Copyright (c) 2018 isis agora lovecruft
-#
-# From: https://raw.githubusercontent.com/gridsync/gridsync/def54f8166089b733d166665fdabcad4cdc526d8/misc/irc-notify.py
-# and: https://github.com/gridsync/gridsync
-#
-# Modified by nexB on October 2016:
-# - rework the handling of environment variables.
-# - made the script use functions
-# - support only Appveyor loading its environment variable to craft IRC notices.
-#
-# Modified by isis agora lovecruft <isis@torproject.org> in 2018:
-# - Make IRC server configurable.
-# - Make bot IRC nick deterministic.
-# - Make bot join the channel rather than sending NOTICE messages externally.
-# - Fix a bug which always caused sys.exit() to be logged as a traceback.
-# - Actually reset the IRC colour codes after printing.
-#
-# Modified by Marcin Cieślak in 2018:
-# - Accept UTF-8
-# - only guess github URLs
-# - stop using ANSI colors
-
-# This program is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software Foundation;
-# either version 2 of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with this
-# program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
-# Fifth Floor, Boston, MA 02110-1301 USA.
-
-"""Simple AppVeyor IRC notification script.
-
-The first argument is an IRC server and port; the second is the channel. Other
-arguments passed to the script will be sent as notice messages content and any
-{var}-formatted environment variables will be expanded automatically, replaced
-with a corresponding Appveyor environment variable value. Use commas to
-delineate multiple messages.
-
-
-Example:
-export APPVEYOR_URL=https://ci.appveyor.com
-export APPVEYOR_PROJECT_NAME=tor
-export APPVEYOR_REPO_COMMIT_AUTHOR=isislovecruft
-export APPVEYOR_REPO_COMMIT_TIMESTAMP=2018-04-23
-export APPVEYOR_REPO_PROVIDER=gihub
-export APPVEYOR_REPO_BRANCH=repo_branch
-export APPVEYOR_PULL_REQUEST_TITLE=pull_request_title
-export APPVEYOR_BUILD_VERSION=1
-export APPVEYOR_REPO_COMMIT=22c95b72e29248dc4de9b85e590ee18f6f587de8
-export APPVEYOR_REPO_COMMIT_MESSAGE="some IRC test"
-export APPVEYOR_ACCOUNT_NAME=isislovecruft
-export APPVEYOR_PULL_REQUEST_NUMBER=pull_request_number
-export APPVEYOR_REPO_NAME=isislovecruft/tor
-python ./appveyor-irc-notify.py irc.oftc.net:6697 tor-ci '{repo_name} {repo_branch} {short_commit} - {repo_commit_author}: {repo_commit_message}','Build #{build_version} passed. Details: {build_url} | Commit: {commit_url}
-
-See also https://github.com/gridsync/gridsync/blob/master/appveyor.yml for examples
-in Appveyor's YAML:
-
- on_success:
- - "python scripts/test/appveyor-irc-notify.py irc.oftc.net:6697 tor-ci success
- on_failure:
- - "python scripts/test/appveyor-irc-notify.py irc.oftc.net:6697 tor-ci failure
-"""
-
-from __future__ import print_function
-from __future__ import absolute_import
-
-import os
-import random
-import socket
-import ssl
-import sys
-import time
-
-
-def appveyor_vars():
- """
- Return a dict of key value carfted from appveyor environment variables.
- """
-
- vars = dict([
- (
- v.replace('APPVEYOR_', '').lower(),
- os.getenv(v, '').decode('utf-8')
- ) for v in [
- 'APPVEYOR_URL',
- 'APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED',
- 'APPVEYOR_REPO_BRANCH',
- 'APPVEYOR_REPO_COMMIT_AUTHOR',
- 'APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL',
- 'APPVEYOR_REPO_COMMIT_TIMESTAMP',
- 'APPVEYOR_REPO_PROVIDER',
- 'APPVEYOR_PROJECT_NAME',
- 'APPVEYOR_PULL_REQUEST_TITLE',
- 'APPVEYOR_BUILD_VERSION',
- 'APPVEYOR_REPO_COMMIT',
- 'APPVEYOR_REPO_COMMIT_MESSAGE',
- 'APPVEYOR_ACCOUNT_NAME',
- 'APPVEYOR_PULL_REQUEST_NUMBER',
- 'APPVEYOR_REPO_NAME'
- ]
- ])
-
- BUILD_FMT = u'{url}/project/{account_name}/{project_name}/build/{build_version}'
-
- if vars["repo_provider"] == 'github':
- COMMIT_FMT = u'https://{repo_provider}.com/{repo_name}/commit/{repo_commit}'
- vars.update(commit_url=COMMIT_FMT.format(**vars))
-
- vars.update(
- build_url=BUILD_FMT.format(**vars),
- short_commit=vars["repo_commit"][:7],
- )
- return vars
-
-
-def notify():
- """
- Send IRC notification
- """
- apvy_vars = appveyor_vars()
-
- server, port = sys.argv[1].rsplit(":", 1)
- channel = sys.argv[2]
- success = sys.argv[3] == "success"
- failure = sys.argv[3] == "failure"
-
- if success or failure:
- messages = []
- messages.append(u"{repo_name} {repo_branch} {short_commit} - {repo_commit_author}: {repo_commit_message}")
-
- if success:
- m = u"Build #{build_version} passed. Details: {build_url}"
- if failure:
- m = u"Build #{build_version} failed. Details: {build_url}"
-
- if "commit_url" in apvy_vars:
- m += " Commit: {commit_url}"
-
- messages.append(m)
- else:
- messages = sys.argv[3:]
- messages = ' '.join(messages)
- messages = messages.decode("utf-8").split(',')
-
- print(repr(apvy_vars))
- messages = [msg.format(**apvy_vars).strip() for msg in messages]
-
- irc_username = 'appveyor-ci'
- irc_nick = irc_username
-
- # establish connection
- irc_sock = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
- irc_sock.connect((socket.gethostbyname(server), int(port)))
- irc_sock.send('NICK {0}\r\nUSER {0} * 0 :{0}\r\n'.format(irc_username).encode())
- irc_sock.send('JOIN #{0}\r\n'.format(channel).encode())
- irc_file = irc_sock.makefile()
-
- while irc_file:
- line = irc_file.readline()
- print(line.rstrip())
- response = line.split()
-
- if response[0] == 'PING':
- irc_file.send('PONG {}\r\n'.format(response[1]).encode())
-
- elif response[1] == '433':
- irc_sock.send('NICK {}\r\n'.format(irc_nick).encode())
-
- elif response[1] == '001':
- time.sleep(5)
- # send notification
- for msg in messages:
- print(u'PRIVMSG #{} :{}'.format(channel, msg).encode("utf-8"))
- irc_sock.send(u'PRIVMSG #{} :{}\r\n'.format(channel, msg).encode("utf-8"))
- time.sleep(5)
- return
-
-
-if __name__ == '__main__':
- try:
- notify()
- except:
- import traceback
- print('ERROR: Failed to send notification: \n' + traceback.format_exc())
diff --git a/scripts/test/cov-diff b/scripts/test/cov-diff
index 6179dff63e..ed8874d2d3 100755
--- a/scripts/test/cov-diff
+++ b/scripts/test/cov-diff
@@ -10,12 +10,12 @@ DIRB="$2"
for B in $DIRB/*; do
A=$DIRA/`basename $B`
if [ -f $A ]; then
- perl -pe 's/^\s*\!*\d+(\*?):/ 1$1:/; s/^([^:]+:)[\d\s]+:/$1/; s/^ *-:(Runs|Programs):.*//;' "$A" > "$A.tmp"
+ perl -pe 's/^\s*\!*\d+:/ 1:/; s/^([^:]+:)[\d\s]+:/$1/; s/^ *-:(Runs|Programs):.*//;' "$A" > "$A.tmp"
else
cat /dev/null > "$A.tmp"
fi
- perl -pe 's/^\s*\!*\d+(\*?):/ 1$1:/; s/^([^:]+:)[\d\s]+:/$1/; s/^ *-:(Runs|Programs):.*//;' "$B" > "$B.tmp"
- diff -u "$A.tmp" "$B.tmp" |perl -pe 's/^((?:\+\+\+|---)(?:.*tmp))\s+.*/$1/;'
+ perl -pe 's/^\s*\!*\d+:/ 1:/; s/^([^:]+:)[\d\s]+:/$1/; s/^ *-:(Runs|Programs):.*//;' "$B" > "$B.tmp"
+ diff -u "$A.tmp" "$B.tmp"
rm "$A.tmp" "$B.tmp"
done
diff --git a/src/common/.may_include b/src/common/.may_include
deleted file mode 100644
index fab9ad0da8..0000000000
--- a/src/common/.may_include
+++ /dev/null
@@ -1,11 +0,0 @@
-orconfig.h
-common/*.h
-lib/*/*.h
-
-# XXXX These all belong somewhere else
-ht.h
-linux_syscalls.inc
-siphash.h
-src/ext/timeouts/timeout.c
-tor_queue.h
-tor_readpassphrase.h
diff --git a/src/common/address.c b/src/common/address.c
index 42052f85ec..a32df99107 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -35,14 +35,13 @@
#include <iphlpapi.h>
#endif /* defined(_WIN32) */
-#include "common/compat.h"
-#include "common/util.h"
-#include "common/util_format.h"
-#include "common/address.h"
-#include "lib/log/torlog.h"
-#include "lib/container/smartlist.h"
-#include "common/sandbox.h"
-#include "siphash.h"
+#include "compat.h"
+#include "util.h"
+#include "util_format.h"
+#include "address.h"
+#include "torlog.h"
+#include "container.h"
+#include "sandbox.h"
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
@@ -84,6 +83,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
/* tor_addr_is_null() and maybe other functions rely on AF_UNSPEC being 0 to
* work correctly. Bail out here if we've found a platform where AF_UNSPEC
@@ -2170,3 +2170,4 @@ tor_addr_port_eq(const tor_addr_port_t *a,
{
return tor_addr_eq(&a->addr, &b->addr) && a->port == b->port;
}
+
diff --git a/src/common/address.h b/src/common/address.h
index b95ee364ab..c9d9543dee 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -13,9 +13,9 @@
//#include <sys/sockio.h>
#include "orconfig.h"
-#include "lib/cc/torint.h"
-#include "common/compat.h"
-#include "lib/log/util_bug.h"
+#include "torint.h"
+#include "compat.h"
+#include "container.h"
#ifdef ADDRESS_PRIVATE
@@ -206,11 +206,10 @@ const char * fmt_addr32(uint32_t addr);
MOCK_DECL(int,get_interface_address6,(int severity, sa_family_t family,
tor_addr_t *addr));
-struct smartlist_t;
-void interface_address6_list_free_(struct smartlist_t * addrs);// XXXX
+void interface_address6_list_free_(smartlist_t * addrs);// XXXX
#define interface_address6_list_free(addrs) \
- FREE_AND_NULL(struct smartlist_t, interface_address6_list_free_, (addrs))
-MOCK_DECL(struct smartlist_t *,get_interface_address6_list,(int severity,
+ FREE_AND_NULL(smartlist_t, interface_address6_list_free_, (addrs))
+MOCK_DECL(smartlist_t *,get_interface_address6_list,(int severity,
sa_family_t family,
int include_internal));
@@ -336,7 +335,7 @@ MOCK_DECL(int,get_interface_address,(int severity, uint32_t *addr));
* Returns NULL on failure.
* Use free_interface_address_list to free the returned list.
*/
-static inline struct smartlist_t *
+static inline smartlist_t *
get_interface_address_list(int severity, int include_internal)
{
return get_interface_address6_list(severity, AF_INET, include_internal);
@@ -347,33 +346,34 @@ int tor_addr_port_eq(const tor_addr_port_t *a,
const tor_addr_port_t *b);
#ifdef ADDRESS_PRIVATE
-MOCK_DECL(struct smartlist_t *,get_interface_addresses_raw,(int severity,
+MOCK_DECL(smartlist_t *,get_interface_addresses_raw,(int severity,
sa_family_t family));
MOCK_DECL(int,get_interface_address6_via_udp_socket_hack,(int severity,
sa_family_t family,
tor_addr_t *addr));
#ifdef HAVE_IFADDRS_TO_SMARTLIST
-STATIC struct smartlist_t *ifaddrs_to_smartlist(const struct ifaddrs *ifa,
+STATIC smartlist_t *ifaddrs_to_smartlist(const struct ifaddrs *ifa,
sa_family_t family);
-STATIC struct smartlist_t *get_interface_addresses_ifaddrs(int severity,
+STATIC smartlist_t *get_interface_addresses_ifaddrs(int severity,
sa_family_t family);
#endif /* defined(HAVE_IFADDRS_TO_SMARTLIST) */
#ifdef HAVE_IP_ADAPTER_TO_SMARTLIST
-STATIC struct smartlist_t *ip_adapter_addresses_to_smartlist(
+STATIC smartlist_t *ip_adapter_addresses_to_smartlist(
const IP_ADAPTER_ADDRESSES *addresses);
-STATIC struct smartlist_t *get_interface_addresses_win32(int severity,
+STATIC smartlist_t *get_interface_addresses_win32(int severity,
sa_family_t family);
#endif /* defined(HAVE_IP_ADAPTER_TO_SMARTLIST) */
#ifdef HAVE_IFCONF_TO_SMARTLIST
-STATIC struct smartlist_t *ifreq_to_smartlist(char *ifr,
+STATIC smartlist_t *ifreq_to_smartlist(char *ifr,
size_t buflen);
-STATIC struct smartlist_t *get_interface_addresses_ioctl(int severity,
+STATIC smartlist_t *get_interface_addresses_ioctl(int severity,
sa_family_t family);
#endif /* defined(HAVE_IFCONF_TO_SMARTLIST) */
#endif /* defined(ADDRESS_PRIVATE) */
#endif /* !defined(TOR_ADDRESS_H) */
+
diff --git a/src/common/address_set.c b/src/common/address_set.c
index f4c5f581c8..b2f4bb4c95 100644
--- a/src/common/address_set.c
+++ b/src/common/address_set.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2018-2018, The Tor Project, Inc. */
+/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -11,12 +11,12 @@
**/
#include "orconfig.h"
-#include "common/address_set.h"
-#include "common/address.h"
-#include "common/compat.h"
-#include "lib/container/bitarray.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "common/util.h"
+#include "address_set.h"
+#include "address.h"
+#include "compat.h"
+#include "container.h"
+#include "crypto_rand.h"
+#include "util.h"
#include "siphash.h"
/** How many 64-bit siphash values to extract per address */
@@ -126,3 +126,4 @@ address_set_probably_contains(address_set_t *set,
}
return matches == N_BITS_PER_ITEM;
}
+
diff --git a/src/common/address_set.h b/src/common/address_set.h
index cfee89cfb8..28d29f3fdf 100644
--- a/src/common/address_set.h
+++ b/src/common/address_set.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2018-2018, The Tor Project, Inc. */
+/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -14,7 +14,7 @@
#define TOR_ADDRESS_SET_H
#include "orconfig.h"
-#include "lib/cc/torint.h"
+#include "torint.h"
/**
* An address_set_t represents a set of tor_addr_t values. The implementation
diff --git a/src/lib/crypt_ops/aes.c b/src/common/aes.c
index 3a66e369c9..a83a654348 100644
--- a/src/lib/crypt_ops/aes.c
+++ b/src/common/aes.c
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -16,9 +16,8 @@
#include <ws2tcpip.h>
#endif
-#include "lib/crypt_ops/compat_openssl.h"
#include <openssl/opensslv.h>
-#include "lib/crypt_ops/crypto_openssl_mgt.h"
+#include "crypto_openssl_mgt.h"
#if OPENSSL_VERSION_NUMBER < OPENSSL_V_SERIES(1,0,0)
#error "We require OpenSSL >= 1.0.0"
@@ -26,6 +25,7 @@
DISABLE_GCC_WARNING(redundant-decls)
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/aes.h>
@@ -35,11 +35,11 @@ DISABLE_GCC_WARNING(redundant-decls)
ENABLE_GCC_WARNING(redundant-decls)
-#include "common/compat.h"
-#include "lib/crypt_ops/aes.h"
-#include "common/util.h"
-#include "lib/log/torlog.h"
-#include "lib/ctime/di_ops.h"
+#include "compat.h"
+#include "aes.h"
+#include "util.h"
+#include "torlog.h"
+#include "di_ops.h"
#ifdef ANDROID
/* Android's OpenSSL seems to have removed all of its Engine support. */
@@ -115,7 +115,7 @@ aes_cipher_free_(aes_cnt_cipher_t *cipher_)
if (!cipher_)
return;
EVP_CIPHER_CTX *cipher = (EVP_CIPHER_CTX *) cipher_;
-#ifdef OPENSSL_1_1_API
+#if OPENSSL_VERSION_NUMBER >= OPENSSL_V_SERIES(1,1,0)
EVP_CIPHER_CTX_reset(cipher);
#else
EVP_CIPHER_CTX_cleanup(cipher);
diff --git a/src/lib/crypt_ops/aes.h b/src/common/aes.h
index e1287d330e..0b17cd55a4 100644
--- a/src/lib/crypt_ops/aes.h
+++ b/src/common/aes.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/* Implements a minimal interface to counter-mode AES. */
diff --git a/src/lib/err/backtrace.c b/src/common/backtrace.c
index cded6459f7..f2498b2aa6 100644
--- a/src/lib/err/backtrace.c
+++ b/src/common/backtrace.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2018, The Tor Project, Inc. */
+/* Copyright (c) 2013-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -14,7 +14,9 @@
*/
#include "orconfig.h"
-#include "lib/err/torerr.h"
+#include "compat.h"
+#include "util.h"
+#include "torlog.h"
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
@@ -28,9 +30,6 @@
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
#ifdef HAVE_CYGWIN_SIGNAL_H
#include <cygwin/signal.h>
@@ -40,13 +39,8 @@
#include <ucontext.h>
#endif /* defined(HAVE_CYGWIN_SIGNAL_H) || ... */
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-
#define EXPOSE_CLEAN_BACKTRACE
-#include "lib/err/backtrace.h"
-#include "lib/err/torerr.h"
+#include "backtrace.h"
#if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && \
defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_SIGACTION)
@@ -57,21 +51,17 @@
#define NO_BACKTRACE_IMPL
#endif
-// Redundant with util.h, but doing it here so we can avoid that dependency.
-#define raw_free free
-
-#ifdef USE_BACKTRACE
/** Version of Tor to report in backtrace messages. */
-static char bt_version[128] = "";
+static char *bt_version = NULL;
+#ifdef USE_BACKTRACE
/** Largest stack depth to try to dump. */
#define MAX_DEPTH 256
/** Static allocation of stack to dump. This is static so we avoid stack
* pressure. */
static void *cb_buf[MAX_DEPTH];
-/** Protects cb_buf from concurrent access. Pthreads, since this code
- * is Unix-only, and since this code needs to be lowest-level. */
-static pthread_mutex_t cb_buf_mutex = PTHREAD_MUTEX_INITIALIZER;
+/** Protects cb_buf from concurrent access */
+static tor_mutex_t cb_buf_mutex;
/** Change a stacktrace in <b>stack</b> of depth <b>depth</b> so that it will
* log the correct function from which a signal was received with context
@@ -104,35 +94,33 @@ clean_backtrace(void **stack, size_t depth, const ucontext_t *ctx)
}
/** Log a message <b>msg</b> at <b>severity</b> in <b>domain</b>, and follow
- * that with a backtrace log. Send messages via the tor_log function at
- * logger". */
+ * that with a backtrace log. */
void
-log_backtrace_impl(int severity, int domain, const char *msg,
- tor_log_fn logger)
+log_backtrace(int severity, int domain, const char *msg)
{
size_t depth;
char **symbols;
size_t i;
- pthread_mutex_lock(&cb_buf_mutex);
+ tor_mutex_acquire(&cb_buf_mutex);
depth = backtrace(cb_buf, MAX_DEPTH);
symbols = backtrace_symbols(cb_buf, (int)depth);
- logger(severity, domain, "%s. Stack trace:", msg);
+ tor_log(severity, domain, "%s. Stack trace:", msg);
if (!symbols) {
/* LCOV_EXCL_START -- we can't provoke this. */
- logger(severity, domain, " Unable to generate backtrace.");
+ tor_log(severity, domain, " Unable to generate backtrace.");
goto done;
/* LCOV_EXCL_STOP */
}
for (i=0; i < depth; ++i) {
- logger(severity, domain, " %s", symbols[i]);
+ tor_log(severity, domain, " %s", symbols[i]);
}
raw_free(symbols);
done:
- pthread_mutex_unlock(&cb_buf_mutex);
+ tor_mutex_release(&cb_buf_mutex);
}
static void crash_handler(int sig, siginfo_t *si, void *ctx_)
@@ -167,35 +155,19 @@ crash_handler(int sig, siginfo_t *si, void *ctx_)
abort();
}
-/** Write a backtrace to all of the emergency-error fds. */
-void
-dump_stack_symbols_to_error_fds(void)
-{
- int n_fds, i;
- const int *fds = NULL;
- size_t depth;
-
- depth = backtrace(cb_buf, MAX_DEPTH);
-
- n_fds = tor_log_get_sigsafe_err_fds(&fds);
- for (i=0; i < n_fds; ++i)
- backtrace_symbols_fd(cb_buf, (int)depth, fds[i]);
-}
-
/** Install signal handlers as needed so that when we crash, we produce a
- * useful stack trace. Return 0 on success, -errno on failure. */
+ * useful stack trace. Return 0 on success, -1 on failure. */
static int
-install_bt_handler(const char *software)
+install_bt_handler(void)
{
int trap_signals[] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS, SIGSYS,
SIGIO, -1 };
int i, rv=0;
- strncpy(bt_version, software, sizeof(bt_version) - 1);
- bt_version[sizeof(bt_version) - 1] = 0;
-
struct sigaction sa;
+ tor_mutex_init(&cb_buf_mutex);
+
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = crash_handler;
sa.sa_flags = SA_SIGINFO;
@@ -204,7 +176,8 @@ install_bt_handler(const char *software)
for (i = 0; trap_signals[i] >= 0; ++i) {
if (sigaction(trap_signals[i], &sa, NULL) == -1) {
/* LCOV_EXCL_START */
- rv = -errno;
+ log_warn(LD_BUG, "Sigaction failed: %s", strerror(errno));
+ rv = -1;
/* LCOV_EXCL_STOP */
}
}
@@ -227,21 +200,20 @@ install_bt_handler(const char *software)
static void
remove_bt_handler(void)
{
+ tor_mutex_uninit(&cb_buf_mutex);
}
#endif /* defined(USE_BACKTRACE) */
#ifdef NO_BACKTRACE_IMPL
void
-log_backtrace_impl(int severity, int domain, const char *msg,
- tor_log_fn logger)
+log_backtrace(int severity, int domain, const char *msg)
{
- logger(severity, domain, "%s. (Stack trace not available)", msg);
+ tor_log(severity, domain, "%s. (Stack trace not available)", msg);
}
static int
-install_bt_handler(const char *software)
+install_bt_handler(void)
{
- (void) software;
return 0;
}
@@ -249,28 +221,19 @@ static void
remove_bt_handler(void)
{
}
-
-void
-dump_stack_symbols_to_error_fds(void)
-{
-}
#endif /* defined(NO_BACKTRACE_IMPL) */
/** Set up code to handle generating error messages on crashes. */
int
configure_backtrace_handler(const char *tor_version)
{
- char version[128];
- strncpy(version, "Tor", sizeof(version)-1);
-
- if (tor_version) {
- strncat(version, " ", sizeof(version)-1);
- strncat(version, tor_version, sizeof(version)-1);
- }
+ tor_free(bt_version);
+ if (tor_version)
+ tor_asprintf(&bt_version, "Tor %s", tor_version);
+ else
+ tor_asprintf(&bt_version, "Tor");
- version[sizeof(version) - 1] = 0;
-
- return install_bt_handler(version);
+ return install_bt_handler();
}
/** Perform end-of-process cleanup for code that generates error messages on
@@ -279,4 +242,7 @@ void
clean_up_backtrace_handler(void)
{
remove_bt_handler();
+
+ tor_free(bt_version);
}
+
diff --git a/src/lib/err/backtrace.h b/src/common/backtrace.h
index 7f77428436..3d0ab8a90a 100644
--- a/src/lib/err/backtrace.h
+++ b/src/common/backtrace.h
@@ -1,23 +1,14 @@
-/* Copyright (c) 2013-2018, The Tor Project, Inc. */
+/* Copyright (c) 2013-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_BACKTRACE_H
#define TOR_BACKTRACE_H
#include "orconfig.h"
-#include "lib/cc/compat_compiler.h"
-typedef void (*tor_log_fn)(int, unsigned, const char *fmt, ...)
- CHECK_PRINTF(3,4);
-
-void log_backtrace_impl(int severity, int domain, const char *msg,
- tor_log_fn logger);
+void log_backtrace(int severity, int domain, const char *msg);
int configure_backtrace_handler(const char *tor_version);
void clean_up_backtrace_handler(void);
-void dump_stack_symbols_to_error_fds(void);
-
-#define log_backtrace(sev, dom, msg) \
- log_backtrace_impl((sev), (dom), (msg), tor_log)
#ifdef EXPOSE_CLEAN_BACKTRACE
#if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && \
@@ -27,3 +18,4 @@ void clean_backtrace(void **stack, size_t depth, const ucontext_t *ctx);
#endif /* defined(EXPOSE_CLEAN_BACKTRACE) */
#endif /* !defined(TOR_BACKTRACE_H) */
+
diff --git a/src/common/buffers.c b/src/common/buffers.c
index 4e5f56c733..a01add9bef 100644
--- a/src/common/buffers.c
+++ b/src/common/buffers.c
@@ -1,7 +1,7 @@
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -21,12 +21,12 @@
#define BUFFERS_PRIVATE
#include "orconfig.h"
#include <stddef.h>
-#include "common/buffers.h"
-#include "common/compat.h"
-#include "lib/compress/compress.h"
-#include "common/util.h"
-#include "lib/cc/torint.h"
-#include "lib/log/torlog.h"
+#include "buffers.h"
+#include "compat.h"
+#include "compress.h"
+#include "util.h"
+#include "torint.h"
+#include "torlog.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
diff --git a/src/common/buffers.h b/src/common/buffers.h
index 80103af776..4275152de2 100644
--- a/src/common/buffers.h
+++ b/src/common/buffers.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -12,9 +12,9 @@
#ifndef TOR_BUFFERS_H
#define TOR_BUFFERS_H
-#include "common/compat.h"
-#include "lib/cc/torint.h"
-#include "lib/testsupport/testsupport.h"
+#include "compat.h"
+#include "torint.h"
+#include "testsupport.h"
typedef struct buf_t buf_t;
diff --git a/src/lib/tls/buffers_tls.c b/src/common/buffers_tls.c
index ac78b6501b..041f78b818 100644
--- a/src/lib/tls/buffers_tls.c
+++ b/src/common/buffers_tls.c
@@ -1,19 +1,20 @@
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#define BUFFERS_PRIVATE
#include "orconfig.h"
#include <stddef.h>
-#include "common/buffers.h"
-#include "lib/tls/buffers_tls.h"
-#include "common/compat.h"
-#include "common/util.h"
-#include "lib/cc/torint.h"
-#include "lib/log/torlog.h"
-#include "lib/tls/tortls.h"
+#include "buffers.h"
+#include "buffers_tls.h"
+#include "compat.h"
+#include "compress.h"
+#include "util.h"
+#include "torint.h"
+#include "torlog.h"
+#include "tortls.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -175,3 +176,4 @@ buf_flush_to_tls(buf_t *buf, tor_tls_t *tls, size_t flushlen,
tor_assert(flushed < INT_MAX);
return (int)flushed;
}
+
diff --git a/src/lib/tls/buffers_tls.h b/src/common/buffers_tls.h
index d9d26c82bd..2f9fda45a0 100644
--- a/src/lib/tls/buffers_tls.h
+++ b/src/common/buffers_tls.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_BUFFERS_TLS_H
diff --git a/src/lib/tls/ciphers.inc b/src/common/ciphers.inc
index 0084b3e325..0084b3e325 100644
--- a/src/lib/tls/ciphers.inc
+++ b/src/common/ciphers.inc
diff --git a/src/common/compat.c b/src/common/compat.c
index 8e418f4c1d..6fdd6ecf00 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -13,7 +13,7 @@
**/
#define COMPAT_PRIVATE
-#include "common/compat.h"
+#include "compat.h"
#ifdef _WIN32
#include <winsock2.h>
@@ -111,6 +111,7 @@ SecureZeroMemory(PVOID ptr, SIZE_T cnt)
#endif
#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
@@ -124,12 +125,19 @@ SecureZeroMemory(PVOID ptr, SIZE_T cnt)
#include <sys/file.h>
#endif
-#include "lib/log/torlog.h"
-#include "common/util.h"
-#include "lib/container/smartlist.h"
-#include "lib/wallclock/tm_cvt.h"
-#include "common/address.h"
-#include "common/sandbox.h"
+#include "torlog.h"
+#include "util.h"
+#include "container.h"
+#include "address.h"
+#include "sandbox.h"
+
+/* Inline the strl functions if the platform doesn't have them. */
+#ifndef HAVE_STRLCPY
+#include "strlcpy.c"
+#endif
+#ifndef HAVE_STRLCAT
+#include "strlcat.c"
+#endif
/* When set_max_file_descriptors() is called, update this with the max file
* descriptor value so we can use it to check the limit when opening a new
@@ -397,6 +405,147 @@ tor_munmap_file(tor_mmap_t *handle)
#error "cannot implement tor_mmap_file"
#endif /* defined(HAVE_MMAP) || ... || ... */
+/** Replacement for snprintf. Differs from platform snprintf in two
+ * ways: First, always NUL-terminates its output. Second, always
+ * returns -1 if the result is truncated. (Note that this return
+ * behavior does <i>not</i> conform to C99; it just happens to be
+ * easier to emulate "return -1" with conformant implementations than
+ * it is to emulate "return number that would be written" with
+ * non-conformant implementations.) */
+int
+tor_snprintf(char *str, size_t size, const char *format, ...)
+{
+ va_list ap;
+ int r;
+ va_start(ap,format);
+ r = tor_vsnprintf(str,size,format,ap);
+ va_end(ap);
+ return r;
+}
+
+/** Replacement for vsnprintf; behavior differs as tor_snprintf differs from
+ * snprintf.
+ */
+int
+tor_vsnprintf(char *str, size_t size, const char *format, va_list args)
+{
+ int r;
+ if (size == 0)
+ return -1; /* no place for the NUL */
+ if (size > SIZE_T_CEILING)
+ return -1;
+#ifdef _WIN32
+ r = _vsnprintf(str, size, format, args);
+#else
+ r = vsnprintf(str, size, format, args);
+#endif
+ str[size-1] = '\0';
+ if (r < 0 || r >= (ssize_t)size)
+ return -1;
+ return r;
+}
+
+/**
+ * Portable asprintf implementation. Does a printf() into a newly malloc'd
+ * string. Sets *<b>strp</b> to this string, and returns its length (not
+ * including the terminating NUL character).
+ *
+ * You can treat this function as if its implementation were something like
+ <pre>
+ char buf[_INFINITY_];
+ tor_snprintf(buf, sizeof(buf), fmt, args);
+ *strp = tor_strdup(buf);
+ return strlen(*strp):
+ </pre>
+ * Where _INFINITY_ is an imaginary constant so big that any string can fit
+ * into it.
+ */
+int
+tor_asprintf(char **strp, const char *fmt, ...)
+{
+ int r;
+ va_list args;
+ va_start(args, fmt);
+ r = tor_vasprintf(strp, fmt, args);
+ va_end(args);
+ if (!*strp || r < 0) {
+ /* LCOV_EXCL_START */
+ log_err(LD_BUG, "Internal error in asprintf");
+ tor_assert(0);
+ /* LCOV_EXCL_STOP */
+ }
+ return r;
+}
+
+/**
+ * Portable vasprintf implementation. Does a printf() into a newly malloc'd
+ * string. Differs from regular vasprintf in the same ways that
+ * tor_asprintf() differs from regular asprintf.
+ */
+int
+tor_vasprintf(char **strp, const char *fmt, va_list args)
+{
+ /* use a temporary variable in case *strp is in args. */
+ char *strp_tmp=NULL;
+#ifdef HAVE_VASPRINTF
+ /* If the platform gives us one, use it. */
+ int r = vasprintf(&strp_tmp, fmt, args);
+ if (r < 0)
+ *strp = NULL;
+ else
+ *strp = strp_tmp;
+ return r;
+#elif defined(HAVE__VSCPRINTF)
+ /* On Windows, _vsnprintf won't tell us the length of the string if it
+ * overflows, so we need to use _vcsprintf to tell how much to allocate */
+ int len, r;
+ va_list tmp_args;
+ va_copy(tmp_args, args);
+ len = _vscprintf(fmt, tmp_args);
+ va_end(tmp_args);
+ if (len < 0) {
+ *strp = NULL;
+ return -1;
+ }
+ strp_tmp = tor_malloc(len + 1);
+ r = _vsnprintf(strp_tmp, len+1, fmt, args);
+ if (r != len) {
+ tor_free(strp_tmp);
+ *strp = NULL;
+ return -1;
+ }
+ *strp = strp_tmp;
+ return len;
+#else
+ /* Everywhere else, we have a decent vsnprintf that tells us how many
+ * characters we need. We give it a try on a short buffer first, since
+ * it might be nice to avoid the second vsnprintf call.
+ */
+ char buf[128];
+ int len, r;
+ va_list tmp_args;
+ va_copy(tmp_args, args);
+ /* vsnprintf() was properly checked but tor_vsnprintf() available so
+ * why not use it? */
+ len = tor_vsnprintf(buf, sizeof(buf), fmt, tmp_args);
+ va_end(tmp_args);
+ if (len < (int)sizeof(buf)) {
+ *strp = tor_strdup(buf);
+ return len;
+ }
+ strp_tmp = tor_malloc(len+1);
+ /* use of tor_vsnprintf() will ensure string is null terminated */
+ r = tor_vsnprintf(strp_tmp, len+1, fmt, args);
+ if (r != len) {
+ tor_free(strp_tmp);
+ *strp = NULL;
+ return -1;
+ }
+ *strp = strp_tmp;
+ return len;
+#endif /* defined(HAVE_VASPRINTF) || ... */
+}
+
/** Given <b>hlen</b> bytes at <b>haystack</b> and <b>nlen</b> bytes at
* <b>needle</b>, return a pointer to the first occurrence of the needle
* within the haystack, or NULL if there is no such occurrence.
@@ -443,6 +592,67 @@ tor_memmem(const void *_haystack, size_t hlen,
#endif /* defined(HAVE_MEMMEM) && (!defined(__GNUC__) || __GNUC__ >= 2) */
}
+/**
+ * Tables to implement ctypes-replacement TOR_IS*() functions. Each table
+ * has 256 bits to look up whether a character is in some set or not. This
+ * fails on non-ASCII platforms, but it is hard to find a platform whose
+ * character set is not a superset of ASCII nowadays. */
+
+/**@{*/
+const uint32_t TOR_ISALPHA_TABLE[8] =
+ { 0, 0, 0x7fffffe, 0x7fffffe, 0, 0, 0, 0 };
+const uint32_t TOR_ISALNUM_TABLE[8] =
+ { 0, 0x3ff0000, 0x7fffffe, 0x7fffffe, 0, 0, 0, 0 };
+const uint32_t TOR_ISSPACE_TABLE[8] = { 0x3e00, 0x1, 0, 0, 0, 0, 0, 0 };
+const uint32_t TOR_ISXDIGIT_TABLE[8] =
+ { 0, 0x3ff0000, 0x7e, 0x7e, 0, 0, 0, 0 };
+const uint32_t TOR_ISDIGIT_TABLE[8] = { 0, 0x3ff0000, 0, 0, 0, 0, 0, 0 };
+const uint32_t TOR_ISPRINT_TABLE[8] =
+ { 0, 0xffffffff, 0xffffffff, 0x7fffffff, 0, 0, 0, 0x0 };
+const uint32_t TOR_ISUPPER_TABLE[8] = { 0, 0, 0x7fffffe, 0, 0, 0, 0, 0 };
+const uint32_t TOR_ISLOWER_TABLE[8] = { 0, 0, 0, 0x7fffffe, 0, 0, 0, 0 };
+
+/** Upper-casing and lowercasing tables to map characters to upper/lowercase
+ * equivalents. Used by tor_toupper() and tor_tolower(). */
+/**@{*/
+const uint8_t TOR_TOUPPER_TABLE[256] = {
+ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
+ 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
+ 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
+ 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
+ 96,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
+ 80,81,82,83,84,85,86,87,88,89,90,123,124,125,126,127,
+ 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
+ 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
+ 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
+ 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
+ 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
+ 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
+ 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
+ 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
+};
+const uint8_t TOR_TOLOWER_TABLE[256] = {
+ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
+ 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
+ 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+ 64,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
+ 112,113,114,115,116,117,118,119,120,121,122,91,92,93,94,95,
+ 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
+ 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
+ 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
+ 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
+ 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
+ 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
+ 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
+ 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
+ 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
+ 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
+};
+/**@}*/
+
/** Helper for tor_strtok_r_impl: Advances cp past all characters in
* <b>sep</b>, and returns its new value. */
static char *
@@ -493,6 +703,32 @@ tor_strtok_r_impl(char *str, const char *sep, char **lasts)
return start;
}
+#ifdef _WIN32
+/** Take a filename and return a pointer to its final element. This
+ * function is called on __FILE__ to fix a MSVC nit where __FILE__
+ * contains the full path to the file. This is bad, because it
+ * confuses users to find the home directory of the person who
+ * compiled the binary in their warning messages.
+ */
+const char *
+tor_fix_source_file(const char *fname)
+{
+ const char *cp1, *cp2, *r;
+ cp1 = strrchr(fname, '/');
+ cp2 = strrchr(fname, '\\');
+ if (cp1 && cp2) {
+ r = (cp1<cp2)?(cp2+1):(cp1+1);
+ } else if (cp1) {
+ r = cp1+1;
+ } else if (cp2) {
+ r = cp2+1;
+ } else {
+ r = fname;
+ }
+ return r;
+}
+#endif /* defined(_WIN32) */
+
/**
* Read a 16-bit value beginning at <b>cp</b>. Equivalent to
* *(uint16_t*)(cp), but will not cause segfaults on platforms that forbid
@@ -707,6 +943,80 @@ tor_lockfile_unlock(tor_lockfile_t *lockfile)
tor_free(lockfile);
}
+/** @{ */
+/** Some old versions of Unix didn't define constants for these values,
+ * and instead expect you to say 0, 1, or 2. */
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#endif
+#ifndef SEEK_CUR
+#define SEEK_CUR 1
+#endif
+#ifndef SEEK_END
+#define SEEK_END 2
+#endif
+/** @} */
+
+/** Return the position of <b>fd</b> with respect to the start of the file. */
+off_t
+tor_fd_getpos(int fd)
+{
+#ifdef _WIN32
+ return (off_t) _lseek(fd, 0, SEEK_CUR);
+#else
+ return (off_t) lseek(fd, 0, SEEK_CUR);
+#endif
+}
+
+/** Move <b>fd</b> to the end of the file. Return -1 on error, 0 on success.
+ * If the file is a pipe, do nothing and succeed.
+ **/
+int
+tor_fd_seekend(int fd)
+{
+#ifdef _WIN32
+ return _lseek(fd, 0, SEEK_END) < 0 ? -1 : 0;
+#else
+ off_t rc = lseek(fd, 0, SEEK_END) < 0 ? -1 : 0;
+#ifdef ESPIPE
+ /* If we get an error and ESPIPE, then it's a pipe or a socket of a fifo:
+ * no need to worry. */
+ if (rc < 0 && errno == ESPIPE)
+ rc = 0;
+#endif /* defined(ESPIPE) */
+ return (rc < 0) ? -1 : 0;
+#endif /* defined(_WIN32) */
+}
+
+/** Move <b>fd</b> to position <b>pos</b> in the file. Return -1 on error, 0
+ * on success. */
+int
+tor_fd_setpos(int fd, off_t pos)
+{
+#ifdef _WIN32
+ return _lseek(fd, pos, SEEK_SET) < 0 ? -1 : 0;
+#else
+ return lseek(fd, pos, SEEK_SET) < 0 ? -1 : 0;
+#endif
+}
+
+/** Replacement for ftruncate(fd, 0): move to the front of the file and remove
+ * all the rest of the file. Return -1 on error, 0 on success. */
+int
+tor_ftruncate(int fd)
+{
+ /* Rumor has it that some versions of ftruncate do not move the file pointer.
+ */
+ if (tor_fd_setpos(fd, 0) < 0)
+ return -1;
+
+#ifdef _WIN32
+ return _chsize(fd, 0);
+#else
+ return ftruncate(fd, 0);
+#endif
+}
+
#undef DEBUG_SOCKET_COUNTING
#ifdef DEBUG_SOCKET_COUNTING
/** A bitarray of all fds that should be passed to tor_socket_close(). Only
@@ -2541,39 +2851,183 @@ compute_num_cpus(void)
return num_cpus;
}
+#if !defined(_WIN32)
+/** Defined iff we need to add locks when defining fake versions of reentrant
+ * versions of time-related functions. */
+#define TIME_FNS_NEED_LOCKS
+#endif
+
+/** Helper: Deal with confused or out-of-bounds values from localtime_r and
+ * friends. (On some platforms, they can give out-of-bounds values or can
+ * return NULL.) If <b>islocal</b>, this is a localtime result; otherwise
+ * it's from gmtime. The function returns <b>r</b>, when given <b>timep</b>
+ * as its input. If we need to store new results, store them in
+ * <b>resultbuf</b>. */
+static struct tm *
+correct_tm(int islocal, const time_t *timep, struct tm *resultbuf,
+ struct tm *r)
+{
+ const char *outcome;
+
+ if (PREDICT_LIKELY(r)) {
+ /* We can't strftime dates after 9999 CE, and we want to avoid dates
+ * before 1 CE (avoiding the year 0 issue and negative years). */
+ if (r->tm_year > 8099) {
+ r->tm_year = 8099;
+ r->tm_mon = 11;
+ r->tm_mday = 31;
+ r->tm_yday = 364;
+ r->tm_wday = 6;
+ r->tm_hour = 23;
+ r->tm_min = 59;
+ r->tm_sec = 59;
+ } else if (r->tm_year < (1-1900)) {
+ r->tm_year = (1-1900);
+ r->tm_mon = 0;
+ r->tm_mday = 1;
+ r->tm_yday = 0;
+ r->tm_wday = 0;
+ r->tm_hour = 0;
+ r->tm_min = 0;
+ r->tm_sec = 0;
+ }
+ return r;
+ }
+
+ /* If we get here, gmtime or localtime returned NULL. It might have done
+ * this because of overrun or underrun, or it might have done it because of
+ * some other weird issue. */
+ if (timep) {
+ if (*timep < 0) {
+ r = resultbuf;
+ r->tm_year = 70; /* 1970 CE */
+ r->tm_mon = 0;
+ r->tm_mday = 1;
+ r->tm_yday = 0;
+ r->tm_wday = 0;
+ r->tm_hour = 0;
+ r->tm_min = 0 ;
+ r->tm_sec = 0;
+ outcome = "Rounding up to 1970";
+ goto done;
+ } else if (*timep >= INT32_MAX) {
+ /* Rounding down to INT32_MAX isn't so great, but keep in mind that we
+ * only do it if gmtime/localtime tells us NULL. */
+ r = resultbuf;
+ r->tm_year = 137; /* 2037 CE */
+ r->tm_mon = 11;
+ r->tm_mday = 31;
+ r->tm_yday = 364;
+ r->tm_wday = 6;
+ r->tm_hour = 23;
+ r->tm_min = 59;
+ r->tm_sec = 59;
+ outcome = "Rounding down to 2037";
+ goto done;
+ }
+ }
+
+ /* If we get here, then gmtime/localtime failed without getting an extreme
+ * value for *timep */
+ /* LCOV_EXCL_START */
+ tor_fragile_assert();
+ r = resultbuf;
+ memset(resultbuf, 0, sizeof(struct tm));
+ outcome="can't recover";
+ /* LCOV_EXCL_STOP */
+ done:
+ log_warn(LD_BUG, "%s("I64_FORMAT") failed with error %s: %s",
+ islocal?"localtime":"gmtime",
+ timep?I64_PRINTF_ARG(*timep):0,
+ strerror(errno),
+ outcome);
+ return r;
+}
+
+/** @{ */
/** As localtime_r, but defined for platforms that don't have it:
*
* Convert *<b>timep</b> to a struct tm in local time, and store the value in
* *<b>result</b>. Return the result on success, or NULL on failure.
*/
+#ifdef HAVE_LOCALTIME_R
struct tm *
tor_localtime_r(const time_t *timep, struct tm *result)
{
- char *err = NULL;
- struct tm *r = tor_localtime_r_msg(timep, result, &err);
- if (err) {
- log_warn(LD_BUG, "%s", err);
- tor_free(err);
- }
- return r;
+ struct tm *r;
+ r = localtime_r(timep, result);
+ return correct_tm(1, timep, result, r);
+}
+#elif defined(TIME_FNS_NEED_LOCKS)
+struct tm *
+tor_localtime_r(const time_t *timep, struct tm *result)
+{
+ struct tm *r;
+ static tor_mutex_t *m=NULL;
+ if (!m) { m=tor_mutex_new(); }
+ tor_assert(result);
+ tor_mutex_acquire(m);
+ r = localtime(timep);
+ if (r)
+ memcpy(result, r, sizeof(struct tm));
+ tor_mutex_release(m);
+ return correct_tm(1, timep, result, r);
+}
+#else
+struct tm *
+tor_localtime_r(const time_t *timep, struct tm *result)
+{
+ struct tm *r;
+ tor_assert(result);
+ r = localtime(timep);
+ if (r)
+ memcpy(result, r, sizeof(struct tm));
+ return correct_tm(1, timep, result, r);
}
+#endif /* defined(HAVE_LOCALTIME_R) || ... */
+/** @} */
+/** @{ */
/** As gmtime_r, but defined for platforms that don't have it:
*
* Convert *<b>timep</b> to a struct tm in UTC, and store the value in
* *<b>result</b>. Return the result on success, or NULL on failure.
*/
+#ifdef HAVE_GMTIME_R
struct tm *
tor_gmtime_r(const time_t *timep, struct tm *result)
{
- char *err = NULL;
- struct tm *r = tor_gmtime_r_msg(timep, result, &err);
- if (err) {
- log_warn(LD_BUG, "%s", err);
- tor_free(err);
- }
- return r;
+ struct tm *r;
+ r = gmtime_r(timep, result);
+ return correct_tm(0, timep, result, r);
}
+#elif defined(TIME_FNS_NEED_LOCKS)
+struct tm *
+tor_gmtime_r(const time_t *timep, struct tm *result)
+{
+ struct tm *r;
+ static tor_mutex_t *m=NULL;
+ if (!m) { m=tor_mutex_new(); }
+ tor_assert(result);
+ tor_mutex_acquire(m);
+ r = gmtime(timep);
+ if (r)
+ memcpy(result, r, sizeof(struct tm));
+ tor_mutex_release(m);
+ return correct_tm(0, timep, result, r);
+}
+#else
+struct tm *
+tor_gmtime_r(const time_t *timep, struct tm *result)
+{
+ struct tm *r;
+ tor_assert(result);
+ r = gmtime(timep);
+ if (r)
+ memcpy(result, r, sizeof(struct tm));
+ return correct_tm(0, timep, result, r);
+}
+#endif /* defined(HAVE_GMTIME_R) || ... */
#if defined(HAVE_MLOCKALL) && HAVE_DECL_MLOCKALL && defined(RLIMIT_MEMLOCK)
#define HAVE_UNIX_MLOCKALL
@@ -3074,3 +3528,4 @@ tor_get_avail_disk_space(const char *path)
return -1;
#endif /* defined(HAVE_STATVFS) || ... */
}
+
diff --git a/src/common/compat.h b/src/common/compat.h
index 691824a2e7..c7e7f8d9ef 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_COMPAT_H
@@ -14,8 +14,8 @@
#define SIO_IDEAL_SEND_BACKLOG_QUERY 0x4004747b
#endif
#endif
-#include "lib/cc/torint.h"
-#include "lib/testsupport/testsupport.h"
+#include "torint.h"
+#include "testsupport.h"
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
@@ -45,17 +45,272 @@
#include <netinet6/in6.h>
#endif
-#include "lib/cc/compat_compiler.h"
-#include "common/compat_time.h"
-#include "lib/string/compat_ctype.h"
-#include "lib/string/compat_string.h"
-#include "lib/string/printf.h"
+#include "compat_time.h"
+
+#if defined(__has_feature)
+# if __has_feature(address_sanitizer)
+/* Some of the fancy glibc strcmp() macros include references to memory that
+ * clang rejects because it is off the end of a less-than-3. Clang hates this,
+ * even though those references never actually happen. */
+# undef strcmp
+#endif /* __has_feature(address_sanitizer) */
+#endif /* defined(__has_feature) */
#include <stdio.h>
#include <errno.h>
+#ifndef NULL_REP_IS_ZERO_BYTES
+#error "It seems your platform does not represent NULL as zero. We can't cope."
+#endif
+
+#ifndef DOUBLE_0_REP_IS_ZERO_BYTES
+#error "It seems your platform does not represent 0.0 as zeros. We can't cope."
+#endif
+
+#if 'a'!=97 || 'z'!=122 || 'A'!=65 || ' '!=32
+#error "It seems that you encode characters in something other than ASCII."
+#endif
+
/* ===== Compiler compatibility */
+/* GCC can check printf and scanf types on arbitrary functions. */
+#ifdef __GNUC__
+#define CHECK_PRINTF(formatIdx, firstArg) \
+ __attribute__ ((format(printf, formatIdx, firstArg)))
+#else
+#define CHECK_PRINTF(formatIdx, firstArg)
+#endif /* defined(__GNUC__) */
+#ifdef __GNUC__
+#define CHECK_SCANF(formatIdx, firstArg) \
+ __attribute__ ((format(scanf, formatIdx, firstArg)))
+#else
+#define CHECK_SCANF(formatIdx, firstArg)
+#endif /* defined(__GNUC__) */
+
+/* What GCC do we have? */
+#ifdef __GNUC__
+#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
+#else
+#define GCC_VERSION 0
+#endif
+
+/* Temporarily enable and disable warnings. */
+#ifdef __GNUC__
+# define PRAGMA_STRINGIFY_(s) #s
+# define PRAGMA_JOIN_STRINGIFY_(a,b) PRAGMA_STRINGIFY_(a ## b)
+/* Support for macro-generated pragmas (c99) */
+# define PRAGMA_(x) _Pragma (#x)
+# ifdef __clang__
+# define PRAGMA_DIAGNOSTIC_(x) PRAGMA_(clang diagnostic x)
+# else
+# define PRAGMA_DIAGNOSTIC_(x) PRAGMA_(GCC diagnostic x)
+# endif
+# if defined(__clang__) || GCC_VERSION >= 406
+/* we have push/pop support */
+# define DISABLE_GCC_WARNING(warningopt) \
+ PRAGMA_DIAGNOSTIC_(push) \
+ PRAGMA_DIAGNOSTIC_(ignored PRAGMA_JOIN_STRINGIFY_(-W,warningopt))
+# define ENABLE_GCC_WARNING(warningopt) \
+ PRAGMA_DIAGNOSTIC_(pop)
+#else /* !(defined(__clang__) || GCC_VERSION >= 406) */
+/* older version of gcc: no push/pop support. */
+# define DISABLE_GCC_WARNING(warningopt) \
+ PRAGMA_DIAGNOSTIC_(ignored PRAGMA_JOIN_STRINGIFY_(-W,warningopt))
+# define ENABLE_GCC_WARNING(warningopt) \
+ PRAGMA_DIAGNOSTIC_(warning PRAGMA_JOIN_STRINGIFY_(-W,warningopt))
+#endif /* defined(__clang__) || GCC_VERSION >= 406 */
+#else /* !(defined(__GNUC__)) */
+/* not gcc at all */
+# define DISABLE_GCC_WARNING(warning)
+# define ENABLE_GCC_WARNING(warning)
+#endif /* defined(__GNUC__) */
+
+/* inline is __inline on windows. */
+#ifdef _WIN32
+#define inline __inline
+#endif
+
+/* Try to get a reasonable __func__ substitute in place. */
+#if defined(_MSC_VER)
+
+#define __func__ __FUNCTION__
+
+#else
+/* For platforms where autoconf works, make sure __func__ is defined
+ * sanely. */
+#ifndef HAVE_MACRO__func__
+#ifdef HAVE_MACRO__FUNCTION__
+#define __func__ __FUNCTION__
+#elif HAVE_MACRO__FUNC__
+#define __func__ __FUNC__
+#else
+#define __func__ "???"
+#endif /* defined(HAVE_MACRO__FUNCTION__) || ... */
+#endif /* !defined(HAVE_MACRO__func__) */
+#endif /* defined(_MSC_VER) */
+
+#define U64_TO_DBL(x) ((double) (x))
+#define DBL_TO_U64(x) ((uint64_t) (x))
+
+#ifdef ENUM_VALS_ARE_SIGNED
+#define ENUM_BF(t) unsigned
+#else
+/** Wrapper for having a bitfield of an enumerated type. Where possible, we
+ * just use the enumerated type (so the compiler can help us and notice
+ * problems), but if enumerated types are unsigned, we must use unsigned,
+ * so that the loss of precision doesn't make large values negative. */
+#define ENUM_BF(t) t
+#endif /* defined(ENUM_VALS_ARE_SIGNED) */
+
+/* GCC has several useful attributes. */
+#if defined(__GNUC__) && __GNUC__ >= 3
+#define ATTR_NORETURN __attribute__((noreturn))
+#define ATTR_CONST __attribute__((const))
+#define ATTR_MALLOC __attribute__((malloc))
+#define ATTR_NORETURN __attribute__((noreturn))
+#define ATTR_WUR __attribute__((warn_unused_result))
+/* Alas, nonnull is not at present a good idea for us. We'd like to get
+ * warnings when we pass NULL where we shouldn't (which nonnull does, albeit
+ * spottily), but we don't want to tell the compiler to make optimizations
+ * with the assumption that the argument can't be NULL (since this would make
+ * many of our checks go away, and make our code less robust against
+ * programming errors). Unfortunately, nonnull currently does both of these
+ * things, and there's no good way to split them up.
+ *
+ * #define ATTR_NONNULL(x) __attribute__((nonnull x)) */
+#define ATTR_NONNULL(x)
+#define ATTR_UNUSED __attribute__ ((unused))
+
+/** Macro: Evaluates to <b>exp</b> and hints the compiler that the value
+ * of <b>exp</b> will probably be true.
+ *
+ * In other words, "if (PREDICT_LIKELY(foo))" is the same as "if (foo)",
+ * except that it tells the compiler that the branch will be taken most of the
+ * time. This can generate slightly better code with some CPUs.
+ */
+#define PREDICT_LIKELY(exp) __builtin_expect(!!(exp), 1)
+/** Macro: Evaluates to <b>exp</b> and hints the compiler that the value
+ * of <b>exp</b> will probably be false.
+ *
+ * In other words, "if (PREDICT_UNLIKELY(foo))" is the same as "if (foo)",
+ * except that it tells the compiler that the branch will usually not be
+ * taken. This can generate slightly better code with some CPUs.
+ */
+#define PREDICT_UNLIKELY(exp) __builtin_expect(!!(exp), 0)
+#else /* !(defined(__GNUC__) && __GNUC__ >= 3) */
+#define ATTR_NORETURN
+#define ATTR_CONST
+#define ATTR_MALLOC
+#define ATTR_NORETURN
+#define ATTR_NONNULL(x)
+#define ATTR_UNUSED
+#define ATTR_WUR
+#define PREDICT_LIKELY(exp) (exp)
+#define PREDICT_UNLIKELY(exp) (exp)
+#endif /* defined(__GNUC__) && __GNUC__ >= 3 */
+
+/** Expands to a syntactically valid empty statement. */
+#define STMT_NIL (void)0
+
+/** Expands to a syntactically valid empty statement, explicitly (void)ing its
+ * argument. */
+#define STMT_VOID(a) while (0) { (void)(a); }
+
+#ifdef __GNUC__
+/** STMT_BEGIN and STMT_END are used to wrap blocks inside macros so that
+ * the macro can be used as if it were a single C statement. */
+#define STMT_BEGIN (void) ({
+#define STMT_END })
+#elif defined(sun) || defined(__sun__)
+#define STMT_BEGIN if (1) {
+#define STMT_END } else STMT_NIL
+#else
+#define STMT_BEGIN do {
+#define STMT_END } while (0)
+#endif /* defined(__GNUC__) || ... */
+
+/* Some tools (like coccinelle) don't like to see operators as macro
+ * arguments. */
+#define OP_LT <
+#define OP_GT >
+#define OP_GE >=
+#define OP_LE <=
+#define OP_EQ ==
+#define OP_NE !=
+
+/* ===== String compatibility */
+#ifdef _WIN32
+/* Windows names string functions differently from most other platforms. */
+#define strncasecmp _strnicmp
+#define strcasecmp _stricmp
+#endif
+
+#if defined __APPLE__
+/* On OSX 10.9 and later, the overlap-checking code for strlcat would
+ * appear to have a severe bug that can sometimes cause aborts in Tor.
+ * Instead, use the non-checking variants. This is sad.
+ *
+ * See https://trac.torproject.org/projects/tor/ticket/15205
+ */
+#undef strlcat
+#undef strlcpy
+#endif /* defined __APPLE__ */
+
+#ifndef HAVE_STRLCAT
+size_t strlcat(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2));
+#endif
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2));
+#endif
+
+#ifdef _MSC_VER
+/** Casts the uint64_t value in <b>a</b> to the right type for an argument
+ * to printf. */
+#define U64_PRINTF_ARG(a) (a)
+/** Casts the uint64_t* value in <b>a</b> to the right type for an argument
+ * to scanf. */
+#define U64_SCANF_ARG(a) (a)
+/** Expands to a literal uint64_t-typed constant for the value <b>n</b>. */
+#define U64_LITERAL(n) (n ## ui64)
+#define I64_PRINTF_ARG(a) (a)
+#define I64_SCANF_ARG(a) (a)
+#define I64_LITERAL(n) (n ## i64)
+#else /* !(defined(_MSC_VER)) */
+#define U64_PRINTF_ARG(a) ((long long unsigned int)(a))
+#define U64_SCANF_ARG(a) ((long long unsigned int*)(a))
+#define U64_LITERAL(n) (n ## llu)
+#define I64_PRINTF_ARG(a) ((long long signed int)(a))
+#define I64_SCANF_ARG(a) ((long long signed int*)(a))
+#define I64_LITERAL(n) (n ## ll)
+#endif /* defined(_MSC_VER) */
+
+#if defined(__MINGW32__) || defined(__MINGW64__)
+#define MINGW_ANY
+#endif
+
+#if defined(_MSC_VER) || defined(MINGW_ANY)
+/** The formatting string used to put a uint64_t value in a printf() or
+ * scanf() function. See also U64_PRINTF_ARG and U64_SCANF_ARG. */
+#define U64_FORMAT "%I64u"
+#define I64_FORMAT "%I64d"
+#else /* !(defined(_MSC_VER) || defined(MINGW_ANY)) */
+#define U64_FORMAT "%llu"
+#define I64_FORMAT "%lld"
+#endif /* defined(_MSC_VER) || defined(MINGW_ANY) */
+
+#if (SIZEOF_INTPTR_T == SIZEOF_INT)
+#define INTPTR_T_FORMAT "%d"
+#define INTPTR_PRINTF_ARG(x) ((int)(x))
+#elif (SIZEOF_INTPTR_T == SIZEOF_LONG)
+#define INTPTR_T_FORMAT "%ld"
+#define INTPTR_PRINTF_ARG(x) ((long)(x))
+#elif (SIZEOF_INTPTR_T == 8)
+#define INTPTR_T_FORMAT I64_FORMAT
+#define INTPTR_PRINTF_ARG(x) I64_PRINTF_ARG(x)
+#else
+#error Unknown: SIZEOF_INTPTR_T
+#endif /* (SIZEOF_INTPTR_T == SIZEOF_INT) || ... */
+
/** Represents an mmaped file. Allocated via tor_mmap_file; freed with
* tor_munmap_file. */
typedef struct tor_mmap_t {
@@ -75,6 +330,16 @@ typedef struct tor_mmap_t {
tor_mmap_t *tor_mmap_file(const char *filename) ATTR_NONNULL((1));
int tor_munmap_file(tor_mmap_t *handle) ATTR_NONNULL((1));
+int tor_snprintf(char *str, size_t size, const char *format, ...)
+ CHECK_PRINTF(3,4) ATTR_NONNULL((1,3));
+int tor_vsnprintf(char *str, size_t size, const char *format, va_list args)
+ CHECK_PRINTF(3,0) ATTR_NONNULL((1,3));
+
+int tor_asprintf(char **strp, const char *fmt, ...)
+ CHECK_PRINTF(2,3);
+int tor_vasprintf(char **strp, const char *fmt, va_list args)
+ CHECK_PRINTF(2,0);
+
const void *tor_memmem(const void *haystack, size_t hlen, const void *needle,
size_t nlen) ATTR_NONNULL((1,3));
static const void *tor_memstr(const void *haystack, size_t hlen,
@@ -85,6 +350,28 @@ tor_memstr(const void *haystack, size_t hlen, const char *needle)
return tor_memmem(haystack, hlen, needle, strlen(needle));
}
+/* Much of the time when we're checking ctypes, we're doing spec compliance,
+ * which all assumes we're doing ASCII. */
+#define DECLARE_CTYPE_FN(name) \
+ static int TOR_##name(char c); \
+ extern const uint32_t TOR_##name##_TABLE[]; \
+ static inline int TOR_##name(char c) { \
+ uint8_t u = c; \
+ return !!(TOR_##name##_TABLE[(u >> 5) & 7] & (1u << (u & 31))); \
+ }
+DECLARE_CTYPE_FN(ISALPHA)
+DECLARE_CTYPE_FN(ISALNUM)
+DECLARE_CTYPE_FN(ISSPACE)
+DECLARE_CTYPE_FN(ISDIGIT)
+DECLARE_CTYPE_FN(ISXDIGIT)
+DECLARE_CTYPE_FN(ISPRINT)
+DECLARE_CTYPE_FN(ISLOWER)
+DECLARE_CTYPE_FN(ISUPPER)
+extern const uint8_t TOR_TOUPPER_TABLE[];
+extern const uint8_t TOR_TOLOWER_TABLE[];
+#define TOR_TOLOWER(c) (TOR_TOLOWER_TABLE[(uint8_t)c])
+#define TOR_TOUPPER(c) (TOR_TOUPPER_TABLE[(uint8_t)c])
+
char *tor_strtok_r_impl(char *str, const char *sep, char **lasts);
#ifdef HAVE_STRTOK_R
#define tor_strtok_r(str, sep, lasts) strtok_r(str, sep, lasts)
@@ -92,6 +379,14 @@ char *tor_strtok_r_impl(char *str, const char *sep, char **lasts);
#define tor_strtok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts)
#endif
+#ifdef _WIN32
+#define SHORT_FILE__ (tor_fix_source_file(__FILE__))
+const char *tor_fix_source_file(const char *fname);
+#else
+#define SHORT_FILE__ (__FILE__)
+#define tor_fix_source_file(s) (s)
+#endif /* defined(_WIN32) */
+
/* ===== Time compatibility */
struct tm *tor_localtime_r(const time_t *timep, struct tm *result);
@@ -152,6 +447,11 @@ tor_lockfile_t *tor_lockfile_lock(const char *filename, int blocking,
int *locked_out);
void tor_lockfile_unlock(tor_lockfile_t *lockfile);
+off_t tor_fd_getpos(int fd);
+int tor_fd_setpos(int fd, off_t pos);
+int tor_fd_seekend(int fd);
+int tor_ftruncate(int fd);
+
int64_t tor_get_avail_disk_space(const char *path);
#ifdef _WIN32
@@ -451,6 +751,7 @@ STATIC int tor_ersatz_socketpair(int family, int type, int protocol,
ssize_t tor_getpass(const char *prompt, char *output, size_t buflen);
/* This needs some of the declarations above so we include it here. */
-#include "common/compat_threads.h"
+#include "compat_threads.h"
#endif /* !defined(TOR_COMPAT_H) */
+
diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c
index a0b9bc535f..fa00fb836b 100644
--- a/src/common/compat_libevent.c
+++ b/src/common/compat_libevent.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009-2018, The Tor Project, Inc. */
+/* Copyright (c) 2009-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -7,14 +7,14 @@
*/
#include "orconfig.h"
-#include "common/compat.h"
+#include "compat.h"
#define COMPAT_LIBEVENT_PRIVATE
-#include "common/compat_libevent.h"
+#include "compat_libevent.h"
-#include "lib/crypt_ops/crypto_rand.h"
+#include "crypto_rand.h"
-#include "common/util.h"
-#include "lib/log/torlog.h"
+#include "util.h"
+#include "torlog.h"
#include <event2/event.h>
#include <event2/thread.h>
@@ -253,39 +253,10 @@ periodic_timer_new(struct event_base *base,
}
timer->cb = cb;
timer->data = data;
- periodic_timer_launch(timer, tv);
+ event_add(timer->ev, (struct timeval *)tv); /*drop const for old libevent*/
return timer;
}
-/**
- * Launch the timer <b>timer</b> to run at <b>tv</b> from now, and every
- * <b>tv</b> thereafter.
- *
- * If the timer is already enabled, this function does nothing.
- */
-void
-periodic_timer_launch(periodic_timer_t *timer, const struct timeval *tv)
-{
- tor_assert(timer);
- if (event_pending(timer->ev, EV_TIMEOUT, NULL))
- return;
- event_add(timer->ev, tv);
-}
-
-/**
- * Disable the provided <b>timer</b>, but do not free it.
- *
- * You can reenable the same timer later with periodic_timer_launch.
- *
- * If the timer is already disabled, this function does nothing.
- */
-void
-periodic_timer_disable(periodic_timer_t *timer)
-{
- tor_assert(timer);
- (void) event_del(timer->ev);
-}
-
/** Stop and free a periodic timer */
void
periodic_timer_free_(periodic_timer_t *timer)
diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h
index 4b2672b7b5..e2747860a9 100644
--- a/src/common/compat_libevent.h
+++ b/src/common/compat_libevent.h
@@ -1,11 +1,11 @@
-/* Copyright (c) 2009-2018, The Tor Project, Inc. */
+/* Copyright (c) 2009-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_COMPAT_LIBEVENT_H
#define TOR_COMPAT_LIBEVENT_H
#include "orconfig.h"
-#include "lib/testsupport/testsupport.h"
+#include "testsupport.h"
void configure_libevent_logging(void);
void suppress_libevent_log_msg(const char *msg);
@@ -31,8 +31,6 @@ periodic_timer_t *periodic_timer_new(struct event_base *base,
void (*cb)(periodic_timer_t *timer, void *data),
void *data);
void periodic_timer_free_(periodic_timer_t *);
-void periodic_timer_launch(periodic_timer_t *, const struct timeval *tv);
-void periodic_timer_disable(periodic_timer_t *);
#define periodic_timer_free(t) \
FREE_AND_NULL(periodic_timer_t, periodic_timer_free_, (t))
diff --git a/src/lib/crypt_ops/compat_openssl.h b/src/common/compat_openssl.h
index 317c01134a..1299ac36bb 100644
--- a/src/lib/crypt_ops/compat_openssl.h
+++ b/src/common/compat_openssl.h
@@ -1,15 +1,14 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_COMPAT_OPENSSL_H
#define TOR_COMPAT_OPENSSL_H
#include <openssl/opensslv.h>
-#include "lib/crypt_ops/crypto_openssl_mgt.h"
-
+#include "crypto_openssl_mgt.h"
/**
* \file compat_openssl.h
*
@@ -28,11 +27,8 @@
#define OPENSSL_1_1_API
#endif /* OPENSSL_VERSION_NUMBER >= OPENSSL_V_SERIES(1,1,0) && ... */
-#ifndef OPENSSL_VERSION
-#define OPENSSL_VERSION SSLEAY_VERSION
-#endif
-
#ifndef OPENSSL_1_1_API
+#define OPENSSL_VERSION SSLEAY_VERSION
#define OpenSSL_version(v) SSLeay_version(v)
#define OpenSSL_version_num() SSLeay()
#define RAND_OpenSSL() RAND_SSLeay()
diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c
index e345cfef0f..002274c469 100644
--- a/src/common/compat_pthreads.c
+++ b/src/common/compat_pthreads.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -15,9 +15,9 @@
#include <signal.h>
#include <time.h>
-#include "common/compat.h"
-#include "lib/log/torlog.h"
-#include "common/util.h"
+#include "compat.h"
+#include "torlog.h"
+#include "util.h"
/** Wraps a void (*)(void*) function and its argument so we can
* invoke them in a way pthreads would expect.
@@ -91,6 +91,88 @@ spawn_exit(void)
pthread_exit(NULL);
}
+/** A mutex attribute that we're going to use to tell pthreads that we want
+ * "recursive" mutexes (i.e., once we can re-lock if we're already holding
+ * them.) */
+static pthread_mutexattr_t attr_recursive;
+
+/** Initialize <b>mutex</b> so it can be locked. Every mutex must be set
+ * up with tor_mutex_init() or tor_mutex_new(); not both. */
+void
+tor_mutex_init(tor_mutex_t *mutex)
+{
+ if (PREDICT_UNLIKELY(!threads_initialized))
+ tor_threads_init(); // LCOV_EXCL_LINE
+ const int err = pthread_mutex_init(&mutex->mutex, &attr_recursive);
+ if (PREDICT_UNLIKELY(err)) {
+ // LCOV_EXCL_START
+ log_err(LD_GENERAL, "Error %d creating a mutex.", err);
+ tor_assert_unreached();
+ // LCOV_EXCL_STOP
+ }
+}
+
+/** As tor_mutex_init, but initialize a mutex suitable that may be
+ * non-recursive, if the OS supports that. */
+void
+tor_mutex_init_nonrecursive(tor_mutex_t *mutex)
+{
+ int err;
+ if (!threads_initialized)
+ tor_threads_init(); // LCOV_EXCL_LINE
+ err = pthread_mutex_init(&mutex->mutex, NULL);
+ if (PREDICT_UNLIKELY(err)) {
+ // LCOV_EXCL_START
+ log_err(LD_GENERAL, "Error %d creating a mutex.", err);
+ tor_assert_unreached();
+ // LCOV_EXCL_STOP
+ }
+}
+
+/** Wait until <b>m</b> is free, then acquire it. */
+void
+tor_mutex_acquire(tor_mutex_t *m)
+{
+ int err;
+ tor_assert(m);
+ err = pthread_mutex_lock(&m->mutex);
+ if (PREDICT_UNLIKELY(err)) {
+ // LCOV_EXCL_START
+ log_err(LD_GENERAL, "Error %d locking a mutex.", err);
+ tor_assert_unreached();
+ // LCOV_EXCL_STOP
+ }
+}
+/** Release the lock <b>m</b> so another thread can have it. */
+void
+tor_mutex_release(tor_mutex_t *m)
+{
+ int err;
+ tor_assert(m);
+ err = pthread_mutex_unlock(&m->mutex);
+ if (PREDICT_UNLIKELY(err)) {
+ // LCOV_EXCL_START
+ log_err(LD_GENERAL, "Error %d unlocking a mutex.", err);
+ tor_assert_unreached();
+ // LCOV_EXCL_STOP
+ }
+}
+/** Clean up the mutex <b>m</b> so that it no longer uses any system
+ * resources. Does not free <b>m</b>. This function must only be called on
+ * mutexes from tor_mutex_init(). */
+void
+tor_mutex_uninit(tor_mutex_t *m)
+{
+ int err;
+ tor_assert(m);
+ err = pthread_mutex_destroy(&m->mutex);
+ if (PREDICT_UNLIKELY(err)) {
+ // LCOV_EXCL_START
+ log_err(LD_GENERAL, "Error %d destroying a mutex.", err);
+ tor_assert_unreached();
+ // LCOV_EXCL_STOP
+ }
+}
/** Return an integer representing this thread. */
unsigned long
tor_get_thread_id(void)
@@ -251,7 +333,8 @@ void
tor_threads_init(void)
{
if (!threads_initialized) {
- tor_locking_init();
+ pthread_mutexattr_init(&attr_recursive);
+ pthread_mutexattr_settype(&attr_recursive, PTHREAD_MUTEX_RECURSIVE);
const int ret1 = pthread_attr_init(&attr_detached);
tor_assert(ret1 == 0);
#ifndef PTHREAD_CREATE_DETACHED
@@ -264,3 +347,4 @@ tor_threads_init(void)
set_main_thread();
}
}
+
diff --git a/src/common/compat_threads.c b/src/common/compat_threads.c
index e66143b35c..3171c4b2f2 100644
--- a/src/common/compat_threads.c
+++ b/src/common/compat_threads.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -13,11 +13,11 @@
#include "orconfig.h"
#include <stdlib.h>
-#include "common/compat.h"
-#include "common/compat_threads.h"
+#include "compat.h"
+#include "compat_threads.h"
-#include "common/util.h"
-#include "lib/log/torlog.h"
+#include "util.h"
+#include "torlog.h"
#ifdef HAVE_SYS_EVENTFD_H
#include <sys/eventfd.h>
@@ -29,6 +29,33 @@
#include <unistd.h>
#endif
+/** Return a newly allocated, ready-for-use mutex. */
+tor_mutex_t *
+tor_mutex_new(void)
+{
+ tor_mutex_t *m = tor_malloc_zero(sizeof(tor_mutex_t));
+ tor_mutex_init(m);
+ return m;
+}
+/** Return a newly allocated, ready-for-use mutex. This one might be
+ * non-recursive, if that's faster. */
+tor_mutex_t *
+tor_mutex_new_nonrecursive(void)
+{
+ tor_mutex_t *m = tor_malloc_zero(sizeof(tor_mutex_t));
+ tor_mutex_init_nonrecursive(m);
+ return m;
+}
+/** Release all storage and system resources held by <b>m</b>. */
+void
+tor_mutex_free_(tor_mutex_t *m)
+{
+ if (!m)
+ return;
+ tor_mutex_uninit(m);
+ tor_free(m);
+}
+
/** Allocate and return a new condition variable. */
tor_cond_t *
tor_cond_new(void)
@@ -377,3 +404,4 @@ atomic_counter_exchange(atomic_counter_t *counter, size_t newval)
return oldval;
}
#endif /* !defined(HAVE_STDATOMIC_H) */
+
diff --git a/src/common/compat_threads.h b/src/common/compat_threads.h
index d1fdfc96cc..c93e601ec5 100644
--- a/src/common/compat_threads.h
+++ b/src/common/compat_threads.h
@@ -1,23 +1,62 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_COMPAT_THREADS_H
#define TOR_COMPAT_THREADS_H
#include "orconfig.h"
-#include "lib/cc/torint.h"
-#include "lib/testsupport/testsupport.h"
-#include "lib/lock/compat_mutex.h"
+#include "torint.h"
+#include "testsupport.h"
+
+#if defined(HAVE_PTHREAD_H) && !defined(_WIN32)
+#include <pthread.h>
+#endif
#ifdef HAVE_STDATOMIC_H
#include <stdatomic.h>
#endif
+#if defined(_WIN32)
+#define USE_WIN32_THREADS
+#elif defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_CREATE)
+#define USE_PTHREADS
+#else
+#error "No threading system was found"
+#endif /* defined(_WIN32) || ... */
+
int spawn_func(void (*func)(void *), void *data);
void spawn_exit(void) ATTR_NORETURN;
+/* Because we use threads instead of processes on most platforms (Windows,
+ * Linux, etc), we need locking for them. On platforms with poor thread
+ * support or broken gethostbyname_r, these functions are no-ops. */
+
+/** A generic lock structure for multithreaded builds. */
+typedef struct tor_mutex_t {
+#if defined(USE_WIN32_THREADS)
+ /** Windows-only: on windows, we implement locks with CRITICAL_SECTIONS. */
+ CRITICAL_SECTION mutex;
+#elif defined(USE_PTHREADS)
+ /** Pthreads-only: with pthreads, we implement locks with
+ * pthread_mutex_t. */
+ pthread_mutex_t mutex;
+#else
+ /** No-threads only: Dummy variable so that tor_mutex_t takes up space. */
+ int _unused;
+#endif /* defined(USE_WIN32_THREADS) || ... */
+} tor_mutex_t;
+
+tor_mutex_t *tor_mutex_new(void);
+tor_mutex_t *tor_mutex_new_nonrecursive(void);
+void tor_mutex_init(tor_mutex_t *m);
+void tor_mutex_init_nonrecursive(tor_mutex_t *m);
+void tor_mutex_acquire(tor_mutex_t *m);
+void tor_mutex_release(tor_mutex_t *m);
+void tor_mutex_free_(tor_mutex_t *m);
+#define tor_mutex_free(m) FREE_AND_NULL(tor_mutex_t, tor_mutex_free_, (m))
+void tor_mutex_uninit(tor_mutex_t *m);
unsigned long tor_get_thread_id(void);
void tor_threads_init(void);
@@ -181,3 +220,4 @@ atomic_counter_exchange(atomic_counter_t *counter, size_t newval)
#endif /* defined(HAVE_STDATOMIC_H) */
#endif /* !defined(TOR_COMPAT_THREADS_H) */
+
diff --git a/src/common/compat_time.c b/src/common/compat_time.c
index 148f2f8957..40847a8442 100644
--- a/src/common/compat_time.c
+++ b/src/common/compat_time.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -10,7 +10,7 @@
**/
#define COMPAT_TIME_PRIVATE
-#include "common/compat.h"
+#include "compat.h"
#ifdef _WIN32
#include <winsock2.h>
@@ -34,9 +34,15 @@
#include <mach/mach_time.h>
#endif
-#include "lib/err/torerr.h"
-#include "lib/log/torlog.h"
-#include "common/util.h"
+#include "torlog.h"
+#include "util.h"
+#include "container.h"
+
+#ifndef HAVE_GETTIMEOFDAY
+#ifdef HAVE_FTIME
+#include <sys/timeb.h>
+#endif
+#endif
#ifdef _WIN32
#undef HAVE_CLOCK_GETTIME
@@ -62,6 +68,54 @@ tor_sleep_msec(int msec)
}
#endif /* defined(TOR_UNIT_TESTS) */
+/** Set *timeval to the current time of day. On error, log and terminate.
+ * (Same as gettimeofday(timeval,NULL), but never returns -1.)
+ */
+MOCK_IMPL(void,
+tor_gettimeofday, (struct timeval *timeval))
+{
+#ifdef _WIN32
+ /* Epoch bias copied from perl: number of units between windows epoch and
+ * Unix epoch. */
+#define EPOCH_BIAS U64_LITERAL(116444736000000000)
+#define UNITS_PER_SEC U64_LITERAL(10000000)
+#define USEC_PER_SEC U64_LITERAL(1000000)
+#define UNITS_PER_USEC U64_LITERAL(10)
+ union {
+ uint64_t ft_64;
+ FILETIME ft_ft;
+ } ft;
+ /* number of 100-nsec units since Jan 1, 1601 */
+ GetSystemTimeAsFileTime(&ft.ft_ft);
+ if (ft.ft_64 < EPOCH_BIAS) {
+ /* LCOV_EXCL_START */
+ log_err(LD_GENERAL,"System time is before 1970; failing.");
+ exit(1); // exit ok: system clock is broken.
+ /* LCOV_EXCL_STOP */
+ }
+ ft.ft_64 -= EPOCH_BIAS;
+ timeval->tv_sec = (unsigned) (ft.ft_64 / UNITS_PER_SEC);
+ timeval->tv_usec = (unsigned) ((ft.ft_64 / UNITS_PER_USEC) % USEC_PER_SEC);
+#elif defined(HAVE_GETTIMEOFDAY)
+ if (gettimeofday(timeval, NULL)) {
+ /* LCOV_EXCL_START */
+ log_err(LD_GENERAL,"gettimeofday failed.");
+ /* If gettimeofday dies, we have either given a bad timezone (we didn't),
+ or segfaulted.*/
+ exit(1); // exit ok: gettimeofday failed.
+ /* LCOV_EXCL_STOP */
+ }
+#elif defined(HAVE_FTIME)
+ struct timeb tb;
+ ftime(&tb);
+ timeval->tv_sec = tb.time;
+ timeval->tv_usec = tb.millitm * 1000;
+#else
+#error "No way to get time."
+#endif /* defined(_WIN32) || ... */
+ return;
+}
+
#define ONE_MILLION ((int64_t) (1000 * 1000))
#define ONE_BILLION ((int64_t) (1000 * 1000 * 1000))
@@ -846,3 +900,4 @@ monotime_msec_to_approx_coarse_stamp_units(uint64_t msec)
return (msec * STAMP_TICKS_PER_SECOND) / 1000;
}
#endif
+
diff --git a/src/common/compat_time.h b/src/common/compat_time.h
index 2f7e87a633..57ab20ab11 100644
--- a/src/common/compat_time.h
+++ b/src/common/compat_time.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -19,8 +19,6 @@
#define TOR_COMPAT_TIME_H
#include "orconfig.h"
-#include "lib/wallclock/tor_gettimeofday.h"
-
#ifdef _WIN32
#undef HAVE_CLOCK_GETTIME
#endif
@@ -202,6 +200,8 @@ monotime_coarse_diff_msec32(const monotime_coarse_t *start,
#endif
}
+MOCK_DECL(void, tor_gettimeofday, (struct timeval *timeval));
+
#ifdef TOR_UNIT_TESTS
void tor_sleep_msec(int msec);
@@ -230,3 +230,4 @@ void monotime_reset_ratchets_for_testing(void);
#endif /* defined(COMPAT_TIME_PRIVATE) */
#endif /* !defined(TOR_COMPAT_TIME_H) */
+
diff --git a/src/common/compat_winthreads.c b/src/common/compat_winthreads.c
index d082af31c9..7021344f6e 100644
--- a/src/common/compat_winthreads.c
+++ b/src/common/compat_winthreads.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -12,11 +12,12 @@
#ifdef _WIN32
-#include "common/compat.h"
+#include "compat.h"
#include <windows.h>
#include <process.h>
-#include "common/util.h"
-#include "lib/log/torlog.h"
+#include "util.h"
+#include "container.h"
+#include "torlog.h"
/* This value is more or less total cargo-cult */
#define SPIN_COUNT 2000
@@ -54,6 +55,33 @@ spawn_exit(void)
// LCOV_EXCL_STOP
}
+void
+tor_mutex_init(tor_mutex_t *m)
+{
+ InitializeCriticalSection(&m->mutex);
+}
+void
+tor_mutex_init_nonrecursive(tor_mutex_t *m)
+{
+ InitializeCriticalSection(&m->mutex);
+}
+
+void
+tor_mutex_uninit(tor_mutex_t *m)
+{
+ DeleteCriticalSection(&m->mutex);
+}
+void
+tor_mutex_acquire(tor_mutex_t *m)
+{
+ tor_assert(m);
+ EnterCriticalSection(&m->mutex);
+}
+void
+tor_mutex_release(tor_mutex_t *m)
+{
+ LeaveCriticalSection(&m->mutex);
+}
unsigned long
tor_get_thread_id(void)
{
@@ -220,3 +248,4 @@ tor_threads_init(void)
}
#endif /* defined(_WIN32) */
+
diff --git a/src/lib/compress/compress.c b/src/common/compress.c
index 64f10b45ce..cb1549f1aa 100644
--- a/src/lib/compress/compress.c
+++ b/src/common/compress.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -12,20 +12,21 @@
#include <stdlib.h>
#include <stdio.h>
+#include <assert.h>
#include <string.h>
-#include "lib/cc/torint.h"
+#include "torint.h"
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
-#include "common/util.h"
-#include "lib/log/torlog.h"
-#include "lib/compress/compress.h"
-#include "lib/compress/compress_lzma.h"
-#include "lib/compress/compress_none.h"
-#include "lib/compress/compress_zlib.h"
-#include "lib/compress/compress_zstd.h"
+#include "util.h"
+#include "torlog.h"
+#include "compress.h"
+#include "compress_lzma.h"
+#include "compress_none.h"
+#include "compress_zlib.h"
+#include "compress_zstd.h"
/** Total number of bytes allocated for compression state overhead. */
static atomic_counter_t total_compress_allocation;
diff --git a/src/lib/compress/compress.h b/src/common/compress.h
index 10ad6d86bc..65d63a4386 100644
--- a/src/lib/compress/compress.h
+++ b/src/common/compress.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
diff --git a/src/lib/compress/compress_lzma.c b/src/common/compress_lzma.c
index e7f3680b28..051c59ba2d 100644
--- a/src/lib/compress/compress_lzma.c
+++ b/src/common/compress_lzma.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -13,10 +13,10 @@
#include "orconfig.h"
-#include "common/util.h"
-#include "lib/log/torlog.h"
-#include "lib/compress/compress.h"
-#include "lib/compress/compress_lzma.h"
+#include "util.h"
+#include "torlog.h"
+#include "compress.h"
+#include "compress_lzma.h"
#ifdef HAVE_LZMA
#include <lzma.h>
diff --git a/src/lib/compress/compress_lzma.h b/src/common/compress_lzma.h
index 9ef3382a25..38a447c1f3 100644
--- a/src/lib/compress/compress_lzma.h
+++ b/src/common/compress_lzma.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
diff --git a/src/lib/compress/compress_none.c b/src/common/compress_none.c
index 11f99d82e6..34314e4af7 100644
--- a/src/lib/compress/compress_none.c
+++ b/src/common/compress_none.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -16,10 +16,10 @@
#include "orconfig.h"
-#include "common/util.h"
-#include "lib/log/torlog.h"
-#include "lib/compress/compress.h"
-#include "lib/compress/compress_none.h"
+#include "util.h"
+#include "torlog.h"
+#include "compress.h"
+#include "compress_none.h"
/** Transfer some bytes using the identity transformation. Read up to
* *<b>in_len</b> bytes from *<b>in</b>, and write up to *<b>out_len</b> bytes
diff --git a/src/lib/compress/compress_none.h b/src/common/compress_none.h
index 5c395bbb30..77c3cef47b 100644
--- a/src/lib/compress/compress_none.h
+++ b/src/common/compress_none.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
diff --git a/src/lib/compress/compress_zlib.c b/src/common/compress_zlib.c
index 7cba1150ed..23d71d27be 100644
--- a/src/lib/compress/compress_zlib.c
+++ b/src/common/compress_zlib.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -13,10 +13,10 @@
#include "orconfig.h"
-#include "common/util.h"
-#include "lib/log/torlog.h"
-#include "lib/compress/compress.h"
-#include "lib/compress/compress_zlib.h"
+#include "util.h"
+#include "torlog.h"
+#include "compress.h"
+#include "compress_zlib.h"
/* zlib 1.2.4 and 1.2.5 do some "clever" things with macros. Instead of
saying "(defined(FOO) ? FOO : 0)" they like to say "FOO-0", on the theory
diff --git a/src/lib/compress/compress_zlib.h b/src/common/compress_zlib.h
index 7af68044de..e3c1a2b339 100644
--- a/src/lib/compress/compress_zlib.h
+++ b/src/common/compress_zlib.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
diff --git a/src/lib/compress/compress_zstd.c b/src/common/compress_zstd.c
index f24c7a5abc..4024f5594d 100644
--- a/src/lib/compress/compress_zstd.c
+++ b/src/common/compress_zstd.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -13,10 +13,10 @@
#include "orconfig.h"
-#include "common/util.h"
-#include "lib/log/torlog.h"
-#include "lib/compress/compress.h"
-#include "lib/compress/compress_zstd.h"
+#include "util.h"
+#include "torlog.h"
+#include "compress.h"
+#include "compress_zstd.h"
#ifdef ENABLE_ZSTD_ADVANCED_APIS
/* This is a lie, but we make sure it doesn't get us in trouble by wrapping
@@ -26,9 +26,7 @@
#endif
#ifdef HAVE_ZSTD
-DISABLE_GCC_WARNING(unused-const-variable)
#include <zstd.h>
-ENABLE_GCC_WARNING(unused-const-variable)
#endif
/** Total number of bytes allocated for Zstandard state. */
diff --git a/src/lib/compress/compress_zstd.h b/src/common/compress_zstd.h
index 1177537a9e..bd42cf65ce 100644
--- a/src/lib/compress/compress_zstd.h
+++ b/src/common/compress_zstd.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
diff --git a/src/common/confline.c b/src/common/confline.c
index 9e37bfbdb7..bf613ab742 100644
--- a/src/common/confline.c
+++ b/src/common/confline.c
@@ -1,14 +1,14 @@
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
-#include "common/compat.h"
-#include "common/confline.h"
-#include "lib/log/torlog.h"
-#include "common/util.h"
-#include "lib/container/smartlist.h"
+#include "compat.h"
+#include "confline.h"
+#include "torlog.h"
+#include "util.h"
+#include "container.h"
static int config_get_lines_aux(const char *string, config_line_t **result,
int extended, int allow_include,
@@ -535,3 +535,4 @@ parse_config_line_from_str_verbose(const char *line, char **key_out,
return line;
}
+
diff --git a/src/common/confline.h b/src/common/confline.h
index d1f6fdb7e5..772a9bbbdc 100644
--- a/src/common/confline.h
+++ b/src/common/confline.h
@@ -1,13 +1,13 @@
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_CONFLINE_H
#define TOR_CONFLINE_H
-struct smartlist_t;
+#include "container.h"
/** Ordinary configuration line. */
#define CONFIG_LINE_NORMAL 0
@@ -47,7 +47,7 @@ int config_count_key(const config_line_t *a, const char *key);
int config_get_lines(const char *string, config_line_t **result, int extended);
int config_get_lines_include(const char *string, config_line_t **result,
int extended, int *has_include,
- struct smartlist_t *opened_lst);
+ smartlist_t *opened_lst);
void config_free_lines_(config_line_t *front);
#define config_free_lines(front) \
do { \
@@ -58,3 +58,4 @@ const char *parse_config_line_from_str_verbose(const char *line,
char **key_out, char **value_out,
const char **err_out);
#endif /* !defined(TOR_CONFLINE_H) */
+
diff --git a/src/lib/container/smartlist.c b/src/common/container.c
index 3c0844384a..5386e6458b 100644
--- a/src/lib/container/smartlist.c
+++ b/src/common/container.c
@@ -1,28 +1,27 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file container.c
* \brief Implements a smartlist (a resizable array) along
- * with helper functions to use smartlists.
+ * with helper functions to use smartlists. Also includes
+ * hash table implementations of a string-to-void* map, and of
+ * a digest-to-void* map.
**/
-#include "lib/malloc/util_malloc.h"
-#include "lib/container/smartlist.h"
-#include "lib/err/torerr.h"
-#include "lib/malloc/util_malloc.h"
-#include "lib/defs/digest_sizes.h"
-#include "lib/ctime/di_ops.h"
-#include "lib/string/compat_ctype.h"
-#include "lib/string/util_string.h"
-#include "lib/string/printf.h"
-
-#include "lib/log/util_bug.h"
+#include "compat.h"
+#include "util.h"
+#include "torlog.h"
+#include "container.h"
+#include "crypto_digest.h"
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
+
+#include "ht.h"
/** All newly allocated smartlists have this capacity. */
#define SMARTLIST_DEFAULT_CAPACITY 16
@@ -75,7 +74,7 @@ smartlist_ensure_capacity(smartlist_t *sl, size_t size)
#define MAX_CAPACITY (int)((SIZE_MAX / (sizeof(void*))))
#endif
- raw_assert(size <= MAX_CAPACITY);
+ tor_assert(size <= MAX_CAPACITY);
if (size > (size_t) sl->capacity) {
size_t higher = (size_t) sl->capacity;
@@ -115,41 +114,6 @@ smartlist_add_all(smartlist_t *s1, const smartlist_t *s2)
s1->num_used = (int) new_size;
}
-/** Append a copy of string to sl */
-void
-smartlist_add_strdup(struct smartlist_t *sl, const char *string)
-{
- char *copy;
-
- copy = tor_strdup(string);
-
- smartlist_add(sl, copy);
-}
-
-/** Append the string produced by tor_asprintf(<b>pattern</b>, <b>...</b>)
- * to <b>sl</b>. */
-void
-smartlist_add_asprintf(struct smartlist_t *sl, const char *pattern, ...)
-{
- va_list ap;
- va_start(ap, pattern);
- smartlist_add_vasprintf(sl, pattern, ap);
- va_end(ap);
-}
-
-/** va_list-based backend of smartlist_add_asprintf. */
-void
-smartlist_add_vasprintf(struct smartlist_t *sl, const char *pattern,
- va_list args)
-{
- char *str = NULL;
-
- tor_vasprintf(&str, pattern, args);
- tor_assert(str != NULL);
-
- smartlist_add(sl, str);
-}
-
/** Remove all elements E from sl such that E==element. Preserve
* the order of any elements before E, but elements after E can be
* rearranged.
@@ -1120,3 +1084,459 @@ smartlist_uniq_digests256(smartlist_t *sl)
{
smartlist_uniq(sl, compare_digests256_, tor_free_);
}
+
+/** Helper: Declare an entry type and a map type to implement a mapping using
+ * ht.h. The map type will be called <b>maptype</b>. The key part of each
+ * entry is declared using the C declaration <b>keydecl</b>. All functions
+ * and types associated with the map get prefixed with <b>prefix</b> */
+#define DEFINE_MAP_STRUCTS(maptype, keydecl, prefix) \
+ typedef struct prefix ## entry_t { \
+ HT_ENTRY(prefix ## entry_t) node; \
+ void *val; \
+ keydecl; \
+ } prefix ## entry_t; \
+ struct maptype { \
+ HT_HEAD(prefix ## impl, prefix ## entry_t) head; \
+ }
+
+DEFINE_MAP_STRUCTS(strmap_t, char *key, strmap_);
+DEFINE_MAP_STRUCTS(digestmap_t, char key[DIGEST_LEN], digestmap_);
+DEFINE_MAP_STRUCTS(digest256map_t, uint8_t key[DIGEST256_LEN], digest256map_);
+
+/** Helper: compare strmap_entry_t objects by key value. */
+static inline int
+strmap_entries_eq(const strmap_entry_t *a, const strmap_entry_t *b)
+{
+ return !strcmp(a->key, b->key);
+}
+
+/** Helper: return a hash value for a strmap_entry_t. */
+static inline unsigned int
+strmap_entry_hash(const strmap_entry_t *a)
+{
+ return (unsigned) siphash24g(a->key, strlen(a->key));
+}
+
+/** Helper: compare digestmap_entry_t objects by key value. */
+static inline int
+digestmap_entries_eq(const digestmap_entry_t *a, const digestmap_entry_t *b)
+{
+ return tor_memeq(a->key, b->key, DIGEST_LEN);
+}
+
+/** Helper: return a hash value for a digest_map_t. */
+static inline unsigned int
+digestmap_entry_hash(const digestmap_entry_t *a)
+{
+ return (unsigned) siphash24g(a->key, DIGEST_LEN);
+}
+
+/** Helper: compare digestmap_entry_t objects by key value. */
+static inline int
+digest256map_entries_eq(const digest256map_entry_t *a,
+ const digest256map_entry_t *b)
+{
+ return tor_memeq(a->key, b->key, DIGEST256_LEN);
+}
+
+/** Helper: return a hash value for a digest_map_t. */
+static inline unsigned int
+digest256map_entry_hash(const digest256map_entry_t *a)
+{
+ return (unsigned) siphash24g(a->key, DIGEST256_LEN);
+}
+
+HT_PROTOTYPE(strmap_impl, strmap_entry_t, node, strmap_entry_hash,
+ strmap_entries_eq)
+HT_GENERATE2(strmap_impl, strmap_entry_t, node, strmap_entry_hash,
+ strmap_entries_eq, 0.6, tor_reallocarray_, tor_free_)
+
+HT_PROTOTYPE(digestmap_impl, digestmap_entry_t, node, digestmap_entry_hash,
+ digestmap_entries_eq)
+HT_GENERATE2(digestmap_impl, digestmap_entry_t, node, digestmap_entry_hash,
+ digestmap_entries_eq, 0.6, tor_reallocarray_, tor_free_)
+
+HT_PROTOTYPE(digest256map_impl, digest256map_entry_t, node,
+ digest256map_entry_hash,
+ digest256map_entries_eq)
+HT_GENERATE2(digest256map_impl, digest256map_entry_t, node,
+ digest256map_entry_hash,
+ digest256map_entries_eq, 0.6, tor_reallocarray_, tor_free_)
+
+#define strmap_entry_free(ent) \
+ FREE_AND_NULL(strmap_entry_t, strmap_entry_free_, (ent))
+#define digestmap_entry_free(ent) \
+ FREE_AND_NULL(digestmap_entry_t, digestmap_entry_free_, (ent))
+#define digest256map_entry_free(ent) \
+ FREE_AND_NULL(digest256map_entry_t, digest256map_entry_free_, (ent))
+
+static inline void
+strmap_entry_free_(strmap_entry_t *ent)
+{
+ tor_free(ent->key);
+ tor_free(ent);
+}
+static inline void
+digestmap_entry_free_(digestmap_entry_t *ent)
+{
+ tor_free(ent);
+}
+static inline void
+digest256map_entry_free_(digest256map_entry_t *ent)
+{
+ tor_free(ent);
+}
+
+static inline void
+strmap_assign_tmp_key(strmap_entry_t *ent, const char *key)
+{
+ ent->key = (char*)key;
+}
+static inline void
+digestmap_assign_tmp_key(digestmap_entry_t *ent, const char *key)
+{
+ memcpy(ent->key, key, DIGEST_LEN);
+}
+static inline void
+digest256map_assign_tmp_key(digest256map_entry_t *ent, const uint8_t *key)
+{
+ memcpy(ent->key, key, DIGEST256_LEN);
+}
+static inline void
+strmap_assign_key(strmap_entry_t *ent, const char *key)
+{
+ ent->key = tor_strdup(key);
+}
+static inline void
+digestmap_assign_key(digestmap_entry_t *ent, const char *key)
+{
+ memcpy(ent->key, key, DIGEST_LEN);
+}
+static inline void
+digest256map_assign_key(digest256map_entry_t *ent, const uint8_t *key)
+{
+ memcpy(ent->key, key, DIGEST256_LEN);
+}
+
+/**
+ * Macro: implement all the functions for a map that are declared in
+ * container.h by the DECLARE_MAP_FNS() macro. You must additionally define a
+ * prefix_entry_free_() function to free entries (and their keys), a
+ * prefix_assign_tmp_key() function to temporarily set a stack-allocated
+ * entry to hold a key, and a prefix_assign_key() function to set a
+ * heap-allocated entry to hold a key.
+ */
+#define IMPLEMENT_MAP_FNS(maptype, keytype, prefix) \
+ /** Create and return a new empty map. */ \
+ MOCK_IMPL(maptype *, \
+ prefix##_new,(void)) \
+ { \
+ maptype *result; \
+ result = tor_malloc(sizeof(maptype)); \
+ HT_INIT(prefix##_impl, &result->head); \
+ return result; \
+ } \
+ \
+ /** Return the item from <b>map</b> whose key matches <b>key</b>, or \
+ * NULL if no such value exists. */ \
+ void * \
+ prefix##_get(const maptype *map, const keytype key) \
+ { \
+ prefix ##_entry_t *resolve; \
+ prefix ##_entry_t search; \
+ tor_assert(map); \
+ tor_assert(key); \
+ prefix ##_assign_tmp_key(&search, key); \
+ resolve = HT_FIND(prefix ##_impl, &map->head, &search); \
+ if (resolve) { \
+ return resolve->val; \
+ } else { \
+ return NULL; \
+ } \
+ } \
+ \
+ /** Add an entry to <b>map</b> mapping <b>key</b> to <b>val</b>; \
+ * return the previous value, or NULL if no such value existed. */ \
+ void * \
+ prefix##_set(maptype *map, const keytype key, void *val) \
+ { \
+ prefix##_entry_t search; \
+ void *oldval; \
+ tor_assert(map); \
+ tor_assert(key); \
+ tor_assert(val); \
+ prefix##_assign_tmp_key(&search, key); \
+ /* We a lot of our time in this function, so the code below is */ \
+ /* meant to optimize the check/alloc/set cycle by avoiding the two */\
+ /* trips to the hash table that we would do in the unoptimized */ \
+ /* version of this code. (Each of HT_INSERT and HT_FIND calls */ \
+ /* HT_SET_HASH and HT_FIND_P.) */ \
+ HT_FIND_OR_INSERT_(prefix##_impl, node, prefix##_entry_hash, \
+ &(map->head), \
+ prefix##_entry_t, &search, ptr, \
+ { \
+ /* we found an entry. */ \
+ oldval = (*ptr)->val; \
+ (*ptr)->val = val; \
+ return oldval; \
+ }, \
+ { \
+ /* We didn't find the entry. */ \
+ prefix##_entry_t *newent = \
+ tor_malloc_zero(sizeof(prefix##_entry_t)); \
+ prefix##_assign_key(newent, key); \
+ newent->val = val; \
+ HT_FOI_INSERT_(node, &(map->head), \
+ &search, newent, ptr); \
+ return NULL; \
+ }); \
+ } \
+ \
+ /** Remove the value currently associated with <b>key</b> from the map. \
+ * Return the value if one was set, or NULL if there was no entry for \
+ * <b>key</b>. \
+ * \
+ * Note: you must free any storage associated with the returned value. \
+ */ \
+ void * \
+ prefix##_remove(maptype *map, const keytype key) \
+ { \
+ prefix##_entry_t *resolve; \
+ prefix##_entry_t search; \
+ void *oldval; \
+ tor_assert(map); \
+ tor_assert(key); \
+ prefix##_assign_tmp_key(&search, key); \
+ resolve = HT_REMOVE(prefix##_impl, &map->head, &search); \
+ if (resolve) { \
+ oldval = resolve->val; \
+ prefix##_entry_free(resolve); \
+ return oldval; \
+ } else { \
+ return NULL; \
+ } \
+ } \
+ \
+ /** Return the number of elements in <b>map</b>. */ \
+ int \
+ prefix##_size(const maptype *map) \
+ { \
+ return HT_SIZE(&map->head); \
+ } \
+ \
+ /** Return true iff <b>map</b> has no entries. */ \
+ int \
+ prefix##_isempty(const maptype *map) \
+ { \
+ return HT_EMPTY(&map->head); \
+ } \
+ \
+ /** Assert that <b>map</b> is not corrupt. */ \
+ void \
+ prefix##_assert_ok(const maptype *map) \
+ { \
+ tor_assert(!prefix##_impl_HT_REP_IS_BAD_(&map->head)); \
+ } \
+ \
+ /** Remove all entries from <b>map</b>, and deallocate storage for \
+ * those entries. If free_val is provided, invoked it every value in \
+ * <b>map</b>. */ \
+ MOCK_IMPL(void, \
+ prefix##_free_, (maptype *map, void (*free_val)(void*))) \
+ { \
+ prefix##_entry_t **ent, **next, *this; \
+ if (!map) \
+ return; \
+ for (ent = HT_START(prefix##_impl, &map->head); ent != NULL; \
+ ent = next) { \
+ this = *ent; \
+ next = HT_NEXT_RMV(prefix##_impl, &map->head, ent); \
+ if (free_val) \
+ free_val(this->val); \
+ prefix##_entry_free(this); \
+ } \
+ tor_assert(HT_EMPTY(&map->head)); \
+ HT_CLEAR(prefix##_impl, &map->head); \
+ tor_free(map); \
+ } \
+ \
+ /** return an <b>iterator</b> pointer to the front of a map. \
+ * \
+ * Iterator example: \
+ * \
+ * \code \
+ * // uppercase values in "map", removing empty values. \
+ * \
+ * strmap_iter_t *iter; \
+ * const char *key; \
+ * void *val; \
+ * char *cp; \
+ * \
+ * for (iter = strmap_iter_init(map); !strmap_iter_done(iter); ) { \
+ * strmap_iter_get(iter, &key, &val); \
+ * cp = (char*)val; \
+ * if (!*cp) { \
+ * iter = strmap_iter_next_rmv(map,iter); \
+ * free(val); \
+ * } else { \
+ * for (;*cp;cp++) *cp = TOR_TOUPPER(*cp); \
+ */ \
+ prefix##_iter_t * \
+ prefix##_iter_init(maptype *map) \
+ { \
+ tor_assert(map); \
+ return HT_START(prefix##_impl, &map->head); \
+ } \
+ \
+ /** Advance <b>iter</b> a single step to the next entry, and return \
+ * its new value. */ \
+ prefix##_iter_t * \
+ prefix##_iter_next(maptype *map, prefix##_iter_t *iter) \
+ { \
+ tor_assert(map); \
+ tor_assert(iter); \
+ return HT_NEXT(prefix##_impl, &map->head, iter); \
+ } \
+ /** Advance <b>iter</b> a single step to the next entry, removing the \
+ * current entry, and return its new value. */ \
+ prefix##_iter_t * \
+ prefix##_iter_next_rmv(maptype *map, prefix##_iter_t *iter) \
+ { \
+ prefix##_entry_t *rmv; \
+ tor_assert(map); \
+ tor_assert(iter); \
+ tor_assert(*iter); \
+ rmv = *iter; \
+ iter = HT_NEXT_RMV(prefix##_impl, &map->head, iter); \
+ prefix##_entry_free(rmv); \
+ return iter; \
+ } \
+ /** Set *<b>keyp</b> and *<b>valp</b> to the current entry pointed \
+ * to by iter. */ \
+ void \
+ prefix##_iter_get(prefix##_iter_t *iter, const keytype *keyp, \
+ void **valp) \
+ { \
+ tor_assert(iter); \
+ tor_assert(*iter); \
+ tor_assert(keyp); \
+ tor_assert(valp); \
+ *keyp = (*iter)->key; \
+ *valp = (*iter)->val; \
+ } \
+ /** Return true iff <b>iter</b> has advanced past the last entry of \
+ * <b>map</b>. */ \
+ int \
+ prefix##_iter_done(prefix##_iter_t *iter) \
+ { \
+ return iter == NULL; \
+ }
+
+IMPLEMENT_MAP_FNS(strmap_t, char *, strmap)
+IMPLEMENT_MAP_FNS(digestmap_t, char *, digestmap)
+IMPLEMENT_MAP_FNS(digest256map_t, uint8_t *, digest256map)
+
+/** Same as strmap_set, but first converts <b>key</b> to lowercase. */
+void *
+strmap_set_lc(strmap_t *map, const char *key, void *val)
+{
+ /* We could be a little faster by using strcasecmp instead, and a separate
+ * type, but I don't think it matters. */
+ void *v;
+ char *lc_key = tor_strdup(key);
+ tor_strlower(lc_key);
+ v = strmap_set(map,lc_key,val);
+ tor_free(lc_key);
+ return v;
+}
+
+/** Same as strmap_get, but first converts <b>key</b> to lowercase. */
+void *
+strmap_get_lc(const strmap_t *map, const char *key)
+{
+ void *v;
+ char *lc_key = tor_strdup(key);
+ tor_strlower(lc_key);
+ v = strmap_get(map,lc_key);
+ tor_free(lc_key);
+ return v;
+}
+
+/** Same as strmap_remove, but first converts <b>key</b> to lowercase */
+void *
+strmap_remove_lc(strmap_t *map, const char *key)
+{
+ void *v;
+ char *lc_key = tor_strdup(key);
+ tor_strlower(lc_key);
+ v = strmap_remove(map,lc_key);
+ tor_free(lc_key);
+ return v;
+}
+
+/** Declare a function called <b>funcname</b> that acts as a find_nth_FOO
+ * function for an array of type <b>elt_t</b>*.
+ *
+ * NOTE: The implementation kind of sucks: It's O(n log n), whereas finding
+ * the kth element of an n-element list can be done in O(n). Then again, this
+ * implementation is not in critical path, and it is obviously correct. */
+#define IMPLEMENT_ORDER_FUNC(funcname, elt_t) \
+ static int \
+ _cmp_ ## elt_t(const void *_a, const void *_b) \
+ { \
+ const elt_t *a = _a, *b = _b; \
+ if (*a<*b) \
+ return -1; \
+ else if (*a>*b) \
+ return 1; \
+ else \
+ return 0; \
+ } \
+ elt_t \
+ funcname(elt_t *array, int n_elements, int nth) \
+ { \
+ tor_assert(nth >= 0); \
+ tor_assert(nth < n_elements); \
+ qsort(array, n_elements, sizeof(elt_t), _cmp_ ##elt_t); \
+ return array[nth]; \
+ }
+
+IMPLEMENT_ORDER_FUNC(find_nth_int, int)
+IMPLEMENT_ORDER_FUNC(find_nth_time, time_t)
+IMPLEMENT_ORDER_FUNC(find_nth_double, double)
+IMPLEMENT_ORDER_FUNC(find_nth_uint32, uint32_t)
+IMPLEMENT_ORDER_FUNC(find_nth_int32, int32_t)
+IMPLEMENT_ORDER_FUNC(find_nth_long, long)
+
+/** Return a newly allocated digestset_t, optimized to hold a total of
+ * <b>max_elements</b> digests with a reasonably low false positive weight. */
+digestset_t *
+digestset_new(int max_elements)
+{
+ /* The probability of false positives is about P=(1 - exp(-kn/m))^k, where k
+ * is the number of hash functions per entry, m is the bits in the array,
+ * and n is the number of elements inserted. For us, k==4, n<=max_elements,
+ * and m==n_bits= approximately max_elements*32. This gives
+ * P<(1-exp(-4*n/(32*n)))^4 == (1-exp(1/-8))^4 == .00019
+ *
+ * It would be more optimal in space vs false positives to get this false
+ * positive rate by going for k==13, and m==18.5n, but we also want to
+ * conserve CPU, and k==13 is pretty big.
+ */
+ int n_bits = 1u << (tor_log2(max_elements)+5);
+ digestset_t *r = tor_malloc(sizeof(digestset_t));
+ r->mask = n_bits - 1;
+ r->ba = bitarray_init_zero(n_bits);
+ return r;
+}
+
+/** Free all storage held in <b>set</b>. */
+void
+digestset_free_(digestset_t *set)
+{
+ if (!set)
+ return;
+ bitarray_free(set->ba);
+ tor_free(set);
+}
+
diff --git a/src/common/container.h b/src/common/container.h
new file mode 100644
index 0000000000..5d2dce5416
--- /dev/null
+++ b/src/common/container.h
@@ -0,0 +1,742 @@
+/* Copyright (c) 2003-2004, Roger Dingledine
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef TOR_CONTAINER_H
+#define TOR_CONTAINER_H
+
+#include "util.h"
+#include "siphash.h"
+
+/** A resizeable list of pointers, with associated helpful functionality.
+ *
+ * The members of this struct are exposed only so that macros and inlines can
+ * use them; all access to smartlist internals should go through the functions
+ * and macros defined here.
+ **/
+typedef struct smartlist_t {
+ /** @{ */
+ /** <b>list</b> has enough capacity to store exactly <b>capacity</b> elements
+ * before it needs to be resized. Only the first <b>num_used</b> (\<=
+ * capacity) elements point to valid data.
+ */
+ void **list;
+ int num_used;
+ int capacity;
+ /** @} */
+} smartlist_t;
+
+MOCK_DECL(smartlist_t *, smartlist_new, (void));
+MOCK_DECL(void, smartlist_free_, (smartlist_t *sl));
+#define smartlist_free(sl) FREE_AND_NULL(smartlist_t, smartlist_free_, (sl))
+
+void smartlist_clear(smartlist_t *sl);
+void smartlist_add(smartlist_t *sl, void *element);
+void smartlist_add_all(smartlist_t *sl, const smartlist_t *s2);
+void smartlist_remove(smartlist_t *sl, const void *element);
+void smartlist_remove_keeporder(smartlist_t *sl, const void *element);
+void *smartlist_pop_last(smartlist_t *sl);
+void smartlist_reverse(smartlist_t *sl);
+void smartlist_string_remove(smartlist_t *sl, const char *element);
+int smartlist_contains(const smartlist_t *sl, const void *element);
+int smartlist_contains_string(const smartlist_t *sl, const char *element);
+int smartlist_pos(const smartlist_t *sl, const void *element);
+int smartlist_string_pos(const smartlist_t *, const char *elt);
+int smartlist_contains_string_case(const smartlist_t *sl, const char *element);
+int smartlist_contains_int_as_string(const smartlist_t *sl, int num);
+int smartlist_strings_eq(const smartlist_t *sl1, const smartlist_t *sl2);
+int smartlist_contains_digest(const smartlist_t *sl, const char *element);
+int smartlist_ints_eq(const smartlist_t *sl1, const smartlist_t *sl2);
+int smartlist_overlap(const smartlist_t *sl1, const smartlist_t *sl2);
+void smartlist_intersect(smartlist_t *sl1, const smartlist_t *sl2);
+void smartlist_subtract(smartlist_t *sl1, const smartlist_t *sl2);
+
+/* smartlist_choose() is defined in crypto.[ch] */
+#ifdef DEBUG_SMARTLIST
+/** Return the number of items in sl.
+ */
+static inline int smartlist_len(const smartlist_t *sl);
+static inline int smartlist_len(const smartlist_t *sl) {
+ tor_assert(sl);
+ return (sl)->num_used;
+}
+/** Return the <b>idx</b>th element of sl.
+ */
+static inline void *smartlist_get(const smartlist_t *sl, int idx);
+static inline void *smartlist_get(const smartlist_t *sl, int idx) {
+ tor_assert(sl);
+ tor_assert(idx>=0);
+ tor_assert(sl->num_used > idx);
+ return sl->list[idx];
+}
+static inline void smartlist_set(smartlist_t *sl, int idx, void *val) {
+ tor_assert(sl);
+ tor_assert(idx>=0);
+ tor_assert(sl->num_used > idx);
+ sl->list[idx] = val;
+}
+#else /* !(defined(DEBUG_SMARTLIST)) */
+#define smartlist_len(sl) ((sl)->num_used)
+#define smartlist_get(sl, idx) ((sl)->list[idx])
+#define smartlist_set(sl, idx, val) ((sl)->list[idx] = (val))
+#endif /* defined(DEBUG_SMARTLIST) */
+
+/** Exchange the elements at indices <b>idx1</b> and <b>idx2</b> of the
+ * smartlist <b>sl</b>. */
+static inline void smartlist_swap(smartlist_t *sl, int idx1, int idx2)
+{
+ if (idx1 != idx2) {
+ void *elt = smartlist_get(sl, idx1);
+ smartlist_set(sl, idx1, smartlist_get(sl, idx2));
+ smartlist_set(sl, idx2, elt);
+ }
+}
+
+void smartlist_del(smartlist_t *sl, int idx);
+void smartlist_del_keeporder(smartlist_t *sl, int idx);
+void smartlist_insert(smartlist_t *sl, int idx, void *val);
+void smartlist_sort(smartlist_t *sl,
+ int (*compare)(const void **a, const void **b));
+void *smartlist_get_most_frequent_(const smartlist_t *sl,
+ int (*compare)(const void **a, const void **b),
+ int *count_out);
+#define smartlist_get_most_frequent(sl, compare) \
+ smartlist_get_most_frequent_((sl), (compare), NULL)
+void smartlist_uniq(smartlist_t *sl,
+ int (*compare)(const void **a, const void **b),
+ void (*free_fn)(void *elt));
+
+void smartlist_sort_strings(smartlist_t *sl);
+void smartlist_sort_digests(smartlist_t *sl);
+void smartlist_sort_digests256(smartlist_t *sl);
+void smartlist_sort_pointers(smartlist_t *sl);
+
+const char *smartlist_get_most_frequent_string(smartlist_t *sl);
+const char *smartlist_get_most_frequent_string_(smartlist_t *sl,
+ int *count_out);
+const uint8_t *smartlist_get_most_frequent_digest256(smartlist_t *sl);
+
+void smartlist_uniq_strings(smartlist_t *sl);
+void smartlist_uniq_digests(smartlist_t *sl);
+void smartlist_uniq_digests256(smartlist_t *sl);
+void *smartlist_bsearch(smartlist_t *sl, const void *key,
+ int (*compare)(const void *key, const void **member));
+int smartlist_bsearch_idx(const smartlist_t *sl, const void *key,
+ int (*compare)(const void *key, const void **member),
+ int *found_out);
+
+void smartlist_pqueue_add(smartlist_t *sl,
+ int (*compare)(const void *a, const void *b),
+ int idx_field_offset,
+ void *item);
+void *smartlist_pqueue_pop(smartlist_t *sl,
+ int (*compare)(const void *a, const void *b),
+ int idx_field_offset);
+void smartlist_pqueue_remove(smartlist_t *sl,
+ int (*compare)(const void *a, const void *b),
+ int idx_field_offset,
+ void *item);
+void smartlist_pqueue_assert_ok(smartlist_t *sl,
+ int (*compare)(const void *a, const void *b),
+ int idx_field_offset);
+
+#define SPLIT_SKIP_SPACE 0x01
+#define SPLIT_IGNORE_BLANK 0x02
+#define SPLIT_STRIP_SPACE 0x04
+int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep,
+ int flags, int max);
+char *smartlist_join_strings(smartlist_t *sl, const char *join, int terminate,
+ size_t *len_out) ATTR_MALLOC;
+char *smartlist_join_strings2(smartlist_t *sl, const char *join,
+ size_t join_len, int terminate, size_t *len_out)
+ ATTR_MALLOC;
+
+/** Iterate over the items in a smartlist <b>sl</b>, in order. For each item,
+ * assign it to a new local variable of type <b>type</b> named <b>var</b>, and
+ * execute the statements inside the loop body. Inside the loop, the loop
+ * index can be accessed as <b>var</b>_sl_idx and the length of the list can
+ * be accessed as <b>var</b>_sl_len.
+ *
+ * NOTE: Do not change the length of the list while the loop is in progress,
+ * unless you adjust the _sl_len variable correspondingly. See second example
+ * below.
+ *
+ * Example use:
+ * <pre>
+ * smartlist_t *list = smartlist_split("A:B:C", ":", 0, 0);
+ * SMARTLIST_FOREACH_BEGIN(list, char *, cp) {
+ * printf("%d: %s\n", cp_sl_idx, cp);
+ * tor_free(cp);
+ * } SMARTLIST_FOREACH_END(cp);
+ * smartlist_free(list);
+ * </pre>
+ *
+ * Example use (advanced):
+ * <pre>
+ * SMARTLIST_FOREACH_BEGIN(list, char *, cp) {
+ * if (!strcmp(cp, "junk")) {
+ * tor_free(cp);
+ * SMARTLIST_DEL_CURRENT(list, cp);
+ * }
+ * } SMARTLIST_FOREACH_END(cp);
+ * </pre>
+ */
+/* Note: these macros use token pasting, and reach into smartlist internals.
+ * This can make them a little daunting. Here's the approximate unpacking of
+ * the above examples, for entertainment value:
+ *
+ * <pre>
+ * smartlist_t *list = smartlist_split("A:B:C", ":", 0, 0);
+ * {
+ * int cp_sl_idx, cp_sl_len = smartlist_len(list);
+ * char *cp;
+ * for (cp_sl_idx = 0; cp_sl_idx < cp_sl_len; ++cp_sl_idx) {
+ * cp = smartlist_get(list, cp_sl_idx);
+ * printf("%d: %s\n", cp_sl_idx, cp);
+ * tor_free(cp);
+ * }
+ * }
+ * smartlist_free(list);
+ * </pre>
+ *
+ * <pre>
+ * {
+ * int cp_sl_idx, cp_sl_len = smartlist_len(list);
+ * char *cp;
+ * for (cp_sl_idx = 0; cp_sl_idx < cp_sl_len; ++cp_sl_idx) {
+ * cp = smartlist_get(list, cp_sl_idx);
+ * if (!strcmp(cp, "junk")) {
+ * tor_free(cp);
+ * smartlist_del(list, cp_sl_idx);
+ * --cp_sl_idx;
+ * --cp_sl_len;
+ * }
+ * }
+ * }
+ * </pre>
+ */
+#define SMARTLIST_FOREACH_BEGIN(sl, type, var) \
+ STMT_BEGIN \
+ int var ## _sl_idx, var ## _sl_len=(sl)->num_used; \
+ type var; \
+ for (var ## _sl_idx = 0; var ## _sl_idx < var ## _sl_len; \
+ ++var ## _sl_idx) { \
+ var = (sl)->list[var ## _sl_idx];
+
+#define SMARTLIST_FOREACH_END(var) \
+ var = NULL; \
+ (void) var ## _sl_idx; \
+ } STMT_END
+
+/**
+ * An alias for SMARTLIST_FOREACH_BEGIN and SMARTLIST_FOREACH_END, using
+ * <b>cmd</b> as the loop body. This wrapper is here for convenience with
+ * very short loops.
+ *
+ * By convention, we do not use this for loops which nest, or for loops over
+ * 10 lines or so. Use SMARTLIST_FOREACH_{BEGIN,END} for those.
+ */
+#define SMARTLIST_FOREACH(sl, type, var, cmd) \
+ SMARTLIST_FOREACH_BEGIN(sl,type,var) { \
+ cmd; \
+ } SMARTLIST_FOREACH_END(var)
+
+/** Helper: While in a SMARTLIST_FOREACH loop over the list <b>sl</b> indexed
+ * with the variable <b>var</b>, remove the current element in a way that
+ * won't confuse the loop. */
+#define SMARTLIST_DEL_CURRENT(sl, var) \
+ STMT_BEGIN \
+ smartlist_del(sl, var ## _sl_idx); \
+ --var ## _sl_idx; \
+ --var ## _sl_len; \
+ STMT_END
+
+/** Helper: While in a SMARTLIST_FOREACH loop over the list <b>sl</b> indexed
+ * with the variable <b>var</b>, remove the current element in a way that
+ * won't confuse the loop. */
+#define SMARTLIST_DEL_CURRENT_KEEPORDER(sl, var) \
+ STMT_BEGIN \
+ smartlist_del_keeporder(sl, var ## _sl_idx); \
+ --var ## _sl_idx; \
+ --var ## _sl_len; \
+ STMT_END
+
+/** Helper: While in a SMARTLIST_FOREACH loop over the list <b>sl</b> indexed
+ * with the variable <b>var</b>, replace the current element with <b>val</b>.
+ * Does not deallocate the current value of <b>var</b>.
+ */
+#define SMARTLIST_REPLACE_CURRENT(sl, var, val) \
+ STMT_BEGIN \
+ smartlist_set(sl, var ## _sl_idx, val); \
+ STMT_END
+
+/* Helper: Given two lists of items, possibly of different types, such that
+ * both lists are sorted on some common field (as determined by a comparison
+ * expression <b>cmpexpr</b>), and such that one list (<b>sl1</b>) has no
+ * duplicates on the common field, loop through the lists in lockstep, and
+ * execute <b>unmatched_var2</b> on items in var2 that do not appear in
+ * var1.
+ *
+ * WARNING: It isn't safe to add remove elements from either list while the
+ * loop is in progress.
+ *
+ * Example use:
+ * SMARTLIST_FOREACH_JOIN(routerstatus_list, routerstatus_t *, rs,
+ * routerinfo_list, routerinfo_t *, ri,
+ * tor_memcmp(rs->identity_digest, ri->identity_digest, 20),
+ * log_info(LD_GENERAL,"No match for %s", ri->nickname)) {
+ * log_info(LD_GENERAL, "%s matches routerstatus %p", ri->nickname, rs);
+ * } SMARTLIST_FOREACH_JOIN_END(rs, ri);
+ **/
+/* The example above unpacks (approximately) to:
+ * int rs_sl_idx = 0, rs_sl_len = smartlist_len(routerstatus_list);
+ * int ri_sl_idx, ri_sl_len = smartlist_len(routerinfo_list);
+ * int rs_ri_cmp;
+ * routerstatus_t *rs;
+ * routerinfo_t *ri;
+ * for (; ri_sl_idx < ri_sl_len; ++ri_sl_idx) {
+ * ri = smartlist_get(routerinfo_list, ri_sl_idx);
+ * while (rs_sl_idx < rs_sl_len) {
+ * rs = smartlist_get(routerstatus_list, rs_sl_idx);
+ * rs_ri_cmp = tor_memcmp(rs->identity_digest, ri->identity_digest, 20);
+ * if (rs_ri_cmp > 0) {
+ * break;
+ * } else if (rs_ri_cmp == 0) {
+ * goto matched_ri;
+ * } else {
+ * ++rs_sl_idx;
+ * }
+ * }
+ * log_info(LD_GENERAL,"No match for %s", ri->nickname);
+ * continue;
+ * matched_ri: {
+ * log_info(LD_GENERAL,"%s matches with routerstatus %p",ri->nickname,rs);
+ * }
+ * }
+ */
+#define SMARTLIST_FOREACH_JOIN(sl1, type1, var1, sl2, type2, var2, \
+ cmpexpr, unmatched_var2) \
+ STMT_BEGIN \
+ int var1 ## _sl_idx = 0, var1 ## _sl_len=(sl1)->num_used; \
+ int var2 ## _sl_idx = 0, var2 ## _sl_len=(sl2)->num_used; \
+ int var1 ## _ ## var2 ## _cmp; \
+ type1 var1; \
+ type2 var2; \
+ for (; var2##_sl_idx < var2##_sl_len; ++var2##_sl_idx) { \
+ var2 = (sl2)->list[var2##_sl_idx]; \
+ while (var1##_sl_idx < var1##_sl_len) { \
+ var1 = (sl1)->list[var1##_sl_idx]; \
+ var1##_##var2##_cmp = (cmpexpr); \
+ if (var1##_##var2##_cmp > 0) { \
+ break; \
+ } else if (var1##_##var2##_cmp == 0) { \
+ goto matched_##var2; \
+ } else { \
+ ++var1##_sl_idx; \
+ } \
+ } \
+ /* Ran out of v1, or no match for var2. */ \
+ unmatched_var2; \
+ continue; \
+ matched_##var2: ; \
+
+#define SMARTLIST_FOREACH_JOIN_END(var1, var2) \
+ } \
+ STMT_END
+
+#define DECLARE_MAP_FNS(maptype, keytype, prefix) \
+ typedef struct maptype maptype; \
+ typedef struct prefix##entry_t *prefix##iter_t; \
+ MOCK_DECL(maptype*, prefix##new, (void)); \
+ void* prefix##set(maptype *map, keytype key, void *val); \
+ void* prefix##get(const maptype *map, keytype key); \
+ void* prefix##remove(maptype *map, keytype key); \
+ MOCK_DECL(void, prefix##free_, (maptype *map, void (*free_val)(void*))); \
+ int prefix##isempty(const maptype *map); \
+ int prefix##size(const maptype *map); \
+ prefix##iter_t *prefix##iter_init(maptype *map); \
+ prefix##iter_t *prefix##iter_next(maptype *map, prefix##iter_t *iter); \
+ prefix##iter_t *prefix##iter_next_rmv(maptype *map, prefix##iter_t *iter); \
+ void prefix##iter_get(prefix##iter_t *iter, keytype *keyp, void **valp); \
+ int prefix##iter_done(prefix##iter_t *iter); \
+ void prefix##assert_ok(const maptype *map)
+
+/* Map from const char * to void *. Implemented with a hash table. */
+DECLARE_MAP_FNS(strmap_t, const char *, strmap_);
+/* Map from const char[DIGEST_LEN] to void *. Implemented with a hash table. */
+DECLARE_MAP_FNS(digestmap_t, const char *, digestmap_);
+/* Map from const uint8_t[DIGEST256_LEN] to void *. Implemented with a hash
+ * table. */
+DECLARE_MAP_FNS(digest256map_t, const uint8_t *, digest256map_);
+
+#define MAP_FREE_AND_NULL(maptype, map, fn) \
+ do { \
+ maptype ## _free_((map), (fn)); \
+ (map) = NULL; \
+ } while (0)
+
+#define strmap_free(map, fn) MAP_FREE_AND_NULL(strmap, (map), (fn))
+#define digestmap_free(map, fn) MAP_FREE_AND_NULL(digestmap, (map), (fn))
+#define digest256map_free(map, fn) MAP_FREE_AND_NULL(digest256map, (map), (fn))
+
+#undef DECLARE_MAP_FNS
+
+/** Iterates over the key-value pairs in a map <b>map</b> in order.
+ * <b>prefix</b> is as for DECLARE_MAP_FNS (i.e., strmap_ or digestmap_).
+ * The map's keys and values are of type keytype and valtype respectively;
+ * each iteration assigns them to keyvar and valvar.
+ *
+ * Example use:
+ * MAP_FOREACH(digestmap_, m, const char *, k, routerinfo_t *, r) {
+ * // use k and r
+ * } MAP_FOREACH_END.
+ */
+/* Unpacks to, approximately:
+ * {
+ * digestmap_iter_t *k_iter;
+ * for (k_iter = digestmap_iter_init(m); !digestmap_iter_done(k_iter);
+ * k_iter = digestmap_iter_next(m, k_iter)) {
+ * const char *k;
+ * void *r_voidp;
+ * routerinfo_t *r;
+ * digestmap_iter_get(k_iter, &k, &r_voidp);
+ * r = r_voidp;
+ * // use k and r
+ * }
+ * }
+ */
+#define MAP_FOREACH(prefix, map, keytype, keyvar, valtype, valvar) \
+ STMT_BEGIN \
+ prefix##iter_t *keyvar##_iter; \
+ for (keyvar##_iter = prefix##iter_init(map); \
+ !prefix##iter_done(keyvar##_iter); \
+ keyvar##_iter = prefix##iter_next(map, keyvar##_iter)) { \
+ keytype keyvar; \
+ void *valvar##_voidp; \
+ valtype valvar; \
+ prefix##iter_get(keyvar##_iter, &keyvar, &valvar##_voidp); \
+ valvar = valvar##_voidp;
+
+/** As MAP_FOREACH, except allows members to be removed from the map
+ * during the iteration via MAP_DEL_CURRENT. Example use:
+ *
+ * Example use:
+ * MAP_FOREACH(digestmap_, m, const char *, k, routerinfo_t *, r) {
+ * if (is_very_old(r))
+ * MAP_DEL_CURRENT(k);
+ * } MAP_FOREACH_END.
+ **/
+/* Unpacks to, approximately:
+ * {
+ * digestmap_iter_t *k_iter;
+ * int k_del=0;
+ * for (k_iter = digestmap_iter_init(m); !digestmap_iter_done(k_iter);
+ * k_iter = k_del ? digestmap_iter_next(m, k_iter)
+ * : digestmap_iter_next_rmv(m, k_iter)) {
+ * const char *k;
+ * void *r_voidp;
+ * routerinfo_t *r;
+ * k_del=0;
+ * digestmap_iter_get(k_iter, &k, &r_voidp);
+ * r = r_voidp;
+ * if (is_very_old(r)) {
+ * k_del = 1;
+ * }
+ * }
+ * }
+ */
+#define MAP_FOREACH_MODIFY(prefix, map, keytype, keyvar, valtype, valvar) \
+ STMT_BEGIN \
+ prefix##iter_t *keyvar##_iter; \
+ int keyvar##_del=0; \
+ for (keyvar##_iter = prefix##iter_init(map); \
+ !prefix##iter_done(keyvar##_iter); \
+ keyvar##_iter = keyvar##_del ? \
+ prefix##iter_next_rmv(map, keyvar##_iter) : \
+ prefix##iter_next(map, keyvar##_iter)) { \
+ keytype keyvar; \
+ void *valvar##_voidp; \
+ valtype valvar; \
+ keyvar##_del=0; \
+ prefix##iter_get(keyvar##_iter, &keyvar, &valvar##_voidp); \
+ valvar = valvar##_voidp;
+
+/** Used with MAP_FOREACH_MODIFY to remove the currently-iterated-upon
+ * member of the map. */
+#define MAP_DEL_CURRENT(keyvar) \
+ STMT_BEGIN \
+ keyvar##_del = 1; \
+ STMT_END
+
+/** Used to end a MAP_FOREACH() block. */
+#define MAP_FOREACH_END } STMT_END ;
+
+/** As MAP_FOREACH, but does not require declaration of prefix or keytype.
+ * Example use:
+ * DIGESTMAP_FOREACH(m, k, routerinfo_t *, r) {
+ * // use k and r
+ * } DIGESTMAP_FOREACH_END.
+ */
+#define DIGESTMAP_FOREACH(map, keyvar, valtype, valvar) \
+ MAP_FOREACH(digestmap_, map, const char *, keyvar, valtype, valvar)
+
+/** As MAP_FOREACH_MODIFY, but does not require declaration of prefix or
+ * keytype.
+ * Example use:
+ * DIGESTMAP_FOREACH_MODIFY(m, k, routerinfo_t *, r) {
+ * if (is_very_old(r))
+ * MAP_DEL_CURRENT(k);
+ * } DIGESTMAP_FOREACH_END.
+ */
+#define DIGESTMAP_FOREACH_MODIFY(map, keyvar, valtype, valvar) \
+ MAP_FOREACH_MODIFY(digestmap_, map, const char *, keyvar, valtype, valvar)
+/** Used to end a DIGESTMAP_FOREACH() block. */
+#define DIGESTMAP_FOREACH_END MAP_FOREACH_END
+
+#define DIGEST256MAP_FOREACH(map, keyvar, valtype, valvar) \
+ MAP_FOREACH(digest256map_, map, const uint8_t *, keyvar, valtype, valvar)
+#define DIGEST256MAP_FOREACH_MODIFY(map, keyvar, valtype, valvar) \
+ MAP_FOREACH_MODIFY(digest256map_, map, const uint8_t *, \
+ keyvar, valtype, valvar)
+#define DIGEST256MAP_FOREACH_END MAP_FOREACH_END
+
+#define STRMAP_FOREACH(map, keyvar, valtype, valvar) \
+ MAP_FOREACH(strmap_, map, const char *, keyvar, valtype, valvar)
+#define STRMAP_FOREACH_MODIFY(map, keyvar, valtype, valvar) \
+ MAP_FOREACH_MODIFY(strmap_, map, const char *, keyvar, valtype, valvar)
+#define STRMAP_FOREACH_END MAP_FOREACH_END
+
+void* strmap_set_lc(strmap_t *map, const char *key, void *val);
+void* strmap_get_lc(const strmap_t *map, const char *key);
+void* strmap_remove_lc(strmap_t *map, const char *key);
+
+#define DECLARE_TYPED_DIGESTMAP_FNS(prefix, maptype, valtype) \
+ typedef struct maptype maptype; \
+ typedef struct prefix##iter_t *prefix##iter_t; \
+ ATTR_UNUSED static inline maptype* \
+ prefix##new(void) \
+ { \
+ return (maptype*)digestmap_new(); \
+ } \
+ ATTR_UNUSED static inline digestmap_t* \
+ prefix##to_digestmap(maptype *map) \
+ { \
+ return (digestmap_t*)map; \
+ } \
+ ATTR_UNUSED static inline valtype* \
+ prefix##get(maptype *map, const char *key) \
+ { \
+ return (valtype*)digestmap_get((digestmap_t*)map, key); \
+ } \
+ ATTR_UNUSED static inline valtype* \
+ prefix##set(maptype *map, const char *key, valtype *val) \
+ { \
+ return (valtype*)digestmap_set((digestmap_t*)map, key, val); \
+ } \
+ ATTR_UNUSED static inline valtype* \
+ prefix##remove(maptype *map, const char *key) \
+ { \
+ return (valtype*)digestmap_remove((digestmap_t*)map, key); \
+ } \
+ ATTR_UNUSED static inline void \
+ prefix##f##ree_(maptype *map, void (*free_val)(void*)) \
+ { \
+ digestmap_free_((digestmap_t*)map, free_val); \
+ } \
+ ATTR_UNUSED static inline int \
+ prefix##isempty(maptype *map) \
+ { \
+ return digestmap_isempty((digestmap_t*)map); \
+ } \
+ ATTR_UNUSED static inline int \
+ prefix##size(maptype *map) \
+ { \
+ return digestmap_size((digestmap_t*)map); \
+ } \
+ ATTR_UNUSED static inline \
+ prefix##iter_t *prefix##iter_init(maptype *map) \
+ { \
+ return (prefix##iter_t*) digestmap_iter_init((digestmap_t*)map); \
+ } \
+ ATTR_UNUSED static inline \
+ prefix##iter_t *prefix##iter_next(maptype *map, prefix##iter_t *iter) \
+ { \
+ return (prefix##iter_t*) digestmap_iter_next( \
+ (digestmap_t*)map, (digestmap_iter_t*)iter); \
+ } \
+ ATTR_UNUSED static inline prefix##iter_t* \
+ prefix##iter_next_rmv(maptype *map, prefix##iter_t *iter) \
+ { \
+ return (prefix##iter_t*) digestmap_iter_next_rmv( \
+ (digestmap_t*)map, (digestmap_iter_t*)iter); \
+ } \
+ ATTR_UNUSED static inline void \
+ prefix##iter_get(prefix##iter_t *iter, \
+ const char **keyp, \
+ valtype **valp) \
+ { \
+ void *v; \
+ digestmap_iter_get((digestmap_iter_t*) iter, keyp, &v); \
+ *valp = v; \
+ } \
+ ATTR_UNUSED static inline int \
+ prefix##iter_done(prefix##iter_t *iter) \
+ { \
+ return digestmap_iter_done((digestmap_iter_t*)iter); \
+ }
+
+#if SIZEOF_INT == 4
+#define BITARRAY_SHIFT 5
+#elif SIZEOF_INT == 8
+#define BITARRAY_SHIFT 6
+#else
+#error "int is neither 4 nor 8 bytes. I can't deal with that."
+#endif /* SIZEOF_INT == 4 || ... */
+#define BITARRAY_MASK ((1u<<BITARRAY_SHIFT)-1)
+
+/** A random-access array of one-bit-wide elements. */
+typedef unsigned int bitarray_t;
+/** Create a new bit array that can hold <b>n_bits</b> bits. */
+static inline bitarray_t *
+bitarray_init_zero(unsigned int n_bits)
+{
+ /* round up to the next int. */
+ size_t sz = (n_bits+BITARRAY_MASK) >> BITARRAY_SHIFT;
+ return tor_calloc(sz, sizeof(unsigned int));
+}
+/** Expand <b>ba</b> from holding <b>n_bits_old</b> to <b>n_bits_new</b>,
+ * clearing all new bits. Returns a possibly changed pointer to the
+ * bitarray. */
+static inline bitarray_t *
+bitarray_expand(bitarray_t *ba,
+ unsigned int n_bits_old, unsigned int n_bits_new)
+{
+ size_t sz_old = (n_bits_old+BITARRAY_MASK) >> BITARRAY_SHIFT;
+ size_t sz_new = (n_bits_new+BITARRAY_MASK) >> BITARRAY_SHIFT;
+ char *ptr;
+ if (sz_new <= sz_old)
+ return ba;
+ ptr = tor_reallocarray(ba, sz_new, sizeof(unsigned int));
+ /* This memset does nothing to the older excess bytes. But they were
+ * already set to 0 by bitarry_init_zero. */
+ memset(ptr+sz_old*sizeof(unsigned int), 0,
+ (sz_new-sz_old)*sizeof(unsigned int));
+ return (bitarray_t*) ptr;
+}
+/** Free the bit array <b>ba</b>. */
+static inline void
+bitarray_free_(bitarray_t *ba)
+{
+ tor_free(ba);
+}
+#define bitarray_free(ba) FREE_AND_NULL(bitarray_t, bitarray_free_, (ba))
+
+/** Set the <b>bit</b>th bit in <b>b</b> to 1. */
+static inline void
+bitarray_set(bitarray_t *b, int bit)
+{
+ b[bit >> BITARRAY_SHIFT] |= (1u << (bit & BITARRAY_MASK));
+}
+/** Set the <b>bit</b>th bit in <b>b</b> to 0. */
+static inline void
+bitarray_clear(bitarray_t *b, int bit)
+{
+ b[bit >> BITARRAY_SHIFT] &= ~ (1u << (bit & BITARRAY_MASK));
+}
+/** Return true iff <b>bit</b>th bit in <b>b</b> is nonzero. NOTE: does
+ * not necessarily return 1 on true. */
+static inline unsigned int
+bitarray_is_set(bitarray_t *b, int bit)
+{
+ return b[bit >> BITARRAY_SHIFT] & (1u << (bit & BITARRAY_MASK));
+}
+
+/** A set of digests, implemented as a Bloom filter. */
+typedef struct {
+ int mask; /**< One less than the number of bits in <b>ba</b>; always one less
+ * than a power of two. */
+ bitarray_t *ba; /**< A bit array to implement the Bloom filter. */
+} digestset_t;
+
+#define BIT(n) ((n) & set->mask)
+/** Add the digest <b>digest</b> to <b>set</b>. */
+static inline void
+digestset_add(digestset_t *set, const char *digest)
+{
+ const uint64_t x = siphash24g(digest, 20);
+ const uint32_t d1 = (uint32_t) x;
+ const uint32_t d2 = (uint32_t)( (x>>16) + x);
+ const uint32_t d3 = (uint32_t)( (x>>32) + x);
+ const uint32_t d4 = (uint32_t)( (x>>48) + x);
+ bitarray_set(set->ba, BIT(d1));
+ bitarray_set(set->ba, BIT(d2));
+ bitarray_set(set->ba, BIT(d3));
+ bitarray_set(set->ba, BIT(d4));
+}
+
+/** If <b>digest</b> is in <b>set</b>, return nonzero. Otherwise,
+ * <em>probably</em> return zero. */
+static inline int
+digestset_contains(const digestset_t *set, const char *digest)
+{
+ const uint64_t x = siphash24g(digest, 20);
+ const uint32_t d1 = (uint32_t) x;
+ const uint32_t d2 = (uint32_t)( (x>>16) + x);
+ const uint32_t d3 = (uint32_t)( (x>>32) + x);
+ const uint32_t d4 = (uint32_t)( (x>>48) + x);
+ return bitarray_is_set(set->ba, BIT(d1)) &&
+ bitarray_is_set(set->ba, BIT(d2)) &&
+ bitarray_is_set(set->ba, BIT(d3)) &&
+ bitarray_is_set(set->ba, BIT(d4));
+}
+#undef BIT
+
+digestset_t *digestset_new(int max_elements);
+void digestset_free_(digestset_t* set);
+#define digestset_free(set) FREE_AND_NULL(digestset_t, digestset_free_, (set))
+
+/* These functions, given an <b>array</b> of <b>n_elements</b>, return the
+ * <b>nth</b> lowest element. <b>nth</b>=0 gives the lowest element;
+ * <b>n_elements</b>-1 gives the highest; and (<b>n_elements</b>-1) / 2 gives
+ * the median. As a side effect, the elements of <b>array</b> are sorted. */
+int find_nth_int(int *array, int n_elements, int nth);
+time_t find_nth_time(time_t *array, int n_elements, int nth);
+double find_nth_double(double *array, int n_elements, int nth);
+int32_t find_nth_int32(int32_t *array, int n_elements, int nth);
+uint32_t find_nth_uint32(uint32_t *array, int n_elements, int nth);
+long find_nth_long(long *array, int n_elements, int nth);
+static inline int
+median_int(int *array, int n_elements)
+{
+ return find_nth_int(array, n_elements, (n_elements-1)/2);
+}
+static inline time_t
+median_time(time_t *array, int n_elements)
+{
+ return find_nth_time(array, n_elements, (n_elements-1)/2);
+}
+static inline double
+median_double(double *array, int n_elements)
+{
+ return find_nth_double(array, n_elements, (n_elements-1)/2);
+}
+static inline uint32_t
+median_uint32(uint32_t *array, int n_elements)
+{
+ return find_nth_uint32(array, n_elements, (n_elements-1)/2);
+}
+static inline int32_t
+median_int32(int32_t *array, int n_elements)
+{
+ return find_nth_int32(array, n_elements, (n_elements-1)/2);
+}
+
+static inline uint32_t
+third_quartile_uint32(uint32_t *array, int n_elements)
+{
+ return find_nth_uint32(array, n_elements, (n_elements*3)/4);
+}
+
+#endif /* !defined(TOR_CONTAINER_H) */
+
diff --git a/src/common/crypto.c b/src/common/crypto.c
new file mode 100644
index 0000000000..e148878be0
--- /dev/null
+++ b/src/common/crypto.c
@@ -0,0 +1,1124 @@
+/* Copyright (c) 2001, Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file crypto.c
+ * \brief Wrapper functions to present a consistent interface to
+ * public-key and symmetric cryptography operations from OpenSSL and
+ * other places.
+ **/
+
+#include "orconfig.h"
+
+#ifdef _WIN32
+#include <winsock2.h>
+#include <windows.h>
+#include <wincrypt.h>
+/* Windows defines this; so does OpenSSL 0.9.8h and later. We don't actually
+ * use either definition. */
+#undef OCSP_RESPONSE
+#endif /* defined(_WIN32) */
+
+#define CRYPTO_PRIVATE
+#include "compat_openssl.h"
+#include "crypto.h"
+#include "crypto_curve25519.h"
+#include "crypto_digest.h"
+#include "crypto_ed25519.h"
+#include "crypto_format.h"
+#include "crypto_rand.h"
+#include "crypto_rsa.h"
+#include "crypto_util.h"
+
+DISABLE_GCC_WARNING(redundant-decls)
+
+#include <openssl/err.h>
+#include <openssl/evp.h>
+#include <openssl/engine.h>
+#include <openssl/bn.h>
+#include <openssl/dh.h>
+#include <openssl/conf.h>
+#include <openssl/hmac.h>
+#include <openssl/ssl.h>
+
+ENABLE_GCC_WARNING(redundant-decls)
+
+#if __GNUC__ && GCC_VERSION >= 402
+#if GCC_VERSION >= 406
+#pragma GCC diagnostic pop
+#else
+#pragma GCC diagnostic warning "-Wredundant-decls"
+#endif
+#endif /* __GNUC__ && GCC_VERSION >= 402 */
+
+#ifdef HAVE_CTYPE_H
+#include <ctype.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
+#ifdef HAVE_SYS_RANDOM_H
+#include <sys/random.h>
+#endif
+
+#include "torlog.h"
+#include "torint.h"
+#include "aes.h"
+#include "util.h"
+#include "container.h"
+#include "compat.h"
+#include "sandbox.h"
+#include "util_format.h"
+
+#include "keccak-tiny/keccak-tiny.h"
+
+/** A structure to hold the first half (x, g^x) of a Diffie-Hellman handshake
+ * while we're waiting for the second.*/
+struct crypto_dh_t {
+ DH *dh; /**< The openssl DH object */
+};
+
+static int tor_check_dh_key(int severity, const BIGNUM *bn);
+
+/** Boolean: has OpenSSL's crypto been initialized? */
+static int crypto_early_initialized_ = 0;
+
+/** Boolean: has OpenSSL's crypto been initialized? */
+static int crypto_global_initialized_ = 0;
+
+/** Log all pending crypto errors at level <b>severity</b>. Use
+ * <b>doing</b> to describe our current activities.
+ */
+static void
+crypto_log_errors(int severity, const char *doing)
+{
+ unsigned long err;
+ const char *msg, *lib, *func;
+ while ((err = ERR_get_error()) != 0) {
+ msg = (const char*)ERR_reason_error_string(err);
+ lib = (const char*)ERR_lib_error_string(err);
+ func = (const char*)ERR_func_error_string(err);
+ if (!msg) msg = "(null)";
+ if (!lib) lib = "(null)";
+ if (!func) func = "(null)";
+ if (BUG(!doing)) doing = "(null)";
+ tor_log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)",
+ doing, msg, lib, func);
+ }
+}
+
+#ifndef DISABLE_ENGINES
+/** Log any OpenSSL engines we're using at NOTICE. */
+static void
+log_engine(const char *fn, ENGINE *e)
+{
+ if (e) {
+ const char *name, *id;
+ name = ENGINE_get_name(e);
+ id = ENGINE_get_id(e);
+ log_notice(LD_CRYPTO, "Default OpenSSL engine for %s is %s [%s]",
+ fn, name?name:"?", id?id:"?");
+ } else {
+ log_info(LD_CRYPTO, "Using default implementation for %s", fn);
+ }
+}
+#endif /* !defined(DISABLE_ENGINES) */
+
+#ifndef DISABLE_ENGINES
+/** Try to load an engine in a shared library via fully qualified path.
+ */
+static ENGINE *
+try_load_engine(const char *path, const char *engine)
+{
+ ENGINE *e = ENGINE_by_id("dynamic");
+ if (e) {
+ if (!ENGINE_ctrl_cmd_string(e, "ID", engine, 0) ||
+ !ENGINE_ctrl_cmd_string(e, "DIR_LOAD", "2", 0) ||
+ !ENGINE_ctrl_cmd_string(e, "DIR_ADD", path, 0) ||
+ !ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0)) {
+ ENGINE_free(e);
+ e = NULL;
+ }
+ }
+ return e;
+}
+#endif /* !defined(DISABLE_ENGINES) */
+
+static int have_seeded_siphash = 0;
+
+/** Set up the siphash key if we haven't already done so. */
+int
+crypto_init_siphash_key(void)
+{
+ struct sipkey key;
+ if (have_seeded_siphash)
+ return 0;
+
+ crypto_rand((char*) &key, sizeof(key));
+ siphash_set_global_key(&key);
+ have_seeded_siphash = 1;
+ return 0;
+}
+
+/** Initialize the crypto library. Return 0 on success, -1 on failure.
+ */
+int
+crypto_early_init(void)
+{
+ if (!crypto_early_initialized_) {
+
+ crypto_early_initialized_ = 1;
+
+#if OPENSSL_VERSION_NUMBER >= OPENSSL_V_SERIES(1,1,0)
+ OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS |
+ OPENSSL_INIT_LOAD_CRYPTO_STRINGS |
+ OPENSSL_INIT_ADD_ALL_CIPHERS |
+ OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
+#else
+ ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+#endif
+
+ setup_openssl_threading();
+
+ unsigned long version_num = OpenSSL_version_num();
+ const char *version_str = OpenSSL_version(OPENSSL_VERSION);
+ if (version_num == OPENSSL_VERSION_NUMBER &&
+ !strcmp(version_str, OPENSSL_VERSION_TEXT)) {
+ log_info(LD_CRYPTO, "OpenSSL version matches version from headers "
+ "(%lx: %s).", version_num, version_str);
+ } else {
+ log_warn(LD_CRYPTO, "OpenSSL version from headers does not match the "
+ "version we're running with. If you get weird crashes, that "
+ "might be why. (Compiled with %lx: %s; running with %lx: %s).",
+ (unsigned long)OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_TEXT,
+ version_num, version_str);
+ }
+
+ crypto_force_rand_ssleay();
+
+ if (crypto_seed_rng() < 0)
+ return -1;
+ if (crypto_init_siphash_key() < 0)
+ return -1;
+
+ curve25519_init();
+ ed25519_init();
+ }
+ return 0;
+}
+
+/** Initialize the crypto library. Return 0 on success, -1 on failure.
+ */
+int
+crypto_global_init(int useAccel, const char *accelName, const char *accelDir)
+{
+ if (!crypto_global_initialized_) {
+ if (crypto_early_init() < 0)
+ return -1;
+
+ crypto_global_initialized_ = 1;
+
+ if (useAccel > 0) {
+#ifdef DISABLE_ENGINES
+ (void)accelName;
+ (void)accelDir;
+ log_warn(LD_CRYPTO, "No OpenSSL hardware acceleration support enabled.");
+#else
+ ENGINE *e = NULL;
+
+ log_info(LD_CRYPTO, "Initializing OpenSSL engine support.");
+ ENGINE_load_builtin_engines();
+ ENGINE_register_all_complete();
+
+ if (accelName) {
+ if (accelDir) {
+ log_info(LD_CRYPTO, "Trying to load dynamic OpenSSL engine \"%s\""
+ " via path \"%s\".", accelName, accelDir);
+ e = try_load_engine(accelName, accelDir);
+ } else {
+ log_info(LD_CRYPTO, "Initializing dynamic OpenSSL engine \"%s\""
+ " acceleration support.", accelName);
+ e = ENGINE_by_id(accelName);
+ }
+ if (!e) {
+ log_warn(LD_CRYPTO, "Unable to load dynamic OpenSSL engine \"%s\".",
+ accelName);
+ } else {
+ log_info(LD_CRYPTO, "Loaded dynamic OpenSSL engine \"%s\".",
+ accelName);
+ }
+ }
+ if (e) {
+ log_info(LD_CRYPTO, "Loaded OpenSSL hardware acceleration engine,"
+ " setting default ciphers.");
+ ENGINE_set_default(e, ENGINE_METHOD_ALL);
+ }
+ /* Log, if available, the intersection of the set of algorithms
+ used by Tor and the set of algorithms available in the engine */
+ log_engine("RSA", ENGINE_get_default_RSA());
+ log_engine("DH", ENGINE_get_default_DH());
+#ifdef OPENSSL_1_1_API
+ log_engine("EC", ENGINE_get_default_EC());
+#else
+ log_engine("ECDH", ENGINE_get_default_ECDH());
+ log_engine("ECDSA", ENGINE_get_default_ECDSA());
+#endif /* defined(OPENSSL_1_1_API) */
+ log_engine("RAND", ENGINE_get_default_RAND());
+ log_engine("RAND (which we will not use)", ENGINE_get_default_RAND());
+ log_engine("SHA1", ENGINE_get_digest_engine(NID_sha1));
+ log_engine("3DES-CBC", ENGINE_get_cipher_engine(NID_des_ede3_cbc));
+ log_engine("AES-128-ECB", ENGINE_get_cipher_engine(NID_aes_128_ecb));
+ log_engine("AES-128-CBC", ENGINE_get_cipher_engine(NID_aes_128_cbc));
+#ifdef NID_aes_128_ctr
+ log_engine("AES-128-CTR", ENGINE_get_cipher_engine(NID_aes_128_ctr));
+#endif
+#ifdef NID_aes_128_gcm
+ log_engine("AES-128-GCM", ENGINE_get_cipher_engine(NID_aes_128_gcm));
+#endif
+ log_engine("AES-256-CBC", ENGINE_get_cipher_engine(NID_aes_256_cbc));
+#ifdef NID_aes_256_gcm
+ log_engine("AES-256-GCM", ENGINE_get_cipher_engine(NID_aes_256_gcm));
+#endif
+
+#endif /* defined(DISABLE_ENGINES) */
+ } else {
+ log_info(LD_CRYPTO, "NOT using OpenSSL engine support.");
+ }
+
+ if (crypto_force_rand_ssleay()) {
+ if (crypto_seed_rng() < 0)
+ return -1;
+ }
+
+ evaluate_evp_for_aes(-1);
+ evaluate_ctr_for_aes();
+ }
+ return 0;
+}
+
+/** Free crypto resources held by this thread. */
+void
+crypto_thread_cleanup(void)
+{
+#ifndef NEW_THREAD_API
+ ERR_remove_thread_state(NULL);
+#endif
+}
+
+/** Used by tortls.c: Get the DH* from a crypto_dh_t.
+ */
+DH *
+crypto_dh_get_dh_(crypto_dh_t *dh)
+{
+ return dh->dh;
+}
+
+/** Allocate and return a new symmetric cipher using the provided key and iv.
+ * The key is <b>bits</b> bits long; the IV is CIPHER_IV_LEN bytes. Both
+ * must be provided. Key length must be 128, 192, or 256 */
+crypto_cipher_t *
+crypto_cipher_new_with_iv_and_bits(const uint8_t *key,
+ const uint8_t *iv,
+ int bits)
+{
+ tor_assert(key);
+ tor_assert(iv);
+
+ return aes_new_cipher((const uint8_t*)key, (const uint8_t*)iv, bits);
+}
+
+/** Allocate and return a new symmetric cipher using the provided key and iv.
+ * The key is CIPHER_KEY_LEN bytes; the IV is CIPHER_IV_LEN bytes. Both
+ * must be provided.
+ */
+crypto_cipher_t *
+crypto_cipher_new_with_iv(const char *key, const char *iv)
+{
+ return crypto_cipher_new_with_iv_and_bits((uint8_t*)key, (uint8_t*)iv,
+ 128);
+}
+
+/** Return a new crypto_cipher_t with the provided <b>key</b> and an IV of all
+ * zero bytes and key length <b>bits</b>. Key length must be 128, 192, or
+ * 256. */
+crypto_cipher_t *
+crypto_cipher_new_with_bits(const char *key, int bits)
+{
+ char zeroiv[CIPHER_IV_LEN];
+ memset(zeroiv, 0, sizeof(zeroiv));
+ return crypto_cipher_new_with_iv_and_bits((uint8_t*)key, (uint8_t*)zeroiv,
+ bits);
+}
+
+/** Return a new crypto_cipher_t with the provided <b>key</b> (of
+ * CIPHER_KEY_LEN bytes) and an IV of all zero bytes. */
+crypto_cipher_t *
+crypto_cipher_new(const char *key)
+{
+ return crypto_cipher_new_with_bits(key, 128);
+}
+
+/** Free a symmetric cipher.
+ */
+void
+crypto_cipher_free_(crypto_cipher_t *env)
+{
+ if (!env)
+ return;
+
+ aes_cipher_free(env);
+}
+
+/** Copy <b>in</b> to the <b>outlen</b>-byte buffer <b>out</b>, adding spaces
+ * every four characters. */
+void
+crypto_add_spaces_to_fp(char *out, size_t outlen, const char *in)
+{
+ int n = 0;
+ char *end = out+outlen;
+ tor_assert(outlen < SIZE_T_CEILING);
+
+ while (*in && out<end) {
+ *out++ = *in++;
+ if (++n == 4 && *in && out<end) {
+ n = 0;
+ *out++ = ' ';
+ }
+ }
+ tor_assert(out<end);
+ *out = '\0';
+}
+
+/* symmetric crypto */
+
+/** Encrypt <b>fromlen</b> bytes from <b>from</b> using the cipher
+ * <b>env</b>; on success, store the result to <b>to</b> and return 0.
+ * Does not check for failure.
+ */
+int
+crypto_cipher_encrypt(crypto_cipher_t *env, char *to,
+ const char *from, size_t fromlen)
+{
+ tor_assert(env);
+ tor_assert(env);
+ tor_assert(from);
+ tor_assert(fromlen);
+ tor_assert(to);
+ tor_assert(fromlen < SIZE_T_CEILING);
+
+ memcpy(to, from, fromlen);
+ aes_crypt_inplace(env, to, fromlen);
+ return 0;
+}
+
+/** Decrypt <b>fromlen</b> bytes from <b>from</b> using the cipher
+ * <b>env</b>; on success, store the result to <b>to</b> and return 0.
+ * Does not check for failure.
+ */
+int
+crypto_cipher_decrypt(crypto_cipher_t *env, char *to,
+ const char *from, size_t fromlen)
+{
+ tor_assert(env);
+ tor_assert(from);
+ tor_assert(to);
+ tor_assert(fromlen < SIZE_T_CEILING);
+
+ memcpy(to, from, fromlen);
+ aes_crypt_inplace(env, to, fromlen);
+ return 0;
+}
+
+/** Encrypt <b>len</b> bytes on <b>from</b> using the cipher in <b>env</b>;
+ * on success. Does not check for failure.
+ */
+void
+crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *buf, size_t len)
+{
+ tor_assert(len < SIZE_T_CEILING);
+ aes_crypt_inplace(env, buf, len);
+}
+
+/** Encrypt <b>fromlen</b> bytes (at least 1) from <b>from</b> with the key in
+ * <b>key</b> to the buffer in <b>to</b> of length
+ * <b>tolen</b>. <b>tolen</b> must be at least <b>fromlen</b> plus
+ * CIPHER_IV_LEN bytes for the initialization vector. On success, return the
+ * number of bytes written, on failure, return -1.
+ */
+int
+crypto_cipher_encrypt_with_iv(const char *key,
+ char *to, size_t tolen,
+ const char *from, size_t fromlen)
+{
+ crypto_cipher_t *cipher;
+ tor_assert(from);
+ tor_assert(to);
+ tor_assert(fromlen < INT_MAX);
+
+ if (fromlen < 1)
+ return -1;
+ if (tolen < fromlen + CIPHER_IV_LEN)
+ return -1;
+
+ char iv[CIPHER_IV_LEN];
+ crypto_rand(iv, sizeof(iv));
+ cipher = crypto_cipher_new_with_iv(key, iv);
+
+ memcpy(to, iv, CIPHER_IV_LEN);
+ crypto_cipher_encrypt(cipher, to+CIPHER_IV_LEN, from, fromlen);
+ crypto_cipher_free(cipher);
+ memwipe(iv, 0, sizeof(iv));
+ return (int)(fromlen + CIPHER_IV_LEN);
+}
+
+/** Decrypt <b>fromlen</b> bytes (at least 1+CIPHER_IV_LEN) from <b>from</b>
+ * with the key in <b>key</b> to the buffer in <b>to</b> of length
+ * <b>tolen</b>. <b>tolen</b> must be at least <b>fromlen</b> minus
+ * CIPHER_IV_LEN bytes for the initialization vector. On success, return the
+ * number of bytes written, on failure, return -1.
+ */
+int
+crypto_cipher_decrypt_with_iv(const char *key,
+ char *to, size_t tolen,
+ const char *from, size_t fromlen)
+{
+ crypto_cipher_t *cipher;
+ tor_assert(key);
+ tor_assert(from);
+ tor_assert(to);
+ tor_assert(fromlen < INT_MAX);
+
+ if (fromlen <= CIPHER_IV_LEN)
+ return -1;
+ if (tolen < fromlen - CIPHER_IV_LEN)
+ return -1;
+
+ cipher = crypto_cipher_new_with_iv(key, from);
+
+ crypto_cipher_encrypt(cipher, to, from+CIPHER_IV_LEN, fromlen-CIPHER_IV_LEN);
+ crypto_cipher_free(cipher);
+ return (int)(fromlen - CIPHER_IV_LEN);
+}
+
+/* DH */
+
+/** Our DH 'g' parameter */
+#define DH_GENERATOR 2
+
+/** Shared P parameter for our circuit-crypto DH key exchanges. */
+static BIGNUM *dh_param_p = NULL;
+/** Shared P parameter for our TLS DH key exchanges. */
+static BIGNUM *dh_param_p_tls = NULL;
+/** Shared G parameter for our DH key exchanges. */
+static BIGNUM *dh_param_g = NULL;
+
+/** Validate a given set of Diffie-Hellman parameters. This is moderately
+ * computationally expensive (milliseconds), so should only be called when
+ * the DH parameters change. Returns 0 on success, * -1 on failure.
+ */
+static int
+crypto_validate_dh_params(const BIGNUM *p, const BIGNUM *g)
+{
+ DH *dh = NULL;
+ int ret = -1;
+
+ /* Copy into a temporary DH object, just so that DH_check() can be called. */
+ if (!(dh = DH_new()))
+ goto out;
+#ifdef OPENSSL_1_1_API
+ BIGNUM *dh_p, *dh_g;
+ if (!(dh_p = BN_dup(p)))
+ goto out;
+ if (!(dh_g = BN_dup(g)))
+ goto out;
+ if (!DH_set0_pqg(dh, dh_p, NULL, dh_g))
+ goto out;
+#else /* !(defined(OPENSSL_1_1_API)) */
+ if (!(dh->p = BN_dup(p)))
+ goto out;
+ if (!(dh->g = BN_dup(g)))
+ goto out;
+#endif /* defined(OPENSSL_1_1_API) */
+
+ /* Perform the validation. */
+ int codes = 0;
+ if (!DH_check(dh, &codes))
+ goto out;
+ if (BN_is_word(g, DH_GENERATOR_2)) {
+ /* Per https://wiki.openssl.org/index.php/Diffie-Hellman_parameters
+ *
+ * OpenSSL checks the prime is congruent to 11 when g = 2; while the
+ * IETF's primes are congruent to 23 when g = 2.
+ */
+ BN_ULONG residue = BN_mod_word(p, 24);
+ if (residue == 11 || residue == 23)
+ codes &= ~DH_NOT_SUITABLE_GENERATOR;
+ }
+ if (codes != 0) /* Specifics on why the params suck is irrelevant. */
+ goto out;
+
+ /* Things are probably not evil. */
+ ret = 0;
+
+ out:
+ if (dh)
+ DH_free(dh);
+ return ret;
+}
+
+/** Set the global Diffie-Hellman generator, used for both TLS and internal
+ * DH stuff.
+ */
+static void
+crypto_set_dh_generator(void)
+{
+ BIGNUM *generator;
+ int r;
+
+ if (dh_param_g)
+ return;
+
+ generator = BN_new();
+ tor_assert(generator);
+
+ r = BN_set_word(generator, DH_GENERATOR);
+ tor_assert(r);
+
+ dh_param_g = generator;
+}
+
+/** Set the global TLS Diffie-Hellman modulus. Use the Apache mod_ssl DH
+ * modulus. */
+void
+crypto_set_tls_dh_prime(void)
+{
+ BIGNUM *tls_prime = NULL;
+ int r;
+
+ /* If the space is occupied, free the previous TLS DH prime */
+ if (BUG(dh_param_p_tls)) {
+ /* LCOV_EXCL_START
+ *
+ * We shouldn't be calling this twice.
+ */
+ BN_clear_free(dh_param_p_tls);
+ dh_param_p_tls = NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ tls_prime = BN_new();
+ tor_assert(tls_prime);
+
+ /* This is the 1024-bit safe prime that Apache uses for its DH stuff; see
+ * modules/ssl/ssl_engine_dh.c; Apache also uses a generator of 2 with this
+ * prime.
+ */
+ r = BN_hex2bn(&tls_prime,
+ "D67DE440CBBBDC1936D693D34AFD0AD50C84D239A45F520BB88174CB98"
+ "BCE951849F912E639C72FB13B4B4D7177E16D55AC179BA420B2A29FE324A"
+ "467A635E81FF5901377BEDDCFD33168A461AAD3B72DAE8860078045B07A7"
+ "DBCA7874087D1510EA9FCC9DDD330507DD62DB88AEAA747DE0F4D6E2BD68"
+ "B0E7393E0F24218EB3");
+ tor_assert(r);
+
+ tor_assert(tls_prime);
+
+ dh_param_p_tls = tls_prime;
+ crypto_set_dh_generator();
+ tor_assert(0 == crypto_validate_dh_params(dh_param_p_tls, dh_param_g));
+}
+
+/** Initialize dh_param_p and dh_param_g if they are not already
+ * set. */
+static void
+init_dh_param(void)
+{
+ BIGNUM *circuit_dh_prime;
+ int r;
+ if (BUG(dh_param_p && dh_param_g))
+ return; // LCOV_EXCL_LINE This function isn't supposed to be called twice.
+
+ circuit_dh_prime = BN_new();
+ tor_assert(circuit_dh_prime);
+
+ /* This is from rfc2409, section 6.2. It's a safe prime, and
+ supposedly it equals:
+ 2^1024 - 2^960 - 1 + 2^64 * { [2^894 pi] + 129093 }.
+ */
+ r = BN_hex2bn(&circuit_dh_prime,
+ "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E08"
+ "8A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B"
+ "302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9"
+ "A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE6"
+ "49286651ECE65381FFFFFFFFFFFFFFFF");
+ tor_assert(r);
+
+ /* Set the new values as the global DH parameters. */
+ dh_param_p = circuit_dh_prime;
+ crypto_set_dh_generator();
+ tor_assert(0 == crypto_validate_dh_params(dh_param_p, dh_param_g));
+
+ if (!dh_param_p_tls) {
+ crypto_set_tls_dh_prime();
+ }
+}
+
+/** Number of bits to use when choosing the x or y value in a Diffie-Hellman
+ * handshake. Since we exponentiate by this value, choosing a smaller one
+ * lets our handhake go faster.
+ */
+#define DH_PRIVATE_KEY_BITS 320
+
+/** Allocate and return a new DH object for a key exchange. Returns NULL on
+ * failure.
+ */
+crypto_dh_t *
+crypto_dh_new(int dh_type)
+{
+ crypto_dh_t *res = tor_malloc_zero(sizeof(crypto_dh_t));
+
+ tor_assert(dh_type == DH_TYPE_CIRCUIT || dh_type == DH_TYPE_TLS ||
+ dh_type == DH_TYPE_REND);
+
+ if (!dh_param_p)
+ init_dh_param();
+
+ if (!(res->dh = DH_new()))
+ goto err;
+
+#ifdef OPENSSL_1_1_API
+ BIGNUM *dh_p = NULL, *dh_g = NULL;
+
+ if (dh_type == DH_TYPE_TLS) {
+ dh_p = BN_dup(dh_param_p_tls);
+ } else {
+ dh_p = BN_dup(dh_param_p);
+ }
+ if (!dh_p)
+ goto err;
+
+ dh_g = BN_dup(dh_param_g);
+ if (!dh_g) {
+ BN_free(dh_p);
+ goto err;
+ }
+
+ if (!DH_set0_pqg(res->dh, dh_p, NULL, dh_g)) {
+ goto err;
+ }
+
+ if (!DH_set_length(res->dh, DH_PRIVATE_KEY_BITS))
+ goto err;
+#else /* !(defined(OPENSSL_1_1_API)) */
+ if (dh_type == DH_TYPE_TLS) {
+ if (!(res->dh->p = BN_dup(dh_param_p_tls)))
+ goto err;
+ } else {
+ if (!(res->dh->p = BN_dup(dh_param_p)))
+ goto err;
+ }
+
+ if (!(res->dh->g = BN_dup(dh_param_g)))
+ goto err;
+
+ res->dh->length = DH_PRIVATE_KEY_BITS;
+#endif /* defined(OPENSSL_1_1_API) */
+
+ return res;
+
+ /* LCOV_EXCL_START
+ * This error condition is only reached when an allocation fails */
+ err:
+ crypto_log_errors(LOG_WARN, "creating DH object");
+ if (res->dh) DH_free(res->dh); /* frees p and g too */
+ tor_free(res);
+ return NULL;
+ /* LCOV_EXCL_STOP */
+}
+
+/** Return a copy of <b>dh</b>, sharing its internal state. */
+crypto_dh_t *
+crypto_dh_dup(const crypto_dh_t *dh)
+{
+ crypto_dh_t *dh_new = tor_malloc_zero(sizeof(crypto_dh_t));
+ tor_assert(dh);
+ tor_assert(dh->dh);
+ dh_new->dh = dh->dh;
+ DH_up_ref(dh->dh);
+ return dh_new;
+}
+
+/** Return the length of the DH key in <b>dh</b>, in bytes.
+ */
+int
+crypto_dh_get_bytes(crypto_dh_t *dh)
+{
+ tor_assert(dh);
+ return DH_size(dh->dh);
+}
+
+/** Generate \<x,g^x\> for our part of the key exchange. Return 0 on
+ * success, -1 on failure.
+ */
+int
+crypto_dh_generate_public(crypto_dh_t *dh)
+{
+#ifndef OPENSSL_1_1_API
+ again:
+#endif
+ if (!DH_generate_key(dh->dh)) {
+ /* LCOV_EXCL_START
+ * To test this we would need some way to tell openssl to break DH. */
+ crypto_log_errors(LOG_WARN, "generating DH key");
+ return -1;
+ /* LCOV_EXCL_STOP */
+ }
+#ifdef OPENSSL_1_1_API
+ /* OpenSSL 1.1.x doesn't appear to let you regenerate a DH key, without
+ * recreating the DH object. I have no idea what sort of aliasing madness
+ * can occur here, so do the check, and just bail on failure.
+ */
+ const BIGNUM *pub_key, *priv_key;
+ DH_get0_key(dh->dh, &pub_key, &priv_key);
+ if (tor_check_dh_key(LOG_WARN, pub_key)<0) {
+ log_warn(LD_CRYPTO, "Weird! Our own DH key was invalid. I guess once-in-"
+ "the-universe chances really do happen. Treating as a failure.");
+ return -1;
+ }
+#else /* !(defined(OPENSSL_1_1_API)) */
+ if (tor_check_dh_key(LOG_WARN, dh->dh->pub_key)<0) {
+ /* LCOV_EXCL_START
+ * If this happens, then openssl's DH implementation is busted. */
+ log_warn(LD_CRYPTO, "Weird! Our own DH key was invalid. I guess once-in-"
+ "the-universe chances really do happen. Trying again.");
+ /* Free and clear the keys, so OpenSSL will actually try again. */
+ BN_clear_free(dh->dh->pub_key);
+ BN_clear_free(dh->dh->priv_key);
+ dh->dh->pub_key = dh->dh->priv_key = NULL;
+ goto again;
+ /* LCOV_EXCL_STOP */
+ }
+#endif /* defined(OPENSSL_1_1_API) */
+ return 0;
+}
+
+/** Generate g^x as necessary, and write the g^x for the key exchange
+ * as a <b>pubkey_len</b>-byte value into <b>pubkey</b>. Return 0 on
+ * success, -1 on failure. <b>pubkey_len</b> must be \>= DH_BYTES.
+ */
+int
+crypto_dh_get_public(crypto_dh_t *dh, char *pubkey, size_t pubkey_len)
+{
+ int bytes;
+ tor_assert(dh);
+
+ const BIGNUM *dh_pub;
+
+#ifdef OPENSSL_1_1_API
+ const BIGNUM *dh_priv;
+ DH_get0_key(dh->dh, &dh_pub, &dh_priv);
+#else
+ dh_pub = dh->dh->pub_key;
+#endif /* defined(OPENSSL_1_1_API) */
+
+ if (!dh_pub) {
+ if (crypto_dh_generate_public(dh)<0)
+ return -1;
+ else {
+#ifdef OPENSSL_1_1_API
+ DH_get0_key(dh->dh, &dh_pub, &dh_priv);
+#else
+ dh_pub = dh->dh->pub_key;
+#endif
+ }
+ }
+
+ tor_assert(dh_pub);
+ bytes = BN_num_bytes(dh_pub);
+ tor_assert(bytes >= 0);
+ if (pubkey_len < (size_t)bytes) {
+ log_warn(LD_CRYPTO,
+ "Weird! pubkey_len (%d) was smaller than DH_BYTES (%d)",
+ (int) pubkey_len, bytes);
+ return -1;
+ }
+
+ memset(pubkey, 0, pubkey_len);
+ BN_bn2bin(dh_pub, (unsigned char*)(pubkey+(pubkey_len-bytes)));
+
+ return 0;
+}
+
+/** Check for bad Diffie-Hellman public keys (g^x). Return 0 if the key is
+ * okay (in the subgroup [2,p-2]), or -1 if it's bad.
+ * See http://www.cl.cam.ac.uk/ftp/users/rja14/psandqs.ps.gz for some tips.
+ */
+static int
+tor_check_dh_key(int severity, const BIGNUM *bn)
+{
+ BIGNUM *x;
+ char *s;
+ tor_assert(bn);
+ x = BN_new();
+ tor_assert(x);
+ if (BUG(!dh_param_p))
+ init_dh_param(); //LCOV_EXCL_LINE we already checked whether we did this.
+ BN_set_word(x, 1);
+ if (BN_cmp(bn,x)<=0) {
+ log_fn(severity, LD_CRYPTO, "DH key must be at least 2.");
+ goto err;
+ }
+ BN_copy(x,dh_param_p);
+ BN_sub_word(x, 1);
+ if (BN_cmp(bn,x)>=0) {
+ log_fn(severity, LD_CRYPTO, "DH key must be at most p-2.");
+ goto err;
+ }
+ BN_clear_free(x);
+ return 0;
+ err:
+ BN_clear_free(x);
+ s = BN_bn2hex(bn);
+ log_fn(severity, LD_CRYPTO, "Rejecting insecure DH key [%s]", s);
+ OPENSSL_free(s);
+ return -1;
+}
+
+/** Given a DH key exchange object, and our peer's value of g^y (as a
+ * <b>pubkey_len</b>-byte value in <b>pubkey</b>) generate
+ * <b>secret_bytes_out</b> bytes of shared key material and write them
+ * to <b>secret_out</b>. Return the number of bytes generated on success,
+ * or -1 on failure.
+ *
+ * (We generate key material by computing
+ * SHA1( g^xy || "\x00" ) || SHA1( g^xy || "\x01" ) || ...
+ * where || is concatenation.)
+ */
+ssize_t
+crypto_dh_compute_secret(int severity, crypto_dh_t *dh,
+ const char *pubkey, size_t pubkey_len,
+ char *secret_out, size_t secret_bytes_out)
+{
+ char *secret_tmp = NULL;
+ BIGNUM *pubkey_bn = NULL;
+ size_t secret_len=0, secret_tmp_len=0;
+ int result=0;
+ tor_assert(dh);
+ tor_assert(secret_bytes_out/DIGEST_LEN <= 255);
+ tor_assert(pubkey_len < INT_MAX);
+
+ if (!(pubkey_bn = BN_bin2bn((const unsigned char*)pubkey,
+ (int)pubkey_len, NULL)))
+ goto error;
+ if (tor_check_dh_key(severity, pubkey_bn)<0) {
+ /* Check for invalid public keys. */
+ log_fn(severity, LD_CRYPTO,"Rejected invalid g^x");
+ goto error;
+ }
+ secret_tmp_len = crypto_dh_get_bytes(dh);
+ secret_tmp = tor_malloc(secret_tmp_len);
+ result = DH_compute_key((unsigned char*)secret_tmp, pubkey_bn, dh->dh);
+ if (result < 0) {
+ log_warn(LD_CRYPTO,"DH_compute_key() failed.");
+ goto error;
+ }
+ secret_len = result;
+ if (crypto_expand_key_material_TAP((uint8_t*)secret_tmp, secret_len,
+ (uint8_t*)secret_out, secret_bytes_out)<0)
+ goto error;
+ secret_len = secret_bytes_out;
+
+ goto done;
+ error:
+ result = -1;
+ done:
+ crypto_log_errors(LOG_WARN, "completing DH handshake");
+ if (pubkey_bn)
+ BN_clear_free(pubkey_bn);
+ if (secret_tmp) {
+ memwipe(secret_tmp, 0, secret_tmp_len);
+ tor_free(secret_tmp);
+ }
+ if (result < 0)
+ return result;
+ else
+ return secret_len;
+}
+
+/** Given <b>key_in_len</b> bytes of negotiated randomness in <b>key_in</b>
+ * ("K"), expand it into <b>key_out_len</b> bytes of negotiated key material in
+ * <b>key_out</b> by taking the first <b>key_out_len</b> bytes of
+ * H(K | [00]) | H(K | [01]) | ....
+ *
+ * This is the key expansion algorithm used in the "TAP" circuit extension
+ * mechanism; it shouldn't be used for new protocols.
+ *
+ * Return 0 on success, -1 on failure.
+ */
+int
+crypto_expand_key_material_TAP(const uint8_t *key_in, size_t key_in_len,
+ uint8_t *key_out, size_t key_out_len)
+{
+ int i, r = -1;
+ uint8_t *cp, *tmp = tor_malloc(key_in_len+1);
+ uint8_t digest[DIGEST_LEN];
+
+ /* If we try to get more than this amount of key data, we'll repeat blocks.*/
+ tor_assert(key_out_len <= DIGEST_LEN*256);
+
+ memcpy(tmp, key_in, key_in_len);
+ for (cp = key_out, i=0; cp < key_out+key_out_len;
+ ++i, cp += DIGEST_LEN) {
+ tmp[key_in_len] = i;
+ if (crypto_digest((char*)digest, (const char *)tmp, key_in_len+1) < 0)
+ goto exit;
+ memcpy(cp, digest, MIN(DIGEST_LEN, key_out_len-(cp-key_out)));
+ }
+
+ r = 0;
+ exit:
+ memwipe(tmp, 0, key_in_len+1);
+ tor_free(tmp);
+ memwipe(digest, 0, sizeof(digest));
+ return r;
+}
+
+/** Expand some secret key material according to RFC5869, using SHA256 as the
+ * underlying hash. The <b>key_in_len</b> bytes at <b>key_in</b> are the
+ * secret key material; the <b>salt_in_len</b> bytes at <b>salt_in</b> and the
+ * <b>info_in_len</b> bytes in <b>info_in_len</b> are the algorithm's "salt"
+ * and "info" parameters respectively. On success, write <b>key_out_len</b>
+ * bytes to <b>key_out</b> and return 0. Assert on failure.
+ */
+int
+crypto_expand_key_material_rfc5869_sha256(
+ const uint8_t *key_in, size_t key_in_len,
+ const uint8_t *salt_in, size_t salt_in_len,
+ const uint8_t *info_in, size_t info_in_len,
+ uint8_t *key_out, size_t key_out_len)
+{
+ uint8_t prk[DIGEST256_LEN];
+ uint8_t tmp[DIGEST256_LEN + 128 + 1];
+ uint8_t mac[DIGEST256_LEN];
+ int i;
+ uint8_t *outp;
+ size_t tmp_len;
+
+ crypto_hmac_sha256((char*)prk,
+ (const char*)salt_in, salt_in_len,
+ (const char*)key_in, key_in_len);
+
+ /* If we try to get more than this amount of key data, we'll repeat blocks.*/
+ tor_assert(key_out_len <= DIGEST256_LEN * 256);
+ tor_assert(info_in_len <= 128);
+ memset(tmp, 0, sizeof(tmp));
+ outp = key_out;
+ i = 1;
+
+ while (key_out_len) {
+ size_t n;
+ if (i > 1) {
+ memcpy(tmp, mac, DIGEST256_LEN);
+ memcpy(tmp+DIGEST256_LEN, info_in, info_in_len);
+ tmp[DIGEST256_LEN+info_in_len] = i;
+ tmp_len = DIGEST256_LEN + info_in_len + 1;
+ } else {
+ memcpy(tmp, info_in, info_in_len);
+ tmp[info_in_len] = i;
+ tmp_len = info_in_len + 1;
+ }
+ crypto_hmac_sha256((char*)mac,
+ (const char*)prk, DIGEST256_LEN,
+ (const char*)tmp, tmp_len);
+ n = key_out_len < DIGEST256_LEN ? key_out_len : DIGEST256_LEN;
+ memcpy(outp, mac, n);
+ key_out_len -= n;
+ outp += n;
+ ++i;
+ }
+
+ memwipe(tmp, 0, sizeof(tmp));
+ memwipe(mac, 0, sizeof(mac));
+ return 0;
+}
+
+/** Free a DH key exchange object.
+ */
+void
+crypto_dh_free_(crypto_dh_t *dh)
+{
+ if (!dh)
+ return;
+ tor_assert(dh->dh);
+ DH_free(dh->dh);
+ tor_free(dh);
+}
+
+/** @{ */
+/** Uninitialize the crypto library. Return 0 on success. Does not detect
+ * failure.
+ */
+int
+crypto_global_cleanup(void)
+{
+#if OPENSSL_VERSION_NUMBER < OPENSSL_V_SERIES(1,1,0)
+ EVP_cleanup();
+#endif
+#ifndef NEW_THREAD_API
+ ERR_remove_thread_state(NULL);
+#endif
+#if OPENSSL_VERSION_NUMBER < OPENSSL_V_SERIES(1,1,0)
+ ERR_free_strings();
+#endif
+
+ if (dh_param_p)
+ BN_clear_free(dh_param_p);
+ if (dh_param_p_tls)
+ BN_clear_free(dh_param_p_tls);
+ if (dh_param_g)
+ BN_clear_free(dh_param_g);
+
+ dh_param_p = dh_param_p_tls = dh_param_g = NULL;
+
+#ifndef DISABLE_ENGINES
+#if OPENSSL_VERSION_NUMBER < OPENSSL_V_SERIES(1,1,0)
+ ENGINE_cleanup();
+#endif
+#endif
+
+ CONF_modules_unload(1);
+#if OPENSSL_VERSION_NUMBER < OPENSSL_V_SERIES(1,1,0)
+ CRYPTO_cleanup_all_ex_data();
+#endif
+
+ crypto_openssl_free_all();
+
+ crypto_early_initialized_ = 0;
+ crypto_global_initialized_ = 0;
+ have_seeded_siphash = 0;
+ siphash_unset_global_key();
+
+ return 0;
+}
+
+/** @} */
+
+#ifdef USE_DMALLOC
+/** Tell the crypto library to use Tor's allocation functions rather than
+ * calling libc's allocation functions directly. Return 0 on success, -1
+ * on failure. */
+int
+crypto_use_tor_alloc_functions(void)
+{
+ int r = CRYPTO_set_mem_ex_functions(tor_malloc_, tor_realloc_, tor_free_);
+ return r ? 0 : -1;
+}
+#endif /* defined(USE_DMALLOC) */
+
diff --git a/src/lib/crypt_ops/crypto.h b/src/common/crypto.h
index 58afafed83..c773557310 100644
--- a/src/lib/crypt_ops/crypto.h
+++ b/src/common/crypto.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -16,10 +16,10 @@
#include "orconfig.h"
#include <stdio.h>
-#include "lib/cc/torint.h"
-#include "common/compat.h"
-#include "common/util.h"
-#include "lib/crypt_ops/crypto_rsa.h"
+#include "torint.h"
+#include "compat.h"
+#include "util.h"
+#include "crypto_rsa.h"
/** Length of our symmetric cipher's keys of 128-bit. */
#define CIPHER_KEY_LEN 16
@@ -27,12 +27,15 @@
#define CIPHER_IV_LEN 16
/** Length of our symmetric cipher's keys of 256-bit. */
#define CIPHER256_KEY_LEN 32
+/** Length of our DH keys. */
+#define DH_BYTES (1024/8)
/** Length of encoded public key fingerprints, including space; but not
* including terminating NUL. */
#define FINGERPRINT_LEN 49
typedef struct aes_cnt_cipher crypto_cipher_t;
+typedef struct crypto_dh_t crypto_dh_t;
/* global state */
int crypto_init_siphash_key(void);
@@ -40,11 +43,15 @@ int crypto_early_init(void) ATTR_WUR;
int crypto_global_init(int hardwareAccel,
const char *accelName,
const char *accelPath) ATTR_WUR;
+#ifdef USE_DMALLOC
+int crypto_use_tor_alloc_functions(void);
+#endif
void crypto_thread_cleanup(void);
int crypto_global_cleanup(void);
/* environment setup */
+void crypto_set_tls_dh_prime(void);
crypto_cipher_t *crypto_cipher_new(const char *key);
crypto_cipher_t *crypto_cipher_new_with_bits(const char *key, int bits);
crypto_cipher_t *crypto_cipher_new_with_iv(const char *key, const char *iv);
@@ -71,6 +78,37 @@ int crypto_cipher_decrypt_with_iv(const char *key,
char *to, size_t tolen,
const char *from, size_t fromlen);
+/* Key negotiation */
+#define DH_TYPE_CIRCUIT 1
+#define DH_TYPE_REND 2
+#define DH_TYPE_TLS 3
+crypto_dh_t *crypto_dh_new(int dh_type);
+crypto_dh_t *crypto_dh_dup(const crypto_dh_t *dh);
+int crypto_dh_get_bytes(crypto_dh_t *dh);
+int crypto_dh_generate_public(crypto_dh_t *dh);
+int crypto_dh_get_public(crypto_dh_t *dh, char *pubkey_out,
+ size_t pubkey_out_len);
+ssize_t crypto_dh_compute_secret(int severity, crypto_dh_t *dh,
+ const char *pubkey, size_t pubkey_len,
+ char *secret_out, size_t secret_out_len);
+void crypto_dh_free_(crypto_dh_t *dh);
+#define crypto_dh_free(dh) FREE_AND_NULL(crypto_dh_t, crypto_dh_free_, (dh))
+
+int crypto_expand_key_material_TAP(const uint8_t *key_in,
+ size_t key_in_len,
+ uint8_t *key_out, size_t key_out_len);
+int crypto_expand_key_material_rfc5869_sha256(
+ const uint8_t *key_in, size_t key_in_len,
+ const uint8_t *salt_in, size_t salt_in_len,
+ const uint8_t *info_in, size_t info_in_len,
+ uint8_t *key_out, size_t key_out_len);
+
+/* Prototypes for private functions only used by tortls.c, crypto.c, and the
+ * unit tests. */
+struct dh_st;
+struct dh_st *crypto_dh_get_dh_(crypto_dh_t *dh);
+
void crypto_add_spaces_to_fp(char *out, size_t outlen, const char *in);
#endif /* !defined(TOR_CRYPTO_H) */
+
diff --git a/src/lib/crypt_ops/crypto_curve25519.c b/src/common/crypto_curve25519.c
index 276ff208aa..996d94c6e2 100644
--- a/src/lib/crypt_ops/crypto_curve25519.c
+++ b/src/common/crypto_curve25519.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2018, The Tor Project, Inc. */
+/* Copyright (c) 2012-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -20,13 +20,14 @@
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
-#include "lib/crypt_ops/crypto_curve25519.h"
-#include "lib/crypt_ops/crypto_digest.h"
-#include "lib/crypt_ops/crypto_format.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "common/util.h"
-#include "lib/log/torlog.h"
+#include "container.h"
+#include "crypto_curve25519.h"
+#include "crypto_digest.h"
+#include "crypto_format.h"
+#include "crypto_rand.h"
+#include "crypto_util.h"
+#include "util.h"
+#include "torlog.h"
#include "ed25519/donna/ed25519_donna_tor.h"
diff --git a/src/lib/crypt_ops/crypto_curve25519.h b/src/common/crypto_curve25519.h
index 2e614848e4..4834fa0836 100644
--- a/src/lib/crypt_ops/crypto_curve25519.h
+++ b/src/common/crypto_curve25519.h
@@ -1,13 +1,13 @@
-/* Copyright (c) 2012-2018, The Tor Project, Inc. */
+/* Copyright (c) 2012-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_CRYPTO_CURVE25519_H
#define TOR_CRYPTO_CURVE25519_H
-#include "lib/testsupport/testsupport.h"
-#include "lib/cc/torint.h"
-#include "lib/crypt_ops/crypto_digest.h"
-#include "lib/crypt_ops/crypto_openssl_mgt.h"
+#include "testsupport.h"
+#include "torint.h"
+#include "crypto_digest.h"
+#include "crypto_openssl_mgt.h"
/** Length of a curve25519 public key when encoded. */
#define CURVE25519_PUBKEY_LEN 32
diff --git a/src/lib/crypt_ops/crypto_digest.c b/src/common/crypto_digest.c
index a505435935..f7163de133 100644
--- a/src/lib/crypt_ops/crypto_digest.c
+++ b/src/common/crypto_digest.c
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -10,11 +10,11 @@
* operations.
**/
-#include "lib/container/smartlist.h"
-#include "lib/crypt_ops/crypto_digest.h"
-#include "lib/crypt_ops/crypto_openssl_mgt.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "lib/log/torlog.h"
+#include "container.h"
+#include "crypto_digest.h"
+#include "crypto_openssl_mgt.h"
+#include "crypto_util.h"
+#include "torlog.h"
#include "keccak-tiny/keccak-tiny.h"
@@ -268,11 +268,7 @@ crypto_digest_new(void)
}
/** Allocate and return a new digest object to compute 256-bit digests
- * using <b>algorithm</b>.
- *
- * C_RUST_COUPLED: `external::crypto_digest::crypto_digest256_new`
- * C_RUST_COUPLED: `crypto::digest::Sha256::default`
- */
+ * using <b>algorithm</b>. */
crypto_digest_t *
crypto_digest256_new(digest_algorithm_t algorithm)
{
@@ -302,9 +298,6 @@ crypto_digest_free_(crypto_digest_t *digest)
}
/** Add <b>len</b> bytes from <b>data</b> to the digest object.
- *
- * C_RUST_COUPLED: `external::crypto_digest::crypto_digest_add_bytess`
- * C_RUST_COUPLED: `crypto::digest::Sha256::process`
*/
void
crypto_digest_add_bytes(crypto_digest_t *digest, const char *data,
@@ -342,9 +335,6 @@ crypto_digest_add_bytes(crypto_digest_t *digest, const char *data,
/** Compute the hash of the data that has been passed to the digest
* object; write the first out_len bytes of the result to <b>out</b>.
* <b>out_len</b> must be \<= DIGEST512_LEN.
- *
- * C_RUST_COUPLED: `external::crypto_digest::crypto_digest_get_digest`
- * C_RUST_COUPLED: `impl digest::FixedOutput for Sha256`
*/
void
crypto_digest_get_digest(crypto_digest_t *digest,
@@ -393,9 +383,6 @@ crypto_digest_get_digest(crypto_digest_t *digest,
/** Allocate and return a new digest object with the same state as
* <b>digest</b>
- *
- * C_RUST_COUPLED: `external::crypto_digest::crypto_digest_dup`
- * C_RUST_COUPLED: `impl Clone for crypto::digest::Sha256`
*/
crypto_digest_t *
crypto_digest_dup(const crypto_digest_t *digest)
@@ -580,3 +567,4 @@ crypto_xof_free_(crypto_xof_t *xof)
memwipe(xof, 0, sizeof(crypto_xof_t));
tor_free(xof);
}
+
diff --git a/src/lib/crypt_ops/crypto_digest.h b/src/common/crypto_digest.h
index 15bc5ad5b9..3bd74acdfa 100644
--- a/src/lib/crypt_ops/crypto_digest.h
+++ b/src/common/crypto_digest.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -13,9 +13,18 @@
#ifndef TOR_CRYPTO_DIGEST_H
#define TOR_CRYPTO_DIGEST_H
-#include "lib/cc/torint.h"
-#include "lib/defs/digest_sizes.h"
-#include "lib/malloc/util_malloc.h"
+#include <stdio.h>
+
+#include "container.h"
+#include "torint.h"
+
+/** Length of the output of our message digest. */
+#define DIGEST_LEN 20
+/** Length of the output of our second (improved) message digests. (For now
+ * this is just sha256, but it could be any other 256-bit digest.) */
+#define DIGEST256_LEN 32
+/** Length of the output of our 64-bit optimized message digests (SHA512). */
+#define DIGEST512_LEN 64
/** Length of a sha1 message digest when encoded in base32 with trailing =
* signs removed. */
@@ -69,8 +78,6 @@ typedef struct {
typedef struct crypto_digest_t crypto_digest_t;
typedef struct crypto_xof_t crypto_xof_t;
-struct smartlist_t;
-
/* SHA-1 and other digests */
int crypto_digest(char *digest, const char *m, size_t len);
int crypto_digest256(char *digest, const char *m, size_t len,
@@ -126,3 +133,4 @@ digest_algorithm_t crypto_digest_get_algorithm(crypto_digest_t *digest);
#endif
#endif /* !defined(TOR_CRYPTO_DIGEST_H) */
+
diff --git a/src/lib/crypt_ops/crypto_ed25519.c b/src/common/crypto_ed25519.c
index 5655fbf508..9c13e3bdf0 100644
--- a/src/lib/crypt_ops/crypto_ed25519.c
+++ b/src/common/crypto_ed25519.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2018, The Tor Project, Inc. */
+/* Copyright (c) 2013-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -21,15 +21,15 @@
#include <sys/stat.h>
#endif
-#include "lib/crypt_ops/crypto_curve25519.h"
-#include "lib/crypt_ops/crypto_digest.h"
-#include "lib/crypt_ops/crypto_ed25519.h"
-#include "lib/crypt_ops/crypto_format.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "lib/log/torlog.h"
-#include "common/util.h"
-#include "common/util_format.h"
+#include "crypto_curve25519.h"
+#include "crypto_digest.h"
+#include "crypto_ed25519.h"
+#include "crypto_format.h"
+#include "crypto_rand.h"
+#include "crypto_util.h"
+#include "torlog.h"
+#include "util.h"
+#include "util_format.h"
#include "ed25519/ref10/ed25519_ref10.h"
#include "ed25519/donna/ed25519_donna_tor.h"
diff --git a/src/lib/crypt_ops/crypto_ed25519.h b/src/common/crypto_ed25519.h
index de992aaa8c..74269ccffd 100644
--- a/src/lib/crypt_ops/crypto_ed25519.h
+++ b/src/common/crypto_ed25519.h
@@ -1,13 +1,13 @@
-/* Copyright (c) 2012-2018, The Tor Project, Inc. */
+/* Copyright (c) 2012-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_CRYPTO_ED25519_H
#define TOR_CRYPTO_ED25519_H
-#include "lib/testsupport/testsupport.h"
-#include "lib/cc/torint.h"
-#include "lib/crypt_ops/crypto_curve25519.h"
-#include "common/util.h"
+#include "testsupport.h"
+#include "torint.h"
+#include "crypto_curve25519.h"
+#include "util.h"
#define ED25519_PUBKEY_LEN 32
#define ED25519_SECKEY_LEN 64
diff --git a/src/lib/crypt_ops/crypto_format.c b/src/common/crypto_format.c
index 888c0794ec..460e85bac1 100644
--- a/src/lib/crypt_ops/crypto_format.c
+++ b/src/common/crypto_format.c
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -14,16 +14,15 @@
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
-#include "lib/container/smartlist.h"
-#include "lib/crypt_ops/crypto_curve25519.h"
-#include "lib/crypt_ops/crypto_digest.h"
-#include "lib/crypt_ops/crypto_ed25519.h"
-#include "lib/crypt_ops/crypto_format.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "lib/string/util_string.h"
-#include "common/util.h"
-#include "common/util_format.h"
-#include "lib/log/torlog.h"
+#include "container.h"
+#include "crypto_curve25519.h"
+#include "crypto_digest.h"
+#include "crypto_ed25519.h"
+#include "crypto_format.h"
+#include "crypto_util.h"
+#include "util.h"
+#include "util_format.h"
+#include "torlog.h"
/** Write the <b>datalen</b> bytes from <b>data</b> to the file named
* <b>fname</b> in the tagged-data format. This format contains a
@@ -297,3 +296,4 @@ digest256_from_base64(char *digest, const char *d64)
else
return -1;
}
+
diff --git a/src/lib/crypt_ops/crypto_format.h b/src/common/crypto_format.h
index 77983f2161..bbd85dc720 100644
--- a/src/lib/crypt_ops/crypto_format.h
+++ b/src/common/crypto_format.h
@@ -1,15 +1,15 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_CRYPTO_FORMAT_H
#define TOR_CRYPTO_FORMAT_H
-#include "lib/testsupport/testsupport.h"
-#include "lib/cc/torint.h"
-#include "lib/crypt_ops/crypto_ed25519.h"
+#include "testsupport.h"
+#include "torint.h"
+#include "crypto_ed25519.h"
int crypto_write_tagged_contents_to_file(const char *fname,
const char *typestring,
diff --git a/src/lib/crypt_ops/crypto_openssl_mgt.c b/src/common/crypto_openssl_mgt.c
index 2c2c2048e9..ea3519efa2 100644
--- a/src/lib/crypt_ops/crypto_openssl_mgt.c
+++ b/src/common/crypto_openssl_mgt.c
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -10,9 +10,8 @@
* \brief Block of functions related to operations from OpenSSL.
**/
-#include "lib/crypt_ops/compat_openssl.h"
-#include "lib/crypt_ops/crypto_openssl_mgt.h"
-#include "lib/string/util_string.h"
+#include "compat_openssl.h"
+#include "crypto_openssl_mgt.h"
DISABLE_GCC_WARNING(redundant-decls)
@@ -159,3 +158,4 @@ crypto_openssl_free_all(void)
}
#endif /* !defined(NEW_THREAD_API) */
}
+
diff --git a/src/lib/crypt_ops/crypto_openssl_mgt.h b/src/common/crypto_openssl_mgt.h
index e3f5531b7d..09b6737962 100644
--- a/src/lib/crypt_ops/crypto_openssl_mgt.h
+++ b/src/common/crypto_openssl_mgt.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -14,7 +14,7 @@
#define TOR_CRYPTO_OPENSSL_H
#include <stdio.h>
-#include "common/util.h"
+#include "util.h"
#include <openssl/engine.h>
diff --git a/src/lib/crypt_ops/crypto_pwbox.c b/src/common/crypto_pwbox.c
index 6944f8ab52..c2bd1d26cb 100644
--- a/src/lib/crypt_ops/crypto_pwbox.c
+++ b/src/common/crypto_pwbox.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014-2018, The Tor Project, Inc. */
+/* Copyright (c) 2014-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -8,16 +8,15 @@
* them to disk.
*/
-#include "lib/crypt_ops/crypto.h"
-#include "lib/crypt_ops/crypto_digest.h"
-#include "lib/crypt_ops/crypto_pwbox.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_s2k.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "lib/ctime/di_ops.h"
-#include "lib/intmath/muldiv.h"
-#include "common/util.h"
-#include "trunnel/pwbox.h"
+#include "crypto.h"
+#include "crypto_digest.h"
+#include "crypto_pwbox.h"
+#include "crypto_rand.h"
+#include "crypto_s2k.h"
+#include "crypto_util.h"
+#include "di_ops.h"
+#include "util.h"
+#include "pwbox.h"
/* 8 bytes "TORBOX00"
1 byte: header len (H)
@@ -213,3 +212,4 @@ crypto_unpwbox(uint8_t **out, size_t *outlen_out,
memwipe(keys, 0, sizeof(keys));
return rv;
}
+
diff --git a/src/lib/crypt_ops/crypto_pwbox.h b/src/common/crypto_pwbox.h
index 9ed35a150e..a26b6d2c17 100644
--- a/src/lib/crypt_ops/crypto_pwbox.h
+++ b/src/common/crypto_pwbox.h
@@ -1,10 +1,10 @@
-/* Copyright (c) 2014-2018, The Tor Project, Inc. */
+/* Copyright (c) 2014-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef CRYPTO_PWBOX_H_INCLUDED_
#define CRYPTO_PWBOX_H_INCLUDED_
-#include "lib/cc/torint.h"
+#include "torint.h"
#define UNPWBOX_OKAY 0
#define UNPWBOX_BAD_SECRET -1
diff --git a/src/lib/crypt_ops/crypto_rand.c b/src/common/crypto_rand.c
index bff32c7ec6..5abf0b0968 100644
--- a/src/lib/crypt_ops/crypto_rand.c
+++ b/src/common/crypto_rand.c
@@ -14,22 +14,22 @@
#ifndef CRYPTO_RAND_PRIVATE
#define CRYPTO_RAND_PRIVATE
-#include "lib/crypt_ops/crypto_rand.h"
+#include "crypto_rand.h"
#ifdef _WIN32
#include <windows.h>
#include <wincrypt.h>
#endif /* defined(_WIN32) */
-#include "lib/container/smartlist.h"
-#include "common/compat.h"
-#include "lib/crypt_ops/compat_openssl.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "common/sandbox.h"
-#include "lib/testsupport/testsupport.h"
-#include "lib/log/torlog.h"
-#include "common/util.h"
-#include "common/util_format.h"
+#include "container.h"
+#include "compat.h"
+#include "compat_openssl.h"
+#include "crypto_util.h"
+#include "sandbox.h"
+#include "testsupport.h"
+#include "torlog.h"
+#include "util.h"
+#include "util_format.h"
DISABLE_GCC_WARNING(redundant-decls)
#include <openssl/rand.h>
@@ -55,12 +55,6 @@ ENABLE_GCC_WARNING(redundant-decls)
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#ifdef HAVE_SYS_SYSCALL_H
-#include <sys/syscall.h>
-#endif
-#ifdef HAVE_SYS_RANDOM_H
-#include <sys/random.h>
-#endif
/**
* How many bytes of entropy we add at once.
@@ -612,3 +606,4 @@ crypto_force_rand_ssleay(void)
}
#endif /* !defined(CRYPTO_RAND_PRIVATE) */
+
diff --git a/src/lib/crypt_ops/crypto_rand.h b/src/common/crypto_rand.h
index 8309bb21ca..4eac94f57b 100644
--- a/src/lib/crypt_ops/crypto_rand.h
+++ b/src/common/crypto_rand.h
@@ -7,14 +7,14 @@
/**
* \file crypto_rand.h
*
- * \brief Common functions for using (pseudo-)random number generators.
+ * \brief Common functions for using (psuedo-)random number generators.
**/
#ifndef TOR_CRYPTO_RAND_H
#define TOR_CRYPTO_RAND_H
-#include "lib/cc/torint.h"
-#include "common/util.h"
+#include "torint.h"
+#include "util.h"
/* random numbers */
int crypto_seed_rng(void) ATTR_WUR;
diff --git a/src/lib/crypt_ops/crypto_rsa.c b/src/common/crypto_rsa.c
index 3f2f8544f7..0a88b0e772 100644
--- a/src/lib/crypt_ops/crypto_rsa.c
+++ b/src/common/crypto_rsa.c
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -9,14 +9,14 @@
* \brief Block of functions related with RSA utilities and operations.
**/
-#include "lib/crypt_ops/crypto.h"
-#include "lib/crypt_ops/crypto_curve25519.h"
-#include "lib/crypt_ops/crypto_digest.h"
-#include "lib/crypt_ops/crypto_format.h"
-#include "lib/crypt_ops/compat_openssl.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_rsa.h"
-#include "lib/crypt_ops/crypto_util.h"
+#include "crypto.h"
+#include "crypto_curve25519.h"
+#include "crypto_digest.h"
+#include "crypto_format.h"
+#include "compat_openssl.h"
+#include "crypto_rand.h"
+#include "crypto_rsa.h"
+#include "crypto_util.h"
DISABLE_GCC_WARNING(redundant-decls)
@@ -33,9 +33,9 @@ DISABLE_GCC_WARNING(redundant-decls)
ENABLE_GCC_WARNING(redundant-decls)
-#include "lib/log/torlog.h"
-#include "common/util.h"
-#include "common/util_format.h"
+#include "torlog.h"
+#include "util.h"
+#include "util_format.h"
/** Declaration for crypto_pk_t structure. */
struct crypto_pk_t
@@ -44,6 +44,27 @@ struct crypto_pk_t
RSA *key; /**< The key itself */
};
+/** Log all pending crypto errors at level <b>severity</b>. Use
+ * <b>doing</b> to describe our current activities.
+ */
+static void
+crypto_log_errors(int severity, const char *doing)
+{
+ unsigned long err;
+ const char *msg, *lib, *func;
+ while ((err = ERR_get_error()) != 0) {
+ msg = (const char*)ERR_reason_error_string(err);
+ lib = (const char*)ERR_lib_error_string(err);
+ func = (const char*)ERR_func_error_string(err);
+ if (!msg) msg = "(null)";
+ if (!lib) lib = "(null)";
+ if (!func) func = "(null)";
+ if (BUG(!doing)) doing = "(null)";
+ tor_log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)",
+ doing, msg, lib, func);
+ }
+}
+
/** Return the number of bytes added by padding method <b>padding</b>.
*/
int
@@ -218,7 +239,7 @@ pem_no_password_cb(char *buf, int size, int rwflag, void *u)
(void)size;
(void)rwflag;
(void)u;
- return -1;
+ return 0;
}
/** Read a PEM-encoded private key from the <b>len</b>-byte string <b>s</b>
diff --git a/src/lib/crypt_ops/crypto_rsa.h b/src/common/crypto_rsa.h
index 75255c9cc8..e952089318 100644
--- a/src/lib/crypt_ops/crypto_rsa.h
+++ b/src/common/crypto_rsa.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -15,13 +15,13 @@
#include "orconfig.h"
-#include "lib/crypt_ops/crypto_digest.h"
+#include "crypto_digest.h"
#include <stdio.h>
-#include "lib/cc/torint.h"
-#include "lib/testsupport/testsupport.h"
-#include "common/compat.h"
-#include "common/util.h"
-#include "lib/log/torlog.h"
+#include "torint.h"
+#include "testsupport.h"
+#include "compat.h"
+#include "util.h"
+#include "torlog.h"
/** Length of our public keys. */
#define PK_BYTES (1024/8)
diff --git a/src/lib/crypt_ops/crypto_s2k.c b/src/common/crypto_s2k.c
index 722407bf48..8543760ec5 100644
--- a/src/lib/crypt_ops/crypto_s2k.c
+++ b/src/common/crypto_s2k.c
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -12,14 +12,13 @@
#define CRYPTO_S2K_PRIVATE
-#include "common/compat.h"
-#include "lib/crypt_ops/crypto.h"
-#include "lib/crypt_ops/crypto_digest.h"
-#include "lib/crypt_ops/crypto_hkdf.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_s2k.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "common/util.h"
+#include "compat.h"
+#include "crypto.h"
+#include "crypto_digest.h"
+#include "crypto_rand.h"
+#include "crypto_s2k.h"
+#include "crypto_util.h"
+#include "util.h"
#include <openssl/evp.h>
diff --git a/src/lib/crypt_ops/crypto_s2k.h b/src/common/crypto_s2k.h
index b270897b68..849ff59ce8 100644
--- a/src/lib/crypt_ops/crypto_s2k.h
+++ b/src/common/crypto_s2k.h
@@ -1,14 +1,14 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_CRYPTO_S2K_H_INCLUDED
#define TOR_CRYPTO_S2K_H_INCLUDED
#include <stdio.h>
-#include "lib/cc/torint.h"
+#include "torint.h"
/** Length of RFC2440-style S2K specifier: the first 8 bytes are a salt, the
* 9th describes how much iteration to do. */
diff --git a/src/lib/crypt_ops/crypto_util.c b/src/common/crypto_util.c
index db88805a78..b0d5b6b2f7 100644
--- a/src/lib/crypt_ops/crypto_util.c
+++ b/src/common/crypto_util.c
@@ -13,7 +13,7 @@
#ifndef CRYPTO_UTIL_PRIVATE
#define CRYPTO_UTIL_PRIVATE
-#include "lib/crypt_ops/crypto_util.h"
+#include "crypto_util.h"
#include <string.h>
@@ -23,17 +23,14 @@
#include <wincrypt.h>
#endif /* defined(_WIN32) */
-#include "common/util.h"
+#include "util.h"
DISABLE_GCC_WARNING(redundant-decls)
-#include <openssl/err.h>
#include <openssl/crypto.h>
ENABLE_GCC_WARNING(redundant-decls)
-#include "lib/log/torlog.h"
-
/**
* Destroy the <b>sz</b> bytes of data stored at <b>mem</b>, setting them to
* the value <b>byte</b>.
@@ -106,25 +103,5 @@ memwipe(void *mem, uint8_t byte, size_t sz)
memset(mem, byte, sz);
}
-/** Log all pending crypto errors at level <b>severity</b>. Use
- * <b>doing</b> to describe our current activities.
- */
-void
-crypto_log_errors(int severity, const char *doing)
-{
- unsigned long err;
- const char *msg, *lib, *func;
- while ((err = ERR_get_error()) != 0) {
- msg = (const char*)ERR_reason_error_string(err);
- lib = (const char*)ERR_lib_error_string(err);
- func = (const char*)ERR_func_error_string(err);
- if (!msg) msg = "(null)";
- if (!lib) lib = "(null)";
- if (!func) func = "(null)";
- if (BUG(!doing)) doing = "(null)";
- tor_log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)",
- doing, msg, lib, func);
- }
-}
#endif /* !defined(CRYPTO_UTIL_PRIVATE) */
diff --git a/src/lib/crypt_ops/crypto_util.h b/src/common/crypto_util.h
index 3ce34e6f23..922942b371 100644
--- a/src/lib/crypt_ops/crypto_util.h
+++ b/src/common/crypto_util.h
@@ -13,14 +13,11 @@
#ifndef TOR_CRYPTO_UTIL_H
#define TOR_CRYPTO_UTIL_H
-#include "lib/cc/torint.h"
+#include "torint.h"
/** OpenSSL-based utility functions. */
void memwipe(void *mem, uint8_t byte, size_t sz);
-/** Log utility function */
-void crypto_log_errors(int severity, const char *doing);
-
#ifdef CRYPTO_UTIL_PRIVATE
#ifdef TOR_UNIT_TESTS
#endif /* defined(TOR_UNIT_TESTS) */
diff --git a/src/lib/ctime/di_ops.c b/src/common/di_ops.c
index 287ff6080a..90e9357c8e 100644
--- a/src/lib/ctime/di_ops.c
+++ b/src/common/di_ops.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2018, The Tor Project, Inc. */
+/* Copyright (c) 2011-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -7,11 +7,9 @@
**/
#include "orconfig.h"
-#include "lib/ctime/di_ops.h"
-#include "lib/err/torerr.h"
-#include "lib/malloc/util_malloc.h"
-
-#include <string.h>
+#include "di_ops.h"
+#include "torlog.h"
+#include "util.h"
/**
* Timing-safe version of memcmp. As memcmp, compare the <b>sz</b> bytes at
@@ -173,8 +171,8 @@ dimap_add_entry(di_digest256_map_t **map,
di_digest256_map_t *new_ent;
{
void *old_val = dimap_search(*map, key, NULL);
- raw_assert(! old_val);
- raw_assert(val);
+ tor_assert(! old_val);
+ tor_assert(val);
}
new_ent = tor_malloc_zero(sizeof(di_digest256_map_t));
new_ent->next = *map;
@@ -266,10 +264,11 @@ select_array_member_cumulative_timei(const uint64_t *entries, int n_entries,
rand_val = INT64_MAX;
}
}
- raw_assert(total_so_far == total);
- raw_assert(n_chosen == 1);
- raw_assert(i_chosen >= 0);
- raw_assert(i_chosen < n_entries);
+ tor_assert(total_so_far == total);
+ tor_assert(n_chosen == 1);
+ tor_assert(i_chosen >= 0);
+ tor_assert(i_chosen < n_entries);
return i_chosen;
}
+
diff --git a/src/lib/ctime/di_ops.h b/src/common/di_ops.h
index 92af7ae278..67d9c9f0df 100644
--- a/src/lib/ctime/di_ops.h
+++ b/src/common/di_ops.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -12,7 +12,7 @@
#define TOR_DI_OPS_H
#include "orconfig.h"
-#include "lib/cc/torint.h"
+#include "torint.h"
int tor_memcmp(const void *a, const void *b, size_t sz);
int tor_memeq(const void *a, const void *b, size_t sz);
diff --git a/src/common/handles.h b/src/common/handles.h
index ca345b0bcb..aef8cd89ef 100644
--- a/src/common/handles.h
+++ b/src/common/handles.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2016-2018, The Tor Project, Inc. */
+/* Copyright (c) 2016-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -51,7 +51,7 @@
#include "orconfig.h"
#include "tor_queue.h"
-#include "common/util.h"
+#include "util.h"
#define HANDLE_ENTRY(name, structname) \
struct name ## _handle_head_t *handle_head
diff --git a/src/common/include.am b/src/common/include.am
index 4927f57425..bce3fa20f6 100644
--- a/src/common/include.am
+++ b/src/common/include.am
@@ -1,22 +1,54 @@
noinst_LIBRARIES += \
src/common/libor.a \
+ src/common/libor-ctime.a \
+ src/common/libor-crypto.a \
src/common/libor-event.a
if UNITTESTS_ENABLED
noinst_LIBRARIES += \
src/common/libor-testing.a \
+ src/common/libor-ctime-testing.a \
+ src/common/libor-crypto-testing.a \
src/common/libor-event-testing.a
endif
EXTRA_DIST += src/common/Makefile.nmake
+#CFLAGS = -Wall -Wpointer-arith -O2
+AM_CPPFLAGS += -I$(srcdir)/src/common -Isrc/common -I$(srcdir)/src/ext/trunnel -I$(srcdir)/src/trunnel
+
if USE_OPENBSD_MALLOC
libor_extra_source=src/ext/OpenBSD_malloc_Linux.c
else
libor_extra_source=
endif
+src_common_libcurve25519_donna_a_CFLAGS=
+
+if BUILD_CURVE25519_DONNA
+src_common_libcurve25519_donna_a_SOURCES=\
+ src/ext/curve25519_donna/curve25519-donna.c
+# See bug 13538 -- this code is known to have signed overflow issues.
+src_common_libcurve25519_donna_a_CFLAGS+=\
+ @F_OMIT_FRAME_POINTER@ @CFLAGS_CONSTTIME@
+noinst_LIBRARIES+=src/common/libcurve25519_donna.a
+LIBDONNA=src/common/libcurve25519_donna.a
+else
+if BUILD_CURVE25519_DONNA_C64
+src_common_libcurve25519_donna_a_CFLAGS+=@CFLAGS_CONSTTIME@
+src_common_libcurve25519_donna_a_SOURCES=\
+ src/ext/curve25519_donna/curve25519-donna-c64.c
+noinst_LIBRARIES+=src/common/libcurve25519_donna.a
+LIBDONNA=src/common/libcurve25519_donna.a
+else
+LIBDONNA=
+endif
+endif
+
+LIBDONNA += $(LIBED25519_REF10)
+LIBDONNA += $(LIBED25519_DONNA)
+
if THREADS_PTHREADS
threads_impl_source=src/common/compat_pthreads.c
endif
@@ -30,16 +62,37 @@ else
readpassphrase_source=
endif
+if ADD_MULODI4
+mulodi4_source=src/ext/mulodi/mulodi4.c
+else
+mulodi4_source=
+endif
+
+LIBOR_CTIME_A_SRC = \
+ $(mulodi4_source) \
+ src/ext/csiphash.c \
+ src/common/di_ops.c
+
+src_common_libor_ctime_a_SOURCES = $(LIBOR_CTIME_A_SRC)
+src_common_libor_ctime_testing_a_SOURCES = $(LIBOR_CTIME_A_SRC)
+src_common_libor_ctime_a_CFLAGS = @CFLAGS_CONSTTIME@
+src_common_libor_ctime_testing_a_CFLAGS = @CFLAGS_CONSTTIME@ $(TEST_CFLAGS)
+
LIBOR_A_SRC = \
src/common/address.c \
src/common/address_set.c \
+ src/common/backtrace.c \
src/common/buffers.c \
src/common/compat.c \
src/common/compat_threads.c \
src/common/compat_time.c \
src/common/confline.c \
+ src/common/container.c \
+ src/common/log.c \
src/common/memarea.c \
+ src/common/pubsub.c \
src/common/util.c \
+ src/common/util_bug.c \
src/common/util_format.c \
src/common/util_process.c \
src/common/sandbox.c \
@@ -53,6 +106,27 @@ LIBOR_A_SRC = \
src/common/src_common_libor_testing_a-log.$(OBJEXT) \
src/common/log.$(OBJEXT): micro-revision.i
+LIBOR_CRYPTO_A_SRC = \
+ src/common/aes.c \
+ src/common/buffers_tls.c \
+ src/common/compress.c \
+ src/common/compress_lzma.c \
+ src/common/compress_none.c \
+ src/common/compress_zlib.c \
+ src/common/compress_zstd.c \
+ src/common/crypto.c \
+ src/common/crypto_digest.c \
+ src/common/crypto_format.c \
+ src/common/crypto_openssl_mgt.c \
+ src/common/crypto_pwbox.c \
+ src/common/crypto_rand.c \
+ src/common/crypto_rsa.c \
+ src/common/crypto_s2k.c \
+ src/common/crypto_util.c \
+ src/common/tortls.c \
+ src/common/crypto_curve25519.c \
+ src/common/crypto_ed25519.c
+
LIBOR_EVENT_A_SRC = \
src/common/compat_libevent.c \
src/common/procmon.c \
@@ -60,41 +134,70 @@ LIBOR_EVENT_A_SRC = \
src/ext/timeouts/timeout.c
src_common_libor_a_SOURCES = $(LIBOR_A_SRC)
+src_common_libor_crypto_a_SOURCES = $(LIBOR_CRYPTO_A_SRC)
src_common_libor_event_a_SOURCES = $(LIBOR_EVENT_A_SRC)
-if UNITTESTS_ENABLED
src_common_libor_testing_a_SOURCES = $(LIBOR_A_SRC)
+src_common_libor_crypto_testing_a_SOURCES = $(LIBOR_CRYPTO_A_SRC)
src_common_libor_event_testing_a_SOURCES = $(LIBOR_EVENT_A_SRC)
-else
-src_common_libor_testing_a_SOURCES =
-src_common_libor_event_testing_a_SOURCES =
-endif
src_common_libor_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
+src_common_libor_crypto_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
src_common_libor_event_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
src_common_libor_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
+src_common_libor_crypto_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
src_common_libor_event_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
COMMONHEADERS = \
src/common/address.h \
src/common/address_set.h \
+ src/common/backtrace.h \
src/common/buffers.h \
+ src/common/buffers_tls.h \
+ src/common/aes.h \
+ src/common/ciphers.inc \
src/common/compat.h \
src/common/compat_libevent.h \
+ src/common/compat_openssl.h \
src/common/compat_threads.h \
src/common/compat_time.h \
+ src/common/compress.h \
+ src/common/compress_lzma.h \
+ src/common/compress_none.h \
+ src/common/compress_zlib.h \
+ src/common/compress_zstd.h \
src/common/confline.h \
+ src/common/container.h \
+ src/common/crypto.h \
+ src/common/crypto_digest.h \
+ src/common/crypto_curve25519.h \
+ src/common/crypto_ed25519.h \
+ src/common/crypto_format.h \
+ src/common/crypto_openssl_mgt.h \
+ src/common/crypto_pwbox.h \
+ src/common/crypto_rand.h \
+ src/common/crypto_rsa.h \
+ src/common/crypto_s2k.h \
+ src/common/crypto_util.h \
+ src/common/di_ops.h \
src/common/handles.h \
src/common/memarea.h \
src/common/linux_syscalls.inc \
src/common/procmon.h \
+ src/common/pubsub.h \
src/common/sandbox.h \
src/common/storagedir.h \
+ src/common/testsupport.h \
src/common/timers.h \
src/common/token_bucket.h \
+ src/common/torint.h \
+ src/common/torlog.h \
+ src/common/tortls.h \
src/common/util.h \
+ src/common/util_bug.h \
src/common/util_format.h \
src/common/util_process.h \
src/common/workqueue.h
noinst_HEADERS+= $(COMMONHEADERS)
+
diff --git a/src/lib/log/torlog.c b/src/common/log.c
index 5709dd8199..ebd50f62d3 100644
--- a/src/lib/log/torlog.c
+++ b/src/common/log.c
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -11,7 +11,8 @@
#include "orconfig.h"
#include <stdarg.h>
-#include <stdio.h>
+#include <assert.h>
+// #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_SYS_TIME_H
@@ -29,23 +30,11 @@
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
-
+#include "compat.h"
+#include "util.h"
#define LOG_PRIVATE
-#include "lib/log/torlog.h"
-#include "lib/log/ratelim.h"
-#include "lib/lock/compat_mutex.h"
-#include "lib/container/smartlist.h"
-#include "lib/err/torerr.h"
-#include "lib/intmath/bits.h"
-#include "lib/string/compat_string.h"
-#include "lib/string/printf.h"
-#include "lib/malloc/util_malloc.h"
-#include "lib/string/util_string.h"
-#include "lib/wallclock/tor_gettimeofday.h"
-#include "lib/wallclock/approx_time.h"
-#include "lib/wallclock/tm_cvt.h"
-#include "lib/fdio/fdio.h"
-
+#include "torlog.h"
+#include "container.h"
#ifdef HAVE_ANDROID_LOG_H
#include <android/log.h>
#endif // HAVE_ANDROID_LOG_H.
@@ -61,6 +50,8 @@
#define TRUNCATED_STR_LEN 14
/** @} */
+#define raw_assert(x) assert(x) // assert OK
+
/** Defining compile-time constants for Tor log levels (used by the Rust
* log wrapper at src/rust/tor_log) */
const int LOG_WARN_ = LOG_WARN;
@@ -98,9 +89,9 @@ sev_to_string(int severity)
case LOG_NOTICE: return "notice";
case LOG_WARN: return "warn";
case LOG_ERR: return "err";
- default: /* Call assert, not tor_assert, since tor_assert
- * calls log on failure. */
- raw_assert_unreached(); return "UNKNOWN"; // LCOV_EXCL_LINE
+ default: /* Call assert, not tor_assert, since tor_assert
+ * calls log on failure. */
+ raw_assert(0); return "UNKNOWN"; // LCOV_EXCL_LINE
}
}
@@ -204,12 +195,12 @@ static int pretty_fn_has_parens = 0;
/** Lock the log_mutex to prevent others from changing the logfile_t list */
#define LOCK_LOGS() STMT_BEGIN \
- raw_assert(log_mutex_initialized); \
+ tor_assert(log_mutex_initialized); \
tor_mutex_acquire(&log_mutex); \
STMT_END
/** Unlock the log_mutex */
#define UNLOCK_LOGS() STMT_BEGIN \
- raw_assert(log_mutex_initialized); \
+ tor_assert(log_mutex_initialized); \
tor_mutex_release(&log_mutex); \
STMT_END
@@ -277,7 +268,6 @@ void
set_log_time_granularity(int granularity_msec)
{
log_time_granularity = granularity_msec;
- tor_log_sigsafe_err_set_granularity(granularity_msec);
}
/** Helper: Write the standard prefix for log lines to a
@@ -302,8 +292,7 @@ log_prefix_(char *buf, size_t buf_len, int severity)
ms -= ((int)now.tv_usec / 1000) % log_time_granularity;
}
- n = strftime(buf, buf_len, "%b %d %H:%M:%S",
- tor_localtime_r_msg(&t, &tm, NULL));
+ n = strftime(buf, buf_len, "%b %d %H:%M:%S", tor_localtime_r(&t, &tm));
r = tor_snprintf(buf+n, buf_len-n, ".%.3i [%s] ", ms,
sev_to_string(severity));
@@ -346,7 +335,7 @@ log_tor_version(logfile_t *lf, int reset)
tor_snprintf(buf+n, sizeof(buf)-n,
"Tor %s opening %slog file.\n", VERSION, is_new?"new ":"");
}
- if (write_all_to_fd(lf->fd, buf, strlen(buf)) < 0) /* error */
+ if (write_all(lf->fd, buf, strlen(buf), 0) < 0) /* error */
return -1; /* failed */
return 0;
}
@@ -560,7 +549,7 @@ logfile_deliver(logfile_t *lf, const char *buf, size_t msg_len,
lf->callback(severity, domain, msg_after_prefix);
}
} else {
- if (write_all_to_fd(lf->fd, buf, msg_len) < 0) { /* error */
+ if (write_all(lf->fd, buf, msg_len, 0) < 0) { /* error */
/* don't log the error! mark this log entry to be blown away, and
* continue. */
lf->seems_dead = 1;
@@ -583,7 +572,7 @@ logv,(int severity, log_domain_mask_t domain, const char *funcname,
char *end_of_prefix=NULL;
int callbacks_deferred = 0;
- /* Call assert, not raw_assert, since raw_assert calls log on failure. */
+ /* Call assert, not tor_assert, since tor_assert calls log on failure. */
raw_assert(format);
/* check that severity is sane. Overrunning the masks array leads to
* interesting and hard to diagnose effects */
@@ -645,6 +634,71 @@ tor_log(int severity, log_domain_mask_t domain, const char *format, ...)
va_end(ap);
}
+/** Maximum number of fds that will get notifications if we crash */
+#define MAX_SIGSAFE_FDS 8
+/** Array of fds to log crash-style warnings to. */
+static int sigsafe_log_fds[MAX_SIGSAFE_FDS] = { STDERR_FILENO };
+/** The number of elements used in sigsafe_log_fds */
+static int n_sigsafe_log_fds = 1;
+
+/** Write <b>s</b> to each element of sigsafe_log_fds. Return 0 on success, -1
+ * on failure. */
+static int
+tor_log_err_sigsafe_write(const char *s)
+{
+ int i;
+ ssize_t r;
+ size_t len = strlen(s);
+ int err = 0;
+ for (i=0; i < n_sigsafe_log_fds; ++i) {
+ r = write(sigsafe_log_fds[i], s, len);
+ err += (r != (ssize_t)len);
+ }
+ return err ? -1 : 0;
+}
+
+/** Given a list of string arguments ending with a NULL, writes them
+ * to our logs and to stderr (if possible). This function is safe to call
+ * from within a signal handler. */
+void
+tor_log_err_sigsafe(const char *m, ...)
+{
+ va_list ap;
+ const char *x;
+ char timebuf[33];
+ time_t now = time(NULL);
+
+ if (!m)
+ return;
+ if (log_time_granularity >= 2000) {
+ int g = log_time_granularity / 1000;
+ now -= now % g;
+ }
+ timebuf[0] = now < 0 ? '-' : ' ';
+ if (now < 0) now = -now;
+ timebuf[1] = '\0';
+ format_dec_number_sigsafe(now, timebuf+1, sizeof(timebuf)-1);
+ tor_log_err_sigsafe_write("\n=========================================="
+ "================== T=");
+ tor_log_err_sigsafe_write(timebuf);
+ tor_log_err_sigsafe_write("\n");
+ tor_log_err_sigsafe_write(m);
+ va_start(ap, m);
+ while ((x = va_arg(ap, const char*))) {
+ tor_log_err_sigsafe_write(x);
+ }
+ va_end(ap);
+}
+
+/** Set *<b>out</b> to a pointer to an array of the fds to log errors to from
+ * inside a signal handler. Return the number of elements in the array. */
+int
+tor_log_get_sigsafe_err_fds(const int **out)
+{
+ *out = sigsafe_log_fds;
+ return n_sigsafe_log_fds;
+}
+
/** Helper function; return true iff the <b>n</b>-element array <b>array</b>
* contains <b>item</b>. */
static int
@@ -666,14 +720,11 @@ tor_log_update_sigsafe_err_fds(void)
const logfile_t *lf;
int found_real_stderr = 0;
- int fds[TOR_SIGSAFE_LOG_MAX_FDS];
- int n_fds;
-
LOCK_LOGS();
/* Reserve the first one for stderr. This is safe because when we daemonize,
* we dup2 /dev/null to stderr, */
- fds[0] = STDERR_FILENO;
- n_fds = 1;
+ sigsafe_log_fds[0] = STDERR_FILENO;
+ n_sigsafe_log_fds = 1;
for (lf = logfiles; lf; lf = lf->next) {
/* Don't try callback to the control port, or syslogs: We can't
@@ -687,24 +738,22 @@ tor_log_update_sigsafe_err_fds(void)
if (lf->fd == STDERR_FILENO)
found_real_stderr = 1;
/* Avoid duplicates */
- if (int_array_contains(fds, n_fds, lf->fd))
+ if (int_array_contains(sigsafe_log_fds, n_sigsafe_log_fds, lf->fd))
continue;
- fds[n_fds++] = lf->fd;
- if (n_fds == TOR_SIGSAFE_LOG_MAX_FDS)
+ sigsafe_log_fds[n_sigsafe_log_fds++] = lf->fd;
+ if (n_sigsafe_log_fds == MAX_SIGSAFE_FDS)
break;
}
}
if (!found_real_stderr &&
- int_array_contains(fds, n_fds, STDOUT_FILENO)) {
+ int_array_contains(sigsafe_log_fds, n_sigsafe_log_fds, STDOUT_FILENO)) {
/* Don't use a virtual stderr when we're also logging to stdout. */
- raw_assert(n_fds >= 2); /* Don't raw_assert inside log fns */
- fds[0] = fds[--n_fds];
+ raw_assert(n_sigsafe_log_fds >= 2); /* Don't tor_assert inside log fns */
+ sigsafe_log_fds[0] = sigsafe_log_fds[--n_sigsafe_log_fds];
}
UNLOCK_LOGS();
-
- tor_log_set_sigsafe_err_fds(fds, n_fds);
}
/** Add to <b>out</b> a copy of every currently configured log file name. Used
@@ -713,7 +762,7 @@ void
tor_log_get_logfile_names(smartlist_t *out)
{
logfile_t *lf;
- raw_assert(out);
+ tor_assert(out);
LOCK_LOGS();
@@ -826,8 +875,8 @@ delete_log(logfile_t *victim)
logfiles = victim->next;
else {
for (tmpl = logfiles; tmpl && tmpl->next != victim; tmpl=tmpl->next) ;
-// raw_assert(tmpl);
-// raw_assert(tmpl->next == victim);
+// tor_assert(tmpl);
+// tor_assert(tmpl->next == victim);
if (!tmpl)
return;
tmpl->next = victim->next;
@@ -861,9 +910,9 @@ set_log_severity_config(int loglevelMin, int loglevelMax,
log_severity_list_t *severity_out)
{
int i;
- raw_assert(loglevelMin >= loglevelMax);
- raw_assert(loglevelMin >= LOG_ERR && loglevelMin <= LOG_DEBUG);
- raw_assert(loglevelMax >= LOG_ERR && loglevelMax <= LOG_DEBUG);
+ tor_assert(loglevelMin >= loglevelMax);
+ tor_assert(loglevelMin >= LOG_ERR && loglevelMin <= LOG_DEBUG);
+ tor_assert(loglevelMax >= LOG_ERR && loglevelMax <= LOG_DEBUG);
memset(severity_out, 0, sizeof(log_severity_list_t));
for (i = loglevelMin; i >= loglevelMax; --i) {
severity_out->masks[SEVERITY_MASK_IDX(i)] = ~0u;
@@ -1133,17 +1182,20 @@ mark_logs_temp(void)
}
/**
- * Add a log handler to send messages to <b>filename</b> via <b>fd</b>. If
- * opening the logfile failed, -1 is returned and errno is set appropriately
- * (by open(2)). Takes ownership of fd.
+ * Add a log handler to send messages to <b>filename</b>. If opening the
+ * logfile fails, -1 is returned and errno is set appropriately (by open(2)).
*/
int
-add_file_log(const log_severity_list_t *severity,
- const char *filename,
- int fd)
+add_file_log(const log_severity_list_t *severity, const char *filename,
+ const int truncate_log)
{
+ int fd;
logfile_t *lf;
+ int open_flags = O_WRONLY|O_CREAT;
+ open_flags |= truncate_log ? O_TRUNC : O_APPEND;
+
+ fd = tor_open_cloexec(filename, open_flags, 0640);
if (fd<0)
return -1;
if (tor_fd_seekend(fd)<0) {
@@ -1484,3 +1536,4 @@ truncate_logs(void)
}
}
}
+
diff --git a/src/common/memarea.c b/src/common/memarea.c
index 589277ba3d..68c1625fe4 100644
--- a/src/common/memarea.c
+++ b/src/common/memarea.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008-2018, The Tor Project, Inc. */
+/* Copyright (c) 2008-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/** \file memarea.c
@@ -9,10 +9,11 @@
#include "orconfig.h"
#include <stddef.h>
#include <stdlib.h>
-#include "common/memarea.h"
-#include "common/util.h"
-#include "common/compat.h"
-#include "lib/log/torlog.h"
+#include "memarea.h"
+#include "util.h"
+#include "compat.h"
+#include "torlog.h"
+#include "container.h"
#ifndef DISABLE_MEMORY_SENTINELS
diff --git a/src/common/memarea.h b/src/common/memarea.h
index 7dc7ec1fed..5207e8a5bd 100644
--- a/src/common/memarea.h
+++ b/src/common/memarea.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008-2018, The Tor Project, Inc. */
+/* Copyright (c) 2008-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/* Tor dependencies */
diff --git a/src/common/procmon.c b/src/common/procmon.c
index 7703b88afd..73c14cd584 100644
--- a/src/common/procmon.c
+++ b/src/common/procmon.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2018, The Tor Project, Inc. */
+/* Copyright (c) 2011-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -6,9 +6,9 @@
* \brief Process-termination monitor functions
**/
-#include "common/procmon.h"
+#include "procmon.h"
-#include "common/util.h"
+#include "util.h"
#ifdef HAVE_SIGNAL_H
#include <signal.h>
diff --git a/src/common/procmon.h b/src/common/procmon.h
index 246ddd71d0..63777e4111 100644
--- a/src/common/procmon.h
+++ b/src/common/procmon.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011-2018, The Tor Project, Inc. */
+/* Copyright (c) 2011-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -9,10 +9,10 @@
#ifndef TOR_PROCMON_H
#define TOR_PROCMON_H
-#include "common/compat.h"
-#include "common/compat_libevent.h"
+#include "compat.h"
+#include "compat_libevent.h"
-#include "lib/log/torlog.h"
+#include "torlog.h"
typedef struct tor_process_monitor_t tor_process_monitor_t;
diff --git a/src/common/pubsub.c b/src/common/pubsub.c
new file mode 100644
index 0000000000..336e8a6e7f
--- /dev/null
+++ b/src/common/pubsub.c
@@ -0,0 +1,129 @@
+/* Copyright (c) 2016-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file pubsub.c
+ *
+ * \brief DOCDOC
+ */
+
+#include "orconfig.h"
+#include "pubsub.h"
+#include "container.h"
+
+/** Helper: insert <b>s</b> into <b>topic's</b> list of subscribers, keeping
+ * them sorted in priority order. */
+static void
+subscriber_insert(pubsub_topic_t *topic, pubsub_subscriber_t *s)
+{
+ int i;
+ smartlist_t *sl = topic->subscribers;
+ for (i = 0; i < smartlist_len(sl); ++i) {
+ pubsub_subscriber_t *other = smartlist_get(sl, i);
+ if (s->priority < other->priority) {
+ break;
+ }
+ }
+ smartlist_insert(sl, i, s);
+}
+
+/**
+ * Add a new subscriber to <b>topic</b>, where (when an event is triggered),
+ * we'll notify the function <b>fn</b> by passing it <b>subscriber_data</b>.
+ * Return a handle to the subscribe which can later be passed to
+ * pubsub_unsubscribe_().
+ *
+ * Functions are called in priority order, from lowest to highest.
+ *
+ * See pubsub.h for <b>subscribe_flags</b>.
+ */
+const pubsub_subscriber_t *
+pubsub_subscribe_(pubsub_topic_t *topic,
+ pubsub_subscriber_fn_t fn,
+ void *subscriber_data,
+ unsigned subscribe_flags,
+ unsigned priority)
+{
+ tor_assert(! topic->locked);
+ if (subscribe_flags & SUBSCRIBE_ATSTART) {
+ tor_assert(topic->n_events_fired == 0);
+ }
+ pubsub_subscriber_t *r = tor_malloc_zero(sizeof(*r));
+ r->priority = priority;
+ r->subscriber_flags = subscribe_flags;
+ r->fn = fn;
+ r->subscriber_data = subscriber_data;
+ if (topic->subscribers == NULL) {
+ topic->subscribers = smartlist_new();
+ }
+ subscriber_insert(topic, r);
+ return r;
+}
+
+/**
+ * Remove the subscriber <b>s</b> from <b>topic</b>. After calling this
+ * function, <b>s</b> may no longer be used.
+ */
+int
+pubsub_unsubscribe_(pubsub_topic_t *topic,
+ const pubsub_subscriber_t *s)
+{
+ tor_assert(! topic->locked);
+ smartlist_t *sl = topic->subscribers;
+ if (sl == NULL)
+ return -1;
+ int i = smartlist_pos(sl, s);
+ if (i == -1)
+ return -1;
+ pubsub_subscriber_t *tmp = smartlist_get(sl, i);
+ tor_assert(tmp == s);
+ smartlist_del_keeporder(sl, i);
+ tor_free(tmp);
+ return 0;
+}
+
+/**
+ * For every subscriber s in <b>topic</b>, invoke notify_fn on s and
+ * event_data. Return 0 if there were no nonzero return values, and -1 if
+ * there were any.
+ */
+int
+pubsub_notify_(pubsub_topic_t *topic, pubsub_notify_fn_t notify_fn,
+ void *event_data, unsigned notify_flags)
+{
+ tor_assert(! topic->locked);
+ (void) notify_flags;
+ smartlist_t *sl = topic->subscribers;
+ int n_bad = 0;
+ ++topic->n_events_fired;
+ if (sl == NULL)
+ return -1;
+ topic->locked = 1;
+ SMARTLIST_FOREACH_BEGIN(sl, pubsub_subscriber_t *, s) {
+ int r = notify_fn(s, event_data);
+ if (r != 0)
+ ++n_bad;
+ } SMARTLIST_FOREACH_END(s);
+ topic->locked = 0;
+ return (n_bad == 0) ? 0 : -1;
+}
+
+/**
+ * Release all storage held by <b>topic</b>.
+ */
+void
+pubsub_clear_(pubsub_topic_t *topic)
+{
+ tor_assert(! topic->locked);
+
+ smartlist_t *sl = topic->subscribers;
+ if (sl == NULL)
+ return;
+ SMARTLIST_FOREACH_BEGIN(sl, pubsub_subscriber_t *, s) {
+ tor_free(s);
+ } SMARTLIST_FOREACH_END(s);
+ smartlist_free(sl);
+ topic->subscribers = NULL;
+ topic->n_events_fired = 0;
+}
+
diff --git a/src/common/pubsub.h b/src/common/pubsub.h
new file mode 100644
index 0000000000..2bee3af085
--- /dev/null
+++ b/src/common/pubsub.h
@@ -0,0 +1,179 @@
+/* Copyright (c) 2016-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file pubsub.h
+ * \brief Macros to implement publish/subscribe abstractions.
+ *
+ * To use these macros, call DECLARE_PUBSUB_TOPIC() with an identifier to use
+ * as your topic. Below, I'm going to assume you say DECLARE_PUBSUB_TOPIC(T).
+ *
+ * Doing this will declare the following types:
+ * typedef struct T_event_data_t T_event_data_t; // you define this struct
+ * typedef struct T_subscriber_data_t T_subscriber_data_t; // this one too.
+ * typedef struct T_subscriber_t T_subscriber_t; // opaque
+ * typedef int (*T_subscriber_fn_t)(T_event_data_t*, T_subscriber_data_t*);
+ *
+ * and it will declare the following functions:
+ * const T_subscriber_t *T_subscribe(T_subscriber_fn_t,
+ * T_subscriber_data_t *,
+ * unsigned flags,
+ * unsigned priority);
+ * int T_unsubscribe(const T_subscriber_t *)
+ *
+ * Elsewhere you can say DECLARE_NOTIFY_PUBSUB_TOPIC(static, T), which
+ * declares:
+ *
+ * static int T_notify(T_event_data_t *, unsigned notify_flags);
+ * static void T_clear(void);
+ *
+ * And in some C file, you would define these functions with:
+ * IMPLEMENT_PUBSUB_TOPIC(static, T).
+ *
+ * The implementations will be small typesafe wrappers over generic versions
+ * of the above functions.
+ *
+ * To use the typesafe functions, you add any number of subscribers with
+ * T_subscribe(). Each has an associated function pointer, data pointer,
+ * and priority. Later, you can invoke T_notify() to declare that the
+ * event has occurred. Each of the subscribers will be invoked once.
+ **/
+
+#ifndef TOR_PUBSUB_H
+#define TOR_PUBSUB_H
+
+#include "torint.h"
+
+/**
+ * Flag for T_subscribe: die with an assertion failure if the event
+ * have ever been published before. Used when a subscriber must absolutely
+ * never have missed an event.
+ */
+#define SUBSCRIBE_ATSTART (1u<<0)
+
+#define DECLARE_PUBSUB_STRUCT_TYPES(name) \
+ /* You define this type. */ \
+ typedef struct name ## _event_data_t name ## _event_data_t; \
+ /* You define this type. */ \
+ typedef struct name ## _subscriber_data_t name ## _subscriber_data_t;
+
+#define DECLARE_PUBSUB_TOPIC(name) \
+ /* This type is opaque. */ \
+ typedef struct name ## _subscriber_t name ## _subscriber_t; \
+ /* You declare functions matching this type. */ \
+ typedef int (*name ## _subscriber_fn_t)( \
+ name ## _event_data_t *data, \
+ name ## _subscriber_data_t *extra); \
+ /* Call this function to subscribe to a topic. */ \
+ const name ## _subscriber_t *name ## _subscribe( \
+ name##_subscriber_fn_t subscriber, \
+ name##_subscriber_data_t *extra_data, \
+ unsigned flags, \
+ unsigned priority); \
+ /* Call this function to unsubscribe from a topic. */ \
+ int name ## _unsubscribe(const name##_subscriber_t *s);
+
+#define DECLARE_NOTIFY_PUBSUB_TOPIC(linkage, name) \
+ /* Call this function to notify all subscribers. Flags not yet used. */ \
+ linkage int name ## _notify(name ## _event_data_t *data, unsigned flags); \
+ /* Call this function to release storage held by the topic. */ \
+ linkage void name ## _clear(void);
+
+/**
+ * Type used to hold a generic function for a subscriber.
+ *
+ * [Yes, it is safe to cast to this, so long as we cast back to the original
+ * type before calling. From C99: "A pointer to a function of one type may be
+ * converted to a pointer to a function of another type and back again; the
+ * result shall compare equal to the original pointer."]
+*/
+typedef int (*pubsub_subscriber_fn_t)(void *, void *);
+
+/**
+ * Helper type to implement pubsub abstraction. Don't use this directly.
+ * It represents a subscriber.
+ */
+typedef struct pubsub_subscriber_t {
+ /** Function to invoke when the event triggers. */
+ pubsub_subscriber_fn_t fn;
+ /** Data associated with this subscriber. */
+ void *subscriber_data;
+ /** Priority for this subscriber. Low priorities happen first. */
+ unsigned priority;
+ /** Flags set on this subscriber. Not yet used.*/
+ unsigned subscriber_flags;
+} pubsub_subscriber_t;
+
+/**
+ * Helper type to implement pubsub abstraction. Don't use this directly.
+ * It represents a topic, and keeps a record of subscribers.
+ */
+typedef struct pubsub_topic_t {
+ /** List of subscribers to this topic. May be NULL. */
+ struct smartlist_t *subscribers;
+ /** Total number of times that pubsub_notify_() has ever been called on this
+ * topic. */
+ uint64_t n_events_fired;
+ /** True iff we're running 'notify' on this topic, and shouldn't allow
+ * any concurrent modifications or events. */
+ unsigned locked;
+} pubsub_topic_t;
+
+const pubsub_subscriber_t *pubsub_subscribe_(pubsub_topic_t *topic,
+ pubsub_subscriber_fn_t fn,
+ void *subscriber_data,
+ unsigned subscribe_flags,
+ unsigned priority);
+int pubsub_unsubscribe_(pubsub_topic_t *topic, const pubsub_subscriber_t *sub);
+void pubsub_clear_(pubsub_topic_t *topic);
+typedef int (*pubsub_notify_fn_t)(pubsub_subscriber_t *subscriber,
+ void *notify_data);
+int pubsub_notify_(pubsub_topic_t *topic, pubsub_notify_fn_t notify_fn,
+ void *notify_data, unsigned notify_flags);
+
+#define IMPLEMENT_PUBSUB_TOPIC(notify_linkage, name) \
+ static pubsub_topic_t name ## _topic_ = { NULL, 0, 0 }; \
+ const name ## _subscriber_t * \
+ name ## _subscribe(name##_subscriber_fn_t subscriber, \
+ name##_subscriber_data_t *extra_data, \
+ unsigned flags, \
+ unsigned priority) \
+ { \
+ const pubsub_subscriber_t *s; \
+ s = pubsub_subscribe_(&name##_topic_, \
+ (pubsub_subscriber_fn_t)subscriber, \
+ extra_data, \
+ flags, \
+ priority); \
+ return (const name##_subscriber_t *)s; \
+ } \
+ int \
+ name ## _unsubscribe(const name##_subscriber_t *subscriber) \
+ { \
+ return pubsub_unsubscribe_(&name##_topic_, \
+ (const pubsub_subscriber_t *)subscriber); \
+ } \
+ static int \
+ name##_call_the_notify_fn_(pubsub_subscriber_t *subscriber, \
+ void *notify_data) \
+ { \
+ name ## _subscriber_fn_t fn; \
+ fn = (name ## _subscriber_fn_t) subscriber->fn; \
+ return fn(notify_data, subscriber->subscriber_data); \
+ } \
+ notify_linkage int \
+ name ## _notify(name ## _event_data_t *event_data, unsigned flags) \
+ { \
+ return pubsub_notify_(&name##_topic_, \
+ name##_call_the_notify_fn_, \
+ event_data, \
+ flags); \
+ } \
+ notify_linkage void \
+ name ## _clear(void) \
+ { \
+ pubsub_clear_(&name##_topic_); \
+ }
+
+#endif /* !defined(TOR_PUBSUB_H) */
+
diff --git a/src/common/sandbox.c b/src/common/sandbox.c
index b41b8f4ba5..440f8722f2 100644
--- a/src/common/sandbox.c
+++ b/src/common/sandbox.c
@@ -1,7 +1,7 @@
-/* Copyright (c) 2001 Matej Pfajfar.
+ /* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -32,18 +32,15 @@
#include <string.h>
#include <stdlib.h>
-#include "common/sandbox.h"
-#include "lib/container/map.h"
-#include "lib/err/torerr.h"
-#include "lib/log/torlog.h"
-#include "lib/cc/torint.h"
-#include "common/util.h"
+#include "sandbox.h"
+#include "container.h"
+#include "torlog.h"
+#include "torint.h"
+#include "util.h"
#include "tor_queue.h"
#include "ht.h"
-#include "siphash.h"
-
#define DEBUGGING_CLOSE
#if defined(USE_LIBSECCOMP)
@@ -82,7 +79,7 @@
defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_SIGACTION)
#define USE_BACKTRACE
#define EXPOSE_CLEAN_BACKTRACE
-#include "lib/err/backtrace.h"
+#include "backtrace.h"
#endif /* defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && ... */
#ifdef USE_BACKTRACE
@@ -1977,3 +1974,4 @@ sandbox_disable_getaddrinfo_cache(void)
{
}
#endif /* !defined(USE_LIBSECCOMP) */
+
diff --git a/src/common/sandbox.h b/src/common/sandbox.h
index f7c990e013..d0f85570f4 100644
--- a/src/common/sandbox.h
+++ b/src/common/sandbox.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -13,7 +13,7 @@
#define SANDBOX_H_
#include "orconfig.h"
-#include "lib/cc/torint.h"
+#include "torint.h"
#ifndef SYS_SECCOMP
diff --git a/src/common/storagedir.c b/src/common/storagedir.c
index 10b2301274..e2c7b4bb87 100644
--- a/src/common/storagedir.c
+++ b/src/common/storagedir.c
@@ -1,14 +1,14 @@
-/* Copyright (c) 2017-2018, The Tor Project, Inc. */
+/* Copyright (c) 2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
-#include "lib/container/smartlist.h"
-#include "common/compat.h"
-#include "common/confline.h"
-#include "common/memarea.h"
-#include "common/sandbox.h"
-#include "common/storagedir.h"
-#include "lib/log/torlog.h"
-#include "common/util.h"
+#include "container.h"
+#include "compat.h"
+#include "confline.h"
+#include "memarea.h"
+#include "sandbox.h"
+#include "storagedir.h"
+#include "torlog.h"
+#include "util.h"
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
@@ -583,3 +583,4 @@ storage_dir_get_max_files(storage_dir_t *d)
{
return d->max_files;
}
+
diff --git a/src/common/storagedir.h b/src/common/storagedir.h
index 3b46c20b5d..d99bd7ec52 100644
--- a/src/common/storagedir.h
+++ b/src/common/storagedir.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2017-2018, The Tor Project, Inc. */
+/* Copyright (c) 2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_STORAGEDIR_H
diff --git a/src/lib/testsupport/testsupport.h b/src/common/testsupport.h
index 9a55d306fc..a3f2ff91ed 100644
--- a/src/lib/testsupport/testsupport.h
+++ b/src/common/testsupport.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2018, The Tor Project, Inc. */
+/* Copyright (c) 2013-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_TESTSUPPORT_H
diff --git a/src/common/timers.c b/src/common/timers.c
index 72562f4cf5..6f6236ed3b 100644
--- a/src/common/timers.c
+++ b/src/common/timers.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2016-2018, The Tor Project, Inc. */
+/* Copyright (c) 2016-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -31,11 +31,11 @@
#define TOR_TIMERS_PRIVATE
-#include "common/compat.h"
-#include "common/compat_libevent.h"
-#include "common/timers.h"
-#include "lib/log/torlog.h"
-#include "common/util.h"
+#include "compat.h"
+#include "compat_libevent.h"
+#include "timers.h"
+#include "torlog.h"
+#include "util.h"
struct timeout_cb {
timer_cb_fn_t cb;
diff --git a/src/common/timers.h b/src/common/timers.h
index 2348c7b7c1..6d27f3e01e 100644
--- a/src/common/timers.h
+++ b/src/common/timers.h
@@ -1,11 +1,11 @@
-/* Copyright (c) 2016-2018, The Tor Project, Inc. */
+/* Copyright (c) 2016-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_TIMERS_H
#define TOR_TIMERS_H
#include "orconfig.h"
-#include "lib/testsupport/testsupport.h"
+#include "testsupport.h"
struct monotime_t;
typedef struct timeout tor_timer_t;
diff --git a/src/common/token_bucket.c b/src/common/token_bucket.c
index 3a16720d7f..f2396ec58a 100644
--- a/src/common/token_bucket.c
+++ b/src/common/token_bucket.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2018-2018, The Tor Project, Inc. */
+/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -18,9 +18,8 @@
#define TOKEN_BUCKET_PRIVATE
-#include "common/token_bucket.h"
-#include "common/compat.h"
-#include "lib/log/util_bug.h"
+#include "token_bucket.h"
+#include "util_bug.h"
/**
* Set the <b>rate</b> and <b>burst</b> value in a token_bucket_cfg.
@@ -253,3 +252,4 @@ token_bucket_rw_dec(token_bucket_rw_t *bucket,
flags |= TB_WRITE;
return flags;
}
+
diff --git a/src/common/token_bucket.h b/src/common/token_bucket.h
index 787317fa1f..0e7832e838 100644
--- a/src/common/token_bucket.h
+++ b/src/common/token_bucket.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2018-2018, The Tor Project, Inc. */
+/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -9,8 +9,8 @@
#ifndef TOR_TOKEN_BUCKET_H
#define TOR_TOKEN_BUCKET_H
-#include "lib/cc/torint.h"
-#include "lib/testsupport/testsupport.h"
+#include "torint.h"
+#include "testsupport.h"
/** Largest allowable burst value for a token buffer. */
#define TOKEN_BUCKET_MAX_BURST INT32_MAX
diff --git a/src/lib/cc/torint.h b/src/common/torint.h
index 55b15402f2..fc7818fe2c 100644
--- a/src/lib/cc/torint.h
+++ b/src/common/torint.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2018, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
diff --git a/src/lib/log/torlog.h b/src/common/torlog.h
index c24b638191..de389883c0 100644
--- a/src/lib/log/torlog.h
+++ b/src/common/torlog.h
@@ -1,7 +1,7 @@
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Co