Changeset 2210 for trunk/reader-cryptoworks.c
- Timestamp:
- 05/06/10 22:59:27 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/reader-cryptoworks.c
r2074 r2210 4 4 #define CMD_LEN 5 5 5 6 void RotateBytes1(unsigned char *out, unsigned char *in, int n)6 static void RotateBytes1(unsigned char *out, unsigned char *in, int n) 7 7 { 8 8 // loop is executed atleast once, so it's not a good idea to … … 12 12 } 13 13 14 void RotateBytes2(unsigned char *in, int n)14 static void RotateBytes2(unsigned char *in, int n) 15 15 { 16 16 // loop is executed atleast once, so it's not a good idea to … … 25 25 } 26 26 27 int Input(BIGNUM *d, unsigned char *in, int n, int LE)27 static int Input(BIGNUM *d, unsigned char *in, int n, int LE) 28 28 { 29 29 if (LE) … … 37 37 } 38 38 39 int Output(unsigned char *out, int n, BIGNUM *r, int LE)39 static int Output(unsigned char *out, int n, BIGNUM *r, int LE) 40 40 { 41 41 int s=BN_num_bytes(r); … … 61 61 } 62 62 63 int RSA(unsigned char *out, unsigned char *in, int n, BIGNUM *exp, BIGNUM *mod, int LE)63 static int RSA(unsigned char *out, unsigned char *in, int n, BIGNUM *exp, BIGNUM *mod, int LE) 64 64 { 65 65 int rc=0; … … 131 131 } 132 132 133 //int cryptoworks_send_pin(struct s_reader * reader) 134 //{ 135 // unsigned char insPIN[] = { 0xA4, 0x20, 0x00, 0x00, 0x04, 0x00,0x00,0x00,0x00 }; //Verify PIN 136 // 137 // if(reader->pincode[0] && (reader->pincode[0]&0xF0)==0x30) 138 // { 139 // memcpy(insPIN+5,reader->pincode,4); 140 // 141 // write_cmd(insPIN, insPIN+5); 142 // cs_ri_log (reader, "sending pincode to card"); 143 // if((cta_res[0]==0x98)&&(cta_res[1]==0x04)) cs_ri_log (reader, "bad pincode"); 144 // 145 // return OK; 146 // } 147 // 148 // return(0); 149 //} 133 /* 134 int cryptoworks_send_pin(struct s_reader * reader) 135 { 136 unsigned char insPIN[] = { 0xA4, 0x20, 0x00, 0x00, 0x04, 0x00,0x00,0x00,0x00 }; //Verify PIN 137 138 if(reader->pincode[0] && (reader->pincode[0]&0xF0)==0x30) 139 { 140 memcpy(insPIN+5,reader->pincode,4); 141 142 write_cmd(insPIN, insPIN+5); 143 cs_ri_log (reader, "sending pincode to card"); 144 if((cta_res[0]==0x98)&&(cta_res[1]==0x04)) cs_ri_log (reader, "bad pincode"); 145 146 return OK; 147 } 148 149 return(0); 150 } 151 */ 150 152 151 153 static int cryptoworks_disable_pin(struct s_reader * reader) … … 180 182 181 183 if ((atr[6]!=0xC4) || (atr[9]!=0x8F) || (atr[10]!=0xF1)) return ERROR; 184 185 cs_log("[cryptoworks-reader] card detected"); 186 cs_log("[cryptoworks-reader] type: CryptoWorks"); 182 187 183 188 reader->caid[0]=0xD00; … … 265 270 cs_ri_log (reader, "issuer: %s, id: %02X, bios: v%d, pin: %s, mfid: %04X", issuer, issuerid, atr[7], pin, mfid); 266 271 cs_ri_log (reader, "providers: %d (%s)", reader->nprov, ptxt+1); 267 cs_log("[cryptoworks-reader] ready for requests");268 272 269 cryptoworks_disable_pin(reader); //by KrazyIvan273 cryptoworks_disable_pin(reader); 270 274 271 275 return OK; 272 276 } 273 277 274 //#ifdef LALL 275 //bool cSmartCardCryptoworks::Decode(const cEcmInfo *ecm, const unsigned char *data, unsigned char *cw) 276 //{ 277 // static unsigned char ins4c[] = { 0xA4,0x4C,0x00,0x00,0x00 }; 278 // 279 // unsigned char nanoD4[10]; 280 // int l=CheckSctLen(data,-5+(ucpkValid ? sizeof(nanoD4):0)); 281 // if(l>5) { 282 // unsigned char buff[MAX_LEN]; 283 // if(ucpkValid) { 284 // memcpy(buff,data,l); 285 // nanoD4[0]=0xD4; 286 // nanoD4[1]=0x08; 287 // for(unsigned int i=2; i<sizeof(nanoD4); i++) nanoD4[i]=rand(); 288 // memcpy(&buff[l],nanoD4,sizeof(nanoD4)); 289 // data=buff; l+=sizeof(nanoD4); 290 // } 291 // ins4c[3]=ucpkValid ? 2 : 0; 292 // ins4c[4]=l-5; 293 // if(IsoWrite(ins4c,&data[5]) && Status() && 294 // (l=GetLen())>0 && ReadData(buff,l)==l) { 295 // int r=0; 296 // for(int i=0; i<l && r<2; ) { 297 // int n=buff[i+1]; 298 // switch(buff[i]) { 299 // case 0x80: 300 // de(printf("smartcardcryptoworks: nano 80 (serial)\n")) 301 // break; 302 // case 0xD4: 303 // de(printf("smartcardcryptoworks: nano D4 (rand)\n")) 304 // if(n<8 || memcmp(&buff[i],nanoD4,sizeof(nanoD4))) 305 // di(printf("smartcardcryptoworks: random data check failed after decrypt\n")) 306 // break; 307 // case 0xDB: // CW 308 // de(printf("smartcardcryptoworks: nano DB (cw)\n")) 309 // if(n==0x10) { 310 // memcpy(cw,&buff[i+2],16); 311 // r|=1; 312 // } 313 // break; 314 // case 0xDF: // signature 315 // de(printf("smartcardcryptoworks: nano DF %02x (sig)\n",n)) 316 // if(n==0x08) { 317 // if((buff[i+2]&0x50)==0x50 && !(buff[i+3]&0x01) && (buff[i+5]&0x80)) 318 // r|=2; 319 // } 320 // else if(n==0x40) { // camcrypt 321 // if(ucpkValid) { 322 // RSA(&buff[i+2],&buff[i+2],n,exp,ucpk,false); 323 // de(printf("smartcardcryptoworks: after camcrypt ")) 324 // de(HexDump(&buff[i+2],n)) 325 // r=0; l=n-4; n=4; 326 // } 327 // else { 328 // di(printf("smartcardcryptoworks: valid UCPK needed for camcrypt!\n")) 329 // return false; 330 // } 331 // } 332 // break; 333 // default: 334 // de(printf("smartcardcryptoworks: nano %02x (unhandled)\n",buff[i])) 335 // break; 336 // } 337 // i+=n+2; 338 // } 339 // return r==3; 340 // } 341 // } 342 // return false; 343 //} 344 //#endif 278 /* 279 #ifdef LALL 280 bool cSmartCardCryptoworks::Decode(const cEcmInfo *ecm, const unsigned char *data, unsigned char *cw) 281 { 282 static unsigned char ins4c[] = { 0xA4,0x4C,0x00,0x00,0x00 }; 283 284 unsigned char nanoD4[10]; 285 int l=CheckSctLen(data,-5+(ucpkValid ? sizeof(nanoD4):0)); 286 if(l>5) { 287 unsigned char buff[MAX_LEN]; 288 if(ucpkValid) { 289 memcpy(buff,data,l); 290 nanoD4[0]=0xD4; 291 nanoD4[1]=0x08; 292 for(unsigned int i=2; i<sizeof(nanoD4); i++) nanoD4[i]=rand(); 293 memcpy(&buff[l],nanoD4,sizeof(nanoD4)); 294 data=buff; l+=sizeof(nanoD4); 295 } 296 ins4c[3]=ucpkValid ? 2 : 0; 297 ins4c[4]=l-5; 298 if(IsoWrite(ins4c,&data[5]) && Status() && 299 (l=GetLen())>0 && ReadData(buff,l)==l) { 300 int r=0; 301 for(int i=0; i<l && r<2; ) { 302 int n=buff[i+1]; 303 switch(buff[i]) { 304 case 0x80: 305 de(printf("smartcardcryptoworks: nano 80 (serial)\n")) 306 break; 307 case 0xD4: 308 de(printf("smartcardcryptoworks: nano D4 (rand)\n")) 309 if(n<8 || memcmp(&buff[i],nanoD4,sizeof(nanoD4))) 310 di(printf("smartcardcryptoworks: random data check failed after decrypt\n")) 311 break; 312 case 0xDB: // CW 313 de(printf("smartcardcryptoworks: nano DB (cw)\n")) 314 if(n==0x10) { 315 memcpy(cw,&buff[i+2],16); 316 r|=1; 317 } 318 break; 319 case 0xDF: // signature 320 de(printf("smartcardcryptoworks: nano DF %02x (sig)\n",n)) 321 if(n==0x08) { 322 if((buff[i+2]&0x50)==0x50 && !(buff[i+3]&0x01) && (buff[i+5]&0x80)) 323 r|=2; 324 } 325 else if(n==0x40) { // camcrypt 326 if(ucpkValid) { 327 RSA(&buff[i+2],&buff[i+2],n,exp,ucpk,false); 328 de(printf("smartcardcryptoworks: after camcrypt ")) 329 de(HexDump(&buff[i+2],n)) 330 r=0; l=n-4; n=4; 331 } 332 else { 333 di(printf("smartcardcryptoworks: valid UCPK needed for camcrypt!\n")) 334 return false; 335 } 336 } 337 break; 338 default: 339 de(printf("smartcardcryptoworks: nano %02x (unhandled)\n",buff[i])) 340 break; 341 } 342 i+=n+2; 343 } 344 return r==3; 345 } 346 } 347 return false; 348 } 349 #endif 350 */ 345 351 346 352 int cryptoworks_do_ecm(struct s_reader * reader, ECM_REQUEST *er) … … 429 435 } 430 436 431 //#ifdef LALL 432 //######################################################################## 433 // if ((cta_res[cta_lr-2]==0x9f)&&(cta_res[cta_lr-1]==0x1c)) 434 // { 435 // write_cmd(insC0, NULL); 436 // if ((cta_lr>26)&&(cta_res[cta_lr-2]==0x90)&&(cta_res[cta_lr-1]==0)) 437 // { 438 // if (rc=(((cta_res[20]&0x50)==0x50) && 439 // (!(cta_res[21]&0x01)) && 440 // (cta_res[23]&0x80))) 441 // memcpy(er->cw, cta_res+2, 16); 442 // } 443 // } 444 //#endif 445 } 446 // return(rc ? 1 : 0); 437 /* 438 #ifdef LALL 439 if ((cta_res[cta_lr-2]==0x9f)&&(cta_res[cta_lr-1]==0x1c)) 440 { 441 write_cmd(insC0, NULL); 442 if ((cta_lr>26)&&(cta_res[cta_lr-2]==0x90)&&(cta_res[cta_lr-1]==0)) 443 { 444 if (rc=(((cta_res[20]&0x50)==0x50) && 445 (!(cta_res[21]&0x01)) && 446 (cta_res[23]&0x80))) 447 memcpy(er->cw, cta_res+2, 16); 448 } 449 } 450 #endif 451 */ 452 } 453 //return(rc ? 1 : 0); 447 454 return((r==3) ? 1 : 0); 448 455 } … … 625 632 uchar insB2[] = {0xA4, 0xB2, 0x00, 0x00, 0x00}; 626 633 char l_name[20+8]=", name: "; 627 cs_log("[cryptoworks-reader] card detected");628 cs_log("[cryptoworks-reader] type: CryptoWorks");629 634 630 635 for (i=0; i<reader->nprov; i++) … … 659 664 } 660 665 } 661 //================================================================================ 662 //by KrazyIvan 666 663 667 select_file(reader, 0x0f, 0x00, cta_res, &cta_lr); // select provider channel 664 668 write_cmd(insA21, insA21+5); … … 680 684 } 681 685 } 682 //================================================================================ 683 684 } 686 } 687 cs_log("[cryptoworks-reader] ready for requests"); 685 688 return OK; 686 689 }
Note:
See TracChangeset
for help on using the changeset viewer.