smartcard 0.4.6 → 0.4.7

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/BUILD CHANGED
@@ -22,8 +22,8 @@ anything.
22
22
 
23
23
  You need to install the Developer Tools to get gcc.
24
24
 
25
- Leopard (OSX 10.5) includes a working PC/SC provider, as well as a good driver
26
- for CCID readers.
25
+ Leopard and Snow Leopard (OSX 10.5 / 10.6) include a working PC/SC provider, as
26
+ well as a good driver for CCID readers.
27
27
 
28
28
  Tiger's (OSX 10.4) PC/SC implementation is broken and incomplete, so the Ruby
29
29
  extension code in +smartcard+ has a few hacks to work around that (look for the
@@ -35,13 +35,13 @@ don't work:
35
35
  * Smartcard::PCSC::Card#control (Tiger's API is broken, the call may not work)
36
36
 
37
37
  The developer team doesn't support or test against ports of +gcc+ or +pcsclite+,
38
- but we success notifications are welcome.
38
+ but we welcome patches or success stories.
39
39
 
40
40
  == Windows
41
41
 
42
42
  A lot of effort has been spent to make Windows builds as easy as possible.
43
43
  +smartcard+ is currently built using a full edition of
44
- {Visual Studio 2005}[http://msdn.microsoft.com/vstudio/], but all sources
44
+ {Visual Studio 6.0}[http://msdn.microsoft.com/vstudio/], but all sources
45
45
  indicate that
46
46
  {Visual C++ Express 2005}[http://www.microsoft.com/express/download/]
47
47
  works, as long as you also install a Windows SDK (you're on your own for that).
@@ -69,7 +69,7 @@ readers.
69
69
  === Ubuntu
70
70
 
71
71
  Installing the following packages (and their dependencies) gets you going on
72
- Ubuntu (tested on 7.10, 8.04, and 8.10):
72
+ Ubuntu (tested on 8.04, 8.10, 9.04 and 9.10):
73
73
  * build-essential
74
74
  * libccid
75
75
  * libpcsclite-dev (depends on libpcsclite or libpcsclite1)
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.4.7. Custom exception class for APDU responses with error codes.
2
+
1
3
  v0.4.6. Automatic detection of package AID from CAP in install_applet.
2
4
 
3
5
  v0.4.5. More bugfixes in JcopRemoteTransport's ATR forwarding logic.
data/Manifest CHANGED
@@ -22,6 +22,7 @@ lib/smartcard/gp/asn1_ber.rb
22
22
  lib/smartcard/gp/cap_loader.rb
23
23
  lib/smartcard/gp/des.rb
24
24
  lib/smartcard/gp/gp_card_mixin.rb
25
+ lib/smartcard/iso/apdu_error.rb
25
26
  lib/smartcard/iso/auto_configurator.rb
26
27
  lib/smartcard/iso/iso_card_mixin.rb
27
28
  lib/smartcard/iso/jcop_remote_protocol.rb
@@ -30,6 +31,7 @@ lib/smartcard/iso/jcop_remote_transport.rb
30
31
  lib/smartcard/iso/pcsc_transport.rb
31
32
  lib/smartcard/iso/transport.rb
32
33
  lib/smartcard/pcsc/pcsc_exception.rb
34
+ smartcard.gemspec
33
35
  test/gp/asn1_ber_test.rb
34
36
  test/gp/cap_loader_test.rb
35
37
  test/gp/des_test.rb
@@ -38,6 +40,7 @@ test/gp/hello.apdu
38
40
  test/gp/hello.cap
39
41
  test/iso/auto_configurator_test.rb
40
42
  test/iso/iso_card_mixin_test.rb
43
+ test/iso/iso_exception_test.rb
41
44
  test/iso/jcop_remote_test.rb
42
45
  test/pcsc/containers_test.rb
43
46
  test/pcsc/smoke_test.rb
data/lib/smartcard.rb CHANGED
@@ -2,6 +2,7 @@ require 'smartcard/pcsc'
2
2
  require 'smartcard/pcsc/pcsc_exception.rb'
3
3
 
4
4
 
5
+ require 'smartcard/iso/apdu_error.rb'
5
6
  require 'smartcard/iso/iso_card_mixin.rb'
6
7
  require 'smartcard/iso/jcop_remote_protocol.rb'
7
8
  require 'smartcard/iso/jcop_remote_transport.rb'
@@ -179,7 +179,7 @@ module GpCardMixin
179
179
  raw = iso_apdu :cla => 0x80, :ins => 0xF2, :p1 => scope_byte,
180
180
  :p2 => (first ? 0 : 1), :data => [0x4F, 0x00]
181
181
  if raw[:status] != 0x9000 && raw[:status] != 0x6310
182
- Smartcard::Iso::IsoCardMixin.raise_response_exception raw
182
+ raise Smartcard::Iso::ApduException, raw
183
183
  end
184
184
 
185
185
  offset = 0
@@ -0,0 +1,43 @@
1
+ # Exception indicating an error code in an ISO-7618 response APDU.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Massachusetts Institute of Technology
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module Smartcard::Iso
9
+
10
+
11
+ # Indicates an error code in an ISO-7618 response APDU.
12
+ #
13
+ # This exception should be raised if the response obtained from iso_apdu has an
14
+ # error status. When raising the exception, supply the entire response as the
15
+ # only argument to raise.
16
+ #
17
+ # Usage example:
18
+ # response = transport.iso_apdu :ins => 0x12
19
+ # raise Smartcard::Iso::ApduError, response unless response[:status] == 0x9000
20
+ class ApduError < RuntimeError
21
+ # The data in the error APDU.
22
+ attr_accessor :data
23
+ # The error status.
24
+ attr_accessor :status
25
+
26
+ # Creates a new exception (for raising).
27
+ #
28
+ # Args:
29
+ # response:: the APDU response (hash with +:data+ and +:status+ keys)
30
+ def initialize(response)
31
+ @data = response[:data]
32
+ @status = response[:status]
33
+ super ApduError.message_for_apdu_response response
34
+ end
35
+
36
+ # Computes the exception message for an APDU response.
37
+ def self.message_for_apdu_response(response)
38
+ "ISO-7816 response APDU has error status 0x#{'%04x' % response[:status]}" +
39
+ " - #{response[:data].map { |ch| '%02x' % ch }.join(' ')}"
40
+ end
41
+ end # class Smartcard::Iso::ApduError
42
+
43
+ end # namespace Smartcard::Iso
@@ -16,7 +16,7 @@ module Smartcard::Iso
16
16
  # the APDU data as an array of integers between 0 and 255, and expects a
17
17
  # response in the same format.
18
18
  module IsoCardMixin
19
- # APDU exchange with the ISO7816 card, raising an exception if the return
19
+ # APDU exchange with the ISO7816 card, raising an ApduError if the return
20
20
  # code is not success (0x9000).
21
21
  #
22
22
  # :call_seq:
@@ -24,22 +24,13 @@ module IsoCardMixin
24
24
  #
25
25
  # The apdu_data should be in the format expected by
26
26
  # IsoCardMixin#serialize_apdu. Returns the response data, if the response
27
- # status indicates success (0x9000). Otherwise, raises an exeception.
27
+ # status indicates success (0x9000). Otherwise, raises an ApduError.
28
28
  def iso_apdu!(apdu_data)
29
29
  response = self.iso_apdu apdu_data
30
30
  return response[:data] if response[:status] == 0x9000
31
- IsoCardMixin.raise_response_exception response
31
+ raise ApduError, response
32
32
  end
33
33
 
34
- # Raises an exception in response to an error status in an APDU.
35
- #
36
- # :call_seq:
37
- # IsoCardMixin.raise_response_exception(response)
38
- def self.raise_response_exception(response)
39
- raise "JavaCard response has error status 0x#{'%04x' % response[:status]}" +
40
- " - #{response[:data].map { |ch| '%02x' % ch }.join(' ')}"
41
- end
42
-
43
34
  # Performs an APDU exchange with the ISO7816 card.
44
35
  #
45
36
  # :call-seq:
data/smartcard.gemspec CHANGED
@@ -2,23 +2,23 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{smartcard}
5
- s.version = "0.4.6"
5
+ s.version = "0.4.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Victor Costan"]
9
- s.date = %q{2009-11-01}
9
+ s.date = %q{2009-11-10}
10
10
  s.description = %q{Interface with ISO 7816 smart cards.}
11
11
  s.email = %q{victor@costan.us}
12
12
  s.extensions = ["ext/smartcard_pcsc/extconf.rb"]
13
- s.extra_rdoc_files = ["BUILD", "CHANGELOG", "LICENSE", "README", "ext/smartcard_pcsc/extconf.rb", "ext/smartcard_pcsc/pcsc.h", "ext/smartcard_pcsc/pcsc_card.c", "ext/smartcard_pcsc/pcsc_constants.c", "ext/smartcard_pcsc/pcsc_context.c", "ext/smartcard_pcsc/pcsc_exception.c", "ext/smartcard_pcsc/pcsc_io_request.c", "ext/smartcard_pcsc/pcsc_main.c", "ext/smartcard_pcsc/pcsc_multi_strings.c", "ext/smartcard_pcsc/pcsc_namespace.c", "ext/smartcard_pcsc/pcsc_reader_states.c", "ext/smartcard_pcsc/pcsc_surrogate_reader.h", "ext/smartcard_pcsc/pcsc_surrogate_wintypes.h", "lib/smartcard.rb", "lib/smartcard/gp/asn1_ber.rb", "lib/smartcard/gp/cap_loader.rb", "lib/smartcard/gp/des.rb", "lib/smartcard/gp/gp_card_mixin.rb", "lib/smartcard/iso/auto_configurator.rb", "lib/smartcard/iso/iso_card_mixin.rb", "lib/smartcard/iso/jcop_remote_protocol.rb", "lib/smartcard/iso/jcop_remote_server.rb", "lib/smartcard/iso/jcop_remote_transport.rb", "lib/smartcard/iso/pcsc_transport.rb", "lib/smartcard/iso/transport.rb", "lib/smartcard/pcsc/pcsc_exception.rb"]
14
- s.files = ["BUILD", "CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "ext/smartcard_pcsc/extconf.rb", "ext/smartcard_pcsc/pcsc.h", "ext/smartcard_pcsc/pcsc_card.c", "ext/smartcard_pcsc/pcsc_constants.c", "ext/smartcard_pcsc/pcsc_context.c", "ext/smartcard_pcsc/pcsc_exception.c", "ext/smartcard_pcsc/pcsc_io_request.c", "ext/smartcard_pcsc/pcsc_main.c", "ext/smartcard_pcsc/pcsc_multi_strings.c", "ext/smartcard_pcsc/pcsc_namespace.c", "ext/smartcard_pcsc/pcsc_reader_states.c", "ext/smartcard_pcsc/pcsc_surrogate_reader.h", "ext/smartcard_pcsc/pcsc_surrogate_wintypes.h", "lib/smartcard.rb", "lib/smartcard/gp/asn1_ber.rb", "lib/smartcard/gp/cap_loader.rb", "lib/smartcard/gp/des.rb", "lib/smartcard/gp/gp_card_mixin.rb", "lib/smartcard/iso/auto_configurator.rb", "lib/smartcard/iso/iso_card_mixin.rb", "lib/smartcard/iso/jcop_remote_protocol.rb", "lib/smartcard/iso/jcop_remote_server.rb", "lib/smartcard/iso/jcop_remote_transport.rb", "lib/smartcard/iso/pcsc_transport.rb", "lib/smartcard/iso/transport.rb", "lib/smartcard/pcsc/pcsc_exception.rb", "test/gp/asn1_ber_test.rb", "test/gp/cap_loader_test.rb", "test/gp/des_test.rb", "test/gp/gp_card_mixin_test.rb", "test/gp/hello.apdu", "test/gp/hello.cap", "test/iso/auto_configurator_test.rb", "test/iso/iso_card_mixin_test.rb", "test/iso/jcop_remote_test.rb", "test/pcsc/containers_test.rb", "test/pcsc/smoke_test.rb", "tests/ts_pcsc_ext.rb", "smartcard.gemspec"]
13
+ s.extra_rdoc_files = ["BUILD", "CHANGELOG", "LICENSE", "README", "ext/smartcard_pcsc/extconf.rb", "ext/smartcard_pcsc/pcsc.h", "ext/smartcard_pcsc/pcsc_card.c", "ext/smartcard_pcsc/pcsc_constants.c", "ext/smartcard_pcsc/pcsc_context.c", "ext/smartcard_pcsc/pcsc_exception.c", "ext/smartcard_pcsc/pcsc_io_request.c", "ext/smartcard_pcsc/pcsc_main.c", "ext/smartcard_pcsc/pcsc_multi_strings.c", "ext/smartcard_pcsc/pcsc_namespace.c", "ext/smartcard_pcsc/pcsc_reader_states.c", "ext/smartcard_pcsc/pcsc_surrogate_reader.h", "ext/smartcard_pcsc/pcsc_surrogate_wintypes.h", "lib/smartcard.rb", "lib/smartcard/gp/asn1_ber.rb", "lib/smartcard/gp/cap_loader.rb", "lib/smartcard/gp/des.rb", "lib/smartcard/gp/gp_card_mixin.rb", "lib/smartcard/iso/apdu_error.rb", "lib/smartcard/iso/auto_configurator.rb", "lib/smartcard/iso/iso_card_mixin.rb", "lib/smartcard/iso/jcop_remote_protocol.rb", "lib/smartcard/iso/jcop_remote_server.rb", "lib/smartcard/iso/jcop_remote_transport.rb", "lib/smartcard/iso/pcsc_transport.rb", "lib/smartcard/iso/transport.rb", "lib/smartcard/pcsc/pcsc_exception.rb"]
14
+ s.files = ["BUILD", "CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "ext/smartcard_pcsc/extconf.rb", "ext/smartcard_pcsc/pcsc.h", "ext/smartcard_pcsc/pcsc_card.c", "ext/smartcard_pcsc/pcsc_constants.c", "ext/smartcard_pcsc/pcsc_context.c", "ext/smartcard_pcsc/pcsc_exception.c", "ext/smartcard_pcsc/pcsc_io_request.c", "ext/smartcard_pcsc/pcsc_main.c", "ext/smartcard_pcsc/pcsc_multi_strings.c", "ext/smartcard_pcsc/pcsc_namespace.c", "ext/smartcard_pcsc/pcsc_reader_states.c", "ext/smartcard_pcsc/pcsc_surrogate_reader.h", "ext/smartcard_pcsc/pcsc_surrogate_wintypes.h", "lib/smartcard.rb", "lib/smartcard/gp/asn1_ber.rb", "lib/smartcard/gp/cap_loader.rb", "lib/smartcard/gp/des.rb", "lib/smartcard/gp/gp_card_mixin.rb", "lib/smartcard/iso/apdu_error.rb", "lib/smartcard/iso/auto_configurator.rb", "lib/smartcard/iso/iso_card_mixin.rb", "lib/smartcard/iso/jcop_remote_protocol.rb", "lib/smartcard/iso/jcop_remote_server.rb", "lib/smartcard/iso/jcop_remote_transport.rb", "lib/smartcard/iso/pcsc_transport.rb", "lib/smartcard/iso/transport.rb", "lib/smartcard/pcsc/pcsc_exception.rb", "smartcard.gemspec", "test/gp/asn1_ber_test.rb", "test/gp/cap_loader_test.rb", "test/gp/des_test.rb", "test/gp/gp_card_mixin_test.rb", "test/gp/hello.apdu", "test/gp/hello.cap", "test/iso/auto_configurator_test.rb", "test/iso/iso_card_mixin_test.rb", "test/iso/iso_exception_test.rb", "test/iso/jcop_remote_test.rb", "test/pcsc/containers_test.rb", "test/pcsc/smoke_test.rb", "tests/ts_pcsc_ext.rb"]
15
15
  s.homepage = %q{http://www.costan.us/smartcard}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Smartcard", "--main", "README"]
17
17
  s.require_paths = ["lib", "ext"]
18
18
  s.rubyforge_project = %q{smartcard}
19
19
  s.rubygems_version = %q{1.3.5}
20
20
  s.summary = %q{Interface with ISO 7816 smart cards.}
21
- s.test_files = ["test/gp/asn1_ber_test.rb", "test/gp/cap_loader_test.rb", "test/gp/des_test.rb", "test/gp/gp_card_mixin_test.rb", "test/iso/auto_configurator_test.rb", "test/iso/iso_card_mixin_test.rb", "test/iso/jcop_remote_test.rb", "test/pcsc/containers_test.rb", "test/pcsc/smoke_test.rb"]
21
+ s.test_files = ["test/iso/iso_card_mixin_test.rb", "test/iso/auto_configurator_test.rb", "test/iso/iso_exception_test.rb", "test/iso/jcop_remote_test.rb", "test/pcsc/smoke_test.rb", "test/pcsc/containers_test.rb", "test/gp/gp_card_mixin_test.rb", "test/gp/cap_loader_test.rb", "test/gp/asn1_ber_test.rb", "test/gp/des_test.rb"]
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -89,8 +89,15 @@ class IsoCardMixinTest < Test::Unit::TestCase
89
89
 
90
90
  def test_iso_apdu_bang
91
91
  assert_equal [0x67, 0x31], win_mock.iso_apdu!(win_apdu)
92
- assert_raise(RuntimeError) do
92
+ assert_raise(Smartcard::Iso::ApduError) do
93
93
  lose_mock.iso_apdu!(lose_apdu)
94
94
  end
95
+
96
+ begin
97
+ lose_mock.iso_apdu! lose_apdu
98
+ rescue Smartcard::Iso::ApduError => e
99
+ assert_equal [], e.data, 'APDU data in raised error'
100
+ assert_equal 0x8631, e.status, 'APDU error status in raised error'
101
+ end
95
102
  end
96
103
  end
@@ -0,0 +1,36 @@
1
+ # Author:: Victor Costan
2
+ # Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
3
+ # License:: MIT
4
+
5
+ require 'smartcard'
6
+
7
+ require 'test/unit'
8
+
9
+ require 'rubygems'
10
+ require 'flexmock/test_unit'
11
+
12
+
13
+ class ApduErrorTest < Test::Unit::TestCase
14
+ def setup
15
+ @response = { :data => [0x31, 0x41, 0x59], :status => 0x6A88 }
16
+ end
17
+
18
+ def test_raise
19
+ assert_raise Smartcard::Iso::ApduError do
20
+ raise Smartcard::Iso::ApduError, @response
21
+ end
22
+ end
23
+
24
+ def test_contents
25
+ begin
26
+ raise Smartcard::Iso::ApduError, @response
27
+ rescue Smartcard::Iso::ApduError => e
28
+ assert_equal @response[:status], e.status, 'Error status attribute'
29
+ assert_equal @response[:data], e.data, 'APDU data attribute'
30
+ golden_message =
31
+ 'ISO-7816 response APDU has error status 0x6a88 - 31 41 59'
32
+ assert_equal golden_message, e.message, 'Exception message'
33
+ end
34
+ end
35
+ IsoCardMixin = Smartcard::Iso::IsoCardMixin
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartcard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Costan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-01 01:00:00 -04:00
12
+ date: 2009-11-10 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,6 +51,7 @@ extra_rdoc_files:
51
51
  - lib/smartcard/gp/cap_loader.rb
52
52
  - lib/smartcard/gp/des.rb
53
53
  - lib/smartcard/gp/gp_card_mixin.rb
54
+ - lib/smartcard/iso/apdu_error.rb
54
55
  - lib/smartcard/iso/auto_configurator.rb
55
56
  - lib/smartcard/iso/iso_card_mixin.rb
56
57
  - lib/smartcard/iso/jcop_remote_protocol.rb
@@ -84,6 +85,7 @@ files:
84
85
  - lib/smartcard/gp/cap_loader.rb
85
86
  - lib/smartcard/gp/des.rb
86
87
  - lib/smartcard/gp/gp_card_mixin.rb
88
+ - lib/smartcard/iso/apdu_error.rb
87
89
  - lib/smartcard/iso/auto_configurator.rb
88
90
  - lib/smartcard/iso/iso_card_mixin.rb
89
91
  - lib/smartcard/iso/jcop_remote_protocol.rb
@@ -92,6 +94,7 @@ files:
92
94
  - lib/smartcard/iso/pcsc_transport.rb
93
95
  - lib/smartcard/iso/transport.rb
94
96
  - lib/smartcard/pcsc/pcsc_exception.rb
97
+ - smartcard.gemspec
95
98
  - test/gp/asn1_ber_test.rb
96
99
  - test/gp/cap_loader_test.rb
97
100
  - test/gp/des_test.rb
@@ -100,11 +103,11 @@ files:
100
103
  - test/gp/hello.cap
101
104
  - test/iso/auto_configurator_test.rb
102
105
  - test/iso/iso_card_mixin_test.rb
106
+ - test/iso/iso_exception_test.rb
103
107
  - test/iso/jcop_remote_test.rb
104
108
  - test/pcsc/containers_test.rb
105
109
  - test/pcsc/smoke_test.rb
106
110
  - tests/ts_pcsc_ext.rb
107
- - smartcard.gemspec
108
111
  has_rdoc: true
109
112
  homepage: http://www.costan.us/smartcard
110
113
  licenses: []
@@ -140,12 +143,13 @@ signing_key:
140
143
  specification_version: 3
141
144
  summary: Interface with ISO 7816 smart cards.
142
145
  test_files:
143
- - test/gp/asn1_ber_test.rb
144
- - test/gp/cap_loader_test.rb
145
- - test/gp/des_test.rb
146
- - test/gp/gp_card_mixin_test.rb
147
- - test/iso/auto_configurator_test.rb
148
146
  - test/iso/iso_card_mixin_test.rb
147
+ - test/iso/auto_configurator_test.rb
148
+ - test/iso/iso_exception_test.rb
149
149
  - test/iso/jcop_remote_test.rb
150
- - test/pcsc/containers_test.rb
151
150
  - test/pcsc/smoke_test.rb
151
+ - test/pcsc/containers_test.rb
152
+ - test/gp/gp_card_mixin_test.rb
153
+ - test/gp/cap_loader_test.rb
154
+ - test/gp/asn1_ber_test.rb
155
+ - test/gp/des_test.rb