ccrypto-java 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.java-version +1 -1
  3. data/.release_history.yml +4 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +68 -53
  7. data/Rakefile +2 -1
  8. data/bin/console +14 -0
  9. data/jars/bcjmail-jdk18on-172.jar +0 -0
  10. data/jars/bcmail-jdk18on-172.jar +0 -0
  11. data/jars/bcpg-jdk18on-172.1.jar +0 -0
  12. data/jars/bcpkix-jdk18on-172.jar +0 -0
  13. data/jars/bcprov-ext-jdk18on-172.jar +0 -0
  14. data/jars/bcprov-jdk18on-172.jar +0 -0
  15. data/jars/bctls-jdk18on-172.jar +0 -0
  16. data/jars/bcutil-jdk18on-172.jar +0 -0
  17. data/lib/ccrypto/java/bc_const_mapping.rb +42 -0
  18. data/lib/ccrypto/java/data_conversion.rb +23 -2
  19. data/lib/ccrypto/java/engines/argon2_engine.rb +95 -0
  20. data/lib/ccrypto/java/engines/asn1_engine.rb +2 -1
  21. data/lib/ccrypto/java/engines/bcrypt_engine.rb +56 -0
  22. data/lib/ccrypto/java/engines/cipher_engine.rb +462 -130
  23. data/lib/ccrypto/java/engines/compression_engine.rb +7 -28
  24. data/lib/ccrypto/java/engines/crystal_dilithium_engine.rb +226 -0
  25. data/lib/ccrypto/java/engines/crystal_kyber_engine.rb +260 -0
  26. data/lib/ccrypto/java/engines/decompression_engine.rb +5 -4
  27. data/lib/ccrypto/java/engines/digest_engine.rb +221 -139
  28. data/lib/ccrypto/java/engines/ecc_engine.rb +249 -96
  29. data/lib/ccrypto/java/engines/ed25519_engine.rb +211 -0
  30. data/lib/ccrypto/java/engines/hkdf_engine.rb +82 -23
  31. data/lib/ccrypto/java/engines/hmac_engine.rb +98 -23
  32. data/lib/ccrypto/java/engines/pbkdf2_engine.rb +82 -33
  33. data/lib/ccrypto/java/engines/pkcs7_engine.rb +44 -33
  34. data/lib/ccrypto/java/engines/rsa_engine.rb +85 -31
  35. data/lib/ccrypto/java/engines/scrypt_engine.rb +12 -3
  36. data/lib/ccrypto/java/engines/secret_key_engine.rb +77 -12
  37. data/lib/ccrypto/java/engines/secret_sharing_engine.rb +17 -2
  38. data/lib/ccrypto/java/engines/x25519_engine.rb +249 -0
  39. data/lib/ccrypto/java/engines/x509_csr_engine.rb +141 -0
  40. data/lib/ccrypto/java/engines/x509_engine.rb +365 -71
  41. data/lib/ccrypto/java/ext/secret_key.rb +37 -25
  42. data/lib/ccrypto/java/ext/x509_cert.rb +429 -5
  43. data/lib/ccrypto/java/ext/x509_csr.rb +151 -0
  44. data/lib/ccrypto/java/jce_provider.rb +0 -11
  45. data/lib/ccrypto/java/keystore/jce_keystore.rb +205 -0
  46. data/lib/ccrypto/java/keystore/jks_keystore.rb +52 -0
  47. data/lib/ccrypto/java/keystore/keystore.rb +97 -0
  48. data/lib/ccrypto/java/keystore/pem_keystore.rb +147 -0
  49. data/lib/ccrypto/java/keystore/pkcs12_keystore.rb +56 -0
  50. data/lib/ccrypto/java/utils/comparator.rb +25 -2
  51. data/lib/ccrypto/java/version.rb +1 -1
  52. data/lib/ccrypto/java.rb +46 -0
  53. data/lib/ccrypto/provider.rb +139 -3
  54. metadata +40 -24
  55. data/ccrypto-java.gemspec +0 -44
  56. data/jars/bcmail-jdk15on-165.jar +0 -0
  57. data/jars/bcpg-jdk15on-165.jar +0 -0
  58. data/jars/bcpkix-jdk15on-165.jar +0 -0
  59. data/jars/bcprov-ext-jdk15on-165.jar +0 -0
  60. data/jars/bcprov-jdk15on-165.jar +0 -0
  61. data/jars/bctls-jdk15on-165.jar +0 -0
  62. data/lib/ccrypto/java/keybundle_store/pkcs12.rb +0 -125
