Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

rsacard.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  $RCSfile: rsacard.h,v $
00003  -------------------
00004  cvs         : $Id: rsacard.h,v 1.14 2003/05/07 22:27:22 aquamaniac Exp $
00005  begin       : Sat Dec 14 2002
00006  copyright   : (C) 2002 by Martin Preuss
00007  email       : martin@libchipcard.de
00008 
00009  ***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00024  *   MA  02111-1307  USA                                                   *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00028 
00029 
00030 /*___________________________________________________________________________
00031  *AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA*
00032  *                            W A R N I N G ! !                             *
00033  *                                                                          *
00034  * This class is under heavy development, it might render your card         *
00035  * useless !!                                                               *
00036  * For now this class implements all methods I will need to add support for *
00037  * this previously unsupported card to OpenHBCI.                            *
00038  *                                                                          *
00039  * YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY*
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 

Generated on Fri Dec 3 23:10:24 2004 for libchipcard by  doxygen 1.3.9.1