Skip to content

Commit b0de8ba

Browse files
committed
ossl.c: improve docs for constants and methods under ::OpenSSL
1 parent 695126f commit b0de8ba

File tree

4 files changed

+71
-43
lines changed

4 files changed

+71
-43
lines changed

ext/openssl/ossl.c

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,14 @@ osslerror_detailed_message(int argc, VALUE *argv, VALUE self)
388388
* call-seq:
389389
* OpenSSL.errors -> [String...]
390390
*
391-
* See any remaining errors held in queue.
391+
* Returns any remaining errors held in the \OpenSSL thread-local error queue
392+
* and clears the queue. This should normally return an empty array.
392393
*
393-
* Any errors you see here are probably due to a bug in Ruby's OpenSSL
394-
* implementation.
394+
* This is intended for debugging Ruby/OpenSSL. If you see any errors here,
395+
* it likely indicates a bug in the extension. Please file an issue at
396+
* https://github.com/ruby/openssl.
397+
*
398+
* For debugging your program, OpenSSL.debug= may be useful.
395399
*/
396400
static VALUE
397401
ossl_get_errors(VALUE _)
@@ -415,6 +419,8 @@ VALUE dOSSL;
415419
/*
416420
* call-seq:
417421
* OpenSSL.debug -> true | false
422+
*
423+
* Returns whether Ruby/OpenSSL's debug mode is currently enabled.
418424
*/
419425
static VALUE
420426
ossl_debug_get(VALUE self)
@@ -424,9 +430,9 @@ ossl_debug_get(VALUE self)
424430

425431
/*
426432
* call-seq:
427-
* OpenSSL.debug = boolean -> boolean
433+
* OpenSSL.debug = boolean
428434
*
429-
* Turns on or off debug mode. With debug mode, all errors added to the OpenSSL
435+
* Turns on or off debug mode. With debug mode, all errors added to the \OpenSSL
430436
* error queue will be printed to stderr.
431437
*/
432438
static VALUE
@@ -440,6 +446,8 @@ ossl_debug_set(VALUE self, VALUE val)
440446
/*
441447
* call-seq:
442448
* OpenSSL.fips_mode -> true | false
449+
*
450+
* Returns whether the FIPS mode is currently enabled.
443451
*/
444452
static VALUE
445453
ossl_fips_mode_get(VALUE self)
@@ -460,10 +468,10 @@ ossl_fips_mode_get(VALUE self)
460468

461469
/*
462470
* call-seq:
463-
* OpenSSL.fips_mode = boolean -> boolean
471+
* OpenSSL.fips_mode = boolean
464472
*
465473
* Turns FIPS mode on or off. Turning on FIPS mode will obviously only have an
466-
* effect for FIPS-capable installations of the OpenSSL library. Trying to do
474+
* effect for FIPS-capable installations of the \OpenSSL library. Trying to do
467475
* so otherwise will result in an error.
468476
*
469477
* === Examples
@@ -503,13 +511,13 @@ ossl_fips_mode_set(VALUE self, VALUE enabled)
503511

504512
/*
505513
* call-seq:
506-
* OpenSSL.fixed_length_secure_compare(string, string) -> boolean
514+
* OpenSSL.fixed_length_secure_compare(string, string) -> true or false
507515
*
508516
* Constant time memory comparison for fixed length strings, such as results
509-
* of HMAC calculations.
517+
* of \HMAC calculations.
510518
*
511519
* Returns +true+ if the strings are identical, +false+ if they are of the same
512-
* length but not identical. If the length is different, +ArgumentError+ is
520+
* length but not identical. If the length is different, ArgumentError is
513521
* raised.
514522
*/
515523
static VALUE
@@ -531,7 +539,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
531539
}
532540

