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

Add "fastmode" for dhparam generation #79

Closed
c33s opened this issue Jan 5, 2017 · 2 comments
Closed

Add "fastmode" for dhparam generation #79

c33s opened this issue Jan 5, 2017 · 2 comments

Comments

@c33s
Copy link
Member

c33s commented Jan 5, 2017

dhparam generation can be quite time expensive but openssl provides a flag for faster generation named -dsaparam
details on https://security.stackexchange.com/a/95184

the following code is just quick test implementation:

define openssl::dhparam(
  $path,
  $ensure = present,
  $size = 512,
  $owner = 'root',
  $group = 'root',
  $mode = '0644',
  $fastmode = true,
) {

  validate_absolute_path($path)
  validate_re($ensure, '^(present|absent)$',
    "\$ensure must be either 'present' or 'absent', got '${ensure}'")
  validate_integer($size, '', 1) # positive integer
  validate_string($owner)
  validate_string($group)
  validate_string($mode)

  dhparam { $path:
    ensure => $ensure,
    size   => $size,
    fastmode => $fastmode,
  }

  # Set file access
  file { $path:
      ensure  => $ensure,
      owner   => $owner,
      group   => $group,
      mode    => $mode,
      require => Dhparam[$path];
  }
}
require 'pathname'
Puppet::Type.newtype(:dhparam) do
  desc 'A Diffie Helman parameter file'

  ensurable

  newparam(:path, :namevar => true) do
    validate do |value|
      path = Pathname.new(value)
      unless path.absolute?
        raise ArgumentError, "Path must be absolute: #{path}"
      end
    end
  end


  newparam(:size) do
    desc 'The key size'
    newvalues /\d+/
    defaultto 512
    validate do |value|
      size = value.to_i
      if size <= 0 || value.to_s != size.to_s
        raise ArgumentError, "Size must be a positive integer: #{value.inspect}"
      end
    end
  end

  newparam(:fastmode) do
    desc 'Enable fast mode'
    defaultto false
    #validate do |value|
      #size = value.to_i
      #if size <= 0 || value.to_s != size.to_s
      #  raise ArgumentError, "Size must be a positive integer: #{value.inspect}"
      #end
    #end
  end
end
require 'pathname'
Puppet::Type.type(:dhparam).provide(:openssl) do
  desc 'Manages dhparam files with OpenSSL'

  commands :openssl => 'openssl'

  def exists?
    Pathname.new(resource[:path]).exist?
  end

  def create
    if resource[:fastmode]
        fastmode="-dsaparam"
    else
        fastmode=""
    end


    options = [
      'dhparam',
      fastmode,
      '-out', resource[:path],
      resource[:size]
    ]
    openssl options
  end

  def destroy
    Pathname.new(resource[:path]).delete
  end
end
@c33s
Copy link
Member Author

c33s commented Jan 11, 2017

fixed with PR #80

@c33s c33s closed this as completed Jan 11, 2017
@raphink
Copy link
Member

raphink commented Jan 11, 2017

Thank you for closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants