Skip to content

Commit 509fc7f

Browse files
committed
Merge branch 'maint-3.1' into maint-3.2
* maint-3.1: .github/workflows/test.yml: synchronize with master pkcs7: fix memory leak in error path of PKCS7.new and .read_smime asn1: fix ObjectId#== x509: fix handling of multiple URIs in Certificate#crl_uris test_x509cert.rb: break up test_extension into smaller units
2 parents 0b0a0df + 68fd941 commit 509fc7f

File tree

6 files changed

+194
-127
lines changed

6 files changed

+194
-127
lines changed

.github/workflows/test.yml

Lines changed: 68 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ jobs:
88
with:
99
engine: cruby-truffleruby
1010
min_version: 2.7
11+
1112
test:
1213
needs: ruby-versions
1314
name: >-
@@ -20,12 +21,8 @@ jobs:
2021
os: [ ubuntu-22.04, ubuntu-20.04, macos-latest, windows-latest ]
2122
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
2223
exclude:
23-
# uses non-standard MSYS2 OpenSSL 3 package
24-
- { os: windows-latest, ruby: head }
2524
- { os: windows-latest, ruby: truffleruby }
2625
- { os: windows-latest, ruby: truffleruby-head }
27-
- { os: macos-latest, ruby: truffleruby }
28-
- { os: ubuntu-20.04, ruby: truffleruby }
2926
include:
3027
- { os: windows-latest, ruby: ucrt }
3128
- { os: windows-latest, ruby: mswin }
@@ -38,44 +35,43 @@ jobs:
3835
uses: ruby/setup-ruby@v1
3936
with:
4037
ruby-version: ${{ matrix.ruby }}
41-
42-
- name: depends
43-
run: bundle install
38+
bundler-cache: true # `bundle install` and cache
4439

4540
# Enable the verbose option in mkmf.rb to print the compiling commands.
4641
- name: enable mkmf verbose
4742
run: echo "MAKEFLAGS=V=1" >> $GITHUB_ENV
4843
if: runner.os == 'Linux' || runner.os == 'macOS'
4944

50-
- name: set flags to check compiler warnings.
45+
- name: set flags to check compiler warnings
5146
run: echo "RUBY_OPENSSL_EXTCFLAGS=-Werror" >> $GITHUB_ENV
5247
if: ${{ !matrix.skip-warnings }}
5348

54-
- name: compile
55-
run: rake compile
49+
- name: rake compile
50+
run: bundle exec rake compile
5651

57-
- name: test
58-
run: rake test TESTOPTS="-v --no-show-detail-immediately"
52+
- name: rake test
53+
run: bundle exec rake test TESTOPTS="-v --no-show-detail-immediately"
5954
timeout-minutes: 5
6055

6156
test-openssls:
6257
name: >-
63-
${{ matrix.openssl }} ${{ matrix.name-extra || '' }}
64-
runs-on: ${{ matrix.os }}
58+
${{ matrix.openssl }} ${{ matrix.name-extra }}
59+
runs-on: ubuntu-latest
6560
strategy:
6661
fail-fast: false
6762
matrix:
68-
os: [ ubuntu-latest ]
69-
ruby: [ "3.0" ]
63+
name-extra: [ '' ]
7064
openssl:
71-
# https://www.openssl.org/source/
65+
# https://openssl-library.org/source/
7266
- openssl-1.0.2u # EOL
7367
- openssl-1.1.0l # EOL
74-
- openssl-1.1.1w # EOL
75-
- openssl-3.0.13
76-
- openssl-3.1.5
77-
- openssl-3.2.1
78-
- openssl-3.3.0
68+
- openssl-1.1.1w # EOL 2023-09-11, still used by RHEL 8 and Ubuntu 20.04
69+
- openssl-3.0.15 # Supported until 2026-09-07
70+
- openssl-3.1.7 # Supported until 2025-03-14
71+
- openssl-3.2.3 # Supported until 2025-11-23
72+
- openssl-3.3.2 # Supported until 2026-04-09
73+
- openssl-3.4.0 # Supported until 2026-10-22
74+
- openssl-master
7975
# http://www.libressl.org/releases.html
8076
- libressl-3.1.5 # EOL
8177
- libressl-3.2.7 # EOL
@@ -84,93 +80,89 @@ jobs:
8480
- libressl-3.5.3 # EOL
8581
- libressl-3.6.3 # EOL
8682
- libressl-3.7.3 # EOL
87-
- libressl-3.8.4
88-
- libressl-3.9.1
89-
fips-enabled: [ false ]
83+
- libressl-3.8.4 # EOL 2024-10-16
84+
- libressl-3.9.2 # Supported until 2025-04-05
85+
- libressl-4.0.0
9086
include:
91-
- { os: ubuntu-latest, ruby: "3.0", openssl: openssl-3.0.10, fips-enabled: true, append-configure: 'enable-fips', name-extra: 'fips' }
92-
- { os: ubuntu-latest, ruby: "3.0", openssl: openssl-3.1.2, fips-enabled: true, append-configure: 'enable-fips', name-extra: 'fips' }
93-
- { os: ubuntu-latest, ruby: "3.0", openssl: openssl-head, git: 'https://github.com/openssl/openssl.git', branch: 'master' }
94-
- { os: ubuntu-latest, ruby: "3.0", openssl: openssl-head, git: 'https://github.com/openssl/openssl.git', branch: 'master', fips-enabled: true, append-configure: 'enable-fips', name-extra: 'fips' }
87+
- { name-extra: 'with fips provider', openssl: openssl-3.0.15, fips-enabled: true }
88+
- { name-extra: 'with fips provider', openssl: openssl-3.1.7, fips-enabled: true }
89+
- { name-extra: 'with fips provider', openssl: openssl-3.2.3, fips-enabled: true }
90+
- { name-extra: 'with fips provider', openssl: openssl-3.3.2, fips-enabled: true }
91+
- { name-extra: 'without legacy provider', openssl: openssl-3.4.0, append-configure: 'no-legacy' }
9592
steps:
9693
- name: repo checkout
9794
uses: actions/checkout@v4
9895

99-
- name: prepare openssl
96+
- id: cache-openssl
97+
uses: actions/cache@v4
98+
with:
99+
path: ~/openssl
100+
key: openssl-${{ runner.os }}-${{ matrix.openssl }}-${{ matrix.append-configure || 'default' }}
101+
if: matrix.openssl != 'openssl-master' && matrix.openssl != 'libressl-master'
102+
103+
- name: Compile OpenSSL library
104+
if: steps.cache-openssl.outputs.cache-hit != 'true'
100105
run: |
101106
# Enable Bash debugging option temporarily for debugging use.
102107
set -x
103108
mkdir -p tmp/build-openssl && cd tmp/build-openssl
104109
case ${{ matrix.openssl }} in
105-
openssl-*)
106-
if [ -z "${{ matrix.git }}" ]; then
107-
curl -OL https://openssl.org/source/${{ matrix.openssl }}.tar.gz
108-
tar xf ${{ matrix.openssl }}.tar.gz && cd ${{ matrix.openssl }}
109-
else
110-
git clone -b ${{ matrix.branch }} --depth 1 ${{ matrix.git }} ${{ matrix.openssl }}
111-
cd ${{ matrix.openssl }}
112-
# Log the commit hash.
113-
echo "Git commit: $(git rev-parse HEAD)"
114-
fi
110+
openssl-1.*)
111+
OPENSSL_COMMIT=$(echo ${{ matrix.openssl }} | sed -e 's/^openssl-/OpenSSL_/' | sed -e 's/\./_/g')
112+
git clone -b $OPENSSL_COMMIT --depth 1 https://github.com/openssl/openssl.git .
113+
echo "Git commit: $(git rev-parse HEAD)"
115114
# shared is required for 1.0.x.
116-
./Configure --prefix=$HOME/.openssl/${{ matrix.openssl }} --libdir=lib \
117-
shared linux-x86_64 ${{ matrix.append-configure }}
118-
make depend
115+
./Configure --prefix=$HOME/openssl --libdir=lib shared linux-x86_64
116+
make depend && make -j4 && make install_sw
117+
;;
118+
openssl-*)
119+
OPENSSL_COMMIT=${{ matrix.openssl == 'openssl-master' && 'master' || matrix.openssl }}
120+
git clone -b $OPENSSL_COMMIT --depth 1 https://github.com/openssl/openssl.git .
121+
echo "Git commit: $(git rev-parse HEAD)"
122+
./Configure --prefix=$HOME/openssl --libdir=lib enable-fips ${{ matrix.append-configure }}
123+
make -j4 && make install_sw && make install_fips
119124
;;
120125
libressl-*)
121-
curl -OL https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/${{ matrix.openssl }}.tar.gz
122-
tar xf ${{ matrix.openssl }}.tar.gz && cd ${{ matrix.openssl }}
123-
./configure --prefix=$HOME/.openssl/${{ matrix.openssl }}
126+
curl -L https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/${{ matrix.openssl }}.tar.gz | \
127+
tar xzf - --strip-components=1
128+
./configure --prefix=$HOME/openssl
129+
make -j4 && make install
124130
;;
125131
*)
126132
false
127133
;;
128134
esac
129-
make -j4
130-
make install_sw
131-
132-
- name: prepare openssl fips
133-
run: make install_fips
134-
working-directory: tmp/build-openssl/${{ matrix.openssl }}
135-
if: matrix.fips-enabled
136-
137-
- name: set the open installed directory
138-
run: >
139-
sed -e "s|OPENSSL_DIR|$HOME/.openssl/${{ matrix.openssl }}|"
140-
tool/openssl_fips.cnf.tmpl > tmp/openssl_fips.cnf
141-
if: matrix.fips-enabled
142-
143-
- name: set openssl config file path for fips.
144-
run: echo "OPENSSL_CONF=$(pwd)/tmp/openssl_fips.cnf" >> $GITHUB_ENV
145-
if: matrix.fips-enabled
146135
147136
- name: load ruby
148137
uses: ruby/setup-ruby@v1
149138
with:
150-
ruby-version: ${{ matrix.ruby }}
151-
152-
- name: depends
153-
run: bundle install
139+
ruby-version: '3.0'
140+
bundler-cache: true
154141

