Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
Add type for creating a cert and key directly in the NSS DB.
Browse files Browse the repository at this point in the history
  • Loading branch information
itewk committed Jun 17, 2014
1 parent 602fae0 commit 34f2193
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 3 deletions.
50 changes: 48 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ nsstools::add_cert { <title>:

* `certdir`

`String`/absolute path required

`String`/absolute path required
Absolute path to the directory to contain the database files.

* `cert`
Expand Down Expand Up @@ -266,6 +265,53 @@ nsstools::add_cert_and_key { <title>:

The "nickname" of the certificate in the database.

### `create_cert_and_key`

Create a certificate and it's associated private key directly in an existing NSS database.

```puppet
nsstools::create_cert_and_key { <title>:
nickname => <title>, # defaults to $title
subject => <subject>, # required
certdir => <certdir>, # required
}
```

* `title`

Used as the default value for the `nickname` parameter.

* `nickname`

`String` defaults to: `title`

The "nickname" of the certificate in the database.

* `subject`

`String` required

The subject of the certificate. The subject identification format follows RFC #1485.

* `keytype`

`String` defaults to: 'rsa'

The type of key to generate with the self signed cert.
Valid options: ras|dsa|ec|all

* `noisefile`

`String`/absolute path defaults to: '/var/log/messages'

The path to a file to use as noise to generate the cert. The minimum file size is 20 bytes.

* `certdir`

`String`/absolute path required

Absolute path to the directory that contains the already created NSS database.

## Functions

### `nsstools_add_cert`
Expand Down
3 changes: 2 additions & 1 deletion manifests/create.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$enable_fips = false,
) {
include nsstools
include nsstools::params

validate_string($password)
validate_absolute_path($certdir)
Expand All @@ -66,7 +67,7 @@
$require_certdir = undef
}

$_password_file = "${certdir}/nss-password.txt"
$_password_file = "${certdir}/${nsstools::params::password_file_name}"
file { $_password_file:
ensure => file,
owner => $owner,
Expand Down
58 changes: 58 additions & 0 deletions manifests/create_cert_and_key.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Creates a self signed certificate with key directly in the NSS database.
#
# Parameters:
# $nickname - optional - The nickname for the NSS certificate, defaults to the title
# $subject - required - The subject of the certificate.
# The subject identification format follows RFC #1485.
# $keytype - optional - The type of key to generate with the self signed cert.
# Valid options: ras|dsa|ec|all
# $noisefile - optional - The path to a file to use as noise to generate the cert.
# The minimum file size is 20 bytes.
# $certdir - required - The path to the NSS DB to add the cert to
#
# Actions:
# Creates a self signed certifacate directly in the NSS databae.
#
# Requires:
# $subject
# $certdir
#
# Sample Usage:
#
# nsstools::create_cert_and_key { 'server_cert':
# nickname => 'Servert Cert',
# subject => 'CN=localhost, OU=OrgUnit, O=Org, L=City, ST=State, C=MY\',
# certdir => '/etc/pki/foo',
# }
#
define nsstools::create_cert_and_key(
$nickname = $title,
$subject,
$keytype = 'rsa',
$noisefile = '/var/log/messages',
$certdir,
) {
include nsstools
include nsstools::params

validate_string($nickname)
validate_string($subject)
validate_re($keytype, [ '^rsa', '^dsa', '^ec', '^all' ])
validate_absolute_path($certdir)
validate_absolute_path($noisefile)

$_password_file = "${certdir}/${nsstools::params::password_file_name}"

# create the cert and key in the NSS database
exec { "create_cert_and_key_${title}":
path => ['/usr/bin'],
command => "certutil -S -k ${keytype} -n '${nickname}' -t \"u,u,u\" -x -s \"${subject}\" -d ${certdir} -f ${_password_file} -z ${noisefile}",
unless => "certutil -d ${certdir} -L -n '${nickname}'",
logoutput => true,
require => [
Nsstools::Create[$certdir],
File[$_password_file],
Class['nsstools'],
],
}
}
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# this class should be considered private
class nsstools::params {
$password_file_name = 'nss-password.txt'

case $::osfamily {
'redhat': {
$package_name = ['nss-tools']
Expand Down

0 comments on commit 34f2193

Please sign in to comment.