virgil-crypto 2.3.0 → 3.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -0
  3. data/.gitmodules +0 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +0 -0
  6. data/README.md +113 -9
  7. data/Rakefile +0 -0
  8. data/ext/native/src/.clang-format +37 -0
  9. data/ext/native/src/.gitignore +3 -0
  10. data/ext/native/src/.travis.yml +2 -1
  11. data/ext/native/src/CMakeLists.txt +66 -63
  12. data/ext/native/src/ChangeLog +114 -2
  13. data/ext/native/src/Dockerfile_Golang +29 -8
  14. data/ext/native/src/Jenkinsfile +61 -50
  15. data/ext/native/src/LICENSE +0 -0
  16. data/ext/native/src/README.md +137 -167
  17. data/ext/native/src/VERSION +1 -1
  18. data/ext/native/src/benchmark.md +140 -0
  19. data/ext/native/src/benchmark/CMakeLists.txt +0 -0
  20. data/ext/native/src/benchmark/benchmark_cipher.cxx +0 -0
  21. data/ext/native/src/benchmark/benchmark_hash.cxx +0 -0
  22. data/ext/native/src/benchmark/benchmark_keys.cxx +0 -0
  23. data/ext/native/src/benchmark/benchmark_pythia.cxx +61 -0
  24. data/ext/native/src/benchmark/benchmark_random.cxx +0 -0
  25. data/ext/native/src/benchmark/benchmark_signer.cxx +0 -0
  26. data/ext/native/src/ci/install-dependencies.sh +8 -12
  27. data/ext/native/src/ci/publish-docs.sh +107 -22
  28. data/ext/native/src/ci/travis-deployment-key.enc +0 -0
  29. data/ext/native/src/cmake/TransitiveArgs.cmake +78 -0
  30. data/ext/native/src/cmake/TransitiveToolchainArgs.cmake +105 -0
  31. data/ext/native/src/cmake/add_mono_metadata.cmake +103 -0
  32. data/ext/native/src/cmake/apple.cmake +56 -11
  33. data/ext/native/src/cmake/aux_source_directory_to_file.cmake +0 -0
  34. data/ext/native/src/cmake/check_pointer_size.cmake +0 -0
  35. data/ext/native/src/cmake/copy_all_files.cmake +0 -0
  36. data/ext/native/src/cmake/file_regex_replace.cmake +0 -0
  37. data/ext/native/src/cmake/find_host_utils.cmake +0 -0
  38. data/ext/native/src/cmake/uppercase_first_char.cmake +0 -0
  39. data/ext/native/src/cmake/uppercase_namespaces.cmake +3 -0
  40. data/ext/native/src/cmake/virgil_depends.cmake +0 -0
  41. data/ext/native/src/cmake/virgil_depends_local.cmake +2 -0
  42. data/ext/native/src/docs/.gitignore +0 -0
  43. data/ext/native/src/lib/CMakeLists.txt +59 -1
  44. data/ext/native/src/lib/Doxyfile.in +1 -1
  45. data/ext/native/src/lib/Info.plist.in +0 -0
  46. data/ext/native/src/lib/cmake/config.cmake.in +0 -0
  47. data/ext/native/src/lib/include/virgil/crypto/VirgilByteArrayUtils.h +0 -0
  48. data/ext/native/src/lib/include/virgil/crypto/VirgilChunkCipher.h +0 -0
  49. data/ext/native/src/lib/include/virgil/crypto/VirgilCipherBase.h +0 -0
  50. data/ext/native/src/lib/include/virgil/crypto/VirgilContentInfo.h +0 -0
  51. data/ext/native/src/lib/include/virgil/crypto/VirgilCrypto.h +13 -0
  52. data/ext/native/src/lib/include/virgil/crypto/VirgilCryptoError.h +0 -0
  53. data/ext/native/src/lib/include/virgil/crypto/VirgilCustomParams.h +0 -0
  54. data/ext/native/src/lib/include/virgil/crypto/VirgilKeyPair.h +30 -0
  55. data/ext/native/src/lib/include/virgil/crypto/VirgilSignerBase.h +0 -0
  56. data/ext/native/src/lib/include/virgil/crypto/VirgilStreamCipher.h +0 -0
  57. data/ext/native/src/lib/include/virgil/crypto/VirgilStreamSigner.h +0 -0
  58. data/ext/native/src/lib/include/virgil/crypto/VirgilTinyCipher.h +0 -0
  59. data/ext/native/src/lib/include/virgil/crypto/VirgilVersion.h +0 -0
  60. data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilAsymmetricCipher.h +17 -0
  61. data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilHKDF.h +0 -0
  62. data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilPBKDF.h +0 -0
  63. data/ext/native/src/lib/include/virgil/crypto/foundation/VirgilSystemCryptoError.h +0 -0
  64. data/ext/native/src/lib/include/virgil/crypto/foundation/asn1/VirgilAsn1Compatible.h +0 -0
  65. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSContent.h +0 -0
  66. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSContentInfo.h +0 -0
  67. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSEncryptedContent.h +0 -0
  68. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSEnvelopedData.h +0 -0
  69. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSKeyTransRecipient.h +0 -0
  70. data/ext/native/src/lib/include/virgil/crypto/foundation/cms/VirgilCMSPasswordRecipient.h +0 -0
  71. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFS.h +0 -0
  72. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSEncryptedMessage.h +0 -0
  73. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSInitiatorPrivateInfo.h +0 -0
  74. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSInitiatorPublicInfo.h +0 -0
  75. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSPrivateKey.h +0 -0
  76. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSPublicKey.h +0 -0
  77. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSResponderPrivateInfo.h +0 -0
  78. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSResponderPublicInfo.h +0 -0
  79. data/ext/native/src/lib/include/virgil/crypto/pfs/VirgilPFSSession.h +0 -0
  80. data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationCipher.h +0 -0
  81. data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationDH.h +0 -0
  82. data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationHash.h +0 -0
  83. data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationKDF.h +0 -0
  84. data/ext/native/src/lib/include/virgil/crypto/primitive/VirgilOperationRandom.h +0 -0
  85. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythia.h +181 -0
  86. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaBlindResult.h +89 -0
  87. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaContext.h +72 -0
  88. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaError.h +161 -0
  89. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaProveResult.h +89 -0
  90. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaTransformResult.h +91 -0
  91. data/ext/native/src/lib/include/virgil/crypto/pythia/VirgilPythiaTransformationKeyPair.h +87 -0
  92. data/ext/native/src/lib/include/virgil/crypto/pythia/virgil_pythia_c.h +203 -0
  93. data/ext/native/src/lib/include/virgil/crypto/stream/VirgilBytesDataSink.h +0 -0
  94. data/ext/native/src/lib/include/virgil/crypto/stream/VirgilBytesDataSource.h +0 -0
  95. data/ext/native/src/lib/mainpage.dox +6 -0
  96. data/ext/native/src/lib/module.modulemap +7 -0
  97. data/ext/native/src/lib/src/VirgilAsn1Alg.cxx +0 -0
  98. data/ext/native/src/lib/src/VirgilAsn1Alg.h +0 -0
  99. data/ext/native/src/lib/src/VirgilAsn1Compatible.cxx +0 -0
  100. data/ext/native/src/lib/src/VirgilAsymmetricCipher.cxx +82 -0
  101. data/ext/native/src/lib/src/VirgilByteArrayUtils.cxx +0 -0
  102. data/ext/native/src/lib/src/VirgilCMSContent.cxx +0 -0
  103. data/ext/native/src/lib/src/VirgilCMSContentInfo.cxx +0 -0
  104. data/ext/native/src/lib/src/VirgilCMSEncryptedContent.cxx +0 -0
  105. data/ext/native/src/lib/src/VirgilCMSEnvelopedData.cxx +0 -0
  106. data/ext/native/src/lib/src/VirgilCMSKeyTransRecipient.cxx +0 -0
  107. data/ext/native/src/lib/src/VirgilCMSPasswordRecipient.cxx +0 -0
  108. data/ext/native/src/lib/src/VirgilChunkCipher.cxx +0 -0
  109. data/ext/native/src/lib/src/VirgilCipherBase.cxx +0 -0
  110. data/ext/native/src/lib/src/VirgilConfig.cxx +51 -0
  111. data/ext/native/src/lib/src/VirgilConfig.h.in +43 -1
  112. data/ext/native/src/lib/src/VirgilContentInfo.cxx +0 -0
  113. data/ext/native/src/lib/src/VirgilCryptoError.cxx +0 -0
  114. data/ext/native/src/lib/src/VirgilCustomParams.cxx +0 -0
  115. data/ext/native/src/lib/src/VirgilDataSink.cxx +0 -0
  116. data/ext/native/src/lib/src/VirgilHKDF.cxx +0 -0
  117. data/ext/native/src/lib/src/VirgilKeyPair.cxx +19 -0
  118. data/ext/native/src/lib/src/VirgilOID.h +0 -0
  119. data/ext/native/src/lib/src/VirgilPBKDF.cxx +0 -0
  120. data/ext/native/src/lib/src/VirgilSignerBase.cxx +0 -0
  121. data/ext/native/src/lib/src/VirgilStreamCipher.cxx +0 -0
  122. data/ext/native/src/lib/src/VirgilStreamSigner.cxx +0 -0
  123. data/ext/native/src/lib/src/VirgilSystemCryptoError.cxx +0 -0
  124. data/ext/native/src/lib/src/VirgilTagFilter.cxx +0 -0
  125. data/ext/native/src/lib/src/VirgilTagFilter.h +0 -0
  126. data/ext/native/src/lib/src/VirgilTinyCipher.cxx +0 -0
  127. data/ext/native/src/lib/src/VirgilVersion.cxx.in +0 -0
  128. data/ext/native/src/lib/src/mbedtls_context.h +0 -0
  129. data/ext/native/src/lib/src/mbedtls_context_policy_spec.h +0 -0
  130. data/ext/native/src/lib/src/mbedtls_type_utils.h +0 -0
  131. data/ext/native/src/lib/src/pfs/VirgilPFS.cxx +0 -0
  132. data/ext/native/src/lib/src/pfs/VirgilPFSEncryptedMessage.cxx +0 -0
  133. data/ext/native/src/lib/src/pfs/VirgilPFSInitiatorPrivateInfo.cxx +0 -0
  134. data/ext/native/src/lib/src/pfs/VirgilPFSInitiatorPublicInfo.cxx +0 -0
  135. data/ext/native/src/lib/src/pfs/VirgilPFSPrivateKey.cxx +0 -0
  136. data/ext/native/src/lib/src/pfs/VirgilPFSPublicKey.cxx +0 -0
  137. data/ext/native/src/lib/src/pfs/VirgilPFSResponderPrivateInfo.cxx +0 -0
  138. data/ext/native/src/lib/src/pfs/VirgilPFSResponderPublicInfo.cxx +0 -0
  139. data/ext/native/src/lib/src/pfs/VirgilPFSSession.cxx +0 -0
  140. data/ext/native/src/lib/src/primitive/VirgilOperationCipher.cxx +0 -0
  141. data/ext/native/src/lib/src/primitive/VirgilOperationDH.cxx +0 -0
  142. data/ext/native/src/lib/src/primitive/VirgilOperationHash.cxx +0 -0
  143. data/ext/native/src/lib/src/primitive/VirgilOperationKDF.cxx +0 -0
  144. data/ext/native/src/lib/src/primitive/VirgilOperationRandom.cxx +0 -0
  145. data/ext/native/src/lib/src/pythia/VirgilPythia.cxx +202 -0
  146. data/ext/native/src/lib/src/pythia/VirgilPythiaContext.cxx +116 -0
  147. data/ext/native/src/lib/src/pythia/VirgilPythiaError.cxx +58 -0
  148. data/ext/native/src/lib/src/pythia/virgil_pythia_c.cxx +129 -0
  149. data/ext/native/src/lib/src/stream/VirgilBytesDataSink.cxx +0 -0
  150. data/ext/native/src/lib/src/stream/VirgilBytesDataSource.cxx +0 -0
  151. data/ext/native/src/lib/src/utils.h +3 -2
  152. data/ext/native/src/libs_ext/mbedtls/configs/config.h +0 -0
  153. data/ext/native/src/libs_ext/mbedtls/configs/config_desktop.h +0 -0
  154. data/ext/native/src/libs_ext/mbedtls/mbedtls.cmake +0 -0
  155. data/ext/native/src/{cmake/cmake_args.cmake → libs_ext/pythia/pythia.cmake} +24 -28
  156. data/ext/native/src/libs_ext/rapidjson/rapidjson.cmake +0 -0
  157. data/ext/native/src/libs_ext/tinyformat/cmake/config.cmake.in +0 -0
  158. data/ext/native/src/libs_ext/tinyformat/tinyformat.cmake +0 -0
  159. data/ext/native/src/migration-2.0.md +0 -0
  160. data/ext/native/src/tests/CMakeLists.txt +0 -0
  161. data/ext/native/src/tests/catch.hpp +0 -0
  162. data/ext/native/src/tests/data/test_data_pfs_with_otc.json +0 -0
  163. data/ext/native/src/tests/data/test_data_pfs_without_otc.json +0 -0
  164. data/ext/native/src/tests/deterministic_keys.h +293 -0
  165. data/ext/native/src/tests/rsa_keys.h +229 -123
  166. data/ext/native/src/tests/test_asn1_writer.cxx +0 -0
  167. data/ext/native/src/tests/test_asymmetric_cipher.cxx +65 -0
  168. data/ext/native/src/tests/test_base64.cxx +0 -0
  169. data/ext/native/src/tests/test_byte_array_utils.cxx +0 -0
  170. data/ext/native/src/tests/test_chunk_cipher.cxx +0 -0
  171. data/ext/native/src/tests/test_cipher.cxx +8 -4
  172. data/ext/native/src/tests/test_cipher_base.cxx +0 -0
  173. data/ext/native/src/tests/test_contract_copy_move.cxx +4 -1
  174. data/ext/native/src/tests/test_data_pfs.h +0 -0
  175. data/ext/native/src/tests/test_hash.cxx +0 -0
  176. data/ext/native/src/tests/test_hkdf.cxx +0 -0
  177. data/ext/native/src/tests/test_key_pair.cxx +65 -3
  178. data/ext/native/src/tests/test_pbe.cxx +0 -0
  179. data/ext/native/src/tests/test_pbkdf.cxx +0 -0
  180. data/ext/native/src/tests/test_pfs.cxx +0 -0
  181. data/ext/native/src/tests/test_pythia.cxx +157 -0
  182. data/ext/native/src/tests/test_random.cxx +0 -0
  183. data/ext/native/src/tests/test_runner.cxx +0 -0
  184. data/ext/native/src/tests/test_signer.cxx +0 -0
  185. data/ext/native/src/tests/test_stream_cipher.cxx +0 -0
  186. data/ext/native/src/tests/test_stream_data_source.cxx +0 -0
  187. data/ext/native/src/tests/test_symmetric_cipher.cxx +0 -0
  188. data/ext/native/src/tests/test_tag_filter.cxx +0 -0
  189. data/ext/native/src/tests/test_tiny_cipher.cxx +0 -0
  190. data/ext/native/src/utils/build.bat +0 -0
  191. data/ext/native/src/utils/build.sh +238 -68
  192. data/ext/native/src/utils/zip.vbs +0 -0
  193. data/ext/native/src/virgil-crypto.sublime-project +15 -0
  194. data/ext/native/src/wrappers/asmjs/CMakeLists.txt +0 -8
  195. data/ext/native/src/wrappers/emsdk/CMakeLists.txt +2 -2
  196. data/ext/native/src/wrappers/emsdk/error.js +0 -0
  197. data/ext/native/src/wrappers/emsdk/example.html +152 -31
  198. data/ext/native/src/wrappers/emsdk/helpers.js +140 -135
  199. data/ext/native/src/wrappers/emsdk/patch_embind.pl +0 -0
  200. data/ext/native/src/wrappers/emsdk/wrapper.cxx +55 -0
  201. data/ext/native/src/wrappers/go/CMakeLists.txt +6 -5
  202. data/ext/native/src/wrappers/java/CMakeLists.txt +27 -4
  203. data/ext/native/src/wrappers/java/src/JniLoader.java +167 -0
  204. data/ext/native/src/wrappers/java/src/VirgilStreamDataSink.java +0 -0
  205. data/ext/native/src/wrappers/java/src/VirgilStreamDataSource.java +0 -0
  206. data/ext/native/src/wrappers/net/CMakeLists.txt +41 -8
  207. data/ext/native/src/wrappers/net/cmake/UseCSharp.cmake +5 -5
  208. data/ext/native/src/wrappers/net/src/VirgilStreamDataSink.cs +0 -0
  209. data/ext/native/src/wrappers/net/src/VirgilStreamDataSource.cs +0 -0
  210. data/ext/native/src/wrappers/nodejs/checksum.txt +66 -0
  211. data/ext/native/src/wrappers/php/CMakeLists.txt +2 -5
  212. data/ext/native/src/wrappers/php/tests/CMakeLists.txt +6 -0
  213. data/ext/native/src/wrappers/php/tests/VirgilChunkCipher_Test.php.in +0 -0
  214. data/ext/native/src/wrappers/php/tests/VirgilCustomParams_Test.php.in +0 -0
  215. data/ext/native/src/wrappers/php/tests/VirgilKDF_Test.php.in +0 -0
  216. data/ext/native/src/wrappers/php/tests/VirgilPBE_Test.php.in +0 -0
  217. data/ext/native/src/wrappers/php/tests/VirgilPBKDF_Test.php.in +0 -0
  218. data/ext/native/src/wrappers/php/tests/VirgilPythia_Test.php.in +87 -0
  219. data/ext/native/src/wrappers/php/tests/VirgilStreamCipher_Test.php.in +0 -0
  220. data/ext/native/src/wrappers/php/tests/VirgilStreamSigner_Test.php.in +0 -0
  221. data/ext/native/src/wrappers/php/tests/VirgilVersion_Test.php.in +0 -0
  222. data/ext/native/src/wrappers/python/CMakeLists.txt +4 -1
  223. data/ext/native/src/wrappers/ruby/CMakeLists.txt +4 -1
  224. data/ext/native/src/wrappers/swig/common.i +0 -0
  225. data/ext/native/src/wrappers/swig/csharp/FixedArray.i +0 -0
  226. data/ext/native/src/wrappers/swig/csharp/VirgilByteArray.i +0 -0
  227. data/ext/native/src/wrappers/swig/csharp/common.i +0 -0
  228. data/ext/native/src/wrappers/swig/csharp/csharphead.swg.in +0 -0
  229. data/ext/native/src/wrappers/swig/go/common.i.in +7 -0
  230. data/ext/native/src/wrappers/swig/java/VirgilByteArray.i +0 -0
  231. data/ext/native/src/wrappers/swig/java/common.i +6 -0
  232. data/ext/native/src/wrappers/swig/php/common.i +0 -0
  233. data/ext/native/src/wrappers/swig/php/php7/VirgilByteArray.i +0 -0
  234. data/ext/native/src/wrappers/swig/util.i +0 -0
  235. data/ext/native/src/wrappers/swig/wrapper.i.in +18 -7
  236. data/ext/native/src/wrappers/webasm/CMakeLists.txt +0 -8
  237. data/ext/rakefile.rb +77 -56
  238. data/lib/virgil/crypto.rb +53 -9
  239. data/lib/virgil/crypto/access_token_signer.rb +79 -0
  240. data/lib/virgil/crypto/bytes.rb +81 -17
  241. data/lib/virgil/crypto/card_crypto.rb +115 -0
  242. data/lib/virgil/crypto/crypto_exception.rb +40 -0
  243. data/lib/virgil/crypto/hash_algorithm.rb +82 -0
  244. data/lib/virgil/crypto/key_pair.rb +41 -0
  245. data/lib/virgil/crypto/key_pair_type.rb +98 -0
  246. data/lib/virgil/crypto/private_key.rb +40 -0
  247. data/lib/virgil/crypto/private_key_exporter.rb +67 -0
  248. data/lib/virgil/crypto/public_key.rb +40 -0
  249. data/lib/virgil/crypto/{virgil_stream_data_sink.rb → stream_data_sink.rb} +12 -12
  250. data/lib/virgil/crypto/{virgil_stream_data_source.rb → stream_data_source.rb} +12 -12
  251. data/lib/virgil/crypto/validation.rb +59 -0
  252. data/lib/virgil/crypto/version.rb +35 -1
  253. data/lib/virgil/crypto/virgil_crypto.rb +595 -0
  254. data/lib/virgil/native_crypto.rb +80 -60
  255. data/lib/virgil/os.rb +40 -6
  256. data/secrets.tar.enc +0 -0
  257. data/virgil-crypto.gemspec +6 -7
  258. metadata +62 -12
  259. data/ext/native/src/cmake/android.toolchain.cmake +0 -1697
