[BACK]Return to scard.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/Attic/scard.c between version 1.7 and 1.8

version 1.7, 2001/07/26 20:04:27 version 1.8, 2001/07/30 16:06:07
Line 56 
Line 56 
         if (sc_fd >= 0)          if (sc_fd >= 0)
                 return sc_fd;                  return sc_fd;
   
         sc_fd = sectok_open(sc_reader_num, 0, &sw);          sc_fd = sectok_open(sc_reader_num, STONOWAIT, &sw);
         if (sc_fd < 0) {          if (sc_fd < 0) {
                 error("sectok_open failed: %s", sectok_get_sw(sw));                  error("sectok_open failed: %s", sectok_get_sw(sw));
                 return -1;                  return SCARD_ERROR_FAIL;
         }          }
           if (! sectok_cardpresent(sc_fd)) {
                   error("smartcard in reader %d not present, skipping",
                       sc_reader_num);
                   return SCARD_ERROR_NOCARD;
           }
         if (sectok_reset(sc_fd, 0, NULL, &sw) <= 0) {          if (sectok_reset(sc_fd, 0, NULL, &sw) <= 0) {
                 error("sectok_reset failed: %s", sectok_get_sw(sw));                  error("sectok_reset failed: %s", sectok_get_sw(sw));
                 sc_fd = -1;                  sc_fd = -1;
                 return sc_fd;                  return SCARD_ERROR_FAIL;
         }          }
         if ((cla = cyberflex_inq_class(sc_fd)) < 0)          if ((cla = cyberflex_inq_class(sc_fd)) < 0)
                 cla = 0;                  cla = 0;
Line 92 
Line 97 
 static int  static int
 sc_init(void)  sc_init(void)
 {  {
         if (sc_open() < 0) {          int status;
   
           status = sc_open();
           if (status == SCARD_ERROR_NOCARD) {
                   return SCARD_ERROR_NOCARD;
           }
           if (status < 0 ) {
                 error("sc_open failed");                  error("sc_open failed");
                 return -1;                  return status;
         }          }
         if (sc_enable_applet() < 0) {          if (sc_enable_applet() < 0) {
                 error("sc_enable_applet failed");                  error("sc_enable_applet failed");
                 return -1;                  return SCARD_ERROR_APPLET;
         }          }
         return 0;          return 0;
 }  }
Line 108 
Line 119 
 {  {
         u_char buf[2], *n;          u_char buf[2], *n;
         char *p;          char *p;
         int len, sw;          int len, sw, status;
   
         len = sw = 0;          len = sw = 0;
   
         if (sc_fd < 0)          if (sc_fd < 0) {
                 if (sc_init() < 0)                  status = sc_init();
                         return -1;                  if (status < 0 )
                           return status;
           }
   
         /* get key size */          /* get key size */
         sectok_apdu(sc_fd, CLA_SSH, INS_GET_KEYLENGTH, 0, 0, 0, NULL,          sectok_apdu(sc_fd, CLA_SSH, INS_GET_KEYLENGTH, 0, 0, 0, NULL,
Line 165 
Line 178 
 sc_private_decrypt(int flen, u_char *from, u_char *to, RSA *rsa, int padding)  sc_private_decrypt(int flen, u_char *from, u_char *to, RSA *rsa, int padding)
 {  {
         u_char *padded = NULL;          u_char *padded = NULL;
         int sw, len, olen;          int sw, len, olen, status;
   
         debug("sc_private_decrypt called");          debug("sc_private_decrypt called");
   
         olen = len = sw = 0;          olen = len = sw = 0;
         if (sc_fd < 0)          if (sc_fd < 0) {
                 if (sc_init() < 0)                  status = sc_init();
                   if (status < 0 )
                         goto err;                          goto err;
           }
         if (padding != RSA_PKCS1_PADDING)          if (padding != RSA_PKCS1_PADDING)
                 goto err;                  goto err;
   
Line 199 
Line 214 
 err:  err:
         if (padded)          if (padded)
                 xfree(padded);                  xfree(padded);
         return olen;          return (olen >= 0 ? olen : status);
 }  }
   
 static int  static int
 sc_private_encrypt(int flen, u_char *from, u_char *to, RSA *rsa, int padding)  sc_private_encrypt(int flen, u_char *from, u_char *to, RSA *rsa, int padding)
 {  {
         u_char *padded = NULL;          u_char *padded = NULL;
         int sw, len;          int sw, len, status;
   
         len = sw = 0;          len = sw = 0;
         if (sc_fd < 0)          if (sc_fd < 0) {
                 if (sc_init() < 0)                  status = sc_init();
                   if (status < 0 )
                         goto err;                          goto err;
           }
         if (padding != RSA_PKCS1_PADDING)          if (padding != RSA_PKCS1_PADDING)
                 goto err;                  goto err;
   
Line 241 
Line 258 
 err:  err:
         if (padded)          if (padded)
                 xfree(padded);                  xfree(padded);
         return len;          return (len >= 0 ? len : status);
 }  }
   
 /* engine for overloading private key operations */  /* engine for overloading private key operations */

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8