]> www.vanbest.org Git - sasc-ng.git/commitdiff
smartcard: restructure card data loader
authorleslie <unknown>
Wed, 25 Feb 2009 09:42:57 +0000 (17:42 +0800)
committerleslie <unknown>
Wed, 25 Feb 2009 09:42:57 +0000 (17:42 +0800)
sc.c
smartcard.c
smartcard.h
systems/sc-cryptoworks/sc-cryptoworks.c
systems/sc-irdeto/sc-irdeto.c
systems/sc-nagra/sc-nagra.c
systems/sc-videoguard2/sc-videoguard2.c

diff --git a/sc.c b/sc.c
index 4b3d9895c284f79b313a0ce08f3212c4cb1150f0..0a5f03761a0b94d736a89834b5ce1a4faf7d7be3 100644 (file)
--- a/sc.c
+++ b/sc.c
@@ -1008,7 +1008,7 @@ bool cScSetup::Ignore(unsigned short caid)
 bool cSoftCAM::Load(const char *cfgdir)
 {
   if(!Feature.KeyFile()) keys.Disable();
-  if(!Feature.SmartCard()) smartcards.Disable();
+  if(!Feature.SmartCard()) carddatas.Disable();
   cStructLoaders::Load(false);
   if(Feature.KeyFile() && keys.Count()<1)
     PRINTF(L_GEN_ERROR,"no keys loaded for softcam!");
@@ -1022,6 +1022,7 @@ void cSoftCAM::Shutdown(void)
   cStructLoaders::Save(true);
   cSystems::Clean();
   smartcards.Shutdown();
+  carddatas.SafeClear();
   keys.SafeClear();
 }
 
index 0f642bd248df6c1e68578d5919ce1d0dbdaaeb52..fa7f73df897a3c4d988830bfef02b6f3d8938710 100644 (file)
@@ -1093,6 +1093,38 @@ cSmartCardData::cSmartCardData(int Ident)
   ident=Ident;
 }
 
+// -- cSmartCardDatas ----------------------------------------------------------
+
+cSmartCardDatas carddatas;
+
+cSmartCardDatas::cSmartCardDatas(void)
+:cStructList<cSmartCardData>("smartcard data",DATAFILE,SL_MISSINGOK|SL_WATCH|SL_VERBOSE)
+{}
+
+cSmartCardData *cSmartCardDatas::Find(cSmartCardData *param)
+{
+  ListLock(false);
+  cSmartCardData *cd;
+  for(cd=First(); cd; cd=Next(cd))
+    if(cd->Ident()==param->Ident() && cd->Matches(param)) break;
+  ListUnlock();
+  return cd;
+}
+
+cStructItem *cSmartCardDatas::ParseLine(char *line)
+{
+  char *r=index(line,':');
+  if(r)
+    for(cSmartCardLink *scl=cSmartCards::first; scl; scl=scl->next)
+      if(!strncasecmp(scl->name,line,r-line)) {
+        cSmartCardData *scd=scl->CreateData();
+        if(scd && scd->Parse(r+1)) return scd;
+        delete scd;
+        break;
+        }
+  return 0;
+}
+
 // -- cSmartCardLink -----------------------------------------------------------
 
 cSmartCardLink::cSmartCardLink(const char *Name, int Id)
@@ -1111,7 +1143,6 @@ static const char *serModes[] = { 0,"8e2","8o2","8n2" };
 
 cSmartCards::cSmartCards(void)
 :cThread("SmartcardWatcher")
-,cStructList<cSmartCardData>("smartcard data",DATAFILE,SL_MISSINGOK|SL_WATCH|SL_VERBOSE)
 {
   for(int i=0 ; i<MAX_PORTS ; i++) ports[i].Serial=0;
   firstRun=true;
@@ -1144,7 +1175,6 @@ void cSmartCards::Shutdown(void)
       }
     }
   mutex.Unlock();
-  ListLock(true); Clear(); ListUnlock();
 }
 
 bool cSmartCards::AddPort(const char *devName, bool invCD, bool invRST, int clock)
@@ -1178,30 +1208,6 @@ bool cSmartCards::AddPort(const char *devName, bool invCD, bool invRST, int cloc
   return false;
 }
 
-cStructItem *cSmartCards::ParseLine(char *line)
-{
-  char *r=index(line,':');
-  if(r)
-    for(cSmartCardLink *scl=first; scl; scl=scl->next)
-      if(!strncasecmp(scl->name,line,r-line)) {
-        cSmartCardData *scd=scl->CreateData();
-        if(scd && scd->Parse(r+1)) return scd;
-        delete scd;
-        break;
-        }
-  return 0;
-}
-
-cSmartCardData *cSmartCards::FindCardData(cSmartCardData *param)
-{
-  ListLock(false);
-  cSmartCardData *cd;
-  for(cd=First(); cd; cd=Next(cd))
-    if(cd->ident==param->ident && cd->Matches(param)) break;
-  ListUnlock();
-  return cd;
-}
-
 bool cSmartCards::HaveCard(int id)
 {
   cMutexLock lock(&mutex);
index 838ab07cd59a9348a076567d098fa83f50d813f4..e7a9ed0c25f0e5b5a2a884457b8f8dceec26cef9 100644 (file)
@@ -140,7 +140,6 @@ public:
 // ----------------------------------------------------------------
 
 class cSmartCardData : public cStructItem {
-friend class cSmartCards;
 protected:
   int ident;
 public:
@@ -148,13 +147,25 @@ public:
   virtual ~cSmartCardData() {}
   virtual bool Parse(const char *line)=0;
   virtual bool Matches(cSmartCardData *cmp)=0;
+  int Ident(void) const { return ident; }
   };
 
 // ----------------------------------------------------------------
 
+class cSmartCardDatas : public cStructList<cSmartCardData> {
+protected:
+  virtual cStructItem *ParseLine(char *line);
+public:
+  cSmartCardDatas(void);
+  cSmartCardData *Find(cSmartCardData *param);
+  };
+
+extern cSmartCardDatas carddatas;
+
+// ----------------------------------------------------------------
+
 class cSmartCardLink {
-friend class cSmartCards;
-private:
+public:
   cSmartCardLink *next;
   const char *name;
   int id;
@@ -163,7 +174,6 @@ public:
   virtual ~cSmartCardLink() {}
   virtual cSmartCard *Create(void)=0;
   virtual cSmartCardData *CreateData(void) { return 0; }
-  int ID(void) { return id; }
   };
 
 // ----------------------------------------------------------------
@@ -178,8 +188,9 @@ struct Port {
   struct Atr Atr;
   };
 
-class cSmartCards : private cThread, public cStructList<cSmartCardData> {
+class cSmartCards : private cThread {
 friend class cSmartCardLink;
+friend class cSmartCardDatas;
 private:
   static cSmartCardLink *first;
   cMutex mutex;
@@ -195,7 +206,6 @@ private:
   void SetPort(struct Port *port, cSmartCard *sc, int id, bool dead);
 protected:
   virtual void Action(void);
-  virtual cStructItem *ParseLine(char *line);
 public:
   cSmartCards(void);
   void Shutdown(void);
@@ -203,7 +213,6 @@ public:
   bool HaveCard(int id);
   cSmartCard *LockCard(int id);
   void ReleaseCard(cSmartCard *sc);
-  cSmartCardData *FindCardData(cSmartCardData *param);
   // to be called ONLY from frontend thread!
   bool AddPort(const char *devName, bool invCD, bool invRST, int clock);
   void LaunchWatcher(void);
index 9f1688999a4b040a43ce6794e18be51aa25facf4..af38f162cde80d43ea45cfbab6642df58ab0ba2d 100644 (file)
@@ -304,7 +304,7 @@ bool cSmartCardCryptoworks::Init(void)
   if(ReadRecord(buff,0x9E)>=66) {
     HEXDUMP(L_SC_EXTRA,&buff[2],64,"card ISK");
     cSmartCardDataCryptoworks cd(dtIPK,Caid);
-    cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)smartcards.FindCardData(&cd);
+    cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)carddatas.Find(&cd);
     if(entry) {
       PRINTF(L_SC_EXTRA,"got IPK from smartcard.conf");
       if(rsa.RSA(&buff[2],&buff[2],64,exp,entry->key,false)>0) {
@@ -322,7 +322,7 @@ bool cSmartCardCryptoworks::Init(void)
     }
   if(!ucpkValid) {
     cSmartCardDataCryptoworks cd(dtUCPK,serial);
-    cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)smartcards.FindCardData(&cd);
+    cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)carddatas.Find(&cd);
     if(entry) {
       BN_copy(ucpk,entry->key);
       ucpkValid=true;
@@ -418,7 +418,7 @@ bool cSmartCardCryptoworks::Init(void)
       }
     if(!pinOK) {
       cSmartCardDataCryptoworks cd(dtPIN,serial);
-      cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)smartcards.FindCardData(&cd);
+      cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)carddatas.Find(&cd);
       if(entry) {
         memcpy(&buff[2],entry->pin,4);
         pinOK=true;
index 2a316f568c76ac6af8d08c081c13a23e4b422348..628b90d5697205eee901ffefcd47ce0cd795b667 100644 (file)
@@ -462,10 +462,10 @@ bool cSmartCardIrdeto::Init(void)
   cSmartCardDataIrdeto *entry=0;
   if(!doPlain) {
     cSmartCardDataIrdeto cd(ACS,caId);
-    if(!(entry=(cSmartCardDataIrdeto *)smartcards.FindCardData(&cd))) {
+    if(!(entry=(cSmartCardDataIrdeto *)carddatas.Find(&cd))) {
       PRINTF(L_GEN_WARN,"didn't find Irdeto card specific certificate, falling back to default");
       cSmartCardDataIrdeto cd(-1,-1);
-      if(!(entry=(cSmartCardDataIrdeto *)smartcards.FindCardData(&cd))) {
+      if(!(entry=(cSmartCardDataIrdeto *)carddatas.Find(&cd))) {
         PRINTF(L_GEN_WARN,"didn't find default Irdeto certificate, please add one");
         if(ACS!=0x0384) return false;
         PRINTF(L_GEN_WARN,"trying pre-coded ACS 384 challenge. This mode is DEPRECATED. There ARE valid certificates for these cards available!");
index e0feeac0d52b2769ff628eb9df44d5e82c5fe6b2..ec16d096705be4cda7109df953c74408983f0084 100644 (file)
@@ -385,7 +385,7 @@ bool cSmartCardNagra::Init(void)
   bool sessOk=false;
   if(buff[5]!=0 && irdProvId==((buff[10]*256)|buff[11])) { // prepare DT08 data
     cSmartCardDataNagra cd(irdProvId,true);
-    if(!(entry=(cSmartCardDataNagra *)smartcards.FindCardData(&cd))) {
+    if(!(entry=(cSmartCardDataNagra *)carddatas.Find(&cd))) {
       PRINTF(L_GEN_WARN,"didn't find smartcard Nagra IRD modulus");
       }
     else {
@@ -395,7 +395,7 @@ bool cSmartCardNagra::Init(void)
     }
   else {
     cSmartCardDataNagra cd(irdProvId);
-    if(!(entry=(cSmartCardDataNagra *)smartcards.FindCardData(&cd))) {
+    if(!(entry=(cSmartCardDataNagra *)carddatas.Find(&cd))) {
       PRINTF(L_GEN_WARN,"didn't find smartcard Nagra CAM modulus");
       }
     else {
index 3080e88a484df21a5636278242f408a2db188801..c0bbd29a2696ec3631d2398a8ffa563a6103af46 100644 (file)
@@ -566,7 +566,7 @@ bool cSmartCardVideoGuard2::Init(void)
       }
   if(!boxidOK) {
     cSmartCardDataVideoGuard2 cd(dtBoxId);
-    cSmartCardDataVideoGuard2 *entry=(cSmartCardDataVideoGuard2 *)smartcards.FindCardData(&cd);
+    cSmartCardDataVideoGuard2 *entry=(cSmartCardDataVideoGuard2 *)carddatas.Find(&cd);
     if(entry) {
       memcpy(&boxID,entry->boxid,sizeof(boxID));
       boxidOK=true;
@@ -603,7 +603,7 @@ bool cSmartCardVideoGuard2::Init(void)
   PRINTF(L_SC_INIT,"cardtype: %c%c.%d boxID %s caid %04x cardID %s",atr->hist[10],atr->hist[11],atr->hist[12],HexStr(str,boxID,4),CAID,HexStr(str2,cardID,4));
 
   cSmartCardDataVideoGuard2 cd(dtSeed);
-  cSmartCardDataVideoGuard2 *entry=(cSmartCardDataVideoGuard2 *)smartcards.FindCardData(&cd);
+  cSmartCardDataVideoGuard2 *entry=(cSmartCardDataVideoGuard2 *)carddatas.Find(&cd);
   if(!entry) {
     PRINTF(L_SC_ERROR,"no NDS seed available");
     return false;