ccrypto 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 708c818b1776a95812b03efc9cc90bffb7e75ef5fe3325c455dfd3b5ae8b52fe
4
- data.tar.gz: f62763565bb50a8216d461e02dfb9737cb20867b8606c06e7f1200a161960d9a
3
+ metadata.gz: 0d9b4e9adddf9cbf8aca58067b846446828debe3ccb6bf628d22c710bfd21c90
4
+ data.tar.gz: b18db1468580e01942f76a5774a799f8041406ea8a97a0baabe1680d08782673
5
5
  SHA512:
6
- metadata.gz: b35007b3c2e4316328d14fa4a2929f2c8b6be032468711586efb63aeaf4271d5b9714f8d8723b4f0e9871bc46b4bab4e9afcf2dc9a43a7679bd33377cf6fabcb
7
- data.tar.gz: '08e2704618f620d371b4d1eebfbe4715b0516a88b1ab09a336d631bedfbccc7dbb96d19ea872918976c6909bdda81c1dbb0f700bf29474083a6ffa961ee42af2'
6
+ metadata.gz: 6b155d2377681522df9e5ff54996dda2a545b890b6cbb854552d52d8f7e31d7e219399cb5fd053cfe70622616b8d32fcc9e7c2a6b436602cf055df1a71281bc9
7
+ data.tar.gz: e4941b14400b7ef909095299a6f2c0e89fb931c5057c3b0d70b2eb6952f48bb7cb8b535594bc1c71c6e74de60b70281bc37047c3a45ffe9f6c1a602184fa6ff7
@@ -0,0 +1,6 @@
1
+ ---
2
+ ccrypto:
3
+ - :version: 0.1.0
4
+ :timestamp: 1660209199.3682408
5
+ - :version: 0.1.1
6
+ :timestamp: 1678162760.4304333
data/Gemfile.lock CHANGED
@@ -1,40 +1,83 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ccrypto (0.1.0)
4
+ ccrypto (0.1.1)
5
+ activesupport
5
6
  teLogger
6
7
  toolrack
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
12
+ activesupport (7.0.4.3)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
11
17
  base58 (0.2.3)
18
+ concurrent-ruby (1.2.2)
19
+ devops_assist (0.3.9)
20
+ git_cli
21
+ git_cli_prompt
22
+ gvcs
23
+ teLogger
24
+ toolrack
25
+ tty-prompt
12
26
  diff-lcs (1.5.0)
27
+ git_cli (0.11.2)
28
+ gvcs
29
+ ptools (~> 1.4.0)
30
+ teLogger
31
+ toolrack
32
+ git_cli_prompt (0.3.2)
33
+ teLogger
34
+ toolrack
35
+ tty-prompt
36
+ gvcs (0.1.1)
37
+ i18n (1.12.0)
38
+ concurrent-ruby (~> 1.0)
39
+ minitest (5.18.0)
40
+ pastel (0.8.0)
41
+ tty-color (~> 0.5)
42
+ ptools (1.4.3)
13
43
  rake (13.0.6)
14
- rspec (3.11.0)
15
- rspec-core (~> 3.11.0)
16
- rspec-expectations (~> 3.11.0)
17
- rspec-mocks (~> 3.11.0)
18
- rspec-core (3.11.0)
19
- rspec-support (~> 3.11.0)
20
- rspec-expectations (3.11.0)
44
+ rspec (3.12.0)
45
+ rspec-core (~> 3.12.0)
46
+ rspec-expectations (~> 3.12.0)
47
+ rspec-mocks (~> 3.12.0)
48
+ rspec-core (3.12.1)
49
+ rspec-support (~> 3.12.0)
50
+ rspec-expectations (3.12.2)
21
51
  diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.11.0)
23
- rspec-mocks (3.11.0)
52
+ rspec-support (~> 3.12.0)
53
+ rspec-mocks (3.12.4)
24
54
  diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.11.0)
26
- rspec-support (3.11.0)
27
- teLogger (0.1.0)
28
- tlogger (0.26.3)
29
- toolrack (0.18.3)
55
+ rspec-support (~> 3.12.0)
56
+ rspec-support (3.12.0)
57
+ teLogger (0.2.2)
58
+ toolrack (0.20.2)
30
59
  base58
31
- tlogger
60
+ tty-color (0.6.0)
61
+ tty-cursor (0.7.1)
62
+ tty-prompt (0.23.1)
63
+ pastel (~> 0.8)
64
+ tty-reader (~> 0.8)
65
+ tty-reader (0.9.0)
66
+ tty-cursor (~> 0.7)
67
+ tty-screen (~> 0.8)
68
+ wisper (~> 2.0)
69
+ tty-screen (0.8.1)
70
+ tzinfo (2.0.6)
71
+ concurrent-ruby (~> 1.0)
72
+ wisper (2.0.1)
32
73
 
