Skip to content

Commit

Permalink
Bugfix in JcopRemoteTransport's ATR forwarding logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Costan committed Nov 1, 2009
1 parent 9fae2a4 commit 4cf5935
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
v0.4.4. Bugfixes in JcopRemoteTransport's ATR forwarding logic.

v0.4.3. Fixed gem manifest to state dependency on rubyzip.

v0.4.2. GlobalPlatform applet instalation.
Expand Down
4 changes: 2 additions & 2 deletions lib/smartcard/iso/jcop_remote_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def exchange_apdu(apdu)
[0x90, 0x00]
end

# The smartcard's APDU.
def card_apdu
# The smartcard's ATR.
def card_atr
# ATR from the card simulator in JCOP 3.2.7.
[0x3B, 0xF8, 0x13, 0x00, 0x00, 0x81, 0x31, 0xFE, 0x45, 0x4A, 0x43, 0x4F,
0x50, 0x76, 0x32, 0x34, 0x31, 0xB7].pack('C*')
Expand Down
14 changes: 11 additions & 3 deletions lib/smartcard/iso/jcop_remote_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ class JcopRemoteTransport
def initialize(options)
@host, @port = options[:host], options[:port]
@socket = nil
@atr = nil
end

#
# :nodoc: standard transport method
def exchange_apdu(apdu)
send_message @socket, :type => 1, :node => 0, :data => apdu
loop do
message = recv_message @socket
return message[:data] if message[:type] == 1
end
end
end

# :nodoc: standard transport method
def card_atr
@atr
end

# Makes a transport-level connection to the TEM.
def connect
Expand All @@ -51,7 +57,8 @@ def connect

# Wait for the card to be inserted.
send_message @socket, :type => 0, :node => 0, :data => [0, 1, 0, 0]
recv_message @socket # ATR should come here, but who cares
message = recv_message @socket
@atr = message[:data]
rescue Exception
@socket = nil
raise
Expand All @@ -63,6 +70,7 @@ def disconnect
if @socket
@socket.close
@socket = nil
@atr = nil
end
end

Expand Down
2 changes: 1 addition & 1 deletion smartcard.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = %q{smartcard}
s.version = "0.4.3"
s.version = "0.4.4"

s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Victor Costan"]
Expand Down
1 change: 1 addition & 0 deletions test/iso/jcop_remote_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _test_apdu_exchange
Kernel.sleep 0.05 # Wait for the server to start up.
@client.connect
assert_equal apdu_response, @client.exchange_apdu(apdu_request)
assert_equal [0x31, 0x41, 0x59], @client.card_atr
@client.disconnect
Kernel.sleep 0.05 # Wait for the server to process the disconnect.
assert_equal [:start, apdu_request, :end], logic.received
Expand Down

0 comments on commit 4cf5935

Please sign in to comment.