diff --git a/src/demo_client.rb b/src/demo_client.rb index e04e302..7ece6ea 100755 --- a/src/demo_client.rb +++ b/src/demo_client.rb @@ -69,6 +69,7 @@ VERBOSE = 0 include APDU +# tell APDU methods how to send def transmit_apdu(apdu) return @client.apdu(apdu) end diff --git a/src/demo_server.rb b/src/demo_server.rb new file mode 100755 index 0000000..414c5d3 --- /dev/null +++ b/src/demo_server.rb @@ -0,0 +1,60 @@ +#!/usr/bin/env ruby +=begin +This file is part of SAP. + +SAP is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SAP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SAP. If not, see . + +Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info +=end +# this program is there to start a server +require 'socket' +require 'pcsc_server' +require 'sim_server' + +# the io the server should use (:tcp, :unix) +io_type = :tcp +# the server to use (:pcsc, :sim) +server_type = :pcsc + +# create the IO +case io_type +when :tcp + TCP_HOST = "localhost" + TCP_PORT = "1337" + socket = TCPServer.new(TCP_HOST,TCP_PORT) +when :unix + UNIX = "/tmp/sap_server.socket" + socket = UNIXServer.new(APDU_SOCKET) +else + raise "unkown IO type" +end + +# wait for a client to connect +io = socket.accept + +case server_type +when :pcsc + server = PCSCServer.new(io) +when :sim + server = SIMServer.new(io) +else + raise "unkown server type" +end + +# starting the server +server.start + +# close IO when finished +io.close +server.close diff --git a/src/pcsc_server.rb b/src/pcsc_server.rb old mode 100755 new mode 100644 index a06c1e7..a57d3f7 --- a/src/pcsc_server.rb +++ b/src/pcsc_server.rb @@ -18,7 +18,6 @@ along with SAP. If not, see . Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info =end require 'lib/server' -require 'socket' require 'rubygems' require 'smartcard' =begin @@ -109,9 +108,3 @@ class PCSCServer < Server end end - -# demo application, using TCP socket -socket = TCPServer.new("localhost",1337) -io = socket.accept -server = PCSCServer.new(io) -server.start diff --git a/src/sim_server.rb b/src/sim_server.rb old mode 100755 new mode 100644 index b6873dc..58f016a --- a/src/sim_server.rb +++ b/src/sim_server.rb @@ -140,7 +140,7 @@ class SIMServer < Server # select file using the file ID # node representing the file is returned # nil is return if file does not exist or is unaccessible - def select (id) + def select(id) response = nil # get the current directory dfs = [0x3f,0x5f,0x7f] @@ -179,9 +179,3 @@ class SIMServer < Server end end - -# demo application, using TCP socket -socket = TCPServer.new("localhost",1337) -io = socket.accept -server = SIMServer.new(io) -server.start