14695 Commits

Author SHA1 Message Date
xanimo
d693d4a008
random: getentropy on macOS does not need unistd.h
change sys/random.h to random.h in AC_MSG_CHECK
remove definitions that are applicable to macos which include unistd.h
additionally change comparator argument from NULL to nullptr when evaluating &getentropy

Inspired by: c13c97dbf846cf0e6a5581ac414ef96a215b0dc6
2024-06-13 11:44:33 -07:00
James Hilliard
743c3acd3d
Check if sys/random.h is required for getentropy on OSX.
Cherry-picked from: ee2d10ad0c0e04d0b9da4535a6fff265ac2501e5
2024-06-13 11:42:50 -07:00
Pieter Wuille
265f258540
scripted-diff: Use new naming style for insecure_rand* functions
-BEGIN VERIFY SCRIPT-
sed -i 's/\<insecure_randbits(/InsecureRandBits(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
sed -i 's/\<insecure_randbool(/InsecureRandBool(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
sed -i 's/\<insecure_randrange(/InsecureRandRange(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
sed -i 's/\<insecure_randbytes(/InsecureRandBytes(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
sed -i 's/\<insecure_rand256(/InsecureRand256(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
sed -i 's/\<insecure_rand(/InsecureRand32(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
sed -i 's/\<seed_insecure_rand(/SeedInsecureRand(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
-END VERIFY SCRIPT-

