ffi-pkcs11 0.2.0
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.md +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/rspec +17 -0
- data/bin/setup +8 -0
- data/ffi-pkcs11.gemspec +27 -0
- data/lib/ffi-pkcs11.rb +6 -0
- data/lib/ffi-pkcs11/error.rb +4 -0
- data/lib/ffi-pkcs11/functions.rb +75 -0
- data/lib/ffi-pkcs11/return_value.rb +158 -0
- data/lib/ffi-pkcs11/session.rb +64 -0
- data/lib/ffi-pkcs11/version.rb +3 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cd6f4b5ce9c4b6b6fe51184c11b052bfb278b1e8
|
4
|
+
data.tar.gz: c12881078bb7be5e5b68762e6a73a7faad9732bc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 770748cb742be5064d4043ef88b61bf15cb38cec59bc1af3e0a8084d07305f3436d5da23d08b41983185b872dc92a87c16f9e056a8f47bc6a2d499ea97686909
|
7
|
+
data.tar.gz: 5242f88b5094743287650c56c49903de2bc2be684d8cf3eb70345a0f2ecfa8c4ce53a5c0dd4b8810bbbfaf9a8388f8d6df18c083b2fa0c53fe95b6dc4d73e46d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Vincent Touchard
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# FFI::Pkcs11
|
2
|
+
|
3
|
+
Minimalistic Ruby FFI bindings for using a "Cryptoki" (PKCS11) library.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ffi-pkcs11'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ffi-pkcs11
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Low-level API
|
24
|
+
|
25
|
+
In order to use a PKCS11 function, one should prefix the function with the `Pkcs11` module name e.g.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
result = Pkcs11.C_Initialize(nil)
|
29
|
+
if result == Pkcs11::CKR_OK
|
30
|
+
[...]
|
31
|
+
```
|
32
|
+
|
33
|
+
### High-level API
|
34
|
+
|
35
|
+
Coming soon (TM).
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
The tests are using a software-only PKCS11 implementation [SoftHSM](https://wiki.opendnssec.org/display/SoftHSMDOCS/SoftHSM+Documentation+v2).
|
42
|
+
|
43
|
+
It is initialized using the following command:
|
44
|
+
`softhsm2-util --init-token --slot 0 --id 0x00 --label 'zero' --pin 1234 --so-pin 5678`
|
45
|
+
|
46
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/touchardv/ffi-pkcs11.
|
51
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/rspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
data/ffi-pkcs11.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ffi-pkcs11/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ffi-pkcs11"
|
8
|
+
spec.version = Pkcs11::VERSION
|
9
|
+
spec.authors = ["Vincent Touchard"]
|
10
|
+
spec.email = ["touchardv@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Minimalistic Ruby FFI bindings for using a "Cryptoki" (PKCS11) library.}
|
13
|
+
spec.homepage = "https://github.com/touchardv/ffi-pkcs11"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "ffi", "~> 1.9"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
24
|
+
spec.add_development_dependency "pry-byebug"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
data/lib/ffi-pkcs11.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Pkcs11
|
4
|
+
extend FFI::Library
|
5
|
+
|
6
|
+
ffi_lib 'cryptoki'
|
7
|
+
|
8
|
+
typedef :ulong, :CK_RV
|
9
|
+
|
10
|
+
CKS_RO_PUBLIC_SESSION = 0
|
11
|
+
CKS_RO_USER_FUNCTIONS = 1
|
12
|
+
CKS_RW_PUBLIC_SESSION = 2
|
13
|
+
CKS_RW_USER_FUNCTIONS = 3
|
14
|
+
CKS_RW_SO_FUNCTIONS = 4
|
15
|
+
|
16
|
+
class CK_SESSION_INFO < FFI::Struct
|
17
|
+
layout :slot_id, :ulong,
|
18
|
+
:state, :ulong,
|
19
|
+
:flags, :ulong,
|
20
|
+
:u_device_error, :ulong
|
21
|
+
end
|
22
|
+
|
23
|
+
enum :CK_ATTRIBUTE_TYPE, [
|
24
|
+
:CKA_CLASS, 0x00000000,
|
25
|
+
:CKA_TOKEN, 0x00000001,
|
26
|
+
:CKA_PRIVATE, 0x00000002,
|
27
|
+
:CKA_LABEL, 0x00000003
|
28
|
+
]
|
29
|
+
|
30
|
+
class CK_ATTRIBUTE < FFI::Struct
|
31
|
+
layout :type, :CK_ATTRIBUTE_TYPE,
|
32
|
+
:value, :pointer,
|
33
|
+
:value_len, :ulong
|
34
|
+
end
|
35
|
+
|
36
|
+
CKF_RW_SESSION = 0x00000002
|
37
|
+
CKF_SERIAL_SESSION = 0x00000004
|
38
|
+
|
39
|
+
CKM_MD5 = 0x00000210
|
40
|
+
CKM_SHA_1 = 0x00000220
|
41
|
+
CKM_VENDOR_DEFINED = 0x80000000
|
42
|
+
|
43
|
+
CKU_SO = 0
|
44
|
+
CKU_USER = 1
|
45
|
+
CKU_CONTEXT_SPECIFIC = 2
|
46
|
+
|
47
|
+
def self.import_function(function_name, *args)
|
48
|
+
function_symbol = "native_#{function_name}".to_sym
|
49
|
+
attach_function(function_symbol, function_name, *args)
|
50
|
+
|
51
|
+
self.class.send(:define_method, function_name) do |*arguments|
|
52
|
+
result = send(function_symbol, *arguments)
|
53
|
+
ReturnValue[result]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
import_function :C_Initialize, [:pointer], :CK_RV
|
58
|
+
import_function :C_Finalize, [:pointer], :CK_RV
|
59
|
+
|
60
|
+
import_function :C_GetSlotList, [:bool, :pointer, :pointer], :CK_RV
|
61
|
+
|
62
|
+
import_function :C_GetSessionInfo, [:ulong, :pointer], :CK_RV
|
63
|
+
import_function :C_OpenSession, [:ulong, :ulong, :pointer, :pointer, :pointer], :CK_RV
|
64
|
+
import_function :C_CloseSession, [:ulong], :CK_RV
|
65
|
+
|
66
|
+
import_function :C_Login, [:ulong, :ulong, :string, :ulong], :CK_RV
|
67
|
+
import_function :C_Logout, [:ulong], :CK_RV
|
68
|
+
|
69
|
+
import_function :C_FindObjectsInit, [:ulong, :pointer, :ulong], :CK_RV
|
70
|
+
import_function :C_FindObjects, [:ulong, :pointer, :ulong, :pointer], :CK_RV
|
71
|
+
import_function :C_FindObjectsFinal, [:ulong], :CK_RV
|
72
|
+
|
73
|
+
import_function :C_DigestInit, [:ulong, :pointer], :CK_RV
|
74
|
+
import_function :C_Digest, [:ulong, :pointer, :ulong, :pointer, :pointer], :CK_RV
|
75
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
module Pkcs11
|
2
|
+
RETURN_VALUES = {}
|
3
|
+
|
4
|
+
class ReturnValue
|
5
|
+
attr_reader :result
|
6
|
+
|
7
|
+
def self.[](result)
|
8
|
+
if RETURN_VALUES.has_key? result
|
9
|
+
RETURN_VALUES[result]
|
10
|
+
elsif result >= CKR_VENDOR_DEFINED.result
|
11
|
+
ReturnValue.new(result, :CKR_VENDOR_DEFINED)
|
12
|
+
else
|
13
|
+
raise "Unknown CKR result: #{result}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def ok?
|
18
|
+
@result == 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def inspect
|
22
|
+
to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
if @symbol == :CKR_VENDOR_DEFINED
|
27
|
+
"#{@symbol}_#{sprintf('0x%x', @result)}"
|
28
|
+
else
|
29
|
+
@symbol.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def initialize(result, symbol)
|
36
|
+
@result = result
|
37
|
+
@symbol = symbol
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.define_code(symbol, result)
|
42
|
+
return_value = ReturnValue.new(result, symbol)
|
43
|
+
self.const_set symbol, return_value
|
44
|
+
|
45
|
+
RETURN_VALUES[result] = return_value
|
46
|
+
end
|
47
|
+
|
48
|
+
define_code :CKR_OK, 0x00000000
|
49
|
+
define_code :CKR_CANCEL, 0x00000001
|
50
|
+
define_code :CKR_HOST_MEMORY, 0x00000002
|
51
|
+
define_code :CKR_SLOT_ID_INVALID, 0x00000003
|
52
|
+
|
53
|
+
define_code :CKR_GENERAL_ERROR, 0x00000005
|
54
|
+
define_code :CKR_FUNCTION_FAILED, 0x00000006
|
55
|
+
|
56
|
+
define_code :CKR_ARGUMENTS_BAD, 0x00000007
|
57
|
+
define_code :CKR_NO_EVENT, 0x00000008
|
58
|
+
define_code :CKR_NEED_TO_CREATE_THREADS, 0x00000009
|
59
|
+
define_code :CKR_CANT_LOCK, 0x0000000A
|
60
|
+
|
61
|
+
define_code :CKR_ATTRIBUTE_READ_ONLY, 0x00000010
|
62
|
+
define_code :CKR_ATTRIBUTE_SENSITIVE, 0x00000011
|
63
|
+
define_code :CKR_ATTRIBUTE_TYPE_INVALID, 0x00000012
|
64
|
+
define_code :CKR_ATTRIBUTE_result_INVALID, 0x00000013
|
65
|
+
define_code :CKR_DATA_INVALID, 0x00000020
|
66
|
+
define_code :CKR_DATA_LEN_RANGE, 0x00000021
|
67
|
+
define_code :CKR_DEVICE_ERROR, 0x00000030
|
68
|
+
define_code :CKR_DEVICE_MEMORY, 0x00000031
|
69
|
+
define_code :CKR_DEVICE_REMOVED, 0x00000032
|
70
|
+
define_code :CKR_ENCRYPTED_DATA_INVALID, 0x00000040
|
71
|
+
define_code :CKR_ENCRYPTED_DATA_LEN_RANGE, 0x00000041
|
72
|
+
define_code :CKR_FUNCTION_CANCELED, 0x00000050
|
73
|
+
define_code :CKR_FUNCTION_NOT_PARALLEL, 0x00000051
|
74
|
+
|
75
|
+
define_code :CKR_FUNCTION_NOT_SUPPORTED, 0x00000054
|
76
|
+
|
77
|
+
define_code :CKR_KEY_HANDLE_INVALID, 0x00000060
|
78
|
+
|
79
|
+
define_code :CKR_KEY_SIZE_RANGE, 0x00000062
|
80
|
+
define_code :CKR_KEY_TYPE_INCONSISTENT, 0x00000063
|
81
|
+
|
82
|
+
define_code :CKR_KEY_NOT_NEEDED, 0x00000064
|
83
|
+
define_code :CKR_KEY_CHANGED, 0x00000065
|
84
|
+
define_code :CKR_KEY_NEEDED, 0x00000066
|
85
|
+
define_code :CKR_KEY_INDIGESTIBLE, 0x00000067
|
86
|
+
define_code :CKR_KEY_FUNCTION_NOT_PERMITTED, 0x00000068
|
87
|
+
define_code :CKR_KEY_NOT_WRAPPABLE, 0x00000069
|
88
|
+
define_code :CKR_KEY_UNEXTRACTABLE, 0x0000006A
|
89
|
+
|
90
|
+
define_code :CKR_MECHANISM_INVALID, 0x00000070
|
91
|
+
define_code :CKR_MECHANISM_PARAM_INVALID, 0x00000071
|
92
|
+
|
93
|
+
define_code :CKR_OBJECT_HANDLE_INVALID, 0x00000082
|
94
|
+
define_code :CKR_OPERATION_ACTIVE, 0x00000090
|
95
|
+
define_code :CKR_OPERATION_NOT_INITIALIZED, 0x00000091
|
96
|
+
define_code :CKR_PIN_INCORRECT, 0x000000A0
|
97
|
+
define_code :CKR_PIN_INVALID, 0x000000A1
|
98
|
+
define_code :CKR_PIN_LEN_RANGE, 0x000000A2
|
99
|
+
|
100
|
+
define_code :CKR_PIN_EXPIRED, 0x000000A3
|
101
|
+
define_code :CKR_PIN_LOCKED, 0x000000A4
|
102
|
+
|
103
|
+
define_code :CKR_SESSION_CLOSED, 0x000000B0
|
104
|
+
define_code :CKR_SESSION_COUNT, 0x000000B1
|
105
|
+
define_code :CKR_SESSION_HANDLE_INVALID, 0x000000B3
|
106
|
+
define_code :CKR_SESSION_PARALLEL_NOT_SUPPORTED, 0x000000B4
|
107
|
+
define_code :CKR_SESSION_READ_ONLY, 0x000000B5
|
108
|
+
define_code :CKR_SESSION_EXISTS, 0x000000B6
|
109
|
+
|
110
|
+
define_code :CKR_SESSION_READ_ONLY_EXISTS, 0x000000B7
|
111
|
+
define_code :CKR_SESSION_READ_WRITE_SO_EXISTS, 0x000000B8
|
112
|
+
|
113
|
+
define_code :CKR_SIGNATURE_INVALID, 0x000000C0
|
114
|
+
define_code :CKR_SIGNATURE_LEN_RANGE, 0x000000C1
|
115
|
+
define_code :CKR_TEMPLATE_INCOMPLETE, 0x000000D0
|
116
|
+
define_code :CKR_TEMPLATE_INCONSISTENT, 0x000000D1
|
117
|
+
define_code :CKR_TOKEN_NOT_PRESENT, 0x000000E0
|
118
|
+
define_code :CKR_TOKEN_NOT_RECOGNIZED, 0x000000E1
|
119
|
+
define_code :CKR_TOKEN_WRITE_PROTECTED, 0x000000E2
|
120
|
+
define_code :CKR_UNWRAPPING_KEY_HANDLE_INVALID, 0x000000F0
|
121
|
+
define_code :CKR_UNWRAPPING_KEY_SIZE_RANGE, 0x000000F1
|
122
|
+
define_code :CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT, 0x000000F2
|
123
|
+
define_code :CKR_USER_ALREADY_LOGGED_IN, 0x00000100
|
124
|
+
define_code :CKR_USER_NOT_LOGGED_IN, 0x00000101
|
125
|
+
define_code :CKR_USER_PIN_NOT_INITIALIZED, 0x00000102
|
126
|
+
define_code :CKR_USER_TYPE_INVALID, 0x00000103
|
127
|
+
|
128
|
+
define_code :CKR_USER_ANOTHER_ALREADY_LOGGED_IN, 0x00000104
|
129
|
+
define_code :CKR_USER_TOO_MANY_TYPES, 0x00000105
|
130
|
+
|
131
|
+
define_code :CKR_WRAPPED_KEY_INVALID, 0x00000110
|
132
|
+
define_code :CKR_WRAPPED_KEY_LEN_RANGE, 0x00000112
|
133
|
+
define_code :CKR_WRAPPING_KEY_HANDLE_INVALID, 0x00000113
|
134
|
+
define_code :CKR_WRAPPING_KEY_SIZE_RANGE, 0x00000114
|
135
|
+
define_code :CKR_WRAPPING_KEY_TYPE_INCONSISTENT, 0x00000115
|
136
|
+
define_code :CKR_RANDOM_SEED_NOT_SUPPORTED, 0x00000120
|
137
|
+
|
138
|
+
define_code :CKR_RANDOM_NO_RNG, 0x00000121
|
139
|
+
|
140
|
+
define_code :CKR_DOMAIN_PARAMS_INVALID, 0x00000130
|
141
|
+
|
142
|
+
define_code :CKR_BUFFER_TOO_SMALL, 0x00000150
|
143
|
+
define_code :CKR_SAVED_STATE_INVALID, 0x00000160
|
144
|
+
define_code :CKR_INFORMATION_SENSITIVE, 0x00000170
|
145
|
+
define_code :CKR_STATE_UNSAVEABLE, 0x00000180
|
146
|
+
|
147
|
+
define_code :CKR_CRYPTOKI_NOT_INITIALIZED, 0x00000190
|
148
|
+
define_code :CKR_CRYPTOKI_ALREADY_INITIALIZED, 0x00000191
|
149
|
+
define_code :CKR_MUTEX_BAD, 0x000001A0
|
150
|
+
define_code :CKR_MUTEX_NOT_LOCKED, 0x000001A1
|
151
|
+
|
152
|
+
define_code :CKR_NEW_PIN_MODE, 0x000001B0
|
153
|
+
define_code :CKR_NEXT_OTP, 0x000001B1
|
154
|
+
|
155
|
+
define_code :CKR_FUNCTION_REJECTED, 0x00000200
|
156
|
+
|
157
|
+
define_code :CKR_VENDOR_DEFINED, 0x80000000
|
158
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Pkcs11
|
2
|
+
class Session
|
3
|
+
def initialize
|
4
|
+
@session_pointer = FFI::MemoryPointer.new(:ulong)
|
5
|
+
@session_pointer.write_ulong(0)
|
6
|
+
end
|
7
|
+
|
8
|
+
def close
|
9
|
+
result = Pkcs11.C_CloseSession(session_handle)
|
10
|
+
check result
|
11
|
+
|
12
|
+
@session_pointer.write_ulong(0)
|
13
|
+
end
|
14
|
+
|
15
|
+
def closed?
|
16
|
+
@session_pointer.read_ulong == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def login(pin)
|
20
|
+
result = Pkcs11.C_Login(session_handle, Pkcs11::CKU_USER, pin, pin.size)
|
21
|
+
check result
|
22
|
+
if block_given?
|
23
|
+
begin
|
24
|
+
yield self
|
25
|
+
ensure
|
26
|
+
logout
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def logout
|
32
|
+
result = Pkcs11::C_Logout(session_handle)
|
33
|
+
check result
|
34
|
+
end
|
35
|
+
|
36
|
+
def open(slot, flags = default_flags)
|
37
|
+
result = Pkcs11.C_OpenSession(slot,
|
38
|
+
flags,
|
39
|
+
nil, nil, @session_pointer)
|
40
|
+
check result
|
41
|
+
if block_given?
|
42
|
+
begin
|
43
|
+
yield self
|
44
|
+
ensure
|
45
|
+
close
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def session_handle
|
51
|
+
@session_pointer.read_ulong
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def check(result)
|
57
|
+
raise Pkcs11::Error.new(result.to_s) unless result == Pkcs11::CKR_OK
|
58
|
+
end
|
59
|
+
|
60
|
+
def default_flags
|
61
|
+
Pkcs11::CKF_RW_SESSION | Pkcs11::CKF_SERIAL_SESSION
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ffi-pkcs11
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vincent Touchard
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- touchardv@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.md
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/rspec
|
98
|
+
- bin/setup
|
99
|
+
- ffi-pkcs11.gemspec
|
100
|
+
- lib/ffi-pkcs11.rb
|
101
|
+
- lib/ffi-pkcs11/error.rb
|
102
|
+
- lib/ffi-pkcs11/functions.rb
|
103
|
+
- lib/ffi-pkcs11/return_value.rb
|
104
|
+
- lib/ffi-pkcs11/session.rb
|
105
|
+
- lib/ffi-pkcs11/version.rb
|
106
|
+
homepage: https://github.com/touchardv/ffi-pkcs11
|
107
|
+
licenses: []
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.6.13
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Minimalistic Ruby FFI bindings for using a "Cryptoki" (PKCS11) library.
|
129
|
+
test_files: []
|