33
74
  PLATFORMS
75
+ ruby
34
76
  x86_64-linux
35
77
 
36
78
  DEPENDENCIES
37
79
  ccrypto!
80
+ devops_assist
38
81
  rake (~> 13.0)
39
82
  rspec (~> 3.0)
40
83
 
data/ccrypto.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Ian"]
9
9
  spec.email = ["cameronian0@protonmail.com"]
10
10
 
11
- spec.summary = ""
12
- spec.description = ""
11
+ spec.summary = "Crypto API normalization for Ruby and Java"
12
+ spec.description = "Attempt to have a common crypto for Ruby and Java to take the selection decision out from the application development until further date"
13
13
  spec.homepage = "https://github.com/cameronian/ccrypto"
14
14
  spec.required_ruby_version = ">= 2.4.0"
15
15
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Ccrypto
4
4
 
5
- module CipherGCMMode
5
+ module CipherAuthMode
6
6
  attr_accessor :auth_data, :auth_tag
7
7
  end
8
8
 
@@ -15,23 +15,41 @@ module Ccrypto
15
15
  attr_accessor :iv, :ivLength
16
16
  attr_accessor :cipherOps
17
17
 
18
+ # required by certain mode such as CCM
19
+ attr_accessor :plaintext_length, :ciphertext_length
20
+
21
+ # Use cases :
22
+ # openssl aes-128-xts only accepts input min 16 bytes
23
+ # other no padding mode aes128-wrap only works on block of 8 bytes
24
+ attr_reader :min_input_length, :mandatory_block_size
25
+
26
+ # provider specific
27
+ attr_accessor :native_config
28
+
18
29
  def initialize(algo, opts = { }, &block)
19
30
  @algo = algo
20
31
 
21
32
  @logger = Tlogger.new
22
33
  @logger.tag = :cipher_conf
34
+
35
+ @authMode = false
36
+ @plaintext_length = 0
37
+ @ciphertext_length = 0
38
+ @min_input_length = -1
39
+ @mandatory_Block_size = -1
23
40
 
24
41
  if not_empty?(opts) and opts.is_a?(Hash)
25
42
  @mode = opts[:mode]
26
43
 
27
- if is_mode?(:gcm)
28
- self.extend CipherGCMMode
29
- @logger.debug "Extending GCM mode"
44
+ @authMode = opts[:authMode] || false
45
+ #if is_mode?(:gcm)
46
+ if @authMode
47
+ self.extend CipherAuthMode
48
+ @logger.debug "Extending auth mode"
30
49
 
31
50
  @auth_data = opts[:auth_data]
32
51
  @auth_tag = opts[:auth_tag]
33
52
 
34
- #p "auth data : #{@auth_data}"
35
53
  end
36
54
 
37
55
  @iv = opts[:iv]
@@ -43,29 +61,41 @@ module Ccrypto
43
61
  @padding = opts[:padding]
44
62
 
45
63
  @cipherOps = opts[:cipherOps]
64
+
65
+ @min_input_length = opts[:min_input_length] || -1
66
+
67
+ @mandatory_block_size = opts[:mandatory_block_size] || -1
68
+
46
69
  end
47
70
 
48
- if block
49
- @mode = block.call(:mode)
71
+ #if block
72
+ # @mode = block.call(:mode)
50
73
 
51
- if is_mode?(:gcm)
52
- self.extend CipherGCMMode
53
- @logger.debug "Extending GCM mode"
74
+ # #if is_mode?(:gcm)
75
+ # if @authMode
76
+ # self.extend CipherAuthMode
77
+ # @logger.debug "Extending auth mode"
54
78
 
55
- @auth_data = block.call(:auth_data)
56
- @auth_tag = block.call(:auth_tag)
57
- end
79
+ # @auth_data = block.call(:auth_data)
80
+ # @auth_tag = block.call(:auth_tag)
81
+ # end
58
82
 
59
- @iv = block.call(:iv)
60
- @ivLength = block.call(:ivLength) || 16 if @iv.nil?
83
+ # @iv = block.call(:iv)
84
+ # @ivLength = block.call(:ivLength) || 16 if @iv.nil?
61
85
 
62
- @key = block.call(:key)
63
- @keysize = block.call(:keysize) if @key.nil?
86
+ # @key = block.call(:key)
87
+ # @keysize = block.call(:keysize) if @key.nil?
64
88
 
