tem_multi_updater 0.1
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.
- data/CHANGELOG +1 -0
- data/LICENSE +21 -0
- data/Manifest +8 -0
- data/README +5 -0
- data/Rakefile +31 -0
- data/bin/tem_multi_update_fw +22 -0
- data/lib/tem_multi_updater/updater.rb +121 -0
- data/lib/tem_multi_updater.rb +18 -0
- data/tem_multi_updater.gemspec +41 -0
- metadata +102 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.1. Initial release.
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Massachusetts Institute of Technology
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/Manifest
ADDED
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Rakefile for the tem_multi_updater gem.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'echoe'
|
9
|
+
require 'echoe'
|
10
|
+
|
11
|
+
Echoe.new('tem_multi_updater') do |p|
|
12
|
+
p.project = 'tem' # rubyforge project
|
13
|
+
p.docs_host = "costan@rubyforge.org:/var/www/gforge-projects/tem/rdoc/"
|
14
|
+
|
15
|
+
p.author = 'Victor Costan'
|
16
|
+
p.email = 'victor@costan.us'
|
17
|
+
p.summary = 'Updates the firmware on all TEMs connected to a tem_multi_proxy.'
|
18
|
+
p.url = 'http://tem.rubyforge.org'
|
19
|
+
p.dependencies = ['smartcard >=0.4.7',
|
20
|
+
'tem_multi_proxy >=0.2.5',
|
21
|
+
'tem_ruby >=0.12.0']
|
22
|
+
|
23
|
+
p.need_tar_gz = !Gem.win_platform?
|
24
|
+
p.need_zip = !Gem.win_platform?
|
25
|
+
p.rdoc_pattern = /^(lib|bin|tasks|ext)|^BUILD|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
|
26
|
+
end
|
27
|
+
|
28
|
+
if $0 == __FILE__
|
29
|
+
Rake.application = Rake::Application.new
|
30
|
+
Rake.application.run
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Launcher for the multi-updater code.
|
4
|
+
#
|
5
|
+
# Author:: Victor Costan
|
6
|
+
# Copyright:: Copyright (C) 2009 Massachusetts Institute of Technology
|
7
|
+
# License:: MIT
|
8
|
+
#
|
9
|
+
# Usage: tem_multi_update_fw [host[:port]]
|
10
|
+
# The host:port should point to the RPC port of the tem_multi_proxy server.
|
11
|
+
# The default host is localhost, and the default port is 9000.
|
12
|
+
|
13
|
+
require 'logger'
|
14
|
+
require 'rubygems'
|
15
|
+
require 'tem_multi_proxy'
|
16
|
+
require 'tem_multi_updater'
|
17
|
+
|
18
|
+
server_addr = ARGV[0] || 'localhost'
|
19
|
+
logger = Logger.new STDERR
|
20
|
+
logger.level = Logger::INFO
|
21
|
+
updater = Tem::MultiUpdater::Updater.new logger, server_addr
|
22
|
+
updater.run
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# Updates the TEM firmware in all the smartcards on tem_multi_proxy server.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require 'thread'
|
8
|
+
|
9
|
+
# :nodoc: namespace
|
10
|
+
module Tem::MultiUpdater
|
11
|
+
|
12
|
+
|
13
|
+
# Updates the TEM firmware in all the smartcards on tem_multi_proxy server.
|
14
|
+
class Updater
|
15
|
+
# Creates a multi-proxy firmware updater.
|
16
|
+
#
|
17
|
+
# Args:
|
18
|
+
# logger:: receives update progress notifications
|
19
|
+
# multiproxy_server_addr:: the address (host or host:port) of the
|
20
|
+
# tem_multi_proxy RPC port
|
21
|
+
def initialize(logger, multiproxy_server_addr)
|
22
|
+
@logger = logger
|
23
|
+
@server_addr = multiproxy_server_addr
|
24
|
+
@pending = nil
|
25
|
+
@pending_mx, @pending_cv = Mutex.new, ConditionVariable.new
|
26
|
+
end
|
27
|
+
|
28
|
+
# Runs the multi-proxy update.
|
29
|
+
def run
|
30
|
+
return unless @pending.nil?
|
31
|
+
|
32
|
+
@logger.info "Querying #{@server_addr}"
|
33
|
+
@transport_configs = Tem::MultiProxy::Client.query_tems @server_addr
|
34
|
+
|
35
|
+
spawn_threads
|
36
|
+
wait_for_threads
|
37
|
+
end
|
38
|
+
|
39
|
+
# Spawns one updating thread for each smart-card transport configuration.
|
40
|
+
def spawn_threads
|
41
|
+
@pending = @transport_configs.length
|
42
|
+
@transport_configs.each do |transport_config|
|
43
|
+
Thread.new(transport_config) do |config|
|
44
|
+
update_thread config
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Waits for all the updating threads to complete.
|
50
|
+
def wait_for_threads
|
51
|
+
@pending_mx.synchronize do
|
52
|
+
loop do
|
53
|
+
break if @pending == 0
|
54
|
+
@pending_cv.wait @pending_mx
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Main method for a TEM firmware updating thread.
|
60
|
+
#
|
61
|
+
# Args:
|
62
|
+
# transport_config:: configuration for the TEM's smart-card transport
|
63
|
+
def update_thread(transport_config)
|
64
|
+
transport = Smartcard::Iso::AutoConfigurator.try_transport transport_config
|
65
|
+
if transport
|
66
|
+
@logger.info "Connected to #{transport.inspect}"
|
67
|
+
update_transport transport
|
68
|
+
else
|
69
|
+
@logger.warn "Failed connecting to #{transport_config.inspect}"
|
70
|
+
end
|
71
|
+
|
72
|
+
@pending_mx.synchronize do
|
73
|
+
@pending -= 1
|
74
|
+
@pending_cv.signal
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Installs or updates TEM firmware on a smart-card.
|
79
|
+
#
|
80
|
+
# Args:
|
81
|
+
# transport_config:: smart-card transport connecting to the TEM card
|
82
|
+
#
|
83
|
+
# No firmware will be uploaded if the smart-card already has the latest
|
84
|
+
# version of the TEM software.
|
85
|
+
def update_transport(transport)
|
86
|
+
if !needs_update? transport
|
87
|
+
@logger.info "No update needed at #{transport.inspect}"
|
88
|
+
return
|
89
|
+
end
|
90
|
+
|
91
|
+
@logger.info "Uploading TEM firmware to #{transport.inspect}"
|
92
|
+
begin
|
93
|
+
Tem::Firmware::Uploader.upload_cap transport
|
94
|
+
rescue Exception => e
|
95
|
+
@logger.error "Error while uploading TEM firmware to " +
|
96
|
+
"#{transport.inspect} - #{e.class.name}: #{e.message}"
|
97
|
+
@logger.info e.backtrace.join("\n")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Checks if the a smart-card needs a TEM firmware upload.
|
102
|
+
#
|
103
|
+
# Args:
|
104
|
+
# transport_config:: smart-card transport connecting to the TEM card
|
105
|
+
def needs_update?(transport)
|
106
|
+
begin
|
107
|
+
tem = Tem::Session.new transport
|
108
|
+
tem_version = tem.fw_version
|
109
|
+
local_version = Tem::Firmware::Uploader.fw_version
|
110
|
+
if local_version[:major] != tem_version[:major]
|
111
|
+
return local_version[:major] > tem_version[:major]
|
112
|
+
end
|
113
|
+
return local_version[:minor] > tem_version[:minor]
|
114
|
+
rescue Smartcard::Iso::ApduError
|
115
|
+
# An APDU error here means the TEM firmware was not installed.
|
116
|
+
return true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end # class Tem::MultiUpdater::Updater
|
120
|
+
|
121
|
+
end # namespace Tem::MultiUpdater
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Main include file for the tem_multi_updater Rubygem.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
# Gem requirements.
|
8
|
+
require 'rubygems'
|
9
|
+
require 'smartcard'
|
10
|
+
require 'tem_ruby'
|
11
|
+
require 'tem_multi_proxy'
|
12
|
+
|
13
|
+
# :nodoc: namespace
|
14
|
+
module Tem
|
15
|
+
end
|
16
|
+
|
17
|
+
# The files making up the gem.
|
18
|
+
require 'tem_multi_updater/updater.rb'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{tem_multi_updater}
|
5
|
+
s.version = "0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Victor Costan"]
|
9
|
+
s.date = %q{2009-11-10}
|
10
|
+
s.default_executable = %q{tem_multi_update_fw}
|
11
|
+
s.description = %q{Updates the firmware on all TEMs connected to a tem_multi_proxy.}
|
12
|
+
s.email = %q{victor@costan.us}
|
13
|
+
s.executables = ["tem_multi_update_fw"]
|
14
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "bin/tem_multi_update_fw", "lib/tem_multi_updater.rb", "lib/tem_multi_updater/updater.rb"]
|
15
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "bin/tem_multi_update_fw", "lib/tem_multi_updater.rb", "lib/tem_multi_updater/updater.rb", "tem_multi_updater.gemspec"]
|
16
|
+
s.homepage = %q{http://tem.rubyforge.org}
|
17
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tem_multi_updater", "--main", "README"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{tem}
|
20
|
+
s.rubygems_version = %q{1.3.5}
|
21
|
+
s.summary = %q{Updates the firmware on all TEMs connected to a tem_multi_proxy.}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_runtime_dependency(%q<smartcard>, [">= 0.4.7"])
|
29
|
+
s.add_runtime_dependency(%q<tem_multi_proxy>, [">= 0.2.5"])
|
30
|
+
s.add_runtime_dependency(%q<tem_ruby>, [">= 0.12.0"])
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<smartcard>, [">= 0.4.7"])
|
33
|
+
s.add_dependency(%q<tem_multi_proxy>, [">= 0.2.5"])
|
34
|
+
s.add_dependency(%q<tem_ruby>, [">= 0.12.0"])
|
35
|
+
end
|
36
|
+
else
|
37
|
+
s.add_dependency(%q<smartcard>, [">= 0.4.7"])
|
38
|
+
s.add_dependency(%q<tem_multi_proxy>, [">= 0.2.5"])
|
39
|
+
s.add_dependency(%q<tem_ruby>, [">= 0.12.0"])
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tem_multi_updater
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Costan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-10 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: smartcard
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.4.7
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: tem_multi_proxy
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.5
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: tem_ruby
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.12.0
|
44
|
+
version:
|
45
|
+
description: Updates the firmware on all TEMs connected to a tem_multi_proxy.
|
46
|
+
email: victor@costan.us
|
47
|
+
executables:
|
48
|
+
- tem_multi_update_fw
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- CHANGELOG
|
53
|
+
- LICENSE
|
54
|
+
- README
|
55
|
+
- bin/tem_multi_update_fw
|
56
|
+
- lib/tem_multi_updater.rb
|
57
|
+
- lib/tem_multi_updater/updater.rb
|
58
|
+
files:
|
59
|
+
- CHANGELOG
|
60
|
+
- LICENSE
|
61
|
+
- Manifest
|
62
|
+
- README
|
63
|
+
- Rakefile
|
64
|
+
- bin/tem_multi_update_fw
|
65
|
+
- lib/tem_multi_updater.rb
|
66
|
+
- lib/tem_multi_updater/updater.rb
|
67
|
+
- tem_multi_updater.gemspec
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://tem.rubyforge.org
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --line-numbers
|
75
|
+
- --inline-source
|
76
|
+
- --title
|
77
|
+
- Tem_multi_updater
|
78
|
+
- --main
|
79
|
+
- README
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
version:
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "1.2"
|
93
|
+
version:
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project: tem
|
97
|
+
rubygems_version: 1.3.5
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Updates the firmware on all TEMs connected to a tem_multi_proxy.
|
101
|
+
test_files: []
|
102
|
+
|