-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no more pom.xml - as far as possible
Showing
385 changed files
with
62,262 additions
and
6,417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<extensions> | ||
<extension> | ||
<groupId>io.tesla.polyglot</groupId> | ||
<artifactId>tesla-polyglot-ruby</artifactId> | ||
<version>0.1.2-SNAPSHOT</version> | ||
<groupId>io.takari.polyglot</groupId> | ||
<artifactId>polyglot-ruby</artifactId> | ||
<version>0.1.3</version> | ||
</extension> | ||
</extensions> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
require 'rubygems' | ||
Gem.load_yaml | ||
require 'rdoc' | ||
require 'gauntlet' | ||
require 'fileutils' | ||
|
||
## | ||
# Allows for testing of RDoc against every gem | ||
|
||
class RDoc::Gauntlet < Gauntlet | ||
|
||
def initialize # :nodoc: | ||
super | ||
|
||
@args = nil | ||
@type = nil | ||
end | ||
|
||
## | ||
# Runs an RDoc generator for gem +name+ | ||
|
||
def run name | ||
return if self.data.key? name | ||
|
||
dir = File.expand_path "~/.gauntlet/data/#{@type}/#{name}" | ||
FileUtils.rm_rf dir if File.exist? dir | ||
|
||
yaml = File.read 'gemspec' | ||
begin | ||
spec = Gem::Specification.from_yaml yaml | ||
rescue Psych::SyntaxError | ||
puts "bad spec #{name}" | ||
self.data[name] = false | ||
return | ||
end | ||
|
||
args = @args.dup | ||
args << '--op' << dir | ||
args.concat spec.rdoc_options | ||
args << spec.require_paths | ||
args << spec.extra_rdoc_files | ||
args = args.flatten.map { |a| a.to_s } | ||
args.delete '--quiet' | ||
|
||
puts "#{name} - rdoc #{args.join ' '}" | ||
|
||
self.dirty = true | ||
r = RDoc::RDoc.new | ||
|
||
begin | ||
r.document args | ||
self.data[name] = true | ||
puts 'passed' | ||
FileUtils.rm_rf dir | ||
rescue Interrupt, StandardError, RDoc::Error, SystemStackError => e | ||
puts "failed - (#{e.class}) #{e.message}" | ||
self.data[name] = false | ||
end | ||
rescue Gem::Exception | ||
puts "bad gem #{name}" | ||
ensure | ||
puts | ||
end | ||
|
||
## | ||
# Runs the gauntlet with the given +type+ (rdoc or ri) and +filter+ for | ||
# which gems to run | ||
|
||
def run_the_gauntlet type = 'rdoc', filter = nil | ||
@type = type || 'rdoc' | ||
@args = type == 'rdoc' ? [] : %w[--ri] | ||
@data_file = "#{DATADIR}/#{@type}-data.yml" | ||
|
||
super filter | ||
end | ||
|
||
end | ||
|
||
type = ARGV.shift | ||
filter = ARGV.shift | ||
filter = /#{filter}/ if filter | ||
|
||
RDoc::Gauntlet.new.run_the_gauntlet type, filter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# Copyright (C) 2014 Christian Meier | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
# this software and associated documentation files (the "Software"), to deal in | ||
# the Software without restriction, including without limitation the rights to | ||
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
# the Software, and to permit persons to whom the Software is furnished to do so, | ||
# subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
# | ||
|
||
require 'jar_dependencies' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
# | ||
# Copyright (C) 2014 Christian Meier | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
# this software and associated documentation files (the "Software"), to deal in | ||
# the Software without restriction, including without limitation the rights to | ||
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
# the Software, and to permit persons to whom the Software is furnished to do so, | ||
# subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
# | ||
|
||
module Jars | ||
HOME = 'JARS_HOME'.freeze | ||
MAVEN_SETTINGS = 'JARS_MAVEN_SETTINGS'.freeze | ||
SKIP = 'JARS_SKIP'.freeze | ||
NO_REQUIRE = 'JARS_NO_REQUIRE'.freeze | ||
QUIET = 'JARS_QUIET'.freeze | ||
VERBOSE = 'JARS_VERBOSE'.freeze | ||
DEBUG = 'JARS_DEBUG'.freeze | ||
VENDOR = 'JARS_VENDOR'.freeze | ||
|
||
class << self | ||
|
||
if defined? JRUBY_VERSION | ||
def to_prop( key ) | ||
java.lang.System.getProperty( key.downcase.gsub( /_/, '.' ) ) || | ||
ENV[ key.upcase.gsub( /[.]/, '_' ) ] | ||
end | ||
else | ||
def to_prop( key ) | ||
ENV[ key.upcase.gsub( /[.]/, '_' ) ] | ||
end | ||
end | ||
|
||
def to_boolean( key ) | ||
prop = to_prop( key ) | ||
# prop == nil => false | ||
# prop == 'false' => false | ||
# anything else => true | ||
prop == '' or prop == 'true' | ||
end | ||
|
||
def skip? | ||
to_boolean( SKIP ) | ||
end | ||
|
||
def no_require? | ||
to_boolean( NO_REQUIRE ) | ||
end | ||
|
||
def quiet? | ||
to_boolean( QUIET ) | ||
end | ||
|
||
def verbose? | ||
to_boolean( VERBOSE ) | ||
end | ||
|
||
def debug? | ||
to_boolean( DEBUG ) | ||
end | ||
|
||
def vendor? | ||
to_boolean( VENDOR ) | ||
end | ||
|
||
def freeze_loading | ||
ENV[ NO_REQUIRE ] = 'true' | ||
end | ||
|
||
def reset | ||
instance_variables.each { |var| instance_variable_set(var, nil) } | ||
( @@jars ||= {} ).clear | ||
end | ||
|
||
def maven_user_settings | ||
if @_jars_maven_user_settings_.nil? | ||
if settings = absolute( to_prop( MAVEN_SETTINGS ) ) | ||
settings = File.expand_path(settings) | ||
unless File.exists?(settings) | ||
warn "configured ENV['#{MAVEN_SETTINGS}'] = '#{settings}' not found" unless quiet? | ||
settings = false | ||
end | ||
else # use maven default (user) settings | ||
settings = File.join( user_home, '.m2', 'settings.xml' ) | ||
settings = false unless File.exists?(settings) | ||
end | ||
@_jars_maven_user_settings_ = settings | ||
end | ||
@_jars_maven_user_settings_ || nil | ||
end | ||
alias maven_settings maven_user_settings | ||
|
||
def maven_global_settings | ||
if @_jars_maven_global_settings_.nil? | ||
if mvn_home = ENV[ 'M2_HOME' ] || ENV[ 'MAVEN_HOME' ] | ||
settings = File.join( mvn_home, 'conf/settings.xml' ) | ||
settings = false unless File.exists?(settings) | ||
else | ||
settings = false | ||
end | ||
@_jars_maven_global_settings_ = settings | ||
end | ||
@_jars_maven_global_settings_ || nil | ||
end | ||
|
||
def home | ||
if @_jars_home_.nil? | ||
unless @_jars_home_ = absolute( to_prop( HOME ) ) | ||
begin | ||
if user_settings = maven_user_settings | ||
@_jars_home_ = detect_local_repository(user_settings) | ||
end | ||
if ! @_jars_home_ && global_settings = maven_global_settings | ||
@_jars_home_ = detect_local_repository(global_settings) | ||
end | ||
rescue # ignore | ||
end | ||
end | ||
# use maven default repository | ||
@_jars_home_ ||= File.join( user_home, '.m2', 'repository' ) | ||
end | ||
@_jars_home_ | ||
end | ||
|
||
def require_jar( group_id, artifact_id, *classifier_version ) | ||
version = classifier_version[ -1 ] | ||
classifier = classifier_version[ -2 ] | ||
|
||
@@jars ||= {} | ||
coordinate = "#{group_id}:#{artifact_id}" | ||
coordinate += ":#{classifier}" if classifier | ||
if @@jars.key? coordinate | ||
if @@jars[ coordinate ] == version | ||
false | ||
else | ||
# version of already registered jar | ||
@@jars[ coordinate ] | ||
end | ||
else | ||
do_require( group_id, artifact_id, version, classifier ) | ||
@@jars[ coordinate ] = version | ||
return true | ||
end | ||
end | ||
|
||
private | ||
|
||
def absolute( file ) | ||
File.expand_path( file ) if file | ||
end | ||
|
||
def user_home | ||
ENV[ 'HOME' ] || begin | ||
user_home = Dir.home if Dir.respond_to?(:home) | ||
unless user_home | ||
user_home = ENV_JAVA[ 'user.home' ] if Object.const_defined?(:ENV_JAVA) | ||
end | ||
user_home | ||
end | ||
end | ||
|
||
def detect_local_repository(settings); require 'rexml/document' | ||
doc = REXML::Document.new( File.read( settings ) ) | ||
if local_repo = doc.root.elements['localRepository'] | ||
if ( local_repo = local_repo.first ) | ||
local_repo = local_repo.value | ||
local_repo = nil if local_repo.empty? | ||
end | ||
end | ||
local_repo | ||
end | ||
|
||
def to_jar( group_id, artifact_id, version, classifier ) | ||
file = "#{group_id.gsub( /\./, '/' )}/#{artifact_id}/#{version}/#{artifact_id}-#{version}" | ||
file << "-#{classifier}" if classifier | ||
file << '.jar' | ||
file | ||
end | ||
|
||
def do_require( *args ) | ||
jar = to_jar( *args ) | ||
file = File.join( home, jar ) | ||
# use jar from local repository if exists | ||
if File.exists?( file ) | ||
require file | ||
else | ||
# otherwise try to find it on the load path | ||
require jar | ||
end | ||
rescue LoadError => e | ||
raise "\n\n\tyou might need to reinstall the gem which depends on the missing jar\n\n" + e.message + " (LoadError)" | ||
end | ||
|
||
end # class << self | ||
|
||
end | ||
|
||
def require_jar( *args ) | ||
return false if Jars.no_require? | ||
result = Jars.require_jar( *args ) | ||
if result.is_a? String | ||
warn "jar coordinate #{args[0..-2].join( ':' )} already loaded with version #{result}" unless Jars.quiet? | ||
return false | ||
end | ||
result | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# | ||
# Copyright (C) 2014 Christian Meier | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
# this software and associated documentation files (the "Software"), to deal in | ||
# the Software without restriction, including without limitation the rights to | ||
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
# the Software, and to permit persons to whom the Software is furnished to do so, | ||
# subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
# | ||
|
||
if defined?( JRUBY_VERSION ) && Gem.post_install_hooks.empty? | ||
Gem.post_install do |gem_installer| | ||
unless (ENV['JARS_SKIP'] || ENV_JAVA['jars.skip']) == 'true' | ||
require 'jar_installer' | ||
jars = Jars::JarInstaller.new( gem_installer.spec ) | ||
jars.ruby_maven_install_options = gem_installer.options || {} | ||
jars.vendor_jars | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
require 'jar_dependencies' | ||
module Jars | ||
class JarInstaller | ||
|
||
class Dependency | ||
|
||
attr_reader :path, :file, :gav, :scope, :type, :coord | ||
|
||
def self.new( line ) | ||
if line.match /:jar:|:pom:/ | ||
super | ||
end | ||
end | ||
|
||
def setup_type( line ) | ||
if line.match /:pom:/ | ||
@type = :pom | ||
elsif line.match /:jar:/ | ||
@type = :jar | ||
end | ||
end | ||
private :setup_type | ||
|
||
def setup_scope( line ) | ||
@scope = | ||
case line | ||
when /:provided:/ | ||
:provided | ||
when /:test:/ | ||
:test | ||
else | ||
:runtime | ||
end | ||
end | ||
private :setup_scope | ||
|
||
def initialize( line ) | ||
setup_type( line ) | ||
|
||
line.sub!( /^\s+/, '' ) | ||
@coord = line.sub( /:[^:]+:[^:]+$/, '' ) | ||
first, second = line.sub( /:[^:]+:[^:]+$/, '' ).split( /:#{type}:/ ) | ||
group_id, artifact_id = first.split( /:/ ) | ||
parts = group_id.split( '.' ) | ||
parts << artifact_id | ||
parts << second.split( /:/ )[ -1 ] | ||
parts << File.basename( line.sub /.:/, '' ) | ||
@path = File.join( parts ).strip | ||
|
||
setup_scope( line ) | ||
|
||
line.gsub!( /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:/, ':' ) | ||
@file = line.sub( /^.*:/, '' ).strip | ||
@gav = line.sub( /:[^:]+$/, '' ) | ||
end | ||
end | ||
|
||
def self.install_jars( write_require_file = false ) | ||
new.install_jars( write_require_file ) | ||
end | ||
|
||
def self.vendor_jars( write_require_file = false ) | ||
new.vendor_jars( write_require_file ) | ||
end | ||
|
||
def self.load_from_maven( file ) | ||
result = [] | ||
File.read( file ).each_line do |line| | ||
dep = Dependency.new( line ) | ||
result << dep if dep | ||
end | ||
result | ||
end | ||
|
||
def self.write_require_file( require_filename ) | ||
FileUtils.mkdir_p( File.dirname( require_filename ) ) | ||
comment = '# this is a generated file, to avoid over-writing it just delete this comment' | ||
if ! File.exists?( require_filename ) || File.read( require_filename ).match( comment ) | ||
f = File.open( require_filename, 'w' ) | ||
f.puts comment | ||
f.puts "require 'jar_dependencies'" | ||
f.puts | ||
f | ||
end | ||
end | ||
|
||
def self.vendor_file( dir, dep ) | ||
vendored = File.join( dir, dep.path ) | ||
FileUtils.mkdir_p( File.dirname( vendored ) ) | ||
FileUtils.cp( dep.file, vendored ) | ||
end | ||
|
||
def self.install_deps( deps, dir, require_filename, vendor ) | ||
f = write_require_file( require_filename ) if require_filename | ||
deps.each do |dep| | ||
next if dep.type != :jar || dep.scope != :runtime | ||
args = dep.gav.gsub( /:/, "', '" ) | ||
vendor_file( dir, dep ) if vendor | ||
f.puts( "require_jar( '#{args}' )" ) if f | ||
end | ||
yield f if block_given? | ||
ensure | ||
f.close if f | ||
end | ||
|
||
def find_spec( allow_no_file ) | ||
specs = Dir[ '*.gemspec' ] | ||
case specs.size | ||
when 0 | ||
raise 'no gemspec found' unless allow_no_file | ||
when 1 | ||
specs.first | ||
else | ||
raise 'more then one gemspec found. please specify a specfile' unless allow_no_file | ||
end | ||
end | ||
private :find_spec | ||
|
||
def initialize( spec = nil ) | ||
setup( spec ) | ||
end | ||
|
||
def setup( spec = nil, allow_no_file = false ) | ||
spec ||= find_spec( allow_no_file ) | ||
|
||
case spec | ||
when String | ||
@specfile = File.expand_path( spec ) | ||
@basedir = File.dirname( @specfile ) | ||
spec = eval( File.read( spec ) ) | ||
when Gem::Specification | ||
if File.exists?( spec.spec_file ) | ||
@basedir = spec.gem_dir | ||
@specfile = spec.spec_file | ||
else | ||
# this happens with bundle and local gems | ||
# there the spec_file is "not installed" but inside | ||
# the gem_dir directory | ||
Dir.chdir( spec.gem_dir ) do | ||
setup( nil, true ) | ||
end | ||
end | ||
when NilClass | ||
else | ||
raise 'spec must be either String or Gem::Specification' | ||
end | ||
|
||
@spec = spec | ||
rescue | ||
# for all those strange gemspec we skip looking for jar-dependencies | ||
end | ||
|
||
def ruby_maven_install_options=( options ) | ||
@options = options.dup | ||
end | ||
|
||
def vendor_jars( write_require_file = true ) | ||
return unless has_jars? | ||
# do not vendor only if set explicitly via ENV/system-properties | ||
do_install( Jars.to_prop( Jars::VENDOR ) != 'false', write_require_file ) | ||
end | ||
|
||
def install_jars( write_require_file = true ) | ||
return unless has_jars? | ||
do_install( false, write_require_file ) | ||
end | ||
|
||
private | ||
|
||
def has_jars? | ||
# first look if there are any requirements in the spec | ||
# and then if gem depends on jar-dependencies | ||
# only then install the jars declared in the requirements | ||
! @spec.requirements.empty? && @spec.dependencies.detect { |d| d.name == 'jar-dependencies' && d.type == :runtime } | ||
end | ||
|
||
def do_install( vendor, write_require_file ) | ||
vendor_dir = File.join( @basedir, @spec.require_path ) | ||
jars_file = File.join( vendor_dir, "#{@spec.name}_jars.rb" ) | ||
|
||
# write out new jars_file it write_require_file is true or | ||
# check timestamps: | ||
# do not generate file if specfile is older then the generated file | ||
if ! write_require_file && | ||
File.exists?( jars_file ) && | ||
File.mtime( @specfile ) < File.mtime( jars_file ) | ||
# leave jars_file as is | ||
jars_file = nil | ||
end | ||
self.class.install_deps( install_dependencies, vendor_dir, | ||
jars_file, vendor ) | ||
end | ||
|
||
def setup_arguments( deps ) | ||
args = [ 'dependency:list', "-DoutputFile=#{deps}", '-DincludeScope=runtime', '-DoutputAbsoluteArtifactFilename=true', '-DincludeTypes=jar', '-DoutputScope=true', '-f', @specfile ] | ||
|
||
if Jars.debug? | ||
args << '-X' | ||
elsif not Jars.verbose? | ||
args << '--quiet' | ||
end | ||
|
||
if defined? JRUBY_VERSION | ||
args << "-Dmaven.repo.local=#{java.io.File.new( Jars.home ).absolute_path}" | ||
else | ||
args << "-Dmaven.repo.local=#{File.expand_path( Jars.home )}" | ||
end | ||
|
||
args | ||
end | ||
|
||
def lazy_load_maven | ||
require 'maven/ruby/maven' | ||
rescue LoadError | ||
install_ruby_maven | ||
require 'maven/ruby/maven' | ||
end | ||
|
||
def install_ruby_maven | ||
require 'rubygems/dependency_installer' | ||
jars = Gem.loaded_specs[ 'jar-dependencies' ] | ||
dep = jars.dependencies.detect { |d| d.name == 'ruby-maven' } | ||
req = dep.nil? ? Gem::Requirement.create( '>0' ) : dep.requirement | ||
inst = Gem::DependencyInstaller.new( @options || {} ) | ||
inst.install 'ruby-maven', req | ||
rescue => e | ||
warn e.backtrace.join( "\n" ) if Jars.verbose? | ||
raise "there was an error installing 'ruby-maven'. please install it manually: #{e.inspect}" | ||
end | ||
|
||
def monkey_path_gem_dependencies | ||
# monkey patch to NOT include gem dependencies | ||
require 'maven/tools/gemspec_dependencies' | ||
eval <<EOF | ||
class ::Maven::Tools::GemspecDependencies | ||
def runtime; []; end | ||
def development; []; end | ||
end | ||
EOF | ||
end | ||
|
||
def install_dependencies | ||
lazy_load_maven | ||
|
||
monkey_path_gem_dependencies | ||
|
||
deps = File.join( @basedir, 'deps.lst' ) | ||
|
||
maven = Maven::Ruby::Maven.new | ||
maven.verbose = Jars.verbose? | ||
maven.exec( *setup_arguments( deps ) ) | ||
|
||
self.class.load_from_maven( deps ) | ||
ensure | ||
FileUtils.rm_f( deps ) if deps | ||
end | ||
end | ||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
warn 'Loading jruby-openssl in a non-JRuby interpreter' unless defined? JRUBY_VERSION | ||
|
||
require 'java' | ||
require 'jopenssl/version' | ||
|
||
version = Jopenssl::Version::BOUNCY_CASTLE_VERSION | ||
bc_jars = nil | ||
begin | ||
# if we have jar-dependencies we let it track the jars | ||
require_jar( 'org.bouncycastle', 'bcpkix-jdk15on', version ) | ||
require_jar( 'org.bouncycastle', 'bcprov-jdk15on', version ) | ||
bc_jars = true | ||
rescue LoadError | ||
end if defined?(Jars) && ( ! Jars.skip? ) rescue nil | ||
unless bc_jars | ||
load "org/bouncycastle/bcpkix-jdk15on/#{version}/bcpkix-jdk15on-#{version}.jar" | ||
load "org/bouncycastle/bcprov-jdk15on/#{version}/bcprov-jdk15on-#{version}.jar" | ||
end | ||
|
||
require 'jruby' | ||
require 'jopenssl.jar' | ||
org.jruby.ext.openssl.OpenSSL.load(JRuby.runtime) | ||
|
||
if RUBY_VERSION >= '2.1.0' | ||
load('jopenssl21/openssl.rb') | ||
elsif RUBY_VERSION >= '1.9.0' | ||
load('jopenssl19/openssl.rb') | ||
else | ||
load('jopenssl18/openssl.rb') | ||
end | ||
|
||
require 'openssl/pkcs12' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Jopenssl | ||
module Version | ||
VERSION = '0.9.6' | ||
BOUNCY_CASTLE_VERSION = '1.49' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
=begin | ||
= $RCSfile$ -- Loader for all OpenSSL C-space and Ruby-space definitions | ||
= Info | ||
'OpenSSL for Ruby 2' project | ||
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
All rights reserved. | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id: openssl.rb 12496 2007-06-08 15:02:04Z technorama $ | ||
=end | ||
|
||
require 'openssl/bn' | ||
require 'openssl/cipher' | ||
require 'openssl/config' | ||
require 'openssl/digest' | ||
require 'openssl/pkcs7' | ||
require 'openssl/ssl-internal' | ||
require 'openssl/x509-internal' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
=begin | ||
= $RCSfile$ -- Ruby-space definitions that completes C-space funcs for BN | ||
= Info | ||
'OpenSSL for Ruby 2' project | ||
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
All rights reserved. | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id$ | ||
=end | ||
|
||
## | ||
# Add double dispatch to Integer | ||
# | ||
class Integer | ||
def to_bn | ||
OpenSSL::BN::new(self.to_s(16), 16) | ||
end | ||
end # Integer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
=begin | ||
= $RCSfile$ -- Buffering mix-in module. | ||
= Info | ||
'OpenSSL for Ruby 2' project | ||
Copyright (C) 2001 GOTOU YUUZOU <gotoyuzo@notwork.org> | ||
All rights reserved. | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id$ | ||
=end | ||
|
||
module OpenSSL | ||
module Buffering | ||
include Enumerable | ||
attr_accessor :sync | ||
BLOCK_SIZE = 1024*16 | ||
|
||
def initialize(*args) | ||
@eof = false | ||
@rbuffer = "" | ||
@sync = @io.sync | ||
end | ||
|
||
# | ||
# for reading. | ||
# | ||
private | ||
|
||
def fill_rbuff | ||
begin | ||
@rbuffer << self.sysread(BLOCK_SIZE) | ||
rescue Errno::EAGAIN | ||
retry | ||
rescue EOFError | ||
@eof = true | ||
end | ||
end | ||
|
||
def consume_rbuff(size=nil) | ||
if @rbuffer.empty? | ||
nil | ||
else | ||
size = @rbuffer.size unless size | ||
ret = @rbuffer[0, size] | ||
@rbuffer[0, size] = "" | ||
ret | ||
end | ||
end | ||
|
||
public | ||
|
||
def read(size=nil, buf=nil) | ||
if size == 0 | ||
if buf | ||
buf.clear | ||
else | ||
buf = "" | ||
end | ||
return @eof ? nil : buf | ||
end | ||
until @eof | ||
break if size && size <= @rbuffer.size | ||
fill_rbuff | ||
end | ||
ret = consume_rbuff(size) || "" | ||
if buf | ||
buf.replace(ret) | ||
ret = buf | ||
end | ||
(size && ret.empty?) ? nil : ret | ||
end | ||
|
||
def readpartial(maxlen, buf=nil) | ||
if maxlen == 0 | ||
if buf | ||
buf.clear | ||
else | ||
buf = "" | ||
end | ||
return @eof ? nil : buf | ||
end | ||
if @rbuffer.empty? | ||
begin | ||
return sysread(maxlen, buf) | ||
rescue Errno::EAGAIN | ||
retry | ||
end | ||
end | ||
ret = consume_rbuff(maxlen) | ||
if buf | ||
buf.replace(ret) | ||
ret = buf | ||
end | ||
raise EOFError if ret.empty? | ||
ret | ||
end | ||
|
||
def gets(eol=$/) | ||
idx = @rbuffer.index(eol) | ||
until @eof | ||
break if idx | ||
fill_rbuff | ||
idx = @rbuffer.index(eol) | ||
end | ||
if eol.is_a?(Regexp) | ||
size = idx ? idx+$&.size : nil | ||
else | ||
size = idx ? idx+eol.size : nil | ||
end | ||
consume_rbuff(size) | ||
end | ||
|
||
def each(eol=$/) | ||
while line = self.gets(eol) | ||
yield line | ||
end | ||
end | ||
alias each_line each | ||
|
||
def readlines(eol=$/) | ||
ary = [] | ||
while line = self.gets(eol) | ||
ary << line | ||
end | ||
ary | ||
end | ||
|
||
def readline(eol=$/) | ||
raise EOFError if eof? | ||
gets(eol) | ||
end | ||
|
||
def getc | ||
c = read(1) | ||
c ? c[0] : nil | ||
end | ||
|
||
def each_byte | ||
while c = getc | ||
yield(c) | ||
end | ||
end | ||
|
||
def readchar | ||
raise EOFError if eof? | ||
getc | ||
end | ||
|
||
def ungetc(c) | ||
@rbuffer[0,0] = c.chr | ||
end | ||
|
||
def eof? | ||
fill_rbuff if !@eof && @rbuffer.empty? | ||
@eof && @rbuffer.empty? | ||
end | ||
alias eof eof? | ||
|
||
# | ||
# for writing. | ||
# | ||
private | ||
|
||
def do_write(s) | ||
@wbuffer = "" unless defined? @wbuffer | ||
@wbuffer << s | ||
@sync ||= false | ||
if @sync or @wbuffer.size > BLOCK_SIZE or idx = @wbuffer.rindex($/) | ||
remain = idx ? idx + $/.size : @wbuffer.length | ||
nwritten = 0 | ||
while remain > 0 | ||
str = @wbuffer[nwritten,remain] | ||
begin | ||
nwrote = syswrite(str) | ||
rescue Errno::EAGAIN | ||
retry | ||
end | ||
remain -= nwrote | ||
nwritten += nwrote | ||
end | ||
@wbuffer[0,nwritten] = "" | ||
end | ||
end | ||
|
||
public | ||
|
||
def write(s) | ||
do_write(s) | ||
s.length | ||
end | ||
|
||
def << (s) | ||
do_write(s) | ||
self | ||
end | ||
|
||
def puts(*args) | ||
s = "" | ||
if args.empty? | ||
s << "\n" | ||
end | ||
args.each{|arg| | ||
s << arg.to_s | ||
if $/ && /\n\z/ !~ s | ||
s << "\n" | ||
end | ||
} | ||
do_write(s) | ||
nil | ||
end | ||
|
||
def print(*args) | ||
s = "" | ||
args.each{ |arg| s << arg.to_s } | ||
do_write(s) | ||
nil | ||
end | ||
|
||
def printf(s, *args) | ||
do_write(s % args) | ||
nil | ||
end | ||
|
||
def flush | ||
osync = @sync | ||
@sync = true | ||
do_write "" | ||
@sync = osync | ||
end | ||
|
||
def close | ||
flush rescue nil | ||
sysclose | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
=begin | ||
= $RCSfile$ -- Ruby-space predefined Cipher subclasses | ||
= Info | ||
'OpenSSL for Ruby 2' project | ||
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
All rights reserved. | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id$ | ||
=end | ||
|
||
## | ||
# Should we care what if somebody require this file directly? | ||
#require 'openssl' | ||
|
||
module OpenSSL | ||
class Cipher | ||
# This class is only provided for backwards compatibility. Use OpenSSL::Digest in the future. | ||
class Cipher < Cipher | ||
# add warning | ||
end | ||
end # Cipher | ||
end # OpenSSL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,316 @@ | ||
=begin | ||
= Ruby-space definitions that completes C-space funcs for Config | ||
= Info | ||
Copyright (C) 2010 Hiroshi Nakamura <nahi@ruby-lang.org> | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
=end | ||
|
||
## | ||
# Should we care what if somebody require this file directly? | ||
#require 'openssl' | ||
require 'stringio' | ||
|
||
module OpenSSL | ||
class Config | ||
include Enumerable | ||
|
||
class << self | ||
def parse(str) | ||
c = new() | ||
parse_config(StringIO.new(str)).each do |section, hash| | ||
c[section] = hash | ||
end | ||
c | ||
end | ||
|
||
alias load new | ||
|
||
def parse_config(io) | ||
begin | ||
parse_config_lines(io) | ||
rescue ConfigError => e | ||
e.message.replace("error in line #{io.lineno}: " + e.message) | ||
raise | ||
end | ||
end | ||
|
||
def get_key_string(data, section, key) # :nodoc: | ||
if v = data[section] && data[section][key] | ||
return v | ||
elsif section == 'ENV' | ||
if v = ENV[key] | ||
return v | ||
end | ||
end | ||
if v = data['default'] && data['default'][key] | ||
return v | ||
end | ||
end | ||
|
||
private | ||
|
||
def parse_config_lines(io) | ||
section = 'default' | ||
data = {section => {}} | ||
while definition = get_definition(io) | ||
definition = clear_comments(definition) | ||
next if definition.empty? | ||
if definition[0] == ?[ | ||
if /\[([^\]]*)\]/ =~ definition | ||
section = $1.strip | ||
data[section] ||= {} | ||
else | ||
raise ConfigError, "missing close square bracket" | ||
end | ||
else | ||
if /\A([^:\s]*)(?:::([^:\s]*))?\s*=(.*)\z/ =~ definition | ||
if $2 | ||
section = $1 | ||
key = $2 | ||
else | ||
key = $1 | ||
end | ||
value = unescape_value(data, section, $3) | ||
(data[section] ||= {})[key] = value.strip | ||
else | ||
raise ConfigError, "missing equal sign" | ||
end | ||
end | ||
end | ||
data | ||
end | ||
|
||
# escape with backslash | ||
QUOTE_REGEXP_SQ = /\A([^'\\]*(?:\\.[^'\\]*)*)'/ | ||
# escape with backslash and doubled dq | ||
QUOTE_REGEXP_DQ = /\A([^"\\]*(?:""[^"\\]*|\\.[^"\\]*)*)"/ | ||
# escaped char map | ||
ESCAPE_MAP = { | ||
"r" => "\r", | ||
"n" => "\n", | ||
"b" => "\b", | ||
"t" => "\t", | ||
} | ||
|
||
def unescape_value(data, section, value) | ||
scanned = [] | ||
while m = value.match(/['"\\$]/) | ||
scanned << m.pre_match | ||
c = m[0] | ||
value = m.post_match | ||
case c | ||
when "'" | ||
if m = value.match(QUOTE_REGEXP_SQ) | ||
scanned << m[1].gsub(/\\(.)/, '\\1') | ||
value = m.post_match | ||
else | ||
break | ||
end | ||
when '"' | ||
if m = value.match(QUOTE_REGEXP_DQ) | ||
scanned << m[1].gsub(/""/, '').gsub(/\\(.)/, '\\1') | ||
value = m.post_match | ||
else | ||
break | ||
end | ||
when "\\" | ||
c = value.slice!(0, 1) | ||
scanned << (ESCAPE_MAP[c] || c) | ||
when "$" | ||
ref, value = extract_reference(value) | ||
refsec = section | ||
if ref.index('::') | ||
refsec, ref = ref.split('::', 2) | ||
end | ||
if v = get_key_string(data, refsec, ref) | ||
scanned << v | ||
else | ||
raise ConfigError, "variable has no value" | ||
end | ||
else | ||
raise 'must not reaced' | ||
end | ||
end | ||
scanned << value | ||
scanned.join | ||
end | ||
|
||
def extract_reference(value) | ||
rest = '' | ||
if m = value.match(/\(([^)]*)\)|\{([^}]*)\}/) | ||
value = m[1] || m[2] | ||
rest = m.post_match | ||
elsif [?(, ?{].include?(value[0]) | ||
raise ConfigError, "no close brace" | ||
end | ||
if m = value.match(/[a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]*)?/) | ||
return m[0], m.post_match + rest | ||
else | ||
raise | ||
end | ||
end | ||
|
||
def clear_comments(line) | ||
# FCOMMENT | ||
if m = line.match(/\A([\t\n\f ]*);.*\z/) | ||
return m[1] | ||
end | ||
# COMMENT | ||
scanned = [] | ||
while m = line.match(/[#'"\\]/) | ||
scanned << m.pre_match | ||
c = m[0] | ||
line = m.post_match | ||
case c | ||
when '#' | ||
line = nil | ||
break | ||
when "'", '"' | ||
regexp = (c == "'") ? QUOTE_REGEXP_SQ : QUOTE_REGEXP_DQ | ||
scanned << c | ||
if m = line.match(regexp) | ||
scanned << m[0] | ||
line = m.post_match | ||
else | ||
scanned << line | ||
line = nil | ||
break | ||
end | ||
when "\\" | ||
scanned << c | ||
scanned << line.slice!(0, 1) | ||
else | ||
raise 'must not reaced' | ||
end | ||
end | ||
scanned << line | ||
scanned.join | ||
end | ||
|
||
def get_definition(io) | ||
if line = get_line(io) | ||
while /[^\\]\\\z/ =~ line | ||
if extra = get_line(io) | ||
line += extra | ||
else | ||
break | ||
end | ||
end | ||
return line.strip | ||
end | ||
end | ||
|
||
def get_line(io) | ||
if line = io.gets | ||
line.gsub(/[\r\n]*/, '') | ||
end | ||
end | ||
end | ||
|
||
def initialize(filename = nil) | ||
@data = {} | ||
if filename | ||
File.open(filename.to_s) do |file| | ||
Config.parse_config(file).each do |section, hash| | ||
self[section] = hash | ||
end | ||
end | ||
end | ||
end | ||
|
||
def get_value(section, key) | ||
if section.nil? | ||
raise TypeError.new('nil not allowed') | ||
end | ||
section = 'default' if section.empty? | ||
get_key_string(section, key) | ||
end | ||
|
||
def value(arg1, arg2 = nil) | ||
warn('Config#value is deprecated; use Config#get_value') | ||
if arg2.nil? | ||
section, key = 'default', arg1 | ||
else | ||
section, key = arg1, arg2 | ||
end | ||
section ||= 'default' | ||
section = 'default' if section.empty? | ||
get_key_string(section, key) | ||
end | ||
|
||
def add_value(section, key, value) | ||
check_modify | ||
(@data[section] ||= {})[key] = value | ||
end | ||
|
||
def [](section) | ||
@data[section] || {} | ||
end | ||
|
||
def section(name) | ||
warn('Config#section is deprecated; use Config#[]') | ||
@data[name] || {} | ||
end | ||
|
||
def []=(section, pairs) | ||
check_modify | ||
@data[section] ||= {} | ||
pairs.each do |key, value| | ||
self.add_value(section, key, value) | ||
end | ||
end | ||
|
||
def sections | ||
@data.keys | ||
end | ||
|
||
def to_s | ||
ary = [] | ||
@data.keys.sort.each do |section| | ||
ary << "[ #{section} ]\n" | ||
@data[section].keys.each do |key| | ||
ary << "#{key}=#{@data[section][key]}\n" | ||
end | ||
ary << "\n" | ||
end | ||
ary.join | ||
end | ||
|
||
def each | ||
@data.each do |section, hash| | ||
hash.each do |key, value| | ||
yield(section, key, value) | ||
end | ||
end | ||
end | ||
|
||
def inspect | ||
"#<#{self.class.name} sections=#{sections.inspect}>" | ||
end | ||
|
||
protected | ||
|
||
def data | ||
@data | ||
end | ||
|
||
private | ||
|
||
def initialize_copy(other) | ||
@data = other.data.dup | ||
end | ||
|
||
def check_modify | ||
raise TypeError.new("Insecure: can't modify OpenSSL config") if frozen? | ||
end | ||
|
||
def get_key_string(section, key) | ||
Config.get_key_string(@data, section, key) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
=begin | ||
= $RCSfile$ -- Ruby-space predefined Digest subclasses | ||
= Info | ||
'OpenSSL for Ruby 2' project | ||
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
All rights reserved. | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id$ | ||
=end | ||
|
||
## | ||
# Should we care what if somebody require this file directly? | ||
#require 'openssl' | ||
|
||
module OpenSSL | ||
class Digest | ||
# This class is only provided for backwards compatibility. Use OpenSSL::Digest in the future. | ||
class Digest < Digest | ||
def initialize(*args) | ||
# add warning | ||
super(*args) | ||
end | ||
end | ||
end # Digest | ||
end # OpenSSL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
=begin | ||
= $RCSfile$ -- PKCS7 | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id: digest.rb 12148 2007-04-05 05:59:22Z technorama $ | ||
=end | ||
|
||
module OpenSSL | ||
class PKCS7 | ||
# This class is only provided for backwards compatibility. Use OpenSSL::PKCS7 in the future. | ||
class PKCS7 < PKCS7 | ||
def initialize(*args) | ||
super(*args) | ||
|
||
warn("Warning: OpenSSL::PKCS7::PKCS7 is deprecated after Ruby 1.9; use OpenSSL::PKCS7 instead") | ||
end | ||
end | ||
|
||
end # PKCS7 | ||
end # OpenSSL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
=begin | ||
= $RCSfile$ -- Ruby-space definitions that completes C-space funcs for SSL | ||
= Info | ||
'OpenSSL for Ruby 2' project | ||
Copyright (C) 2001 GOTOU YUUZOU <gotoyuzo@notwork.org> | ||
All rights reserved. | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id$ | ||
=end | ||
|
||
require "openssl/buffering" | ||
require "fcntl" | ||
|
||
module OpenSSL | ||
module SSL | ||
module SocketForwarder | ||
def addr | ||
to_io.addr | ||
end | ||
|
||
def peeraddr | ||
to_io.peeraddr | ||
end | ||
|
||
def setsockopt(level, optname, optval) | ||
to_io.setsockopt(level, optname, optval) | ||
end | ||
|
||
def getsockopt(level, optname) | ||
to_io.getsockopt(level, optname) | ||
end | ||
|
||
def fcntl(*args) | ||
to_io.fcntl(*args) | ||
end | ||
|
||
def closed? | ||
to_io.closed? | ||
end | ||
|
||
def do_not_reverse_lookup=(flag) | ||
to_io.do_not_reverse_lookup = flag | ||
end | ||
end | ||
|
||
module Nonblock | ||
def initialize(*args) | ||
flag = File::NONBLOCK | ||
flag |= @io.fcntl(Fcntl::F_GETFL) if defined?(Fcntl::F_GETFL) | ||
@io.fcntl(Fcntl::F_SETFL, flag) | ||
super | ||
end | ||
end | ||
|
||
def verify_certificate_identity(cert, hostname) | ||
should_verify_common_name = true | ||
cert.extensions.each{|ext| | ||
next if ext.oid != "subjectAltName" | ||
ext.value.split(/,\s+/).each{|general_name| | ||
if /\ADNS:(.*)/ =~ general_name | ||
should_verify_common_name = false | ||
reg = Regexp.escape($1).gsub(/\\\*/, "[^.]+") | ||
return true if /\A#{reg}\z/i =~ hostname | ||
# NOTE: somehow we need the IP: canonical form | ||
# seems there were failures elsewhere when not | ||
# not sure how that's possible possible to-do! | ||
elsif /\AIP(?: Address)?:(.*)/ =~ general_name | ||
#elsif /\AIP Address:(.*)/ =~ general_name | ||
should_verify_common_name = false | ||
return true if $1 == hostname | ||
end | ||
} | ||
} | ||
if should_verify_common_name | ||
cert.subject.to_a.each{|oid, value| | ||
if oid == "CN" | ||
reg = Regexp.escape(value).gsub(/\\\*/, "[^.]+") | ||
return true if /\A#{reg}\z/i =~ hostname | ||
end | ||
} | ||
end | ||
return false | ||
end | ||
module_function :verify_certificate_identity | ||
|
||
class SSLSocket | ||
include Buffering | ||
include SocketForwarder | ||
include Nonblock | ||
|
||
def post_connection_check(hostname) | ||
unless OpenSSL::SSL.verify_certificate_identity(peer_cert, hostname) | ||
raise SSLError, "hostname was not match with the server certificate" | ||
end | ||
return true | ||
end | ||
|
||
def session | ||
SSL::Session.new(self) | ||
rescue SSL::Session::SessionError | ||
nil | ||
end | ||
end | ||
|
||
class SSLServer | ||
include SocketForwarder | ||
attr_accessor :start_immediately | ||
|
||
def initialize(svr, ctx) | ||
@svr = svr | ||
@ctx = ctx | ||
unless ctx.session_id_context | ||
session_id = OpenSSL::Digest::MD5.hexdigest($0) | ||
@ctx.session_id_context = session_id | ||
end | ||
@start_immediately = true | ||
end | ||
|
||
def to_io | ||
@svr | ||
end | ||
|
||
def listen(backlog=5) | ||
@svr.listen(backlog) | ||
end | ||
|
||
def shutdown(how=Socket::SHUT_RDWR) | ||
@svr.shutdown(how) | ||
end | ||
|
||
def accept | ||
sock = @svr.accept | ||
begin | ||
ssl = OpenSSL::SSL::SSLSocket.new(sock, @ctx) | ||
ssl.sync_close = true | ||
ssl.accept if @start_immediately | ||
ssl | ||
rescue SSLError => ex | ||
sock.close | ||
raise ex | ||
end | ||
end | ||
|
||
def close | ||
@svr.close | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'openssl' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
=begin | ||
= $RCSfile$ -- Ruby-space definitions that completes C-space funcs for X509 and subclasses | ||
= Info | ||
'OpenSSL for Ruby 2' project | ||
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
All rights reserved. | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id$ | ||
=end | ||
|
||
module OpenSSL | ||
module X509 | ||
class Name | ||
module RFC2253DN | ||
Special = ',=+<>#;' | ||
HexChar = /[0-9a-fA-F]/ | ||
HexPair = /#{HexChar}#{HexChar}/ | ||
HexString = /#{HexPair}+/ | ||
Pair = /\\(?:[#{Special}]|\\|"|#{HexPair})/ | ||
StringChar = /[^#{Special}\\"]/ | ||
QuoteChar = /[^\\"]/ | ||
AttributeType = /[a-zA-Z][0-9a-zA-Z]*|[0-9]+(?:\.[0-9]+)*/ | ||
AttributeValue = / | ||
(?!["#])((?:#{StringChar}|#{Pair})*)| | ||
\#(#{HexString})| | ||
"((?:#{QuoteChar}|#{Pair})*)" | ||
/x | ||
TypeAndValue = /\A(#{AttributeType})=#{AttributeValue}/ | ||
|
||
module_function | ||
|
||
def expand_pair(str) | ||
return nil unless str | ||
return str.gsub(Pair){ | ||
pair = $& | ||
case pair.size | ||
when 2 then pair[1,1] | ||
when 3 then Integer("0x#{pair[1,2]}").chr | ||
else raise OpenSSL::X509::NameError, "invalid pair: #{str}" | ||
end | ||
} | ||
end | ||
|
||
def expand_hexstring(str) | ||
return nil unless str | ||
der = str.gsub(HexPair){$&.to_i(16).chr } | ||
a1 = OpenSSL::ASN1.decode(der) | ||
return a1.value, a1.tag | ||
end | ||
|
||
def expand_value(str1, str2, str3) | ||
value = expand_pair(str1) | ||
value, tag = expand_hexstring(str2) unless value | ||
value = expand_pair(str3) unless value | ||
return value, tag | ||
end | ||
|
||
def scan(dn) | ||
str = dn | ||
ary = [] | ||
while true | ||
if md = TypeAndValue.match(str) | ||
matched = md.to_s | ||
remain = md.post_match | ||
type = md[1] | ||
value, tag = expand_value(md[2], md[3], md[4]) rescue nil | ||
if value | ||
type_and_value = [type, value] | ||
type_and_value.push(tag) if tag | ||
ary.unshift(type_and_value) | ||
if remain.length > 2 && remain[0] == ?, | ||
str = remain[1..-1] | ||
next | ||
elsif remain.length > 2 && remain[0] == ?+ | ||
raise OpenSSL::X509::NameError, | ||
"multi-valued RDN is not supported: #{dn}" | ||
elsif remain.empty? | ||
break | ||
end | ||
end | ||
end | ||
msg_dn = dn[0, dn.length - str.length] + " =>" + str | ||
raise OpenSSL::X509::NameError, "malformed RDN: #{msg_dn}" | ||
end | ||
return ary | ||
end | ||
end | ||
|
||
class <<self | ||
def parse_rfc2253(str, template=OBJECT_TYPE_TEMPLATE) | ||
ary = OpenSSL::X509::Name::RFC2253DN.scan(str) | ||
self.new(ary, template) | ||
end | ||
|
||
def parse_openssl(str, template=OBJECT_TYPE_TEMPLATE) | ||
ary = str.scan(/\s*([^\/,]+)\s*/).collect{|i| i[0].split("=", 2) } | ||
self.new(ary, template) | ||
end | ||
|
||
alias parse parse_openssl | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'openssl' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
=begin | ||
= $RCSfile$ -- Loader for all OpenSSL C-space and Ruby-space definitions | ||
= Info | ||
'OpenSSL for Ruby 2' project | ||
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
All rights reserved. | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id$ | ||
=end | ||
|
||
require 'openssl/bn' | ||
require 'openssl/cipher' | ||
require 'openssl/config' | ||
require 'openssl/digest' | ||
require 'openssl/ssl-internal' | ||
require 'openssl/x509-internal' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#-- | ||
# | ||
# $RCSfile$ | ||
# | ||
# = Ruby-space definitions that completes C-space funcs for BN | ||
# | ||
# = Info | ||
# 'OpenSSL for Ruby 2' project | ||
# Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
# All rights reserved. | ||
# | ||
# = Licence | ||
# This program is licenced under the same licence as Ruby. | ||
# (See the file 'LICENCE'.) | ||
# | ||
# = Version | ||
# $Id$ | ||
# | ||
#++ | ||
|
||
## | ||
# Add double dispatch to Integer | ||
# | ||
class Integer | ||
def to_bn | ||
OpenSSL::BN::new(self) | ||
end | ||
end # Integer | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#-- | ||
# | ||
# $RCSfile$ | ||
# | ||
# = Ruby-space predefined Cipher subclasses | ||
# | ||
# = Info | ||
# 'OpenSSL for Ruby 2' project | ||
# Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
# All rights reserved. | ||
# | ||
# = Licence | ||
# This program is licenced under the same licence as Ruby. | ||
# (See the file 'LICENCE'.) | ||
# | ||
# = Version | ||
# $Id$ | ||
# | ||
#++ | ||
|
||
module OpenSSL | ||
class Cipher | ||
# This class is only provided for backwards compatibility. Use OpenSSL::Cipher in the future. | ||
class Cipher < Cipher | ||
# add warning | ||
end | ||
end # Cipher | ||
end # OpenSSL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,313 @@ | ||
=begin | ||
= Ruby-space definitions that completes C-space funcs for Config | ||
= Info | ||
Copyright (C) 2010 Hiroshi Nakamura <nahi@ruby-lang.org> | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
=end | ||
|
||
require 'stringio' | ||
|
||
module OpenSSL | ||
class Config | ||
include Enumerable | ||
|
||
class << self | ||
def parse(str) | ||
c = new() | ||
parse_config(StringIO.new(str)).each do |section, hash| | ||
c[section] = hash | ||
end | ||
c | ||
end | ||
|
||
alias load new | ||
|
||
def parse_config(io) | ||
begin | ||
parse_config_lines(io) | ||
rescue ConfigError => e | ||
e.message.replace("error in line #{io.lineno}: " + e.message) | ||
raise | ||
end | ||
end | ||
|
||
def get_key_string(data, section, key) # :nodoc: | ||
if v = data[section] && data[section][key] | ||
return v | ||
elsif section == 'ENV' | ||
if v = ENV[key] | ||
return v | ||
end | ||
end | ||
if v = data['default'] && data['default'][key] | ||
return v | ||
end | ||
end | ||
|
||
private | ||
|
||
def parse_config_lines(io) | ||
section = 'default' | ||
data = {section => {}} | ||
while definition = get_definition(io) | ||
definition = clear_comments(definition) | ||
next if definition.empty? | ||
if definition[0] == ?[ | ||
if /\[([^\]]*)\]/ =~ definition | ||
section = $1.strip | ||
data[section] ||= {} | ||
else | ||
raise ConfigError, "missing close square bracket" | ||
end | ||
else | ||
if /\A([^:\s]*)(?:::([^:\s]*))?\s*=(.*)\z/ =~ definition | ||
if $2 | ||
section = $1 | ||
key = $2 | ||
else | ||
key = $1 | ||
end | ||
value = unescape_value(data, section, $3) | ||
(data[section] ||= {})[key] = value.strip | ||
else | ||
raise ConfigError, "missing equal sign" | ||
end | ||
end | ||
end | ||
data | ||
end | ||
|
||
# escape with backslash | ||
QUOTE_REGEXP_SQ = /\A([^'\\]*(?:\\.[^'\\]*)*)'/ | ||
# escape with backslash and doubled dq | ||
QUOTE_REGEXP_DQ = /\A([^"\\]*(?:""[^"\\]*|\\.[^"\\]*)*)"/ | ||
# escaped char map | ||
ESCAPE_MAP = { | ||
"r" => "\r", | ||
"n" => "\n", | ||
"b" => "\b", | ||
"t" => "\t", | ||
} | ||
|
||
def unescape_value(data, section, value) | ||
scanned = [] | ||
while m = value.match(/['"\\$]/) | ||
scanned << m.pre_match | ||
c = m[0] | ||
value = m.post_match | ||
case c | ||
when "'" | ||
if m = value.match(QUOTE_REGEXP_SQ) | ||
scanned << m[1].gsub(/\\(.)/, '\\1') | ||
value = m.post_match | ||
else | ||
break | ||
end | ||
when '"' | ||
if m = value.match(QUOTE_REGEXP_DQ) | ||
scanned << m[1].gsub(/""/, '').gsub(/\\(.)/, '\\1') | ||
value = m.post_match | ||
else | ||
break | ||
end | ||
when "\\" | ||
c = value.slice!(0, 1) | ||
scanned << (ESCAPE_MAP[c] || c) | ||
when "$" | ||
ref, value = extract_reference(value) | ||
refsec = section | ||
if ref.index('::') | ||
refsec, ref = ref.split('::', 2) | ||
end | ||
if v = get_key_string(data, refsec, ref) | ||
scanned << v | ||
else | ||
raise ConfigError, "variable has no value" | ||
end | ||
else | ||
raise 'must not reaced' | ||
end | ||
end | ||
scanned << value | ||
scanned.join | ||
end | ||
|
||
def extract_reference(value) | ||
rest = '' | ||
if m = value.match(/\(([^)]*)\)|\{([^}]*)\}/) | ||
value = m[1] || m[2] | ||
rest = m.post_match | ||
elsif [?(, ?{].include?(value[0]) | ||
raise ConfigError, "no close brace" | ||
end | ||
if m = value.match(/[a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]*)?/) | ||
return m[0], m.post_match + rest | ||
else | ||
raise | ||
end | ||
end | ||
|
||
def clear_comments(line) | ||
# FCOMMENT | ||
if m = line.match(/\A([\t\n\f ]*);.*\z/) | ||
return m[1] | ||
end | ||
# COMMENT | ||
scanned = [] | ||
while m = line.match(/[#'"\\]/) | ||
scanned << m.pre_match | ||
c = m[0] | ||
line = m.post_match | ||
case c | ||
when '#' | ||
line = nil | ||
break | ||
when "'", '"' | ||
regexp = (c == "'") ? QUOTE_REGEXP_SQ : QUOTE_REGEXP_DQ | ||
scanned << c | ||
if m = line.match(regexp) | ||
scanned << m[0] | ||
line = m.post_match | ||
else | ||
scanned << line | ||
line = nil | ||
break | ||
end | ||
when "\\" | ||
scanned << c | ||
scanned << line.slice!(0, 1) | ||
else | ||
raise 'must not reaced' | ||
end | ||
end | ||
scanned << line | ||
scanned.join | ||
end | ||
|
||
def get_definition(io) | ||
if line = get_line(io) | ||
while /[^\\]\\\z/ =~ line | ||
if extra = get_line(io) | ||
line += extra | ||
else | ||
break | ||
end | ||
end | ||
return line.strip | ||
end | ||
end | ||
|
||
def get_line(io) | ||
if line = io.gets | ||
line.gsub(/[\r\n]*/, '') | ||
end | ||
end | ||
end | ||
|
||
def initialize(filename = nil) | ||
@data = {} | ||
if filename | ||
File.open(filename.to_s) do |file| | ||
Config.parse_config(file).each do |section, hash| | ||
self[section] = hash | ||
end | ||
end | ||
end | ||
end | ||
|
||
def get_value(section, key) | ||
if section.nil? | ||
raise TypeError.new('nil not allowed') | ||
end | ||
section = 'default' if section.empty? | ||
get_key_string(section, key) | ||
end | ||
|
||
def value(arg1, arg2 = nil) | ||
warn('Config#value is deprecated; use Config#get_value') | ||
if arg2.nil? | ||
section, key = 'default', arg1 | ||
else | ||
section, key = arg1, arg2 | ||
end | ||
section ||= 'default' | ||
section = 'default' if section.empty? | ||
get_key_string(section, key) | ||
end | ||
|
||
def add_value(section, key, value) | ||
check_modify | ||
(@data[section] ||= {})[key] = value | ||
end | ||
|
||
def [](section) | ||
@data[section] || {} | ||
end | ||
|
||
def section(name) | ||
warn('Config#section is deprecated; use Config#[]') | ||
@data[name] || {} | ||
end | ||
|
||
def []=(section, pairs) | ||
check_modify | ||
@data[section] ||= {} | ||
pairs.each do |key, value| | ||
self.add_value(section, key, value) | ||
end | ||
end | ||
|
||
def sections | ||
@data.keys | ||
end | ||
|
||
def to_s | ||
ary = [] | ||
@data.keys.sort.each do |section| | ||
ary << "[ #{section} ]\n" | ||
@data[section].keys.each do |key| | ||
ary << "#{key}=#{@data[section][key]}\n" | ||
end | ||
ary << "\n" | ||
end | ||
ary.join | ||
end | ||
|
||
def each | ||
@data.each do |section, hash| | ||
hash.each do |key, value| | ||
yield [section, key, value] | ||
end | ||
end | ||
end | ||
|
||
def inspect | ||
"#<#{self.class.name} sections=#{sections.inspect}>" | ||
end | ||
|
||
protected | ||
|
||
def data | ||
@data | ||
end | ||
|
||
private | ||
|
||
def initialize_copy(other) | ||
@data = other.data.dup | ||
end | ||
|
||
def check_modify | ||
raise TypeError.new("Insecure: can't modify OpenSSL config") if frozen? | ||
end | ||
|
||
def get_key_string(section, key) | ||
Config.get_key_string(@data, section, key) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#-- | ||
# | ||
# $RCSfile$ | ||
# | ||
# = Ruby-space predefined Digest subclasses | ||
# | ||
# = Info | ||
# 'OpenSSL for Ruby 2' project | ||
# Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
# All rights reserved. | ||
# | ||
# = Licence | ||
# This program is licenced under the same licence as Ruby. | ||
# (See the file 'LICENCE'.) | ||
# | ||
# = Version | ||
# $Id$ | ||
# | ||
#++ | ||
|
||
module OpenSSL | ||
class Digest | ||
# This class is only provided for backwards compatibility. Use OpenSSL::Digest in the future. | ||
class Digest < Digest | ||
def initialize(*args) | ||
# add warning | ||
super(*args) | ||
end | ||
end | ||
end # Digest | ||
end # OpenSSL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
=begin | ||
= $RCSfile$ -- Ruby-space definitions that completes C-space funcs for SSL | ||
= Info | ||
'OpenSSL for Ruby 2' project | ||
Copyright (C) 2001 GOTOU YUUZOU <gotoyuzo@notwork.org> | ||
All rights reserved. | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id$ | ||
=end | ||
|
||
require "openssl/buffering" | ||
require "fcntl" | ||
|
||
module OpenSSL | ||
module SSL | ||
module SocketForwarder | ||
def addr | ||
to_io.addr | ||
end | ||
|
||
def peeraddr | ||
to_io.peeraddr | ||
end | ||
|
||
def setsockopt(level, optname, optval) | ||
to_io.setsockopt(level, optname, optval) | ||
end | ||
|
||
def getsockopt(level, optname) | ||
to_io.getsockopt(level, optname) | ||
end | ||
|
||
def fcntl(*args) | ||
to_io.fcntl(*args) | ||
end | ||
|
||
def closed? | ||
to_io.closed? | ||
end | ||
|
||
def do_not_reverse_lookup=(flag) | ||
to_io.do_not_reverse_lookup = flag | ||
end | ||
end | ||
|
||
module Nonblock | ||
def initialize(*args) | ||
flag = File::NONBLOCK | ||
flag |= @io.fcntl(Fcntl::F_GETFL) if defined?(Fcntl::F_GETFL) | ||
@io.fcntl(Fcntl::F_SETFL, flag) | ||
super | ||
end | ||
end | ||
|
||
def verify_certificate_identity(cert, hostname) | ||
should_verify_common_name = true | ||
cert.extensions.each{|ext| | ||
next if ext.oid != "subjectAltName" | ||
ext.value.split(/,\s+/).each{|general_name| | ||
if /\ADNS:(.*)/ =~ general_name | ||
should_verify_common_name = false | ||
reg = Regexp.escape($1).gsub(/\\\*/, "[^.]+") | ||
return true if /\A#{reg}\z/i =~ hostname | ||
# NOTE: somehow we need the IP: canonical form | ||
# seems there were failures elsewhere when not | ||
# not sure how that's possible possible to-do! | ||
elsif /\AIP(?: Address)?:(.*)/ =~ general_name | ||
#elsif /\AIP Address:(.*)/ =~ general_name | ||
should_verify_common_name = false | ||
return true if $1 == hostname | ||
end | ||
} | ||
} | ||
if should_verify_common_name | ||
cert.subject.to_a.each{|oid, value| | ||
if oid == "CN" | ||
reg = Regexp.escape(value).gsub(/\\\*/, "[^.]+") | ||
return true if /\A#{reg}\z/i =~ hostname | ||
end | ||
} | ||
end | ||
return false | ||
end | ||
module_function :verify_certificate_identity | ||
|
||
class SSLSocket | ||
include Buffering | ||
include SocketForwarder | ||
include Nonblock | ||
|
||
def post_connection_check(hostname) | ||
unless OpenSSL::SSL.verify_certificate_identity(peer_cert, hostname) | ||
raise SSLError, "hostname does not match the server certificate" | ||
end | ||
return true | ||
end | ||
|
||
def session | ||
SSL::Session.new(self) | ||
rescue SSL::Session::SessionError | ||
nil | ||
end | ||
end | ||
|
||
class SSLServer | ||
include SocketForwarder | ||
attr_accessor :start_immediately | ||
|
||
def initialize(svr, ctx) | ||
@svr = svr | ||
@ctx = ctx | ||
unless ctx.session_id_context | ||
session_id = OpenSSL::Digest::MD5.hexdigest($0) | ||
@ctx.session_id_context = session_id | ||
end | ||
@start_immediately = true | ||
end | ||
|
||
def to_io | ||
@svr | ||
end | ||
|
||
def listen(backlog=5) | ||
@svr.listen(backlog) | ||
end | ||
|
||
def shutdown(how=Socket::SHUT_RDWR) | ||
@svr.shutdown(how) | ||
end | ||
|
||
def accept | ||
sock = @svr.accept | ||
begin | ||
ssl = OpenSSL::SSL::SSLSocket.new(sock, @ctx) | ||
ssl.sync_close = true | ||
ssl.accept if @start_immediately | ||
ssl | ||
rescue SSLError => ex | ||
sock.close | ||
raise ex | ||
end | ||
end | ||
|
||
def close | ||
@svr.close | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
warn 'deprecated openssl/ssl use: require "openssl" instead of "openssl/ssl"' | ||
require 'openssl' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
=begin | ||
= $RCSfile$ -- Ruby-space definitions that completes C-space funcs for X509 and subclasses | ||
= Info | ||
'OpenSSL for Ruby 2' project | ||
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
All rights reserved. | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id$ | ||
=end | ||
|
||
module OpenSSL | ||
module X509 | ||
class Name | ||
module RFC2253DN | ||
Special = ',=+<>#;' | ||
HexChar = /[0-9a-fA-F]/ | ||
HexPair = /#{HexChar}#{HexChar}/ | ||
HexString = /#{HexPair}+/ | ||
Pair = /\\(?:[#{Special}]|\\|"|#{HexPair})/ | ||
StringChar = /[^#{Special}\\"]/ | ||
QuoteChar = /[^\\"]/ | ||
AttributeType = /[a-zA-Z][0-9a-zA-Z]*|[0-9]+(?:\.[0-9]+)*/ | ||
AttributeValue = / | ||
(?!["#])((?:#{StringChar}|#{Pair})*)| | ||
\#(#{HexString})| | ||
"((?:#{QuoteChar}|#{Pair})*)" | ||
/x | ||
TypeAndValue = /\A(#{AttributeType})=#{AttributeValue}/ | ||
|
||
module_function | ||
|
||
def expand_pair(str) | ||
return nil unless str | ||
return str.gsub(Pair){ | ||
pair = $& | ||
case pair.size | ||
when 2 then pair[1,1] | ||
when 3 then Integer("0x#{pair[1,2]}").chr | ||
else raise OpenSSL::X509::NameError, "invalid pair: #{str}" | ||
end | ||
} | ||
end | ||
|
||
def expand_hexstring(str) | ||
return nil unless str | ||
der = str.gsub(HexPair){$&.to_i(16).chr } | ||
a1 = OpenSSL::ASN1.decode(der) | ||
return a1.value, a1.tag | ||
end | ||
|
||
def expand_value(str1, str2, str3) | ||
value = expand_pair(str1) | ||
value, tag = expand_hexstring(str2) unless value | ||
value = expand_pair(str3) unless value | ||
return value, tag | ||
end | ||
|
||
def scan(dn) | ||
str = dn | ||
ary = [] | ||
while true | ||
if md = TypeAndValue.match(str) | ||
remain = md.post_match | ||
type = md[1] | ||
value, tag = expand_value(md[2], md[3], md[4]) rescue nil | ||
if value | ||
type_and_value = [type, value] | ||
type_and_value.push(tag) if tag | ||
ary.unshift(type_and_value) | ||
if remain.length > 2 && remain[0] == ?, | ||
str = remain[1..-1] | ||
next | ||
elsif remain.length > 2 && remain[0] == ?+ | ||
raise OpenSSL::X509::NameError, | ||
"multi-valued RDN is not supported: #{dn}" | ||
elsif remain.empty? | ||
break | ||
end | ||
end | ||
end | ||
msg_dn = dn[0, dn.length - str.length] + " =>" + str | ||
raise OpenSSL::X509::NameError, "malformed RDN: #{msg_dn}" | ||
end | ||
return ary | ||
end | ||
end | ||
|
||
class << self | ||
def parse_rfc2253(str, template=OBJECT_TYPE_TEMPLATE) | ||
ary = OpenSSL::X509::Name::RFC2253DN.scan(str) | ||
self.new(ary, template) | ||
end | ||
|
||
def parse_openssl(str, template=OBJECT_TYPE_TEMPLATE) | ||
ary = str.scan(/\s*([^\/,]+)\s*/).collect{|i| i[0].split("=", 2) } | ||
self.new(ary, template) | ||
end | ||
|
||
alias parse parse_openssl | ||
end | ||
end | ||
|
||
class StoreContext | ||
def cleanup | ||
warn "(#{caller.first}) OpenSSL::X509::StoreContext#cleanup is deprecated with no replacement" if $VERBOSE | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
warn 'deprecated openssl/x509 use: require "openssl" instead of "openssl/x509"' | ||
require 'openssl' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
=begin | ||
= $RCSfile$ -- Loader for all OpenSSL C-space and Ruby-space definitions | ||
= Info | ||
'OpenSSL for Ruby 2' project | ||
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
All rights reserved. | ||
= Licence | ||
This program is licenced under the same licence as Ruby. | ||
(See the file 'LICENCE'.) | ||
= Version | ||
$Id$ | ||
=end | ||
|
||
require 'openssl/bn' | ||
require 'openssl/cipher' | ||
require 'openssl/config' | ||
require 'openssl/digest' | ||
require 'openssl/x509' | ||
require 'openssl/ssl' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#-- | ||
# | ||
# $RCSfile$ | ||
# | ||
# = Ruby-space definitions that completes C-space funcs for BN | ||
# | ||
# = Info | ||
# 'OpenSSL for Ruby 2' project | ||
# Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz> | ||
# All rights reserved. | ||
# | ||
# = Licence | ||
# This program is licenced under the same licence as Ruby. | ||
# (See the file 'LICENCE'.) | ||
# | ||
# = Version | ||
# $Id$ | ||
# | ||
#++ | ||
|
||
## | ||
# Add double dispatch to Integer | ||
# | ||
class Integer | ||
def to_bn | ||
OpenSSL::BN::new(self) | ||
end | ||
end # Integer | ||
|
Oops, something went wrong.