Cherry-picked from: e945848582160b23fa0bc6f797e2bd8ac676ee0e
2024-06-13 11:42:49 -07:00
Pieter Wuille
7abc3c6c6d
scripted-diff: Use randbits/bool instead of randrange where possible
-BEGIN VERIFY SCRIPT-
sed -i 's/insecure_randbits(1)/insecure_randbool()/g' src/test/*_tests.cpp
sed -i 's/insecure_randrange(2)/insecure_randbool()/g' src/test/*_tests.cpp
sed -i 's/insecure_randrange(4)/insecure_randbits(2)/g' src/test/*_tests.cpp
sed -i 's/insecure_randrange(32)/insecure_randbits(5)/g' src/test/*_tests.cpp
sed -i 's/insecure_randrange(256)/insecure_randbits(8)/g' src/test/*_tests.cpp
-END VERIFY SCRIPT-

Cherry-picked from: 2fcd9cc86bfce944e3312e9a24685403250f3bdc
2024-06-13 11:42:49 -07:00
Pieter Wuille
046cbb0091
Use randbits instead of ad-hoc emulation in prevector tests
Cherry-picked from: 2ada67852174a76753080d65a7adbe27241a9caa
2024-06-13 11:42:49 -07:00
Pieter Wuille
9fa9876e4c
Replace rand() & ((1 << N) - 1) with randbits(N)
Cherry-picked from: 5f0b04eedc5bbdb9319c9f1f1a6c599337f5bbe3
2024-06-13 11:42:48 -07:00
Pieter Wuille
a36981dec6
Replace more rand() % NUM by randranges
Cherry-picked from: 3ecabae36364e905e7821fba3e60aa7f8418de6c
2024-06-13 11:42:48 -07:00
Pieter Wuille
fe5b701634
scripted-diff: use insecure_rand256/randrange more
-BEGIN VERIFY SCRIPT-
sed -i "s/\<GetRandHash(/insecure_rand256(/" src/test/*_tests.cpp
sed -i "s/\<GetRand(/insecure_randrange(/" src/test/*_tests.cpp src/test/test_bitcoin.cpp
sed -i 's/\<insecure_rand() % \([0-9]\+\)/insecure_randrange(\1)/g' src/test/*_tests.cpp
-END VERIFY SCRIPT-

Cherry-picked from: efee1db21a652019e0ab18fffc233d91bb7f1816
2024-06-13 11:42:48 -07:00
Pieter Wuille
2ee602e3ce
Add various insecure_rand wrappers for tests
Cherry-picked from: 1119927df03c94f9306e4d92f55d147b900522fb
2024-06-13 11:42:47 -07:00
Pieter Wuille
9feb51fe9d
Merge test_random.h into test_bitcoin.h
Cherry-picked from: 124d13a58cdcd9f66eeffc7e6281e3eb129e3398
2024-06-13 11:42:47 -07:00
Pieter Wuille
a8cad7ed4c
Add FastRandomContext::rand256() and ::randbytes()
FastRandomContext now provides all functionality that the real Rand* functions
provide.

Cherry-picked from: 37e864eb9fee4b592bd61c5ec3555b00a2de2cf7
2024-06-13 11:42:47 -07:00
Pieter Wuille
3f511675be
Add a FastRandomContext::randrange and use it
Cherry-picked from: 4fd2d2fc97e21efceab849576e544160fd5e3e3d
2024-06-13 11:42:46 -07:00
Pieter Wuille
b2dc5e349b
Switch FastRandomContext to ChaCha20
Cherry-picked from: 16329224e70d0525208f6b0ba00c5e1531a4f5ea
2024-06-13 11:42:46 -07:00
Wladimir J. van der Laan
74888ca567
random: Add fallback if getrandom syscall not available
If the code was compiled with newer (>=3.17) kernel headers but executed
on a system without the system call, every use of random would crash the
program. Add a fallback for that case.

Cherry-picked from: 7e6dcd9995b99e894b8017f09016c405b066ca36
2024-06-13 11:42:46 -07:00
Wladimir J. van der Laan
18a8fd4506
sanity: Move OS random to sanity check function
Move the OS random test to a sanity check function that is called every
time bitcoind is initialized.

Keep `src/test/random_tests.cpp` for the case that later random tests
are added, and keep a rudimentary test that just calls the sanity check.

Cherry-picked from: 7cad84929907c4294f07377453aa77887911b486
2024-06-13 11:42:45 -07:00
Wladimir J. van der Laan
f75d5ea728
util: Specific GetOSRandom for Linux/FreeBSD/OpenBSD
These are available in sandboxes without access to files or
devices. Also [they are safer and more straightforward](https://en.wikipedia.org/wiki/Entropy-supplying_system_calls)
to use than `/dev/urandom` as reading from a file has quite a few edge
cases:

- Linux: `getrandom(buf, buflen, 0)`. [getrandom(2)](http://man7.org/linux/man-pages/man2/getrandom.2.html)
  was introduced in version 3.17 of the Linux kernel.
- OpenBSD: `getentropy(buf, buflen)`. The [getentropy(2)](http://man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2)
  function appeared in OpenBSD 5.6.
- FreeBSD and NetBSD: `sysctl(KERN_ARND)`. Not sure when this was added
  but it has existed for quite a while.

Alternatives:

- Linux has sysctl `CTL_KERN` / `KERN_RANDOM` / `RANDOM_UUID`
  which gives 16 bytes of randomness. This may be available
  on older kernels, however [sysctl is deprecated on Linux](https://lwn.net/Articles/605392/)
  and even removed in some distros so we shouldn't use it.

Add tests for `GetOSRand()`:

- Test that no error happens (otherwise `RandFailure()` which aborts)
- Test that all 32 bytes are overwritten (initialize with zeros, try multiple times)

Discussion:

- When to use these? Currently they are always used when available.
  Another option would be to use them only when `/dev/urandom` is not
  available. But this would mean these code paths receive less testing,
  and I'm not sure there is any reason to prefer `/dev/urandom`.

Closes: #9676

Cherry-picked from: 224e6eb089a0f4977d22f3803fc27e44b5e7eea5

Contains squashed commit of aa09ccbb74ea9febd83ce3362238ac5339069909 squashme: comment that NUM_OS_RANDOM_BYTES should not be changed lightly
2024-06-13 11:42:45 -07:00
Pieter Wuille
e25cad0012
Add ChaCha20
Cherry-picked from: e04326fe6652543dc26d90eba4a48fbdc935fd0c
2024-06-13 11:42:45 -07:00
Pieter Wuille
6ec0fe4acb
FastRandom benchmark
Cherry-picked from: 663fbae7776b0c238f6f27d73811b4bc627d0b6b
2024-06-13 11:42:44 -07:00
Pieter Wuille
cab3eb10ab
Introduce FastRandomContext::randbool()
Cherry-picked from: c21cbe61c6249bcfca098705df6f9b4baab9f296
2024-06-13 11:42:44 -07:00
Old Dip Tracker
0879cb86e7
Merge pull request #3529 from mazyaryousefinia/master
fix: update Persian readme
2024-06-12 13:38:28 +02:00
Patrick Lodder
0d2ce0a1e8
doc: add security policy with contacts 2024-06-11 01:36:51 -04:00
chromatic
9d6b484134
Merge pull request #3494 from patricklodder/1.15.0-ax_cxx_compile_stdcxx
build: update AX_CXX_COMPILE_STDCXX to serial 18
2024-05-30 20:33:08 -07:00
mazyaryousefinia
c32958a0fe Update Persian readme 2024-04-27 14:47:40 +03:30
Russell Yanofsky
11f5dd6ea9
Add unit test for DEBUG_LOCKORDER code
Cherry-picked from: 41b88e933
2024-04-17 09:56:16 -04:00
Patrick Lodder
a9129315f5
cleanup: remove unneccesary boost dependencies from sync.cpp
Removes boost dependencies in sync.cpp in favor of standard c++
for-loops, improving readability.
2024-04-17 09:56:16 -04:00
Patrick Lodder
06e4040717
refactor: remove DEBUG_LOCKORDER undefined behavior
Removes undefined behavior by refactoring the way we destruct
objects that track mutexes when debugging.

1. Prevent UB from LockData custom destructor by making it implicit
2. Replace the thread_specific_ptr holding the lock stack with a
   static map that stores it per thread.

Also cleans up the aliasing to make the code better readable.

Backported from: 458992b0
                 8d8921ab
                 f511f61d
                 58e6881b
                 26c093a9

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
Co-authored-by: Wladimir J. van der Laan <laanwj@protonmail.com>
2024-04-17 09:56:15 -04:00
chromatic
27b08e8fd1
Merge pull request #3517 from patricklodder/ci/codeql-v3-dev
ci: update codeql to v3
2024-04-13 22:42:55 -07:00
Patrick Lodder
73d977b4d5
ci: update codeql to v3 2024-04-11 16:54:16 -04:00
Old Dip Tracker
497c6026fc
Merge pull request #3506 from danielw86dev/1.15.0-dev-fix-rebrand-koinu
fix: missing koinu string
2024-04-07 16:11:04 +02:00
chromatic
672018c33c
Merge pull request #3499 from danielw86dev/1.15.0-dev-add-rpc-uptime
rpc: add uptime (backport)
2024-04-03 17:49:28 -07:00
danielw86dev
45dd454e25 fix: mising koinu rebrand 2024-04-02 19:32:55 +02:00
Ricardo Velhote
69a7fc7cd6 [RPC] Add an uptime command that displays the amount of time that bitcoind has been running
Cherry-picked from: c07475294a

Resolved conflict:
- change path to qa\rpc-tests\uptime.py and qa\pull-tester\rpc-tests.py
- src\util.cpp

Manually executed:
- qa\rpc-tests\uptime.py: overridden setup_network(), skip connecting nodes
- doc\rpc-maturity.md: add uptime rpc

Co-Authored-By: danielw86dev <67072678+danielw86dev@users.noreply.github.com>
2024-04-02 13:37:27 +02:00
chromatic
6c0095bed1
Merge pull request #3488 from patricklodder/1.15-fs-wrapper
backport: fs wrapper
2024-03-27 16:03:22 -07:00
Patrick Lodder
6c3a24b252
build: update AX_CXX_COMPILE_STDCXX to serial 18
Downloaded the latest version available from
https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
at the time of writing. This allows configuring for up to c++20.
2024-03-27 16:18:01 -04:00
chromatic
3738a5311a
Merge pull request #3490 from patricklodder/1.15.0-const-comparator-operator
net: make IteratorComparator's operator const
2024-03-27 12:32:08 -07:00
chromatic
aefb848ef4
Merge pull request #3492 from patricklodder/1.15-ci-cxx14-experimental
ci: run experimental CIs with c++14
2024-03-27 11:58:40 -07:00
Old Dip Tracker
e249afc03e
Merge pull request #3362 from edtubbs/1.14.7-dev-freetype
depends: updated to freetype 2.11.0
2024-03-27 01:55:02 +01:00
Patrick Lodder
9134d9e090
ci: run experimental CIs with c++14 2024-03-25 21:16:00 -04:00
Ed Tubbs
97c64ffdba depends: updated to freetype 2.11.0 2024-03-25 22:49:29 +00:00
Patrick Lodder
bcdcf24f35
net: make IteratorComparator's operator const
Although this is okay to be sloppy on c++11, it is not okay when
using c++17. See: https://cplusplus.github.io/LWG/issue2542
2024-03-24 22:24:06 -04:00
Wladimir J. van der Laan
b16ff7152c
torcontrol: Use fs::path instead of std::string for private key path
Cherry-picked from: 75594bd7f
2024-03-24 16:38:08 -04:00
Wladimir J. van der Laan
d1dba0ac38
Use fsbridge for fopen and freopen
Abstracts away how a path is opened to a `FILE*`.

Reduces the number of places where path is converted to a string
for anything else but printing.

Cherry-picked from: 2a5f5747

Conflicts:
- additional instances in bitcoin-tx.cpp and test/script_tests.cpp
2024-03-24 16:38:08 -04:00
Patrick Lodder
a2caaf1f99
rewire calls to boost::filesystem to use the fs wrapper
* replaces boost/filesystem includes with fs.h
* replaces boost::filesystem:: with fs::
* removes file-local fs namespace aliases
* removes unused includes from:
  * net.h
  * src/wallet/walletdb.cpp
* adds missing includes in:
  * rpc/protocol.cpp
  * test/dbwrapper_tests.cpp
  * wallet/rpcutil.cpp
2024-03-24 16:38:08 -04:00
Wladimir J. van der Laan
e044c640b3
Add fs.cpp/h
Cherry-picked from: 19e36bbef
2024-03-24 16:38:04 -04:00
Old Dip Tracker
5eaff1e096
Merge pull request #3480 from spencerlepine/1.15.0-dev-typos
fix: minor typo corrections
2024-03-15 01:07:17 +01:00
Old Dip Tracker
fbc0c28b8b
Merge pull request #3479 from TailsFanLOL/patch-1
Fix a minor formatting mistake in build-unix.md
2024-03-14 15:31:42 +01:00
Twinky-kms
7f089c6257
bump expat version
2.5.0 version of expat has a vulnerability in it and it is recommended to use 2.6.2 as seen in the file names on the download page.
2024-03-14 03:28:26 -04:00
Spencer Lepine
346a51ca0a fix: minor typo corrections 2024-03-13 15:07:17 -07:00
ApertureUA
1282bdbe66
Fix a minor formatting mistake in build-unix.md
[Minor Spelling Mistake, I Win](https://github-production-user-asset-6210df.s3.amazonaws.com/96183936/284324285-d9adcb91-4aa2-4fa1-bccc-c1a9235d4109.webm)
2024-03-13 15:49:34 +02:00
Patrick Lodder
0495f2a7f3
rpc: add dust stats to getblockstats
adds:
- maxoutamount - highest value output
- minoutamount - lowest value output
- dustouts - number of outputs under our soft dust limit

Each of these ignores OP_RETURN and coinbase outputs
2024-03-12 17:12:49 -04:00