Represents a specification retrieved via the rubygems.org API.
This is used to avoid loading the full Specification object when all we need is the name, version, and dependencies.
Represents a possible Specification object returned from IndexSet. Used to delay needed to download full Specification objects when only the name
and version
are needed.
An InstalledSpecification
represents a gem that is already installed locally.
A LocalSpecification
comes from a .gem file on the local filesystem.
The LockSpecification
comes from a lockfile (Gem::RequestSet::Lockfile
).
A LockSpecification’s dependency information is pre-filled from the lockfile.
The Resolver::SpecSpecification contains common functionality for Resolver specifications that are backed by a Gem::Specification
.
A Resolver::Specification contains a subset of the information contained in a Gem::Specification
. Only the information necessary for dependency resolution in the resolver is included.
A VendorSpecification
represents a gem that has been unpacked into a project and is being loaded through a gem dependencies file through the path:
option.
Gem::Security
default exception type
An object representation of a stack frame, initialized by Kernel#caller_locations
.
For example:
# caller_locations.rb def a(skip) caller_locations(skip) end def b(skip) a(skip) end def c(skip) b(skip) end c(0..2).map do |call| puts call.to_s end
Running ruby caller_locations.rb
will produce:
caller_locations.rb:2:in `a' caller_locations.rb:5:in `b' caller_locations.rb:8:in `c'
Here’s another example with a slightly different result:
# foo.rb class Foo attr_accessor :locations def initialize(skip) @locations = caller_locations(skip) end end Foo.new(0..2).locations.map do |call| puts call.to_s end
Now run ruby foo.rb
and you should see:
init.rb:4:in `initialize' init.rb:8:in `new' init.rb:8:in `<main>'
class that Parses String’s into URI’s
It contains a Hash
set of patterns and Regexp’s that match and validate.
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 an OpenSSL::BN
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 an OpenSSL::BN
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.
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)
The parent class for all constructed encodings. The value
attribute of a Constructive
is always an Array
. Attributes are the same as for ASN1Data
, with the addition of tagging
.
Most constructed encodings come in the form of a SET or a SEQUENCE. These encodings are represented by one of the two sub-classes of Constructive:
OpenSSL::ASN1::Sequence
Please note that tagged sequences and sets are still parsed as instances of ASN1Data
. Find
further details on tagged values there.
int = OpenSSL::ASN1::Integer.new(1) str = OpenSSL::ASN1::PrintableString.new('abc') sequence = OpenSSL::ASN1::Sequence.new( [ int, str ] )
int = OpenSSL::ASN1::Integer.new(1) str = OpenSSL::ASN1::PrintableString.new('abc') set = OpenSSL::ASN1::Set.new( [ int, str ] )
The only case where Constructive
is used directly is for infinite length encodings of primitive values. These encodings are always constructed, with the contents of the value
Array
being either UNIVERSAL non-infinite length partial encodings of the actual value or again constructive encodings with infinite length (i.e. infinite length primitive encodings may be constructed recursively with another infinite length value within an already infinite length value). Each partial encoding must be of the same UNIVERSAL type as the overall encoding. The value of the overall encoding consists of the concatenation of each partial encoding taken in sequence. The value
array of the outer infinite length value must end with a OpenSSL::ASN1::EndOfContent instance.
Please note that it is not possible to encode Constructive
without the infinite_length
attribute being set to true
, use OpenSSL::ASN1::Sequence or OpenSSL::ASN1::Set
in these cases instead.
partial1 = OpenSSL::ASN1::OctetString.new("\x01") partial2 = OpenSSL::ASN1::OctetString.new("\x02") inf_octets = OpenSSL::ASN1::Constructive.new( [ partial1, partial2, OpenSSL::ASN1::EndOfContent.new ], OpenSSL::ASN1::OCTET_STRING, nil, :UNIVERSAL ) # The real value of inf_octets is "\x01\x02", i.e. the concatenation # of partial1 and partial2 inf_octets.infinite_length = true der = inf_octets.to_der asn1 = OpenSSL::ASN1.decode(der) puts asn1.infinite_length # => true
An OpenSSL::OCSP::CertificateId
identifies a certificate to the CA so that a status check can be performed.
Error
raised when a response from the server is non-parseable.
The Transitive
formatter writes an XML
document that parses to an identical document as the source document. This means that no extra whitespace nodes are inserted, and whitespace within text nodes is preserved. Within these constraints, the document is pretty-printed, with whitespace inserted into the metadata to introduce formatting.
Note that this is only useful if the original XML
is not already formatted. Since this formatter does not alter whitespace nodes, the results of formatting already formatted XML
will be odd.
You don’t want to use this class. Really. Use XPath
, which is a wrapper for this class. Believe me. You don’t want to poke around in here. There is strange, dark magic at work in this code. Beware. Go back! Go back while you still can!