aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/commands/cert_command.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-22 22:46:50 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-22 22:46:50 +0000
commit4c2304f0004e9f1784540f3d36976aad9eab1f68 (patch)
treefe5d7f52b7e01644d0a57316aab03299ed0ee5c8 /lib/rubygems/commands/cert_command.rb
parent66cc0fa4abde68ae360ba2d2cdf4e44bc833e33a (diff)
downloadruby-4c2304f0004e9f1784540f3d36976aad9eab1f68.tar.gz
* lib/rubygems: Import RubyGems from master as of commit b165260
* test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42124 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/commands/cert_command.rb')
-rw-r--r--lib/rubygems/commands/cert_command.rb85
1 files changed, 56 insertions, 29 deletions
diff --git a/lib/rubygems/commands/cert_command.rb b/lib/rubygems/commands/cert_command.rb
index 99e9690755..e417193bca 100644
--- a/lib/rubygems/commands/cert_command.rb
+++ b/lib/rubygems/commands/cert_command.rb
@@ -85,44 +85,52 @@ class Gem::Commands::CertCommand < Gem::Command
end
end
+ def add_certificate certificate # :nodoc:
+ Gem::Security.trust_dir.trust_cert certificate
+
+ say "Added '#{certificate.subject}'"
+ end
+
def execute
options[:add].each do |certificate|
- Gem::Security.trust_dir.trust_cert certificate
-
- say "Added '#{certificate.subject}'"
+ add_certificate certificate
end
options[:remove].each do |filter|
- certificates_matching filter do |certificate, path|
- FileUtils.rm path
- say "Removed '#{certificate.subject}'"
- end
+ remove_certificates_matching filter
end
options[:list].each do |filter|
- certificates_matching filter do |certificate, _|
- # this could probably be formatted more gracefully
- say certificate.subject.to_s
- end
+ list_certificates_matching filter
end
options[:build].each do |name|
build name
end
- unless options[:sign].empty? then
- load_default_cert unless options[:issuer_cert]
- load_default_key unless options[:key]
- end
+ sign_certificates unless options[:sign].empty?
+ end
- options[:sign].each do |cert_file|
- sign cert_file
+ def build name
+ key, key_path = build_key
+ cert_path = build_cert name, key
+
+ say "Certificate: #{cert_path}"
+
+ if key_path
+ say "Private Key: #{key_path}"
+ say "Don't forget to move the key file to somewhere private!"
end
end
- def build name
- if options[:key]
- key = options[:key]
+ def build_cert name, key # :nodoc:
+ cert = Gem::Security.create_cert_email name, key
+ Gem::Security.write cert, "gem-public_cert.pem"
+ end
+
+ def build_key # :nodoc:
+ if options[:key] then
+ options[:key]
else
passphrase = ask_for_password 'Passphrase for your Private Key:'
say "\n"
@@ -135,16 +143,8 @@ class Gem::Commands::CertCommand < Gem::Command
key = Gem::Security.create_key
key_path = Gem::Security.write key, "gem-private_key.pem", 0600, passphrase
- end
- cert = Gem::Security.create_cert_email name, key
- cert_path = Gem::Security.write cert, "gem-public_cert.pem"
-
- say "Certificate: #{cert_path}"
-
- if key_path
- say "Private Key: #{key_path}"
- say "Don't forget to move the key file to somewhere private!"
+ return key, key_path
end
end
@@ -200,6 +200,13 @@ For further reading on signing gems see `ri Gem::Security`.
EOF
end
+ def list_certificates_matching filter # :nodoc:
+ certificates_matching filter do |certificate, _|
+ # this could probably be formatted more gracefully
+ say certificate.subject.to_s
+ end
+ end
+
def load_default_cert
cert_file = File.join Gem.default_cert_path
cert = File.read cert_file
@@ -233,6 +240,18 @@ For further reading on signing gems see `ri Gem::Security`.
terminate_interaction 1
end
+ def load_defaults # :nodoc:
+ load_default_cert unless options[:issuer_cert]
+ load_default_key unless options[:key]
+ end
+
+ def remove_certificates_matching filter # :nodoc:
+ certificates_matching filter do |certificate, path|
+ FileUtils.rm path
+ say "Removed '#{certificate.subject}'"
+ end
+ end
+
def sign cert_file
cert = File.read cert_file
cert = OpenSSL::X509::Certificate.new cert
@@ -247,5 +266,13 @@ For further reading on signing gems see `ri Gem::Security`.
Gem::Security.write cert, cert_file, permissions
end
+ def sign_certificates # :nodoc:
+ load_defaults unless options[:sign].empty?
+
+ options[:sign].each do |cert_file|
+ sign cert_file
+ end
+ end
+
end if defined?(OpenSSL::SSL)