summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Guterl <mguterl@gmail.com>2011-03-15 07:53:00 -0400
committerDaniel DeLeo <dan@opscode.com>2011-03-21 11:09:24 -0700
commitb2c38e61e7777ad0d1ee1bab1d438016ff9612c5 (patch)
tree4351d1634f44b2eefd7965ee9f8c7d644803db6b
parentd561c7362e1e261f2c46ba1c546f4b88cb495f69 (diff)
downloadchef-b2c38e61e7777ad0d1ee1bab1d438016ff9612c5.tar.gz
don't check format of private key, rescue exception instead
-rw-r--r--chef/lib/chef/rest/auth_credentials.rb23
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