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

Diff for /src/usr.bin/sectok/Attic/cyberflex.c between version 1.1 and 1.2

version 1.1, 2001/06/27 19:41:45 version 1.2, 2001/06/28 21:29:45
Line 362 
Line 362 
     rv = scwrite(fd, cla, 0xa4, 0x04, 0, 0, NULL, &r1, &r2);      rv = scwrite(fd, cla, 0xa4, 0x04, 0, 0, NULL, &r1, &r2);
     if (r1 != 0x90 && r1 != 0x61) {      if (r1 != 0x90 && r1 != 0x61) {
         /* error */          /* error */
         printf("selecting default loader: ");          printf("can't select default loader: %s\n", get_r1r2s(r1, r2));
         print_r1r2(r1, r2);  
         return -1;          return -1;
     }      }
   
     /* select 3f.00 (root) */      /* select 3f.00 (root) */
     rv = sectok_selectfile(fd, cla, root_fid, 0);      if (sectok_selectfile(fd, cla, root_fid, &r1, &r2) < 0)
     if (rv < 0) return rv;          return -1;
   
     /* create program file */      /* create program file */
     data[0] = (size + 16) / 256; /* size, upper byte */      if (cyberflex_create_file(fd, cla, progID, size, 3, &r1, &r2) < 0) {
     data[1] = (size + 16) % 256; /* size, lower byte */  
     data[2] = progID[0];        /* FID, upper */  
     data[3] = progID[1];        /* FID, lower */  
     data[4] = 0x03;             /* file type = 3 (program file) */  
     data[5] = 0x01;             /* status = 1 */  
     data[6] = data[7] = 0x00;   /* record related */  
     data[8] = 0xff;             /* ACL can do everything with AUT0 */  
     for (i = 9; i < 16; i++ ) {  
         data[i] = 0x00;         /* ACL : cannot do anything without AUT0 */  
     }  
   
     rv = scwrite(fd, cla, 0xe0, 0, 0, 0x10, data, &r1, &r2);  
     if (r1 != 0x90 && r1 != 0x61) {  
         /* error */          /* error */
         printf("creating file %s: %s\n", progname, get_r1r2s(r1, r2));          printf("can't create %s: %s\n", progname, get_r1r2s(r1, r2));
         return -1;          return -1;
     }      }
   
     /* select program */  
     rv = sectok_selectfile(fd, cla, progID, 0);  
     if (rv < 0) return rv;  
   
     /* update binary */      /* update binary */
     for (i = 0; i < size; i += MAX_APDU_SIZE) {      for (i = 0; i < size; i += MAX_APDU_SIZE) {
         int send_size;          int send_size;
Line 495 
Line 477 
     /*printf ("unload applet\n");*/      /*printf ("unload applet\n");*/
   
     /* select 3f.00 (root) */      /* select 3f.00 (root) */
     rv = sectok_selectfile(fd, cla, root_fid, 0);      if (sectok_selectfile(fd, cla, root_fid, &r1, &r2) < 0)
     if (rv < 0) return rv;          return -1;
   
     /* select program file */      /* select program file */
     rv = sectok_selectfile(fd, cla, progID, 0);      if (sectok_selectfile(fd, cla, progID, &r1, &r2) >= 0) {
     if (rv < 0) {  
         printf ("no program file... proceed to delete data container\n");  
         goto del_container;  
     }  
   
     /* manage program -- reset */          /* manage program -- reset */
     rv = scwrite(fd, cla, 0x0a, 02, 0, 0x0, NULL, &r1, &r2);          rv = scwrite(fd, cla, 0x0a, 02, 0, 0x0, NULL, &r1, &r2);
     if (r1 != 0x90 && r1 != 0x61) {          if (rv < 0 || (r1 != 0x90 && r1 != 0x61)) {
         /* error */              /* error */
         printf("resetting applet: %s\n", get_r1r2s(r1, r2));              printf("resetting applet: %s\n", get_r1r2s(r1, r2));
     }          }
   
     /* delete program file */          /* delete program file */
     cyberflex_delete_file(fd, cla, progID[0], progID[1], 1);          if (cyberflex_delete_file(fd, cla, progID[0], progID[1], &r1, &r2) < 0)
               printf("delete_file %s: %s\n", progname, get_r1r2s(r1, r2));
       } else
           printf ("no program file... proceed to delete data container\n");
   
  del_container:  
     /* delete data container */      /* delete data container */
     cyberflex_delete_file(fd, cla, contID[0], contID[1], 1);      if (cyberflex_delete_file(fd, cla, contID[0], contID[1], &r1, &r2) < 0)
           printf("delete_file %s: %s\n", contname, get_r1r2s(r1, r2));
   
     return 0;      return 0;
 }  }
Line 654 
Line 635 
         printf ("%02x ", data[i]);          printf ("%02x ", data[i]);
     printf ("\n");      printf ("\n");
   
     /* select the key file */  
     /* select 3f.00 (root) */      /* select 3f.00 (root) */
     rv = sectok_selectfile(fd, cla, root_fid, 0);      if (sectok_selectfile(fd, cla, root_fid, &r1, &r2) < 0)
     if (rv < 0) return rv;          return -1;
   
     /* select 00.11 (key file) */      /* select 00.11 (key file) */
     rv = sectok_selectfile(fd, cla, key_fid, 0);      if (sectok_selectfile(fd, cla, key_fid, &r1, &r2) < 0)
     if (rv < 0) return rv;          return -1;
   
     /* all righty, now let's send it to the card! :) */      /* all righty, now let's send it to the card! :) */
     rv = scwrite(fd, cla, 0xd6, 0, 0, KEY_BLOCK_SIZE * (argc + 2) + 2,      rv = scwrite(fd, cla, 0xd6, 0, 0, KEY_BLOCK_SIZE * (argc + 2) + 2,
                  data, &r1, &r2);                   data, &r1, &r2);
     if (r1 != 0x90 && r1 != 0x61) {      if (r1 != 0x90 && r1 != 0x61) {
         /* error */          /* error */
         printf("writing the key file 00.11: ");          printf("writing the key file 00.11: %s\n", get_r1r2s(r1, r2));
         print_r1r2(r1, r2);  
         return -1;          return -1;
     }      }
     print_r1r2 (r1, r2);  
   
     return 0;      return 0;
 }  }
Line 708 
Line 686 
         printf ("%02x ", data[i]);          printf ("%02x ", data[i]);
     printf ("\n");      printf ("\n");
   
     /* select the key file */  
     /* select 3f.00 (root) */      /* select 3f.00 (root) */
     rv = sectok_selectfile(fd, cla, root_fid, 0);      if (sectok_selectfile(fd, cla, root_fid, &r1, &r2) < 0)
     if (rv < 0) return rv;          return -1;
   
     /* select 00.11 (key file) */      /* select 00.11 (key file) */
     rv = sectok_selectfile(fd, cla, key_fid, 0);      if (sectok_selectfile(fd, cla, key_fid, &r1, &r2) < 0)
     if (rv < 0) return rv;          return -1;
   
     /* all righty, now let's send it to the card! :) */      /* all righty, now let's send it to the card! :) */
     rv = scwrite(fd, cla, 0xd6, 0, 0, KEY_BLOCK_SIZE,      rv = scwrite(fd, cla, 0xd6, 0, 0, KEY_BLOCK_SIZE,
                  data, &r1, &r2);                   data, &r1, &r2);
     if (r1 != 0x90 && r1 != 0x61) {      if (r1 != 0x90 && r1 != 0x61) {
         /* error */          /* error */
         printf("writing the key file 00.11: ");          printf("writing the key file 00.11: %s\n", get_r1r2s(r1, r2));
         print_r1r2(r1, r2);  
         return -1;          return -1;
     }      }
     print_r1r2(r1, r2);  
   
     return 0;      return 0;
 }  }
Line 734 
Line 709 
 /* download RSA private key into 3f.00/00.12 */  /* download RSA private key into 3f.00/00.12 */
 int cyberflex_load_rsa(int fd, unsigned char *buf)  int cyberflex_load_rsa(int fd, unsigned char *buf)
 {  {
     int rv, i, j, tmp;      int rv, r1, r2, i, j, tmp;
     static unsigned char key_fid[] = {0x00, 0x12};      static unsigned char key_fid[] = {0x00, 0x12};
     static char *key_names[NUM_RSA_KEY_ELEMENTS]= {"p", "q", "1/p mod q",      static char *key_names[NUM_RSA_KEY_ELEMENTS]= {"p", "q", "1/p mod q",
                                                        "d mod (p-1)", "d mod (q-1)"};                                                         "d mod (p-1)", "d mod (q-1)"};
Line 763 
Line 738 
     }      }
 #endif  #endif
   
     rv = cyberflex_load_rsa_priv(fd, cla, key_fid, NUM_RSA_KEY_ELEMENTS, RSA_BIT_LEN, key_elements);      rv = cyberflex_load_rsa_priv(fd, cla, key_fid, NUM_RSA_KEY_ELEMENTS, RSA_BIT_LEN,
                                    key_elements, &r1, &r2);
   
       if (rv < 0)
           printf("load_rsa_priv: %s\n", get_r1r2s(r1, r2));
   
     for (i = 0; i < NUM_RSA_KEY_ELEMENTS; i++)      for (i = 0; i < NUM_RSA_KEY_ELEMENTS; i++)
         free(key_elements[i]);          free(key_elements[i]);

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2