tem_ruby 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +47 -36
- data/Rakefile +23 -0
- data/bin/tem_bench +0 -0
- data/bin/tem_ca +0 -0
- data/bin/tem_irb +1 -8
- data/bin/tem_proxy +65 -0
- data/bin/tem_stat +8 -12
- data/dev_ca/config.yml +2 -0
- data/lib/tem/auto_conf.rb +25 -0
- data/lib/tem/buffers.rb +21 -34
- data/lib/tem/crypto_abi.rb +78 -30
- data/lib/tem/keys.rb +21 -22
- data/lib/tem/lifecycle.rb +2 -2
- data/lib/tem/seclosures.rb +9 -13
- data/lib/tem/tag.rb +19 -14
- data/lib/tem/tem.rb +9 -25
- data/lib/tem/transport/auto_configurator.rb +87 -0
- data/lib/tem/transport/java_card_mixin.rb +99 -0
- data/lib/tem/transport/jcop_remote_protocol.rb +51 -0
- data/lib/tem/transport/jcop_remote_server.rb +171 -0
- data/lib/tem/transport/jcop_remote_transport.rb +65 -0
- data/lib/tem/transport/pcsc_transport.rb +87 -0
- data/lib/tem/transport/transport.rb +10 -0
- data/lib/tem_ruby.rb +12 -4
- data/tem_ruby.gemspec +24 -40
- data/test/_test_cert.rb +2 -13
- data/test/tem_test_case.rb +26 -0
- data/test/test_driver.rb +3 -22
- data/test/test_exceptions.rb +3 -22
- data/test/test_tem.rb +2 -21
- data/test/transport/test_auto_configurator.rb +114 -0
- data/test/transport/test_java_card_mixin.rb +90 -0
- data/test/transport/test_jcop_remote.rb +82 -0
- data/timings/timings.rb +2 -9
- metadata +94 -62
- data/lib/scard/java_card.rb +0 -31
- data/lib/scard/jcop_remote_terminal.rb +0 -52
- data/lib/scard/pcsc_terminal.rb +0 -83
data/timings/timings.rb
CHANGED
@@ -10,14 +10,7 @@ require 'timings/vm_perf_bound.rb'
|
|
10
10
|
|
11
11
|
class TemTimings
|
12
12
|
def setup
|
13
|
-
@
|
14
|
-
unless @terminal.connect
|
15
|
-
@terminal.disconnect
|
16
|
-
@terminal = Tem::SCard::PCSCTerminal.new
|
17
|
-
@terminal.connect
|
18
|
-
end
|
19
|
-
@javacard = Tem::SCard::JavaCard.new(@terminal)
|
20
|
-
@tem = Tem::Session.new(@javacard)
|
13
|
+
@tem = Tem.auto_tem
|
21
14
|
|
22
15
|
@tem.kill
|
23
16
|
@tem.activate
|
@@ -26,7 +19,7 @@ class TemTimings
|
|
26
19
|
|
27
20
|
def teardown
|
28
21
|
@tem.kill
|
29
|
-
@
|
22
|
+
@tem.disconnect if @tem
|
30
23
|
end
|
31
24
|
|
32
25
|
def do_timing
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tem_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Costan
|
@@ -9,11 +9,12 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-04-08 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: smartcard
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -21,90 +22,118 @@ dependencies:
|
|
21
22
|
- !ruby/object:Gem::Version
|
22
23
|
version: 0.3.0
|
23
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: echoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
24
35
|
description: TEM (Trusted Execution Module) driver, written in and for ruby.
|
25
36
|
email: victor@costan.us
|
26
37
|
executables:
|
27
|
-
-
|
38
|
+
- tem_bench
|
28
39
|
- tem_ca
|
29
40
|
- tem_irb
|
30
|
-
-
|
41
|
+
- tem_proxy
|
42
|
+
- tem_stat
|
31
43
|
extensions: []
|
32
44
|
|
33
45
|
extra_rdoc_files:
|
34
|
-
- bin/
|
46
|
+
- bin/tem_bench
|
35
47
|
- bin/tem_ca
|
36
48
|
- bin/tem_irb
|
37
|
-
- bin/
|
38
|
-
-
|
39
|
-
-
|
40
|
-
- lib/scard/jcop_remote_terminal.rb
|
41
|
-
- lib/scard/pcsc_terminal.rb
|
42
|
-
- lib/tem_ruby.rb
|
43
|
-
- lib/tem/tag.rb
|
44
|
-
- lib/tem/keys.rb
|
45
|
-
- lib/tem/sec_opcodes.rb
|
49
|
+
- bin/tem_proxy
|
50
|
+
- bin/tem_stat
|
51
|
+
- CHANGELOG
|
46
52
|
- lib/tem/_cert.rb
|
47
|
-
- lib/tem/buffers.rb
|
48
|
-
- lib/tem/toolkit.rb
|
49
|
-
- lib/tem/tem.rb
|
50
53
|
- lib/tem/abi.rb
|
51
|
-
- lib/tem/
|
54
|
+
- lib/tem/auto_conf.rb
|
55
|
+
- lib/tem/buffers.rb
|
52
56
|
- lib/tem/ca.rb
|
53
|
-
- lib/tem/
|
54
|
-
- lib/tem/sec_exec_error.rb
|
55
|
-
- lib/tem/sec_assembler.rb
|
56
|
-
- lib/tem/lifecycle.rb
|
57
|
+
- lib/tem/crypto_abi.rb
|
57
58
|
- lib/tem/ecert.rb
|
58
59
|
- lib/tem/hive.rb
|
60
|
+
- lib/tem/keys.rb
|
61
|
+
- lib/tem/lifecycle.rb
|
62
|
+
- lib/tem/sec_assembler.rb
|
63
|
+
- lib/tem/sec_exec_error.rb
|
64
|
+
- lib/tem/sec_opcodes.rb
|
59
65
|
- lib/tem/seclosures.rb
|
66
|
+
- lib/tem/secpack.rb
|
67
|
+
- lib/tem/tag.rb
|
68
|
+
- lib/tem/tem.rb
|
69
|
+
- lib/tem/toolkit.rb
|
70
|
+
- lib/tem/transport/auto_configurator.rb
|
71
|
+
- lib/tem/transport/java_card_mixin.rb
|
72
|
+
- lib/tem/transport/jcop_remote_protocol.rb
|
73
|
+
- lib/tem/transport/jcop_remote_server.rb
|
74
|
+
- lib/tem/transport/jcop_remote_transport.rb
|
75
|
+
- lib/tem/transport/pcsc_transport.rb
|
76
|
+
- lib/tem/transport/transport.rb
|
77
|
+
- lib/tem_ruby.rb
|
78
|
+
- LICENSE
|
60
79
|
- README
|
61
|
-
- CHANGELOG
|
62
80
|
files:
|
63
|
-
- bin/
|
81
|
+
- bin/tem_bench
|
64
82
|
- bin/tem_ca
|
65
83
|
- bin/tem_irb
|
66
|
-
- bin/
|
67
|
-
-
|
68
|
-
-
|
69
|
-
-
|
70
|
-
-
|
71
|
-
-
|
72
|
-
-
|
73
|
-
- timings/vm_perf.rb
|
74
|
-
- timings/devchip_decrypt.rb
|
75
|
-
- timings/simple_apdu.rb
|
76
|
-
- timings/post_buffer.rb
|
77
|
-
- timings/blank_bound_secpack.rb
|
78
|
-
- timings/vm_perf_bound.rb
|
79
|
-
- timings/timings.rb
|
80
|
-
- timings/blank_sec.rb
|
81
|
-
- lib/scard/java_card.rb
|
82
|
-
- lib/scard/jcop_remote_terminal.rb
|
83
|
-
- lib/scard/pcsc_terminal.rb
|
84
|
-
- lib/tem_ruby.rb
|
85
|
-
- lib/tem/tag.rb
|
86
|
-
- lib/tem/keys.rb
|
87
|
-
- lib/tem/sec_opcodes.rb
|
84
|
+
- bin/tem_proxy
|
85
|
+
- bin/tem_stat
|
86
|
+
- CHANGELOG
|
87
|
+
- dev_ca/ca_cert.cer
|
88
|
+
- dev_ca/ca_cert.pem
|
89
|
+
- dev_ca/ca_key.pem
|
90
|
+
- dev_ca/config.yml
|
88
91
|
- lib/tem/_cert.rb
|
89
|
-
- lib/tem/buffers.rb
|
90
|
-
- lib/tem/toolkit.rb
|
91
|
-
- lib/tem/tem.rb
|
92
92
|
- lib/tem/abi.rb
|
93
|
-
- lib/tem/
|
93
|
+
- lib/tem/auto_conf.rb
|
94
|
+
- lib/tem/buffers.rb
|
94
95
|
- lib/tem/ca.rb
|
95
|
-
- lib/tem/
|
96
|
-
- lib/tem/sec_exec_error.rb
|
97
|
-
- lib/tem/sec_assembler.rb
|
98
|
-
- lib/tem/lifecycle.rb
|
96
|
+
- lib/tem/crypto_abi.rb
|
99
97
|
- lib/tem/ecert.rb
|
100
98
|
- lib/tem/hive.rb
|
99
|
+
- lib/tem/keys.rb
|
100
|
+
- lib/tem/lifecycle.rb
|
101
|
+
- lib/tem/sec_assembler.rb
|
102
|
+
- lib/tem/sec_exec_error.rb
|
103
|
+
- lib/tem/sec_opcodes.rb
|
101
104
|
- lib/tem/seclosures.rb
|
105
|
+
- lib/tem/secpack.rb
|
106
|
+
- lib/tem/tag.rb
|
107
|
+
- lib/tem/tem.rb
|
108
|
+
- lib/tem/toolkit.rb
|
109
|
+
- lib/tem/transport/auto_configurator.rb
|
110
|
+
- lib/tem/transport/java_card_mixin.rb
|
111
|
+
- lib/tem/transport/jcop_remote_protocol.rb
|
112
|
+
- lib/tem/transport/jcop_remote_server.rb
|
113
|
+
- lib/tem/transport/jcop_remote_transport.rb
|
114
|
+
- lib/tem/transport/pcsc_transport.rb
|
115
|
+
- lib/tem/transport/transport.rb
|
116
|
+
- lib/tem_ruby.rb
|
117
|
+
- LICENSE
|
118
|
+
- Manifest
|
119
|
+
- Rakefile
|
102
120
|
- README
|
103
|
-
-
|
104
|
-
-
|
105
|
-
-
|
106
|
-
-
|
107
|
-
-
|
121
|
+
- test/_test_cert.rb
|
122
|
+
- test/tem_test_case.rb
|
123
|
+
- test/test_driver.rb
|
124
|
+
- test/test_exceptions.rb
|
125
|
+
- test/test_tem.rb
|
126
|
+
- test/transport/test_auto_configurator.rb
|
127
|
+
- test/transport/test_java_card_mixin.rb
|
128
|
+
- test/transport/test_jcop_remote.rb
|
129
|
+
- timings/blank_bound_secpack.rb
|
130
|
+
- timings/blank_sec.rb
|
131
|
+
- timings/devchip_decrypt.rb
|
132
|
+
- timings/post_buffer.rb
|
133
|
+
- timings/simple_apdu.rb
|
134
|
+
- timings/timings.rb
|
135
|
+
- timings/vm_perf.rb
|
136
|
+
- timings/vm_perf_bound.rb
|
108
137
|
- tem_ruby.gemspec
|
109
138
|
has_rdoc: true
|
110
139
|
homepage: http://tem.rubyforge.org
|
@@ -128,16 +157,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
157
|
requirements:
|
129
158
|
- - ">="
|
130
159
|
- !ruby/object:Gem::Version
|
131
|
-
version: "
|
160
|
+
version: "1.2"
|
132
161
|
version:
|
133
162
|
requirements: []
|
134
163
|
|
135
164
|
rubyforge_project: tem
|
136
|
-
rubygems_version: 1.
|
165
|
+
rubygems_version: 1.3.1
|
137
166
|
signing_key:
|
138
167
|
specification_version: 2
|
139
168
|
summary: TEM (Trusted Execution Module) driver, written in and for ruby.
|
140
169
|
test_files:
|
141
170
|
- test/test_driver.rb
|
142
|
-
- test/test_tem.rb
|
143
171
|
- test/test_exceptions.rb
|
172
|
+
- test/test_tem.rb
|
173
|
+
- test/transport/test_auto_configurator.rb
|
174
|
+
- test/transport/test_java_card_mixin.rb
|
175
|
+
- test/transport/test_jcop_remote.rb
|
data/lib/scard/java_card.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
class Tem::SCard::JavaCard
|
2
|
-
attr_accessor :terminal
|
3
|
-
|
4
|
-
def initialize(_terminal = nil)
|
5
|
-
@terminal = _terminal
|
6
|
-
end
|
7
|
-
|
8
|
-
def select_applet(aid)
|
9
|
-
result = @terminal.issue_apdu [0x00, 0xA4, 0x04, 0x00, aid.length, aid].flatten
|
10
|
-
(result == [0x90, 0x00])
|
11
|
-
end
|
12
|
-
|
13
|
-
def issue_apdu(apdu)
|
14
|
-
@terminal.issue_apdu apdu
|
15
|
-
end
|
16
|
-
|
17
|
-
# returns the failure code of an operation (success would be 0x9000)
|
18
|
-
# returns nil for success
|
19
|
-
def failure_code(reply_apdu)
|
20
|
-
status = reply_apdu[-2] * 256 + reply_apdu.length[-1]
|
21
|
-
return (status == 0x9000) ? nil : status
|
22
|
-
end
|
23
|
-
|
24
|
-
def reply_data(reply_apdu)
|
25
|
-
return reply_apdu[0...-2]
|
26
|
-
end
|
27
|
-
|
28
|
-
def install_applet(cap_contents)
|
29
|
-
raise "Not implemeted; it'd be nice though, right?"
|
30
|
-
end
|
31
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'socket'
|
2
|
-
class Tem::SCard::JCOPRemoteTerminal
|
3
|
-
def initialize(remote_host = 'localhost', remote_port = 8050)
|
4
|
-
@remote_host = remote_host
|
5
|
-
@remote_port = remote_port
|
6
|
-
@sockaddr = Socket.pack_sockaddr_in(@remote_port, @remote_host)
|
7
|
-
@socket = nil
|
8
|
-
end
|
9
|
-
|
10
|
-
def send_message(payload, message_type = 1, node_address = 0)
|
11
|
-
@socket.send [message_type, node_address, payload.length / 256, payload.length % 256, payload].flatten.pack('C*'), 0
|
12
|
-
end
|
13
|
-
|
14
|
-
def receive_message
|
15
|
-
header = @socket.recv(4)
|
16
|
-
message_type, node_address, payload_length = *header.unpack('CCn')
|
17
|
-
return @socket.recv(payload_length).unpack('C*')
|
18
|
-
end
|
19
|
-
|
20
|
-
def connect
|
21
|
-
begin
|
22
|
-
# connect to the terminal
|
23
|
-
@socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
24
|
-
@socket.connect(@sockaddr)
|
25
|
-
|
26
|
-
# wait for the card to be inserted
|
27
|
-
send_message [0, 1, 0, 0], 0
|
28
|
-
receive_message # ATR should come here, but who cares
|
29
|
-
rescue
|
30
|
-
@socket = nil
|
31
|
-
return false
|
32
|
-
end
|
33
|
-
return true
|
34
|
-
end
|
35
|
-
|
36
|
-
def to_s
|
37
|
-
"#<JCOP Remote Terminal: disconnected>" if @socket.nil?
|
38
|
-
"#<JCOP Remote Terminal: #{@remote_host}:#{@remote_port}>"
|
39
|
-
end
|
40
|
-
|
41
|
-
def disconnect
|
42
|
-
unless @socket.nil?
|
43
|
-
@socket.close
|
44
|
-
@socket = nil
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def issue_apdu(apdu)
|
49
|
-
send_message apdu
|
50
|
-
return receive_message
|
51
|
-
end
|
52
|
-
end
|
data/lib/scard/pcsc_terminal.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'pp'
|
2
|
-
|
3
|
-
class Tem::SCard::PCSCTerminal
|
4
|
-
include Smartcard
|
5
|
-
|
6
|
-
@@xmit_iorequest = {
|
7
|
-
Smartcard::PCSC::PROTOCOL_T0 => Smartcard::PCSC::IOREQUEST_T0,
|
8
|
-
Smartcard::PCSC::PROTOCOL_T1 => Smartcard::PCSC::IOREQUEST_T1,
|
9
|
-
}
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
@context = nil
|
13
|
-
@readers = nil
|
14
|
-
@card = nil
|
15
|
-
end
|
16
|
-
|
17
|
-
def connect
|
18
|
-
begin
|
19
|
-
@context = PCSC::Context.new(PCSC::SCOPE_SYSTEM) if @context.nil?
|
20
|
-
|
21
|
-
# get the first reader
|
22
|
-
@readers = @context.list_readers nil
|
23
|
-
@reader_name = @readers.first
|
24
|
-
|
25
|
-
# get the reader's status
|
26
|
-
reader_states = PCSC::ReaderStates.new(1)
|
27
|
-
reader_states.set_reader_name_of!(0, @reader_name)
|
28
|
-
reader_states.set_current_state_of!(0, PCSC::STATE_UNKNOWN)
|
29
|
-
@context.get_status_change reader_states, 100
|
30
|
-
reader_states.acknowledge_events!
|
31
|
-
|
32
|
-
# prompt for card insertion unless that already happened
|
33
|
-
if (reader_states.current_state_of(0) & PCSC::STATE_PRESENT) == 0
|
34
|
-
puts "Please insert TEM card in reader #{@reader_name}\n"
|
35
|
-
while (reader_states.current_state_of(0) & PCSC::STATE_PRESENT) == 0 do
|
36
|
-
@context.get_status_change reader_states, PCSC::INFINITE_TIMEOUT
|
37
|
-
reader_states.acknowledge_events!
|
38
|
-
end
|
39
|
-
puts "Card detected\n"
|
40
|
-
end
|
41
|
-
|
42
|
-
# connect to card
|
43
|
-
@card = PCSC::Card.new(@context, @reader_name, PCSC::SHARE_EXCLUSIVE, PCSC::PROTOCOL_ANY)
|
44
|
-
|
45
|
-
# build the transmit / receive IoRequests
|
46
|
-
status = @card.status
|
47
|
-
@xmit_ioreq = @@xmit_iorequest[status[:protocol]]
|
48
|
-
if RUBY_PLATFORM =~ /win/ and (not RUBY_PLATFORM =~ /darwin/)
|
49
|
-
@recv_ioreq = nil
|
50
|
-
else
|
51
|
-
@recv_ioreq = PCSC::IoRequest.new
|
52
|
-
end
|
53
|
-
rescue
|
54
|
-
return false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def to_s
|
59
|
-
"#<PC/SC Terminal: disconnected>" if @card.nil?
|
60
|
-
"#<PC/SC Terminal: #{@reader_name}>"
|
61
|
-
end
|
62
|
-
|
63
|
-
def disconnect
|
64
|
-
unless @card.nil?
|
65
|
-
@card.disconnect PCSC::DISPOSITION_LEAVE unless @card.nil?
|
66
|
-
@card = nil
|
67
|
-
end
|
68
|
-
unless @context.nil?
|
69
|
-
@context.release
|
70
|
-
@context = nil
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def issue_apdu(apdu)
|
75
|
-
xmit_apdu_string = apdu.map { |byte| byte.chr }.join('')
|
76
|
-
result_string = @card.transmit xmit_apdu_string, @xmit_ioreq, @recv_ioreq
|
77
|
-
return (0...(result_string.length)).map { |i| result_string[i].to_i }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# for compatibility with old source code
|
82
|
-
class Tem::SCard::Terminal < Tem::SCard::PCSCTerminal
|
83
|
-
end
|