2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4 # See LICENSE.txt for permissions.
7 # Some system might not have OpenSSL installed, therefore the core
8 # library file openssl might not be available. We localize testing
9 # for the presence of OpenSSL in this file.
13 # Is SSL (used by the signing commands) available on this
16 require 'rubygems/gem_openssl'
20 # Set the value of the ssl_available flag.
21 attr_writer :ssl_available
23 # Ensure that SSL is available. Throw an exception if it is not.
24 def ensure_ssl_available
26 fail Gem::Exception, "SSL is not installed on this system"
35 # Reference a constant defined in the .rb portion of ssl (just to
36 # make sure that part is loaded too).
38 dummy = OpenSSL::Digest::SHA1
40 Gem.ssl_available = true
42 class OpenSSL::X509::Certificate # :nodoc:
43 # Check the validity of this certificate.
44 def check_validity(issuer_cert = nil, time = Time.now)
45 ret = if @not_before && @not_before > time
46 [false, :expired, "not valid before '#@not_before'"]
47 elsif @not_after && @not_after < time
48 [false, :expired, "not valid after '#@not_after'"]
49 elsif issuer_cert && !verify(issuer_cert.public_key)
50 [false, :issuer, "#{issuer_cert.subject} is not issuer"]
52 [true, :ok, 'Valid certificate']
56 { :is_valid => ret[0], :error => ret[1], :desc => ret[2] }
60 rescue LoadError, StandardError
61 Gem.ssl_available = false
66 # We make our own versions of the constants here. This allows us
67 # to reference the constants, even though some systems might not
68 # have SSL installed in the Ruby core package.
70 # These constants are only used during load time. At runtime, any
71 # method that makes a direct reference to SSL software must be
72 # protected with a Gem.ensure_ssl_available call.
74 if Gem.ssl_available? then
75 PKEY_RSA = OpenSSL::PKey::RSA
76 DIGEST_SHA1 = OpenSSL::Digest::SHA1