Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OpenSSL 3 #223

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/provider/ssl_pkey/openssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.generate_key(resource)
when :rsa
OpenSSL::PKey::RSA.new(resource[:size])
when :ec
OpenSSL::PKey::EC.new(resource[:curve]).generate_key
OpenSSL::PKey::EC.generate(resource[:curve])
else
raise Puppet::Error,
"Unknown authentication type '#{resource[:authentication]}'"
Expand Down
24 changes: 11 additions & 13 deletions spec/unit/puppet/provider/ssl_pkey/openssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
let(:path) { '/tmp/foo.key' }
let(:pathname) { Pathname.new(path) }
let(:resource) { Puppet::Type::Ssl_pkey.new(path: path) }
let(:key) { OpenSSL::PKey::RSA.new }

it 'exists? should return true if key exists' do
expect(Pathname).to receive(:new).twice.with(path).and_return(pathname)
Expand All @@ -24,15 +23,15 @@

context 'when creating a key with defaults' do
it 'creates an rsa key' do
allow(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_return(key)
expect(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_call_original
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end

context 'when setting size' do
it 'creates with given size' do
resource[:size] = 1024
allow(OpenSSL::PKey::RSA).to receive(:new).with(1024).and_return(key)
expect(OpenSSL::PKey::RSA).to receive(:new).with(1024).and_call_original
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
Expand All @@ -41,7 +40,7 @@
context 'when setting password' do
it 'creates with given password' do
resource[:password] = '2x$5{'
allow(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_return(key)
expect(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_call_original
expect(OpenSSL::Cipher).to receive(:new).with('aes-256-cbc')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
Expand All @@ -52,7 +51,7 @@
context 'when setting authentication to rsa' do
it 'creates an rsa key' do
resource[:authentication] = :rsa
allow(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_return(key)
expect(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_call_original
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
Expand All @@ -61,7 +60,7 @@
it 'creates with given size' do
resource[:authentication] = :rsa
resource[:size] = 1024
allow(OpenSSL::PKey::RSA).to receive(:new).with(1024).and_return(key)
expect(OpenSSL::PKey::RSA).to receive(:new).with(1024).and_call_original
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
Expand All @@ -71,7 +70,7 @@
it 'creates with given password' do
resource[:authentication] = :rsa
resource[:password] = '2x$5{'
allow(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_return(key)
expect(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_call_original
expect(OpenSSL::Cipher).to receive(:new).with('aes-256-cbc')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
Expand All @@ -80,20 +79,19 @@
end

context 'when setting authentication to ec' do
key = OpenSSL::PKey::EC.new('secp384r1').generate_key # For mocking

it 'creates an ec key' do
resource[:authentication] = :ec
allow(OpenSSL::PKey::EC).to receive(:new).with('secp384r1').and_return(key)
allow(OpenSSL::PKey::EC).to receive(:generate).with('secp384r1').and_call_original
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end

context 'when setting curve' do
it 'creates with given curve' do
resource[:authentication] = :ec
resource[:curve] = 'prime239v1'
allow(OpenSSL::PKey::EC).to receive(:new).with('prime239v1').and_return(key)
# See: openssl ecparam -list_curves
resource[:curve] = 'prime256v1'
expect(OpenSSL::PKey::EC).to receive(:generate).with('prime256v1').and_call_original
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
Expand All @@ -103,7 +101,7 @@
it 'creates with given password' do
resource[:authentication] = :ec
resource[:password] = '2x$5{'
allow(OpenSSL::PKey::EC).to receive(:new).with('secp384r1').and_return(key)
expect(OpenSSL::PKey::EC).to receive(:generate).with('secp384r1').and_call_original
expect(OpenSSL::Cipher).to receive(:new).with('aes-256-cbc')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
Expand Down