1 #ifdef WITH_SIGNATURE 2 3 /* 'self' struct needs 4 * bool gpg_verified; 5 * char gpg_data[128]; 6 */ 7 8 #ifndef FALSE 9 #define FALSE 0 10 #endif 11 #ifndef TRUE 12 #define TRUE -1 13 #endif 14 15 { 16 self->gpg_verified = FALSE; 17 gp3_initialize (); 18 load_master_key (); // in header WITH_SIGNATURE 19 gp3_loglevel (GP3L_SILENT); 20 int rc = -1; 21 char signature_file0[1024] = ""; 22 char signature_file1[1024] = ""; 23 char signature_file2[1024] = ""; 24 char signature_file3[1024] = ""; 25 #ifdef SIGNOVERSION 26 memset(self->gpg_data, 0, sizeof (self->gpg_data)); 27 #else 28 strcpy(self->gpg_data, "v" VERSION); 29 #endif 30 #ifdef _WIN32 31 ExpandEnvironmentStrings("%localappdata%\\"SIGFILE, signature_file0, 1024); 32 ExpandEnvironmentStrings("%localappdata%\\x42_license.txt", signature_file2, 1024); 33 34 const char * homedrive = getenv("HOMEDRIVE"); 35 const char * homepath = getenv("HOMEPATH"); 36 37 if (homedrive && homepath && (strlen(homedrive) + strlen(homepath) + strlen(SIGFILE) + 3) < 1024) { 38 sprintf(signature_file1, "%s%s\\%s", homedrive, homepath, SIGFILE); 39 } 40 if (homedrive && homepath && (strlen(homedrive) + strlen(homepath) + strlen(SIGFILE) + 17) < 1024) { 41 sprintf(signature_file3, "%s%s\\x42_license.txt", homedrive, homepath); 42 } 43 #else 44 const char * home = getenv("HOME"); 45 if (home && (strlen(home) + strlen(SIGFILE) + 3) < 1024) { 46 sprintf(signature_file0, "%s/%s", home, SIGFILE); 47 } 48 if (home && (strlen(home) + strlen(SIGFILE) + 3) < 1024) { 49 sprintf(signature_file1, "%s/.%s", home, SIGFILE); 50 } 51 if (home && (strlen(home) + 18) < 1024) { 52 sprintf(signature_file2, "%s/x42_license.txt", home); 53 } 54 if (home && (strlen(home) + 18) < 1024) { 55 sprintf(signature_file3, "%s/.x42_license.txt", home); 56 } 57 #endif 58 if (testfile(signature_file0)) { 59 rc = gp3_checksigfile (signature_file0); 60 } else if (testfile(signature_file1)) { 61 rc = gp3_checksigfile (signature_file1); 62 } else if (testfile(signature_file2)) { 63 rc = gp3_checksigfile (signature_file2); 64 } else if (testfile(signature_file3)) { 65 rc = gp3_checksigfile (signature_file3); 66 } else { 67 #if 0 68 fprintf(stderr, " *** no signature file found\n"); 69 #endif 70 } 71 if (rc == 0) { 72 char data[8192]; 73 char *tmp=NULL; 74 uint32_t len = gp3_get_text(data, sizeof(data)); 75 if (len == sizeof(data)) data[sizeof(data)-1] = '\0'; 76 else data[len] = '\0'; 77 #if 0 78 fprintf(stderr, " *** signature:\n"); 79 if (len > 0) fputs(data, stderr); 80 #endif 81 if ((tmp = strchr(data, '\n'))) *tmp = 0; 82 self->gpg_data[sizeof(self->gpg_data) - 1] = 0; 83 if (tmp++ && *tmp) { 84 if ((tmp = strstr(tmp, RTK_URI))) { 85 char *t1, *t2; 86 self->gpg_verified = TRUE; 87 t1 = tmp + strlen(RTK_URI); 88 t2 = strchr(t1, '\n'); 89 if (t2) { *t2 = 0; } 90 if (strlen(t1) > 0 && strncmp(t1, VERSION, strlen(t1))) { 91 self->gpg_verified = FALSE; 92 } 93 } 94 } 95 if (!self->gpg_verified) { 96 #if 0 97 fprintf(stderr, " *** signature is not valid for this version/bundle.\n"); 98 #endif 99 } else { 100 #ifndef SIGNOVERSION 101 strncat(self->gpg_data, " ", sizeof(self->gpg_data) - strlen(self->gpg_data)); 102 #endif 103 strncat(self->gpg_data, data, sizeof(self->gpg_data) - strlen(self->gpg_data)); 104 } 105 } 106 gp3_cleanup (); 107 } 108 #endif 109