Signing plugin for hoe.
generate_key | Generate a key for signing your gems. |
signing_key_file | Signs your gems with this private key. |
signing_cert_file | Signs your gem with this certificate. |
Run the ‘generate_key’ task. This will:
Configure your ~/.hoerc.
Generate a signing key and certificate.
Install the private key and public certificate files into ~/.gem.
Upload the certificate to RubyForge.
Hoe will now generate signed gems when the package task is run. If you have multiple machines you build gems on, be sure to install your key and certificate on each machine.
Keep your private key secret! Keep your private key safe!
To make sure your gems are signed run:
rake package; tar tf pkg/yourproject-1.2.3.gem
If your gem is signed you will see:
data.tar.gz data.tar.gz.sig metadata.gz metadata.gz.sig
Define tasks for plugin.
# File lib/hoe/signing.rb, line 46 46: def define_signing_tasks 47: signing_key = nil 48: cert_chain = [] 49: 50: with_config do |config, path| 51: break unless config['signing_key_file'] and config['signing_cert_file'] 52: key_file = File.expand_path config['signing_key_file'].to_s 53: signing_key = key_file if File.exist? key_file 54: 55: cert_file = File.expand_path config['signing_cert_file'].to_s 56: cert_chain << cert_file if File.exist? cert_file 57: end 58: 59: if signing_key and cert_chain then 60: spec.signing_key = signing_key 61: spec.cert_chain = cert_chain 62: end 63: 64: desc 'Generate a key for signing your gems.' 65: task :generate_key do 66: email = Array(spec.email) 67: abort "No email in your gemspec" if email.nil? or email.empty? 68: 69: key_file = with_config { |config, _| config['signing_key_file'] } 70: cert_file = with_config { |config, _| config['signing_cert_file'] } 71: 72: if key_file.nil? or cert_file.nil? then 73: ENV['SHOW_EDITOR'] ||= 'no' 74: Rake::Task['config_hoe'].invoke 75: 76: key_file = with_config { |config, _| config['signing_key_file'] } 77: cert_file = with_config { |config, _| config['signing_cert_file'] } 78: end 79: 80: key_file = File.expand_path key_file 81: cert_file = File.expand_path cert_file 82: 83: unless File.exist? key_file then 84: puts "Generating certificate" 85: 86: if File.exist? key_file then 87: abort "Have #{key_file} but no #{cert_file}, aborting as a precaution" 88: end 89: 90: warn "NOTICE: using #{email.first} for certificate" if email.size > 1 91: 92: sh "gem cert --build #{email.first}" 93: mv "gem-private_key.pem", key_file, :verbose => true 94: mv "gem-public_cert.pem", cert_file, :verbose => true 95: 96: puts "Installed key and certificate." 97: end 98: 99: rf = RubyForge.new.configure 100: rf.login 101: 102: cert_package = "#{rubyforge_name}-certificates" 103: 104: begin 105: rf.lookup 'package', cert_package 106: rescue 107: rf.create_package rubyforge_name, cert_package 108: end 109: 110: unless rf.lookup('release', cert_package)['certificates'] then 111: rf.add_release rubyforge_name, cert_package, 'certificates', cert_file 112: puts "Uploaded certificates to release \"certificates\" in package #{cert_package}" 113: else 114: puts '"certificates" release exists, adding file anyway (will not overwrite)' 115: rf.add_file rubyforge_name, cert_package, 'certificates', cert_file 116: end 117: end 118: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.