diff options
author | Michael Guterl <mguterl@gmail.com> | 2011-03-15 07:53:00 -0400 |
---|---|---|
committer | Daniel DeLeo <dan@opscode.com> | 2011-03-21 11:09:24 -0700 |
commit | b2c38e61e7777ad0d1ee1bab1d438016ff9612c5 (patch) | |
tree | 4351d1634f44b2eefd7965ee9f8c7d644803db6b /chef/lib/chef/rest | |
parent | d561c7362e1e261f2c46ba1c546f4b88cb495f69 (diff) | |
download | chef-b2c38e61e7777ad0d1ee1bab1d438016ff9612c5.tar.gz |
don't check format of private key, rescue exception instead
Diffstat (limited to 'chef/lib/chef/rest')
-rw-r--r-- | chef/lib/chef/rest/auth_credentials.rb | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/chef/lib/chef/rest/auth_credentials.rb b/chef/lib/chef/rest/auth_credentials.rb index 3f5acd5740..c43957843d 100644 --- a/chef/lib/chef/rest/auth_credentials.rb +++ b/chef/lib/chef/rest/auth_credentials.rb @@ -55,22 +55,15 @@ class Chef private def load_signing_key - begin - @raw_key = IO.read(key_file).strip - rescue SystemCallError, IOError => e - Chef::Log.fatal "Failed to read the private key #{key_file}: #{e.inspect}, #{e.backtrace}" - raise Chef::Exceptions::PrivateKeyMissing, "I cannot read #{key_file}, which you told me to use to sign requests!" - end - assert_valid_key_format!(@raw_key) + @raw_key = IO.read(key_file).strip @key = OpenSSL::PKey::RSA.new(@raw_key) - end - - def assert_valid_key_format!(raw_key) - unless (raw_key =~ /\A-----BEGIN RSA PRIVATE KEY-----$/) && (raw_key =~ /^-----END RSA PRIVATE KEY-----\Z/) - msg = "The file #{key_file} does not contain a correctly formatted private key.\n" - msg << "The key file should begin with '-----BEGIN RSA PRIVATE KEY-----' and end with '-----END RSA PRIVATE KEY-----'" - raise Chef::Exceptions::InvalidPrivateKey, msg - end + rescue SystemCallError, IOError => e + Chef::Log.fatal "Failed to read the private key #{key_file}: #{e.inspect}, #{e.backtrace}" + raise Chef::Exceptions::PrivateKeyMissing, "I cannot read #{key_file}, which you told me to use to sign requests!" + rescue OpenSSL::PKey::RSAError + msg = "The file #{key_file} does not contain a correctly formatted private key.\n" + msg << "The key file should begin with '-----BEGIN RSA PRIVATE KEY-----' and end with '-----END RSA PRIVATE KEY-----'" + raise Chef::Exceptions::InvalidPrivateKey, msg end end |