Skip to content

Commit 576eff6

Browse files
committed
Merge branch 'maint'
* maint: Ruby/OpenSSL 2.0.4 History.md: add entries for 2.0.1-2.0.3 History.md: wrap at 80 characters extconf.rb: simplify searching libraries logic Search SSL libraries by testing various filename patterns openssl: fix broken openssl check openssl: fix broken openssl check x509store: clear error queue after calling X509_LOOKUP_load_file() tool/sync-with-trunk: 'LASY' -> 'LAST' Update .travis.yml and Dockerfile test/test_x509store: skip OpenSSL::TestX509Store#test_set_errors Fix documentation for OpenSSL::Cipher#final Fix typos ssl: check return value of SSL_set_fd() test/test_ssl: fix typo in test_sysread_and_syswrite Fix typos test/test_pkey_ec: do not use dummy 0 order
2 parents e52a351 + dde512a commit 576eff6

File tree

16 files changed

+172
-41
lines changed

16 files changed

+172
-41
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@ matrix:
2424
- env: RUBY_VERSION=ruby-2.4 OPENSSL_VERSION=libressl-2.3
2525
- env: RUBY_VERSION=ruby-2.4 OPENSSL_VERSION=libressl-2.4
2626
- env: RUBY_VERSION=ruby-2.4 OPENSSL_VERSION=libressl-2.5
27+
- language: ruby
28+
rvm: ruby-head
29+
before_install:
30+
- "rake install_dependencies"
31+
script:
32+
- "rake compile -- --enable-debug"
33+
- "rake test"
2734
allow_failures:
35+
- language: ruby
36+
rvm: ruby-head

History.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,53 @@ Deprecations
2323
------------
2424

2525

