SIde-Channel Analysis toolKit (SICAK)
Software toolkit for side-channel analysis
smartcard.h
Go to the documentation of this file.
1 /*
2 * SICAK - SIde-Channel Analysis toolKit
3 * Copyright (C) 2019 Petr Socha, FIT, CTU in Prague
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18 
29 #ifndef SMARTCARD_H
30 #define SMARTCARD_H
31 
32 #include <QObject>
33 #include <QtPlugin>
34 #include "chardevice.h"
35 #include "exceptions.hpp"
36 
37 #ifdef _WIN32
38 
39 #include <winscard.h>
40 
41 #else
42 
43 
44 #endif
45 
53 class SmartCard : public QObject, CharDevice {
54 
55  Q_OBJECT
56  Q_PLUGIN_METADATA(IID "cz.cvut.fit.Sicak.CharDeviceInterface/1.0" FILE "smartcard.json")
57  Q_INTERFACES(CharDevice)
58 
59 public:
60 
61  SmartCard();
62  virtual ~SmartCard() override;
63 
64  virtual QString getPluginName() override;
65  virtual QString getPluginInfo() override;
66 
68  virtual void init(const char * filename, int baudrate = 9600, int parity = 0, int stopBits = 1) override;
69  virtual void deInit() override;
70 
71  virtual QString queryDevices() override;
72 
74  virtual void setTimeout(int ms = 5000) override;
75 
77  virtual size_t send(const VectorType<uint8_t> & data) override;
79  virtual size_t receive(VectorType<uint8_t> & data) override;
80 
82  virtual size_t send(const VectorType<uint8_t> & data, size_t len) override;
84  virtual size_t receive(VectorType<uint8_t> & data, size_t len) override;
85 
87  virtual size_t send(const uint8_t * buffer, size_t len) override;
89  virtual size_t receive(uint8_t * buffer, size_t len) override;
90 
91 protected:
92 
93  bool m_initialized;
94 
95  #ifdef _WIN32
96 
97  SCARDCONTEXT m_context;
98  SCARDHANDLE m_card;
99 
100  #else
101 
102 
103  #endif
104 
105  Vector<uint8_t> m_recvBuf;
106  size_t m_recvBufLen;
107 
108 };
109 
110 #endif /* SMARTCARD_H */
111 
virtual QString queryDevices() override
Query available devices/filenames.
Definition: smartcard.cpp:172
virtual size_t receive(VectorType< uint8_t > &data) override
Response to the previously sent APDU message is stored in data, including status word.
Definition: smartcard.cpp:321
virtual QString getPluginInfo() override
Plugin info.
Definition: smartcard.cpp:45
This header file contains exceptions.
Character device QT plugin interface.
Definition: chardevice.h:42
virtual void deInit() override
Deinitialize the plugin.
Definition: smartcard.cpp:150
Character device plugin interface for use e.g. in meas.
virtual QString getPluginName() override
Plugin name.
Definition: smartcard.cpp:41
SmartCard Win32 SICAK CharDevice plugin.
Definition: smartcard.h:53
virtual void init(const char *filename, int baudrate=9600, int parity=0, int stopBits=1) override
filename is card reader ID, other params are ignored
Definition: smartcard.cpp:49
virtual void setTimeout(int ms=5000) override
setting timeout is not supported, no-op
Definition: smartcard.cpp:228
virtual size_t send(const VectorType< uint8_t > &data) override
The Vector/buffer must contain a valid APDU message. Given the SmartCard nature, the function blocks ...
Definition: smartcard.cpp:281