Update openssl cookbook
This commit is contained in:
@@ -20,7 +20,7 @@ module OpenSSLCookbook
|
||||
def dhparam_pem_valid?(dhparam_pem_path)
|
||||
# Check if the dhparam.pem file exists
|
||||
# Verify the dhparam.pem file contains a key
|
||||
return false unless File.exist?(dhparam_pem_path)
|
||||
return false unless ::File.exist?(dhparam_pem_path)
|
||||
dhparam = OpenSSL::PKey::DH.new File.read(dhparam_pem_path)
|
||||
dhparam.params_ok?
|
||||
end
|
||||
@@ -28,21 +28,21 @@ module OpenSSLCookbook
|
||||
def key_file_valid?(key_file_path, key_password = nil)
|
||||
# Check if the key file exists
|
||||
# Verify the key file contains a private key
|
||||
return false unless File.exist?(key_file_path)
|
||||
return false unless ::File.exist?(key_file_path)
|
||||
key = OpenSSL::PKey::RSA.new File.read(key_file_path), key_password
|
||||
key.private?
|
||||
end
|
||||
|
||||
# Generators
|
||||
def gen_dhparam(key_length, generator)
|
||||
fail ArgumentError, 'Key length must be a power of 2 greater than or equal to 1024' unless key_length_valid?(key_length)
|
||||
fail TypeError, 'Generator must be an integer' unless generator.is_a?(Integer)
|
||||
raise ArgumentError, 'Key length must be a power of 2 greater than or equal to 1024' unless key_length_valid?(key_length)
|
||||
raise TypeError, 'Generator must be an integer' unless generator.is_a?(Integer)
|
||||
|
||||
OpenSSL::PKey::DH.new(key_length, generator)
|
||||
end
|
||||
|
||||
def gen_rsa_key(key_length)
|
||||
fail ArgumentError, 'Key length must be a power of 2 greater than or equal to 1024' unless key_length_valid?(key_length)
|
||||
raise ArgumentError, 'Key length must be a power of 2 greater than or equal to 1024' unless key_length_valid?(key_length)
|
||||
|
||||
OpenSSL::PKey::RSA.new(key_length)
|
||||
end
|
||||
@@ -50,8 +50,8 @@ module OpenSSLCookbook
|
||||
# Key manipulation helpers
|
||||
# Returns a pem string
|
||||
def encrypt_rsa_key(rsa_key, key_password)
|
||||
fail TypeError, 'rsa_key must be a Ruby OpenSSL::PKey::RSA object' unless rsa_key.is_a?(OpenSSL::PKey::RSA)
|
||||
fail TypeError, 'RSA key password must be a string' unless key_password.is_a?(String)
|
||||
raise TypeError, 'rsa_key must be a Ruby OpenSSL::PKey::RSA object' unless rsa_key.is_a?(OpenSSL::PKey::RSA)
|
||||
raise TypeError, 'RSA key password must be a string' unless key_password.is_a?(String)
|
||||
|
||||
cipher = OpenSSL::Cipher::Cipher.new('des3')
|
||||
rsa_key.to_pem(cipher, key_password)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#
|
||||
# Cookbook Name:: openssl
|
||||
# Cookbook:: openssl
|
||||
# Library:: random_password
|
||||
# Author:: Seth Vargo <sethvargo@gmail.com>
|
||||
#
|
||||
# Copyright 2015, Seth Vargo
|
||||
# Copyright:: 2015-2017, Seth Vargo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,7 @@ module OpenSSLCookbook
|
||||
end
|
||||
|
||||
class InvalidPasswordMode < StandardError
|
||||
def initialize(given, acceptable)
|
||||
def initialize(given, _acceptable = nil)
|
||||
super <<-EOH
|
||||
The given password mode '#{given}' is not valid. Valid password modes are :hex,
|
||||
:base64, and :random_bytes!
|
||||
@@ -73,7 +73,7 @@ EOH
|
||||
when :random_bytes
|
||||
length
|
||||
else
|
||||
fail InvalidPasswordMode.new(mode)
|
||||
raise InvalidPasswordMode.new(mode)
|
||||
end
|
||||
|
||||
SecureRandom.send(mode, length).force_encoding(encoding)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#
|
||||
# Cookbook Name:: openssl
|
||||
# Cookbook:: openssl
|
||||
# Library:: secure_password
|
||||
# Author:: Joshua Timberman <joshua@chef.io>
|
||||
#
|
||||
# Copyright 2009, Chef Software, Inc.
|
||||
# Copyright:: 2009-2017, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
||||
Reference in New Issue
Block a user