155142
- name: enable mkmf verbose
156143
run: echo "MAKEFLAGS=V=1" >> $GITHUB_ENV
157-
if: runner.os == 'Linux' || runner.os == 'macOS'
158144

159-
- name: set flags to check compiler warnings.
145+
- name: set flags to check compiler warnings
160146
run: echo "RUBY_OPENSSL_EXTCFLAGS=-Werror" >> $GITHUB_ENV
161147
if: ${{ !matrix.skip-warnings }}
162148

163-
- name: compile
164-
run: rake compile -- --with-openssl-dir=$HOME/.openssl/${{ matrix.openssl }}
149+
- name: rake compile
150+
run: bundle exec rake compile -- --with-openssl-dir=$HOME/openssl
165151

166-
- name: test
167-
run: rake test TESTOPTS="-v --no-show-detail-immediately"
152+
- name: setup OpenSSL config file for fips
153+
run: |
154+
sed -e "s|OPENSSL_DIR|$HOME/openssl|" tool/openssl_fips.cnf.tmpl > tmp/openssl_fips.cnf
155+
echo "OPENSSL_CONF=$(pwd)/tmp/openssl_fips.cnf" >> $GITHUB_ENV
156+
if: matrix.fips-enabled
157+
158+
- name: rake test
159+
run: bundle exec rake test TESTOPTS="-v --no-show-detail-immediately"
168160
timeout-minutes: 5
169161
if: ${{ !matrix.fips-enabled }}
170162

171163
# Run only the passing tests on the FIPS module as a temporary workaround.
172164
# TODO Fix other tests, and run all the tests on FIPS module.
173-
- name: test on fips module
174-
run: |
175-
rake test_fips TESTOPTS="-v --no-show-detail-immediately"
165+
- name: rake test_fips
166+
run: bundle exec rake test_fips TESTOPTS="-v --no-show-detail-immediately"
167+
timeout-minutes: 5
176168
if: matrix.fips-enabled

ext/openssl/ossl_asn1.c

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,30 +1298,6 @@ ossl_asn1obj_get_ln(VALUE self)
12981298
return ret;
12991299
}
13001300

1301-
/*
1302-
* call-seq:
1303-
* oid == other_oid => true or false
1304-
*
1305-
* Returns +true+ if _other_oid_ is the same as _oid_
1306-
*/
1307-
static VALUE
1308-
ossl_asn1obj_eq(VALUE self, VALUE other)
1309-
{
1310-
VALUE valSelf, valOther;
1311-
int nidSelf, nidOther;
1312-
1313-
valSelf = ossl_asn1_get_value(self);
1314-
valOther = ossl_asn1_get_value(other);
1315-
1316-
if ((nidSelf = OBJ_txt2nid(StringValueCStr(valSelf))) == NID_undef)
1317-
ossl_raise(eASN1Error, "OBJ_txt2nid");
1318-
1319-
if ((nidOther = OBJ_txt2nid(StringValueCStr(valOther))) == NID_undef)
1320-
ossl_raise(eASN1Error, "OBJ_txt2nid");
1321-
1322-
return nidSelf == nidOther ? Qtrue : Qfalse;
1323-
}
1324-
13251301
static VALUE
13261302
asn1obj_get_oid_i(VALUE vobj)
13271303
{
@@ -1366,6 +1342,25 @@ ossl_asn1obj_get_oid(VALUE self)
13661342
return str;
13671343
}
13681344

