pkcs11 0.2.2-x86-mingw32 → 0.2.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ === 0.2.3 / 2012-01-25
2
+
3
+ * fix C_WaitForSlotEvent to be a Library- instead of a Slot-method
4
+ * allow :sw/:hsm to ProtectServer::Library#load_library in the same way as #initialize
5
+ * allow Hash argument to Library#C_Initialize in the same way as #initialize
6
+
1
7
  === 0.2.2 / 2011-12-12
2
8
 
3
9
  * add ability to change PKCS11 base methods in order to use vendor defined attributes, return codes and mechanisms
data/Rakefile CHANGED
@@ -36,6 +36,7 @@ hoe = Hoe.spec 'pkcs11' do
36
36
  spec_extras[:files] = File.read_utf("Manifest.txt").split(/\r?\n\r?/).reject{|f| f=~/^pkcs11_/ }
37
37
  spec_extras[:files] += GENERATED_FILES
38
38
  spec_extras[:has_rdoc] = 'yard'
39
+ self.rdoc_locations << "larskanis@rack.rubyforge.org:/var/www/gforge-projects/pkcs11/pkcs11/"
39
40
  end
40
41
 
41
42
  ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.2'
data/ext/pk11.c CHANGED
@@ -244,9 +244,9 @@ pkcs11_initialize(int argc, VALUE *argv, VALUE self)
244
244
 
245
245
  rb_scan_args(argc, argv, "02", &path, &init_args);
246
246
  if( !NIL_P(path) ){
247
- pkcs11_load_library(self, path);
248
- pkcs11_C_GetFunctionList(self);
249
- pkcs11_C_Initialize(1, &init_args, self);
247
+ rb_funcall(self, rb_intern("load_library"), 1, path);
248
+ rb_funcall(self, rb_intern("C_GetFunctionList"), 0);
249
+ rb_funcall2(self, rb_intern("C_Initialize"), 1, &init_args);
250
250
  }
251
251
 
252
252
  return self;
@@ -1,6 +1,6 @@
1
1
  #ifndef RUBY_PK11_VERSION_H
2
2
  #define RUBY_PK11_VERSION_H
3
3
 
4
- static const char *VERSION = "0.2.2";
4
+ static const char *VERSION = "0.2.3";
5
5
 
6
6
  #endif
Binary file
Binary file
@@ -35,6 +35,11 @@ module PKCS11
35
35
  # pkcs11.C_GetFunctionList
36
36
  # pkcs11.C_Initialize(args)
37
37
  def initialize(so_path=nil, args={})
38
+ unwrapped_initialize(so_path, args)
39
+ end
40
+
41
+ alias unwrapped_C_Initialize C_Initialize
42
+ def C_Initialize(args=nil)
38
43
  case args
39
44
  when Hash
40
45
  pargs = CK_C_INITIALIZE_ARGS.new
@@ -42,7 +47,7 @@ module PKCS11
42
47
  else
43
48
  pargs = args
44
49
  end
45
- unwrapped_initialize(so_path, pargs)
50
+ unwrapped_C_Initialize(pargs)
46
51
  end
47
52
 
48
53
  alias unwrapped_C_GetInfo C_GetInfo
@@ -81,6 +86,20 @@ module PKCS11
81
86
  slots(false)
82
87
  end
83
88
 
89
+ alias unwrapped_C_WaitForSlotEvent C_WaitForSlotEvent
90
+
91
+ # Waits for a slot event, such as token insertion or token removal, to occur.
92
+ #
93
+ # @param [Integer] flags determines whether or not the C_WaitForSlotEvent call blocks (i.e., waits
94
+ # for a slot event to occur);
95
+ # At present, the only flag defined for use in the flags argument is PKCS11::CKF_DONT_BLOCK
96
+ # @return [Slot, nil] the slot that the event occurred in; nil if no event occured (CKR_NO_EVENT)
97
+ def C_WaitForSlotEvent(flags=0)
98
+ slot = unwrapped_C_WaitForSlotEvent(flags)
99
+ slot ? Slot.new(self, slot) : nil
100
+ end
101
+ alias wait_for_slot_event C_WaitForSlotEvent
102
+
84
103
  # Finalize and unload the library. If not called explicit, the library is freed by the GC.
