tem_ruby 0.11.3 → 0.11.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +1 -10
- data/Rakefile +1 -1
- data/bin/tem_proxy +4 -4
- data/lib/tem/apdus/buffers.rb +15 -8
- data/lib/tem/apdus/keys.rb +11 -5
- data/lib/tem/apdus/lifecycle.rb +10 -3
- data/lib/tem/apdus/tag.rb +10 -3
- data/lib/tem/auto_conf.rb +8 -5
- data/lib/tem/benchmarks/benchmarks.rb +7 -0
- data/lib/tem/benchmarks/blank_bound_secpack.rb +10 -0
- data/lib/tem/benchmarks/blank_sec.rb +14 -0
- data/lib/tem/benchmarks/devchip_decrypt.rb +12 -0
- data/lib/tem/benchmarks/post_buffer.rb +8 -0
- data/lib/tem/benchmarks/simple_apdu.rb +11 -0
- data/lib/tem/benchmarks/vm_perf.rb +11 -0
- data/lib/tem/benchmarks/vm_perf_bound.rb +12 -0
- data/lib/tem/builders/abi.rb +19 -13
- data/lib/tem/builders/assembler.rb +23 -16
- data/lib/tem/builders/crypto.rb +9 -3
- data/lib/tem/builders/isa.rb +10 -4
- data/lib/tem/definitions/abi.rb +9 -0
- data/lib/tem/definitions/assembler.rb +10 -0
- data/lib/tem/definitions/isa.rb +10 -0
- data/lib/tem/seclosures.rb +5 -5
- data/lib/tem/tem.rb +2 -1
- data/lib/tem_ruby.rb +0 -12
- data/tem_ruby.gemspec +9 -9
- data/test/builders/test_abi_builder.rb +4 -2
- data/test/tem_test_case.rb +3 -2
- data/test/tem_unit/test_tem_alu.rb +1 -1
- data/test/tem_unit/test_tem_bound_secpack.rb +1 -1
- data/test/tem_unit/test_tem_branching.rb +1 -1
- data/test/tem_unit/test_tem_crypto_asymmetric.rb +1 -1
- data/test/tem_unit/test_tem_crypto_hash.rb +1 -1
- data/test/tem_unit/test_tem_crypto_pstore.rb +1 -1
- data/test/tem_unit/test_tem_crypto_random.rb +1 -1
- data/test/tem_unit/test_tem_emit.rb +1 -1
- data/test/tem_unit/test_tem_memory.rb +1 -1
- data/test/tem_unit/test_tem_memory_compare.rb +1 -1
- data/test/tem_unit/test_tem_output.rb +1 -1
- data/test/tem_unit/test_tem_yaml_secpack.rb +4 -3
- data/test/test_auto_conf.rb +2 -0
- data/test/test_driver.rb +2 -1
- data/test/test_exceptions.rb +12 -6
- metadata +5 -24
- data/lib/tem/transport/auto_configurator.rb +0 -87
- data/lib/tem/transport/java_card_mixin.rb +0 -99
- data/lib/tem/transport/jcop_remote_protocol.rb +0 -59
- data/lib/tem/transport/jcop_remote_server.rb +0 -171
- data/lib/tem/transport/jcop_remote_transport.rb +0 -65
- data/lib/tem/transport/pcsc_transport.rb +0 -87
- data/lib/tem/transport/transport.rb +0 -10
- data/test/transport/test_auto_configurator.rb +0 -114
- data/test/transport/test_java_card_mixin.rb +0 -90
- data/test/transport/test_jcop_remote.rb +0 -82
@@ -1,3 +1,13 @@
|
|
1
|
+
# The TEM's assembly language definition.
|
2
|
+
#
|
3
|
+
# This code is the official specification, because Victor likes executable
|
4
|
+
# specifications.
|
5
|
+
#
|
6
|
+
# Author:: Victor Costan
|
7
|
+
# Copyright:: Copyright (C) 2007 Massachusetts Institute of Technology
|
8
|
+
# License:: MIT
|
9
|
+
|
10
|
+
|
1
11
|
class Tem::Assembler
|
2
12
|
Tem::Builders::Assembler.define_assembler self do |assembler|
|
3
13
|
assembler.target_isa Tem::Isa
|
data/lib/tem/definitions/isa.rb
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# The TEM's ISA (Instruction Set Architecture) definition.
|
2
|
+
#
|
3
|
+
# This code is the official specification, because Victor likes executable
|
4
|
+
# specifications.
|
5
|
+
#
|
6
|
+
# Author:: Victor Costan
|
7
|
+
# Copyright:: Copyright (C) 2007 Massachusetts Institute of Technology
|
8
|
+
# License:: MIT
|
9
|
+
|
10
|
+
|
1
11
|
module Tem::Isa
|
2
12
|
Tem::Builders::Isa.define_isa self, Tem::Abi,
|
3
13
|
:opcode_type => :tem_ubyte do |isa|
|
data/lib/tem/seclosures.rb
CHANGED
@@ -14,7 +14,7 @@ module Tem::SeClosures
|
|
14
14
|
|
15
15
|
def sec_trace
|
16
16
|
#begin
|
17
|
-
trace = @transport.
|
17
|
+
trace = @transport.iso_apdu! :ins => 0x54
|
18
18
|
if trace.length > 2
|
19
19
|
case read_tem_short(trace, 0) # trace version
|
20
20
|
when 1
|
@@ -31,20 +31,20 @@ module Tem::SeClosures
|
|
31
31
|
def solve_psfault
|
32
32
|
# TODO: better strategy, lol
|
33
33
|
next_cell = rand(16)
|
34
|
-
@transport.
|
34
|
+
@transport.iso_apdu! :ins => 0x53, :p12 => to_tem_ushort(next_cell)
|
35
35
|
end
|
36
36
|
|
37
37
|
def execute(secpack, key_id = 0)
|
38
38
|
# load SECpack
|
39
39
|
buffer_id = post_buffer(secpack.tem_formatted_body)
|
40
|
-
response = @transport.
|
40
|
+
response = @transport.iso_apdu! :ins => 0x50, :p1 => buffer_id,
|
41
41
|
:p2 => key_id
|
42
42
|
tem_secpack_error(response) if read_tem_byte(response, 0) != 1
|
43
43
|
|
44
44
|
# execute SEC
|
45
45
|
sec_exception = nil
|
46
46
|
loop do
|
47
|
-
response = @transport.
|
47
|
+
response = @transport.iso_apdu! :ins => 0x52
|
48
48
|
sec_status = read_tem_byte(response, 0)
|
49
49
|
case sec_status
|
50
50
|
when 2 # success
|
@@ -64,7 +64,7 @@ module Tem::SeClosures
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# unbind SEC
|
67
|
-
response = @transport.
|
67
|
+
response = @transport.iso_apdu! :ins => 0x51
|
68
68
|
raise sec_exception if sec_exception
|
69
69
|
buffer_id = read_tem_byte(response, 0)
|
70
70
|
buffer_length = read_tem_short(response, 1)
|
data/lib/tem/tem.rb
CHANGED
data/lib/tem_ruby.rb
CHANGED
@@ -6,18 +6,6 @@ require 'smartcard'
|
|
6
6
|
module Tem
|
7
7
|
end
|
8
8
|
|
9
|
-
# :nodoc:
|
10
|
-
module Tem::Transport
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'tem/transport/transport.rb'
|
14
|
-
require 'tem/transport/java_card_mixin.rb'
|
15
|
-
require 'tem/transport/pcsc_transport.rb'
|
16
|
-
require 'tem/transport/jcop_remote_protocol.rb'
|
17
|
-
require 'tem/transport/jcop_remote_transport.rb'
|
18
|
-
require 'tem/transport/jcop_remote_server.rb'
|
19
|
-
require 'tem/transport/auto_configurator.rb'
|
20
|
-
|
21
9
|
require 'tem/keys/key.rb'
|
22
10
|
require 'tem/keys/asymmetric.rb'
|
23
11
|
require 'tem/keys/symmetric.rb'
|
data/tem_ruby.gemspec
CHANGED
@@ -2,34 +2,34 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{tem_ruby}
|
5
|
-
s.version = "0.11.
|
5
|
+
s.version = "0.11.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Victor Costan"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-08-19}
|
10
10
|
s.description = %q{TEM (Trusted Execution Module) driver, written in and for ruby.}
|
11
11
|
s.email = %q{victor@costan.us}
|
12
12
|
s.executables = ["tem_bench", "tem_ca", "tem_irb", "tem_proxy", "tem_stat"]
|
13
|
-
s.extra_rdoc_files = ["bin/tem_bench", "bin/tem_ca", "bin/tem_irb", "bin/tem_proxy", "bin/tem_stat", "CHANGELOG", "lib/tem/_cert.rb", "lib/tem/apdus/buffers.rb", "lib/tem/apdus/keys.rb", "lib/tem/apdus/lifecycle.rb", "lib/tem/apdus/tag.rb", "lib/tem/auto_conf.rb", "lib/tem/benchmarks/benchmarks.rb", "lib/tem/benchmarks/blank_bound_secpack.rb", "lib/tem/benchmarks/blank_sec.rb", "lib/tem/benchmarks/devchip_decrypt.rb", "lib/tem/benchmarks/post_buffer.rb", "lib/tem/benchmarks/simple_apdu.rb", "lib/tem/benchmarks/vm_perf.rb", "lib/tem/benchmarks/vm_perf_bound.rb", "lib/tem/builders/abi.rb", "lib/tem/builders/assembler.rb", "lib/tem/builders/crypto.rb", "lib/tem/builders/isa.rb", "lib/tem/ca.rb", "lib/tem/definitions/abi.rb", "lib/tem/definitions/assembler.rb", "lib/tem/definitions/isa.rb", "lib/tem/ecert.rb", "lib/tem/hive.rb", "lib/tem/keys/asymmetric.rb", "lib/tem/keys/key.rb", "lib/tem/keys/symmetric.rb", "lib/tem/sec_exec_error.rb", "lib/tem/seclosures.rb", "lib/tem/secpack.rb", "lib/tem/tem.rb", "lib/tem/toolkit.rb", "lib/
|
14
|
-
s.files = ["bin/tem_bench", "bin/tem_ca", "bin/tem_irb", "bin/tem_proxy", "bin/tem_stat", "CHANGELOG", "dev_ca/ca_cert.cer", "dev_ca/ca_cert.pem", "dev_ca/ca_key.pem", "dev_ca/config.yml", "lib/tem/_cert.rb", "lib/tem/apdus/buffers.rb", "lib/tem/apdus/keys.rb", "lib/tem/apdus/lifecycle.rb", "lib/tem/apdus/tag.rb", "lib/tem/auto_conf.rb", "lib/tem/benchmarks/benchmarks.rb", "lib/tem/benchmarks/blank_bound_secpack.rb", "lib/tem/benchmarks/blank_sec.rb", "lib/tem/benchmarks/devchip_decrypt.rb", "lib/tem/benchmarks/post_buffer.rb", "lib/tem/benchmarks/simple_apdu.rb", "lib/tem/benchmarks/vm_perf.rb", "lib/tem/benchmarks/vm_perf_bound.rb", "lib/tem/builders/abi.rb", "lib/tem/builders/assembler.rb", "lib/tem/builders/crypto.rb", "lib/tem/builders/isa.rb", "lib/tem/ca.rb", "lib/tem/definitions/abi.rb", "lib/tem/definitions/assembler.rb", "lib/tem/definitions/isa.rb", "lib/tem/ecert.rb", "lib/tem/hive.rb", "lib/tem/keys/asymmetric.rb", "lib/tem/keys/key.rb", "lib/tem/keys/symmetric.rb", "lib/tem/sec_exec_error.rb", "lib/tem/seclosures.rb", "lib/tem/secpack.rb", "lib/tem/tem.rb", "lib/tem/toolkit.rb", "lib/
|
13
|
+
s.extra_rdoc_files = ["bin/tem_bench", "bin/tem_ca", "bin/tem_irb", "bin/tem_proxy", "bin/tem_stat", "CHANGELOG", "lib/tem/_cert.rb", "lib/tem/apdus/buffers.rb", "lib/tem/apdus/keys.rb", "lib/tem/apdus/lifecycle.rb", "lib/tem/apdus/tag.rb", "lib/tem/auto_conf.rb", "lib/tem/benchmarks/benchmarks.rb", "lib/tem/benchmarks/blank_bound_secpack.rb", "lib/tem/benchmarks/blank_sec.rb", "lib/tem/benchmarks/devchip_decrypt.rb", "lib/tem/benchmarks/post_buffer.rb", "lib/tem/benchmarks/simple_apdu.rb", "lib/tem/benchmarks/vm_perf.rb", "lib/tem/benchmarks/vm_perf_bound.rb", "lib/tem/builders/abi.rb", "lib/tem/builders/assembler.rb", "lib/tem/builders/crypto.rb", "lib/tem/builders/isa.rb", "lib/tem/ca.rb", "lib/tem/definitions/abi.rb", "lib/tem/definitions/assembler.rb", "lib/tem/definitions/isa.rb", "lib/tem/ecert.rb", "lib/tem/hive.rb", "lib/tem/keys/asymmetric.rb", "lib/tem/keys/key.rb", "lib/tem/keys/symmetric.rb", "lib/tem/sec_exec_error.rb", "lib/tem/seclosures.rb", "lib/tem/secpack.rb", "lib/tem/tem.rb", "lib/tem/toolkit.rb", "lib/tem_ruby.rb", "LICENSE", "README"]
|
14
|
+
s.files = ["bin/tem_bench", "bin/tem_ca", "bin/tem_irb", "bin/tem_proxy", "bin/tem_stat", "CHANGELOG", "dev_ca/ca_cert.cer", "dev_ca/ca_cert.pem", "dev_ca/ca_key.pem", "dev_ca/config.yml", "lib/tem/_cert.rb", "lib/tem/apdus/buffers.rb", "lib/tem/apdus/keys.rb", "lib/tem/apdus/lifecycle.rb", "lib/tem/apdus/tag.rb", "lib/tem/auto_conf.rb", "lib/tem/benchmarks/benchmarks.rb", "lib/tem/benchmarks/blank_bound_secpack.rb", "lib/tem/benchmarks/blank_sec.rb", "lib/tem/benchmarks/devchip_decrypt.rb", "lib/tem/benchmarks/post_buffer.rb", "lib/tem/benchmarks/simple_apdu.rb", "lib/tem/benchmarks/vm_perf.rb", "lib/tem/benchmarks/vm_perf_bound.rb", "lib/tem/builders/abi.rb", "lib/tem/builders/assembler.rb", "lib/tem/builders/crypto.rb", "lib/tem/builders/isa.rb", "lib/tem/ca.rb", "lib/tem/definitions/abi.rb", "lib/tem/definitions/assembler.rb", "lib/tem/definitions/isa.rb", "lib/tem/ecert.rb", "lib/tem/hive.rb", "lib/tem/keys/asymmetric.rb", "lib/tem/keys/key.rb", "lib/tem/keys/symmetric.rb", "lib/tem/sec_exec_error.rb", "lib/tem/seclosures.rb", "lib/tem/secpack.rb", "lib/tem/tem.rb", "lib/tem/toolkit.rb", "lib/tem_ruby.rb", "LICENSE", "Manifest", "Rakefile", "README", "test/_test_cert.rb", "test/builders/test_abi_builder.rb", "test/tem_test_case.rb", "test/tem_unit/test_tem_alu.rb", "test/tem_unit/test_tem_bound_secpack.rb", "test/tem_unit/test_tem_branching.rb", "test/tem_unit/test_tem_crypto_asymmetric.rb", "test/tem_unit/test_tem_crypto_hash.rb", "test/tem_unit/test_tem_crypto_pstore.rb", "test/tem_unit/test_tem_crypto_random.rb", "test/tem_unit/test_tem_emit.rb", "test/tem_unit/test_tem_memory.rb", "test/tem_unit/test_tem_memory_compare.rb", "test/tem_unit/test_tem_output.rb", "test/tem_unit/test_tem_yaml_secpack.rb", "test/test_auto_conf.rb", "test/test_driver.rb", "test/test_exceptions.rb", "tem_ruby.gemspec"]
|
15
15
|
s.homepage = %q{http://tem.rubyforge.org}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tem_ruby", "--main", "README"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = %q{tem}
|
19
|
-
s.rubygems_version = %q{1.3.
|
19
|
+
s.rubygems_version = %q{1.3.5}
|
20
20
|
s.summary = %q{TEM (Trusted Execution Module) driver, written in and for ruby.}
|
21
|
-
s.test_files = ["test/builders/test_abi_builder.rb", "test/tem_unit/test_tem_alu.rb", "test/tem_unit/test_tem_bound_secpack.rb", "test/tem_unit/test_tem_branching.rb", "test/tem_unit/test_tem_crypto_asymmetric.rb", "test/tem_unit/test_tem_crypto_hash.rb", "test/tem_unit/test_tem_crypto_pstore.rb", "test/tem_unit/test_tem_crypto_random.rb", "test/tem_unit/test_tem_emit.rb", "test/tem_unit/test_tem_memory.rb", "test/tem_unit/test_tem_memory_compare.rb", "test/tem_unit/test_tem_output.rb", "test/tem_unit/test_tem_yaml_secpack.rb", "test/test_auto_conf.rb", "test/test_driver.rb", "test/test_exceptions.rb"
|
21
|
+
s.test_files = ["test/builders/test_abi_builder.rb", "test/tem_unit/test_tem_alu.rb", "test/tem_unit/test_tem_bound_secpack.rb", "test/tem_unit/test_tem_branching.rb", "test/tem_unit/test_tem_crypto_asymmetric.rb", "test/tem_unit/test_tem_crypto_hash.rb", "test/tem_unit/test_tem_crypto_pstore.rb", "test/tem_unit/test_tem_crypto_random.rb", "test/tem_unit/test_tem_emit.rb", "test/tem_unit/test_tem_memory.rb", "test/tem_unit/test_tem_memory_compare.rb", "test/tem_unit/test_tem_output.rb", "test/tem_unit/test_tem_yaml_secpack.rb", "test/test_auto_conf.rb", "test/test_driver.rb", "test/test_exceptions.rb"]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
24
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
25
|
s.specification_version = 3
|
26
26
|
|
27
27
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
-
s.add_runtime_dependency(%q<smartcard>, [">= 0.
|
28
|
+
s.add_runtime_dependency(%q<smartcard>, [">= 0.4.0"])
|
29
29
|
else
|
30
|
-
s.add_dependency(%q<smartcard>, [">= 0.
|
30
|
+
s.add_dependency(%q<smartcard>, [">= 0.4.0"])
|
31
31
|
end
|
32
32
|
else
|
33
|
-
s.add_dependency(%q<smartcard>, [">= 0.
|
33
|
+
s.add_dependency(%q<smartcard>, [">= 0.4.0"])
|
34
34
|
end
|
35
35
|
end
|
data/test/tem_test_case.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
require 'tem_ruby'
|
2
|
+
|
1
3
|
require 'test/unit'
|
2
4
|
|
3
|
-
require 'tem_ruby'
|
4
5
|
|
5
6
|
# Helper methods for TEM tests.
|
6
7
|
#
|
@@ -16,7 +17,7 @@ class TemTestCase < Test::Unit::TestCase
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def teardown
|
19
|
-
@tem.disconnect
|
20
|
+
@tem.disconnect if defined?(@tem) && @tem
|
20
21
|
end
|
21
22
|
|
22
23
|
def test_smoke
|
@@ -1,7 +1,8 @@
|
|
1
|
-
require 'test/tem_test_case'
|
1
|
+
require 'test/tem_test_case.rb'
|
2
|
+
|
3
|
+
require 'test/tem_unit/test_tem_bound_secpack.rb'
|
4
|
+
require 'test/tem_unit/test_tem_memory_compare.rb'
|
2
5
|
|
3
|
-
require 'test/tem_unit/test_tem_bound_secpack'
|
4
|
-
require 'test/tem_unit/test_tem_memory_compare'
|
5
6
|
|
6
7
|
class TemOutputTest < TemTestCase
|
7
8
|
include TemBoundSecpackTestCase
|
data/test/test_auto_conf.rb
CHANGED
data/test/test_driver.rb
CHANGED
data/test/test_exceptions.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require 'test/tem_test_case'
|
1
|
+
require 'test/tem_test_case.rb'
|
2
|
+
|
2
3
|
|
3
4
|
class ExceptionsTest < TemTestCase
|
4
5
|
def test_trace
|
@@ -23,12 +24,17 @@ class ExceptionsTest < TemTestCase
|
|
23
24
|
@tem.execute bad_sec
|
24
25
|
rescue Tem::SecExecError => e
|
25
26
|
caught = true
|
26
|
-
assert_equal Hash, e.trace.class,
|
27
|
+
assert_equal Hash, e.trace.class,
|
28
|
+
"TEM exception does not have a TEM trace"
|
27
29
|
assert_equal 2, e.trace[:out], "Bad output buffer position in TEM trace"
|
28
|
-
assert_equal bad_sec.label_address(:bad_code), e.trace[:ip],
|
29
|
-
|
30
|
-
assert_equal
|
31
|
-
|
30
|
+
assert_equal bad_sec.label_address(:bad_code), e.trace[:ip],
|
31
|
+
"Bad instruction pointer in TEM trace"
|
32
|
+
assert_equal bad_sec.label_address(:stack), e.trace[:sp],
|
33
|
+
"Bad instruction pointer in TEM trace"
|
34
|
+
assert_equal Hash, e.buffer_state.class,
|
35
|
+
"TEM exception does not have buffer state information"
|
36
|
+
assert_equal Hash, e.key_state.class,
|
37
|
+
"TEM exception does not have key state information"
|
32
38
|
end
|
33
39
|
assert caught, "Executing a bad SECpack did not raise a SecExecError"
|
34
40
|
end
|
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.11.
|
4
|
+
version: 0.11.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Costan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-19 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.4.0
|
24
24
|
version:
|
25
25
|
description: TEM (Trusted Execution Module) driver, written in and for ruby.
|
26
26
|
email: victor@costan.us
|
@@ -71,13 +71,6 @@ extra_rdoc_files:
|
|
71
71
|
- lib/tem/secpack.rb
|
72
72
|
- lib/tem/tem.rb
|
73
73
|
- lib/tem/toolkit.rb
|
74
|
-
- lib/tem/transport/auto_configurator.rb
|
75
|
-
- lib/tem/transport/java_card_mixin.rb
|
76
|
-
- lib/tem/transport/jcop_remote_protocol.rb
|
77
|
-
- lib/tem/transport/jcop_remote_server.rb
|
78
|
-
- lib/tem/transport/jcop_remote_transport.rb
|
79
|
-
- lib/tem/transport/pcsc_transport.rb
|
80
|
-
- lib/tem/transport/transport.rb
|
81
74
|
- lib/tem_ruby.rb
|
82
75
|
- LICENSE
|
83
76
|
- README
|
@@ -124,13 +117,6 @@ files:
|
|
124
117
|
- lib/tem/secpack.rb
|
125
118
|
- lib/tem/tem.rb
|
126
119
|
- lib/tem/toolkit.rb
|
127
|
-
- lib/tem/transport/auto_configurator.rb
|
128
|
-
- lib/tem/transport/java_card_mixin.rb
|
129
|
-
- lib/tem/transport/jcop_remote_protocol.rb
|
130
|
-
- lib/tem/transport/jcop_remote_server.rb
|
131
|
-
- lib/tem/transport/jcop_remote_transport.rb
|
132
|
-
- lib/tem/transport/pcsc_transport.rb
|
133
|
-
- lib/tem/transport/transport.rb
|
134
120
|
- lib/tem_ruby.rb
|
135
121
|
- LICENSE
|
136
122
|
- Manifest
|
@@ -151,11 +137,9 @@ files:
|
|
151
137
|
- test/tem_unit/test_tem_memory_compare.rb
|
152
138
|
- test/tem_unit/test_tem_output.rb
|
153
139
|
- test/tem_unit/test_tem_yaml_secpack.rb
|
140
|
+
- test/test_auto_conf.rb
|
154
141
|
- test/test_driver.rb
|
155
142
|
- test/test_exceptions.rb
|
156
|
-
- test/transport/test_auto_configurator.rb
|
157
|
-
- test/transport/test_java_card_mixin.rb
|
158
|
-
- test/transport/test_jcop_remote.rb
|
159
143
|
- tem_ruby.gemspec
|
160
144
|
has_rdoc: true
|
161
145
|
homepage: http://tem.rubyforge.org
|
@@ -186,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
170
|
requirements: []
|
187
171
|
|
188
172
|
rubyforge_project: tem
|
189
|
-
rubygems_version: 1.3.
|
173
|
+
rubygems_version: 1.3.5
|
190
174
|
signing_key:
|
191
175
|
specification_version: 3
|
192
176
|
summary: TEM (Trusted Execution Module) driver, written in and for ruby.
|
@@ -207,6 +191,3 @@ test_files:
|
|
207
191
|
- test/test_auto_conf.rb
|
208
192
|
- test/test_driver.rb
|
209
193
|
- test/test_exceptions.rb
|
210
|
-
- test/transport/test_auto_configurator.rb
|
211
|
-
- test/transport/test_java_card_mixin.rb
|
212
|
-
- test/transport/test_jcop_remote.rb
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# :nodoc: namespace
|
2
|
-
module Tem::Transport
|
3
|
-
|
4
|
-
# Automatic configuration code.
|
5
|
-
module AutoConfigurator
|
6
|
-
# The name of the environment variable that might supply the transport
|
7
|
-
# configuration.
|
8
|
-
ENVIRONMENT_VARIABLE_NAME = 'TEM_PORT'
|
9
|
-
|
10
|
-
# The default configurations to be tried if no configuration is specified.
|
11
|
-
DEFAULT_CONFIGURATIONS = [
|
12
|
-
{ :class => JcopRemoteTransport,
|
13
|
-
:opts => { :host => '127.0.0.1', :port => 8050} },
|
14
|
-
{ :class => PcscTransport, :opts => { :reader_index => 0 }}
|
15
|
-
]
|
16
|
-
|
17
|
-
# Creates a transport based on available configuration information.
|
18
|
-
def self.auto_transport
|
19
|
-
configuration = env_configuration
|
20
|
-
return try_transport(configuration) if configuration
|
21
|
-
|
22
|
-
DEFAULT_CONFIGURATIONS.each do |config|
|
23
|
-
transport = try_transport(config)
|
24
|
-
return transport if transport
|
25
|
-
end
|
26
|
-
return nil
|
27
|
-
end
|
28
|
-
|
29
|
-
# Retrieves transport configuration information from an environment variable.
|
30
|
-
#
|
31
|
-
# :call-seq:
|
32
|
-
# AutoConfigurator.env_configuration -> hash
|
33
|
-
#
|
34
|
-
# The returned configuration has the keys required by
|
35
|
-
# AutoConfigurator#try_transport
|
36
|
-
def self.env_configuration
|
37
|
-
return nil unless conf = ENV[ENVIRONMENT_VARIABLE_NAME]
|
38
|
-
|
39
|
-
case conf[0]
|
40
|
-
when ?:
|
41
|
-
# :8050 -- JCOP emulator at port 8050
|
42
|
-
transport_class = JcopRemoteTransport
|
43
|
-
transport_opts = { :host => '127.0.0.1' }
|
44
|
-
transport_opts[:port] = conf[1..-1].to_i
|
45
|
-
when ?@
|
46
|
-
# @127.0.0.1:8050 -- JCOP emulator at host 127.0.0.1 port 8050
|
47
|
-
transport_class = JcopRemoteTransport
|
48
|
-
port_index = conf.rindex(?:) || conf.length
|
49
|
-
transport_opts = { :host => conf[1...port_index] }
|
50
|
-
transport_opts[:port] = conf[(port_index + 1)..-1].to_i
|
51
|
-
when ?#
|
52
|
-
# #2 -- 2nd PC/SC reader in the system
|
53
|
-
transport_class = PcscTransport
|
54
|
-
transport_opts = { :reader_index => conf[1..-1].to_i - 1 }
|
55
|
-
else
|
56
|
-
# Reader Name -- the PC/SC reader with the given name
|
57
|
-
transport_class = PcscTransport
|
58
|
-
transport_opts = { :reader_name => conf }
|
59
|
-
end
|
60
|
-
|
61
|
-
transport_opts[:port] = 8050 if transport_opts[:port] == 0
|
62
|
-
if transport_opts[:reader_index] and transport_opts[:reader_index] < 0
|
63
|
-
transport_opts[:reader_index] = 0
|
64
|
-
end
|
65
|
-
{ :class => transport_class, :opts => transport_opts }
|
66
|
-
end
|
67
|
-
|
68
|
-
# Attempts to create a new TEM transport with the given configuration.
|
69
|
-
# :call-seq:
|
70
|
-
# AutoConfigurator.try_transport(configuration) -> Transport or nil
|
71
|
-
#
|
72
|
-
# The configuration should have the following keys:
|
73
|
-
# class:: the Ruby class implementing the transport
|
74
|
-
# opts:: the options to be passed to the implementation's constructor
|
75
|
-
def self.try_transport(configuration)
|
76
|
-
raise 'No transport class specified' unless configuration[:class]
|
77
|
-
begin
|
78
|
-
transport = configuration[:class].new(configuration[:opts] || {})
|
79
|
-
transport.connect
|
80
|
-
return transport
|
81
|
-
rescue Exception
|
82
|
-
return nil
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end # module AutoConfigurator
|
86
|
-
|
87
|
-
end # module Tem::Transport
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# :nodoc: namespace
|
2
|
-
module Tem::Transport
|
3
|
-
|
4
|
-
# Module intended to be mixed into transport implementations to mediate between
|
5
|
-
# a high level format for Javacard-specific APDUs and the wire-level APDU
|
6
|
-
# request and response formats.
|
7
|
-
#
|
8
|
-
# The mix-in calls exchange_apdu in the transport implementation. It supplies
|
9
|
-
# the APDU data as an array of integers between 0 and 255, and expects a
|
10
|
-
# response in the same format.
|
11
|
-
module JavaCardMixin
|
12
|
-
# Selects a Javacard applet.
|
13
|
-
def select_applet(applet_id)
|
14
|
-
applet_apdu! :ins => 0xA4, :p1 => 0x04, :p2 => 0x00, :data => applet_id
|
15
|
-
end
|
16
|
-
|
17
|
-
# APDU exchange with the JavaCard applet, raising an exception if the return
|
18
|
-
# code is not success (0x9000).
|
19
|
-
#
|
20
|
-
# :call_seq:
|
21
|
-
# transport.applet_apdu!(apdu_data) -> array
|
22
|
-
#
|
23
|
-
# The apdu_data should be in the format expected by
|
24
|
-
# JavaCardMixin#serialize_apdu. Returns the response data, if the response
|
25
|
-
# status indicates success (0x9000). Otherwise, raises an exeception.
|
26
|
-
def applet_apdu!(apdu_data)
|
27
|
-
response = self.applet_apdu apdu_data
|
28
|
-
return response[:data] if response[:status] == 0x9000
|
29
|
-
raise "JavaCard response has error status 0x#{'%04x' % response[:status]}"
|
30
|
-
end
|
31
|
-
|
32
|
-
# Performs an APDU exchange with the JavaCard applet.
|
33
|
-
#
|
34
|
-
# :call-seq:
|
35
|
-
# transport.applet_apdu(apdu_data) -> hash
|
36
|
-
#
|
37
|
-
# The apdu_data should be in the format expected by
|
38
|
-
# JavaCardMixin#serialize_apdu. The response will be as specified in
|
39
|
-
# JavaCardMixin#deserialize_response.
|
40
|
-
def applet_apdu(apdu_data)
|
41
|
-
apdu = Tem::Transport::JavaCardMixin.serialize_apdu apdu_data
|
42
|
-
response = self.exchange_apdu apdu
|
43
|
-
JavaCardMixin.deserialize_response response
|
44
|
-
end
|
45
|
-
|
46
|
-
# Serializes an APDU for wire transmission.
|
47
|
-
#
|
48
|
-
# :call-seq:
|
49
|
-
# transport.wire_apdu(apdu_data) -> array
|
50
|
-
#
|
51
|
-
# The following keys are recognized in the APDU hash:
|
52
|
-
# cla:: the CLA byte in the APDU (optional, defaults to 0)
|
53
|
-
# ins:: the INS byte in the APDU -- the first byte seen by a JavaCard applet
|
54
|
-
# p::
|
55
|
-
# p1, p2:: the P1 and P2 bytes in the APDU (optional, both default to 0)
|
56
|
-
# data:: the extra data in the APDU (optional, defaults to nothing)
|
57
|
-
def self.serialize_apdu(apdu_data)
|
58
|
-
raise 'Unspecified INS in apdu_data' unless apdu_data[:ins]
|
59
|
-
apdu = [ apdu_data[:cla] || 0, apdu_data[:ins] ]
|
60
|
-
if apdu_data[:p12]
|
61
|
-
unless apdu_data[:p12].length == 2
|
62
|
-
raise "Malformed P1,P2 - #{apdu_data[:p12]}"
|
63
|
-
end
|
64
|
-
apdu += apdu_data[:p12]
|
65
|
-
else
|
66
|
-
apdu << (apdu_data[:p1] || 0)
|
67
|
-
apdu << (apdu_data[:p2] || 0)
|
68
|
-
end
|
69
|
-
if apdu_data[:data]
|
70
|
-
apdu << apdu_data[:data].length
|
71
|
-
apdu += apdu_data[:data]
|
72
|
-
else
|
73
|
-
apdu << 0
|
74
|
-
end
|
75
|
-
apdu
|
76
|
-
end
|
77
|
-
|
78
|
-
# De-serializes a JavaCard response APDU.
|
79
|
-
#
|
80
|
-
# :call-seq:
|
81
|
-
# transport.deserialize_response(response) -> hash
|
82
|
-
#
|
83
|
-
# The response contains the following keys:
|
84
|
-
# status:: the 2-byte status code (e.g. 0x9000 is OK)
|
85
|
-
# data:: the additional data in the response
|
86
|
-
def self.deserialize_response(response)
|
87
|
-
{ :status => response[-2] * 256 + response[-1], :data => response[0...-2] }
|
88
|
-
end
|
89
|
-
|
90
|
-
# Installs a JavaCard applet on the JavaCard.
|
91
|
-
#
|
92
|
-
# This would be really, really nice to have. Sadly, it's a far away TBD right
|
93
|
-
# now.
|
94
|
-
def install_applet(cap_contents)
|
95
|
-
raise "Not implemeted; it'd be nice though, right?"
|
96
|
-
end
|
97
|
-
end # module Tem
|
98
|
-
|
99
|
-
end # module Tem::Transport
|