Skip to content

Commit d19e636

Browse files
committed
Enhance printing OpenSSL versions.
* Updated the `OpenSSL::OPENSSL_VERSION_NUMBER` comment explaining the format. * Added the `OpenSSL::LIBRESSL_VERSION_NUMBER` to print LibreSSL version number, in the case that Ruby OpenSSL binding is compiled with LibreSSL. Note `test/openssl/utils.rb#libressl?` is not using this value in it for now. * Update `rake debug` to print the values in a readable way, adding `OpenSSL::OPENSSL_VERSION_NUMBER` and `OpenSSL::LIBRESSL_VERSION_NUMBER`.
1 parent db633c5 commit d19e636

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Rakefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,18 @@ task :debug_compiler do
3838
end
3939

4040
task :debug do
41-
ruby "-I./lib -ropenssl -ve'puts OpenSSL::OPENSSL_VERSION, OpenSSL::OPENSSL_LIBRARY_VERSION'"
41+
ruby_code = <<~'EOF'
42+
openssl_version_number_str = OpenSSL::OPENSSL_VERSION_NUMBER.to_s(16)
43+
libressl_version_number_str = (defined? OpenSSL::LIBRESSL_VERSION_NUMBER) ?
44+
OpenSSL::LIBRESSL_VERSION_NUMBER.to_s(16) : "undefined"
45+
puts <<~MESSAGE
46+
OpenSSL::OPENSSL_VERSION: #{OpenSSL::OPENSSL_VERSION}
47+
OpenSSL::OPENSSL_LIBRARY_VERSION: #{OpenSSL::OPENSSL_LIBRARY_VERSION}
48+
OpenSSL::OPENSSL_VERSION_NUMBER: #{openssl_version_number_str}
49+
OpenSSL::LIBRESSL_VERSION_NUMBER: #{libressl_version_number_str}
50+
MESSAGE
51+
EOF
52+
ruby %Q(-I./lib -ropenssl -ve'#{ruby_code}')
4253
end
4354

4455
task :default => :test

ext/openssl/ossl.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,10 +1149,27 @@ Init_openssl(void)
11491149

11501150
/*
11511151
* Version number of OpenSSL the ruby OpenSSL extension was built with
1152-
* (base 16)
1152+
* (base 16). The formats are below.
1153+
*
1154+
* [OpenSSL 3] <tt>0xMNN00PP0 (major minor 00 patch 0)</tt>
1155+
* [OpenSSL before 3] <tt>0xMNNFFPPS (major minor fix patch status)</tt>
1156+
* [LibreSSL] <tt>0x20000000 (fixed value)</tt>
1157+
*
1158+
* See also the man page OPENSSL_VERSION_NUMBER(3).
11531159
*/
11541160
rb_define_const(mOSSL, "OPENSSL_VERSION_NUMBER", INT2NUM(OPENSSL_VERSION_NUMBER));
11551161

1162+
#if defined(LIBRESSL_VERSION_NUMBER)
1163+
/*
1164+
* Version number of LibreSSL the ruby OpenSSL extension was built with
1165+
* (base 16). The format is <tt>0xMNNFFPPS (major minor fix patch
1166+
* status)</tt>. This constant is only defined in LibreSSL cases.
1167+
*
1168+
* See also the man page OPENSSL_VERSION_NUMBER(3).
1169+
*/
1170+
rb_define_const(mOSSL, "LIBRESSL_VERSION_NUMBER", INT2NUM(LIBRESSL_VERSION_NUMBER));
1171+
#endif
1172+
11561173
/*
11571174
* Boolean indicating whether OpenSSL is FIPS-capable or not
11581175
*/

0 commit comments

Comments
 (0)