Skip to content

Commit cc2c300

Browse files
authored
Merge pull request #225 from ekohl/array-parameters
Pass openssl commands as an array
2 parents ad07d44 + 6e1c856 commit cc2c300

File tree

5 files changed

+37
-50
lines changed

5 files changed

+37
-50
lines changed

manifests/export/pem_cert.pp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,20 @@
3737
}
3838

3939
if $der_cert {
40-
$sslmodule = 'x509'
40+
$sslmodule = ['x509', '-inform', 'DER']
4141
$in_cert = $der_cert
42-
$module_opt = '-inform DER'
4342
} else {
44-
$sslmodule = 'pkcs12'
43+
$sslmodule = ['pkcs12']
4544
$in_cert = $pfx_cert
46-
$module_opt = ''
4745
}
4846

4947
$passin_opt = $in_pass ? {
50-
undef => '',
51-
default => "-nokeys -passin pass:${shellquote($in_pass)}",
48+
undef => [],
49+
default => ['-nokeys', '-passin', "pass:${in_pass}"],
5250
}
5351

5452
if $ensure == 'present' {
55-
$cmd = [
56-
"openssl ${sslmodule}",
57-
$module_opt,
58-
"-in ${in_cert}",
59-
"-out ${pem_cert}",
60-
$passin_opt,
61-
]
53+
$cmd = ['openssl'] + $sslmodule + ['-in', $in_cert, '-out', $pem_cert] + $passin_opt
6254

6355
if $dynamic {
6456
$exec_params = {
@@ -70,7 +62,7 @@
7062
}
7163

7264
exec { "Export ${in_cert} to ${pem_cert}":
73-
command => inline_template('<%= @cmd.join(" ") %>'),
65+
command => $cmd,
7466
path => $facts['path'],
7567
* => $exec_params,
7668
}

manifests/export/pem_key.pp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,21 @@
2626
) {
2727
if $ensure == 'present' {
2828
$passin_opt = $in_pass ? {
29-
undef => '',
30-
default => "-passin pass:${shellquote($in_pass)}",
29+
undef => [],
30+
default => ['-passin', "pass:${in_pass}"],
3131
}
3232

3333
$passout_opt = $out_pass ? {
34-
undef => '-nodes',
35-
default => "-passout pass:${shellquote($out_pass)}",
34+
undef => ['-nodes'],
35+
default => ['-passout', "pass:${out_pass}"],
3636
}
3737

3838
$cmd = [
39-
'openssl pkcs12',
40-
"-in ${pfx_cert}",
41-
"-out ${pem_key}",
39+
'openssl', 'pkcs12',
40+
'-in', $pfx_cert,
41+
'-out', $pem_key,
4242
'-nocerts',
43-
$passin_opt,
44-
$passout_opt,
45-
]
43+
] + $passin_opt + $passout_opt
4644

4745
if $dynamic {
4846
$exec_params = {
@@ -54,7 +52,7 @@
5452
}
5553

5654
exec { "Export ${pfx_cert} to ${pem_key}":
57-
command => inline_template('<%= @cmd.join(" ") %>'),
55+
command => $cmd,
5856
path => $facts['path'],
5957
* => $exec_params,
6058
}

manifests/export/pkcs12.pp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,32 @@
3030
Optional[String] $in_pass = undef,
3131
Optional[String] $out_pass = undef,
3232
) {
33+
$full_path = "${basedir}/${name}.p12"
34+
3335
if $ensure == 'present' {
3436
$pass_opt = $in_pass ? {
35-
undef => '',
36-
default => "-passin pass:${shellquote($in_pass)}",
37+
undef => [],
38+
default => ['-passin', "pass:${in_pass}"],
3739
}
3840

3941
$passout_opt = $out_pass ? {
40-
undef => '',
41-
default => "-passout pass:${shellquote($out_pass)}",
42+
undef => [],
43+
default => ['-passout', "pass:${out_pass}"],
4244
}
4345

4446
$chain_opt = $chaincert ? {
45-
undef => '',
46-
default => "-chain -CAfile ${chaincert}",
47+
undef => [],
48+
default => ['-chain', '-CAfile', $chaincert],
4749
}
4850

4951
$cmd = [
50-
'openssl pkcs12 -export',
51-
"-in ${cert}",
52-
"-inkey ${pkey}",
53-
"-out ${basedir}/${name}.p12",
54-
"-name ${name}",
55-
'-nodes -noiter',
56-
$chain_opt,
57-
$pass_opt,
58-
$passout_opt,
59-
]
60-
61-
$full_path = "${basedir}/${name}.p12"
52+
'openssl', 'pkcs12', '-export',
53+
'-in', $cert,
54+
'-inkey', $pkey,
55+
'-out', $full_path,
56+
'-name', $name,
57+
'-nodes', '-noiter',
58+
] + $chain_opt + $pass_opt + $passout_opt
6259

6360
if $dynamic {
6461
$exec_params = {
@@ -70,12 +67,12 @@
7067
}
7168

7269
exec { "Export ${name} to ${full_path}":
73-
command => inline_template('<%= @cmd.join(" ") %>'),
70+
command => $cmd,
7471
path => $facts['path'],
7572
* => $exec_params,
7673
}
7774
} else {
78-
file { "${basedir}/${name}.p12":
75+
file { $full_path:
7976
ensure => absent,
8077
}
8178
}

metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"requirements": [
8787
{
8888
"name": "puppet",
89-
"version_requirement": ">= 7.0.0 < 9.0.0"
89+
"version_requirement": ">= 7.9.0 < 9.0.0"
9090
}
9191
]
9292
}

spec/defines/openssl_export_pem_cert_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
it {
4444
is_expected.to contain_exec('Export /etc/ssl/certs/foo.pfx to /etc/ssl/certs/foo.pem').with(
45-
command: 'openssl pkcs12 -in /etc/ssl/certs/foo.pfx -out /etc/ssl/certs/foo.pem ',
45+
command: ['openssl', 'pkcs12', '-in', '/etc/ssl/certs/foo.pfx', '-out', '/etc/ssl/certs/foo.pem'],
4646
creates: '/etc/ssl/certs/foo.pem',
4747
path: '/usr/bin:/bin:/usr/sbin:/sbin'
4848
)
@@ -60,7 +60,7 @@
6060

6161
it {
6262
is_expected.to contain_exec('Export /etc/ssl/certs/foo.pfx to /etc/ssl/certs/foo.pem').with(
63-
command: 'openssl pkcs12 -in /etc/ssl/certs/foo.pfx -out /etc/ssl/certs/foo.pem ',
63+
command: ['openssl', 'pkcs12', '-in', '/etc/ssl/certs/foo.pfx', '-out', '/etc/ssl/certs/foo.pem'],
6464
path: '/usr/bin:/bin:/usr/sbin:/sbin',
6565
refreshonly: true
6666
)
@@ -79,7 +79,7 @@
7979

8080
it {
8181
is_expected.to contain_exec('Export /etc/ssl/certs/foo.pfx to /etc/ssl/certs/foo.pem').with(
82-
command: "openssl pkcs12 -in /etc/ssl/certs/foo.pfx -out /etc/ssl/certs/foo.pem -nokeys -passin pass:'5r$}^'",
82+
command: ['openssl', 'pkcs12', '-in', '/etc/ssl/certs/foo.pfx', '-out', '/etc/ssl/certs/foo.pem', '-nokeys', '-passin', 'pass:5r$}^'],
8383
creates: '/etc/ssl/certs/foo.pem',
8484
path: '/usr/bin:/bin:/usr/sbin:/sbin'
8585
)
@@ -96,7 +96,7 @@
9696

9797
it {
9898
is_expected.to contain_exec('Export /etc/ssl/certs/foo.der to /etc/ssl/certs/foo.pem').with(
99-
command: 'openssl x509 -inform DER -in /etc/ssl/certs/foo.der -out /etc/ssl/certs/foo.pem ',
99+
command: ['openssl', 'x509', '-inform', 'DER', '-in', '/etc/ssl/certs/foo.der', '-out', '/etc/ssl/certs/foo.pem'],
100100
creates: '/etc/ssl/certs/foo.pem',
101101
path: '/usr/bin:/bin:/usr/sbin:/sbin'
102102
)

0 commit comments

Comments
 (0)