1345+
/*
1346+
* call-seq:
1347+
* oid == other_oid => true or false
1348+
*
1349+
* Returns +true+ if _other_oid_ is the same as _oid_.
1350+
*/
1351+
static VALUE
1352+
ossl_asn1obj_eq(VALUE self, VALUE other)
1353+
{
1354+
VALUE oid1, oid2;
1355+
1356+
if (!rb_obj_is_kind_of(other, cASN1ObjectId))
1357+
return Qfalse;
1358+
1359+
oid1 = ossl_asn1obj_get_oid(self);
1360+
oid2 = ossl_asn1obj_get_oid(other);
1361+
return rb_str_equal(oid1, oid2);
1362+
}
1363+
13691364
#define OSSL_ASN1_IMPL_FACTORY_METHOD(klass) \
13701365
static VALUE ossl_asn1_##klass(int argc, VALUE *argv, VALUE self)\
13711366
{ return rb_funcall3(cASN1##klass, rb_intern("new"), argc, argv); }

ext/openssl/ossl_pkcs7.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
167167
BIO_free(in);
168168
if (!pkcs7)
169169
ossl_raise(ePKCS7Error, "Could not parse the PKCS7");
170-
if (!pkcs7->d.ptr)
170+
if (!pkcs7->d.ptr) {
171+
PKCS7_free(pkcs7);
171172
ossl_raise(ePKCS7Error, "No content in PKCS7");
173+
}
172174

173175
data = out ? ossl_membio2str(out) : Qnil;
174176
SetPKCS7(ret, pkcs7);
@@ -350,8 +352,10 @@ ossl_pkcs7_initialize(int argc, VALUE *argv, VALUE self)
350352
BIO_free(in);
351353
if (!p7)
352354
ossl_raise(rb_eArgError, "Could not parse the PKCS7");
353-
if (!p7->d.ptr)
355+
if (!p7->d.ptr) {
356+
PKCS7_free(p7);
354357
ossl_raise(rb_eArgError, "No content in PKCS7");
358+
}
355359

356360
RTYPEDDATA_DATA(self) = p7;
357361
PKCS7_free(p7_orig);

lib/openssl/x509.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ module CRLDistributionPoints
122122
include Helpers
123123

124124
# Get the distributionPoint fullName URI from the certificate's CRL
125-
# distribution points extension, as described in RFC5280 Section
126-
# 4.2.1.13
125+
# distribution points extension, as described in RFC 5280 Section
126+
# 4.2.1.13.
127127
#
128128
# Returns an array of strings or nil or raises ASN1::ASN1Error.
129129
def crl_uris
@@ -135,19 +135,19 @@ def crl_uris
135135
raise ASN1::ASN1Error, "invalid extension"
136136
end
137137

138-
crl_uris = cdp_asn1.map do |crl_distribution_point|
138+
crl_uris = cdp_asn1.flat_map do |crl_distribution_point|
139139
distribution_point = crl_distribution_point.value.find do |v|
140140
v.tag_class == :CONTEXT_SPECIFIC && v.tag == 0
141141
end
142142
full_name = distribution_point&.value&.find do |v|
143143
v.tag_class == :CONTEXT_SPECIFIC && v.tag == 0
144144
end
145-
full_name&.value&.find do |v|
145+
full_name&.value&.select do |v|
146146
v.tag_class == :CONTEXT_SPECIFIC && v.tag == 6 # uniformResourceIdentifier
147147
end
148148
end
149149

150-
crl_uris&.map(&:value)
150+
crl_uris.empty? ? nil : crl_uris.map(&:value)
151151
end
152152
end
153153

test/openssl/test_asn1.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ def test_object_identifier
326326
oid = (0...100).to_a.join(".").b
327327
obj = OpenSSL::ASN1::ObjectId.new(oid)
328328
assert_equal oid, obj.oid
329+
end
329330

331+
def test_object_identifier_equality
330332
aki = [
331333
OpenSSL::ASN1::ObjectId.new("authorityKeyIdentifier"),
332334
OpenSSL::ASN1::ObjectId.new("X509v3 Authority Key Identifier"),
@@ -341,17 +343,22 @@ def test_object_identifier
341343

342344
aki.each do |a|
343345
aki.each do |b|
344-
assert a == b
346+
assert_equal true, a == b
345347
end
346348

347349
ski.each do |b|
348-
refute a == b
350+
assert_equal false, a == b
349351
end
350352
end
351353

352-
assert_raise(TypeError) {
353-
OpenSSL::ASN1::ObjectId.new("authorityKeyIdentifier") == nil
354-
}
354+
obj1 = OpenSSL::ASN1::ObjectId.new("1.2.34.56789.10")
355+
obj2 = OpenSSL::ASN1::ObjectId.new("1.2.34.56789.10")
356+
obj3 = OpenSSL::ASN1::ObjectId.new("1.2.34.56789.11")
357+
omit "OID 1.2.34.56789.10 is registered" if obj1.sn
358+
assert_equal true, obj1 == obj2
359+
assert_equal false, obj1 == obj3
360+
361+
assert_equal false, OpenSSL::ASN1::ObjectId.new("authorityKeyIdentifier") == nil
355362
end
356363

357364
def test_sequence

0 commit comments

Comments
 (0)