ccrypto-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +64 -0
- data/README.md +149 -0
- data/Rakefile +10 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ccrypto-ruby.gemspec +45 -0
- data/lib/ccrypto/provider.rb +175 -0
- data/lib/ccrypto/ruby/data_conversion.rb +68 -0
- data/lib/ccrypto/ruby/engines/asn1_engine.rb +110 -0
- data/lib/ccrypto/ruby/engines/asn1_object.rb +19 -0
- data/lib/ccrypto/ruby/engines/cipher_engine.rb +170 -0
- data/lib/ccrypto/ruby/engines/compression_engine.rb +61 -0
- data/lib/ccrypto/ruby/engines/data_conversion_engine.rb +9 -0
- data/lib/ccrypto/ruby/engines/decompression_engine.rb +70 -0
- data/lib/ccrypto/ruby/engines/digest_engine.rb +127 -0
- data/lib/ccrypto/ruby/engines/ecc_engine.rb +218 -0
- data/lib/ccrypto/ruby/engines/hkdf_engine.rb +54 -0
- data/lib/ccrypto/ruby/engines/hmac_engine.rb +53 -0
- data/lib/ccrypto/ruby/engines/pbkdf2_engine.rb +69 -0
- data/lib/ccrypto/ruby/engines/pkcs7_engine.rb +179 -0
- data/lib/ccrypto/ruby/engines/rsa_engine.rb +300 -0
- data/lib/ccrypto/ruby/engines/scrypt_engine.rb +34 -0
- data/lib/ccrypto/ruby/engines/secret_key_engine.rb +18 -0
- data/lib/ccrypto/ruby/engines/secret_sharing_engine.rb +331 -0
- data/lib/ccrypto/ruby/engines/secure_random_engine.rb +34 -0
- data/lib/ccrypto/ruby/engines/x509_engine.rb +213 -0
- data/lib/ccrypto/ruby/ext/secret_key.rb +24 -0
- data/lib/ccrypto/ruby/ext/x509_cert.rb +24 -0
- data/lib/ccrypto/ruby/keybundle_store/pem_store.rb +73 -0
- data/lib/ccrypto/ruby/keybundle_store/pkcs12.rb +111 -0
- data/lib/ccrypto/ruby/utils/comparator.rb +15 -0
- data/lib/ccrypto/ruby/utils/memory_buffer.rb +63 -0
- data/lib/ccrypto/ruby/utils/native_helper.rb +17 -0
- data/lib/ccrypto/ruby/version.rb +7 -0
- data/lib/ccrypto/ruby.rb +25 -0
- metadata +136 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
|
2
|
+
require_relative '../data_conversion'
|
3
|
+
|
4
|
+
module Ccrypto
|
5
|
+
module Ruby
|
6
|
+
|
7
|
+
module PKCS12Store
|
8
|
+
include TR::CondUtils
|
9
|
+
include DataConversion
|
10
|
+
|
11
|
+
class PKCS12StoreException < KeyBundleStorageException; end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def from_pkcs12(input, &block)
|
15
|
+
raise PKCS12StoreException, "Input cannot be empty" if is_empty?(input)
|
16
|
+
|
17
|
+
raise PKCS12StoreException, "Block is required" if not block
|
18
|
+
|
19
|
+
inForm = block.call(:in_format)
|
20
|
+
case inForm
|
21
|
+
when :b64
|
22
|
+
inp = from_b64(bin)
|
23
|
+
when :hex
|
24
|
+
inp = from_hex(bin)
|
25
|
+
else
|
26
|
+
inp = input
|
27
|
+
end
|
28
|
+
|
29
|
+
pass = block.call(:p12_pass)
|
30
|
+
raise PKCS12StoreException, "Password cannot be empty" if is_empty?(pass)
|
31
|
+
|
32
|
+
begin
|
33
|
+
p12 = OpenSSL::PKCS12.new(inp, pass)
|
34
|
+
case p12.key
|
35
|
+
when OpenSSL::PKey::EC
|
36
|
+
[Ccrypto::Ruby::ECCKeyBundle.new(p12.key), Ccrypto::X509Cert.new(p12.certificate), p12.ca_certs.collect{ |c| Ccrypto::X509Cert.new(c) }]
|
37
|
+
else
|
38
|
+
[Ccrypto::Ruby::RSAKeyBundle.new(p12.key), Ccrypto::X509Cert.new(p12.certificate), p12.ca_certs.collect{ |c| Ccrypto::X509Cert.new(c) }]
|
39
|
+
end
|
40
|
+
rescue Exception => ex
|
41
|
+
raise PKCS12StoreException, ex
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
def self.included(klass)
|
47
|
+
klass.extend(ClassMethods)
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_pkcs12(&block)
|
51
|
+
|
52
|
+
raise PKCS12StoreException, "Block is required" if not block
|
53
|
+
|
54
|
+
ucert = block.call(:cert)
|
55
|
+
raise PKCS12StoreException, "Certificate is required" if is_empty?(ucert)
|
56
|
+
|
57
|
+
case ucert
|
58
|
+
when String
|
59
|
+
begin
|
60
|
+
cert = OpenSSL::X509::Certificate.new(ucert)
|
61
|
+
rescue Exception => ex
|
62
|
+
raise PKCS12StoreException, ex
|
63
|
+
end
|
64
|
+
when OpenSSL::X509::Certificate
|
65
|
+
cert = ucert
|
66
|
+
when Ccrypto::X509Cert
|
67
|
+
cert = ucert.nativeX509
|
68
|
+
else
|
69
|
+
raise PKCS12StoreException, "Unknown given certificate to store in P12 : #{cert}"
|
70
|
+
end
|
71
|
+
|
72
|
+
ca = block.call(:certchain)
|
73
|
+
ca = [cert] if is_empty?(ca)
|
74
|
+
ca = ca.collect do |c|
|
75
|
+
case c
|
76
|
+
when Ccrypto::X509Cert
|
77
|
+
c.nativeX509
|
78
|
+
else
|
79
|
+
c
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
pass = block.call(:p12_pass)
|
84
|
+
raise PKCS12StoreException, "Password is required" if is_empty?(pass)
|
85
|
+
|
86
|
+
name = block.call(:p12_name)
|
87
|
+
name = "Ccrypto KeyBundle" if is_empty?(name)
|
88
|
+
|
89
|
+
keypair = block.call(:keypair)
|
90
|
+
raise PKCS12StoreException, "Keypair is required" if is_empty?(keypair)
|
91
|
+
|
92
|
+
res = OpenSSL::PKCS12.create(pass, name, keypair, cert, ca)
|
93
|
+
|
94
|
+
outFormat = block.call(:out_format)
|
95
|
+
outFormat = :bin if is_empty?(outFormat)
|
96
|
+
|
97
|
+
case outFormat
|
98
|
+
when :b64
|
99
|
+
to_b64(res.to_der)
|
100
|
+
when :to_hex
|
101
|
+
to_hex(res.to_der)
|
102
|
+
else
|
103
|
+
res.to_der
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Ccrypto
|
4
|
+
module Ruby
|
5
|
+
class MemoryBuffer
|
6
|
+
|
7
|
+
def initialize(*args,&block)
|
8
|
+
@buf = StringIO.new
|
9
|
+
@buf.binmode
|
10
|
+
end
|
11
|
+
|
12
|
+
def bytes
|
13
|
+
@buf.string
|
14
|
+
end
|
15
|
+
|
16
|
+
def pos
|
17
|
+
@buf.pos
|
18
|
+
end
|
19
|
+
|
20
|
+
def length
|
21
|
+
@buf.length
|
22
|
+
end
|
23
|
+
|
24
|
+
def rewind
|
25
|
+
@buf.rewind
|
26
|
+
end
|
27
|
+
|
28
|
+
def dispose(wcnt = 32)
|
29
|
+
|
30
|
+
len = @buf.length
|
31
|
+
cnt = 0
|
32
|
+
loop do
|
33
|
+
@buf.rewind
|
34
|
+
@buf.write(SecureRandom.random_bytes(len))
|
35
|
+
|
36
|
+
cnt += 1
|
37
|
+
break if cnt >= wcnt
|
38
|
+
end
|
39
|
+
|
40
|
+
@buffer = nil
|
41
|
+
GC.start
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def write(val)
|
46
|
+
@buf.write(val)
|
47
|
+
end
|
48
|
+
|
49
|
+
def read(len)
|
50
|
+
@buf.read(len)
|
51
|
+
end
|
52
|
+
|
53
|
+
def respond_to_missing?(mtd, *args, &block)
|
54
|
+
@buf.respond_to?(mtd, *args, &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
def equals?(val)
|
58
|
+
bytes == val
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/ccrypto/ruby.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
require 'teLogger'
|
5
|
+
require 'toolrack'
|
6
|
+
|
7
|
+
require 'ccrypto'
|
8
|
+
|
9
|
+
|
10
|
+
require_relative "ruby/version"
|
11
|
+
|
12
|
+
require_relative 'provider'
|
13
|
+
|
14
|
+
require_relative 'ruby/ext/secret_key'
|
15
|
+
require_relative 'ruby/ext/x509_cert'
|
16
|
+
|
17
|
+
module Ccrypto
|
18
|
+
module Ruby
|
19
|
+
class Error < StandardError; end
|
20
|
+
# Your code goes here...
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'ccrypto'
|
25
|
+
Ccrypto::Provider.instance.register(Ccrypto::Ruby::Provider)
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ccrypto-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ian
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-08-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: teLogger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: toolrack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ccrypto
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: devops_assist
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Refers Ccrypto library for further info. This is the Ruby implementation
|
70
|
+
of the core cryptographic API
|
71
|
+
email:
|
72
|
+
- cameronian0@protonmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- ccrypto-ruby.gemspec
|
85
|
+
- lib/ccrypto/provider.rb
|
86
|
+
- lib/ccrypto/ruby.rb
|
87
|
+
- lib/ccrypto/ruby/data_conversion.rb
|
88
|
+
- lib/ccrypto/ruby/engines/asn1_engine.rb
|
89
|
+
- lib/ccrypto/ruby/engines/asn1_object.rb
|
90
|
+
- lib/ccrypto/ruby/engines/cipher_engine.rb
|
91
|
+
- lib/ccrypto/ruby/engines/compression_engine.rb
|
92
|
+
- lib/ccrypto/ruby/engines/data_conversion_engine.rb
|
93
|
+
- lib/ccrypto/ruby/engines/decompression_engine.rb
|
94
|
+
- lib/ccrypto/ruby/engines/digest_engine.rb
|
95
|
+
- lib/ccrypto/ruby/engines/ecc_engine.rb
|
96
|
+
- lib/ccrypto/ruby/engines/hkdf_engine.rb
|
97
|
+
- lib/ccrypto/ruby/engines/hmac_engine.rb
|
98
|
+
- lib/ccrypto/ruby/engines/pbkdf2_engine.rb
|
99
|
+
- lib/ccrypto/ruby/engines/pkcs7_engine.rb
|
100
|
+
- lib/ccrypto/ruby/engines/rsa_engine.rb
|
101
|
+
- lib/ccrypto/ruby/engines/scrypt_engine.rb
|
102
|
+
- lib/ccrypto/ruby/engines/secret_key_engine.rb
|
103
|
+
- lib/ccrypto/ruby/engines/secret_sharing_engine.rb
|
104
|
+
- lib/ccrypto/ruby/engines/secure_random_engine.rb
|
105
|
+
- lib/ccrypto/ruby/engines/x509_engine.rb
|
106
|
+
- lib/ccrypto/ruby/ext/secret_key.rb
|
107
|
+
- lib/ccrypto/ruby/ext/x509_cert.rb
|
108
|
+
- lib/ccrypto/ruby/keybundle_store/pem_store.rb
|
109
|
+
- lib/ccrypto/ruby/keybundle_store/pkcs12.rb
|
110
|
+
- lib/ccrypto/ruby/utils/comparator.rb
|
111
|
+
- lib/ccrypto/ruby/utils/memory_buffer.rb
|
112
|
+
- lib/ccrypto/ruby/utils/native_helper.rb
|
113
|
+
- lib/ccrypto/ruby/version.rb
|
114
|
+
homepage: https://github.com/cameronian/ccrypto-ruby
|
115
|
+
licenses: []
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 2.4.0
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubygems_version: 3.2.22
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Ccrypto API provider for Ruby runtime
|
136
|
+
test_files: []
|