@@ -1,125 +0,0 @@
1
-
2
- require_relative '../data_conversion'
3
-
4
- module Ccrypto
5
- module Java
6
-
7
- module PKCS12
8
- include TR::CondUtils
9
- include DataConversion
10
-
11
- class PKCS12StorageException < KeyBundleStorageException; end
12
-
13
- module ClassMethods
14
- include DataConversion
15
-
16
- def from_pkcs12(bin, &block)
17
-
18
- raise PKCS12StorageException, "block is required" if not block
19
-
20
- storeType = block.call(:store_type)
21
- storeType = "PKCS12" if is_empty?(storeType)
22
-
23
- prof = block.call(:jce_provider)
24
- if not_empty?(prof)
25
- ks = java.security.KeyStore.getInstance(storeType, prof)
26
- else
27
- ks = java.security.KeyStore.getInstance(storeType)
28
- end
29
-
30
- pass = block.call(:p12_pass) || block.call(:jks_pass)
31
- name = block.call(:p12_name) || block.call(:jks_name)
32
-
33
- #case bin
34
- #when String
35
- # bbin = bin.to_java_bytes
36
- #when ::Java::byte[]
37
- # bbin = bin
38
- #else
39
- # raise KeypairEngineException, "Java byte array is expected. Given #{bin.class}"
40
- #end
41
-
42
- bbin = to_java_bytes(bin)
43
-
44
- ks.load(java.io.ByteArrayInputStream.new(bbin),pass.to_java.toCharArray)
45
-
46
- name = ks.aliases.to_a.first if is_empty?(name)
47
-
48
- userCert = Ccrypto::X509Cert.new(ks.getCertificate(name))
49
- chain = ks.get_certificate_chain(name).collect { |c| Ccrypto::X509Cert.new(c) }
50
- chain = chain.delete_if { |c| c.equal?(userCert) }
51
-
52
- key = ks.getKey(name, pass.to_java.toCharArray)
53
- case key
54
- when java.security.interfaces.ECPrivateKey
55
- [Ccrypto::Java::ECCKeyBundle.new(key), userCert, chain]
56
- when java.security.interfaces.RSAPrivateKey
57
- [Ccrypto::Java::RSAKeyBundle.new(key), userCert, chain]
58
- else
59
- raise PKCS12StorageException, "Unknown key type #{key}"
60
- end
61
-
62
- end
63
-
64
- end
65
- def self.included(klass)
66
- klass.extend(ClassMethods)
67
- end
68
-
69
- def to_pkcs12(&block)
70
-
71
- raise KeypairEngineException, "block is required" if not block
72
-
73
- storeType = block.call(:store_type)
74
- storeType = "PKCS12" if is_empty?(storeType)
75
-
76
- prof = block.call(:jce_provider)
77
- if not_empty?(prof)
78
- ks = java.security.KeyStore.getInstance(storeType, prof)
79
- else
80
- ks = java.security.KeyStore.getInstance(storeType)
81
- end
82
-
83
- ks.load(nil,nil)
84
-
85
- gcert = block.call(:cert)
86
- raise KeypairEngineException, "PKCS12 requires the X.509 certificate" if is_empty?(gcert)
87
-
88
- ca = block.call(:certchain) || [cert]
89
- ca = [cert] if is_empty?(ca)
90
- ca = ca.unshift(gcert) if not ca.first.equal?(gcert)
91
- ca = ca.collect { |c|
92
- Ccrypto::X509Cert.to_java_cert(c)
93
- }
94
-
95
- pass = block.call(:p12_pass) || block.call(:jks_pass)
96
- raise KeypairEngineException, "Password is required" if is_empty?(pass)
97
-
98
- name = block.call(:p12_name) || block.call(:jks_name)
99
- name = "Ccrypto P12" if is_empty?(name)
100
-
101
- keypair = block.call(:keypair)
102
- raise KeypairEngineException, "Keypair is required" if is_empty?(keypair)
103
-
104
- ks.setKeyEntry(name, keypair.private, pass.to_java.toCharArray, ca.to_java(java.security.cert.Certificate))
105
-
106
- baos = java.io.ByteArrayOutputStream.new
107
- ks.store(baos, pass.to_java.toCharArray)
108
- res = baos.toByteArray
109
-
110
- outForm = block.call(:out_format)
111
- case outForm
112
- when :b64
113
- to_b64(res)
114
- when :hex
115
- to_hex(res)
116
- else
117
- res
118
- end
119
-
120
- end
121
-
122
- end
123
-
124
- end
125
- end