Skip to content

Commit

Permalink
Incorporate Krypt and wire it up for OpenSSL::PKCS5.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jan 24, 2013
1 parent c554ce2 commit cc9acba
Show file tree
Hide file tree
Showing 26 changed files with 1,299 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/ruby/shared/krypt-core.rb
@@ -0,0 +1,39 @@
=begin
= Info
krypt-core API - Java implementation
Copyright (C) 2011-2013
Hiroshi Nakamura <nahi@ruby-lang.org>
Martin Bosslet <martin.bosslet@gmail.com>
All rights reserved.
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.
=end

unless defined? JRUBY_VERSION
warn 'Loading krypt-core-java in a non-JRuby interpreter'
end

require 'kryptcore.jar'
require 'krypt-provider-jdk'

33 changes: 33 additions & 0 deletions lib/ruby/shared/krypt-provider-jdk.rb
@@ -0,0 +1,33 @@
=begin
= Info
krypt-provider-jdk - Implementation using the JDK security library
Copyright (C) 2011-2013
Hiroshi Nakamura <nahi@ruby-lang.org>
Martin Bosslet <martin.bosslet@gmail.com>
All rights reserved.
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.
=end

require 'kryptproviderjdk.jar'
49 changes: 49 additions & 0 deletions lib/ruby/shared/krypt.rb
@@ -0,0 +1,49 @@
=begin
= Info
krypt - Modern platform- and library-independent cryptography for Ruby
Copyright (C) 2011-2013
Hiroshi Nakamura <nahi@ruby-lang.org>
Martin Bosslet <martin.bosslet@gmail.com>
All rights reserved.
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.
=end

module Krypt
class Error < StandardError; end
end

require_relative 'krypt_missing'
require_relative 'krypt/provider'
require_relative 'krypt/digest'
require_relative 'krypt/hmac'
require_relative 'krypt/pkcs5'

require 'krypt-core'

# The following files depend on krypt-core being loaded
require_relative 'krypt/asn1'
require_relative 'krypt/x509'
require_relative 'krypt/codec'

3 changes: 3 additions & 0 deletions lib/ruby/shared/krypt/asn1.rb
@@ -0,0 +1,3 @@
require_relative 'asn1/template'
require_relative 'asn1/common'

96 changes: 96 additions & 0 deletions lib/ruby/shared/krypt/asn1/common.rb
@@ -0,0 +1,96 @@
module Krypt
module ASN1

class DirectoryString
include Template::Choice

asn1_t61_string
asn1_ia5_string
asn1_printable_string
asn1_universal_string
asn1_utf8_string
asn1_bmp_string
end

class DistinguishedName
include Template::SequenceOf

class AttributeTypeAndValue
include Template::Sequence

asn1_object_id :type
asn1_template :value, DirectoryString
end

class RelativeDistinguishedName
include Template::SetOf

asn1_type AttributeTypeAndValue
end

asn1_type RelativeDistinguishedName
end

class GeneralName
include Template::Choice

class OtherName
include Template::Sequence

asn1_object_id :type
asn1_any :value, tag: 0, tagging: :EXPLICIT
end

class EDIPartyName
include Template::Sequence

asn1_template :name_assigner, DirectoryString, tag: 0, tagging: :IMPLICIT, optional: true
asn1_template :party_name, DirectoryString, tag: 1, tagging: :IMPLICIT
end

asn1_template OtherName, tag: 0, tagging: :IMPLICIT
asn1_ia5_string tag: 1, tagging: :IMPLICIT
asn1_ia5_string tag: 2, tagging: :IMPLICIT
asn1_any tag: 3, tagging: :IMPLICIT
asn1_template DistinguishedName, tag: 4, tagging: :EXPLICIT
asn1_template EDIPartyName, tag: 5, tagging: :IMPLICIT
asn1_ia5_string tag: 6, tagging: :IMPLICIT
asn1_octet_string tag: 7, tagging: :IMPLICIT
asn1_object_id tag: 8, tagging: :IMPLICIT
end

class AlgorithmIdentifier
include Template::Sequence

asn1_object_id :algorithm
asn1_any :params, optional: true

def self.algorithm_null_params(name)
AlgorithmIdentifier.new do |alg|
alg.algorithm = name
alg.params = Krypt::ASN1::Null.new
end
end
class << self; private :algorithm_null_params; end

MD5 = algorithm_null_params('1.2.840.113549.2.5')
RIPEMD160 = algorithm_null_params('1.3.36.3.2.1')
SHA1 = algorithm_null_params('1.3.14.3.2.26')
SHA224 = algorithm_null_params('2.16.840.1.101.3.4.2.4')
SHA256 = algorithm_null_params('2.16.840.1.101.3.4.2.1')
SHA384 = algorithm_null_params('2.16.840.1.101.3.4.2.2')
SHA512 = algorithm_null_params('2.16.840.1.101.3.4.2.3')

RSA = algorithm_null_params('1.2.840.113549.1.1.1')

RSA_MD5 = algorithm_null_params('1.2.840.113549.1.1.4')
RSA_SHA1 = algorithm_null_params('1.2.840.113549.1.1.5')
RSA_SHA224 = algorithm_null_params('1.2.840.113549.1.1.14')
RSA_SHA256 = algorithm_null_params('1.2.840.113549.1.1.11')
RSA_SHA384 = algorithm_null_params('1.2.840.113549.1.1.12')
RSA_SHA512 = algorithm_null_params('1.2.840.113549.1.1.13')
end

end
end

0 comments on commit cc9acba

Please sign in to comment.