mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-26 15:42:34 +01:00
Add crypto_log_errors() to crypto_util.[ch]
crypto_log_errors() has been moved to crypto_util.[ch]. It was duplicated in some files so they have been removed too. Follows #24658. Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
This commit is contained in:
parent
5ad72bc1f5
commit
5b7a12d58a
5 changed files with 23 additions and 65 deletions
|
@ -86,27 +86,6 @@ static int crypto_early_initialized_ = 0;
|
||||||
/** Boolean: has OpenSSL's crypto been initialized? */
|
/** Boolean: has OpenSSL's crypto been initialized? */
|
||||||
static int crypto_global_initialized_ = 0;
|
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
|
#ifndef DISABLE_ENGINES
|
||||||
/** Log any OpenSSL engines we're using at NOTICE. */
|
/** Log any OpenSSL engines we're using at NOTICE. */
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -44,27 +44,6 @@ struct crypto_pk_t
|
||||||
RSA *key; /**< The key itself */
|
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>.
|
/** Return the number of bytes added by padding method <b>padding</b>.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
|
|
|
@ -27,10 +27,13 @@
|
||||||
|
|
||||||
DISABLE_GCC_WARNING(redundant-decls)
|
DISABLE_GCC_WARNING(redundant-decls)
|
||||||
|
|
||||||
|
#include <openssl/err.h>
|
||||||
#include <openssl/crypto.h>
|
#include <openssl/crypto.h>
|
||||||
|
|
||||||
ENABLE_GCC_WARNING(redundant-decls)
|
ENABLE_GCC_WARNING(redundant-decls)
|
||||||
|
|
||||||
|
#include "torlog.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the <b>sz</b> bytes of data stored at <b>mem</b>, setting them to
|
* Destroy the <b>sz</b> bytes of data stored at <b>mem</b>, setting them to
|
||||||
* the value <b>byte</b>.
|
* the value <b>byte</b>.
|
||||||
|
@ -103,5 +106,22 @@ memwipe(void *mem, uint8_t byte, size_t sz)
|
||||||
memset(mem, byte, sz);
|
memset(mem, byte, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) */
|
#endif /* !defined(CRYPTO_UTIL_PRIVATE) */
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
/** OpenSSL-based utility functions. */
|
/** OpenSSL-based utility functions. */
|
||||||
void memwipe(void *mem, uint8_t byte, size_t sz);
|
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 CRYPTO_UTIL_PRIVATE
|
||||||
#ifdef TOR_UNIT_TESTS
|
#ifdef TOR_UNIT_TESTS
|
||||||
#endif /* defined(TOR_UNIT_TESTS) */
|
#endif /* defined(TOR_UNIT_TESTS) */
|
||||||
|
|
|
@ -78,29 +78,6 @@ show_help(void)
|
||||||
"[--passphrase-fd <fd>]\n");
|
"[--passphrase-fd <fd>]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXXX copied from crypto.c */
|
|
||||||
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 (doing) {
|
|
||||||
tor_log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)",
|
|
||||||
doing, msg, lib, func);
|
|
||||||
} else {
|
|
||||||
tor_log(severity, LD_CRYPTO, "crypto error: %s (in %s:%s)",
|
|
||||||
msg, lib, func);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Read the passphrase from the passphrase fd. */
|
/** Read the passphrase from the passphrase fd. */
|
||||||
static int
|
static int
|
||||||
load_passphrase(void)
|
load_passphrase(void)
|
||||||
|
|
Loading…
Add table
Reference in a new issue