Module: Tem::Admin::Migrate
- Included in:
- Session
- Defined in:
- lib/tem/admin/migrate.rb
Overview
Logic for migrating SECpacks.
Class Method Summary collapse
-
.blank_ecert_verify_seclosure ⇒ Object
Blank version of the SEClosure that verifies the destination TEM’s ECert.
-
.blank_migrate_seclosure ⇒ Object
Blank version of the SEClosure that verifies the destination TEM’s ECert.
-
.ecert_verify_bytes_tag_key ⇒ Object
The key storing the encrypted bytes of the ecert_verify SECpack in the TEM’s tag.
-
.ecert_verify_seclosure(key_ps_addr, authz) ⇒ Object
SEClosure that verifies the destination TEM’s ECert.
-
.migrate_bytes_tag_key ⇒ Object
The key storing the encrypted bytes of the migrate SECpack in the TEM’s tag.
-
.migrate_seclosure(key_ps_addr, authz) ⇒ Object
SEClosure that migrates a SECpack.
-
.seclosures_from_tag_data(tem) ⇒ Object
Recovers the migration-related SECpacks from the TEM’s tag data.
-
.tag_data(pubek, privek_authz) ⇒ Object
Data to be included in a TEM’s tag to support migration.
Instance Method Summary collapse
-
#migrate(secpack, ecert) ⇒ Object
Migrates a SECpack to another TEM.
Class Method Details
.blank_ecert_verify_seclosure ⇒ Object
Blank version of the SEClosure that verifies the destination TEM’s ECert.
The returned SEClosure is not suitable for execution. Its encrypted bytes should be replaced with the bytes from a SECpack generated with live data.
65 66 67 68 |
# File 'lib/tem/admin/migrate.rb', line 65 def self.blank_ecert_verify_seclosure ecert_verify_seclosure [0] * Tem::Abi.tem_ps_addr_length, [0] * Tem::Abi.tem_hash_length end |
.blank_migrate_seclosure ⇒ Object
Blank version of the SEClosure that verifies the destination TEM’s ECert.
The returned SEClosure is not suitable for execution. Its encrypted bytes should be replaced with the bytes from a SECpack generated with live data.
142 143 144 145 |
# File 'lib/tem/admin/migrate.rb', line 142 def self.blank_migrate_seclosure migrate_seclosure [0] * Tem::Abi.tem_ps_addr_length, [0] * Tem::Abi.tem_hash_length end |
.ecert_verify_bytes_tag_key ⇒ Object
The key storing the encrypted bytes of the ecert_verify SECpack in the TEM’s tag.
149 150 151 |
# File 'lib/tem/admin/migrate.rb', line 149 def self.ecert_verify_bytes_tag_key 0x11 end |
.ecert_verify_seclosure(key_ps_addr, authz) ⇒ Object
SEClosure that verifies the destination TEM’s ECert.
Args:
key_ps_addr:: the PStore address used to store the TEM key's ID
authz:: the authentication secret for the TEM's PrivEK
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tem/admin/migrate.rb', line 20 def self.ecert_verify_seclosure(key_ps_addr, authz) Tem::Assembler.assemble { |s| # TODO: some actual verification, jump to :failure if it doesn't work s.ldwc :const => :pubek s.rdk s.authk :auth => :authz s.stw :to => :key_id s.pswrfxb :addr => :pstore_addr, :from => :key_id s.label :success s.ldbc :const => 1 s.dupn :n => 1 s.outnew s.outb s.halt s.label :failure s.ldbc :const => 1 s.outnew s.ldbc :const => 0 s.outb s.halt s.label :key_id s.zeros :tem_ps_value # Will hold the ID of the loaded PubEK. s.label :secret s.label :authz # The authentication key for the PrivEK. s.data :tem_ubyte, authz s.label :pstore_addr s.data :tem_ps_addr, key_ps_addr s.label :plain # ARG: the target TEM's public endorsement key. s.label :pubek s.zeros :tem_ubyte, 300 # ARG: the target TEM's endorsement certificate. s.label :ecert s.stack 10 } end |
.migrate_bytes_tag_key ⇒ Object
The key storing the encrypted bytes of the migrate SECpack in the TEM’s tag.
154 155 156 |
# File 'lib/tem/admin/migrate.rb', line 154 def self.migrate_bytes_tag_key 0x12 end |
.migrate_seclosure(key_ps_addr, authz) ⇒ Object
SEClosure that migrates a SECpack.
Args:
key_ps_addr:: the PStore address used to store the TEM key's ID
authz:: the authentication secret for the TEM's PrivEK
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/tem/admin/migrate.rb', line 75 def self.migrate_seclosure(key_ps_addr, authz) Tem::Assembler.assemble { |s| s.ldbc :const => 0 # Authorize PrivEK. s.authk :auth => :authz s.dupn :n => 1 # Compute the size of the encrypted blob. s.ldw :from => :secpack_secret_size s.ldkel # Decrypt secpack. s.ldwc :const => :secpack_encrypted s.ldwc :const => :secpack_encrypted s.kdvb s.ldw :from => :secpack_secret_size # Fail for wrong blob size. s.sub s.jnz :failure # Authorize target PubEK. s.psrdfxb :addr => :pstore_addr, :to => :key_id s.ldw :from => :key_id s.authk :auth => :authz s.dupn :n => 1 # Prepare output buffer. s.ldw :from => :secpack_secret_size s.ldkel s.outnew s.ldw :from => :secpack_secret_size # Re-encrypt the blob. s.ldwc :const => :secpack_encrypted s.ldwc :const => -1 s.kevb s.ldw :from => :key_id # Clean up. s.relk s.ldbc :const => -1 s.stw :to => :key_id s.pswrfxb :addr => :pstore_addr, :from => :key_id s.halt s.label :failure # Communicate some failure. s.ldbc :const => 0 s.outnew s.halt s.label :key_id s.zeros :tem_ps_value # Will hold the ID of the loaded PubEK. s.label :secret s.label :authz # The authentication key for the PrivEK. s.data :tem_ubyte, authz s.label :pstore_addr s.data :tem_ps_addr, key_ps_addr s.label :plain s.stack 20 # ARG: the 'encrypted size' field in the SECpack header. s.label :secpack_secret_size s.zeros :tem_short, 1 # ARG: the encrypted blob in the SECpack. s.label :secpack_encrypted s.zeros :tem_ubyte, 1 s.label :secpack_encrypted_end } end |
.seclosures_from_tag_data(tem) ⇒ Object
Recovers the migration-related SECpacks from the TEM’s tag data.
178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/tem/admin/migrate.rb', line 178 def self.seclosures_from_tag_data(tem) tag_data = tem.tag ecert_verify = blank_ecert_verify_seclosure ecert_verify.fake_bind ecert_verify.encrypted_data = tag_data[ecert_verify_bytes_tag_key] migrate = blank_migrate_seclosure migrate.fake_bind migrate.encrypted_data = tag_data[migrate_bytes_tag_key] { :ecert_verify => ecert_verify, :migrate => migrate } end |
.tag_data(pubek, privek_authz) ⇒ Object
Data to be included in a TEM’s tag to support migration.
Returns a hash of tag key-values to be included in the TEM’s tag during emission.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/tem/admin/migrate.rb', line 162 def self.tag_data(pubek, privek_authz) ps_addr = OpenSSL::Random.random_bytes(Tem::Abi.tem_ps_addr_length). unpack('C*') ev_sec = ecert_verify_seclosure ps_addr, privek_authz ev_sec.bind pubek m_sec = migrate_seclosure ps_addr, privek_authz m_sec.bind pubek { ecert_verify_bytes_tag_key => ev_sec.encrypted_data, migrate_bytes_tag_key => m_sec.encrypted_data } end |
Instance Method Details
#migrate(secpack, ecert) ⇒ Object
Migrates a SECpack to another TEM.
Args:
secpack:: the SECpack to be migrated
ecert:: the Endorsement Certificate of the destination TEM
Returns the migrated SECpack, or nil if the Endorsement Certificate was rejected.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/tem/admin/migrate.rb', line 200 def migrate(secpack, ecert) migrated = secpack.copy secpacks = Tem::Admin::Migrate.seclosures_from_tag_data self verify = secpacks[:ecert_verify] verify.set_bytes :pubek, Tem::Key.new_from_ssl_key(ecert.public_key).to_tem_key return nil if execute(verify) != [1] migrate = secpacks[:migrate] migrate.set_value :secpack_secret_size, :tem_short, secpack.secret_bytes + Tem::Abi.tem_hash_length migrate.set_bytes :secpack_encrypted, migrated.encrypted_data return nil unless new_encrypted_data = execute(migrate) migrated.encrypted_data = new_encrypted_data migrated end |