bi: Add OpenSSL/libcrypto version info

Best 90 minutes I've ever spent in my life. I could've done string
comparisons, but somehow I suspect their format is more likely to change
in the future than the numeric versions.

Also, beware that the upstream documentation (both on their wiki and
their source) does not accurately reflect history -- the version numbers
for releases between 0.9.3 and 0.9.5 were vastly different, and this
version of the algorithm I wrote seems to be the best fit for all of
them.)
This commit is contained in:
Ignacio R. Morelle 2017-05-25 02:13:29 -04:00
parent 30d1c382bd
commit ce0a5c1829
2 changed files with 100 additions and 0 deletions

View file

@ -23,6 +23,7 @@
#include "gettext.hpp"
#include <algorithm>
#include <cstdint>
#include <SDL.h>
#include <SDL_image.h>
@ -31,6 +32,9 @@
#include <boost/version.hpp>
#include <openssl/crypto.h>
#include <openssl/opensslv.h>
#include <pango/pangocairo.h>
#ifdef HAVE_LIBPNG
@ -66,6 +70,92 @@ std::string format_version(const SDL_version& v)
<< unsigned(v.patch);
}
std::string format_openssl_patch_level(uint8_t p)
{
return p <= 26
? std::string(1, 'a' + char(p) - 1)
: "patch" + std::to_string(p);
}
std::string format_openssl_version(long v)
{
int major, minor, fix, patch, status;
std::ostringstream fmt;
//
// The people who maintain OpenSSL are not from this world. I suppose it's
// only fair that I'm the one who gets to try to make sense of their version
// encoding scheme. -- shadowm
//
if(v < 0x0930L) {
// Pre-0.9.3 seems simpler times overall.
minor = v & 0x0F00L >> 8;
fix = v & 0x00F0L >> 4;
patch = v & 0x000FL;
fmt << "0." << minor << '.' << fix;
if(patch) {
fmt << format_openssl_patch_level(patch);
}
} else {
//
// Note that they either assume the major version will never be greater than
// 9, they plan to use hexadecimal digits for versions 10.x.x through
// 15.x.x, or they expect long to be always > 32-bits by then. Who the hell
// knows, really.
//
major = (v & 0xF0000000L) >> 28;
minor = (v & 0x0FF00000L) >> 20;
fix = (v & 0x000FF000L) >> 12;
patch = (v & 0x00000FF0L) >> 4;
status = (v & 0x0000000FL);
if(v < 0x00905100L) {
//
// From wiki.openssl.org (also mentioned in opensslv.h, in the most oblique
// fashion possible):
//
// "Versions between 0.9.3 and 0.9.5 had a version identifier with this interpretation:
// MMNNFFRBB major minor fix final beta/patch"
//
// Both the wiki and opensslv.h fail to accurately list actual version
// numbers that ended up used in the wild -- e.g. 0.9.3a is supposedly
// 0x0090301f when it really was 0x00903101.
//
const uint8_t is_final = (v & 0xF00L) >> 8;
status = is_final ? 0xF : 0;
patch = v & 0xFFL;
} else if(v < 0x00906000L) {
//
// Quoth opensslv.h:
//
// "For continuity reasons (because 0.9.5 is already out, and is coded
// 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level
// part is slightly different, by setting the highest bit. This means
// that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start
// with 0x0090600S..."
//
patch ^= 1 << 7;
}
fmt << major << '.' << minor << '.' << fix;
if(patch) {
fmt << format_openssl_patch_level(patch);
}
if(status == 0x0) {
fmt << "-dev";
} else if(status < 0xF) {
fmt << "-beta" << status;
}
}
return fmt.str();
}
version_table_manager::version_table_manager()
: compiled(LIB_COUNT, "")
, linked(LIB_COUNT, "")
@ -138,6 +228,14 @@ version_table_manager::version_table_manager()
std::replace(compiled[LIB_BOOST].begin(), compiled[LIB_BOOST].end(), '_', '.');
names[LIB_BOOST] = "Boost";
//
// OpenSSL/libcrypto
//
compiled[LIB_CRYPTO] = format_openssl_version(OPENSSL_VERSION_NUMBER);
linked[LIB_CRYPTO] = format_openssl_version(SSLeay());
names[LIB_CRYPTO] = "OpenSSL/libcrypto";
//
// Cairo
//

View file

@ -24,6 +24,8 @@ enum LIBRARY_ID
{
LIB_BOOST,
LIB_CRYPTO,
LIB_CAIRO,
LIB_PANGO,