85
104
  def close
86
105
  self.C_Finalize
@@ -29,22 +29,13 @@ module PKCS11
29
29
  @pk.C_GetSlotInfo(@slot)
30
30
  end
31
31
  alias info C_GetSlotInfo
32
-
32
+
33
33
  # Obtains information about a particular token in the system.
34
34
  # @return [PKCS11::CK_TOKEN_INFO]
35
35
  def C_GetTokenInfo
36
36
  @pk.C_GetTokenInfo(@slot)
37
37
  end
38
38
  alias token_info C_GetTokenInfo
39
-
40
- # Waits for a slot event, such as token insertion or token removal, to
41
- # occur.
42
- # @param flags determines whether or not the C_WaitForSlotEvent call blocks (i.e., waits
43
- # for a slot event to occur);
44
- def C_WaitForSlotEvent(flags)
45
- @pk.C_WaitForSlotEvent(@slot, flags)
46
- end
47
- alias wait_for_event C_WaitForSlotEvent
48
39
 
49
40
  # C_GetMechanismList is used to obtain a list of mechanism types supported by a token.
50
41
  # @return [Array<PKCS11::CKM_*>]
@@ -75,7 +66,7 @@ module PKCS11
75
66
  self
76
67
  end
77
68
  alias init_token C_InitToken
78
-
69
+
79
70
  # Opens a Session between an application and a token in a particular slot.
80
71
  #
81
72
  # @param [Integer] flags indicates the type of session. Default is read-only,
@@ -99,7 +90,7 @@ module PKCS11
99
90
  end
100
91
  end
101
92
  alias open C_OpenSession
102
-
93
+
103
94
  # Closes all sessions an application has with a token.
104
95
  # @return [PKCS11::Slot]
105
96
  def C_CloseAllSessions
@@ -3,31 +3,34 @@ require "pkcs11"
3
3
  require "test/helper"
4
4
 
5
5
  class TestPkcs11 < Test::Unit::TestCase
6
- def setup
6
+ attr_reader :pk
7
+
8
+ def open
7
9
  @pk = open_softokn
8
10
  end
9
11
 
10
- def teardown
12
+ def close
11
13
  @pk.close
12
14
  @pk = nil
13
15
  GC.start
14
16
  end
15
17
 
16
- def pk
17
- @pk
18
- end
19
-
20
18
  def test_info
19
+ open
21
20
  info = pk.info
22
21
  assert info.inspect =~ /cryptokiVersion=/, 'There should be a version in the library info'
22
+ close
23
23
  end
24
24
 
25
25
  def test_slots
26
+ open
26
27
  slots = pk.active_slots
27
28
  assert slots.length>=1, 'Hope there is at least one active slot'
29
+ close
28
30
  end
29
31
 
30
32
  def test_close
33
+ open
31
34
  pk.close
32
35
  pk.unload_library
33
36
  assert_raise(PKCS11::Error){ pk.info }
@@ -43,5 +46,26 @@ class TestPkcs11 < Test::Unit::TestCase
43
46
  pk.C_Initialize(pargs)
44
47
 
45
48
  pk.info
49
+ close
50
+ end
51
+
52
+ def test_C_Initialize_with_Hash
53
+ pk = PKCS11.open
54
+ pk.load_library(find_softokn)
55
+ pk.C_GetFunctionList
56
+ pk.C_Initialize(:flags=>0, :pReserved=>softokn_params_string)
57
+ pk.info
58
+ pk.close
59
+ end
60
+
61
+ def test_wait_for_slot_event
62
+ open
63
+ # Softokn's C_WaitForSlotEvent() currently raises PKCS11::CKR_FUNCTION_NOT_SUPPORTED.
64
+ # So just check, that the call goes to softokn at all.
65
+ begin
66
+ pk.wait_for_slot_event
67
+ rescue PKCS11::Error
68
+ end
69
+ close
46
70
  end