65
- @padding = block.call(:padding)
89
+ # @padding = block.call(:padding)
66
90
 
67
- @cipherOps = block.call(:cipherOps)
68
- end
91
+ # @cipherOps = block.call(:cipherOps)
92
+
93
+ # @plaintext_length = 0
94
+ # @ciphertext_length = 0
95
+
96
+ # @min_input_length = opts[:min_input_length] || -1
97
+
98
+ #end
69
99
 
70
100
  end
71
101
 
@@ -77,6 +107,10 @@ module Ccrypto
77
107
  not_empty?(@key)
78
108
  end
79
109
 
110
+ def is_auth_mode_cipher?
111
+ @authMode
112
+ end
113
+
80
114
  def is_algo?(algo)
81
115
  if @algo.nil? or is_empty?(@algo)
82
116
  false
@@ -118,7 +152,9 @@ module Ccrypto
118
152
  end
119
153
 
120
154
  def to_s
121
- "#{@algo}-#{@keysize}-#{@mode}-#{@padding}"
155
+ res = [@algo, @keysize, @mode, @padding].reject { |v| is_empty?(v) }.join("-")
156
+ "#{res} (#{@authMode})"
157
+ #"#{@algo}-#{@keysize}-#{@mode}-#{@padding}"
122
158
  end
123
159
 
124
160
  def logger
@@ -130,21 +166,21 @@ module Ccrypto
130
166
  end
131
167
  end
132
168
 
133
- class DirectCipherConfig < CipherConfig
134
- # str can be String or Hash
135
- # If String it will be directly used by underlying
136
- # engine with minimum parsing which means might not have other
137
- # info
138
- def initialize(str)
139
- raise CipherConfigException, "Hash is expected" if not str.is_a?(Hash)
140
- super(str[:algo], str)
141
- end
142
-
143
- end
144
-
145
- class CipherEngineConfig < CipherConfig
146
- # engine that is discovered by cipher engine
147
- # Means can directly use the object
148
- end
169
+ #class DirectCipherConfig < CipherConfig
170
+ # # str can be String or Hash
171
+ # # If String it will be directly used by underlying
172
+ # # engine with minimum parsing which means might not have other
173
+ # # info
174
+ # def initialize(str)
175
+ # raise CipherConfigException, "Hash is expected" if not str.is_a?(Hash)
176
+ # super(str[:algo], str)
177
+ # end
178
+
179
+ #end
180
+
181
+ #class CipherEngineConfig < CipherConfig
182
+ # # engine that is discovered by cipher engine
183
+ # # Means can directly use the object
184
+ #end
149
185
 
150
186
  end
@@ -41,6 +41,7 @@ module Ccrypto
41
41
  # https://stackoverflow.com/a/33297994/3625825
42
42
 
43
43
  def initialize
44
+ @algo = :scrypt
44
45
  @cost = 16384 # 2**14
45
46
  @blockSize = 8
46
47
  @parallel = 1
@@ -51,17 +52,57 @@ module Ccrypto
51
52
  class HKDFConfig < KDFConfig
52
53
  attr_accessor :salt, :info, :digest
53
54
  def initialize
55
+ @algo = :hkdf
54
56
  @salt = SecureRandom.random_bytes(16)
55
- @digest = :sha256
57
+ @digest = :sha3_256
56
58
  end
57
59
  end
58
60
 
59
61
  class PBKDF2Config < KDFConfig
60
62
  attr_accessor :salt, :digest, :iter
61
63
  def initialize
64
+ @algo = :pbkdf2
62
65
  @salt = SecureRandom.random_bytes(16)
63
- @digest = :sha256
64
- @iter = rand(200000..400000)
66
+ @digest = :sha3_256
67
+ @iter = rand(300000..500000)
65
68
  end
66
69
  end
70
+
71
+ class Argon2Config < KDFConfig
72
+
73
+ attr_accessor :cost, :salt, :secret, :parallel, :iter
74
+ attr_accessor :variant
75
+
76
+ def initialize
77
+
78
+ @algo = :argon2
79
+
80
+ # "salt" which can be stored non-secure or with the password Hash
81
+ @salt = SecureRandom.random_bytes(16)
82
+
83
+ # Secret value which has to be stored in a different secure location from the password hashes
84
+ @secret = SecureRandom.random_bytes(16)
85
+
86
+ # The RFC recommends 4 GB for backend authentication and 1 GB for frontend authentication.
87
+ @cost = 1*1024*1024*1024
88
+
89
+ # Choose the Number of CPU-Threads you can afford each call (2 Cores = 4 Threads)
90
+ @parallel = 4
91
+
92
+ # Set the number of Iterations each call -> More Iterations = Better Security + more Hashing Time
93
+ # > 3 Iterations recommended
94
+ @iter = 3
95
+
96
+ # Follow BC library
97
+ # Argon2d
98
+ # Argon2i (recommended)
99
+ # Argon2id
100
+ # Argon2_version_10
101
+ # Argon2_version_13
102
+ @variant = :argon2i
103
+
104
+ end
105
+
106
+ end
107
+
67
108
  end