533541
/*
534-
* OpenSSL provides SSL, TLS and general purpose cryptography. It wraps the
542+
* OpenSSL provides \SSL, TLS and general purpose cryptography. It wraps the
535543
* OpenSSL[https://www.openssl.org/] library.
536544
*
537545
* = Examples
@@ -586,7 +594,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
586594
*
587595
* === Loading an Encrypted Key
588596
*
589-
* OpenSSL will prompt you for your password when loading an encrypted key.
597+
* \OpenSSL will prompt you for your password when loading an encrypted key.
590598
* If you will not be able to type in the password you may provide it when
591599
* loading the key:
592600
*
@@ -649,7 +657,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
649657
*
650658
* == PBKDF2 Password-based Encryption
651659
*
652-
* If supported by the underlying OpenSSL version used, Password-based
660+
* If supported by the underlying \OpenSSL version used, Password-based
653661
* Encryption should use the features of PKCS5. If not supported or if
654662
* required by legacy applications, the older, less secure methods specified
655663
* in RFC 2898 are also supported (see below).
@@ -708,7 +716,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
708716
* decrypted = cipher.update encrypted
709717
* decrypted << cipher.final
710718
*
711-
* == X509 Certificates
719+
* == \X509 Certificates
712720
*
713721
* === Creating a Certificate
714722
*
@@ -745,7 +753,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
745753
* extension_factory.create_extension('subjectKeyIdentifier', 'hash')
746754
*
747755
* The list of supported extensions (and in some cases their possible values)
748-
* can be derived from the "objects.h" file in the OpenSSL source code.
756+
* can be derived from the "objects.h" file in the \OpenSSL source code.
749757
*
750758
* === Signing a Certificate
751759
*
@@ -899,23 +907,23 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
899907
* io.write csr_cert.to_pem
900908
* end
901909
*
902-
* == SSL and TLS Connections
910+
* == \SSL and TLS Connections
903911
*
904-
* Using our created key and certificate we can create an SSL or TLS connection.
905-
* An SSLContext is used to set up an SSL session.
912+
* Using our created key and certificate we can create an \SSL or TLS
913+
* connection. An OpenSSL::SSL::SSLContext is used to set up an \SSL session.
906914
*
907915
* context = OpenSSL::SSL::SSLContext.new
908916
*
909-
* === SSL Server
917+
* === \SSL Server
910918
*
911-
* An SSL server requires the certificate and private key to communicate
919+
* An \SSL server requires the certificate and private key to communicate
912920
* securely with its clients:
913921
*
914922
* context.cert = cert
915923
* context.key = key
916924
*
917-
* Then create an SSLServer with a TCP server socket and the context. Use the
918-
* SSLServer like an ordinary TCP server.
925+
* Then create an OpenSSL::SSL::SSLServer with a TCP server socket and the
926+
* context. Use the SSLServer like an ordinary TCP server.
919927
*
920928
* require 'socket'
921929
*
@@ -934,14 +942,15 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
934942
* ssl_connection.close
935943
* end
936944
*
937-
* === SSL client
945+
* === \SSL client
938946
*
939-
* An SSL client is created with a TCP socket and the context.
940-
* SSLSocket#connect must be called to initiate the SSL handshake and start
941-
* encryption. A key and certificate are not required for the client socket.
947+
* An \SSL client is created with a TCP socket and the context.
948+
* OpenSSL::SSL::SSLSocket#connect must be called to initiate the \SSL handshake
949+
* and start encryption. A key and certificate are not required for the client
950+
* socket.
942951
*
943-
* Note that SSLSocket#close doesn't close the underlying socket by default. Set
944-
* SSLSocket#sync_close to true if you want.
952+
* Note that OpenSSL::SSL::SSLSocket#close doesn't close the underlying socket
953+
* by default. Set OpenSSL::SSL::SSLSocket#sync_close to true if you want.
945954
*
946955
* require 'socket'
947956
*
@@ -957,7 +966,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
957966
*
958967
* === Peer Verification
959968
*
960-
* An unverified SSL connection does not provide much security. For enhanced
969+
* An unverified \SSL connection does not provide much security. For enhanced
961970
* security the client or server can verify the certificate of its peer.
962971
*
963972
* The client can be modified to verify the server's certificate against the
@@ -1008,13 +1017,14 @@ Init_openssl(void)
10081017
rb_define_singleton_method(mOSSL, "fixed_length_secure_compare", ossl_crypto_fixed_length_secure_compare, 2);
10091018

10101019
/*
1011-
* Version of OpenSSL the ruby OpenSSL extension was built with
1020+
* \OpenSSL library version string used to compile the Ruby/OpenSSL
1021+
* extension. This may differ from the version used at runtime.
10121022
*/
10131023
rb_define_const(mOSSL, "OPENSSL_VERSION",
10141024
rb_obj_freeze(rb_str_new_cstr(OPENSSL_VERSION_TEXT)));
10151025

10161026
/*
1017-
* Version of OpenSSL the ruby OpenSSL extension is running with
1027+
* \OpenSSL library version string currently used at runtime.
10181028
*/
10191029
rb_define_const(
10201030
mOSSL,
@@ -1023,30 +1033,43 @@ Init_openssl(void)
10231033
);
10241034

