From 14906ff23f9e083ed1e52d2f0326c72b4fcdb3a4 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 21 Jul 2020 18:24:27 +0200 Subject: [PATCH] Fix build on modern Arch Linux --- lib/libcrypto_utils/android_pubkey.c | 20 +++++++++++--------- src/adb_auth_host.cpp | 6 +----- src/client/usb_linux.cpp | 1 + 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/libcrypto_utils/android_pubkey.c b/lib/libcrypto_utils/android_pubkey.c index 3052e52..31e6358 100644 --- a/lib/libcrypto_utils/android_pubkey.c +++ b/lib/libcrypto_utils/android_pubkey.c @@ -81,17 +81,19 @@ bool android_pubkey_decode(const uint8_t* key_buffer, size_t size, RSA** key) { // Convert the modulus to big-endian byte order as expected by BN_bin2bn. memcpy(modulus_buffer, key_struct->modulus, sizeof(modulus_buffer)); reverse_bytes(modulus_buffer, sizeof(modulus_buffer)); - new_key->n = BN_bin2bn(modulus_buffer, sizeof(modulus_buffer), NULL); - if (!new_key->n) { + BIGNUM* n = BN_bin2bn(modulus_buffer, sizeof(modulus_buffer), NULL); + if (!n) { goto cleanup; } // Read the exponent. - new_key->e = BN_new(); - if (!new_key->e || !BN_set_word(new_key->e, key_struct->exponent)) { + BIGNUM* e = BN_new(); + if (!e || !BN_set_word(e, key_struct->exponent)) { goto cleanup; } + RSA_set0_key(new_key, n, e, NULL); + // Note that we don't extract the montgomery parameters n0inv and rr from // the RSAPublicKey structure. They assume a word size of 32 bits, but // BoringSSL may use a word size of 64 bits internally, so we're lacking the @@ -111,7 +113,7 @@ cleanup: } static bool android_pubkey_encode_bignum(const BIGNUM* num, uint8_t* buffer) { - if (!BN_bn2bin_padded(buffer, ANDROID_PUBKEY_MODULUS_SIZE, num)) { + if (!BN_bn2binpad(num, buffer, ANDROID_PUBKEY_MODULUS_SIZE)) { return false; } @@ -137,26 +139,26 @@ bool android_pubkey_encode(const RSA* key, uint8_t* key_buffer, size_t size) { // Compute and store n0inv = -1 / N[0] mod 2^32. if (!ctx || !r32 || !n0inv || !BN_set_bit(r32, 32) || - !BN_mod(n0inv, key->n, r32, ctx) || + !BN_mod(n0inv, RSA_get0_n(key), r32, ctx) || !BN_mod_inverse(n0inv, n0inv, r32, ctx) || !BN_sub(n0inv, r32, n0inv)) { goto cleanup; } key_struct->n0inv = (uint32_t)BN_get_word(n0inv); // Store the modulus. - if (!android_pubkey_encode_bignum(key->n, key_struct->modulus)) { + if (!android_pubkey_encode_bignum(RSA_get0_n(key), key_struct->modulus)) { goto cleanup; } // Compute and store rr = (2^(rsa_size)) ^ 2 mod N. if (!ctx || !rr || !BN_set_bit(rr, ANDROID_PUBKEY_MODULUS_SIZE * 8) || - !BN_mod_sqr(rr, rr, key->n, ctx) || + !BN_mod_sqr(rr, rr, RSA_get0_n(key), ctx) || !android_pubkey_encode_bignum(rr, key_struct->rr)) { goto cleanup; } // Store the exponent. - key_struct->exponent = (uint32_t)BN_get_word(key->e); + key_struct->exponent = (uint32_t)BN_get_word(RSA_get0_e(key)); ret = true; diff --git a/src/adb_auth_host.cpp b/src/adb_auth_host.cpp index dc011d8..6fda9a4 100644 --- a/src/adb_auth_host.cpp +++ b/src/adb_auth_host.cpp @@ -81,11 +81,7 @@ static bool write_public_keyfile(RSA* private_key, const std::string& private_ke return false; } - size_t expected_length; - if (!EVP_EncodedLength(&expected_length, sizeof(binary_key_data))) { - LOG(ERROR) << "Public key too large to base64 encode"; - return false; - } + size_t expected_length = ((4 * (sizeof(binary_key_data)) / 3) + 3) & ~3; std::string content; content.resize(expected_length); diff --git a/src/client/usb_linux.cpp b/src/client/usb_linux.cpp index a7df0ed..e6470f7 100644 --- a/src/client/usb_linux.cpp +++ b/src/client/usb_linux.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include -- 2.27.0