@@ -10,5 +10,9 @@ module Ccrypto
10
10
  "#{@algo}/#{@keysize}"
11
11
  end
12
12
 
13
+ def self.supported_secret_key_config(&block)
14
+ Provider.instance.provider.supported_secret_key_config(&block)
15
+ end
16
+
13
17
  end
14
18
  end
@@ -1,11 +1,30 @@
1
1
 
2
2
 
3
3
  module Ccrypto
4
+
4
5
  class KeypairConfig
5
6
  include AlgoConfig
6
7
 
7
8
  attr_accessor :algo
8
9
  attr_accessor :keypair, :private_key, :public_key
10
+
11
+ attr_reader :algo_status
12
+
13
+ Algo_Active = :active
14
+ Algo_NotRecommended = :not_recommended
15
+ Algo_Obsolete = :obsolete
16
+ Algo_Broken = :broken
17
+
18
+ attr_reader :default
19
+
20
+ def initialize(status = Algo_Active, default = false)
21
+ @algo_status = status
22
+ @default = default
23
+ end
24
+
25
+ def is_default_algo?
26
+ @default
27
+ end
9
28
 
10
29
  def has_keypair?
11
30
  (not @keypair.nil?) or not (@privateKey.nil? and @publicKey.nil?)
@@ -26,29 +45,85 @@ module Ccrypto
26
45
  not @public_key.nil?
27
46
  end
28
47
  end
29
- end
48
+
49
+ def self.keypair_purposes
50
+ {
51
+ signing: "Keypair for signing and digital signature operation",
52
+ cipher: "Keypair for data encryption operation",
53
+ sign_and_encrypt: "Keypair for both signing and data encryption operation"
54
+ }
55
+ end
56
+
57
+ def self.supported_keypair_config(purpose = :signing, &block)
58
+ Provider.instance.provider.supported_keypair_config(purpose, &block)
59
+ end
60
+
61
+ end # KeypairConfig
30
62
 
31
63
  class ECCConfig < KeypairConfig
64
+
65
+ def self.name
66
+ "Elliptic Curve (ECC)"
67
+ end
68
+
32
69
  attr_accessor :curve
33
- def initialize(curve = nil)
70
+ def initialize(curve = nil, status = Algo_Active, default = false)
34
71
  @algo = :ecc
35
72
  @curve = curve || :prime256v1
73
+ @curve = @curve.to_sym if not @curve.is_a?(Symbol)
74
+ super(status, default)
36
75
  end
37
76
 
38
77
  def to_s
39
- "ECC-#{@curve}"
78
+ "#{@curve}"
40
79
  end
41
- end
80
+
81
+ def self.supported_curves(&block)
82
+ Provider.instance.provider.algo_instance(*[ECCConfig], &block).supported_curves
83
+ end
84
+ end # ECCConfig
42
85
 
43
86
  class RSAConfig < KeypairConfig
87
+ def self.name
88
+ "RSA"
89
+ end
90
+
44
91
  attr_accessor :keysize
45
- def initialize(keysize = 2048)
92
+ def initialize(keysize = 2048, status = Algo_Active, default = false)
46
93
  @keysize = keysize
94
+ super(status, default)
47
95
  end
48
96
 
49
97
  def to_s
50
98
  "RSA-#{keysize} bits"
51
99
  end
100
+
101
+ def self.supported_keysizes(&block)
102
+ Provider.instance.provider.algo_instance(*[RSAConfig],&block).supported_keysizes
103
+ end
104
+ end # RSAConfig
105
+
106
+ # ED25519 for data signature
107
+ class ED25519Config < KeypairConfig
108
+ def self.name
109
+ "ED25519 (Signing Only)"
110
+ end
111
+
112
+ def initialize
113
+ algo = :ed25519
114
+ super(Algo_Active, true)
115
+ end
116
+ end
117
+
118
+ # X25519 for key exchange
119
+ class X25519Config < KeypairConfig
120
+ def self.name
121
+ "X25519 (Data Encipherment only)"
122
+ end
123
+ def initialize
124
+ algo = :x25519
125
+ super(Algo_Active, true)
126
+ end
52
127
  end
