10
0
Fork 0

updated to ruby1.9 (I may have missed some), and fixed some bugs/typos

This commit is contained in:
Kevin Redon 2013-01-22 15:08:54 +01:00
parent 9bb57d7ac6
commit 81db0e7926
10 changed files with 77 additions and 60 deletions

View File

@ -18,7 +18,7 @@ along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
=end =end
# this programm will forward APDU from an IO to a SAP server # this programm will forward APDU from an IO to a SAP server
require 'sap/client' require './sap/client.rb'
require 'socket' require 'socket'
SAP_HOST = "localhost" SAP_HOST = "localhost"

View File

@ -17,8 +17,8 @@ along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
=end =end
# this class copies all files from the SIM to an xml file # this class copies all files from the SIM to an xml file
require 'sap/client' require './sap/client.rb'
require 'lib/apdu' require './lib/apdu.rb'
require 'xml' require 'xml'
class Copy class Copy
@ -254,7 +254,7 @@ class Copy
@nb_files = 0 unless @nb_files @nb_files = 0 unless @nb_files
@nb_files += 1 @nb_files += 1
rescue Exception => e rescue Exception => e
puts "file error : #{e.to_s}" puts "file errors: #{e.to_s}"
select_decode(select(id)) select_decode(select(id))
end end
end end

View File

@ -18,10 +18,10 @@ along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
=end =end
# this programm will create a client which can be used to test servers # this programm will create a client which can be used to test servers
require 'sap/client' require './sap/client.rb'
require 'lib/apdu' require './lib/apdu.rb'
require 'info_client' require './info_client.rb'
require 'copy_client' require './copy_client.rb'
#============= #=============
#== default == #== default ==
@ -130,7 +130,7 @@ when "bt"
if @bt then if @bt then
io = SerialPort.new(@bt) io = SerialPort.new(@bt)
else else
require 'lib/bluetooth_sap_serial' require './tools/bluetooth_sap_serial.rb'
bt = BluetoothSAPSerial.new bt = BluetoothSAPSerial.new
# using SerialPort because reading the File does not work (have to find right stty options) # using SerialPort because reading the File does not work (have to find right stty options)
io = SerialPort.new(bt.connect) io = SerialPort.new(bt.connect)

View File

@ -49,7 +49,7 @@ def print_help
puts "options :" puts "options :"
puts " --help,-h\t\tprint this help" puts " --help,-h\t\tprint this help"
puts " --type,-t type\tserver type: pcsc,sim (default #{@type})" puts " --type,-t type\tserver type: pcsc,sim (default #{@type})"
puts " --socket,-s type\tsocket type : tcp,unix,bt (default #{@socket})" puts " --socket,-s type\tsocket type: tcp,unix (default #{@socket})"
puts " --port,-p port\t\ttcp listeing port (default #{@port})" puts " --port,-p port\t\ttcp listeing port (default #{@port})"
puts " --unix,-u file\t\tunix socket (default #{@unix})" puts " --unix,-u file\t\tunix socket (default #{@unix})"
puts " --file,-f file\t\tfile for sim type (default #{@file})" puts " --file,-f file\t\tfile for sim type (default #{@file})"
@ -107,10 +107,10 @@ io = socket.accept
case @type case @type
when "pcsc" when "pcsc"
require 'pcsc_server' require './pcsc_server.rb'
server = PCSCServer.new(io) server = PCSCServer.new(io)
when "sim" when "sim"
require 'simos_server' require './simos_server.rb'
server = SIMServer.new(io) server = SIMServer.new(io)
else else
raise "unkown server type" raise "unkown server type"

View File

@ -18,8 +18,8 @@ along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
=end =end
# this programm will display information stored in the SIM # this programm will display information stored in the SIM
require 'sap/client' require './sap/client.rb'
require 'lib/apdu' require './lib/apdu.rb'
#============= #=============
#== methods == #== methods ==

View File

@ -17,7 +17,7 @@ along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
=end =end
require 'sap/server' require './sap/server.rb'
require 'rubygems' require 'rubygems'
require 'smartcard' require 'smartcard'
=begin =begin

View File

@ -18,7 +18,7 @@ Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
=end =end
# this is the client part of the SAP # this is the client part of the SAP
# it implements the state machine for the client # it implements the state machine for the client
require 'sap/common' require './sap/common.rb'
# this is an abstract class # this is an abstract class
# TODO : # TODO :

View File

@ -19,7 +19,7 @@ Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
# this is the server part of the SAP # this is the server part of the SAP
# it implements the state machine for the server # it implements the state machine for the server
# this is an abstract class # this is an abstract class
require 'sap/common' require './sap/common.rb'
# this is an bastract class # this is an bastract class
# TODO (not implemented) : # TODO (not implemented) :

