Module | Gem::Security |
In: |
lib/rubygems/security.rb
|
Security: a set of methods, classes, and security policies for checking the validity of signed gem files.
OPT | = | { # private key options :key_algo => Gem::SSL::PKEY_RSA, :key_size => 2048, # public cert options :cert_age => 365 * 24 * 3600, # 1 year :dgst_algo => Gem::SSL::DIGEST_SHA1, # x509 certificate extensions :cert_exts => { 'basicConstraints' => 'CA:FALSE', 'subjectKeyIdentifier' => 'hash', 'keyUsage' => 'keyEncipherment,dataEncipherment,digitalSignature', }, # save the key and cert to a file in build_self_signed_cert()? :save_key => true, :save_cert => true, # if you define either of these, then they'll be used instead of # the output_fmt macro below :save_key_path => nil, :save_cert_path => nil, # output name format for self-signed certs :output_fmt => 'gem-%s.pem', :munge_re => Regexp.new(/[^a-z0-9_.-]+/), # output directory for trusted certificate checksums :trust_dir => File::join(Gem.user_home, '.gem', 'trust'), # default permissions for trust directory and certs :perms => { :trust_dir => 0700, :trusted_cert => 0600, :signing_cert => 0600, :signing_key => 0600, }, } | default options for most of the methods below | |
NoSecurity | = | Policy.new({ :verify_data => false, :verify_signer => false, :verify_chain => false, :verify_root => false, :only_trusted => false, :only_signed => false, }) | No security policy: all package signature checks are disabled. | |
AlmostNoSecurity | = | Policy.new({ :verify_data => true, :verify_signer => false, :verify_chain => false, :verify_root => false, :only_trusted => false, :only_signed => false, }) |
AlmostNo security policy: only verify that the signing certificate is the
one that actually signed the data. Make no attempt to verify the signing
certificate chain.
This policy is basically useless. better than nothing, but can still be easily spoofed, and is not recommended. |
|
LowSecurity | = | Policy.new({ :verify_data => true, :verify_signer => true, :verify_chain => false, :verify_root => false, :only_trusted => false, :only_signed => false, }) |
Low security policy: only verify that the signing certificate is actually
the gem signer, and that the signing certificate is valid.
This policy is better than nothing, but can still be easily spoofed, and is not recommended. |
|
MediumSecurity | = | Policy.new({ :verify_data => true, :verify_signer => true, :verify_chain => true, :verify_root => true, :only_trusted => true, :only_signed => false, }) |
Medium security policy: verify the signing certificate, verify the signing
certificate chain all the way to the root certificate, and only trust root
certificates that we have explicity allowed trust for.
This security policy is reasonable, but it allows unsigned packages, so a malicious person could simply delete the package signature and pass the gem off as unsigned. |
|
HighSecurity | = | Policy.new({ :verify_data => true, :verify_signer => true, :verify_chain => true, :verify_root => true, :only_trusted => true, :only_signed => true, }) |
High security policy: only allow signed gems to be installed, verify the
signing certificate, verify the signing certificate chain all the way to
the root certificate, and only trust root certificates that we have
explicity allowed trust for.
This security policy is significantly more difficult to bypass, and offers a reasonable guarantee that the contents of the gem have not been altered. |
Add certificate to trusted cert list.
Note: At the moment these are stored in OPT[:trust_dir], although that directory may change in the future.
Sign the cert cert with @signing_key and @signing_cert, using the digest algorithm opt[:dgst_algo]. Returns the newly signed certificate.