53
128
 
54
129
  end
@@ -15,13 +15,17 @@ module Ccrypto
15
15
 
16
16
  attr_accessor :owner_name, :org
17
17
  attr_accessor :org_unit, :email, :dns_name, :ip_addr, :uri
18
- attr_accessor :public_key, :serial, :not_before, :not_after
18
+ attr_accessor :locality, :country
19
+ attr_accessor :public_key, :serial # , :not_before, :not_after
20
+ attr_accessor :csr
19
21
  attr_accessor :subj_key_id, :auth_key_id
20
22
  attr_accessor :crl_dist_point, :ocsp_url, :issuer_url
21
23
  attr_accessor :issuer_cert
22
24
  attr_accessor :hashAlgo
23
25
  attr_accessor :raise_if_validity_date_not_in_issuer_range
24
26
 
27
+ attr_accessor :issuer_path_len
28
+
25
29
  def initialize
26
30
  @hashAlgo = Ccrypto::SHA256
27
31
  @serial = SecureRandom.hex(16)
@@ -34,6 +38,28 @@ module Ccrypto
34
38
  @raise_if_validity_date_not_in_issuer_range = false
35
39
  end
36
40
 
41
+ def not_before=(val)
42
+ @not_before = val
43
+ end
44
+ alias_method :valid_from=, :not_before=
45
+
46
+ def not_before
47
+ @not_before
48
+ end
49
+ alias_method :valid_from, :not_before
50
+
51
+ def not_after=(val)
52
+ @not_after = val
53
+ end
54
+ alias_method :valid_until=, :not_after=
55
+ alias_method :valid_to=, :not_after=
56
+
57
+ def not_after
58
+ @not_after
59
+ end
60
+ alias_method :valid_until, :not_after
61
+ alias_method :valid_to, :not_after
62
+
37
63
  def gen_issuer_cert?
38
64
  @issuerCert
39
65
  end
@@ -65,6 +91,18 @@ module Ccrypto
65
91
  end
66
92
  end
67
93
 
94
+ def email=(val)
95
+ if @email.nil?
96
+ @email = []
97
+ end
98
+
99
+ case val
100
+ when Array
101
+ @email += val
102
+ else
103
+ @email << val
104
+ end
105
+ end
68
106
  def email
69
107
  if @email.nil?
70
108
  []
@@ -75,6 +113,18 @@ module Ccrypto
75
113
  end
76
114
  end
77
115
 
116
+ def dns_name=(val)
117
+ if @dns_name.nil?
118
+ @dns_name = []
119
+ end
120
+
121
+ case val
122
+ when Array
123
+ @dns_name += val
124
+ else
125
+ @dns_name << val
126
+ end
127
+ end
78
128
  def dns_name
79
129
  if @dns_name.nil?
80
130
  []
@@ -85,6 +135,19 @@ module Ccrypto
85
135
  end
86
136
  end
87
137
 
138
+
139
+ def ip_addr=(val)
140
+ if @ip_addr.nil?
141
+ @ip_addr = []
142
+ end
143
+
144
+ case val
145
+ when Array
146
+ @ip_addr += val
147
+ else
148
+ @ip_addr << val
149
+ end
150
+ end
88
151
  def ip_addr
89
152
  if @ip_addr.nil?
90
153
  []
@@ -95,6 +158,19 @@ module Ccrypto
95
158
  end
96
159
  end
97
160
 
161
+ def uri=(val)
162
+ if @uri.nil?
163
+ @uri = []
164
+ end
165
+
166
+ case val
167
+ when Array
168
+ @uri += val
169
+ else
170
+ @uri << val
171
+ end
172
+ end
173
+
98
174
  def uri
99
175
  if @uri.nil?
100
176
  []
@@ -236,8 +312,8 @@ module Ccrypto
236
312
  clientAuth: "TLS client authentication",
237
313
  codeSigning: "Code signing",
238
314
  emailProtection: "Email protection",
239
- timestamping: "Time stamping",
240
- ocspSigning: "Online Cert Status Protocol signing",
315
+ timeStamping: "Time stamping",
316
+ OCSPSigning: "Online Cert Status Protocol signing",
241
317
  ipSecIKE: "IPSec Initial Key Exchange",
242
318
  msCodeInd: "Microsoft Code Ind",
243
319
  msCodeCom: "Microsoft Code Com",
@@ -292,6 +368,17 @@ module Ccrypto
292
368
  @domainKeyUsage
293
369
  end
294
370
 
