naoki 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +19 -0
- data/data_secure_wrapper.rb +132 -0
- data/lib/libICAPI.so +0 -0
- data/naoki.gemspec +13 -0
- data/sample.rb +21 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
ICAPI_LIB_FILE = '/usr/lib/libICAPI.so'
|
4
|
+
|
5
|
+
unless File.exists? ICAPI_LIB_FILE
|
6
|
+
|
7
|
+
module DataSecureWrapper
|
8
|
+
def self.configure(*args); end
|
9
|
+
def self.open(*args); end
|
10
|
+
def self.encrypt(*args); end
|
11
|
+
def self.decrypt(*args); end
|
12
|
+
def self.close(*args); end
|
13
|
+
end
|
14
|
+
|
15
|
+
else
|
16
|
+
|
17
|
+
module DataSecureWrapper
|
18
|
+
extend FFI::Library
|
19
|
+
ffi_lib ICAPI_LIB_FILE
|
20
|
+
|
21
|
+
I_T_Init_File = 0
|
22
|
+
I_E_OK = 0
|
23
|
+
I_T_Auth_Password = 0
|
24
|
+
I_T_Operation_Encrypt = 0
|
25
|
+
I_T_Operation_Decrypt = 1
|
26
|
+
|
27
|
+
attach_function 'I_C_GetErrorString', [:int], :string
|
28
|
+
attach_function 'I_C_Initialize', [:uint8, :string], :int
|
29
|
+
attach_function 'I_C_OpenSession', [:pointer, :uint8, :string, :string], :int
|
30
|
+
attach_function 'I_C_CreateCipherSpec', [:string, :string, :pointer], :int
|
31
|
+
attach_function 'I_C_CalculateEncipheredSizeForKey', [:pointer, :pointer, :uint8, :uint, :pointer], :int
|
32
|
+
attach_function 'I_C_DeleteCipherSpec', [:pointer], :int
|
33
|
+
attach_function 'I_C_Crypt', [:pointer, :pointer, :uint8, :string, :uint, :pointer, :uint, :pointer, :pointer], :int
|
34
|
+
attach_function 'I_C_CalculateOutputSizeForKey', [:pointer, :pointer, :uint8, :int, :pointer], :int
|
35
|
+
attach_function 'I_C_Fini', [], :void
|
36
|
+
attach_function 'I_C_CloseSession', [:pointer], :void
|
37
|
+
|
38
|
+
@@cipherspec_pointer = nil
|
39
|
+
@@session_pointer = nil
|
40
|
+
|
41
|
+
def self.check
|
42
|
+
return_code = yield
|
43
|
+
if return_code != DataSecureWrapper::I_E_OK
|
44
|
+
I_C_DeleteCipherSpec(@@cipherspec_pointer.get_pointer(0)) if @@cipherspec_pointer
|
45
|
+
@@cipherspec_pointer = nil
|
46
|
+
I_C_CloseSession(@@session_pointer.get_pointer(0)) if @@session_pointer
|
47
|
+
@@session_pointer = nil
|
48
|
+
I_C_Fini()
|
49
|
+
raise I_C_GetErrorString(return_code)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.configure(properties_file)
|
54
|
+
check { I_C_Initialize(I_T_Init_File, properties_file) }
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.open(user_name, password)
|
58
|
+
@@session_pointer = FFI::MemoryPointer.new :pointer
|
59
|
+
check { I_C_OpenSession(@@session_pointer, I_T_Auth_Password, user_name, password) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.encrypt(algorithm, key_name, initialization_vector, plain_text)
|
63
|
+
@@cipherspec_pointer = FFI::MemoryPointer.new :pointer
|
64
|
+
check { I_C_CreateCipherSpec(algorithm, key_name, @@cipherspec_pointer) }
|
65
|
+
|
66
|
+
encrypted_data_length_pointer = FFI::MemoryPointer.new :pointer
|
67
|
+
check { I_C_CalculateEncipheredSizeForKey(
|
68
|
+
@@session_pointer.get_pointer(0),
|
69
|
+
@@cipherspec_pointer.get_pointer(0),
|
70
|
+
I_T_Operation_Encrypt,
|
71
|
+
plain_text.length,
|
72
|
+
encrypted_data_length_pointer
|
73
|
+
) }
|
74
|
+
|
75
|
+
encrypted_data = FFI::MemoryPointer.new :pointer, encrypted_data_length_pointer.read_int/4
|
76
|
+
|
77
|
+
check { I_C_Crypt(
|
78
|
+
@@session_pointer.get_pointer(0),
|
79
|
+
@@cipherspec_pointer.get_pointer(0),
|
80
|
+
I_T_Operation_Encrypt,
|
81
|
+
initialization_vector,
|
82
|
+
initialization_vector.length,
|
83
|
+
plain_text,
|
84
|
+
plain_text.length,
|
85
|
+
encrypted_data,
|
86
|
+
encrypted_data_length_pointer
|
87
|
+
) }
|
88
|
+
|
89
|
+
I_C_DeleteCipherSpec(@@cipherspec_pointer.get_pointer(0))
|
90
|
+
@@cipherspec_pointer = nil
|
91
|
+
|
92
|
+
result = ''
|
93
|
+
encrypted_data_length_pointer.read_int.times { |i| result << encrypted_data.get_uchar(i) }
|
94
|
+
result
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.decrypt(algorithm, key_name, initialization_vector, encrypted_text)
|
98
|
+
@@cipherspec_pointer = FFI::MemoryPointer.new :pointer
|
99
|
+
check { I_C_CreateCipherSpec(algorithm, key_name, @@cipherspec_pointer) }
|
100
|
+
|
101
|
+
decrypted_data_length_pointer = FFI::MemoryPointer.new :pointer
|
102
|
+
|
103
|
+
check { I_C_CalculateOutputSizeForKey(
|
104
|
+
@@session_pointer.get_pointer(0),
|
105
|
+
@@cipherspec_pointer.get_pointer(0),
|
106
|
+
I_T_Operation_Decrypt,
|
107
|
+
encrypted_text.length,
|
108
|
+
decrypted_data_length_pointer
|
109
|
+
) }
|
110
|
+
|
111
|
+
decrypted_data = FFI::MemoryPointer.new :pointer, decrypted_data_length_pointer.read_int/4
|
112
|
+
|
113
|
+
check { I_C_Crypt(
|
114
|
+
@@session_pointer.get_pointer(0),
|
115
|
+
@@cipherspec_pointer.get_pointer(0),
|
116
|
+
I_T_Operation_Decrypt,
|
117
|
+
initialization_vector,
|
118
|
+
initialization_vector.length,
|
119
|
+
encrypted_text,
|
120
|
+
encrypted_text.length,
|
121
|
+
decrypted_data,
|
122
|
+
decrypted_data_length_pointer
|
123
|
+
) }
|
124
|
+
|
125
|
+
I_C_DeleteCipherSpec(@@cipherspec_pointer.get_pointer(0))
|
126
|
+
@@cipherspec_pointer = nil
|
127
|
+
|
128
|
+
decrypted_data.read_string(decrypted_data_length_pointer.read_int)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
data/lib/libICAPI.so
ADDED
Binary file
|
data/naoki.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
SPEC = Gem::Specification.new do |s|
|
2
|
+
s.name = "naoki"
|
3
|
+
s.version = "1.0.6"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.homepage = ""
|
6
|
+
s.summary = "C bindings for SafeNet DataSecure ICAPI"
|
7
|
+
s.files = `git ls-files`.split("\n")
|
8
|
+
s.authors = ["Chris Apolzon", "Liron Yahdav"]
|
9
|
+
s.email = ["apolzon@gmail.com"]
|
10
|
+
s.description = "C bindings for SafeNet DataSecure ICAPI"
|
11
|
+
|
12
|
+
s.add_runtime_dependency('ffi', ['0.6.3'])
|
13
|
+
end
|
data/sample.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.join(File.expand_path(__FILE__), '../data_secure_wrapper')
|
2
|
+
|
3
|
+
properties_file = 'IngrianNAE.properties'
|
4
|
+
user_name = ''
|
5
|
+
password = ''
|
6
|
+
algorithm = ''
|
7
|
+
key_name = ''
|
8
|
+
initialization_vector = ''
|
9
|
+
|
10
|
+
input_data = 'qwertyuiopasdfghjkl;zxcvbnm,./'
|
11
|
+
|
12
|
+
###
|
13
|
+
|
14
|
+
DataSecureWrapper.configure(properties_file)
|
15
|
+
DataSecureWrapper.open(user_name, password)
|
16
|
+
|
17
|
+
puts "encrypting: '#{input_data}'"
|
18
|
+
encrypted_data = DataSecureWrapper.encrypt(algorithm, key_name, initialization_vector, input_data)
|
19
|
+
decrypted_data = DataSecureWrapper.decrypt(algorithm, key_name, initialization_vector, encrypted_data)
|
20
|
+
puts "decrypted: '#{decrypted_data}'"
|
21
|
+
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: naoki
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
version: 1.0.6
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Chris Apolzon
|
13
|
+
- Liron Yahdav
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-18 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: ffi
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 6
|
32
|
+
- 3
|
33
|
+
version: 0.6.3
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: C bindings for SafeNet DataSecure ICAPI
|
37
|
+
email:
|
38
|
+
- apolzon@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- data_secure_wrapper.rb
|
50
|
+
- lib/libICAPI.so
|
51
|
+
- naoki.gemspec
|
52
|
+
- sample.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: ""
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: C bindings for SafeNet DataSecure ICAPI
|
85
|
+
test_files: []
|
86
|
+
|