/usr/include/smartcardpp/CardBase.h is in libsmartcardpp-dev 0.3.0-0ubuntu8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | /*
* SMARTCARDPP
*
* This software is released under either the GNU Library General Public
* License (see LICENSE.LGPL) or the BSD License (see LICENSE.BSD).
*
* Note that the only valid version of the LGPL license as far as this
* project is concerned is the original GNU Library General Public License
* Version 2.1, February 1999
*
*/
#pragma once
#include "ManagerInterface.h"
#include <fstream>
using std::vector;
/// Exception class for smart card errors, keeps the SW1 SW2 codes
class CardError: public std::runtime_error {
const CardError operator=(const CardError &);
public:
const byte SW1,SW2;
std::string desc;
CardError(byte a,byte b);
virtual const char * what() const throw() { return desc.c_str();}
virtual ~CardError() throw(){};
};
/// Exception class thrown when unexpected or inconistent data is read from card
class CardDataError: public std::runtime_error {
public:
CardDataError( std::string p):runtime_error(p) {}
};
/// Exception class for authentication errors, like wrong PIN input etc.
class AuthError :public CardError {
public:
bool m_blocked;
bool m_badinput;
bool m_aborted;
AuthError(byte a,byte b) : CardError(a,b), m_blocked(false),m_badinput(false),m_aborted(false) {};
AuthError(byte a,byte b,bool block) : CardError(a,b), m_blocked(block),m_badinput(false),m_aborted(false) {};
AuthError(CardError _base) : CardError(_base) , m_blocked(false),m_badinput(false),m_aborted(false) {}
};
/// Represents basic ISO7816-4 smartcard
/** Represents a basic smart card, with basic ISO7816-4 command set implemented
Concrete instances of smart cards with appropriate services can be derived from it
or it can be used directly with basic command set. */
class CardBase
{
const CardBase operator=(const CardBase &);
protected:
/// File Control Info structure, parsed
struct FCI {
word fileID;
dword fileLength;
dword recCount;
dword recMaxLen;
} LPFCI;
ManagerInterface &mManager;
ConnectionBase *mConnection;
//std::ostream *mLogger;
/// provide CLA for card APDUs
virtual byte CLAByte() { return 0x00; }
/// helper to parse returned TLVs from card
ByteVec getTag(int identTag,int len,ByteVec &arr);
/// Parses a File Control Infromation block from select file commands
// FIXME: make this pure virtual
virtual FCI parseFCI(ByteVec fci);
/// Reads a record from record-based Elementary File
ByteVec readRecord(int numrec);
/// Read entire binary Elementary File
ByteVec readEF(unsigned int fileLen);
/// perform a basic APDU command. noreply indicates that command expects no reply data apart from status bytes
virtual ByteVec execute(ByteVec cmd, int apducase = 0);
/// perform pin entry command. this is only useful if card manager supports direct pin entry from reader like CTAPI
virtual void executePinEntry(ByteVec cmd);
/// perform pin change command. useful if card manager supports direct pin entry
virtual void executePinChange(ByteVec cmd, size_t oldPinLen,size_t newPinLen);
/* HACK. Implemented here because needed to be called on connect, which is in CardBase. */
/// possibly re-identify the card by sending GET VERSION APDU.
virtual void reIdentify() {};
public:
/// Selects the Master File on card
FCI selectMF(bool ignoreFCI = false);
/// Selects Data File given by two-byte fileID
int selectDF(int fileID,bool ignoreFCI = false);
/// Selects Elementary File given by two-byte fileID
FCI selectEF(int fileID,bool ignoreFCI = false);
/// Constructor, call connect() to connect card to a reader
CardBase(ManagerInterface &ref);
/// Constructor, connects the card instance to the reader at index idx
CardBase(ManagerInterface &ref,unsigned int idx);
/// Constructor, connects the card instance to existing connection
CardBase(ManagerInterface &ref,ConnectionBase *conn);
virtual ~CardBase(void);
/// connects the card instance to the reader at index idx
void connect(unsigned int idx);
/// virtual to be overridden by concrete cards, that can check for ATR or other card specific data
virtual bool isInReader(unsigned int idx) {UNUSED_ARG(idx);return false;}
//FIXME: this should be pure virtual
/// return card RSA key size in bits
virtual unsigned int getKeySize() { return 0; }
/// set logging stream. set to NULL for no logging ( default )
void setLogging(std::ostream *logStream);
/// sigh .. just a hack to reset card in some instances
void endTransaction();
/// check if the manager that we are connected to, supports secure PIN entry
bool hasSecurePinEntry();
//FILE *logFile;
};
|