00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
#ifndef RSACARD_H
00045
#define RSACARD_H
00046
00047
#include <chipcard/ctprocessorcard.h>
00048
#include <chipcard/ctmisc.h>
00049
#include <list>
00050
using namespace std;
00051
00052
00053 #define KEY_STATUS_ACTIVE 0x10
00054 #define KEY_STATUS_INACTIVE_CERT 0x0a
00055 #define KEY_STATUS_INACTIVE_FREE 0x08
00056 #define KEY_STATUS_INACTIVE_NEW 0x07
00057 #define KEY_STATUS_ACTIVE_NEW 0x02
00058 #define KEY_STATUS_ACTIVE_INCOMPLETE 0x01
00059 #define KEY_STATUS_ACTIVE_INILETTER 0x00
00060 #define KEY_STATUS_INTERNAL_UNUSED 0xff
00061
00062
00063
00068 class CHIPCARD_API RSACard:
public CTProcessorCard {
00069
public:
00070 class BankDescription {
00071
private:
00072
bool _chg;
00073
int _country;
00074 string _bankName;
00075 string _userId;
00076
char _service;
00077 string _address;
00078 string _addressSuffix;
00079 string _bankId;
00080 string _systemId;
00081
public:
00082
BankDescription();
00083
BankDescription(
const string &data);
00084 ~
BankDescription();
00085 int country()
const {
return _country;};
00086 void setCountry(
int i) { _country=i;};
00087 const string &bankName()
const {
return _bankName;};
00088 void setBankName(
const string &s) { _chg=
true; _bankName=s;};
00089 const string &userId()
const {
return _userId;};
00090 void setUserId(
const string &s) { _chg=
true; _userId=s;};
00091 char service()
const {
return _service;};
00092 void setService(
char c) { _chg=
true; _service=c;};
00093 const string &address()
const {
return _address;};
00094 void setAddress(
const string &s) { _chg=
true; _address=s;};
00095 const string &addressSuffix()
const {
return _addressSuffix;};
00096 void setAddressSuffix(
const string &s) { _chg=
true; _addressSuffix=s;};
00097 const string &bankId()
const {
return _bankId;};
00098 void setBankId(
const string &s) { _chg=
true; _bankId=s;};
00099 const string &systemId()
const {
return _systemId;};
00100 void setSystemId(
const string &s) { _chg=
true; _systemId=s;};
00101 string toString() const;
00102 bool changed()
const {
return _chg;};
00103 string dump();
00104 };
00105
00106 struct KeyLogStatus {
00107 unsigned maxEntries : 3;
00108 unsigned oldENfree : 1;
00109 unsigned entries : 3;
00110 unsigned oldDSfree : 1;
00111 };
00112
00113
public:
00114 class KeyDescriptor {
00115
private:
00116
bool _chg;
00117
unsigned int _status;
00118
bool _isSignKey;
00119
int _keynum;
00120
int _keyver;
00121
public:
00122
KeyDescriptor();
00123
KeyDescriptor(
unsigned int st,
00124
bool isSignKey,
00125
int keynum,
00126
int keyver);
00127
KeyDescriptor(
const string &data);
00128 ~
KeyDescriptor();
00129 string toString()
const;
00130 unsigned int status()
const {
return _status;};
00131 void setStatus(
unsigned int s) { _chg=
true; _status=s;};
00132 bool isSignKey()
const {
return _isSignKey;};
00133 void setIsSignKey(
bool b) { _chg=
true; _isSignKey=b;};
00134 int keyNumber()
const {
return _keynum;};
00135 void setKeyNumber(
int k) { _chg=
true; _keynum=k;};
00136 int keyVersion()
const {
return _keyver;};
00137 void setKeyVersion(
int k) { _chg=
true; _keyver=k;};
00138 bool changed()
const {
return _chg;};
00139 string dump();
00140 };
00141
00142
private:
00143 string _cmdReadFile;
00144 string _cmdUpdateBinary;
00145 string _cmdUpdateRecord;
00146 string _cmdGenerateKeyPair;
00147 string _cmdManageSE;
00148 string _cmdSelectPubKey;
00149 string _cmdSelectPrivKey;
00150 string _cmdPutHash;
00151 string _cmdSign;
00152 string _cmdVerify;
00153 string _cmdChallenge;
00154 string _cmdEncipher;
00155 string _cmdDecipher;
00156 string _cmdActivateKey;
00157 string _cmdVerifyPin;
00158 string _cmdSecureVerifyPin;
00159 string _cmdChangePin;
00160 string _cmdSecureChangePin;
00161 string _cmdPinStatus;
00162 string _firstPin;
00163
00164
00165
CTError _readFile(
unsigned short fid, string &data);
00166
CTError _getInitialPin(string &pin);
00167
CTError _openCard();
00171
int _findPublicKey(
unsigned int kid);
00172
CTError _manageSE(
int tmpl,
int kids,
int kidp,
int ar);
00173
int _getKeyPos_EF_LOG(
int kid);
00174
CTError _changePin(
int pinid,
const string &oldpin,
00175
const string &newpin);
00176
CTError _changePin(
int pinid);
00177
CTError _verifyPin(
int pinid,
const string &pin);
00178
CTError _verifyPin(
int pinid);
00179
00180
public:
00187 RSACard(
const CTCard &c);
00188
00189 ~RSACard();
00191
00210
virtual CTError reopenCard();
00211
00223
virtual CTError openCard();
00224
00232
virtual CTError closeCard(
bool force=
false);
00234
00245
virtual string
cardType();
00246
00255
virtual string
cardTypes();
00256
00266 const string &initialPin()
const {
return _firstPin;};
00267
00271 string cardNumber()
const {
return CTMisc::bin2hex(_firstPin);};
00273
00288
CTError verifyPin(
int kid,
const string &pin);
00289
00298
CTError changePin(
int kid,
00299
const string &oldpin,
00300
const string &newpin);
00301
00309
CTError changePin(
int kid);
00310
00318
CTError verifyPin(
int kid);
00319
00327
CTError pinStatus(
int &maxerr,
int &errleft);
00329
00330
00338
00344
CTError deleteKeyDescriptor(
int kid);
00345
00349
unsigned int readKeyStatus(
int kid);
00350
00354
CTError writeKeyStatus(
int kid,
unsigned int st);
00355
00359
CTError writeKeyDescriptor(
int kid,
const string &kd);
00360
00364 string readKeyDescriptor(
int kid);
00365
00370 string readPublicKey(
int kid);
00371
00376
CTError writePublicKey(
int kid,
const string &modulus);
00377
00383 string createKey(
int kid,
bool overwrite);
00384
00390
CTError activateKey(
int kid,
int num,
int ver);
00391
00395
bool isBankKey(
int kid);
00396
00400
bool isSignKey(
int kid);
00401
00406
int getKeyId(
int bank,
bool pub,
bool sign);
00407
00413 KeyLogStatus readKeyLogStatus();
00414
00418
CTError writeKeyLogStatus(KeyLogStatus st);
00420
00421
00429 BankDescription readBankDescription(
int idx);
00430
CTError writeBankDescription(
int idx,
const BankDescription &bd);
00431
CTError deleteBankDescription(
int idx);
00432
int findFreeBankDescription();
00434
00442 string getRandom(
int s);
00443 string sign(
int kid,
const string &data);
00444
CTError verify(
int kid,
const string &data,
00445
const string &signature);
00446 string encrypt(
int kid,
const string &data);
00447 string decrypt(
int kid,
const string &data);
00449
00459
unsigned int readSeq(
int bank);
00460
CTError writeSeq(
int bank,
unsigned int seq);
00462 };
00463
00464
00465
00466
00467
00468
00469
00470
#endif
00471
00472