smartcard 1.0.46 → 2.0.0
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.
- package/LICENSE +1 -1
- package/README.md +387 -0
- package/binding.gyp +45 -0
- package/lib/devices.js +251 -0
- package/lib/errors.js +72 -0
- package/lib/index.d.ts +247 -0
- package/lib/index.js +76 -14
- package/package.json +56 -39
- package/src/addon.cpp +54 -0
- package/src/async_workers.cpp +234 -0
- package/src/async_workers.h +100 -0
- package/src/pcsc_card.cpp +248 -0
- package/src/pcsc_card.h +41 -0
- package/src/pcsc_context.cpp +224 -0
- package/src/pcsc_context.h +32 -0
- package/src/pcsc_errors.h +49 -0
- package/src/pcsc_reader.cpp +89 -0
- package/src/pcsc_reader.h +39 -0
- package/src/platform/pcsc.h +36 -0
- package/src/reader_monitor.cpp +344 -0
- package/src/reader_monitor.h +57 -0
- package/.prettierrc +0 -3
- package/README.MD +0 -371
- package/babel.config.json +0 -3
- package/demo/device-activated-promise.js +0 -12
- package/demo/device-activated.js +0 -12
- package/demo/device-deactivated-promise.js +0 -12
- package/demo/device-deactivated.js +0 -12
- package/demo/smartcard-demo.js +0 -100
- package/lib/Card.js +0 -129
- package/lib/CommandApdu.js +0 -109
- package/lib/Device.js +0 -138
- package/lib/Devices.js +0 -134
- package/lib/Iso7816Application.js +0 -169
- package/lib/ResponseApdu.js +0 -129
package/lib/CommandApdu.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
var _events = require("events");
|
|
9
|
-
|
|
10
|
-
var _hexify = _interopRequireDefault(require("hexify"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
-
|
|
16
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
17
|
-
|
|
18
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
19
|
-
|
|
20
|
-
/*
|
|
21
|
-
CASE COMMAND RESPONSE
|
|
22
|
-
1 NO DATA NO DATA
|
|
23
|
-
2 DATA NO DATA
|
|
24
|
-
3 NO DATA DATA
|
|
25
|
-
4 DATA DATA
|
|
26
|
-
*/
|
|
27
|
-
var CommandApdu = /*#__PURE__*/function () {
|
|
28
|
-
function CommandApdu(obj) {
|
|
29
|
-
_classCallCheck(this, CommandApdu);
|
|
30
|
-
|
|
31
|
-
if (obj.bytes) {
|
|
32
|
-
this.bytes = obj.bytes;
|
|
33
|
-
} else {
|
|
34
|
-
var size = obj.size;
|
|
35
|
-
var cla = obj.cla;
|
|
36
|
-
var ins = obj.ins;
|
|
37
|
-
var p1 = obj.p1;
|
|
38
|
-
var p2 = obj.p2;
|
|
39
|
-
var data = obj.data;
|
|
40
|
-
var le = obj.le || 0;
|
|
41
|
-
var lc; // case 1
|
|
42
|
-
|
|
43
|
-
if (!size && !data && !le) {
|
|
44
|
-
//le = -1;
|
|
45
|
-
//console.info('case 1');
|
|
46
|
-
size = 4;
|
|
47
|
-
} // case 2
|
|
48
|
-
else if (!size && !data) {
|
|
49
|
-
//console.info('case 2');
|
|
50
|
-
size = 4 + 2;
|
|
51
|
-
} // case 3
|
|
52
|
-
else if (!size && !le) {
|
|
53
|
-
//console.info('case 3');
|
|
54
|
-
size = data.length + 5 + 4; //le = -1;
|
|
55
|
-
} // case 4
|
|
56
|
-
else if (!size) {
|
|
57
|
-
//console.info('case 4');
|
|
58
|
-
size = data.length + 5 + 4;
|
|
59
|
-
} // set data
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (data) {
|
|
63
|
-
lc = data.length;
|
|
64
|
-
} else {//lc = 0;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.bytes = [];
|
|
68
|
-
this.bytes.push(cla);
|
|
69
|
-
this.bytes.push(ins);
|
|
70
|
-
this.bytes.push(p1);
|
|
71
|
-
this.bytes.push(p2);
|
|
72
|
-
|
|
73
|
-
if (data) {
|
|
74
|
-
this.bytes.push(lc);
|
|
75
|
-
this.bytes = this.bytes.concat(data);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this.bytes.push(le);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
_createClass(CommandApdu, [{
|
|
83
|
-
key: "toString",
|
|
84
|
-
value: function toString() {
|
|
85
|
-
return _hexify["default"].toHexString(this.bytes);
|
|
86
|
-
}
|
|
87
|
-
}, {
|
|
88
|
-
key: "toByteArray",
|
|
89
|
-
value: function toByteArray() {
|
|
90
|
-
return this.bytes;
|
|
91
|
-
}
|
|
92
|
-
}, {
|
|
93
|
-
key: "toBuffer",
|
|
94
|
-
value: function toBuffer() {
|
|
95
|
-
return new Buffer(this.bytes);
|
|
96
|
-
}
|
|
97
|
-
}, {
|
|
98
|
-
key: "setLe",
|
|
99
|
-
value: function setLe(le) {
|
|
100
|
-
this.bytes.pop();
|
|
101
|
-
this.bytes.push(le);
|
|
102
|
-
}
|
|
103
|
-
}]);
|
|
104
|
-
|
|
105
|
-
return CommandApdu;
|
|
106
|
-
}();
|
|
107
|
-
|
|
108
|
-
var _default = CommandApdu;
|
|
109
|
-
exports["default"] = _default;
|
package/lib/Device.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _Card = _interopRequireDefault(require("./Card"));
|
|
11
|
-
|
|
12
|
-
var _events = require("events");
|
|
13
|
-
|
|
14
|
-
var _pino = _interopRequireDefault(require("pino"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
|
-
|
|
18
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
19
|
-
|
|
20
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
21
|
-
|
|
22
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
23
|
-
|
|
24
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
25
|
-
|
|
26
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
27
|
-
|
|
28
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
29
|
-
|
|
30
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
31
|
-
|
|
32
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
33
|
-
|
|
34
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
35
|
-
|
|
36
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
37
|
-
|
|
38
|
-
var logger = (0, _pino["default"])({
|
|
39
|
-
name: 'Device'
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
var Device = /*#__PURE__*/function (_EventEmitter) {
|
|
43
|
-
_inherits(Device, _EventEmitter);
|
|
44
|
-
|
|
45
|
-
var _super = _createSuper(Device);
|
|
46
|
-
|
|
47
|
-
function Device(reader) {
|
|
48
|
-
var _this;
|
|
49
|
-
|
|
50
|
-
_classCallCheck(this, Device);
|
|
51
|
-
|
|
52
|
-
_this = _super.call(this);
|
|
53
|
-
logger.debug("new Device(".concat(reader, ")"));
|
|
54
|
-
_this.reader = reader;
|
|
55
|
-
_this.name = reader.name;
|
|
56
|
-
_this.card = null;
|
|
57
|
-
|
|
58
|
-
var isCardInserted = function isCardInserted(changes, reader, status) {
|
|
59
|
-
return changes & reader.SCARD_STATE_PRESENT && status.state & reader.SCARD_STATE_PRESENT;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
var isCardRemoved = function isCardRemoved(changes, reader, status) {
|
|
63
|
-
return changes & reader.SCARD_STATE_EMPTY && status.state & reader.SCARD_STATE_EMPTY;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
var cardInserted = function cardInserted(reader, status) {
|
|
67
|
-
reader.connect({
|
|
68
|
-
share_mode: 2
|
|
69
|
-
}, function (err, protocol) {
|
|
70
|
-
if (err) {
|
|
71
|
-
_this.emit('error', err);
|
|
72
|
-
} else {
|
|
73
|
-
_this.card = new _Card["default"](_assertThisInitialized(_this), status.atr, protocol);
|
|
74
|
-
|
|
75
|
-
_this.emit('card-inserted', {
|
|
76
|
-
device: _assertThisInitialized(_this),
|
|
77
|
-
card: _this.card
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
var cardRemoved = function cardRemoved(reader) {
|
|
84
|
-
var name = reader.name;
|
|
85
|
-
reader.disconnect(reader.SCARD_LEAVE_CARD, function (err) {
|
|
86
|
-
if (err) {
|
|
87
|
-
_this.emit('error', err);
|
|
88
|
-
} else {
|
|
89
|
-
_this.emit('card-removed', {
|
|
90
|
-
name: name,
|
|
91
|
-
card: _this.card
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
_this.card = null;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
reader.on('status', function (status) {
|
|
100
|
-
var changes = reader.state ^ status.state;
|
|
101
|
-
|
|
102
|
-
if (changes) {
|
|
103
|
-
if (isCardRemoved(changes, reader, status)) {
|
|
104
|
-
cardRemoved(reader);
|
|
105
|
-
} else if (isCardInserted(changes, reader, status)) {
|
|
106
|
-
cardInserted(reader, status);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
return _this;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
_createClass(Device, [{
|
|
114
|
-
key: "transmit",
|
|
115
|
-
value: function transmit(data, res_len, protocol, cb) {
|
|
116
|
-
try {
|
|
117
|
-
this.reader.transmit(data, res_len, protocol, cb);
|
|
118
|
-
} catch (err) {
|
|
119
|
-
logger.warn("transmit", err);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}, {
|
|
123
|
-
key: "getName",
|
|
124
|
-
value: function getName() {
|
|
125
|
-
return this.name;
|
|
126
|
-
}
|
|
127
|
-
}, {
|
|
128
|
-
key: "toString",
|
|
129
|
-
value: function toString() {
|
|
130
|
-
return "".concat(this.getName());
|
|
131
|
-
}
|
|
132
|
-
}]);
|
|
133
|
-
|
|
134
|
-
return Device;
|
|
135
|
-
}(_events.EventEmitter);
|
|
136
|
-
|
|
137
|
-
var _default = Device;
|
|
138
|
-
exports["default"] = _default;
|
package/lib/Devices.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
|
-
var _pino = _interopRequireDefault(require("pino"));
|
|
6
|
-
|
|
7
|
-
var _events = require("events");
|
|
8
|
-
|
|
9
|
-
var _Device = _interopRequireDefault(require("./Device"));
|
|
10
|
-
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
-
|
|
13
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
-
|
|
15
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
16
|
-
|
|
17
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
18
|
-
|
|
19
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
20
|
-
|
|
21
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
22
|
-
|
|
23
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
24
|
-
|
|
25
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
26
|
-
|
|
27
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
28
|
-
|
|
29
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
30
|
-
|
|
31
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
32
|
-
|
|
33
|
-
var pcsclite = require('@pokusew/pcsclite');
|
|
34
|
-
|
|
35
|
-
var logger = (0, _pino["default"])({
|
|
36
|
-
name: 'Devices'
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
var Devices = /*#__PURE__*/function (_EventEmitter) {
|
|
40
|
-
_inherits(Devices, _EventEmitter);
|
|
41
|
-
|
|
42
|
-
var _super = _createSuper(Devices);
|
|
43
|
-
|
|
44
|
-
function Devices() {
|
|
45
|
-
var _this;
|
|
46
|
-
|
|
47
|
-
_classCallCheck(this, Devices);
|
|
48
|
-
|
|
49
|
-
_this = _super.call(this);
|
|
50
|
-
logger.debug("new Devices()");
|
|
51
|
-
_this.pcsc = pcsclite();
|
|
52
|
-
_this.devices = {};
|
|
53
|
-
|
|
54
|
-
_this.pcsc.on('reader', function (reader) {
|
|
55
|
-
var device = new _Device["default"](reader);
|
|
56
|
-
_this.devices[reader.name] = device;
|
|
57
|
-
|
|
58
|
-
_this.emit('device-activated', {
|
|
59
|
-
device: device,
|
|
60
|
-
devices: _this.listDevices()
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
reader.on('end', function () {
|
|
64
|
-
delete _this.devices[reader.name];
|
|
65
|
-
|
|
66
|
-
_this.emit('device-deactivated', {
|
|
67
|
-
device: device,
|
|
68
|
-
devices: _this.listDevices()
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
reader.on('error', function (error) {
|
|
72
|
-
_this.emit('error', {
|
|
73
|
-
reader: reader,
|
|
74
|
-
error: error
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
_this.pcsc.on('error', function (error) {
|
|
80
|
-
_this.emit('error', {
|
|
81
|
-
error: error
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
return _this;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
_createClass(Devices, [{
|
|
89
|
-
key: "onActivated",
|
|
90
|
-
value: function onActivated() {
|
|
91
|
-
var _this2 = this;
|
|
92
|
-
|
|
93
|
-
return new Promise(function (resolve, reject) {
|
|
94
|
-
_this2.on('device-activated', function (event) {
|
|
95
|
-
return resolve(event);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}, {
|
|
100
|
-
key: "onDeactivated",
|
|
101
|
-
value: function onDeactivated() {
|
|
102
|
-
var _this3 = this;
|
|
103
|
-
|
|
104
|
-
return new Promise(function (resolve, reject) {
|
|
105
|
-
_this3.on('device-deactivated', function (event) {
|
|
106
|
-
return resolve(event);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}, {
|
|
111
|
-
key: "listDevices",
|
|
112
|
-
value: function listDevices() {
|
|
113
|
-
var _this4 = this;
|
|
114
|
-
|
|
115
|
-
return Object.keys(this.devices).map(function (k) {
|
|
116
|
-
return _this4.devices[k];
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}, {
|
|
120
|
-
key: "lookup",
|
|
121
|
-
value: function lookup(name) {
|
|
122
|
-
return this.devices[name];
|
|
123
|
-
}
|
|
124
|
-
}, {
|
|
125
|
-
key: "toString",
|
|
126
|
-
value: function toString() {
|
|
127
|
-
return "Devices('".concat(this.listDevices(), "')");
|
|
128
|
-
}
|
|
129
|
-
}]);
|
|
130
|
-
|
|
131
|
-
return Devices;
|
|
132
|
-
}(_events.EventEmitter);
|
|
133
|
-
|
|
134
|
-
module.exports = Devices;
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
|
-
var _events = require("events");
|
|
6
|
-
|
|
7
|
-
var _hexify = _interopRequireDefault(require("hexify"));
|
|
8
|
-
|
|
9
|
-
var _CommandApdu = _interopRequireDefault(require("./CommandApdu"));
|
|
10
|
-
|
|
11
|
-
var _ResponseApdu = _interopRequireDefault(require("./ResponseApdu"));
|
|
12
|
-
|
|
13
|
-
var _pino = _interopRequireDefault(require("pino"));
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
16
|
-
|
|
17
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
18
|
-
|
|
19
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
20
|
-
|
|
21
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
22
|
-
|
|
23
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
24
|
-
|
|
25
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
26
|
-
|
|
27
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
28
|
-
|
|
29
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
30
|
-
|
|
31
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
32
|
-
|
|
33
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
34
|
-
|
|
35
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
36
|
-
|
|
37
|
-
var logger = (0, _pino["default"])({
|
|
38
|
-
name: 'Iso7816Application'
|
|
39
|
-
});
|
|
40
|
-
var ins = {
|
|
41
|
-
APPEND_RECORD: 0xe2,
|
|
42
|
-
ENVELOPE: 0xc2,
|
|
43
|
-
ERASE_BINARY: 0x0e,
|
|
44
|
-
EXTERNAL_AUTHENTICATE: 0x82,
|
|
45
|
-
GET_CHALLENGE: 0x84,
|
|
46
|
-
GET_DATA: 0xca,
|
|
47
|
-
GET_RESPONSE: 0xc0,
|
|
48
|
-
INTERNAL_AUTHENTICATE: 0x88,
|
|
49
|
-
MANAGE_CHANNEL: 0x70,
|
|
50
|
-
PUT_DATA: 0xda,
|
|
51
|
-
READ_BINARY: 0xb0,
|
|
52
|
-
READ_RECORD: 0xb2,
|
|
53
|
-
SELECT_FILE: 0xa4,
|
|
54
|
-
UPDATE_BINARY: 0xd6,
|
|
55
|
-
UPDATE_RECORD: 0xdc,
|
|
56
|
-
VERIFY: 0x20,
|
|
57
|
-
WRITE_BINARY: 0xd0,
|
|
58
|
-
WRITE_RECORD: 0xd2
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
var Iso7816Application = /*#__PURE__*/function (_EventEmitter) {
|
|
62
|
-
_inherits(Iso7816Application, _EventEmitter);
|
|
63
|
-
|
|
64
|
-
var _super = _createSuper(Iso7816Application);
|
|
65
|
-
|
|
66
|
-
function Iso7816Application(card) {
|
|
67
|
-
var _this;
|
|
68
|
-
|
|
69
|
-
_classCallCheck(this, Iso7816Application);
|
|
70
|
-
|
|
71
|
-
_this = _super.call(this);
|
|
72
|
-
_this.card = card;
|
|
73
|
-
return _this;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
_createClass(Iso7816Application, [{
|
|
77
|
-
key: "issueCommand",
|
|
78
|
-
value: function issueCommand(commandApdu) {
|
|
79
|
-
var _this2 = this;
|
|
80
|
-
|
|
81
|
-
logger.debug("issueCommand '".concat(commandApdu, "' "));
|
|
82
|
-
return this.card.issueCommand(commandApdu).then(function (resp) {
|
|
83
|
-
var response = new _ResponseApdu["default"](resp);
|
|
84
|
-
logger.debug("status code '".concat(response.statusCode, "'"));
|
|
85
|
-
|
|
86
|
-
if (response.hasMoreBytesAvailable()) {
|
|
87
|
-
logger.debug("has '".concat(response.data.length, "' more bytes available"));
|
|
88
|
-
return _this2.getResponse(response.numberOfBytesAvailable()).then(function (resp) {
|
|
89
|
-
var responseApdu = new _ResponseApdu["default"](resp);
|
|
90
|
-
return new _ResponseApdu["default"](response.getDataOnly() + responseApdu.data);
|
|
91
|
-
});
|
|
92
|
-
} else if (response.isWrongLength()) {
|
|
93
|
-
logger.debug("'le' should be '".concat(response.correctLength(), "' bytes"));
|
|
94
|
-
commandApdu.setLe(response.correctLength());
|
|
95
|
-
return _this2.issueCommand(commandApdu).then(function (resp) {
|
|
96
|
-
var responseApdu = new _ResponseApdu["default"](resp);
|
|
97
|
-
return new _ResponseApdu["default"](response.getDataOnly() + responseApdu.data);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
logger.debug("return response '".concat(response, "' "));
|
|
102
|
-
return response;
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}, {
|
|
106
|
-
key: "selectFile",
|
|
107
|
-
value: function selectFile(bytes, p1, p2) {
|
|
108
|
-
var _this3 = this;
|
|
109
|
-
|
|
110
|
-
logger.debug("selectFile, file='".concat(bytes, "'"));
|
|
111
|
-
var commandApdu = new _CommandApdu["default"]({
|
|
112
|
-
cla: 0x00,
|
|
113
|
-
ins: ins.SELECT_FILE,
|
|
114
|
-
p1: p1 || 0x04,
|
|
115
|
-
p2: p2 || 0x00,
|
|
116
|
-
data: bytes
|
|
117
|
-
});
|
|
118
|
-
return this.issueCommand(commandApdu).then(function (response) {
|
|
119
|
-
if (response.isOk()) {
|
|
120
|
-
_this3.emit('application-selected', {
|
|
121
|
-
application: _hexify["default"].toHexString(bytes)
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return response;
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}, {
|
|
129
|
-
key: "getResponse",
|
|
130
|
-
value: function getResponse(length) {
|
|
131
|
-
logger.debug("getResponse, length='".concat(length, "'"));
|
|
132
|
-
return this.issueCommand(new _CommandApdu["default"]({
|
|
133
|
-
cla: 0x00,
|
|
134
|
-
ins: ins.GET_RESPONSE,
|
|
135
|
-
p1: 0x00,
|
|
136
|
-
p2: 0x00,
|
|
137
|
-
le: length
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
140
|
-
}, {
|
|
141
|
-
key: "readRecord",
|
|
142
|
-
value: function readRecord(sfi, record) {
|
|
143
|
-
logger.debug("readRecord, sfi='".concat(sfi, "', record=").concat(record));
|
|
144
|
-
return this.issueCommand(new _CommandApdu["default"]({
|
|
145
|
-
cla: 0x00,
|
|
146
|
-
ins: ins.READ_RECORD,
|
|
147
|
-
p1: record,
|
|
148
|
-
p2: (sfi << 3) + 4,
|
|
149
|
-
le: 0
|
|
150
|
-
}));
|
|
151
|
-
}
|
|
152
|
-
}, {
|
|
153
|
-
key: "getData",
|
|
154
|
-
value: function getData(p1, p2) {
|
|
155
|
-
logger.debug("getData, p1='".concat(p1, "', p2=").concat(p2));
|
|
156
|
-
return this.issueCommand(new _CommandApdu["default"]({
|
|
157
|
-
cla: 0x00,
|
|
158
|
-
ins: ins.GET_DATA,
|
|
159
|
-
p1: p1,
|
|
160
|
-
p2: p2,
|
|
161
|
-
le: 0
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
}]);
|
|
165
|
-
|
|
166
|
-
return Iso7816Application;
|
|
167
|
-
}(_events.EventEmitter);
|
|
168
|
-
|
|
169
|
-
module.exports = Iso7816Application;
|
package/lib/ResponseApdu.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
-
|
|
10
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
11
|
-
|
|
12
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
13
|
-
|
|
14
|
-
var statusCodes = {
|
|
15
|
-
'^9000$': 'Normal processing',
|
|
16
|
-
'^61(.{2})$': 'Normal processing, (sw2 indicates the number of response bytes still available)',
|
|
17
|
-
'^62(.{2})$': 'Warning processing',
|
|
18
|
-
'^6200$': 'no info',
|
|
19
|
-
'^6281$': 'Part of return data may be corrupted',
|
|
20
|
-
'^6282$': 'end of file/record reached before reading le bytes',
|
|
21
|
-
'^6283$': 'ret data may contain structural info',
|
|
22
|
-
'^6284$': 'selected file is invalidated',
|
|
23
|
-
'^6285$': 'file control info not in required format',
|
|
24
|
-
'^6286$': 'unsuccessful writing',
|
|
25
|
-
'^63(.{2})$': 'Warning processing',
|
|
26
|
-
'^6300$': 'no info',
|
|
27
|
-
'^6381$': 'last write filled up file',
|
|
28
|
-
'^6382$': 'execution successful after retry',
|
|
29
|
-
// c0 least significant nibble is a counter....
|
|
30
|
-
// .. ..valued from 0 to 15
|
|
31
|
-
// cf
|
|
32
|
-
'^64(.{2})$': 'Execution error',
|
|
33
|
-
'^65(.{2})$': 'Execution error',
|
|
34
|
-
'^6500$': 'no info',
|
|
35
|
-
'^6581$': 'memory failure',
|
|
36
|
-
'^66(.{2})$': 'Reserved for future use',
|
|
37
|
-
'^6700$': 'Wrong length',
|
|
38
|
-
'^68(.{2})$': 'Checking error: functions in CLA not supported (see sw2)',
|
|
39
|
-
'^6800$': 'no info',
|
|
40
|
-
'^6881$': 'logical channel not supported',
|
|
41
|
-
'^6882$': 'secure messaging not supported',
|
|
42
|
-
'^69(.{2})$': 'Checking error: command not allowed (see sw2)',
|
|
43
|
-
'^6a(.{2})$': 'Checking error: wrong parameters (p1 or p2) (see sw2)',
|
|
44
|
-
'^6b(.{2})$': 'Checking error: wrong parameters',
|
|
45
|
-
'^6c(.{2})$': 'Checking error: wrong length (sw2 indicates correct length for le)',
|
|
46
|
-
'^6d(.{2})$': 'Checking error: wrong ins',
|
|
47
|
-
'^6e(.{2})$': 'Checking error: class not supported',
|
|
48
|
-
'^6f(.{2})$': 'Checking error: no precise diagnosis'
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
var ResponseApdu = /*#__PURE__*/function () {
|
|
52
|
-
function ResponseApdu(buffer) {
|
|
53
|
-
_classCallCheck(this, ResponseApdu);
|
|
54
|
-
|
|
55
|
-
this.buffer = buffer;
|
|
56
|
-
this.data = buffer.toString('hex');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
_createClass(ResponseApdu, [{
|
|
60
|
-
key: "meaning",
|
|
61
|
-
value: function meaning() {
|
|
62
|
-
var statusCode = this.getStatusCode();
|
|
63
|
-
|
|
64
|
-
for (var prop in statusCodes) {
|
|
65
|
-
if (statusCodes.hasOwnProperty(prop)) {
|
|
66
|
-
var result = statusCodes[prop];
|
|
67
|
-
|
|
68
|
-
if (statusCode.match(prop)) {
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return 'Unknown';
|
|
75
|
-
}
|
|
76
|
-
}, {
|
|
77
|
-
key: "getDataOnly",
|
|
78
|
-
value: function getDataOnly() {
|
|
79
|
-
return this.data.substr(0, this.data.length - 4);
|
|
80
|
-
}
|
|
81
|
-
}, {
|
|
82
|
-
key: "getStatusCode",
|
|
83
|
-
value: function getStatusCode() {
|
|
84
|
-
return this.data.substr(-4);
|
|
85
|
-
}
|
|
86
|
-
}, {
|
|
87
|
-
key: "isOk",
|
|
88
|
-
value: function isOk() {
|
|
89
|
-
return this.getStatusCode() === '9000';
|
|
90
|
-
}
|
|
91
|
-
}, {
|
|
92
|
-
key: "buffer",
|
|
93
|
-
value: function buffer() {
|
|
94
|
-
return this.buffer;
|
|
95
|
-
}
|
|
96
|
-
}, {
|
|
97
|
-
key: "hasMoreBytesAvailable",
|
|
98
|
-
value: function hasMoreBytesAvailable() {
|
|
99
|
-
return this.data.substr(-4, 2) === '61';
|
|
100
|
-
}
|
|
101
|
-
}, {
|
|
102
|
-
key: "numberOfBytesAvailable",
|
|
103
|
-
value: function numberOfBytesAvailable() {
|
|
104
|
-
var hexLength = this.data.substr(-2, 2);
|
|
105
|
-
return parseInt(hexLength, 16);
|
|
106
|
-
}
|
|
107
|
-
}, {
|
|
108
|
-
key: "isWrongLength",
|
|
109
|
-
value: function isWrongLength() {
|
|
110
|
-
return this.data.substr(-4, 2) === '6c';
|
|
111
|
-
}
|
|
112
|
-
}, {
|
|
113
|
-
key: "correctLength",
|
|
114
|
-
value: function correctLength() {
|
|
115
|
-
var hexLength = this.data.substr(-2, 2);
|
|
116
|
-
return parseInt(hexLength, 16);
|
|
117
|
-
}
|
|
118
|
-
}, {
|
|
119
|
-
key: "toString",
|
|
120
|
-
value: function toString() {
|
|
121
|
-
return this.data.toString('hex');
|
|
122
|
-
}
|
|
123
|
-
}]);
|
|
124
|
-
|
|
125
|
-
return ResponseApdu;
|
|
126
|
-
}();
|
|
127
|
-
|
|
128
|
-
var _default = ResponseApdu;
|
|
129
|
-
exports["default"] = _default;
|