diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 71995f49b..7b145f602 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,14 +25,20 @@ jobs: matrix: name: - armhf-linux + - armhf-linux-test-encrypt - aarch64-linux + - aarch64-linux-test-encrypt - x86_64-linux-dbg - x86_64-linux-openenclave - x86_64-macos + - x86_64-macos-test-encrypt # - arm64-macos - x86_64-win + - x86_64-win-test-encrypt - i686-win + - i686-win-test-encrypt - i686-linux + - i686-linux-test-encrypt include: - name: armhf-linux host: arm-linux-gnueabihf @@ -42,6 +48,14 @@ jobs: config-opts: "--enable-static --disable-shared" run-tests: true goal: install + - name: armhf-linux-test-encrypt + host: arm-linux-gnueabihf + os: ubuntu-20.04 + packages: g++-arm-linux-gnueabihf qemu-user-static qemu-user + dep-opts: "CROSS_COMPILE='yes' SPEED=slow V=1" + config-opts: "--enable-static --disable-shared --enable-test-encrypt --enable-test-passwd" + run-tests: true + goal: install - name: aarch64-linux host: aarch64-linux-gnu os: ubuntu-20.04 @@ -50,6 +64,14 @@ jobs: config-opts: "LIBS='-levent_pthreads' --enable-static --disable-shared" run-tests: true goal: install + - name: aarch64-linux-test-encrypt + host: aarch64-linux-gnu + os: ubuntu-20.04 + packages: g++-aarch64-linux-gnu qemu-user-static qemu-user + dep-opts: "CROSS_COMPILE='yes' SPEED=slow V=1" + config-opts: "LIBS='-levent_pthreads' --enable-static --disable-shared --enable-test-encrypt --enable-test-passwd" + run-tests: true + goal: install - name: x86_64-linux-dbg host: x86_64-pc-linux-gnu os: ubuntu-20.04 @@ -64,7 +86,7 @@ jobs: run-tests: true packages: python3-dev python3-dbg python dep-opts: "DEBUG=1 SPEED=slow V=1" - config-opts: "--enable-debug --enable-openenclave CFLAGS=-U_FORTIFY_SOURCE" + config-opts: "--enable-debug --enable-test-encrypt --enable-test-passwd --enable-openenclave CFLAGS=-U_FORTIFY_SOURCE" goal: install - name: x86_64-macos host: x86_64-apple-darwin15 @@ -77,6 +99,17 @@ jobs: sdk: 12.2 sdk-build: 12B45b sdk-shasum: "df75d30ecafc429e905134333aeae56ac65fac67cb4182622398fd717df77619" + - name: x86_64-macos-test-encrypt + host: x86_64-apple-darwin15 + os: macos-latest + run-tests: true + dep-opts: "SPEED=slow V=1" + config-opts: "--enable-static --disable-shared --enable-test-encrypt --enable-test-passwd" + packages: cmake zlib xorriso + goal: install + sdk: 12.2 + sdk-build: 12B45b + sdk-shasum: "df75d30ecafc429e905134333aeae56ac65fac67cb4182622398fd717df77619" # - name: arm64-macos # host: arm64-apple-darwin # os: macos-latest @@ -102,6 +135,20 @@ jobs: config-opts: "" run-tests: true goal: install + - name: x86_64-win-test-encrypt + host: x86_64-w64-mingw32 + arch: i386 + os: ubuntu-20.04 + packages: python3 nsis g++-mingw-w64-x86-64 wine64 wine-stable bc wine-binfmt + postinstall: | + sudo dpkg -s mono-runtime && sudo apt-get remove mono-runtime || echo "Very nothing to uninstall." + sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix + sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix + sudo update-binfmts --import /usr/share/binfmts/wine + dep-opts: "CROSS_COMPILE='yes' SPEED=slow V=1" + config-opts: "--enable-test-encrypt --enable-test-passwd" + run-tests: true + goal: install - name: i686-win host: i686-w64-mingw32 arch: i386 @@ -124,6 +171,28 @@ jobs: config-opts: "" run-tests: true goal: install + - name: i686-win-test-encrypt + host: i686-w64-mingw32 + arch: i386 + os: ubuntu-20.04 + packages: python3-pip python3-setuptools nsis g++ g++-mingw-w64-i686 mingw-w64-i686-dev wine-stable winehq-stable bc wine-binfmt binfmt-support + preinstall: | + OS_FLAVOR=$(cat /etc/*ease | grep UBUNTU_CODENAME | cut -d "=" -f 2) + if [ ! -d "/etc/apt/keyrings" ]; then sudo mkdir -pm755 /etc/apt/keyrings; fi + sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key + sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/$OS_FLAVOR/winehq-$OS_FLAVOR.sources + sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list + sudo apt-get update -qq + sudo apt-get install -yqq --allow-downgrades libgd3/focal libpcre2-8-0/focal libpcre2-16-0/focal libpcre2-32-0/focal libpcre2-posix2/focal + sudo apt-get purge -yqq libmono* moby* mono* php* libgdiplus libpcre2-posix3 libzip4 + postinstall: | + sudo update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix + sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix + sudo update-binfmts --import /usr/share/binfmts/wine + dep-opts: "CROSS_COMPILE='yes' SPEED=slow V=1" + config-opts: "--enable-test-encrypt --enable-test-passwd" + run-tests: true + goal: install - name: i686-linux host: i686-pc-linux-gnu os: ubuntu-20.04 @@ -132,6 +201,14 @@ jobs: dep-opts: "SPEED=slow V=1" config-opts: "--enable-static --disable-shared" goal: install + - name: i686-linux-test-encrypt + host: i686-pc-linux-gnu + os: ubuntu-20.04 + packages: g++-multilib bc + run-tests: true + dep-opts: "SPEED=slow V=1" + config-opts: "--enable-static --disable-shared --enable-test-encrypt --enable-test-passwd" + goal: install runs-on: ${{ matrix.os }} @@ -147,7 +224,7 @@ jobs: - name: install packages run: | - if ([ "${{ matrix.name }}" == "x86_64-macos" ] || [ "${{ matrix.name }}" == "arm64-macos" ]); then + if ([ "${{ matrix.name }}" == "x86_64-macos" ] || [ "${{ matrix.name }}" == "arm64-macos" ] || [ "${{ matrix.name }}" == "x86_64-macos-test-encrypt" ]); then brew update brew install automake coreutils ${{ matrix.packages }} echo PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" >> ~/.bashrc @@ -216,7 +293,7 @@ jobs: build_dir=./build/libdogecoin-${{ github.sha }}-${{ matrix.name }} make -j"$(getconf _NPROCESSORS_ONLN)" SPEED=slow V=1 mkdir -p $build_dir/bin $build_dir/docs $build_dir/examples $build_dir/include $build_dir/lib - if ([ "${{ matrix.name }}" == "x86_64-win" ] || [ "${{ matrix.name }}" == "i686-win" ]); then + if ([ "${{ matrix.name }}" == "x86_64-win" ] || [ "${{ matrix.name }}" == "i686-win" ] || [ "${{ matrix.name }}" == "x86_64-win-test-encrypt" ] || [ "${{ matrix.name }}" == "i686-win-test-encrypt" ]); then cp spvnode.exe such.exe sendtx.exe $build_dir/bin/ else cp spvnode such sendtx $build_dir/bin/ @@ -239,9 +316,15 @@ jobs: "armhf-linux") qemu-arm -E LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib/ /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 ./tests ;; + "armhf-linux-test-encrypt") + qemu-arm -E LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib/ /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 ./tests + ;; "aarch64-linux") qemu-aarch64 -E LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib/ /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 ./tests ;; + "aarch64-linux-test-encrypt") + qemu-aarch64 -E LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib/ /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 ./tests + ;; "x86_64-linux-dbg") make check -j"$(getconf _NPROCESSORS_ONLN)" V=1 python3 tooltests.py diff --git a/.gitignore b/.gitignore index dfe41248d..23c15c09a 100644 --- a/.gitignore +++ b/.gitignore @@ -149,3 +149,7 @@ include/include.am # QR qrtest.png qrtest.jpg + +# Store +store/* +.store/* diff --git a/CMakeLists.txt b/CMakeLists.txt index f38e57059..da654427c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,9 @@ SET(WITH_WALLET TRUE CACHE BOOL "enable wallet") SET(USE_SSE2 FALSE CACHE BOOL "enable scrypt sse2") SET(USE_TPM2 TRUE CACHE BOOL "enable tpm2") SET(USE_OPENENCLAVE FALSE CACHE BOOL "enable openenclave") -SET(TEST_PASSWD TRUE CACHE BOOL "enable test password") +SET(TEST_ENCRYPT TRUE CACHE BOOL "enable test encrypt") +SET(TEST_PASSWD FALSE CACHE BOOL "enable test password") +string(RANDOM LENGTH 12 ALPHABET abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 PASSWD_STR) SET(RANDOM_DEVICE "/dev/urandom" CACHE STRING "set the device to read random data from") # Set a default build type if none was specified @@ -111,8 +113,12 @@ ENDIF() IF(USE_OPENENCLAVE) ADD_DEFINITIONS(-DUSE_OPENENCLAVE=1) ENDIF() +IF(TEST_ENCRYPT) + ADD_DEFINITIONS(-DTEST_ENCRYPT=1) +ENDIF() IF(TEST_PASSWD) ADD_DEFINITIONS(-DTEST_PASSWD=1) + ADD_DEFINITIONS(-DPASSWD_STR="${PASSWD_STR}") ENDIF() MESSAGE(STATUS "") @@ -126,7 +132,11 @@ MESSAGE(STATUS " WITH_WALLET = ${WITH_WALLET}") MESSAGE(STATUS "") MESSAGE(STATUS " USE_SSE2 = ${USE_SSE2}") MESSAGE(STATUS " USE_TPM2 = ${USE_TPM2}") +MESSAGE(STATUS " TEST_ENCRYPT = ${TEST_ENCRYPT}") MESSAGE(STATUS " TEST_PASSWD = ${TEST_PASSWD}") +IF(TEST_PASSWD) +MESSAGE(STATUS " ${PASSWD_STR}") +ENDIF() MESSAGE(STATUS "") MESSAGE(STATUS " openenclave = ${USE_OPENENCLAVE}") MESSAGE(STATUS "") diff --git a/configure.ac b/configure.ac index 2469404ce..d9c9a3c19 100644 --- a/configure.ac +++ b/configure.ac @@ -139,11 +139,17 @@ AC_ARG_ENABLE(tests, [use_tests=$enableval], [use_tests=yes]) +AC_ARG_ENABLE([test-encrypt], + [AS_HELP_STRING([--enable-test-encrypt], + [disable test encrypt/decrypt (default is no)])], + [test_encrypt=$enableval], + [test_encrypt=no]) + AC_ARG_ENABLE([test-passwd], [AS_HELP_STRING([--enable-test-passwd], - [enable test password for encrypt/decrypt (default is yes)])], + [enable test password for encrypt/decrypt (default is no)])], [test_passwd=$enableval], - [test_passwd=yes]) + [test_passwd=no]) AC_MSG_CHECKING([for __builtin_expect]) AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void myfunc() {__builtin_expect(0,0);}]])], @@ -188,8 +194,14 @@ if test "x$enable_debug" = xyes; then AC_DEFINE_UNQUOTED([ENABLE_DEBUG],[1],[Define to 1 to enable debug output]) fi +if test "x$test_encrypt" = xyes; then + AC_DEFINE_UNQUOTED([TEST_ENCRYPT],[1],[Define to 1 to enable test encrypt/decrypt]) +fi + if test "x$test_passwd" = xyes; then AC_DEFINE_UNQUOTED([TEST_PASSWD],[1],[Define to 1 to enable test password]) + PASSWD_STR=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 12` + AC_SUBST(PASSWD_STR) fi if test "x$with_net" = xyes; then @@ -248,7 +260,11 @@ echo " with wallet = $with_wallet" echo " with unistring = $with_unistring" echo echo " SSE2 Scrypt = $use_scrypt_sse2" +echo " test encrypt = $test_encrypt" echo " test password = $test_passwd" +if test "x$test_passwd" = xyes; then +echo " = $PASSWD_STR" +fi echo echo " openenclave = $use_openenclave" echo diff --git a/doc/getting_started.md b/doc/getting_started.md index 7e72e4b19..ea94e92e4 100644 --- a/doc/getting_started.md +++ b/doc/getting_started.md @@ -53,6 +53,13 @@ At this step there are plenty of flags that can be specified, the two most perti ./configure CFLAGS='-Ipath/to/additional/include/files' ``` +Another useful flag is `--enable-test-passwd`, which will generate a random password for the wallet encryption key. This is useful for testing purposes, but should never be used in production. This flag is disabled by default, but can be enabled with the following command: +```c +./configure --enable-test-passwd +``` + +### `--enable-test-passwd` is for **testing purposes only** and should never be used in production. + For a complete list of all different configuration options, you can run the command `./configure --help`. Finally, once you have configured the library to your liking, it is ready to be built. This can be done with the simple `make` command: diff --git a/src/seal.c b/src/seal.c index 1739ce055..fa408e0c6 100644 --- a/src/seal.c +++ b/src/seal.c @@ -66,7 +66,6 @@ #define AES_KEY_SIZE 32 #define AES_IV_SIZE 16 #define SALT_SIZE 16 -#define TEST_PASS "12345678" #define NAME_MAX_LEN 100 #define PASS_MAX_LEN 100 #define FILE_PATH_MAX_LEN 1000 @@ -511,9 +510,14 @@ LIBDOGECOIN_API dogecoin_bool dogecoin_encrypt_seed_with_sw(const SEED seed, con // Prompt for the password char* password = malloc(PASS_MAX_LEN); #ifdef TEST_PASSWD - strcpy(password, TEST_PASS); + strcpy(password, PASSWD_STR); #else password = getpass("Enter password for seed encryption: \n"); + if (password == NULL) + { + fprintf(stderr, "ERROR: Failed to read password.\n"); + return false; + } #endif if (strlen(password) == 0) { @@ -525,9 +529,15 @@ LIBDOGECOIN_API dogecoin_bool dogecoin_encrypt_seed_with_sw(const SEED seed, con // Confirm the password char* confirm_password = malloc(PASS_MAX_LEN); #ifdef TEST_PASSWD - strcpy(confirm_password, TEST_PASS); + strcpy(confirm_password, PASSWD_STR); #else confirm_password = getpass("Confirm password: \n"); + if (confirm_password == NULL) + { + fprintf(stderr, "ERROR: Failed to read password.\n"); + dogecoin_free(password); + return false; + } #endif if (strcmp(password, confirm_password) != 0) { @@ -638,9 +648,14 @@ LIBDOGECOIN_API dogecoin_bool dogecoin_decrypt_seed_with_sw(SEED seed, const int // Prompt for the password char* password = malloc(PASS_MAX_LEN); #ifdef TEST_PASSWD - strcpy(password, TEST_PASS); + strcpy(password, PASSWD_STR); #else password = getpass("Enter password for seed decryption: \n"); + if (password == NULL) + { + fprintf(stderr, "ERROR: Failed to read password.\n"); + return false; + } #endif if (strlen(password) == 0) { @@ -1191,9 +1206,14 @@ dogecoin_bool dogecoin_generate_hdnode_encrypt_with_sw(dogecoin_hdnode* out, con // Prompt for the password char* password = malloc(PASS_MAX_LEN); #ifdef TEST_PASSWD - strcpy(password, TEST_PASS); + strcpy(password, PASSWD_STR); #else password = getpass("Enter password for HD node encryption: \n"); + if (password == NULL) + { + fprintf(stderr, "ERROR: Failed to read password.\n"); + return false; + } #endif if (strlen(password) == 0) { @@ -1205,9 +1225,15 @@ dogecoin_bool dogecoin_generate_hdnode_encrypt_with_sw(dogecoin_hdnode* out, con // Confirm the password char* confirm_password = malloc(PASS_MAX_LEN); #ifdef TEST_PASSWD - strcpy(confirm_password, TEST_PASS); + strcpy(confirm_password, PASSWD_STR); #else confirm_password = getpass("Confirm password: \n"); + if (confirm_password == NULL) + { + fprintf(stderr, "ERROR: Failed to read password.\n"); + dogecoin_free(password); + return false; + } #endif if (strcmp(password, confirm_password) != 0) { @@ -1326,9 +1352,14 @@ dogecoin_bool dogecoin_decrypt_hdnode_with_sw(dogecoin_hdnode* out, const int fi // Prompt for the password char* password = malloc(PASS_MAX_LEN); #ifdef TEST_PASSWD - strcpy(password, TEST_PASS); + strcpy(password, PASSWD_STR); #else password = getpass("Enter password for HD node decryption: \n"); + if (password == NULL) + { + fprintf(stderr, "ERROR: Failed to read password.\n"); + return false; + } #endif if (strlen(password) == 0) { @@ -1890,9 +1921,14 @@ LIBDOGECOIN_API dogecoin_bool dogecoin_generate_mnemonic_encrypt_with_sw(MNEMONI // Prompt for the password char* password = malloc(PASS_MAX_LEN); #ifdef TEST_PASSWD - strcpy(password, TEST_PASS); + strcpy(password, PASSWD_STR); #else password = getpass("Enter password for mnemonic encryption: \n"); + if (password == NULL) + { + fprintf(stderr, "ERROR: Failed to read password.\n"); + return false; + } #endif if (strlen(password) == 0) { @@ -1904,9 +1940,15 @@ LIBDOGECOIN_API dogecoin_bool dogecoin_generate_mnemonic_encrypt_with_sw(MNEMONI // Confirm the password char* confirm_password = malloc(PASS_MAX_LEN); #ifdef TEST_PASSWD - strcpy(confirm_password, TEST_PASS); + strcpy(confirm_password, PASSWD_STR); #else confirm_password = getpass("Confirm password: \n"); + if (confirm_password == NULL) + { + fprintf(stderr, "ERROR: Failed to read password.\n"); + dogecoin_free(password); + return false; + } #endif if (strcmp(password, confirm_password) != 0) { @@ -2025,9 +2067,14 @@ LIBDOGECOIN_API dogecoin_bool dogecoin_decrypt_mnemonic_with_sw(MNEMONIC mnemoni // Prompt for the password char* password = malloc(PASS_MAX_LEN); #ifdef TEST_PASSWD - strcpy(password, TEST_PASS); + strcpy(password, PASSWD_STR); #else password = getpass("Enter password for mnemonic decryption: \n"); + if (password == NULL) + { + fprintf(stderr, "ERROR: Failed to read password.\n"); + return false; + } #endif if (strlen(password) == 0) { diff --git a/test/unittester.c b/test/unittester.c index b3f606cce..53070e48b 100644 --- a/test/unittester.c +++ b/test/unittester.c @@ -140,7 +140,9 @@ int main() u_run_test(test_sha_hmac); u_run_test(test_signmsg); u_run_test(test_signmsg_ext); +#if TEST_ENCRYPT u_run_test(test_tpm); +#endif u_run_test(test_transaction); u_run_test(test_tx_serialization); u_run_test(test_invalid_tx_deser);