View File

@ -17,8 +17,8 @@ along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
=end =end
require 'sap/server' require './sap/server.rb'
require 'lib/apdu' require './lib/apdu.rb'
require 'socket' require 'socket'
require 'xml' require 'xml'

View File

@ -84,7 +84,6 @@ class BluetoothSAPSerial
bt_adapter = bt_service.object(adapter) bt_adapter = bt_service.object(adapter)
bt_adapter.introspect bt_adapter.introspect
bt_adapter.default_iface = "org.bluez.Adapter" bt_adapter.default_iface = "org.bluez.Adapter"
#$stdout.puts bt_abapter_object["org.bluez.Adapter"].Address
bt_adapter = bt_adapter.GetProperties()[0] bt_adapter = bt_adapter.GetProperties()[0]
bt_adapters << { bt_adapters << {
:object => adapter, :object => adapter,
@ -101,7 +100,7 @@ class BluetoothSAPSerial
elsif bt_adapters.size==1 then elsif bt_adapters.size==1 then
bt_adapter = bt_adapters[0] bt_adapter = bt_adapters[0]
else else
$stdout.puts "multiple bluetooth adapter " $stdout.puts "multiple bluetooth adapter:"
bt_adapters.each_index do |i| bt_adapters.each_index do |i|
bt_adapter = bt_adapters[i] bt_adapter = bt_adapters[i]
$stdout.puts "#{i}) #{bt_adapter[:adapter]} (#{bt_adapter[:address]} - #{bt_adapter[:name]})#{bt_adapter[:default] ? ' [default]' : ''}" $stdout.puts "#{i}) #{bt_adapter[:adapter]} (#{bt_adapter[:address]} - #{bt_adapter[:name]})#{bt_adapter[:default] ? ' [default]' : ''}"
@ -171,7 +170,25 @@ class BluetoothSAPSerial
end end
# get the device (create it if it does not exist) # get the device (create it if it does not exist)
if !device_exists then if !device_exists then
tries = 3
wait_time = 1
begin
device_object = bt_adapter.CreateDevice(properties["Address"])[0] device_object = bt_adapter.CreateDevice(properties["Address"])[0]
rescue DBus::Error => e
if e.to_s.include? "Host is down" then
if tries>0 then
puts "host is down, retrying #{tries} in #{wait_time}s"
tries -= 1;
sleep wait_time;
retry
else
puts "host is down, exiting"
exit 1
end
else
raise
end
end
else else
device_object = bt_adapter.path+"/"+device_object device_object = bt_adapter.path+"/"+device_object
end end
@ -203,12 +220,12 @@ class BluetoothSAPSerial
elsif sap_devices.size == 1 then elsif sap_devices.size == 1 then
sap_device = sap_devices[0] sap_device = sap_devices[0]
else else
$stdout.puts "multiple devices possible" $stdout.puts "multiple devices possible:"
sap_devices.each_index do |i| sap_devices.each_index do |i|
$stdout.puts "- #{sap_devices[0][:name]} (#{sap_devices[0][:addr]}" $stdout.puts "#{i}) #{sap_devices[i][:name]} (#{sap_devices[i][:addr]})"
end end
$stdout.print "select device: " $stdout.print "select device: "
sap_device = $stdin.gets.chomp sap_device = $stdin.gets.chomp.to_i
sap_device = sap_devices[sap_device] sap_device = sap_devices[sap_device]
end end
$stdout.puts "using device #{sap_device[:name]} (#{sap_device[:addr]})" $stdout.puts "using device #{sap_device[:name]} (#{sap_device[:addr]})"
@ -249,10 +266,10 @@ class BluetoothSAPSerial
begin begin
@rfcomm = @bt_sap.Connect(SAP_UUID)[0] @rfcomm = @bt_sap.Connect(SAP_UUID)[0]
rescue DBus::Error => e rescue DBus::Error => e
if e.to_s == "org.bluez.Error.Failed: Connection refused (111)" then if e.to_s.include? "Connection refused (111)" then
$stderr.puts "Connection to device failed. Restarting the device might help" $stderr.puts "Connection to device failed. Restarting the device might help"
exit 1 exit 1
elsif e.to_s == "org.bluez.Error.Failed: Connection timed out" then elsif e.to_s.include? "Connection timed out" then
$stderr.puts "Device does not respond to connection request" $stderr.puts "Device does not respond to connection request"
exit 1 exit 1
else else