371
+ def add_custom_extension(oid, value, type = :string, critical = false)
372
+ custom_extension[oid] = { type: type, value: value, critical: critical }
373
+ end
374
+
375
+ def custom_extension
376
+ if @custom_extension.nil?
377
+ @custom_extension = { }
378
+ end
379
+ @custom_extension
380
+ end
381
+
295
382
  end
296
383
  end
297
384
  end
@@ -0,0 +1,147 @@
1
+
2
+ require_relative 'algo_config'
3
+
4
+ module Ccrypto
5
+ module X509
6
+ class CSRProfile
7
+ include Ccrypto::AlgoConfig
8
+ include TR::CondUtils
9
+
10
+ include TeLogger::TeLogHelper
11
+ teLogger_tag :csr
12
+
13
+ attr_accessor :owner_name, :org
14
+ attr_accessor :org_unit, :email, :dns_name, :ip_addr, :uri
15
+ attr_accessor :public_key
16
+ attr_accessor :hashAlgo
17
+
18
+ def initialize
19
+ @hashAlgo = Ccrypto::SHA256
20
+ end
21
+
22
+ def org_unit
23
+ if @org_unit.nil?
24
+ []
25
+ elsif not @org_unit.is_a?(Array)
26
+ [@org_unit]
27
+ else
28
+ @org_unit
29
+ end
30
+ end
31
+
32
+ def email=(val)
33
+ if @email.nil?
34
+ @email = []
35
+ end
36
+
37
+ case val
38
+ when Array
39
+ @email += val
40
+ else
41
+ @email << val
42
+ end
43
+ end
44
+ def email
45
+ if @email.nil?
46
+ []
47
+ elsif not @email.is_a?(Array)
48
+ [@email]
49
+ else
50
+ @email
51
+ end
52
+ end
53
+
54
+ def dns_name=(val)
55
+ if @dns_name.nil?
56
+ @dns_name = []
57
+ end
58
+
59
+ case val
60
+ when Array
61
+ @dns_name += val
62
+ else
63
+ @dns_name << val
64
+ end
65
+ end
66
+
67
+ def dns_name
68
+ if @dns_name.nil?
69
+ []
70
+ elsif not @dns_name.is_a?(Array)
71
+ [@dns_name]
72
+ else
73
+ @dns_name
74
+ end
75
+ end
76
+
77
+
78
+ def ip_addr=(val)
79
+ if @ip_addr.nil?
80
+ @ip_addr = []
81
+ end
82
+
83
+ case val
84
+ when Array
85
+ @ip_addr += val
86
+ else
87
+ @ip_addr << val
88
+ end
89
+ end
90
+ def ip_addr
91
+ if @ip_addr.nil?
92
+ []
93
+ elsif not @ip_addr.is_a?(Array)
94
+ [@ip_addr]
95
+ else
96
+ @ip_addr
97
+ end
98
+ end
99
+
100
+ def uri=(val)
101
+ if @uri.nil?
102
+ @uri = []
103
+ end
104
+
105
+ case val
106
+ when Array
107
+ @uri += val
108
+ else
109
+ @uri << val
110
+ end
111
+ end
112
+
113
+ def uri
114
+ if @uri.nil?
115
+ []
116
+ elsif not @uri.is_a?(Array)
117
+ [@uri]
118
+ else
119
+ @uri
120
+ end
121
+ end
122
+
123
+ def add_custom_attribute(key,value, type = :string)
124
+ additional_attributes[key] = { value: value, type: type }
125
+ end
126
+
127
+ def additional_attributes
128
+ if @addAttr.nil?
129
+ @addAttr = {}
130
+ end
131
+ @addAttr
132
+ end
133
+
134
+ def add_custom_extension(oid, value, type = :string, critical = false)
135
+ custom_extension[oid] = { type: type, value: value, critical: critical }
136
+ end
137
+
138
+ def custom_extension
139
+ if @custom_extension.nil?
140
+ @custom_extension = { }
141
+ end
142
+ @custom_extension
143
+ end
144
+
145
+ end
146
+ end
147
+ end
@@ -3,6 +3,11 @@
3
3
  module Ccrypto
4
4
  module KeyBundle
5
5
  attr_accessor :nativeKeypair
6
+
7
+ def KeyBundle.from_storage(*args, &block)
8
+ Provider.instance.provider.keybundle_from_storage(*args, &block)
9
+ end
10
+
6
11
  end
7
12
 
8
13
  module ECCKeyBundle
@@ -12,4 +17,12 @@ module Ccrypto
12
17
  module RSAKeyBundle
13
18
  include KeyBundle
