rubythemis 0.9.1.1 → 0.9.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubythemis.rb +124 -64
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3bec344fffa5705ed6a25e7efc5db39a8c8f712
4
- data.tar.gz: a0981e988e300ef2ccf4cb89837c11efed8ee7b8
3
+ metadata.gz: b9d86848a6e79af3e64bb73c9f7398d7a21798ab
4
+ data.tar.gz: 3fafdff57341e45fa5a2a5594c26a44aaf073333
5
5
  SHA512:
6
- metadata.gz: e45a04401c921f2dc458bd987eb4e34cafe7bdb8aa4ab5303e55b20a61c2b6953593f9591fdd39186ab376e1b8c376cfba78971c027068366410a8494fb124ac
7
- data.tar.gz: ed0706d1c8bc948010571639e8604da407b08bbb690913d4a40690b419c068276c63c22769366905801a2fb03bf1d69ca2f34e621ecd3dc1b849f0eb81791b4d
6
+ metadata.gz: ac6285f33af9355895a06f219edf4c182e738abf708d243d259b83c0d41d3b93f2318d2eadd0f8e127eec6ce86487ec8da503ad4fbfc0516d731af3e7b7aae1a
7
+ data.tar.gz: 555da9a428bf300666444ac0df91b129450b297678c7b0e583fb1746edb269789c6c568ea7413c04e679c99b6e028e07c6cadfc6f06ebfde15c6b6dd5d9d7fe2
data/lib/rubythemis.rb CHANGED
@@ -26,45 +26,55 @@ module ThemisCommon
26
26
  end
27
27
 
28
28
  module ThemisImport
29
- extend FFI::Library
30
- ffi_lib 'themis'
29
+ extend FFI::Library
30
+ ffi_lib 'themis'
31
31
 
32
32
 
33
33
 
34
- callback :get_pub_key_by_id_type, [:pointer, :int, :pointer, :int, :pointer], :int
35
- callback :send_callback_type, [:pointer, :int, :uint], :int
36
- callback :receive_callback_type, [:pointer, :int, :uint], :int
34
+ callback :get_pub_key_by_id_type, [:pointer, :int, :pointer, :int, :pointer], :int
35
+ callback :send_callback_type, [:pointer, :int, :uint], :int
36
+ callback :receive_callback_type, [:pointer, :int, :uint], :int
37
37
 
38
- class Callbacks_struct < FFI::Struct
38
+ class Callbacks_struct < FFI::Struct
39
39
  layout :send_data, :send_callback_type,
40
40
  :receive_data, :receive_callback_type,
41
41
  :state_changed, :pointer,
42
42
  :get_pub_key_for_id, :get_pub_key_by_id_type,
43
43
  :user_data, :pointer