26+
Version 2.0.4
27+
=============
28+
29+
Bug fixes
30+
---------
31+
32+
* It now compiles with LibreSSL without renaming on Windows (mswin).
33+
* A workaround for the error queue leak of X509_load_cert_crl_file() that
34+
causes random errors is added.
35+
[[Bug #11033]](https://bugs.ruby-lang.org/issues/11033)
36+
37+
38+
Version 2.0.3
39+
=============
40+
41+
Bug fixes
42+
---------
43+
44+
* OpenSSL::ASN1::Constructive#each which was broken by 2.0.0 is fixed.
45+
[[ruby/openssl#96]](https://github.com/ruby/openssl/pull/96)
46+
* Fixed build with static OpenSSL libraries on Windows.
47+
[[Bug #13080]](https://bugs.ruby-lang.org/issues/13080)
48+
* OpenSSL::X509::Name#eql? which was broken by 2.0.0 is fixed.
49+
50+
51+
Version 2.0.2
52+
=============
53+
54+
Bug fixes
55+
---------
56+
57+
* Fix build with early 0.9.8 series which did not have SSL_CTX_clear_options().
58+
[ruby-core:78693]
59+
60+
61+
Version 2.0.1
62+
=============
63+
64+
Bug fixes
65+
---------
66+
67+
* A GC issue around OpenSSL::BN is fixed.
68+
[[ruby/openssl#87]](https://github.com/ruby/openssl/issues/87)
69+
* OpenSSL::ASN1 now parses BER encoding of GeneralizedTime without seconds.
70+
[[ruby/openssl#88]](https://github.com/ruby/openssl/pull/88)
71+
72+
2673
Version 2.0.0
2774
=============
2875

@@ -48,7 +95,8 @@ Supported platforms
4895
Notable changes
4996
---------------
5097

51-
* Add support for OpenSSL 1.1.0. [[Feature #12324]](https://bugs.ruby-lang.org/issues/12324)
98+
* Add support for OpenSSL 1.1.0.
99+
[[Feature #12324]](https://bugs.ruby-lang.org/issues/12324)
52100
* Add support for LibreSSL
53101

54102
* OpenSSL::Cipher

ext/openssl/extconf.rb

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,65 @@
3636

3737
Logging::message "=== Checking for required stuff... ===\n"
3838
result = pkg_config("openssl") && have_header("openssl/ssl.h")
39-
unless result
39+
40+
def find_openssl_library
4041
if $mswin || $mingw
4142
# required for static OpenSSL libraries
4243
have_library("gdi32") # OpenSSL <= 1.0.2 (for RAND_screen())
4344
have_library("crypt32")
4445
end
4546

46-
result = %w[crypto libeay32].any? {|lib| have_library(lib, "CRYPTO_malloc")}
47-
result &&= %w[ssl ssleay32].any? {|lib| have_library(lib, "SSL_new")}
48-
unless result
47+
return false unless have_header("openssl/ssl.h")
48+
49+
ret = have_library("crypto", "CRYPTO_malloc") &&
50+
have_library("ssl", "SSL_new")
51+
return ret if ret
52+
53+
if $mswin
54+
# OpenSSL >= 1.1.0: libcrypto.lib and libssl.lib.
55+
if have_library("libcrypto", "CRYPTO_malloc") &&
56+
have_library("libssl", "SSL_new")
57+
return true
58+
end
59+
60+
# OpenSSL <= 1.0.2: libeay32.lib and ssleay32.lib.
61+
if have_library("libeay32", "CRYPTO_malloc") &&
62+
have_library("ssleay32", "SSL_new")
63+
return true
64+
end
65+
66+
# LibreSSL: libcrypto-##.lib and libssl-##.lib, where ## is the ABI version
67+
# number. We have to find the version number out by scanning libpath.
68+
libpath = $LIBPATH.dup
69+
libpath |= ENV["LIB"].split(File::PATH_SEPARATOR)
70+
libpath.map! { |d| d.tr(File::ALT_SEPARATOR, File::SEPARATOR) }
71+
72+
ret = [
73+
["crypto", "CRYPTO_malloc"],
74+
["ssl", "SSL_new"]
75+
].all? do |base, func|
76+
result = false
77+
libs = ["lib#{base}-[0-9][0-9]", "lib#{base}-[0-9][0-9][0-9]"]
78+
libs = Dir.glob(libs.map{|l| libpath.map{|d| File.join(d, l + ".*")}}.flatten).map{|path| File.basename(path, ".*")}.uniq
79+
libs.each do |lib|
80+
result = have_library(lib, func)
81+
break if result
82+
end
83+
result
84+
end
85+
return ret if ret
86+
end
87+
return false
88+
end
89+
90+
unless result
91+
unless find_openssl_library
92+
Logging::message "=== Checking for required stuff failed. ===\n"
93+
Logging::message "Makefile wasn't created. Fix the errors above.\n"
4994
raise "OpenSSL library could not be found. You might want to use " \
5095
"--with-openssl-dir=<dir> option to specify the prefix where OpenSSL " \
5196
"is installed."
5297
end
53-
unless have_header("openssl/ssl.h")
54-
raise "OpenSSL library itself was found, but the necessary header files " \
55-
"are missing. Installing \"development package\" of OpenSSL on your " \
56-
"system might help."
57-
end
5898
end
5999

60100
unless checking_for("OpenSSL version is 1.0.1 or later") {

ext/openssl/ossl_bn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ try_convert_to_bn(VALUE obj)
124124
if (rb_obj_is_kind_of(obj, cBN))
125125
return obj;
126126
if (RB_INTEGER_TYPE_P(obj)) {
127-
newobj = NewBN(cBN); /* Handle potencial mem leaks */
127+
newobj = NewBN(cBN); /* Handle potential mem leaks */
128128
bn = integer_to_bnptr(obj, NULL);
129129
SetBN(newobj, bn);
130130
}

ext/openssl/ossl_cipher.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define GetCipher(obj, ctx) do { \
2424
GetCipherInit((obj), (ctx)); \
2525
if (!(ctx)) { \
26-
ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \
26+
ossl_raise(rb_eRuntimeError, "Cipher not initialized!"); \
2727
} \
2828
} while (0)
2929

@@ -118,7 +118,7 @@ ossl_cipher_initialize(VALUE self, VALUE str)
118118
name = StringValueCStr(str);
119119
GetCipherInit(self, ctx);
120120
if (ctx) {
121-
ossl_raise(rb_eRuntimeError, "Cipher already inititalized!");
121+
ossl_raise(rb_eRuntimeError, "Cipher already initialized!");
122122
}
123123
AllocCipher(self, ctx);
124124
if (!(cipher = EVP_get_cipherbyname(name))) {
@@ -414,7 +414,7 @@ ossl_cipher_update(int argc, VALUE *argv, VALUE self)
414414
* Returns the remaining data held in the cipher object. Further calls to
415415
* Cipher#update or Cipher#final will return garbage. This call should always
416416
* be made as the last call of an encryption or decryption operation, after
417-
* after having fed the entire plaintext or ciphertext to the Cipher instance.
417+
* having fed the entire plaintext or ciphertext to the Cipher instance.
418418
*
419419
* If an authenticated cipher was used, a CipherError is raised if the tag
420420
* could not be authenticated successfully. Only call this method after
@@ -1003,7 +1003,7 @@ Init_ossl_cipher(void)
10031003
* An example using the GCM (Galois/Counter Mode). You have 16 bytes _key_,
10041004
* 12 bytes (96 bits) _nonce_ and the associated data _auth_data_. Be sure
10051005
* not to reuse the _key_ and _nonce_ pair. Reusing an nonce ruins the
1006-
* security gurantees of GCM mode.
1006+
* security guarantees of GCM mode.
10071007
*
10081008
* cipher = OpenSSL::Cipher::AES.new(128, :GCM).encrypt
10091009
* cipher.key = key

ext/openssl/ossl_ns_spki.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ ossl_spki_verify(VALUE self, VALUE key)
322322

323323
/* Document-class: OpenSSL::Netscape::SPKI
324324
*
325-
* A Simple Public Key Infrastructure implementation (pronounced "spookey").
325+
* A Simple Public Key Infrastructure implementation (pronounced "spooky").
326326
* The structure is defined as
327327
* PublicKeyAndChallenge ::= SEQUENCE {
328328
* spki SubjectPublicKeyInfo,
@@ -348,7 +348,7 @@ ossl_spki_verify(VALUE self, VALUE key)
348348
* spki.public_key = key.public_key
349349
* spki.sign(key, OpenSSL::Digest::SHA256.new)
350350
* #send a request containing this to a server generating a certificate
351-
* === Verifiying an SPKI request
351+
* === Verifying an SPKI request
352352
* request = #...
353353
* spki = OpenSSL::Netscape::SPKI.new request
354354
* unless spki.verify(spki.public_key)

ext/openssl/ossl_pkey_ec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ ossl_ec_key_get_group(VALUE self)
284284
* key.group = group
285285
*
286286
* Sets the EC::Group for the key. The group structure is internally copied so
287-
* modifition to _group_ after assigning to a key has no effect on the key.
287+
* modification to _group_ after assigning to a key has no effect on the key.
288288
*/
289289
static VALUE
290290
ossl_ec_key_set_group(VALUE self, VALUE group_v)
@@ -1585,11 +1585,11 @@ ossl_ec_point_to_bn(int argc, VALUE *argv, VALUE self)
15851585
* Performs elliptic curve point multiplication.
15861586
*
15871587
* The first form calculates <tt>bn1 * point + bn2 * G</tt>, where +G+ is the
1588-
* generator of the group of _point_. _bn2_ may be ommitted, and in that case,
1588+
* generator of the group of _point_. _bn2_ may be omitted, and in that case,
15891589
* the result is just <tt>bn1 * point</tt>.
15901590
*
15911591
* The second form calculates <tt>bns[0] * point + bns[1] * points[0] + ...
1592-
* + bns[-1] * points[-1] + bn2 * G</tt>. _bn2_ may be ommitted. _bns_ must be
1592+
* + bns[-1] * points[-1] + bn2 * G</tt>. _bn2_ may be omitted. _bns_ must be
15931593
* an array of OpenSSL::BN. _points_ must be an array of
15941594
* OpenSSL::PKey::EC::Point. Please note that <tt>points[0]</tt> is not
15951595
* multiplied by <tt>bns[0]</tt>, but <tt>bns[1]</tt>.

ext/openssl/ossl_pkey_rsa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ Init_ossl_rsa(void)
706706
/* Document-class: OpenSSL::PKey::RSA
707707
*
708708
* RSA is an asymmetric public key algorithm that has been formalized in
709-
* RFC 3447. It is in widespread use in public key infrastuctures (PKI)
709+
* RFC 3447. It is in widespread use in public key infrastructures (PKI)
710710
* where certificates (cf. OpenSSL::X509::Certificate) often are issued
711711
* on the basis of a public/private RSA key pair. RSA is used in a wide
712712
* field of applications such as secure (symmetric) key exchange, e.g.

ext/openssl/ossl_ssl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,8 @@ ossl_ssl_setup(VALUE self)
14661466
GetOpenFile(io, fptr);
14671467
rb_io_check_readable(fptr);
14681468
rb_io_check_writable(fptr);
1469-
SSL_set_fd(ssl, TO_SOCKET(fptr->fd));
1469+
if (!SSL_set_fd(ssl, TO_SOCKET(fptr->fd)))
1470+
ossl_raise(eSSLError, "SSL_set_fd");
14701471

14711472
return Qtrue;
14721473
}

ext/openssl/ossl_x509store.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,15 @@ ossl_x509store_add_file(VALUE self, VALUE file)
313313
if(X509_LOOKUP_load_file(lookup, path, X509_FILETYPE_PEM) != 1){
314314
ossl_raise(eX509StoreError, NULL);
315315
}
316+
#if OPENSSL_VERSION_NUMBER < 0x10101000 || defined(LIBRESSL_VERSION_NUMBER)
317+
/*
318+
* X509_load_cert_crl_file() which is called from X509_LOOKUP_load_file()
319+
* did not check the return value of X509_STORE_add_{cert,crl}(), leaking
320+
* "cert already in hash table" errors on the error queue, if duplicate
321+
* certificates are found. This will be fixed by OpenSSL 1.1.1.
322+
*/
323+
ossl_clear_error();
324+
#endif
316325

317326
return self;
318327
}

0 commit comments

Comments
 (0)