@@ -37,6 +37,8 @@
37
37
  #include <string>
38
38
  #include <memory>
39
39
 
40
+ #include "VirgilConfig.h"
41
+
40
42
  #include <virgil/crypto/VirgilVersion.h>
41
43
  #include <virgil/crypto/VirgilByteArray.h>
42
44
  #include <virgil/crypto/VirgilByteArrayUtils.h>
@@ -74,12 +76,15 @@
74
76
  #include <virgil/crypto/pfs/VirgilPFSResponderPrivateInfo.h>
75
77
  #include <virgil/crypto/pfs/VirgilPFS.h>
76
78
 
79
+ #include <virgil/crypto/pythia/VirgilPythia.h>
80
+
77
81
  #include "@VIRGIL_EMBIND_FILE@"
78
82
 
79
83
  using namespace emscripten;
80
84
  using namespace virgil::crypto;
81
85
  using namespace virgil::crypto::foundation;
82
86
  using namespace virgil::crypto::pfs;
87
+ using namespace virgil::crypto::pythia;
83
88
 
84
89
  namespace virgil { namespace crypto {
85
90
 
@@ -144,6 +149,12 @@ EMSCRIPTEN_BINDINGS(virgil_crypto) {
144
149
  .class_function("patchVersion", &VirgilVersion::patchVersion)
145
150
  ;
146
151
 
152
+ class_<VirgilConfig>("Config")
153
+ .class_function("hasFeatureStreamImpl", &VirgilConfig::hasFeatureStreamImpl)
154
+ .class_function("hasFeaturePythiaImpl", &VirgilConfig::hasFeaturePythiaImpl)
155
+ .class_function("hasFeaturePythiaMultiThread", &VirgilConfig::hasFeaturePythiaMultiThread)
156
+ ;
157
+
147
158
  register_vector<unsigned char>("VirgilByteArray")
148
159
  .function("data", VirgilByteArray_data)
149
160
  .function("assign", VirgilByteArray_assign)
@@ -156,6 +167,8 @@ EMSCRIPTEN_BINDINGS(virgil_crypto) {
156
167
  .class_function("generate", &VirgilKeyPair::generate)
157
168
  .class_function("generateRecommended", &VirgilKeyPair::generateRecommended)
158
169
  .class_function("generateFrom", &VirgilKeyPair::generateFrom)
170
+ .class_function("generateFromKeyMaterial", &VirgilKeyPair::generateFromKeyMaterial)
171
+ .class_function("generateRecommendedFromKeyMaterial", &VirgilKeyPair::generateRecommendedFromKeyMaterial)
159
172
  .class_function("isKeyPairMatch", &VirgilKeyPair::isKeyPairMatch)
160
173
  .class_function("checkPrivateKeyPassword", &VirgilKeyPair::checkPrivateKeyPassword)
161
174
  .class_function("isPrivateKeyEncrypted", &VirgilKeyPair::isPrivateKeyEncrypted)
@@ -518,3 +531,45 @@ EMSCRIPTEN_BINDINGS(virgil_crypto_pfs) {
518
531
  .function("setSession", &VirgilPFS::setSession)
519
532
  ;
520
533
  }
534
+
535
+ #if VIRGIL_CRYPTO_FEATURE_PYTHIA
536
+
537
+ EMSCRIPTEN_BINDINGS(virgil_crypto_pythia) {
538
+ class_<VirgilPythia>("VirgilPythia")
539
+ .constructor<>()
540
+ .function("blind", &VirgilPythia::blind)
541
+ .function("deblind", &VirgilPythia::deblind)
542
+ .function("computeTransformationKeyPair", &VirgilPythia::computeTransformationKeyPair)
543
+ .function("transform", &VirgilPythia::transform)
544
+ .function("prove", &VirgilPythia::prove)
545
+ .function("verify", &VirgilPythia::verify)
546
+ .function("getPasswordUpdateToken", &VirgilPythia::getPasswordUpdateToken)
547
+ .function("updateDeblindedWithToken", &VirgilPythia::updateDeblindedWithToken)
548
+ ;
549
+
550
+ class_<VirgilPythiaBlindResult>("VirgilPythiaBlindResult")
551
+ .constructor<VirgilByteArray, VirgilByteArray>()
552
+ .function("blindedPassword", &VirgilPythiaBlindResult::blindedPassword)
553
+ .function("blindingSecret", &VirgilPythiaBlindResult::blindingSecret)
554
+ ;
555
+
556
+ class_<VirgilPythiaProveResult>("VirgilPythiaProveResult")
557
+ .constructor<VirgilByteArray, VirgilByteArray>()
558
+ .function("proofValueC", &VirgilPythiaProveResult::proofValueC)
559
+ .function("proofValueU", &VirgilPythiaProveResult::proofValueU)
560
+ ;
561
+
562
+ class_<VirgilPythiaTransformationKeyPair>("VirgilPythiaTransformationKeyPair")
563
+ .constructor<VirgilByteArray, VirgilByteArray>()
564
+ .function("privateKey", &VirgilPythiaTransformationKeyPair::privateKey)
565
+ .function("publicKey", &VirgilPythiaTransformationKeyPair::publicKey)
566
+ ;
567
+
568
+ class_<VirgilPythiaTransformResult>("VirgilPythiaTransformResult")
569
+ .constructor<VirgilByteArray, VirgilByteArray>()
570
+ .function("transformedPassword", &VirgilPythiaTransformResult::transformedPassword)
571
+ .function("transformedTweak", &VirgilPythiaTransformResult::transformedTweak)
572
+ ;
573
+ }
574
+
575
+ #endif /* VIRGIL_CRYPTO_FEATURE_PYTHIA */
@@ -75,13 +75,14 @@ message (STATUS "Size of Golang integer: ${GO_INT_SIZE}")
75
75
  set_property (SOURCE "${WRAPPER_INTERFACE_FILE}" PROPERTY CPLUSPLUS ON)
76
76
  set_property (SOURCE "${WRAPPER_INTERFACE_FILE}" PROPERTY SWIG_FLAGS "-ignoremissing;-cgo;-intgosize;${GO_INT_SIZE}")
77
77
 
78
- set (swig_generated_sources)
79
- swig_module_initialize (${GO_MODULE_NAME} go)
80
- swig_add_source_to_module (${GO_MODULE_NAME} swig_generated_source "${WRAPPER_INTERFACE_FILE}")
78
+ swig_add_library (${GO_MODULE_NAME}
79
+ TYPE STATIC
80
+ LANGUAGE go
81
+ SOURCES "${WRAPPER_INTERFACE_FILE}")
81
82
 
83
+ swig_link_libraries (${GO_MODULE_NAME} ${WRAPPED_LIB_NAME})
82
84
  set (GO_SWIG_TARGET_NAME ${SWIG_MODULE_${GO_MODULE_NAME}_REAL_NAME})
83
-
84
- add_library (${GO_SWIG_TARGET_NAME} STATIC ${swig_generated_source})
85
+ set_target_properties (${GO_SWIG_TARGET_NAME} PROPERTIES PREFIX "lib")
85
86
 
86
87
  install (PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/${GO_MODULE_NAME}.go" DESTINATION ".")
87
88
 
@@ -38,17 +38,24 @@ cmake_minimum_required (VERSION 3.10 FATAL_ERROR)
38
38
 
39
39
  project (${WRAPPED_LIB_NAME}_java)
40
40
 
41
+ #
41
42
  # Configure Java
43
+ #
42
44
  set (JAVA_MODULE_NAME ${PROJECT_NAME})
43
45
  set (JAVA_JAR_NAME ${JAVA_MODULE_NAME})
44
46
  set (JAVA_JAR_TARGET_NAME ${JAVA_MODULE_NAME}_jar)
45
47
  set (SWIG_MODULE_NAME ${JAVA_MODULE_NAME})
48
+ set(CMAKE_JAVA_COMPILE_FLAGS -source 1.7 -target 1.7)
46
49
 
50
+ #
47
51
  # Find Java
52
+ #
48
53
  find_host_package (Java REQUIRED)
49
54
  include (UseJava)
50
55
 
56
+ #
51
57
  # Find Java JNI
58
+ #
52
59
  if (ANDROID)
53
60
  find_path (JAVA_INCLUDE_PATH jni.h)
54
61
  set (JNI_INCLUDE_DIRS ${JAVA_INCLUDE_PATH})
@@ -57,13 +64,17 @@ else (ANDROID)
57
64
  endif (ANDROID)
58
65
  include_directories (SYSTEM ${JNI_INCLUDE_DIRS})
59
66
 
67
+ #
60
68
  # Make sure the nested directory structure exists
69
+ #
61
70
  set (JAVA_BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE INTERNAL "")
62
71
  set (JAVA_SWIG_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src CACHE INTERNAL "")
63
72
  file (MAKE_DIRECTORY ${JAVA_BINARY_DIRECTORY})
64
73
  file (MAKE_DIRECTORY ${JAVA_SWIG_OUTPUT_DIRECTORY})
65
74
 
75
+ #
66
76
  # Configure SWIG
77
+ #
67
78
  find_host_package (SWIG REQUIRED)
68
79
  include (${SWIG_USE_FILE})
69
80
 
@@ -83,12 +94,17 @@ set_property (
83
94
  SOURCE "${WRAPPER_INTERFACE_FILE}" PROPERTY SWIG_FLAGS "-ignoremissing;-package;com.virgilsecurity.crypto"
84
95
  )
85
96
 
86
- swig_add_module (${JAVA_MODULE_NAME} java ${WRAPPER_INTERFACE_FILE})
97
+ swig_add_library (${JAVA_MODULE_NAME}
98
+ LANGUAGE java
99
+ SOURCES "${WRAPPER_INTERFACE_FILE}")
100
+
87
101
  swig_link_libraries (${JAVA_MODULE_NAME} ${WRAPPED_LIB_NAME})
88
102
 
89
103
  set (JAVA_SWIG_TARGET_NAME ${SWIG_MODULE_${JAVA_MODULE_NAME}_REAL_NAME})
90
104
 
105
+ #
91
106
  # Configure assembly
107
+ #
92
108
  set_target_properties (${JAVA_SWIG_TARGET_NAME}
93
109
  PROPERTIES OUTPUT_NAME ${JAVA_MODULE_NAME})
94
110
  set_target_properties (${JAVA_SWIG_TARGET_NAME}
@@ -117,15 +133,20 @@ foreach (JAVA_FILE ${JAVA_SRC})
117
133
  )
118
134
  endforeach (JAVA_FILE)
119
135
 
136
+ #
120
137
  # Add assembly dependencies
138
+ #
121
139
  add_jar (${JAVA_JAR_TARGET_NAME}
122
- "${CMAKE_CURRENT_BINARY_DIR}/src/VirgilStreamDataSink.java"
123
- "${CMAKE_CURRENT_BINARY_DIR}/src/VirgilStreamDataSource.java"
140
+ # Just add one source to satisfy precondition for 'java_sources' file creation.
141
+ # All *.java files will be added when SWIG generates them.
142
+ "${CMAKE_CURRENT_BINARY_DIR}/src/JniLoader.java"
124
143
  OUTPUT_NAME ${JAVA_JAR_NAME}
125
144
  )
126
145
  add_dependencies (${JAVA_JAR_TARGET_NAME} ${JAVA_SWIG_TARGET_NAME})
127
146
 
128
- # Payload 'java_sources' file with generated classes
147
+ #
148
+ # Payload file 'java_sources' with generated classes and custom classes.
149
+ #
129
150
  get_property (JAVA_CLASS_DIR TARGET ${JAVA_JAR_TARGET_NAME} PROPERTY CLASS_DIR)
130
151
  if (NOT JAVA_CLASS_DIR)
131
152
  get_property (JAVA_CLASS_DIR TARGET ${JAVA_JAR_TARGET_NAME} PROPERTY CLASSDIR)
@@ -142,7 +163,9 @@ add_custom_command (TARGET ${JAVA_SWIG_TARGET_NAME} POST_BUILD
142
163
  COMMENT "Create java source list file: ${JAVA_SOURCE_LIST_FILE}."
143
164
  )
144
165
 
166
+ #
145
167
  # Install
168
+ #
146
169
  set (PLATFORM_VERSION "${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}" PARENT_SCOPE)
147
170
 
148
171
  if (ANDROID)
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Copyright (C) 2015-2018 Virgil Security Inc.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * (1) Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ *
13
+ * (2) Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in
15
+ * the documentation and/or other materials provided with the
16
+ * distribution.
17
+ *
18
+ * (3) Neither the name of the copyright holder nor the names of its
19
+ * contributors may be used to endorse or promote products derived from
20
+ * this software without specific prior written permission.
21
+ *
22
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
23
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ * POSSIBILITY OF SUCH DAMAGE.
33
+ *
34
+ * Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
35
+ */
36
+
37
+ package com.virgilsecurity.crypto;
38
+
39
+ import java.io.*;
40
+ import java.util.logging.Logger;
41
+
42
+
43
+ public class JniLoader {
44
+ private static final Logger LOGGER = Logger.getLogger(JniLoader.class.getName());
45
+
46
+ private static final String MACOS_OS_NAME = "mac os";
47
+ private static final String LINUX_OS_NAME = "linux";
48
+ private static final String WINDOWS_OS_NAME = "windows";
49
+ private static final String UNKNOWN_OS = "unknown";
50
+
51
+ private static final String MACOS_LIBS_DIRECTORY = MACOS_OS_NAME;
52
+ private static final String LINUX_LIBS_DIRECTORY = LINUX_OS_NAME;
53
+ private static final String WINDOWS_LIBS_DIRECTORY = WINDOWS_OS_NAME;
54
+
55
+ private static final String SEPARATOR = "/";
56
+
57
+ static {
58
+ try {
59
+ loadNativeLibrary("virgil_crypto_java");
60
+ } catch (Exception error) {
61
+ LOGGER.severe("JNI library failed to load.\n" +
62
+ "Try to add OS specific JNI library to java.library.path, " +
63
+ "or to put all libraries into the \'resources\' folder with such structure:\n" +
64
+ "../src/main/resources\n" +
65
+ "|\n" +
66
+ "+---linux\n" +
67
+ "|\t|\n" +
68
+ "|\t+---virgil_crypto_java\n" +
69
+ "+---mac os\n" +
70
+ "|\t|\n" +
71
+ "|\t+---virgil_crypto_java\n"
72
+ +"+---windows\n" +
73
+ "\t|\n" +
74
+ "\t+---amd64\n" +
75
+ "\t|\t|\n" +
76
+ "\t|\t+---virgil_crypto_java\n" +
77
+ "\t+---x86\n" +
78
+ "\t\t|\n" +
79
+ "\t\t+---virgil_crypto_java");
80
+
81
+ LOGGER.severe(error.getMessage());
82
+ }
83
+ }
84
+
85
+ private static void loadNativeLibrary(String libraryName) throws IOException {
86
+ try {
87
+ System.loadLibrary(libraryName);
88
+ // Library is loaded (Android or exists in java.library.path).
89
+ return;
90
+ } catch (Throwable e) {
91
+ // Library couldn't be loaded yet.
92
+ // We'll try to load it from resources.
93
+ LOGGER.warning("JNI library can't be loaded from java.library.path or Android specific folders.\n" +
94
+ "Please, check whether your path to JNI library is correct.");
95
+ }
96
+
97
+ LOGGER.info("Trying to load JNI library from resources.");
98
+
99
+ // Build native library name according to current system
100
+ String osName = System.getProperty("os.name").toLowerCase();
101
+ String os = getOS(osName);
102
+ String osArch = System.getProperty("os.arch").toLowerCase();
103
+
104
+ StringBuilder resourceName = new StringBuilder();
105
+ resourceName.append(getResourceDirectory(os, osArch)).append(SEPARATOR).append(libraryName);
106
+
107
+ // Save native library as temporary file
108
+ InputStream in = virgil_crypto_javaJNI.class.getClassLoader().getResourceAsStream(resourceName.toString());
109
+ if (in == null) {
110
+ LOGGER.warning("Can't load JNI library from resources.");
111
+ throw new FileNotFoundException("Resource \'" + resourceName.toString() + "\' not found");
112
+ }
113
+
114
+ byte[] buffer = new byte[1024];
115
+ int read;
116
+ File temp = File.createTempFile(libraryName, getLibraryFileSuffix(os));
117
+
118
+ FileOutputStream fos = new FileOutputStream(temp);
119
+
120
+ while ((read = in.read(buffer)) != -1) {
121
+ fos.write(buffer, 0, read);
122
+ }
123
+ fos.close();
124
+ in.close();
125
+
126
+ System.load(temp.getAbsolutePath());
127
+ }
128
+
129
+ private static final String getLibraryFileSuffix(String os) {
130
+ switch (os) {
131
+ case LINUX_OS_NAME:
132
+ case MACOS_OS_NAME:
133
+ return ".so";
134
+ case WINDOWS_OS_NAME:
135
+ return ".dll";
136
+ }
137
+ return "";
138
+ }
139
+
140
+ /**
141
+ * Get operation system by operation system name
142
+ *
143
+ * @param osName
144
+ * The OS name.
145
+ * @return
146
+ */
147
+ private static final String getOS(String osName) {
148
+ for (String os : new String[] { LINUX_OS_NAME, WINDOWS_OS_NAME, MACOS_OS_NAME }) {
149
+ if (osName.startsWith(os)) {
150
+ return os;
151
+ }
152
+ }
153
+ return UNKNOWN_OS;
154
+ }
155
+
156
+ private static final String getResourceDirectory(String os, String osArch) {
157
+ switch (os) {
158
+ case LINUX_OS_NAME:
159
+ return LINUX_LIBS_DIRECTORY;
160
+ case MACOS_OS_NAME:
161
+ return MACOS_LIBS_DIRECTORY;
162
+ case WINDOWS_OS_NAME:
163
+ return WINDOWS_LIBS_DIRECTORY + SEPARATOR + osArch;
164
+ }
165
+ return "";
166
+ }
167
+ }
@@ -51,9 +51,38 @@ set (CSHARP_MODULE_NAME ${PROJECT_NAME})
51
51
  set (SWIG_MODULE_NAME ${CSHARP_MODULE_NAME})
52
52
 
53
53
  # Find C#
54
- find_host_package( CSharp REQUIRED )
54
+ find_host_package (CSharp REQUIRED)
55
55
  include (${CSHARP_USE_FILE})
56
56
 
57
+ if (CSHARP_MONO_FOUND AND APPLE_PLATFORM MATCHES "(IOS|TVOS|WATCHOS)")
58
+ find_host_library(XAMARIN_FRAMEWORK_PATH "Xamarin.iOS")
59
+ if (NOT XAMARIN_FRAMEWORK_PATH)
60
+ message (FATAL_ERROR "Can't find Xamarin.iOS framework!")
61
+ endif ()
62
+
63
+ # Define Xamarin library for target Apple Platform.
64
+ if (APPLE_PLATFORM MATCHES "IOS")
65
+ set (XAMARIN_PLATFROM_LIB_NAME "Xamarin.iOS")
66
+
67
+ elseif (APPLE_PLATFORM MATCHES "TVOS")
68
+ set (XAMARIN_PLATFROM_LIB_NAME "Xamarin.TVOS")
69
+
70
+ elseif (APPLE_PLATFORM MATCHES "WATCHOS")
71
+ set (XAMARIN_PLATFROM_LIB_NAME "Xamarin.WatchOS")
72
+
73
+ endif ()
74
+
75
+ set (XAMARIN_PLATFROM_LIB
76
+ "${XAMARIN_FRAMEWORK_PATH}/Versions/Current/lib/mono/${XAMARIN_PLATFROM_LIB_NAME}/${XAMARIN_PLATFROM_LIB_NAME}.dll")
77
+
78
+ if (NOT EXISTS "${XAMARIN_PLATFROM_LIB}")
79
+ message (FATAL_ERROR "Xamarin library for traget ${APPLE_PLATFORM} is not found: ${XAMARIN_PLATFROM_LIB}")
80
+ endif ()
81
+
82
+ set (MONO_FRAMEWORKS "${XAMARIN_PLATFROM_LIB}")
83
+ message (STATUS "Mono frameworks: ${MONO_FRAMEWORKS}" )
84
+ endif()
85
+
57
86
  # Make sure the nested directory structure exists
58
87
  set (CSHARP_SOURCE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src CACHE INTERNAL "")
59
88
  set (CSHARP_BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE INTERNAL "")
@@ -86,7 +115,7 @@ set_property (
86
115
  SOURCE "${WRAPPER_INTERFACE_FILE}" PROPERTY SWIG_FLAGS "-ignoremissing"
87
116
  )
88
117
 
89
- if (CMAKE_CROSSCOMPILING AND APPLE)
118
+ if ( CMAKE_CROSSCOMPILING AND APPLE )
90
119
  set (WRAPPER_TYPE STATIC)
91
120
  else ()
92
121
  set (WRAPPER_TYPE SHARED)
@@ -99,14 +128,14 @@ swig_add_library (${CSHARP_MODULE_NAME}
99
128
  )
100
129
  set (CSHARP_SWIG_TARGET_NAME ${SWIG_MODULE_${CSHARP_MODULE_NAME}_REAL_NAME})
101
130
 
102
- if (WRAPPER_TYPE STREQUAL "STATIC")
131
+ # todo remove patching for mono when the issue https://github.com/swig/swig/issues/1165 is closed.
132
+ if (WRAPPER_TYPE STREQUAL "STATIC" AND APPLE)
103
133
  add_custom_command (TARGET ${CSHARP_SWIG_TARGET_NAME} POST_BUILD
104
134
  COMMAND ${CMAKE_COMMAND}
105
135
  ARGS
136
+ -DCSHARP_MODULE_NAME:STRING="${CSHARP_MODULE_NAME}"
106
137
  -DSRC:PATH="${CSHARP_SWIG_OUTPUT_DIRECTORY}/${CSHARP_MODULE_NAME}PINVOKE.cs"
107
- -DREGULAR_EXPRESSION:STRING="DllImport\\\(\\\"${CSHARP_MODULE_NAME}\\\""
108
- -DREPLACE_EXPRESSION:STRING="DllImport\(\\\"__Internal\\\""
109
- -P ${CMAKE_SOURCE_DIR}/cmake/file_regex_replace.cmake
138
+ -P ${CMAKE_SOURCE_DIR}/cmake/add_mono_metadata.cmake
110
139
  COMMENT "Patch generated source files for mono."
111
140
  )
112
141
  endif ()
@@ -143,8 +172,12 @@ if (UNIX AND NOT APPLE)
143
172
  endif ()
144
173
 
145
174
  # Configure assembly
175
+ if (CMAKE_SYSTEM_NAME MATCHES "Android")
176
+ set_target_properties (${CSHARP_SWIG_TARGET_NAME} PROPERTIES PREFIX "lib")
177
+ endif ()
178
+
146
179
  set_target_properties (${CSHARP_SWIG_TARGET_NAME}
147
- PROPERTIES OUTPUT_NAME ${CSHARP_MODULE_NAME})
180
+ PROPERTIES OUTPUT_NAME "${CSHARP_MODULE_NAME}")
148
181
  set_target_properties (${CSHARP_SWIG_TARGET_NAME}
149
182
  PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CSHARP_BINARY_DIRECTORY})
150
183
  set_target_properties (${CSHARP_SWIG_TARGET_NAME}
@@ -161,7 +194,7 @@ foreach (CS_FILE ${ASSEMBLY_SRC})
161
194
  endforeach (CS_FILE)
162
195
 
163
196
  # Add assembly dependencies
164
- csharp_add_library (${CSHARP_ASSEMBLY_NAME} "${CSHARP_SOURCE_DIRECTORY}/*.cs")
197
+ csharp_add_library (${CSHARP_ASSEMBLY_NAME} "${CSHARP_SOURCE_DIRECTORY}/*.cs" ${MONO_FRAMEWORKS})
165
198
  add_dependencies (${CSHARP_ASSEMBLY_NAME} ${CSHARP_SWIG_TARGET_NAME})
166
199
 
167
200
  # Install