44
- end
45
-
46
- attach_function :secure_session_create, [ :pointer, :uint, :pointer, :uint, :pointer], :pointer
47
- attach_function :secure_session_destroy, [ :pointer], :int
48
- attach_function :secure_session_generate_connect_request, [ :pointer, :pointer, :pointer], :int
49
- attach_function :secure_session_wrap, [ :pointer, :pointer, :int, :pointer, :pointer], :int
50
- attach_function :secure_session_unwrap, [ :pointer, :pointer, :int, :pointer, :pointer], :int
51
- attach_function :secure_session_is_established, [ :pointer], :bool
52
-
53
- attach_function :themis_secure_message_wrap, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
54
- attach_function :themis_secure_message_unwrap, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
55
-
56
- attach_function :themis_gen_rsa_key_pair, [:pointer, :pointer, :pointer, :pointer], :int
57
- attach_function :themis_gen_ec_key_pair, [:pointer, :pointer, :pointer, :pointer], :int
58
- attach_function :themis_version, [], :string
59
-
60
- attach_function :themis_secure_cell_encrypt_full, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
61
- attach_function :themis_secure_cell_decrypt_full, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
62
-
63
- attach_function :themis_secure_cell_encrypt_auto_split, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer, :pointer, :pointer], :int
64
- attach_function :themis_secure_cell_decrypt_auto_split, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
65
-
66
- attach_function :themis_secure_cell_encrypt_user_split, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
67
- attach_function :themis_secure_cell_decrypt_user_split, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
44
+ end
45
+
46
+ attach_function :secure_session_create, [ :pointer, :uint, :pointer, :uint, :pointer], :pointer
47
+ attach_function :secure_session_destroy, [ :pointer], :int
48
+ attach_function :secure_session_generate_connect_request, [ :pointer, :pointer, :pointer], :int
49
+ attach_function :secure_session_wrap, [ :pointer, :pointer, :int, :pointer, :pointer], :int
50
+ attach_function :secure_session_unwrap, [ :pointer, :pointer, :int, :pointer, :pointer], :int
51
+ attach_function :secure_session_is_established, [ :pointer], :bool
52
+
53
+ attach_function :themis_secure_message_wrap, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
54
+ attach_function :themis_secure_message_unwrap, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
55
+
56
+ attach_function :themis_gen_rsa_key_pair, [:pointer, :pointer, :pointer, :pointer], :int
57
+ attach_function :themis_gen_ec_key_pair, [:pointer, :pointer, :pointer, :pointer], :int
58
+ attach_function :themis_version, [], :string
59
+
60
+ attach_function :themis_secure_cell_encrypt_seal, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
61
+ attach_function :themis_secure_cell_decrypt_seal, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
62
+
63
+ attach_function :themis_secure_cell_encrypt_token_protect, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer, :pointer, :pointer], :int
64
+ attach_function :themis_secure_cell_decrypt_token_protect, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
65
+
66
+ attach_function :themis_secure_cell_encrypt_context_imprint, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
67
+ attach_function :themis_secure_cell_decrypt_context_imprint, [:pointer, :int, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
68
+
69
+ begin
70
+ attach_function :secure_comparator_create, [], :pointer
71
+ attach_function :secure_comparator_destroy, [ :pointer], :int
72
+ attach_function :secure_comparator_append_secret, [:pointer, :pointer, :int], :int
73
+ attach_function :secure_comparator_begin_compare, [:pointer, :pointer, :pointer], :int
74
+ attach_function :secure_comparator_proceed_compare, [:pointer, :pointer, :int, :pointer, :pointer], :int
75
+ attach_function :secure_comparator_get_result, [:pointer], :int
76
+ rescue FFI::NotFoundError => e
77
+ end
68
78
  end
69
79
 
70
80
  module Themis
@@ -257,9 +267,9 @@ module Themis
257
267
  include ThemisCommon
258
268
  include ThemisImport
259
269
 
260
- FULL_MODE = 0
261
- AUTO_SPLIT_MODE = 1
262
- USER_SPLIT_MODE = 2
270
+ SEAL_MODE = 0
271
+ TOKEN_PROTECT_MODE = 1
272
+ CONTEXT_IMPRINT_MODE = 2
263
273
 
264
274
  def initialize(key, mode)
265
275
  @key, @key_length = string_to_pointer_size(key)
@@ -272,27 +282,27 @@ module Themis
272
282
  encrypted_message_length=FFI::MemoryPointer.new(:uint)
273
283
  enccontext_length=FFI::MemoryPointer.new(:uint)
274
284
  case @mode
275
- when FULL_MODE
276
- res=themis_secure_cell_encrypt_full(@key, @key_length, context_, context_length_, message_, message_length_, nil, encrypted_message_length)
277
- raise ThemisError, "themis_secure_cell_encrypt_... (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
285
+ when SEAL_MODE
286
+ res=themis_secure_cell_encrypt_seal(@key, @key_length, context_, context_length_, message_, message_length_, nil, encrypted_message_length)
287
+ raise ThemisError, "themis_secure_cell_encrypt_seal (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
278
288
  encrypted_message = FFI::MemoryPointer.new(:char, encrypted_message_length.read_uint)
279
- res=themis_secure_cell_encrypt_full(@key, @key_length, context_, context_length_, message_, message_length_, encrypted_message, encrypted_message_length)
280
- raise ThemisError, "themis_secure_cell_encrypt_full (length determination) error: #{res}" unless res == SUCCESS
289
+ res=themis_secure_cell_encrypt_seal(@key, @key_length, context_, context_length_, message_, message_length_, encrypted_message, encrypted_message_length)
290
+ raise ThemisError, "themis_secure_cell_encrypt_seal error: #{res}" unless res == SUCCESS
281
291
  return encrypted_message.get_bytes(0, encrypted_message_length.read_uint)
282
- when AUTO_SPLIT_MODE
283
- res=themis_secure_cell_encrypt_auto_split(@key, @key_length, context_, context_length_, message_, message_length_, nil, enccontext_length, nil, encrypted_message_length)
284
- raise ThemisError, "themis_secure_cell_encrypt_... (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
292
+ when TOKEN_PROTECT_MODE
293
+ res=themis_secure_cell_encrypt_token_protect(@key, @key_length, context_, context_length_, message_, message_length_, nil, enccontext_length, nil, encrypted_message_length)
294
+ raise ThemisError, "themis_secure_cell_encrypt_token_protect (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
285
295
  encrypted_message = FFI::MemoryPointer.new(:char, encrypted_message_length.read_uint)
286
296
  enccontext = FFI::MemoryPointer.new(:char, enccontext_length.read_uint)
287
- res=themis_secure_cell_encrypt_auto_split(@key, @key_length, context_, context_length_, message_, message_length_, enccontext, enccontext_length, encrypted_message, encrypted_message_length)
288
- raise ThemisError, "themis_secure_cell_encrypt_auto_split (length determination) error: #{res}" unless res == SUCCESS
297
+ res=themis_secure_cell_encrypt_token_protect(@key, @key_length, context_, context_length_, message_, message_length_, enccontext, enccontext_length, encrypted_message, encrypted_message_length)
298
+ raise ThemisError, "themis_secure_cell_encrypt_token_protect error: #{res}" unless res == SUCCESS
289
299
  return enccontext.get_bytes(0, enccontext_length.read_uint), encrypted_message.get_bytes(0, encrypted_message_length.read_uint)
290
- when USER_SPLIT_MODE
291
- res=themis_secure_cell_encrypt_user_split(@key, @key_length, message_, message_length_, context_, context_length_, nil, encrypted_message_length)
292
- raise ThemisError, "themis_secure_cell_encrypt_... (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
300
+ when CONTEXT_IMPRINT_MODE
301
+ res=themis_secure_cell_encrypt_context_imprint(@key, @key_length, message_, message_length_, context_, context_length_, nil, encrypted_message_length)
302
+ raise ThemisError, "themis_secure_cell_encrypt_context_imprint (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
293
303
  encrypted_message = FFI::MemoryPointer.new(:char, encrypted_message_length.read_uint)
294
- res=themis_secure_cell_encrypt_user_split(@key, @key_length, message_, message_length_, context_, context_length_, encrypted_message, encrypted_message_length)
295
- raise ThemisError, "themis_secure_cell_encrypt_user_split (length determination) error: #{res}" unless res == SUCCESS
304
+ res=themis_secure_cell_encrypt_context_imprint(@key, @key_length, message_, message_length_, context_, context_length_, encrypted_message, encrypted_message_length)
305
+ raise ThemisError, "themis_secure_cell_encrypt_context_imprint error: #{res}" unless res == SUCCESS
296
306
  return encrypted_message.get_bytes(0, encrypted_message_length.read_uint)
297
307
  else
298
308
  raise ThemisError, "themis_secure_cell not supported mode"
@@ -303,31 +313,31 @@ module Themis
303
313
  context_, context_length_ = context.nil? ? [nil,0] : string_to_pointer_size(context)
304
314
  decrypted_message_length=FFI::MemoryPointer.new(:uint)
305
315
  case @mode
306
- when FULL_MODE
316
+ when SEAL_MODE
307
317
  message_, message_length_ = string_to_pointer_size(message)
308
- res=themis_secure_cell_decrypt_full(@key, @key_length, context_, context_length_, message_, message_length_, nil, decrypted_message_length)
309
- raise ThemisError, "themis_secure_cell_decrypt_full (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
318
+ res=themis_secure_cell_decrypt_seal(@key, @key_length, context_, context_length_, message_, message_length_, nil, decrypted_message_length)
319
+ raise ThemisError, "themis_secure_cell_decrypt_seal (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
310
320
  decrypted_message = FFI::MemoryPointer.new(:char, decrypted_message_length.read_uint)
311
- res=themis_secure_cell_decrypt_full(@key, @key_length, context_, context_length_, message_, message_length_, decrypted_message, decrypted_message_length)
312
- raise ThemisError, "themis_secure_cell_decrypt_full (length determination) error: #{res}" unless res == SUCCESS
321
+ res=themis_secure_cell_decrypt_seal(@key, @key_length, context_, context_length_, message_, message_length_, decrypted_message, decrypted_message_length)
322
+ raise ThemisError, "themis_secure_cell_decrypt_seal error: #{res}" unless res == SUCCESS
313
323
  return decrypted_message.get_bytes(0, decrypted_message_length.read_uint)
314
- when AUTO_SPLIT_MODE
324
+ when TOKEN_PROTECT_MODE
315
325
  enccontext, message_ = message
316
326
  message__, message_length__ = string_to_pointer_size(message_)
317
327
  enccontext_, enccontext_length = string_to_pointer_size(enccontext)
318
- res=themis_secure_cell_decrypt_auto_split(@key, @key_length, context_, context_length_, message__, message_length__, enccontext_, enccontext_length, nil, decrypted_message_length)
319
- raise ThemisError, "themis_secure_cell_encrypt_auto_split (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
328
+ res=themis_secure_cell_decrypt_token_protect(@key, @key_length, context_, context_length_, message__, message_length__, enccontext_, enccontext_length, nil, decrypted_message_length)
329
+ raise ThemisError, "themis_secure_cell_encrypt_token_protect (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
320
330
  decrypted_message = FFI::MemoryPointer.new(:char, decrypted_message_length.read_uint)
321
- res=themis_secure_cell_decrypt_auto_split(@key, @key_length, context_, context_length_, message__, message_length__, enccontext_, enccontext_length, decrypted_message, decrypted_message_length)
322
- raise ThemisError, "themis_secure_cell_encrypt_auto_split (length determination) error: #{res}" unless res == SUCCESS
331
+ res=themis_secure_cell_decrypt_token_protect(@key, @key_length, context_, context_length_, message__, message_length__, enccontext_, enccontext_length, decrypted_message, decrypted_message_length)
332
+ raise ThemisError, "themis_secure_cell_encrypt_token_protect error: #{res}" unless res == SUCCESS
323
333
  return decrypted_message.get_bytes(0, decrypted_message_length.read_uint)
324
- when USER_SPLIT_MODE
334
+ when CONTEXT_IMPRINT_MODE
325
335
  message_, message_length_ = string_to_pointer_size(message)
326
- res=themis_secure_cell_decrypt_user_split(@key, @key_length, message_, message_length_, context_, context_length_, nil, decrypted_message_length)
327
- raise ThemisError, "themis_secure_cell_decrypt_user_split (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
336
+ res=themis_secure_cell_decrypt_context_imprint(@key, @key_length, message_, message_length_, context_, context_length_, nil, decrypted_message_length)
337
+ raise ThemisError, "themis_secure_cell_decrypt_context_imprint (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
328
338
  decrypted_message = FFI::MemoryPointer.new(:char, decrypted_message_length.read_uint)
329
- res=themis_secure_cell_decrypt_user_split(@key, @key_length, message_, message_length_, context_, context_length_, decrypted_message, decrypted_message_length)
330
- raise ThemisError, "themis_secure_cell_decrypt_user_split (length determination) error: #{res}" unless res == SUCCESS
339
+ res=themis_secure_cell_decrypt_context_imprint(@key, @key_length, message_, message_length_, context_, context_length_, decrypted_message, decrypted_message_length)
340
+ raise ThemisError, "themis_secure_cell_decrypt_context_imprint error: #{res}" unless res == SUCCESS
331
341
  return decrypted_message.get_bytes(0, decrypted_message_length.read_uint)
332
342
  else
333
343
  raise ThemisError, "themis_secure_cell not supported mode"
@@ -335,7 +345,57 @@ module Themis
335
345
  end
336
346
  end
337
347
 
348
+ class Scomparator
349
+ include ThemisCommon
350
+ include ThemisImport
351
+
352
+ MATCH=-252645136
353
+ NOT_MATCH = -1
354
+ NOT_READY = 0
355
+
356
+ def initialize(shared_secret)
357
+ shared_secret_buf, shared_secret_length = string_to_pointer_size(shared_secret)
358
+ @comparator=secure_comparator_create()
359
+ raise ThemisError, "secure_comparator_create error" unless @comparator
360
+ res=secure_comparator_append_secret(@comparator, shared_secret_buf, shared_secret_length)
361
+ raise ThemisError, "secure_comparator_append_secret error" unless res==SUCCESS
362
+ end
363
+
364
+ def finalize()
365
+ res=secure_comparator_destroy(@comparator)
366
+ raise ThemisError, "secure_comparator_destroy error" unless res==SUCCESS
367
+ end
368
+
369
+ def begin_compare()
370
+ res_length=FFI::MemoryPointer.new(:uint)
371
+ res=secure_comparator_begin_compare(@comparator, nil, res_length)
372
+ raise ThemisError, "secure_comparator_begin_compare (length determination) error" unless res==BUFFER_TOO_SMALL
373
+ res_buffer=FFI::MemoryPointer.new(:char, res_length.read_uint)
374
+ res=secure_comparator_begin_compare(@comparator, res_buffer, res_length)
375
+ raise ThemisError, "secure_comparator_begin_compare error" unless res==SUCCESS || res==SEND_AS_IS
376
+ return res_buffer.get_bytes(0,res_length.read_uint)
377
+ end
378
+
379
+ def proceed_compare(control_message)
380
+ message, message_length = string_to_pointer_size(control_message)
381
+ res_length=FFI::MemoryPointer.new(:uint)
382
+ res=secure_comparator_proceed_compare(@comparator, message, message_length, nil, res_length)
383
+ raise ThemisError, "secure_comparator_proceed_compare (length determination) error" unless res==SUCCESS || res == BUFFER_TOO_SMALL
384
+ if res == SUCCESS
385
+ return ""
386
+ end
387
+ res_buffer=FFI::MemoryPointer.new(:char, res_length.read_uint)
388
+ res=secure_comparator_proceed_compare(@comparator, message, message_length, res_buffer, res_length)
389
+ raise ThemisError, "secure_comparator_proceed_compare error" unless res==SUCCESS || res==SEND_AS_IS
390
+ return res_buffer.get_bytes(0,res_length.read_uint)
391
+ end
392
+
393
+ def result()
394
+ return secure_comparator_get_result(@comparator)
395
+ end
396
+ end
397
+
338
398
  module_function :Ssign
339
399
  module_function :Sverify
340
400
 
341
- end
401
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubythemis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CossackLabs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-03 00:00:00.000000000 Z
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements:
63
- - libthemis, v0.9
63
+ - libthemis, v0.9.2
64
64
  rubyforge_project:
65
65
  rubygems_version: 2.4.5
66
66
  signing_key: