tem_ruby 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ v0.9.2. Changed exec-SECpack calling sequence for fw 1.9.1(fire, the released version).
2
+
3
+ v0.9.1. Cleaner names for the pstore data types and opcode arguments. "Bound" instead of "sealed" SECpack.
4
+
1
5
  v0.9.0. Updated tests and re-implemented buffer stat-ing for fw 1.9(fire).
2
6
 
3
7
  v0.8.0. Implemented buffer flushing (fw 1.8) and more timing tests.
data/README CHANGED
@@ -1,5 +1,7 @@
1
- This is the ruby driver for the Trusted Execution Module prototype produced at MIT. The best feature of the
2
- ruby driver is the very powerful DSL (domain-specific language) that TEM procedures are compiled from.
1
+ This is the ruby driver for the Trusted Execution Module prototype produced at
2
+ MIT. The best features of the ruby driver are the very powerful DSL
3
+ (domain-specific language) that TEM SECpacks are compiled from, and the
4
+ usage of debugging line info to translate exception IPs to stack traces.
3
5
 
4
6
  Running coverage tests:
5
7
  gem install rcov
data/lib/tem/abi.rb CHANGED
@@ -6,7 +6,7 @@ module Tem::Abi
6
6
  klass.tem_value_type :ubyte, 1, :signed => false, :endian => :big
7
7
  klass.tem_value_type :short, 2, :signed => true, :endian => :big
8
8
  klass.tem_value_type :ushort, 2, :signed => false, :endian => :big
9
- klass.tem_value_type :ps_key, 20, :signed => false, :endian => :big
9
+ klass.tem_value_type :ps_addr, 20, :signed => false, :endian => :big
10
10
  klass.tem_value_type :ps_value, 20, :signed => false, :endian => :big
11
11
  end
12
12
 
data/lib/tem/ecert.rb CHANGED
@@ -23,46 +23,46 @@ module Tem::ECert
23
23
 
24
24
  # emits a TEM
25
25
  def emit
26
- emit_proc = assemble do |p|
26
+ emit_sec = assemble do |s|
27
27
  # generate EK, compare with (0, 1)
28
- p.genkp :type => 0
29
- p.ldbc 1
30
- p.sub
31
- p.jne :to => :not_ok
32
- p.ldbc 0
33
- p.sub
34
- p.jne :to => :not_ok
28
+ s.genkp :type => 0
29
+ s.ldbc 1
30
+ s.sub
31
+ s.jne :to => :not_ok
32
+ s.ldbc 0
33
+ s.sub
34
+ s.jne :to => :not_ok
35
35
 
36
36
  # generate and output random authorization for PrivEK
37
- p.ldbc 20
38
- p.dupn :n => 1
39
- p.outnew
40
- p.ldwc :privek_auth
41
- p.dupn :n => 2
42
- p.rnd
43
- p.outvb
37
+ s.ldbc 20
38
+ s.dupn :n => 1
39
+ s.outnew
40
+ s.ldwc :privek_auth
41
+ s.dupn :n => 2
42
+ s.rnd
43
+ s.outvb
44
44
  # set authorizations for PrivEK and PubkEK
45
- p.ldbc 0
46
- p.authk :auth => :privek_auth
47
- p.ldbc 1 # PubEK always has its initial authorization be all zeroes
48
- p.authk :auth => :pubek_auth
49
- p.halt
45
+ s.ldbc 0
46
+ s.authk :auth => :privek_auth
47
+ s.ldbc 1 # PubEK always has its initial authorization be all zeroes
48
+ s.authk :auth => :pubek_auth
49
+ s.halt
50
50
 
51
51
  # emitting didn't go well, return nothing and leave
52
- p.label :not_ok
53
- p.ldbc 0
54
- p.outnew
55
- p.halt
52
+ s.label :not_ok
53
+ s.ldbc 0
54
+ s.outnew
55
+ s.halt
56
56
 
57
- p.label :privek_auth
58
- p.filler :ubyte, 20
59
- p.label :pubek_auth
60
- p.filler :ubyte, 20
61
- p.stack
62
- p.extra 8
57
+ s.label :privek_auth
58
+ s.filler :ubyte, 20
59
+ s.label :pubek_auth
60
+ s.filler :ubyte, 20
61
+ s.stack
62
+ s.extra 8
63
63
  end
64
64
 
65
- r = execute emit_proc
65
+ r = execute emit_sec
66
66
  if r.length == 0
67
67
  return nil
68
68
  else
@@ -47,8 +47,8 @@ class Tem::SecAssembler
47
47
  end
48
48
  end
49
49
 
50
- def assemble(&proc_block)
51
- # call the block to build the proc
50
+ def assemble(&sec_block)
51
+ # call the block to build the SECpack
52
52
  yield self
53
53
 
54
54
  # link in label addresses
@@ -29,19 +29,19 @@ class Tem::SecAssembler
29
29
 
30
30
 
31
31
  # 2 IM -> 1 ST
32
- opcode(:psupfxb, 0x48, {:name => :key, :type => :ushort}, {:name => :from, :type => :ushort})
32
+ opcode(:psupfxb, 0x48, {:name => :addr, :type => :ushort}, {:name => :from, :type => :ushort})
33
33
  # 2 ST -> 1 ST
34
34
  opcode :psupvb, 0x49
35
35
  # 2 IM -> 1 ST
36
- opcode(:pswrfxb, 0x4A, {:name => :key, :type => :ushort}, {:name => :from, :type => :ushort})
36
+ opcode(:pswrfxb, 0x4A, {:name => :addr, :type => :ushort}, {:name => :from, :type => :ushort})
37
37
  # 2 ST -> 1 ST
38
38
  opcode :pswrvb, 0x4B
39
39
  # 2 IM -> 1 ST
40
- opcode(:psrdfxb, 0x4C, {:name => :key, :type => :ushort}, {:name => :to, :type => :ushort})
40
+ opcode(:psrdfxb, 0x4C, {:name => :addr, :type => :ushort}, {:name => :to, :type => :ushort})
41
41
  # 2 ST -> 1 ST
42
42
  opcode :psrdvb, 0x4D
43
43
  # 2 IM -> 1 ST
44
- opcode :pshkfxb, 0x4E, {:name => :key, :type => :ushort}
44
+ opcode :pshkfxb, 0x4E, {:name => :addr, :type => :ushort}
45
45
  # 2 ST -> 1 ST
46
46
  opcode :pshkvb, 0x4F
47
47
 
@@ -2,8 +2,8 @@ require 'yaml'
2
2
 
3
3
  module Tem::SeClosures
4
4
  module MixedMethods
5
- def assemble(&proc_block)
6
- return Tem::SecAssembler.new(self).assemble(&proc_block)
5
+ def assemble(&sec_block)
6
+ return Tem::SecAssembler.new(self).assemble(&sec_block)
7
7
  end
8
8
  end
9
9
 
@@ -36,11 +36,10 @@ module Tem::SeClosures
36
36
  tem_error(response) if failure_code(response)
37
37
  end
38
38
 
39
- def execute(compiled_proc, key_id = 0)
39
+ def execute(secpack, key_id = 0)
40
40
  # load SECpack
41
- buffer_id = post_buffer(compiled_proc.tem_formatted_body)
41
+ buffer_id = post_buffer(secpack.tem_formatted_body)
42
42
  response = issue_apdu [0x00, 0x50, to_tem_byte(buffer_id), to_tem_byte(key_id), 0x00].flatten
43
- release_buffer(buffer_id)
44
43
  tem_error(response) if failure_code(response)
45
44
  tem_secpack_error(response) if read_tem_byte(response, 0) != 1
46
45
 
@@ -58,7 +57,7 @@ module Tem::SeClosures
58
57
  b_stat = stat_buffers() rescue nil
59
58
  k_stat = stat_keys() rescue nil
60
59
  trace = sec_trace()
61
- backtrace = (trace && trace[:ip]) ? compiled_proc.stack_for_ip(trace[:ip]) : Kernel.caller
60
+ backtrace = (trace && trace[:ip]) ? secpack.stack_for_ip(trace[:ip]) : Kernel.caller
62
61
  sec_exception = Tem::SecExecError.new backtrace, trace, b_stat, k_stat
63
62
  break
64
63
  when 4 # persistent store fault
data/lib/tem/secpack.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'yaml'
2
2
 
3
3
  class Tem::SecPack
4
- @@serialized_members = [:body, :labels, :ep, :sp, :extra_bytes, :signed_bytes, :encrypted_bytes, :sealed, :lines]
4
+ @@serialized_members = [:body, :labels, :ep, :sp, :extra_bytes, :signed_bytes, :encrypted_bytes, :bound, :lines]
5
5
 
6
6
  def self.new_from_array(array)
7
7
  arg_hash = { :tem_class => Tem::Session }
@@ -22,13 +22,13 @@ class Tem::SecPack
22
22
  self.to_array.to_yaml.to_s
23
23
  end
24
24
 
25
- attr_reader :body, :sealed
25
+ attr_reader :body, :bound
26
26
  attr_reader :lines
27
27
 
28
28
  def initialize(args)
29
29
  @tem_klass = args[:tem_class]
30
30
  @@serialized_members.map { |m| self.instance_variable_set('@' + m.to_s, args[m]) }
31
- @sealed ||= false
31
+ @bound ||= false
32
32
  end
33
33
 
34
34
  def label_address(label_name)
@@ -42,15 +42,15 @@ class Tem::SecPack
42
42
  return hh
43
43
  end
44
44
 
45
- def seal(public_key, encrypt_from = 0, plaintext_from = 0)
45
+ def bind(public_key, encrypt_from = 0, plaintext_from = 0)
46
46
  encrypt_from = @labels[encrypt_from.to_sym] unless encrypt_from.instance_of? Numeric
47
47
  plaintext_from = @labels[plaintext_from.to_sym] unless plaintext_from.instance_of? Numeric
48
48
 
49
49
  @signed_bytes = encrypt_from
50
50
  @encrypted_bytes = plaintext_from - encrypt_from
51
51
 
52
- proc_sig = @tem_klass.hash_for_tem [tem_header, @body[0...plaintext_from]].flatten
53
- crypt = public_key.encrypt [@body[encrypt_from...plaintext_from], proc_sig].flatten
52
+ secpack_sig = @tem_klass.hash_for_tem [tem_header, @body[0...plaintext_from]].flatten
53
+ crypt = public_key.encrypt [@body[encrypt_from...plaintext_from], secpack_sig].flatten
54
54
  @body = [@body[0...encrypt_from], crypt, @body[plaintext_from..-1]].flatten
55
55
 
56
56
  label_delta = crypt.length - @encrypted_bytes
@@ -64,7 +64,7 @@ class Tem::SecPack
64
64
  end
65
65
  }.flatten)]
66
66
 
67
- @sealed = true
67
+ @bound = true
68
68
  end
69
69
 
70
70
  def tem_formatted_body()
data/tem_ruby.gemspec CHANGED
@@ -1,16 +1,16 @@
1
1
 
2
- # Gem::Specification for Tem_ruby-0.9.0
2
+ # Gem::Specification for Tem_ruby-0.9.2
3
3
  # Originally generated by Echoe
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{tem_ruby}
7
- s.version = "0.9.0"
7
+ s.version = "0.9.2"
8
8
 
9
9
  s.specification_version = 2 if s.respond_to? :specification_version=
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Victor Costan"]
13
- s.date = %q{2008-06-11}
13
+ s.date = %q{2008-06-13}
14
14
  s.description = %q{TEM (Trusted Execution Module) driver, written in and for ruby.}
15
15
  s.email = %q{victor@costan.us}
16
16
  s.executables = ["tem_stat", "tem_ca", "tem_irb", "tem_bench"]
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.summary = %q{TEM (Trusted Execution Module) driver, written in and for ruby.}
25
25
  s.test_files = ["test/test_driver.rb", "test/test_tem.rb", "test/test_exceptions.rb"]
26
26
 
27
- s.add_dependency(%q<smartcard>, [">= 0.2.2"])
27
+ s.add_dependency(%q<smartcard>, [">= 0.3.0"])
28
28
  end
29
29
 
30
30
 
@@ -36,14 +36,16 @@ end
36
36
  #
37
37
  # Echoe.new('tem_ruby') do |p|
38
38
  # p.project = 'tem' # rubyforge project
39
+ # p.docs_host = "costan@rubyforge.org:/var/www/gforge-projects/tem/rdoc/"
39
40
  #
40
41
  # p.author = 'Victor Costan'
41
42
  # p.email = 'victor@costan.us'
42
43
  # p.summary = 'TEM (Trusted Execution Module) driver, written in and for ruby.'
43
44
  # p.url = 'http://tem.rubyforge.org'
44
- # p.dependencies = ['smartcard >=0.2.2']
45
+ # p.dependencies = ['smartcard >=0.3.0']
45
46
  #
46
- # p.need_tar_gz = false
47
+ # p.need_tar_gz = true
48
+ # p.need_zip = true
47
49
  # p.rdoc_pattern = /^(lib|bin|tasks|ext)|^BUILD|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
48
50
  # end
49
51
  #
data/test/test_tem.rb CHANGED
@@ -21,7 +21,7 @@ class TemTest < Test::Unit::TestCase
21
21
  end
22
22
 
23
23
  def test_alu
24
- proc = @tem.assemble { |s|
24
+ sec = @tem.assemble { |s|
25
25
  s.ldbc 10
26
26
  s.outnew
27
27
  s.ldwc 0x1234
@@ -45,13 +45,13 @@ class TemTest < Test::Unit::TestCase
45
45
  s.halt
46
46
  s.extra 10
47
47
  }
48
- result = @tem.execute proc
48
+ result = @tem.execute sec
49
49
  assert_equal [0x68, 0xAC, 0xBB, 0xBC, 0x8C, 0x72, 0x00, 0x55, 0x00, 0x9A],
50
50
  result, 'the ALU isn\'t working well'
51
51
  end
52
52
 
53
53
  def test_memory
54
- proc = @tem.assemble { |s|
54
+ sec = @tem.assemble { |s|
55
55
  s.label :clobber
56
56
  s.ldbc 32
57
57
  s.label :clobber2
@@ -88,13 +88,13 @@ class TemTest < Test::Unit::TestCase
88
88
  s.stack
89
89
  s.extra 10
90
90
  }
91
- result = @tem.execute proc
91
+ result = @tem.execute sec
92
92
  assert_equal [0x00, 0x55, 0x55, 0xAA, 0xA5, 0xAA, 0xFF, 0x99, 0x98, 0x66, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66],
93
93
  result, 'the memory unit isn\'t working well'
94
94
  end
95
95
 
96
96
  def test_output
97
- proc = @tem.assemble { |s|
97
+ sec = @tem.assemble { |s|
98
98
  s.ldbc 32
99
99
  s.outnew
100
100
  s.outfxb :size => 3, :from => :area1
@@ -117,7 +117,7 @@ class TemTest < Test::Unit::TestCase
117
117
  s.stack
118
118
  s.extra 10
119
119
  }
120
- result = @tem.execute proc
120
+ result = @tem.execute sec
121
121
  assert_equal [0xFE, 0xCD, 0x9A, 0xAB, 0x95, 0xCE, 0xFD, 0x81, 0xEC, 0xDE, 0xAD, 0xCF, 0x55, 0x99, 0xAA],
122
122
  result, 'the output unit isn\'t working well'
123
123
  end
@@ -232,7 +232,7 @@ class TemTest < Test::Unit::TestCase
232
232
  garbage2 = (0...11).map { |x| (69 * x * x + 62 * x + 10) % 256 }
233
233
  hash_size = 20
234
234
 
235
- proc = @tem.assemble { |s|
235
+ sec = @tem.assemble { |s|
236
236
  s.ldwc hash_size * 3
237
237
  s.outnew
238
238
  s.mdfxb :size => garbage1.length, :from => :garbage1, :to => :hash_area
@@ -254,14 +254,14 @@ class TemTest < Test::Unit::TestCase
254
254
  s.extra 10
255
255
  }
256
256
 
257
- result = @tem.execute proc
257
+ result = @tem.execute sec
258
258
  assert_equal [garbage1, garbage2, garbage2].map { |d| @tem.hash_for_tem d}.flatten,
259
259
  result, 'cryptographic hashing isn\'t working well'
260
260
  end
261
261
 
262
262
  def test_crypto_pstore
263
- key1 = (0...(@tem.tem_ps_key_length)).map { |x| (61 * x * x + 62 * x + 10) % 256 }
264
- key2 = key1.dup; key2[key2.length - 1] += 1
263
+ addr1 = (0...(@tem.tem_ps_addr_length)).map { |x| (61 * x * x + 62 * x + 10) % 256 }
264
+ addr2 = addr1.dup; addr2[addr2.length - 1] += 1
265
265
  random_value = (0...(@tem.tem_ps_value_length)).map { |x| (69 * x * x + 62 * x + 10) % 256 }
266
266
 
267
267
  sec = @tem.assemble { |s|
@@ -269,24 +269,24 @@ class TemTest < Test::Unit::TestCase
269
269
  s.outnew
270
270
 
271
271
  # check that the location is blank
272
- s.ldwc :pstore_key
272
+ s.ldwc :pstore_addr
273
273
  s.pshkvb
274
274
  s.outw
275
275
 
276
276
  # write to create the location
277
- s.pswrfxb :key => :pstore_key, :from => :s_value
277
+ s.pswrfxb :addr => :pstore_addr, :from => :s_value
278
278
  # check that the location isn't blank anymore
279
- s.pshkfxb :key => :pstore_key
279
+ s.pshkfxb :addr => :pstore_addr
280
280
  s.outw
281
281
  # re-read (should get what was written)
282
- s.ldwc :pstore_key
282
+ s.ldwc :pstore_addr
283
283
  s.ldwc :s_value2
284
284
  s.psrdvb
285
285
  s.ldwc :s_value2
286
286
  s.outvb
287
287
 
288
288
  # drop the location
289
- s.ldwc :pstore_key
289
+ s.ldwc :pstore_addr
290
290
  s.dupn :n => 1
291
291
  s.psrm
292
292
  # check that the location is blank again
@@ -295,8 +295,8 @@ class TemTest < Test::Unit::TestCase
295
295
 
296
296
  s.halt
297
297
 
298
- s.label :pstore_key
299
- s.immed :ubyte, key1
298
+ s.label :pstore_addr
299
+ s.immed :ubyte, addr1
300
300
  s.label :s_value
301
301
  s.immed :ubyte, random_value
302
302
  s.label :s_value2
@@ -444,12 +444,12 @@ class TemTest < Test::Unit::TestCase
444
444
  i_test_crypto_pki_ops(pubk_id, privk_id, pubk, privk, keyd[:authz])
445
445
  end
446
446
 
447
- def test_crypted_secpack(yaml_roundtrip = false)
447
+ def test_bound_secpack(yaml_roundtrip = false)
448
448
  keyd = @tem.tk_gen_key
449
449
  pubk = @tem.tk_read_key keyd[:pubk_id], keyd[:authz]
450
450
 
451
451
  secret = (0...16).map { |i| (99 * i * i + 51 * i + 33) % 256 }
452
- sealed_sec = @tem.assemble { |s|
452
+ bound_sec = @tem.assemble { |s|
453
453
  s.ldbc secret.length
454
454
  s.outnew
455
455
  s.label :mess_place
@@ -462,25 +462,25 @@ class TemTest < Test::Unit::TestCase
462
462
  s.extra 8
463
463
  }
464
464
 
465
- sb = sealed_sec.body
465
+ sb = bound_sec.body
466
466
  secret_found = false
467
467
  0.upto(sb.length - 1) { |i| if secret == sb[i, secret.length] then secret_found = true; break; end }
468
- assert secret_found, 'test_crypted_secpack needs rethinking: the raw sec does not contain the secret'
468
+ assert secret_found, 'test_bound_secpack needs rethinking: the unbound secpack does not contain the secret'
469
469
 
470
- sealed_sec.seal pubk, :secret, :plain
470
+ bound_sec.bind pubk, :secret, :plain
471
471
  if yaml_roundtrip
472
472
  # same test, except the SECpack is serialized/deserialized
473
- yaml_sealed_sec = sealed_sec.to_yaml_str
474
- sealed_sec = Tem::SecPack.new_from_yaml_str(yaml_sealed_sec)
473
+ yaml_bound_sec = bound_sec.to_yaml_str
474
+ bound_sec = Tem::SecPack.new_from_yaml_str(yaml_bound_sec)
475
475
  end
476
- result = @tem.execute sealed_sec, keyd[:privk_id]
476
+ result = @tem.execute bound_sec, keyd[:privk_id]
477
477
  assert_equal secret, result, 'TEM failed to decrypt secpack'
478
478
 
479
- sb = sealed_sec.body
480
- 0.upto(sb.length - 1) { |i| assert_not_equal secret, sb[i, secret.length], 'secret found unencrypted in sealed sec' }
479
+ sb = bound_sec.body
480
+ 0.upto(sb.length - 1) { |i| assert_not_equal secret, sb[i, secret.length], 'secret found unencrypted in bound secpack' }
481
481
 
482
- sealed_sec.body[sealed_sec.label_address(:mess_place)] += 1
483
- assert_raise(RuntimeError, 'secpack validation isn\'t working') { @tem.execute sealed_sec }
482
+ bound_sec.body[bound_sec.label_address(:mess_place)] += 1
483
+ assert_raise(RuntimeError, 'secpack validation isn\'t working') { @tem.execute bound_sec }
484
484
  end
485
485
 
486
486
  def test_yaml_secpack
@@ -516,8 +516,8 @@ class TemTest < Test::Unit::TestCase
516
516
 
517
517
  # re-run the memory test (reasonably large SECpack) to ensure that de-serialized SECpacks are equivalent to the originals
518
518
  test_memory_copy_compare(true)
519
- # re-run the memory test (reasonably large SECpack) to ensure that serialization works on sealed SECpacks
520
- test_crypted_secpack(true)
519
+ # re-run the memory test (reasonably large SECpack) to ensure that serialization works on bound SECpacks
520
+ test_bound_secpack(true)
521
521
  end
522
522
 
523
523
  def test_emit
@@ -11,7 +11,7 @@ class TemTimings
11
11
  s.stack
12
12
  s.extra 2
13
13
  }
14
- secpack.seal @tem.pubek, :secret, :plain
14
+ secpack.bind @tem.pubek, :secret, :plain
15
15
 
16
16
  print "SECpack has #{secpack.body.length} bytes, runs 3 instructions and produces 0 bytes\n"
17
17
  do_timing { @tem.execute secpack }
@@ -135,7 +135,7 @@ class TemTimings
135
135
  s.stack
136
136
  s.extra 24
137
137
  }
138
- secpack.seal @tem.pubek, :done, :stack
138
+ secpack.bind @tem.pubek, :done, :stack
139
139
  print "SECpack has #{secpack.body.length} bytes, runs 1020 instructions and produces 470 bytes\n"
140
140
  do_timing { @tem.execute secpack }
141
141
  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.9.0
4
+ version: 0.9.2
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: 2008-06-11 00:00:00 -04:00
12
+ date: 2008-06-13 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.2.2
22
+ version: 0.3.0
23
23
  version:
24
24
  description: TEM (Trusted Execution Module) driver, written in and for ruby.
25
25
  email: victor@costan.us