47
71
  end
@@ -19,7 +19,7 @@ class TestPkcs11Crypt < Test::Unit::TestCase
19
19
  @slot = slots.last
20
20
  @session = slot.open
21
21
  # session.login(:USER, "")
22
-
22
+
23
23
  @rsa_pub_key = session.find_objects(:CLASS => CKO_PUBLIC_KEY,
24
24
  :KEY_TYPE => CKK_RSA).first
25
25
  @rsa_priv_key = session.find_objects(:CLASS => CKO_PRIVATE_KEY,
@@ -47,7 +47,7 @@ class TestPkcs11Crypt < Test::Unit::TestCase
47
47
  cryptogram = session.encrypt( :RSA_PKCS, rsa_pub_key, plaintext1)
48
48
  assert cryptogram.length>10, 'The cryptogram should contain some data'
49
49
  assert_not_equal cryptogram, plaintext1, 'The cryptogram should be different to plaintext'
50
-
50
+
51
51
  plaintext2 = session.decrypt( :RSA_PKCS, rsa_priv_key, cryptogram)
52
52
  assert_equal plaintext1, plaintext2, 'Decrypted plaintext should be the same'
53
53
  end
@@ -57,14 +57,14 @@ class TestPkcs11Crypt < Test::Unit::TestCase
57
57
  cryptogram = session.encrypt( {:DES3_CBC_PAD=>"\0"*8}, secret_key, plaintext1)
58
58
  assert_equal 16, cryptogram.length, 'The cryptogram should contain some data'
59
59
  assert_not_equal cryptogram, plaintext1, 'The cryptogram should be different to plaintext'
60
-
60
+
61
61
  cryptogram2 = ''
62
62
  cryptogram2 << session.encrypt( {:DES3_CBC_PAD=>"\0"*8}, secret_key ) do |cipher|
63
63
  cryptogram2 << cipher.update(plaintext1[0, 8])
64
64
  cryptogram2 << cipher.update(plaintext1[8..-1])
65
65
  end
66
66
  assert_equal cryptogram, cryptogram2, "Encrypt with and w/o block should be lead to the same result"
67
-
67
+
68
68
  plaintext2 = session.decrypt( {:DES3_CBC_PAD=>"\0"*8}, secret_key, cryptogram)
69
69
  assert_equal plaintext1, plaintext2, 'Decrypted plaintext should be the same'
70
70
  end
@@ -82,7 +82,7 @@ class TestPkcs11Crypt < Test::Unit::TestCase
82
82
 
83
83
  valid = session.verify( :SHA1_RSA_PKCS, rsa_pub_key, signature, plaintext)
84
84
  assert valid, 'The signature should be correct'
85
-
85
+
86
86
  assert_raise(CKR_SIGNATURE_INVALID, 'The signature should be invalid on different text') do
87
87
  session.verify( :SHA1_RSA_PKCS, rsa_pub_key, signature, "modified text")
88
88
  end
@@ -150,7 +150,7 @@ class TestPkcs11Crypt < Test::Unit::TestCase
150
150
  {:ENCRYPT=>true, :WRAP=>true, :DECRYPT=>true, :UNWRAP=>true, :TOKEN=>false, :LOCAL=>true})
151
151
  assert_equal true, key[:LOCAL], 'Keys created on the token should be marked as local'
152
152
  assert_equal CKK_DES2, key[:KEY_TYPE], 'Should be a 2 key 3des key'
153
-
153
+
154
154
  # other ways to use mechanisms
155
155
  key = session.generate_key(CKM_DES2_KEY_GEN,
156
156
  {:ENCRYPT=>true, :WRAP=>true, :DECRYPT=>true, :UNWRAP=>true, :TOKEN=>false, :LOCAL=>true})
