iso7816 0.0.3

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.
@@ -0,0 +1,23 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/emv/crypto/crypto'
3
+
4
+ class CryptoTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ end
8
+
9
+ def s2b str
10
+ ISO7816.s2b str
11
+ end
12
+
13
+ def test_retail_mac
14
+ key = s2b '7962D9ECE03D1ACD4C76089DCE131543'
15
+ input = s2b '72C29C2371CC9BDB65B779B8E8D37B29ECC154AA56A8799FAE2F498F76ED92F2'
16
+
17
+ mac = s2b '5F1448EEA8AD90A7'
18
+ assert_equal mac, EMV::Crypto.retail_mac(key, input)
19
+
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,79 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/emv'
3
+
4
+ class TestEMV_APDU < Test::Unit::TestCase
5
+
6
+ def setup
7
+ end
8
+
9
+ def s2b str
10
+ ISO7816.s2b str
11
+ end
12
+
13
+ def test_apdus
14
+ EMV::APDU::APPLICATION_BLOCK.new
15
+ EMV::APDU::APPLICATION_UNBLOCK.new
16
+ EMV::APDU::CARD_BLOCK.new
17
+ EMV::APDU::GENERATE_APPLICATION_CRYPTOGRAM.new
18
+ EMV::APDU::GET_DATA.new
19
+ EMV::APDU::GET_PROCESSING_OPTIONS.new
20
+ EMV::APDU::PIN_CHANGE_UNBLOCK.new
21
+
22
+ EMV::APDU::EXTERNAL_AUTHENTICATE.new ""
23
+ EMV::APDU::GET_CHALLENGE.new ""
24
+ EMV::APDU::INTERNAL_AUTHENTICATE.new ""
25
+ EMV::APDU::READ_RECORD.new ""
26
+ EMV::APDU::SELECT.new ""
27
+ EMV::APDU::VERIFY.new ""
28
+
29
+ assert true
30
+
31
+ end
32
+
33
+ def test_cps_apdus
34
+ ctx = EMV::APDU::CPS::SecureContext.new
35
+
36
+ EMV::APDU::CPS::INITIALIZE_UPDATE.new nil, ctx
37
+ EMV::APDU::CPS::EXTERNAL_AUTHENTICATE.new nil, ctx
38
+ sd = EMV::APDU::CPS::STORE_DATA.new nil, ctx
39
+ assert_equal "\x00", sd.p1
40
+ sd.last_store_data
41
+ assert_equal "\x80", sd.p1
42
+
43
+ assert sd.no_dgi_enc?
44
+ sd.app_dependant
45
+ assert sd.app_dependant?
46
+ assert_equal "\xa0", sd.p1
47
+ assert !sd.all_dgi_enc?
48
+ sd.all_dgi_enc
49
+ assert_equal "\xe0", sd.p1
50
+
51
+
52
+ assert !sd.secure?
53
+ sd.secure
54
+ assert sd.secure?
55
+
56
+ end
57
+
58
+ def test_generated
59
+ test_data = [
60
+ [EMV::APDU::APPLICATION_BLOCK, "\x1E", "\x84"],
61
+ [EMV::APDU::APPLICATION_UNBLOCK, "\x18", "\x84"],
62
+ [EMV::APDU::CARD_BLOCK, "\x16", "\x84"],
63
+ [EMV::APDU::GENERATE_APPLICATION_CRYPTOGRAM, "\xAE", "\x80"],
64
+ [EMV::APDU::GET_DATA, "\xCA", "\x80"],
65
+ [EMV::APDU::GET_PROCESSING_OPTIONS, "\xA8", "\x80"],
66
+ [EMV::APDU::PIN_CHANGE_UNBLOCK, "\x24", "\x84"],
67
+ ]
68
+
69
+ test_data.each {|ins_|
70
+ clazz, ins, cla = ins_
71
+ assert_equal ins, clazz._ins
72
+ assert_equal cla, clazz._cla, clazz
73
+ apdu = clazz.new
74
+ assert_equal ins, apdu.ins
75
+ assert_equal cla, apdu.cla
76
+ }
77
+
78
+ end
79
+ end
@@ -0,0 +1,108 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/iso7816'
3
+
4
+ class TestAPDU < Test::Unit::TestCase
5
+
6
+ def setup
7
+ end
8
+
9
+ def s2b str
10
+ ISO7816.s2b str
11
+ end
12
+
13
+ def test_apdus
14
+ ISO7816::APDU::ACTIVATE_FILE.new
15
+ ISO7816::APDU::APPEND_RECORD.new
16
+ ISO7816::APDU::CHANGE_REFERENCE_DATA.new
17
+ ISO7816::APDU::CREATE_FILE.new
18
+ ISO7816::APDU::DEACTIVATE_FILE.new
19
+ ISO7816::APDU::DELETE_FILE.new
20
+ ISO7816::APDU::DISABLE_VERIFICATION_REQUIREMENT.new
21
+ ISO7816::APDU::ENABLE_VERIFICATION_REQUIREMENT.new
22
+ ISO7816::APDU::ENVELOPE.new
23
+ ISO7816::APDU::ERASE_BINARY.new
24
+ ISO7816::APDU::ERASE_RECORD.new
25
+ ISO7816::APDU::EXTERNAL_AUTHENTICATE.new
26
+ ISO7816::APDU::GENERAL_AUTHENTICATE.new
27
+ ISO7816::APDU::GENERATE_ASYMMETRIC_KEY_PAIR.new
28
+ ISO7816::APDU::GET_CHALLENGE.new
29
+ ISO7816::APDU::GET_DATA.new
30
+ ISO7816::APDU::GET_RESPONSE.new
31
+ ISO7816::APDU::INTERNAL_AUTHENTICATE.new
32
+ ISO7816::APDU::MANAGE_CHANNEL.new
33
+ ISO7816::APDU::MANAGE_SECURITY_ENVIRONMENT.new
34
+ ISO7816::APDU::PERFORM_SCQL_OPERATION.new
35
+ ISO7816::APDU::PERFORM_SECURITY_OPERATION.new
36
+ ISO7816::APDU::PERFORM_TRANSACTION_OPERATION.new
37
+ ISO7816::APDU::PERFORM_USER_OPERATION.new
38
+ ISO7816::APDU::PUT_DATA.new
39
+ ISO7816::APDU::READ_BINARY.new
40
+ ISO7816::APDU::READ_RECORD.new
41
+ ISO7816::APDU::RESET_RETRY_COUNTER.new
42
+ ISO7816::APDU::SEARCH_BINARY.new
43
+ ISO7816::APDU::SEARCH_RECORD.new
44
+ ISO7816::APDU::SELECT.new
45
+ ISO7816::APDU::TERMINATE_CARD_USAGE.new
46
+ ISO7816::APDU::TERMINATE_DF.new
47
+ ISO7816::APDU::TERMINATE_EF.new
48
+ ISO7816::APDU::UPDATE_BINARY.new
49
+ ISO7816::APDU::UPDATE_RECORD.new
50
+ ISO7816::APDU::VERIFY.new
51
+ ISO7816::APDU::WRITE_BINARY.new
52
+ ISO7816::APDU::WRITE_RECORD.new
53
+ assert true
54
+ end
55
+
56
+ def test_proper_ins
57
+ test_data = [
58
+ [ISO7816::APDU::ACTIVATE_FILE, "\x44"],
59
+ [ISO7816::APDU::APPEND_RECORD, "\xE2"],
60
+ [ISO7816::APDU::CHANGE_REFERENCE_DATA, "\x24"],
61
+ [ISO7816::APDU::CREATE_FILE, "\xE0"],
62
+ [ISO7816::APDU::DEACTIVATE_FILE, "\x04"],
63
+ [ISO7816::APDU::DELETE_FILE, "\xE4"],
64
+ [ISO7816::APDU::DISABLE_VERIFICATION_REQUIREMENT, "\x26"],
65
+ [ISO7816::APDU::ENABLE_VERIFICATION_REQUIREMENT, "\x28"],
66
+ [ISO7816::APDU::ENVELOPE, "\xC2"],
67
+ [ISO7816::APDU::ERASE_BINARY, "\x0E"],
68
+ [ISO7816::APDU::ERASE_RECORD, "\x0C"],
69
+ [ISO7816::APDU::EXTERNAL_AUTHENTICATE, "\x82"],
70
+ [ISO7816::APDU::GENERAL_AUTHENTICATE, "\x86"],
71
+ [ISO7816::APDU::GENERATE_ASYMMETRIC_KEY_PAIR, "\x46"],
72
+ [ISO7816::APDU::GET_CHALLENGE, "\x84"],
73
+ [ISO7816::APDU::GET_DATA, "\xCA"],
74
+ [ISO7816::APDU::GET_RESPONSE, "\xC0"],
75
+ [ISO7816::APDU::INTERNAL_AUTHENTICATE, "\x88"],
76
+ [ISO7816::APDU::MANAGE_CHANNEL, "\x70"],
77
+ [ISO7816::APDU::MANAGE_SECURITY_ENVIRONMENT, "\x22"],
78
+ [ISO7816::APDU::PERFORM_SCQL_OPERATION, "\x10"],
79
+ [ISO7816::APDU::PERFORM_SECURITY_OPERATION, "\x2A"],
80
+ [ISO7816::APDU::PERFORM_TRANSACTION_OPERATION, "\x12"],
81
+ [ISO7816::APDU::PERFORM_USER_OPERATION, "\x14"],
82
+ [ISO7816::APDU::PUT_DATA, "\xDA"],
83
+ [ISO7816::APDU::READ_BINARY, "\xB0"],
84
+ [ISO7816::APDU::READ_RECORD, "\xB2"],
85
+ [ISO7816::APDU::RESET_RETRY_COUNTER, "\x2C"],
86
+ [ISO7816::APDU::SEARCH_BINARY, "\xA0"],
87
+ [ISO7816::APDU::SEARCH_RECORD, "\xA2"],
88
+ [ISO7816::APDU::SELECT, "\xA4"],
89
+ [ISO7816::APDU::TERMINATE_CARD_USAGE, "\xFE"],
90
+ [ISO7816::APDU::TERMINATE_DF, "\xE6"],
91
+ [ISO7816::APDU::TERMINATE_EF, "\xE8"],
92
+ [ISO7816::APDU::UPDATE_BINARY, "\xD6"],
93
+ [ISO7816::APDU::UPDATE_RECORD, "\xDC"],
94
+ [ISO7816::APDU::VERIFY, "\x20"],
95
+ [ISO7816::APDU::WRITE_BINARY, "\xD0"],
96
+ [ISO7816::APDU::WRITE_RECORD, "\xD2"]
97
+ ]
98
+
99
+ test_data.each {|ins_|
100
+ clazz, ins = ins_
101
+ assert_equal ins, clazz._ins
102
+ assert_equal "\x00", clazz._cla, clazz
103
+ apdu = clazz.new
104
+ assert_equal ins, apdu.ins
105
+ assert_equal "\x00", apdu.cla
106
+ }
107
+ end
108
+ end
@@ -0,0 +1,30 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/iso7816'
3
+
4
+ class TestUtils < Test::Unit::TestCase
5
+
6
+ def setup
7
+ end
8
+
9
+ def s2b str
10
+ ISO7816.s2b str
11
+ end
12
+
13
+ def tests2b
14
+ str = "aa aa aa aa aa"
15
+ assert_equal "\xaa\xaa\xaa\xaa\xaa", ISO7816.s2b(str)
16
+
17
+ str = str.upcase
18
+ assert_equal "\xaa\xaa\xaa\xaa\xaa", ISO7816.s2b(str)
19
+
20
+ str.gsub! /\s+/, ""
21
+ assert_equal "\xaa\xaa\xaa\xaa\xaa", ISO7816.s2b(str)
22
+ end
23
+
24
+ def testb2s
25
+ str = "\xaa\xaa\xaa\xaa"
26
+ assert_equal "aaaaaaaa", ISO7816.b2s(str)
27
+
28
+ end
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iso7816
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Tim Becker
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-26 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: hexy
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: tlv
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: smartcard
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ description: " Utilities to provided ISO 7816 smartcard functionality \n"
63
+ email: tim.becker@kuriositaet.de
64
+ executables: []
65
+
66
+ extensions: []
67
+
68
+ extra_rdoc_files: []
69
+
70
+ files:
71
+ - lib/7816/apdu.rb
72
+ - lib/7816/atr.rb
73
+ - lib/7816/card.rb
74
+ - lib/7816/iso_apdu.rb
75
+ - lib/7816/pcsc_helper.rb
76
+ - lib/7816.rb
77
+ - lib/emv/cps_apdu.rb
78
+ - lib/emv/crypto/crypto.rb
79
+ - lib/emv/data/cps_ini_update.rb
80
+ - lib/emv/emv.rb
81
+ - lib/emv/emv_apdu.rb
82
+ - lib/emv.rb
83
+ - lib/iso7816.rb
84
+ - lib/iso_7816.rb
85
+ - AUTHORS
86
+ - CHANGELOG
87
+ - COPYING
88
+ - LICENSE
89
+ - Rakefile
90
+ - README
91
+ - THANKS
92
+ - TODO
93
+ - test/apdu_resp_test.rb
94
+ - test/apdu_test.rb
95
+ - test/card_test.rb
96
+ - test/cps_test.rb
97
+ - test/crypto_test.rb
98
+ - test/emv_apdu_test.rb
99
+ - test/iso_apdu_test.rb
100
+ - test/util_test.rb
101
+ homepage: https://github.com/a2800276/7816
102
+ licenses: []
103
+
104
+ post_install_message:
105
+ rdoc_options: []
106
+
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ requirements:
128
+ - none
129
+ rubyforge_project:
130
+ rubygems_version: 1.8.6
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: "iso7816: ruby smartcard access"
134
+ test_files: []
135
+