14
19
  end
20
+
21
+ module ED25519KeyBundle
22
+ include KeyBundle
23
+ end
24
+
25
+ module X25519KeyBundle
26
+ include KeyBundle
27
+ end
15
28
  end
@@ -27,4 +27,6 @@ module Ccrypto
27
27
 
28
28
  class ECCPrivateKey < PrivateKey; end
29
29
  class RSAPrivateKey < PrivateKey; end
30
+ class ED25519PrivateKey < PrivateKey; end
31
+ class X25519PrivateKey < PrivateKey; end
30
32
  end
@@ -27,4 +27,6 @@ module Ccrypto
27
27
 
28
28
  class ECCPublicKey < PublicKey; end
29
29
  class RSAPublicKey < PublicKey; end
30
+ class ED25519PublicKey < PublicKey; end
31
+ class X25519PublicKey < PublicKey; end
30
32
  end
@@ -0,0 +1,127 @@
1
+
2
+ require 'singleton'
3
+
4
+ module Ccrypto
5
+
6
+ class SupportedCipherListError < StandardError; end
7
+
8
+ class SupportedCipherList
9
+ include TR::CondUtils
10
+ include Singleton
11
+
12
+ include TeLogger::TeLogHelper
13
+ teLogger_tag :supCipherList
14
+
15
+ def initialize
16
+ @algos = {}
17
+ @keysizes = {}
18
+ @modes = {}
19
+
20
+ @algoKeysize = {}
21
+ @algoKeysizeMode = {}
22
+ @keysizeMode = {}
23
+ @algoMode = {}
24
+ @items = []
25
+ end
26
+
27
+ def register(cc)
28
+ raise SupportedCipherListError, "Ccrypto::CipherConfig required. Got '#{cc.class}'" if not cc.is_a?(Ccrypto::CipherConfig)
29
+
30
+ @items << cc
31
+ algo = cc.algo.to_sym
32
+ @algos[algo] = [] if @algos[algo].nil?
33
+ @algos[algo] << cc
34
+
35
+ keysize = cc.keysize.to_s
36
+ @keysizes[keysize] = [] if @keysizes[keysize].nil?
37
+ @keysizes[keysize] << cc
38
+
39
+ mode = cc.mode.nil? ? "" : cc.mode.to_s
40
+ if not_empty?(mode)
41
+ @modes[mode.to_s] = [] if @modes[mode.to_s].nil?
42
+ @modes[mode.to_s] << cc
43
+ end
44
+
45
+ @algoKeysize[algo] = { } if @algoKeysize[algo].nil?
46
+ @algoKeysize[algo][keysize] = [] if @algoKeysize[algo][keysize].nil?
47
+ @algoKeysize[algo][keysize] << cc
48
+
49
+ if not_empty?(mode)
50
+ @algoMode[algo] = {} if @algoMode[algo].nil?
51
+ @algoMode[algo][mode] = [] if @algoMode[algo][mode].nil?
52
+ @algoMode[algo][mode] << cc
53
+
54
+ @keysizeMode[keysize] = {} if @keysizeMode[keysize].nil?
55
+ @keysizeMode[keysize][mode] = [] if @keysizeMode[keysize][mode].nil?
56
+ @keysizeMode[keysize][mode] << cc
57
+
58
+ @algoKeysizeMode[algo] = {} if @algoKeysizeMode[algo].nil?
59
+ @algoKeysizeMode[algo][keysize] = {} if @algoKeysizeMode[algo][keysize].nil?
60
+ @algoKeysizeMode[algo][keysize][mode] = [] if @algoKeysizeMode[algo][keysize][mode].nil?
61
+ @algoKeysizeMode[algo][keysize][mode] << cc
62
+ end
63
+
64
+ end
65
+
66
+ def items
67
+ @items
68
+ end
69
+
70
+ def each(&block)
71
+ @items.each(&block)
72
+ end
73
+
74
+ def algo_count
75
+ @algos.length
76
+ end
77
+ def find_algo(algo)
78
+ @algos[algo.to_sym] || []
79
+ end
80
+ def algos
81
+ @algos.keys
82
+ end
83
+
84
+ def keysizes_count
85
+ @keysizes.length
86
+ end
87
+ def keysizes
88
+ @keysizes.keys
89
+ end
90
+ def find_keysize(keysize)
91
+ @keysizes[keysize.to_s]
92
+ end
93
+
94
+ def mode_count
95
+ @modes.length
96
+ end
97
+ def find_mode(mode)
98
+ @modes[mode.to_s]
99
+ end
100
+ def modes
101
+ @modes.keys
102
+ end
103
+
104
+ def find_algo_keysize(algo, keysize)
105
+ res = @algoKeysize[algo.to_sym] || { }
106
+ res[keysize.to_s] || []
107
+ end
108
+
109
+ def find_algo_mode(algo, mode)
110
+ res = @algoMode[algo.to_sym] || {}
111
+ res[mode.to_s] || []
112
+ end
113
+
114
+ def find_algo_keysize_mode(algo, keysize, mode)
115
+ res = @algoKeysizeMode[algo.to_sym] || {}
116
+ res = res[keysize.to_s] || {}
117
+ res[mode.to_s] || []
118
+ end
119
+
120
+ def find_keysize_modes(keysize, mode)
121
+
122
+ res = @keysizeMode[keysize.to_s] || {}
123
+ res[mode.to_s] || []
124
+ end
125
+
126
+ end
127
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ccrypto
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -0,0 +1,11 @@
1
+
2
+
3
+ module Ccrypto
4
+ class X509CSR
5
+ attr_accessor :nativeCSR
6
+
7
+ def initialize(csr)
8
+ @nativeCSR = csr
9
+ end
10
+ end
11
+ end
data/lib/ccrypto.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'toolrack'
4
- require 'tlogger'
4
+ require 'teLogger'
5
5
 
