Skip to content

Commit f478bd0

Browse files
committed
(PUP-11699) Add support for OpenSSL 3
OpenSSL 3 changed some of the error messages and X509_V_ERR_* error codes. Update the tests to work with both openssl 1.1.1 and 3.0.
1 parent ae6969c commit f478bd0

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

spec/unit/ssl/certificate_request_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198

199199
expect do
200200
request.generate(key, :csr_attributes => csr_attributes)
201-
end.to raise_error Puppet::Error, /Cannot create CSR with attribute thats\.no\.moon: first num too large/
201+
end.to raise_error Puppet::Error, /Cannot create CSR with attribute thats\.no\.moon: /
202202
end
203203

204204
it "should support old non-DER encoded extensions" do
@@ -271,7 +271,7 @@
271271
exts = {"thats.no.moon" => "death star"}
272272
expect do
273273
request.generate(key, :extension_requests => exts)
274-
end.to raise_error Puppet::Error, /Cannot create CSR with extension request thats\.no\.moon.*: first num too large/
274+
end.to raise_error Puppet::Error, /Cannot create CSR with extension request thats\.no\.moon.*: /
275275
end
276276
end
277277

@@ -313,6 +313,7 @@
313313

314314
it "should use SHA1 to sign the csr when SHA256 isn't available" do
315315
csr = OpenSSL::X509::Request.new
316+
csr.public_key = key.public_key
316317
expect(OpenSSL::Digest).to receive(:const_defined?).with("SHA256").and_return(false)
317318
expect(OpenSSL::Digest).to receive(:const_defined?).with("SHA1").and_return(true)
318319
signer = Puppet::SSL::CertificateSigner.new
@@ -323,6 +324,7 @@
323324
it "should use SHA512 to sign the csr when SHA256 and SHA1 aren't available" do
324325
key = OpenSSL::PKey::RSA.new(2048)
325326
csr = OpenSSL::X509::Request.new
327+
csr.public_key = key.public_key
326328
expect(OpenSSL::Digest).to receive(:const_defined?).with("SHA256").and_return(false)
327329
expect(OpenSSL::Digest).to receive(:const_defined?).with("SHA1").and_return(false)
328330
expect(OpenSSL::Digest).to receive(:const_defined?).with("SHA512").and_return(true)
@@ -334,6 +336,7 @@
334336
it "should use SHA384 to sign the csr when SHA256/SHA1/SHA512 aren't available" do
335337
key = OpenSSL::PKey::RSA.new(2048)
336338
csr = OpenSSL::X509::Request.new
339+
csr.public_key = key.public_key
337340
expect(OpenSSL::Digest).to receive(:const_defined?).with("SHA256").and_return(false)
338341
expect(OpenSSL::Digest).to receive(:const_defined?).with("SHA1").and_return(false)
339342
expect(OpenSSL::Digest).to receive(:const_defined?).with("SHA512").and_return(false)
@@ -345,6 +348,7 @@
345348

346349
it "should use SHA224 to sign the csr when SHA256/SHA1/SHA512/SHA384 aren't available" do
347350
csr = OpenSSL::X509::Request.new
351+
csr.public_key = key.public_key
348352
expect(OpenSSL::Digest).to receive(:const_defined?).with("SHA256").and_return(false)
349353
expect(OpenSSL::Digest).to receive(:const_defined?).with("SHA1").and_return(false)
350354
expect(OpenSSL::Digest).to receive(:const_defined?).with("SHA512").and_return(false)

spec/unit/ssl/ssl_provider_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,13 @@
459459
it "raises if root CA's isCA basic constraint is false", unless: Puppet::Util::Platform.jruby? || OpenSSL::OPENSSL_VERSION_NUMBER < 0x10100000 do
460460
certs = [cert_fixture('bad-basic-constraints.pem'), cert_fixture('intermediate.pem')]
461461

462+
# openssl 3 returns 79
463+
# define X509_V_ERR_NO_ISSUER_PUBLIC_KEY 24
464+
# define X509_V_ERR_INVALID_CA 79
462465
expect {
463466
subject.create_context(**config.merge(cacerts: certs, crls: [], revocation: false))
464467
}.to raise_error(Puppet::SSL::CertVerifyError,
465-
"Certificate 'CN=Test CA' failed verification (24): invalid CA certificate")
468+
/Certificate 'CN=Test CA' failed verification \((24|79)\): invalid CA certificate/)
466469
end
467470

468471
# OpenSSL < 1.1 does not verify basicConstraints
@@ -472,7 +475,7 @@
472475
expect {
473476
subject.create_context(**config.merge(cacerts: certs, crls: [], revocation: false))
474477
}.to raise_error(Puppet::SSL::CertVerifyError,
475-
"Certificate 'CN=Test CA Subauthority' failed verification (24): invalid CA certificate")
478+
/Certificate 'CN=Test CA Subauthority' failed verification \((24|79)\): invalid CA certificate/)
476479
end
477480

478481
it 'accepts CA certs in any order' do

spec/unit/x509/cert_provider_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def expects_private_file(path)
280280
# password is 74695716c8b6
281281
expect {
282282
provider.load_private_key('encrypted-key')
283-
}.to raise_error(OpenSSL::PKey::PKeyError, /Could not parse PKey: no start line/)
283+
}.to raise_error(OpenSSL::PKey::PKeyError, /Could not parse PKey: (no start line|bad decrypt)/)
284284
end
285285

286286
it 'decrypts an RSA key previously saved using 3DES' do
@@ -315,7 +315,7 @@ def expects_private_file(path)
315315
# password is 74695716c8b6
316316
expect {
317317
provider.load_private_key('encrypted-ec-key')
318-
}.to raise_error(OpenSSL::PKey::PKeyError, /(unknown|invalid) curve name|Could not parse PKey: no start line/)
318+
}.to raise_error(OpenSSL::PKey::PKeyError, /(unknown|invalid) curve name|Could not parse PKey: (no start line|bad decrypt)/)
319319
end
320320
end
321321
end

0 commit comments

Comments
 (0)