Skip to content

Commit

Permalink
Enhance printing OpenSSL versions.
Browse files Browse the repository at this point in the history
* Updated the `OpenSSL::OPENSSL_VERSION_NUMBER` comment explaining the format.
* Added the `OpenSSL::LIBRESSL_VERSION_NUMBER` to print LibreSSL version number.
  The value is `nil` in the OpenSSL case. Note
  `test/openssl/utils.rb#libressl?` is not using this value in it.
* Update `rake debug` to print the values in a readable way, adding
  `OpenSSL::OPENSSL_VERSION_NUMBER` and `OpenSSL::LIBRESSL_VERSION_NUMBER`.
  • Loading branch information
junaruga committed Aug 15, 2023
1 parent db633c5 commit a1656cd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ task :debug_compiler do
end

task :debug do
ruby "-I./lib -ropenssl -ve'puts OpenSSL::OPENSSL_VERSION, OpenSSL::OPENSSL_LIBRARY_VERSION'"
ruby_code = <<~'EOF'
libre_version_number_str = (!OpenSSL::LIBRESSL_VERSION_NUMBER.nil?) ?
OpenSSL::LIBRESSL_VERSION_NUMBER.to_s(16) : "nil"
puts <<~'MESSAGE'
OpenSSL::OPENSSL_VERSION: #{OpenSSL::OPENSSL_VERSION}
OpenSSL::OPENSSL_LIBRARY_VERSION: #{OpenSSL::OPENSSL_LIBRARY_VERSION}
OpenSSL::OPENSSL_VERSION_NUMBER: #{OpenSSL::OPENSSL_VERSION_NUMBER.to_s(16)}
OpenSSL::LIBRESSL_VERSION_NUMBER: #{libre_version_number_str}
MESSAGE
EOF
ruby %Q(-I./lib -ropenssl -ve'#{ruby_code}')
end

task :default => :test
20 changes: 20 additions & 0 deletions ext/openssl/ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,9 +1150,29 @@ Init_openssl(void)
/*
* Version number of OpenSSL the ruby OpenSSL extension was built with
* (base 16)
*
* OpenSSL 3: 0xMNN00PP0 (major minor 00 patch 0)
* OpenSSL 1: 0xMNNFFPPS (major minor fix patch status)
* LibreSSL : 0x20000000 (fixed value)
*
* See also the man page OPENSSL_VERSION_NUMBER(3).
*/
rb_define_const(mOSSL, "OPENSSL_VERSION_NUMBER", INT2NUM(OPENSSL_VERSION_NUMBER));

/*
* Version number of LibreSSL the ruby OpenSSL extension was built with
* (base 16)
*
* LibreSSL: 0xMNNFFPPS (major minor fix patch status)
*
* See also the man page OPENSSL_VERSION_NUMBER(3).
*/
#if defined(LIBRESSL_VERSION_NUMBER)
rb_define_const(mOSSL, "LIBRESSL_VERSION_NUMBER", INT2NUM(LIBRESSL_VERSION_NUMBER));
#else
rb_define_const(mOSSL, "LIBRESSL_VERSION_NUMBER", Qnil);
#endif

/*
* Boolean indicating whether OpenSSL is FIPS-capable or not
*/
Expand Down

0 comments on commit a1656cd

Please sign in to comment.