6
6
  require_relative "ccrypto/version"
7
7
 
8
8
  require_relative 'ccrypto/provider'
9
9
  require_relative 'ccrypto/algo_factory'
10
10
  require_relative 'ccrypto/key_bundle'
11
+ require_relative 'ccrypto/supported_cipher_list'
11
12
 
12
13
  require_relative 'ccrypto/asn1'
13
14
  require_relative 'ccrypto/asn1_object'
@@ -23,6 +24,7 @@ require_relative 'ccrypto/private_key'
23
24
  require_relative 'ccrypto/secret_key'
24
25
 
25
26
  require_relative 'ccrypto/x509_cert'
27
+ require_relative 'ccrypto/x509_csr'
26
28
 
27
29
  module Ccrypto
28
30
  class Error < StandardError; end
@@ -34,6 +36,10 @@ module Ccrypto
34
36
  class KeypairEngineException < StandardError; end
35
37
  class KeyBundleException < StandardError; end
36
38
  class X509EngineException < StandardError; end
39
+
40
+ class X509CSRException < StandardError; end
41
+ class X509CSRSignatureInvalid < StandardError; end
42
+
37
43
  class CipherEngineException < StandardError; end
38
44
  class ASN1EngineException < StandardError; end
39
45
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccrypto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-11 00:00:00.000000000 Z
11
+ date: 2023-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: teLogger
@@ -66,13 +66,15 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: ''
69
+ description: Attempt to have a common crypto for Ruby and Java to take the selection
70
+ decision out from the application development until further date
70
71
  email:
71
72
  - cameronian0@protonmail.com
72
73
  executables: []
73
74
  extensions: []
74
75
  extra_rdoc_files: []
75
76
  files:
77
+ - ".release_history.yml"
76
78
  - ".rspec"
77
79
  - Gemfile
78
80
  - Gemfile.lock
@@ -97,14 +99,17 @@ files:
97
99
  - lib/ccrypto/configs/secret_sharing_config.rb
98
100
  - lib/ccrypto/configs/secure_random_config.rb
99
101
  - lib/ccrypto/configs/x509_cert_profile.rb
102
+ - lib/ccrypto/configs/x509_csr_profile.rb
100
103
  - lib/ccrypto/key_bundle.rb
101
104
  - lib/ccrypto/private_key.rb
102
105
  - lib/ccrypto/provider.rb
103
106
  - lib/ccrypto/public_key.rb
104
107
  - lib/ccrypto/secret_key.rb
108
+ - lib/ccrypto/supported_cipher_list.rb
105
109
  - lib/ccrypto/util_factory.rb
106
110
  - lib/ccrypto/version.rb
107
111
  - lib/ccrypto/x509_cert.rb
112
+ - lib/ccrypto/x509_csr.rb
108
113
  homepage: https://github.com/cameronian/ccrypto
109
114
  licenses: []
110
115
  metadata: {}
@@ -123,8 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
128
  - !ruby/object:Gem::Version
124
129
  version: '0'
125
130
  requirements: []
126
- rubygems_version: 3.2.22
131
+ rubygems_version: 3.4.6
127
132
  signing_key:
128
133
  specification_version: 4
129
- summary: ''
134
+ summary: Crypto API normalization for Ruby and Java
130
135
  test_files: []