A source representing a single .gem file. This is used for installation of local gems.
An absolutely silent progress reporter.
A basic dotted progress reporter.
An absolutely silent download reporter.
Servlet for handling CGI
scripts
Example:
server.mount('/cgi/my_script', WEBrick::HTTPServlet::CGIHandler, '/path/to/my_script')
ERBHandler
evaluates an ERB
file and returns the result. This handler is automatically used if there are .rhtml files in a directory served by the FileHandler
.
ERBHandler
supports GET and POST methods.
The ERB
file is evaluated with the local variables servlet_request
and servlet_response
which are a WEBrick::HTTPRequest
and WEBrick::HTTPResponse
respectively.
Example .rhtml file:
Request to <%= servlet_request.request_uri %> Query params <%= servlet_request.query.inspect %>
Mounts a proc at a path that accepts a request and response.
Instead of mounting this servlet with WEBrick::HTTPServer#mount
use WEBrick::HTTPServer#mount_proc
:
server.mount_proc '/' do |req, res| res.body = 'it worked!' res.status = 200 end
Gem::Resolver::Molinillo
is a generic dependency resolution algorithm.
Raised if the tar IO
is not seekable
An SSLContext
is used to set various options regarding certificates, algorithms, verification, session caching, etc. The SSLContext
is used to create an SSLSocket
.
All attributes must be set before creating an SSLSocket
as the SSLContext
will be frozen afterward.
The following attributes are available but don’t show up in rdoc:
ssl_version, cert, key, client_ca
, ca_file
, ca_path
, timeout,
session_id_context
, session_add_cb, session_new_cb
, session_remove_cb
Implementation of an X.509 certificate as specified in RFC 5280. Provides access to a certificate’s attributes and allows certificates to be read from a string, but also supports the creation of new certificates from scratch.
Certificate
is capable of handling DER-encoded certificates and certificates encoded in OpenSSL’s PEM format.
raw = File.read "cert.cer" # DER- or PEM-encoded certificate = OpenSSL::X509::Certificate.new raw
A certificate may be encoded in DER format
cert = ... File.open("cert.cer", "wb") { |f| f.print cert.to_der }
or in PEM format
cert = ... File.open("cert.pem", "wb") { |f| f.print cert.to_pem }
X.509 certificates are associated with a private/public key pair, typically a RSA, DSA or ECC key (see also OpenSSL::PKey::RSA
, OpenSSL::PKey::DSA
and OpenSSL::PKey::EC
), the public key itself is stored within the certificate and can be accessed in form of an OpenSSL::PKey
. Certificates are typically used to be able to associate some form of identity with a key pair, for example web servers serving pages over HTTPs use certificates to authenticate themselves to the user.
The public key infrastructure (PKI) model relies on trusted certificate authorities (“root CAs”) that issue these certificates, so that end users need to base their trust just on a selected few authorities that themselves again vouch for subordinate CAs issuing their certificates to end users.
The OpenSSL::X509
module provides the tools to set up an independent PKI, similar to scenarios where the ‘openssl’ command line tool is used for issuing certificates in a private PKI.
First, we need to create a “self-signed” root certificate. To do so, we need to generate a key first. Please note that the choice of “1” as a serial number is considered a security flaw for real certificates. Secure choices are integers in the two-digit byte range and ideally not sequential but secure random numbers, steps omitted here to keep the example concise.
root_key = OpenSSL::PKey::RSA.new 2048 # the CA's public/private key root_ca = OpenSSL::X509::Certificate.new root_ca.version = 2 # cf. RFC 5280 - to make it a "v3" certificate root_ca.serial = 1 root_ca.subject = OpenSSL::X509::Name.parse "/DC=org/DC=ruby-lang/CN=Ruby CA" root_ca.issuer = root_ca.subject # root CA's are "self-signed" root_ca.public_key = root_key.public_key root_ca.not_before = Time.now root_ca.not_after = root_ca.not_before + 2 * 365 * 24 * 60 * 60 # 2 years validity ef = OpenSSL::X509::ExtensionFactory.new ef.subject_certificate = root_ca ef.issuer_certificate = root_ca root_ca.add_extension(ef.create_extension("basicConstraints","CA:TRUE",true)) root_ca.add_extension(ef.create_extension("keyUsage","keyCertSign, cRLSign", true)) root_ca.add_extension(ef.create_extension("subjectKeyIdentifier","hash",false)) root_ca.add_extension(ef.create_extension("authorityKeyIdentifier","keyid:always",false)) root_ca.sign(root_key, OpenSSL::Digest::SHA256.new)
The next step is to create the end-entity certificate using the root CA certificate.
key = OpenSSL::PKey::RSA.new 2048 cert = OpenSSL::X509::Certificate.new cert.version = 2 cert.serial = 2 cert.subject = OpenSSL::X509::Name.parse "/DC=org/DC=ruby-lang/CN=Ruby certificate" cert.issuer = root_ca.subject # root CA is the issuer cert.public_key = key.public_key cert.not_before = Time.now cert.not_after = cert.not_before + 1 * 365 * 24 * 60 * 60 # 1 years validity ef = OpenSSL::X509::ExtensionFactory.new ef.subject_certificate = cert ef.issuer_certificate = root_ca cert.add_extension(ef.create_extension("keyUsage","digitalSignature", true)) cert.add_extension(ef.create_extension("subjectKeyIdentifier","hash",false)) cert.sign(root_key, OpenSSL::Digest::SHA256.new)
The parent class for all primitive encodings. Attributes are the same as for ASN1Data
, with the addition of tagging
. Primitive
values can never be infinite length encodings, thus it is not possible to set the infinite_length
attribute for Primitive
and its sub-classes.
Primitive
sub-classes and their mapping to Ruby classes OpenSSL::ASN1::EndOfContent <=> value
is always nil
OpenSSL::ASN1::Boolean <=> value
is a Boolean
OpenSSL::ASN1::Integer
<=> value
is a Number
OpenSSL::ASN1::BitString <=> value
is a String
OpenSSL::ASN1::OctetString <=> value
is a String
OpenSSL::ASN1::Null <=> value
is always nil
OpenSSL::ASN1::Object
<=> value
is a String
OpenSSL::ASN1::Enumerated <=> value
is a Number
OpenSSL::ASN1::UTF8String <=> value
is a String
OpenSSL::ASN1::NumericString <=> value
is a String
OpenSSL::ASN1::PrintableString <=> value
is a String
OpenSSL::ASN1::T61String <=> value
is a String
OpenSSL::ASN1::VideotexString <=> value
is a String
OpenSSL::ASN1::IA5String <=> value
is a String
OpenSSL::ASN1::UTCTime <=> value
is a Time
OpenSSL::ASN1::GeneralizedTime <=> value
is a Time
OpenSSL::ASN1::GraphicString <=> value
is a String
OpenSSL::ASN1::ISO64String <=> value
is a String
OpenSSL::ASN1::GeneralString <=> value
is a String
OpenSSL::ASN1::UniversalString <=> value
is a String
OpenSSL::ASN1::BMPString <=> value
is a String
unused_bits
: if the underlying BIT STRING’s length is a multiple of 8 then unused_bits
is 0. Otherwise unused_bits
indicates the number of bits that are to be ignored in the final octet of the BitString
‘s value
.
OpenSSL::ASN1::ObjectId
NOTE: While OpenSSL::ASN1::ObjectId.new
will allocate a new ObjectId
, it is not typically allocated this way, but rather that are received from parsed ASN1
encodings.
While OpenSSL::ASN1::ObjectId.new
will allocate a new ObjectId
, it is not typically allocated this way, but rather that are received from parsed ASN1
encodings.
sn
: the short name as defined in <openssl/objects.h>.
ln
: the long name as defined in <openssl/objects.h>.
oid
: the object identifier as a String
, e.g. “1.2.3.4.5”
short_name
: alias for sn
.
long_name
: alias for ln
.
With the Exception
of OpenSSL::ASN1::EndOfContent, each Primitive
class constructor takes at least one parameter, the value
.
eoc = OpenSSL::ASN1::EndOfContent.new
Primitive
prim = <class>.new(value) # <class> being one of the sub-classes except EndOfContent prim_zero_tagged_implicit = <class>.new(value, 0, :IMPLICIT) prim_zero_tagged_explicit = <class>.new(value, 0, :EXPLICIT)
An OpenSSL::OCSP::Response
contains the status of a certificate check which is created from an OpenSSL::OCSP::Request
.
An OpenSSL::OCSP::BasicResponse
contains the status of a certificate check which is created from an OpenSSL::OCSP::Request
. A BasicResponse
is more detailed than a Response
.
An OpenSSL::OCSP::CertificateId
identifies a certificate to the CA so that a status check can be performed.