martinpaljak / esteid.js

APDU interface of EstEID cards in JavaScript
MIT License
16 stars 2 forks source link

decrypt function is missing PIN promise/check #4

Open martinl opened 7 years ago

martinl commented 7 years ago

Here is a patch, should I create a pull request?

--- ../esteid-dev/esteid.js    2017-04-29 15:46:20.000000000 +0300
+++ esteid.js   2017-04-27 10:59:02.000000000 +0300
@@ -242,8 +242,16 @@
             header[0] = chunks.length === 0 ? 0x00 : 0x10
             header[4] = chunk.length
             var cmd = Buffer.concat([header, chunk, Buffer.from([0x00])])
-            apdu.check(transmit(cmd)).then(function (r) {
-              if (chunks.length === 0) { return resolve(apdu.data(r)) } else { return decr() }
+            // verify PIN1 and decrypt
+            return eid.verify(eid.PIN1, pin).then(function () {
+              apdu.check(transmit(cmd)).then(function (r) {
+                if (chunks.length === 0) {
+                  return resolve(apdu.data(r))
+                }
+                else {
+                  return decr()
+                }
+              })
             }).catch(function (reason) {
               console.log('Decryption failed')
               reject(reason)
martinpaljak commented 7 years ago

Indeed. Please do!