10251035
/*
1026-
* Version number of OpenSSL the ruby OpenSSL extension was built with
1027-
* (base 16). The formats are below.
1036+
* \OpenSSL library version number used to compile the Ruby/OpenSSL
1037+
* extension. This may differ from the version used at runtime.
10281038
*
1029-
* [OpenSSL 3] <tt>0xMNN00PP0 (major minor 00 patch 0)</tt>
1030-
* [OpenSSL before 3] <tt>0xMNNFFPPS (major minor fix patch status)</tt>
1031-
* [LibreSSL] <tt>0x20000000 (fixed value)</tt>
1039+
* The version number is encoded into a single integer value. The number
1040+
* follows the format:
1041+
*
1042+
* [\OpenSSL 3.0.0 or later]
1043+
* <tt>0xMNN00PP0</tt> (major minor 00 patch 0)
1044+
* [\OpenSSL 1.1.1 or earlier]
1045+
* <tt>0xMNNFFPPS</tt> (major minor fix patch status)
1046+
* [LibreSSL]
1047+
* <tt>0x20000000</tt> (a fixed value)
10321048
*
10331049
* See also the man page OPENSSL_VERSION_NUMBER(3).
10341050
*/
10351051
rb_define_const(mOSSL, "OPENSSL_VERSION_NUMBER", INT2NUM(OPENSSL_VERSION_NUMBER));
10361052

10371053
#if defined(LIBRESSL_VERSION_NUMBER)
10381054
/*
1039-
* Version number of LibreSSL the ruby OpenSSL extension was built with
1040-
* (base 16). The format is <tt>0xMNNFF00f (major minor fix 00
1041-
* status)</tt>. This constant is only defined in LibreSSL cases.
1055+
* LibreSSL library version number used to compile the Ruby/OpenSSL
1056+
* extension. This may differ from the version used at runtime.
1057+
*
1058+
* This constant is only defined if the extension was compiled against
1059+
* LibreSSL. The number follows the format:
1060+
* <tt>0xMNNFF00f</tt> (major minor fix 00 status).
10421061
*
10431062
* See also the man page LIBRESSL_VERSION_NUMBER(3).
10441063
*/
10451064
rb_define_const(mOSSL, "LIBRESSL_VERSION_NUMBER", INT2NUM(LIBRESSL_VERSION_NUMBER));
10461065
#endif
10471066

10481067
/*
1049-
* Boolean indicating whether OpenSSL is FIPS-capable or not
1068+
* Boolean indicating whether the \OpenSSL library is FIPS-capable or not.
1069+
* Always <tt>true</tt> for \OpenSSL 3.0 and later.
1070+
*
1071+
* This is obsolete and will be removed in the future.
1072+
* See also OpenSSL.fips_mode.
10501073
*/
10511074
rb_define_const(mOSSL, "OPENSSL_FIPS",
10521075
/* OpenSSL 3 is FIPS-capable even when it is installed without fips option */

lib/openssl.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@
2323
require_relative 'openssl/x509'
2424

2525
module OpenSSL
26-
# call-seq:
27-
# OpenSSL.secure_compare(string, string) -> boolean
26+
# :call-seq:
27+
# OpenSSL.secure_compare(string, string) -> true or false
2828
#
2929
# Constant time memory comparison. Inputs are hashed using SHA-256 to mask
3030
# the length of the secret. Returns +true+ if the strings are identical,
3131
# +false+ otherwise.
32+
#
33+
# This method is expensive due to the SHA-256 hashing. In most cases, where
34+
# the input lengths are known to be equal or are not sensitive,
35+
# OpenSSL.fixed_length_secure_compare should be used instead.
3236
def self.secure_compare(a, b)
3337
hashed_a = OpenSSL::Digest.digest('SHA256', a)
3438
hashed_b = OpenSSL::Digest.digest('SHA256', b)

lib/openssl/digest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Digest < Digest; end # :nodoc:
5757
# OpenSSL::Digest("MD5")
5858
# # => OpenSSL::Digest::MD5
5959
#
60-
# Digest("Foo")
60+
# OpenSSL::Digest("Foo")
6161
# # => NameError: wrong constant name Foo
6262

6363
def Digest(name)

lib/openssl/version.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

33
module OpenSSL
4+
# The version string of Ruby/OpenSSL.
45
VERSION = "4.0.0.pre"
56
end

0 commit comments

Comments
 (0)