@@ -165,7 +165,7 @@ class TestPkcs11Crypt < Test::Unit::TestCase
165
165
  {:ENCRYPT=>true, :VERIFY=>true, :WRAP=>true, :MODULUS_BITS=>768, :PUBLIC_EXPONENT=>[3].pack("N"), :TOKEN=>false},
166
166
  {:PRIVATE=>true, :SUBJECT=>'test', :ID=>[123].pack("n"),
167
167
  :SENSITIVE=>true, :DECRYPT=>true, :SIGN=>true, :UNWRAP=>true, :TOKEN=>false, :LOCAL=>true})
168
-
168
+
169
169
  assert_equal true, priv_key[:LOCAL], 'Private keys created on the token should be marked as local'
170
170
  assert_equal priv_key[:CLASS], CKO_PRIVATE_KEY
171
171
  assert_equal pub_key[:CLASS], CKO_PUBLIC_KEY
@@ -183,7 +183,7 @@ class TestPkcs11Crypt < Test::Unit::TestCase
183
183
 
184
184
  # Derive secret DES key for side 1 with OpenSSL
185
185
  new_key1 = key1.compute_key(OpenSSL::BN.new pub_key2[:VALUE], 2)
186
-
186
+
187
187
  # Derive secret DES key for side 2 with softokn3
188
188
  new_key2 = session.derive_key( {:DH_PKCS_DERIVE=>key1.pub_key.to_s(2)}, priv_key2,
189
189
  :CLASS=>CKO_SECRET_KEY, :KEY_TYPE=>CKK_AES, :VALUE_LEN=>16, :ENCRYPT=>true, :DECRYPT=>true, :SENSITIVE=>false )
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pkcs11
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: x86-mingw32
12
12
  authors:
13
13
  - Ryosuke Kutsuna
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-12-12 00:00:00 Z
20
+ date: 2012-01-25 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: yard
@@ -50,33 +50,33 @@ dependencies:
50
50
  type: :development
51
51
  version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
53
- name: hoe
53
+ name: rdoc
54
54
  prerelease: false
55
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ~>
59
59
  - !ruby/object:Gem::Version
60
- hash: 27
60
+ hash: 19
61
61
  segments:
62
- - 2
63
- - 12
64
- version: "2.12"
62
+ - 3
63
+ - 10
64
+ version: "3.10"
65
65
  type: :development
66
66
  version_requirements: *id003
67
67
  - !ruby/object:Gem::Dependency
68
- name: rdoc
68
+ name: hoe
69
69
  prerelease: false
70
70
  requirement: &id004 !ruby/object:Gem::Requirement
71
71
  none: false
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- hash: 19
75
+ hash: 27
76
76
  segments:
77
- - 3
78
- - 10
79
- version: "3.10"
77
+ - 2
78
+ - 12
79
+ version: "2.12"
80
80
  type: :development
81
81
  version_requirements: *id004
82
82
  description: "This module allows Ruby programs to interface with \"RSA Security Inc. PKCS #11 Cryptographic Token Interface (Cryptoki)\"."
@@ -177,15 +177,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  requirements: []
178
178
 
179
179
  rubyforge_project: pkcs11
180
- rubygems_version: 1.8.11
180
+ rubygems_version: 1.8.6
181
181
  signing_key:
182
182
  specification_version: 3
183
183
  summary: PKCS#11 binding for Ruby
184
184
  test_files:
185
+ - test/test_pkcs11_object.rb
185
186
  - test/test_pkcs11_thread.rb
186
- - test/test_pkcs11_structs.rb
187
- - test/test_pkcs11_session.rb
188
- - test/test_pkcs11_slot.rb
189
187
  - test/test_pkcs11.rb
188
+ - test/test_pkcs11_slot.rb
189
+ - test/test_pkcs11_session.rb
190
+ - test/test_pkcs11_structs.rb
190
191
  - test/test_pkcs11_crypt.rb
191
- - test/test_pkcs11_object.rb