Skip to content

Commit

Permalink
Merge pull request #233 from bastelfreak/test
Browse files Browse the repository at this point in the history
fix: remove `nokeys` option and set default empty import/export passwords
  • Loading branch information
bastelfreak authored Feb 10, 2025
2 parents b4f2682 + b92aaf3 commit 084efb7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
38 changes: 38 additions & 0 deletions examples/export_pkcs12_from_key.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,41 @@
cert => '/tmp/foo2.example.com.crt',
out_pass => 'mahje1Qu',
}

# same as above, just no password for the X509/pkcs12
openssl::certificate::x509 { 'foo3.example.com':
ensure => present,
country => 'CH',
organization => 'Example.com',
commonname => 'foo3.example.com',
base_dir => '/tmp',
owner => 'nobody',
# This is just to speed up CI - use 2048 or more in production
key_size => 1024,
}
-> openssl::export::pkcs12 { 'export3.pkcs12':
ensure => 'present',
basedir => '/tmp',
pkey => '/tmp/foo3.example.com.key',
cert => '/tmp/foo3.example.com.crt',
}

# same as above, just with password for the X509 / no password for pkcs12
openssl::certificate::x509 { 'foo4.example.com':
ensure => present,
country => 'CH',
organization => 'Example.com',
commonname => 'foo4.example.com',
base_dir => '/tmp',
owner => 'nobody',
password => 'mahje1Qu',
# This is just to speed up CI - use 2048 or more in production
key_size => 1024,
}
-> openssl::export::pkcs12 { 'export4.pkcs12':
ensure => 'present',
basedir => '/tmp',
pkey => '/tmp/foo4.example.com.key',
cert => '/tmp/foo4.example.com.crt',
in_pass => 'mahje1Qu',
}
8 changes: 4 additions & 4 deletions manifests/export/pem_key.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
) {
if $ensure == 'present' {
if $in_pass {
$passin_opt = ['-nokeys', '-passin', 'env:CERTIFICATE_PASSIN']
$passin_opt = ['-passin', 'env:CERTIFICATE_PASSIN']
$passin_env = ["CERTIFICATE_PASSIN=${in_pass}"]
} else {
$passin_opt = []
$passin_opt = ['-passin', 'pass:']
$passin_env = []
}

if $out_pass {
$passout_opt = ['-nokeys', '-passout', 'env:CERTIFICATE_PASSOUT']
$passout_opt = ['-passout', 'env:CERTIFICATE_PASSOUT']
$passout_env = ["CERTIFICATE_PASSOUT=${out_pass}"]
} else {
$passout_opt = []
$passout_opt = ['-nodes']
$passout_env = []
}

Expand Down
8 changes: 4 additions & 4 deletions manifests/export/pkcs12.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@

if $ensure == 'present' {
if $in_pass {
$passin_opt = ['-nokeys', '-passin', 'env:CERTIFICATE_PASSIN']
$passin_opt = ['-passin', 'env:CERTIFICATE_PASSIN']
$passin_env = ["CERTIFICATE_PASSIN=${in_pass}"]
} else {
$passin_opt = []
$passin_opt = ['-passin', 'pass:']
$passin_env = []
}

if $out_pass {
$passout_opt = ['-nokeys', '-passout', 'env:CERTIFICATE_PASSOUT']
$passout_opt = ['-passout', 'env:CERTIFICATE_PASSOUT']
$passout_env = ["CERTIFICATE_PASSOUT=${out_pass}"]
} else {
$passout_opt = []
$passout_opt = ['-passout', 'pass:']
$passout_env = []
}

Expand Down
14 changes: 14 additions & 0 deletions spec/acceptance/pkcs12_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
it { expect(file('/tmp/foo2.example.com.crt')).to be_file.and(have_attributes(owner: 'nobody', group: 'root')) }
it { expect(file('/tmp/foo2.example.com.key')).to be_file.and(have_attributes(owner: 'nobody', group: 'root')) }
it { expect(file('/tmp/export2.pkcs12.p12')).to be_file.and(have_attributes(owner: 'root', group: 'root')) }
it { expect(file('/tmp/foo3.example.com.crt')).to be_file.and(have_attributes(owner: 'nobody', group: 'root')) }
it { expect(file('/tmp/foo3.example.com.key')).to be_file.and(have_attributes(owner: 'nobody', group: 'root')) }
it { expect(file('/tmp/export3.pkcs12.p12')).to be_file.and(have_attributes(owner: 'root', group: 'root')) }
it { expect(file('/tmp/foo4.example.com.crt')).to be_file.and(have_attributes(owner: 'nobody', group: 'root')) }
it { expect(file('/tmp/foo4.example.com.key')).to be_file.and(have_attributes(owner: 'nobody', group: 'root')) }
it { expect(file('/tmp/export4.pkcs12.p12')).to be_file.and(have_attributes(owner: 'root', group: 'root')) }
end
# rubocop:disable RSpec/RepeatedExampleGroupBody
describe file('/tmp/export.pkcs12.p12') do
Expand All @@ -19,5 +25,13 @@
describe file('/tmp/export2.pkcs12.p12') do
its(:size) { is_expected.to be > 0 }
end

describe file('/tmp/export3.pkcs12.p12') do
its(:size) { is_expected.to be > 0 }
end

describe file('/tmp/export4.pkcs12.p12') do
its(:size) { is_expected.to be > 0 }
end
# rubocop:enable RSpec/RepeatedExampleGroupBody
end

0 comments on commit 084efb7

Please sign in to comment.