To do password exchange on the SQL server I need to use SHA-1 to generate a hash (no plain password exchange).
This is done differently on Linux/Mac so I abstracted it slightly.
ThorCryptWrapper.h
#ifndef THORS_ANVIL_MYSQL_DETAILS_THOR_CRYPTO_WRAPPER_H
#define THORS_ANVIL_MYSQL_DETAILS_THOR_CRYPTO_WRAPPER_H
#ifdef __APPLE__
#define COMMON_DIGEST_FOR_OPENSSL
#include <CommonCrypto/CommonDigest.h>
#define THOR_SHA1(data, len, dst) CC_SHA1(data, len, dst)
#else
#include <openssl/sha.h>
#define THOR_SHA1(data, len, dst) SHA1(data, len, dst)
#endif
namespace ThorsAnvil
{
namespace MySQL
{
typedef unsigned char ThorSHADigestStore[SHA_DIGEST_LENGTH];
inline void thorSHA1(ThorSHADigestStore& dest, ThorSHADigestStore& src)
{
THOR_SHA1(src, SHA_DIGEST_LENGTH, dest);
}
inline void thorSHA1(ThorSHADigestStore& dest, std::string const& src)
{
THOR_SHA1(reinterpret_cast<const unsigned char*>(&src[0]), src.length(), dest);
}
}
}
#endif
SHA1( password ) XOR SHA1( "20-bytes random data from server" <concat> SHA1( SHA1( password ) ) )
. Documented here: dev.mysql.com/doc/internals/en/… You can see my use of it here: ThorsSQL Lib: Part 3: Layer 5 HandShake \$\endgroup\$Currently this client does not support that and will throw an exception (A fun task for somebody that want to try :-) )
\$\endgroup\$