Skip to content

Commit 3ed3fc5

Browse files
committed
Merge branch 'maint'
* maint: Ruby/OpenSSL 2.0.5 ssl: fix compile error with OpenSSL 1.0.0 ssl: remove unsupported TLS versions from SSLContext::METHODS Add msys2 library dependency tag in gem metadata ossl_pem_passwd_cb: handle nil from the block explicitly ossl_pem_passwd_cb: do not check for taintedness ossl_pem_passwd_cb: relax passphrase length constraint appveyor.yml: test against Ruby 2.4 Rakefile: install_dependencies: install only when needed bio: do not use the FILE BIO method in ossl_obj2bio() bio: prevent possible GC issue in ossl_obj2bio() test/test_ssl: allow 3DES cipher suites in test_sslctx_set_params
2 parents d4ded26 + df37b7a commit 3ed3fc5

23 files changed

+102
-84
lines changed

History.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ Deprecations
2323
------------
2424

2525

26+
Version 2.0.5
27+
=============
28+
29+
Bug fixes
30+
---------
31+
32+
* Reading a PEM/DER-encoded private key or certificate from an IO object did
33+
not work properly on mswin platforms.
34+
[[ruby/openssl#128]](https://github.com/ruby/openssl/issues/128)
35+
* Broken length check in the PEM passphrase callback is fixed.
36+
* It failed to compile when OpenSSL is configured without TLS 1.0 support.
37+
38+
2639
Version 2.0.4
2740
=============
2841

Rakefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ task :install_dependencies do
3434
gemspec = eval(File.read("openssl.gemspec"))
3535
gemspec.development_dependencies.each do |dep|
3636
print "Installing #{dep.name} (#{dep.requirement}) ... "
37-
gem = Gem.install(dep.name, dep.requirement, force: true)
38-
puts "#{gem[0].version}"
37+
installed = dep.matching_specs
38+
if installed.empty?
39+
installed = Gem.install(dep.name, dep.requirement)
40+
puts "#{installed[0].version}"
41+
else
42+
puts "(found #{installed[0].version})"
43+
end
3944
end
4045
end
4146

appveyor.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
---
22
clone_depth: 10
33
install:
4-
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
5-
- appveyor DownloadFile http://dl.bintray.com/oneclick/OpenKnapsack/x64/openssl-1.0.2j-x64-windows.tar.lzma
6-
- 7z e openssl-1.0.2j-x64-windows.tar.lzma
7-
- 7z x -y -oC:\Ruby%ruby_version% openssl-1.0.2j-x64-windows.tar
8-
- ruby -S rake install_dependencies
4+
- ps: |
5+
$Env:PATH = "C:\Ruby${Env:ruby_version}\bin;${Env:PATH}"
6+
if ($Env:ruby_version -match "^23" ) {
7+
# RubyInstaller; download OpenSSL headers from OpenKnapsack Project
8+
$Env:openssl_dir = "C:\Ruby${Env:ruby_version}"
9+
appveyor DownloadFile http://dl.bintray.com/oneclick/OpenKnapsack/x64/openssl-1.0.2j-x64-windows.tar.lzma
10+
7z e openssl-1.0.2j-x64-windows.tar.lzma
11+
7z x -y -oC:\Ruby${Env:ruby_version} openssl-1.0.2j-x64-windows.tar
12+
} else {
13+
# RubyInstaller2; openssl package seems to be installed already
14+
$Env:openssl_dir = "C:\msys64\mingw64"
15+
}
16+
- ruby -v
17+
- openssl version
18+
- rake install_dependencies
919
build_script:
10-
- rake -rdevkit compile -- --with-openssl-dir=C:\Ruby%ruby_version% --enable-debug
20+
- rake -rdevkit compile -- --with-openssl-dir=%openssl_dir% --enable-debug
1121
test_script:
1222
- rake test OSSL_MDEBUG=1
1323
deploy: off
1424
environment:
1525
matrix:
16-
- ruby_version: "23-x64"
26+
- ruby_version: "23-x64" # RI
27+
- ruby_version: "24-x64" # RI2

ext/openssl/ossl.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,6 @@ ossl_bin2hex(unsigned char *in, char *out, size_t inlen)
147147
/*
148148
* our default PEM callback
149149
*/
150-
151-
/*
152-
* OpenSSL requires passwords for PEM-encoded files to be at least four
153-
* characters long. See crypto/pem/pem_lib.c (as of 1.0.2h)
154-
*/
155-
#define OSSL_MIN_PWD_LEN 4
156-
157150
VALUE
158151
ossl_pem_passwd_value(VALUE pass)
159152
{
@@ -162,8 +155,6 @@ ossl_pem_passwd_value(VALUE pass)
162155

163156
StringValue(pass);
164157

165-
if (RSTRING_LEN(pass) < OSSL_MIN_PWD_LEN)
166-
ossl_raise(eOSSLError, "password must be at least %d bytes", OSSL_MIN_PWD_LEN);
167158
/* PEM_BUFSIZE is currently used as the second argument of pem_password_cb,
168159
* that is +max_len+ of ossl_pem_passwd_cb() */
169160
if (RSTRING_LEN(pass) > PEM_BUFSIZE)
@@ -175,11 +166,10 @@ ossl_pem_passwd_value(VALUE pass)
175166
static VALUE
176167
ossl_pem_passwd_cb0(VALUE flag)
177168
{
178-
VALUE pass;
179-
180-
pass = rb_yield(flag);
181-
SafeStringValue(pass);
182-
169+
VALUE pass = rb_yield(flag);
170+
if (NIL_P(pass))
171+
return Qnil;
172+
StringValue(pass);
183173
return pass;
184174
}
185175

@@ -196,7 +186,7 @@ ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd_)
196186
* bytes silently if the input is over 1024 bytes */
197187
if (RB_TYPE_P(pass, T_STRING)) {
198188
len = RSTRING_LEN(pass);
199-
if (len >= OSSL_MIN_PWD_LEN && len <= max_len) {
189+
if (len <= max_len) {
200190
memcpy(buf, RSTRING_PTR(pass), len);
201191
return (int)len;
202192
}
@@ -222,11 +212,9 @@ ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd_)
222212
rb_set_errinfo(Qnil);
223213
return -1;
224214
}
215+
if (NIL_P(pass))
216+
return -1;
225217
len = RSTRING_LEN(pass);
226-
if (len < OSSL_MIN_PWD_LEN) {
227-
rb_warning("password must be at least %d bytes", OSSL_MIN_PWD_LEN);
228-
continue;
229-
}
230218
if (len > max_len) {
231219
rb_warning("password must not be longer than %d bytes", max_len);
232220
continue;

ext/openssl/ossl_bio.c

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,18 @@
1010
#include "ossl.h"
1111

1212
BIO *
13-
ossl_obj2bio(VALUE obj)
13+
ossl_obj2bio(volatile VALUE *pobj)
1414
{
15+
VALUE obj = *pobj;
1516
BIO *bio;
1617

17-
if (RB_TYPE_P(obj, T_FILE)) {
18-
rb_io_t *fptr;
19-
FILE *fp;
20-
int fd;
21-
22-
GetOpenFile(obj, fptr);
23-
rb_io_check_readable(fptr);
24-
if ((fd = rb_cloexec_dup(fptr->fd)) < 0){
25-
rb_sys_fail(0);
26-
}
27-
rb_update_max_fd(fd);
28-
if (!(fp = fdopen(fd, "r"))){
29-
int e = errno;
30-
close(fd);
31-
rb_syserr_fail(e, 0);
32-
}
33-
if (!(bio = BIO_new_fp(fp, BIO_CLOSE))){
34-
fclose(fp);
35-
ossl_raise(eOSSLError, NULL);
36-
}
37-
}
38-
else {
39-
StringValue(obj);
40-
bio = BIO_new_mem_buf(RSTRING_PTR(obj), RSTRING_LENINT(obj));
41-
if (!bio) ossl_raise(eOSSLError, NULL);
42-
}
43-
18+
if (RB_TYPE_P(obj, T_FILE))
19+
obj = rb_funcallv(obj, rb_intern("read"), 0, NULL);
20+
StringValue(obj);
21+
bio = BIO_new_mem_buf(RSTRING_PTR(obj), RSTRING_LENINT(obj));
22+
if (!bio)
23+
ossl_raise(eOSSLError, "BIO_new_mem_buf");
24+
*pobj = obj;
4425
return bio;
4526
}
4627

ext/openssl/ossl_bio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#if !defined(_OSSL_BIO_H_)
1111
#define _OSSL_BIO_H_
1212

13-
BIO *ossl_obj2bio(VALUE);
13+
BIO *ossl_obj2bio(volatile VALUE *);
1414
VALUE ossl_membio2str(BIO*);
1515

1616
#endif

ext/openssl/ossl_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ DupConfigPtr(VALUE obj)
4141

4242
OSSL_Check_Kind(obj, cConfig);
4343
str = rb_funcall(obj, rb_intern("to_s"), 0);
44-
bio = ossl_obj2bio(str);
44+
bio = ossl_obj2bio(&str);
4545
conf = NCONF_new(NULL);
4646
if(!conf){
4747
BIO_free(bio);

ext/openssl/ossl_pkcs12.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
173173

174174
if(rb_scan_args(argc, argv, "02", &arg, &pass) == 0) return self;
175175
passphrase = NIL_P(pass) ? NULL : StringValueCStr(pass);
176-
in = ossl_obj2bio(arg);
176+
in = ossl_obj2bio(&arg);
177177
d2i_PKCS12_bio(in, &pkcs);
178178
DATA_PTR(self) = pkcs;
179179
BIO_free(in);

ext/openssl/ossl_pkcs7.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
197197
VALUE ret, data;
198198

199199
ret = NewPKCS7(cPKCS7);
200-
in = ossl_obj2bio(arg);
200+
in = ossl_obj2bio(&arg);
201201
out = NULL;
202202
pkcs7 = SMIME_read_PKCS7(in, &out);
203203
BIO_free(in);
@@ -229,7 +229,7 @@ ossl_pkcs7_s_write_smime(int argc, VALUE *argv, VALUE klass)
229229
GetPKCS7(pkcs7, p7);
230230
if(!NIL_P(data) && PKCS7_is_detached(p7))
231231
flg |= PKCS7_DETACHED;
232-
in = NIL_P(data) ? NULL : ossl_obj2bio(data);
232+
in = NIL_P(data) ? NULL : ossl_obj2bio(&data);
233233
if(!(out = BIO_new(BIO_s_mem()))){
234234
BIO_free(in);
235235
ossl_raise(ePKCS7Error, NULL);
@@ -266,7 +266,7 @@ ossl_pkcs7_s_sign(int argc, VALUE *argv, VALUE klass)
266266
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
267267
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
268268
ret = NewPKCS7(cPKCS7);
269-
in = ossl_obj2bio(data);
269+
in = ossl_obj2bio(&data);
270270
if(NIL_P(certs)) x509s = NULL;
271271
else{
272272
x509s = ossl_protect_x509_ary2sk(certs, &status);
@@ -322,7 +322,7 @@ ossl_pkcs7_s_encrypt(int argc, VALUE *argv, VALUE klass)
322322
else ciph = ossl_evp_get_cipherbyname(cipher);
323323
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
324324
ret = NewPKCS7(cPKCS7);
325-
in = ossl_obj2bio(data);
325+
in = ossl_obj2bio(&data);
326326
x509s = ossl_protect_x509_ary2sk(certs, &status);
327327
if(status){
328328
BIO_free(in);
@@ -373,7 +373,7 @@ ossl_pkcs7_initialize(int argc, VALUE *argv, VALUE self)
373373
if(rb_scan_args(argc, argv, "01", &arg) == 0)
374374
return self;
375375
arg = ossl_to_der_if_possible(arg);
376-
in = ossl_obj2bio(arg);
376+
in = ossl_obj2bio(&arg);
377377
p7 = PEM_read_bio_PKCS7(in, &pkcs, NULL, NULL);
378378
if (!p7) {
379379
OSSL_BIO_reset(in);
@@ -765,7 +765,7 @@ ossl_pkcs7_verify(int argc, VALUE *argv, VALUE self)
765765
x509st = GetX509StorePtr(store);
766766
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
767767
if(NIL_P(indata)) indata = ossl_pkcs7_get_data(self);
768-
in = NIL_P(indata) ? NULL : ossl_obj2bio(indata);
768+
in = NIL_P(indata) ? NULL : ossl_obj2bio(&indata);
769769
if(NIL_P(certs)) x509s = NULL;
770770
else{
771771
x509s = ossl_protect_x509_ary2sk(certs, &status);
@@ -832,7 +832,7 @@ ossl_pkcs7_add_data(VALUE self, VALUE data)
832832
if(!PKCS7_content_new(pkcs7, NID_pkcs7_data))
833833
ossl_raise(ePKCS7Error, NULL);
834834
}
835-
in = ossl_obj2bio(data);
835+
in = ossl_obj2bio(&data);
836836
if(!(out = PKCS7_dataInit(pkcs7, NULL))) goto err;
837837
for(;;){
838838
if((len = BIO_read(in, buf, sizeof(buf))) <= 0)

ext/openssl/ossl_pkey.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ ossl_pkey_new_from_data(int argc, VALUE *argv, VALUE self)
144144
rb_scan_args(argc, argv, "11", &data, &pass);
145145
pass = ossl_pem_passwd_value(pass);
146146

147-
bio = ossl_obj2bio(data);
147+
bio = ossl_obj2bio(&data);
148148
if (!(pkey = d2i_PrivateKey_bio(bio, NULL))) {
149149
OSSL_BIO_reset(bio);
150150
if (!(pkey = PEM_read_bio_PrivateKey(bio, NULL, ossl_pem_passwd_cb, (void *)pass))) {

0 commit comments

Comments
 (0)