int retrieve_key(PGconn *conn, char *fingerprint, unsigned int full,struct cks_config *config) { struct openPGP_keyring *keyring = NULL; struct openPGP_pubkey *key_result = NULL; int rslt = 0; key_result = (struct openPGP_pubkey *)retrieve_pubkey(conn,fingerprint,D_SOURCE_ADD_CGI); if(key_result == NULL) { fprintf(stderr,_("Failed to retrieve key: %s\n"),fingerprint); do_error_page(_("Failed to retrieve key from database.\n")); return -1; } rslt = parse_pubkey(&key_result,D_SOURCE_SEARCH_CGI); if(rslt == -1) { fprintf(stderr,_("Failed to parse retrieved pubkey: %s\n"),fingerprint); return -1; } rslt = parse_packets(&key_result,D_SOURCE_SEARCH_CGI); if(rslt == -1) { fprintf(stderr,_("Failed to parse retrieved pubkey's packets: %s\n"),fingerprint); return -1; } if(full) { echo_key_info(conn,key_result); echo_radix_key(key_result,config); } else { printf("<pre>\n"); printf("<hr size=\"1\" width=\"100%%\">\n"); fflush(0); echo_abrev_key_info(conn,key_result); } if(key_result != NULL) { free_pubkey(&key_result); } return rslt; }
int main(void) { GDBM_FILE dbf; int result; datum data; datum info; datum data2; datum info2; float lat1; float lon1; float lat2; float lon2; float distance; /* For parsing post */ char *method; char *content; int content_length = 0; char *nvpair1; char *nvpair2; char *zip_1; char *zip_2; method = (char *)getenv("REQUEST_METHOD"); if(strcmp(method,"POST") != 0) { do_error_page("Only method POST is supported."); } content_length = atoi(getenv("CONTENT_LENGTH")); if(content_length > 100) { do_error_page("Content Length expectation exceeded."); } content = (char *)malloc(content_length+1); if(content == NULL) { do_error_page("Server was unable to malloc memory. Server out of memory."); } fread(content,1,content_length,stdin); nvpair1 = strtok(content,"&"); nvpair2 = strtok('\0',"&"); zip_1 = strtok(nvpair1,"="); zip_1 = strtok('\0',"="); zip_2 = strtok(nvpair2,"="); zip_2 = strtok('\0',"="); if(strlen(zip_1) != 5) { do_error_page("Zip code #1 does not appear to be a valid US zip code."); } if(strlen(zip_2) != 5) { do_error_page("Zip code #2 does not appear to be a valid US zip code."); } if((dbf = gdbm_open("zips_gdbm",1024,GDBM_READER, 0755, 0)) ==NULL) { fprintf(stderr, "Unable to open gdbm data file.\n"); exit(1); } data.dptr = zip_1; data.dsize = 5; info = gdbm_fetch(dbf,data); if(info.dptr == NULL) { do_error_page("Zip code #1 was not found in the data base.\n"); } sscanf(info.dptr,"%f%f",&lon1, &lat1); free(info.dptr); data2.dptr = zip_2; data2.dsize = 5; info2 = gdbm_fetch(dbf,data2); if(info2.dptr == NULL) { do_error_page("Zip code #2 was not found in the data base.\n"); } sscanf(info2.dptr,"%f%f",&lon2,&lat2); free(info2.dptr); gdbm_close(dbf); distance = great_circle_distance(lat1,lon1,lat2,lon2); printf("Content-Type: text/html\n\n"); printf("<HTML><HEAD><TITLE>Zipdy Results</TITLE>\n"); printf("<BODY BGCOLOR=#FFFFFF>\n"); printf("The distance between %s and %s is: %f.\n", zip_1, zip_2, distance); printf("</BODY></HTML>\n"); free(content); return 0; }
int main(void) { struct cks_config *config = NULL; PGconn *conn = NULL; char *method = NULL; char *content = NULL; unsigned long content_length = 0; PGresult *result = NULL; unsigned char stmt[] = "select server,sync_priority from cks_other_servers order by sync_priority"; struct name_value_pair_dllst *form = NULL; /* cgi vars */ char *hostname = NULL; char *srvr_type = NULL; char *priority = NULL; int rslt = 0; int nts = 0; config = (struct cks_config *)malloc(sizeof(struct cks_config)); if(config == NULL) { do_error_page(_("syn_manage: malloc call failed: out of memroy!\n")); return -1; } rslt = init_config(&config); if(rslt == -1) { fprintf(stderr,_("sync_manage: Non-Fatal Error: Failed to read config.\n")); fprintf(stderr,_("sync_manage: Using default configuration information.\n")); } /* Make the DB Connection. */ conn = db_connect(config); if(conn == NULL) { fprintf(stderr,"Failed to connect to the db.\n"); if(config != NULL) { free(config); } return -1; } method = getenv("REQUEST_METHOD"); if(method == NULL) { do_error_page(_("Request Method was Null.\n<P><P>Exiting...")); db_disconnect(conn); if(config != NULL) { free(config); } return 0; } else if(strcmp(method,"GET") == 0) { /* Just Fall Through and Print the Form */ } else if(strcmp(method,"POST") == 0) { content_length = atoi(getenv("CONTENT_LENGTH")); if(content_length > 800) { do_error_page(_("Content Length expectation exceeded\n")); db_disconnect(conn); if(config != NULL) { free(config); } return -1; } content = (char *)malloc(content_length+1); if(content == NULL) { do_error_page(_("Server was unable to malloc memory. Server out of memory.")); db_disconnect(conn); if(config != NULL) { free(config); } return -1; } rslt = fread(content,1,content_length,stdin); if(rslt == 0) { do_error_page(_("Server was unable to read content.")); if(config != NULL) free(config); return -1; } content[content_length] = '\0'; hex_to_ascii(content); /* Test value for SQL injection */ if( (strchr(content, '\'') != NULL) || (strchr(content, ';') != NULL) ) { do_error_page(_("The characters ' and ; are currently not allowed in queries.")); db_disconnect(conn); if(config != NULL) free(config); if(content != NULL) free(content); return 0; } form = parse_name_value_pairs(content); if(form == NULL) { /* No Request, so Echo Default Page */ do_error_page(_("Failed to Parse CGI Form. Are you using a Standard Web Browser?\n")); db_disconnect(conn); if(config != NULL) free(config); if(content != NULL) free(content); return -1; } hostname = get_value(form,"hostname"); srvr_type = get_value(form,"srvr_type"); priority = get_value(form,"priority"); rslt = insert_into_other_server(conn,hostname,srvr_type,priority); if(rslt == -1) { do_error_page("Failed To Insert new record into database."); db_disconnect(conn); if(config != NULL) free(config); if(content != NULL) free(content); return -1; } /* Now Fall Through and Re-Print the Form */ } else { do_error_page("Unknown Method."); db_disconnect(conn); if(config != NULL) free(config); if(content != NULL) free(content); return -1; } printf("content-type: text/html\n\n"); printf(_("<html><head><title>CryptNET OpenPGP Public Key Server</title></head>\n")); printf("<body bgcolor=\"#FFFFFF\">\n"); printf(_("<center><H2>CryptNET Keyserver Administration</h2></center>\n")); printf("<hr size=\"1\" width=\"100%%\">\n"); printf("<center>\n"); printf(_("[ <a href=\"sync.html\">Manage Sync Hosts</a> ]\n")); printf(_("[ <a href=\"delete.html\">Delete A Key From This Server</a> ]\n")); printf(_("[ <a href=\"stats.cgi\">Stats On This Server</a> ]\n")); printf(_("[ <a href=\"index.html\">Admin Home</a> ]\n")); printf(_("[ <a href=\"/index.html\">Home</a> ]\n")); printf("</center>\n"); printf("<hr size=\"1\" width=\"100%%\">\n"); printf(_("<h3>Synchronization Host Management</h3>\n")); result = PQexec(conn, stmt); if(PQresultStatus(result) != PGRES_TUPLES_OK) { do_error_page("Database Query failed.\n"); fprintf(stderr,_("Command didn't return tuples properly\n")); PQclear(result); db_disconnect(conn); if(config != NULL) free(config); if(content != NULL) free(content); return -1; } printf("<table width=\"90%%\" cols=\"5\" border=\"1\">\n"); printf(_("<tr><th width=\"15%%\" align=\"CENTER\">Delete</th><th align=\"CENTER\">Server</th><th align=\"CENTER\">Sync Priority</th><th align=\"center\">Server Type</th></tr>\n")); nts = PQntuples(result); if(nts == 0) { printf("</table>\n"); printf("<p>No host synchronization records found.</p>\n"); } else if(nts == 1) { printf("<form method=\"post\" action=\"sync_manage.cgi\">\n"); printf("<tr><td><input type=\"checkbox\" name=\"%s\"></td><td>%s</td><td>%s</td><td>%s</td><td><input type=\"submit\" value=\"Update\"></td></tr>\n",PQgetvalue(result,0,0),PQgetvalue(result,0,0),PQgetvalue(result,0,1),PQgetvalue(result,0,2)); printf("</form>\n"); } else if(nts > 1) { int i = 0; for(i = 0;i<nts;i++) { printf("<form method=\"post\" action=\"sync_manage.cgi\">\n"); printf("<tr><td><input type=\"checkbox\" name=\"%s\"></td><td>%s</td><td>%s</td><td>%s</td><td><input type=\"submit\" value=\"Update\"></td></tr>\n",PQgetvalue(result,i,0),PQgetvalue(result,i,0),PQgetvalue(result,i,1),PQgetvalue(result,i,2)); printf("</form>\n"); } } else { printf("</table>\n"); fprintf(stderr, _("sync_manage.c: Weird Tuples Returned.\n")); fprintf(stderr,_("Weird Tuples Returned! (negative)\n")); do_error_page("The database query returned in an error state.\n"); PQclear(result); PQfinish(conn); return -1; } /* close up and clean up database connection, we're done with it */ PQclear(result); db_disconnect(conn); /* Print the input form */ printf("</table>\n"); printf("<p></p>\n"); printf("<p></p>\n"); printf("<hr size=\"1\" width=\"100%%\">\n"); printf("<form method=\"POST\" action=\"sync_manage.cgi\">\n"); printf(_("<h3>Add New Synchronization Host</h3>\n")); printf(_("<p>Add Host: <input name=\"hostname\" type=\"text\" length=\"60\" maxlen=\"60\"></p>\n")); printf(_("<p>Priority:\n")); printf("<select name=\"priority\">\n"); printf("<option value=\"1\">1</option>\n"); printf("<option value=\"2\">2</option>\n"); printf("<option value=\"3\">3</option>\n"); printf("<option value=\"4\">4</option\n"); printf("<option value=\"5\">5</option selected>\n"); printf("<option value=\"6\">6</option>\n"); printf("<option value=\"7\">7</option\n"); printf("<option value=\"8\">8</option>\n"); printf("<option value=\"9\">9</option>\n"); printf("<option>10</option>\n"); printf("</select></p>\n"); printf(_("<p>Server Type: <select name=\"srvr_type\">\n")); printf("<option value=\"1\">CryptNET Key Server</option>\n"); printf("<option value=\"2\">PKS Key Server</option>\n"); printf("<option value=\"3\">SKS Key Server</option>\n"); printf("</select></p>\n"); printf("<br></br>\n"); printf(_("<input type=\"submit\" value=\"Update Sync List\">\n")); printf("</form>\n"); printf("<hr size=\"1\" width=\"100%%\">\n"); printf("<center>\n"); printf(_("[ <a href=\"sync.html\">Manage Sync Hosts</a> ]\n")); printf(_("[ <a href=\"delete.html\">Delete A Key From This Server</a> ]\n")); printf(_("[ <a href=\"stats.cgi\">Stats On This Server</a> ]\n")); printf(_("[ <a href=\"index.html\">Admin Home</a> ]\n")); printf(_("[ <a href=\"/index.html\">Home</a> ]\n")); printf("</center>\n"); printf("<hr size=\"1\" width=\"100%%\">\n"); printf(_("<center><a href=\"http://keyserver.cryptnet.net/\">CryptNET Key Server Network</a></center>\n")); printf("</body></html>\n"); /* Free Memory and Exit */ if(content != NULL) { free(content); } if(config != NULL) { free(config); } return 0; }
int main(void) { struct cks_config *config = NULL; PGconn *conn = NULL; char *method = NULL; char *content = NULL; unsigned long content_length = 0; char *name = NULL; char *val = NULL; char *value = NULL; char *debug_val = NULL; int rslt = 0; int tmp_var = 0; config = (struct cks_config *)malloc(sizeof(struct cks_config)); if(config == NULL) { fprintf(stderr,_("cks_export: Fatal Error: Malloc Call Failed: Out of memroy.\n")); return -1; } rslt = init_config(&config); if(rslt == -1) { fprintf(stderr,_("search: Non-Fatal Error: Failed to read config.\n")); fprintf(stderr,_("search: Using default configuration information.\n")); } method = getenv("REQUEST_METHOD"); if(method == NULL) { /* Make the DB Connection. */ conn = db_connect(config); if(conn == NULL) { fprintf(stderr,"Failed to connect to the db.\n"); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } debug_val = (char *)malloc(50); sprintf(debug_val,"%s","92987FBD"); search_by_keyid(conn,debug_val,config); /*search_by_uid(conn,"*****@*****.**",config); */ free(config); return 0; } if(method == NULL) { fprintf(stderr, _("search.c: Request Method is Null.\nExiting...\n")); free(config); return -1; } else if(strcmp(method,"GET") == 0) { content_length = strlen(getenv("QUERY_STRING")); if(content_length > 300) { do_error_page(_("Content Length expectation exceeded\n")); free(config); return -1; } content = (char *)malloc(content_length+1); if(content == NULL) { do_error_page(_("Server was unable to malloc memory. Server out of memory.")); free(config); return -1; } memset(content,0x00,content_length+1); strncpy(content,getenv("QUERY_STRING"),content_length); } else if(strcmp(method,"POST") == 0) { content_length = atoi(getenv("CONTENT_LENGTH")); if(content_length > 300) { do_error_page(_("Content Length expectation exceeded\n")); if(config != NULL) free(config); return -1; } content = (char *)malloc(content_length+1); if(content == NULL) { do_error_page(_("Server was unable to malloc memory. Server out of memory.")); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } rslt = fread(content,1,content_length,stdin); if(rslt == 0) { do_error_page(_("Error reading content.")); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } content[content_length] = '\0'; } else { do_error_page(_("Unknown Method.")); free(config); return -1; } hex_to_ascii(content); name = strtok(content,"&"); if(name == NULL) { fprintf(stderr,"name was null\n"); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } val = strtok('\0',"\0"); if(!(val)) { do_error_page(_("Error: NULL Search value. Please, hit the back button on your browser and search again.")); if(content != NULL) free(content); if(config != NULL) free(config); return 0; } strtok(val,"="); value = strtok('\0',"\0"); if(!(value)) { do_error_page(_("Error: NULL Search value. Please, hit the back button on your browser and search again.")); if(content != NULL) free(content); if(config != NULL) free(config); return 0; } /* Test value for SQL injection */ if( (strchr(value, '\'') != NULL) || (strchr(value, ';') != NULL) ) { do_error_page(_("The characters ' and ; are currently not allowed in queries.")); if(content != NULL) free(content); if(config != NULL) free(config); return 0; } /* Make the DB Connection. */ conn = db_connect(config); if(conn == NULL) { fprintf(stderr,"Failed to connect to the db.\n"); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } print_header(_("Search Results:")); if(strcmp("stype=uid",name) == 0) { search_by_uid(conn,value,config); } else if(strcmp("stype=fp",name) == 0) { rslt = search_by_fingerprint(conn,value,config); if(rslt != 0) { fprintf(stderr,"Function search_by_fingerprint() returned and error: %d\n", rslt); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } } else if(strcmp("stype=keyid_4b",name) == 0) { if(memcmp(value,"00000000",8) == 0) { print_pgp5_x509_note(); } else { search_by_keyid(conn,value,config); } } else if(strcmp("stype=keyid_8b",name) == 0) { search_by_fkeyid(conn,value,config); } else if(strcmp("stype=keyring",name) == 0) { search_ret_keyring(conn,value,config); } else if(strcmp("stype=signers",name) == 0) { search_ret_with_signers(conn,value,config); } else { do_error_page(_("Invalid query. Search type not understood.")); db_disconnect(conn); if(content != NULL) free(content); if(config != NULL) free(config); return 0; } print_footer(); db_disconnect(conn); if(content != NULL) free(content); if(config != NULL) free(config); return 0; }
int main(void) { struct cks_config *config = NULL; PGconn *conn = NULL; char *method = NULL; char *content = NULL; unsigned int content_length = 0; char *name = NULL; char *val = NULL; char *value = NULL; unsigned char *fingerprint = NULL; int rslt = 0; int tmp_var = 0; config = (struct cks_config *)malloc(sizeof(struct cks_config)); if(config == NULL) { fprintf(stderr, "Failed to malloc config\n"); return -1; } rslt = init_config(&config); if(rslt == -1) { fprintf(stderr,_("cks: cks_keyimg.c: Non-Fatal Error: Failed to read config.\n")); fprintf(stderr,_("cks: cks_keyimg.c: Using default configuration information.\n")); } conn = db_connect(config); if(conn == NULL) { do_error_page(_("Failed to connect to postgres database.")); fprintf(stderr,_("cks: cks_keyimg.c: Connection to database failed.\n")); fprintf(stderr,"cks: cks_keyimg.c: %s", PQerrorMessage(conn)); db_disconnect(conn); if(config != NULL) free(config); return -1; } #ifdef DEBUG fingerprint = (char *)malloc(100); strcpy(fingerprint,"72F871AD580481D14C84CADC08B779A592987FBD"); #else method = getenv("REQUEST_METHOD"); if(method == NULL) { fprintf(stderr,"Method was null.\n"); db_disconnect(conn); if(config != NULL) free(config); return 0; } if(method == NULL) { fprintf(stderr, _("search.c: Request Method is Null.\nExiting...\n")); db_disconnect(conn); if(config != NULL) free(config); return -1; } if(strcmp(method,"GET") == 0) { content_length = strlen(getenv("QUERY_STRING")); if(content_length > 300) { do_error_page(_("Content Length expectation exceeded\n")); db_disconnect(conn); if(config != NULL) free(config); return -1; } /* TODO: Make sure content length is not too small */ content = (char *)malloc(content_length+1); if(content == NULL) { do_error_page(_("Server was unable to malloc memory. Server out of memory.")); db_disconnect(conn); if(config != NULL) free(config); return -1; } strncpy(content,getenv("QUERY_STRING"),content_length); } hex_to_ascii(content); value = (unsigned char *)malloc(content_length+1); if(value == NULL) { do_error_page("cks_keyimg.c: Malloc call failed. Out of Memory.\n"); db_disconnect(conn); if(config != NULL) free(config); return -1; } fingerprint = (unsigned char *)malloc(content_length+1); if(fingerprint == NULL) { do_error_page("cks_keyimg.c: Malloc call failed. Out of Memory.\n"); db_disconnect(conn); if(config != NULL) free(config); return -1; } strncpy(value,content,41); strncpy(fingerprint,content,41); if(!(value)) { do_error_page(_("Error: NULL Search value. Please, hit the back button on your browser and search again.")); if(value != NULL) { free(value); } if(fingerprint != NULL) { free(fingerprint); } db_disconnect(conn); if(config != NULL) free(config); return 0; } /* TODO: Move this up higher so we don't have to do the allocs if there's bad code */ /* Test value for SQL injection */ if( (strchr(value, '\'') != NULL) || (strchr(value, ';') != NULL) ) { do_error_page(_("The characters ' and ; are currently not allowed in queries.")); if(value != NULL) { free(value); } if(fingerprint != NULL) { free(fingerprint); } db_disconnect(conn); if(config != NULL) free(config); return 0; } #endif /* Search by Fingerprint */ remove_spaces(fingerprint); if(((strlen(fingerprint)) != 32) && ((strlen(fingerprint)) != 40)) { do_error_page(_("The characters ' and ; are currently not allowed in queries.")); if(value != NULL) { free(value); } if(fingerprint != NULL) { free(fingerprint); } db_disconnect(conn); if(config != NULL) free(config); return -1; } retrieve_key_and_display(conn,fingerprint,1,config); if(value != NULL) { free(value); } if(fingerprint != NULL) { free(fingerprint); } db_disconnect(conn); if(config != NULL) { free(config); } return 0; }
int retrieve_key_and_display(PGconn *conn, char *fingerprint, unsigned int full,struct cks_config *config) { unsigned long i = 0; FILE *test = NULL; struct openPGP_packet *walk_packet = NULL; int rslt = 0; key_result = (struct openPGP_pubkey *)retrieve_pubkey(conn,fingerprint,D_SOURCE_ADD_CGI); if(key_result == NULL) { fprintf(stderr,_("Failed to retrieve key: %s\n"),fingerprint); do_error_page(_("Failed to retrieve key from database.\n")); return -1; } rslt = parse_pubkey(&key_result,D_SOURCE_SEARCH_CGI); if(rslt == -1) { fprintf(stderr,_("cks: cks_keyimg.c: Failed to parse retrieved pubkey: %s\n"),fingerprint); return -1; } rslt = parse_packets(&key_result,D_SOURCE_SEARCH_CGI); if(rslt == -1) { fprintf(stderr,_("Failed to parse retrieved pubkey's packets: %s\n"),fingerprint); return -1; } // dump_pubkey_packet_info_stderr(key_result); if(NULL == (test = fopen("/tmp/test.jpg","w"))) { fprintf(stderr,"Failed to open out put file.\n"); return -1; } fprintf(stderr,"image_len = %lu\n",key_result->image_len); fputc(0xd8,test); fputc(0xff,test); fputc(0xe0,test); fputc(0xff,test); fputc(0x10,test); fputc(0x00,test); fputc(0x46,test); fputc(0x4a,test); fputc(0x46,test); fputc(0x49,test); fputc(0x01,test); fputc(0x00,test); for(i=0;i<key_result->image_len;i++) { fputc(key_result->img_data[i],test); } fclose(test); printf("Content-type: image/jpg\n\n"); printf("%c%c%c%c%c%c%c%c%c%c\n", 0xd8, 0xff, 0xe0, 0xff, 0x10, 0x00, 0x46, 0x4a, 0x46, 0x49, 0x01, 0x00); for(i=0;i<key_result->image_len;i++) { printf("%c",key_result->img_data[i]); } free_pubkey(&key_result); return rslt; }
int parse_v4_sig_sub_packets(struct openPGP_packet *packet,struct key_signature *new_sig,struct openPGP_pubkey *key_result) { unsigned long loop_index = 0; unsigned long total_lenbytes =0; unsigned long j = 0; unsigned long k = 0; unsigned long l = 0; unsigned long subpk_length = 0; #ifdef DEBUG fprintf(stderr,"Calling: parse_v4_sig_sub_packet\n"); #endif if( (packet == NULL) || (new_sig == NULL) ) { return -1; } total_lenbytes = ((packet->packet_data[4] << 8) + packet->packet_data[5]); loop_index = 6; total_lenbytes = total_lenbytes+6; /* printf("Parsing walk_sig = (struct key_signature *)get_first_sig(walk_id->signatures); while(walk_sig != NULL) { fprintf(stderr," pubkey->id->sig: %p\n",walk_sig); fprintf(stderr," pubkey->id->sig->the_packet: %p\n",walk_sig->the_packet); fprintf(stderr," pubkey->id->sig->the_packet->packet_data: %p\n",walk_sig->the_packet->packet_data); fprintf(stderr," pubkey->id->sig->the_packet->full_packet_data: %p\n",walk_sig->the_packet->full_packet_data); fprintf(stderr," pubkey->id->sig->prev: %p\n",walk_sig->prev); fprintf(stderr," pubkey->id->sig->next: %p\n",walk_sig->next); walk_sig = walk_sig->next; }Hashed Sub Packet Data.\n"); */ while(loop_index < total_lenbytes) { if(packet->packet_data[loop_index] < 192) { subpk_length = packet->packet_data[loop_index++]; } else if((packet->packet_data[loop_index] >= 192) && (packet->packet_data[loop_index] < 255)) { subpk_length = ((packet->packet_data[loop_index++] << 8) + packet->packet_data[loop_index++]); } else if(packet->packet_data[loop_index] == 255) { subpk_length = 0; /* TODO FIXME 4 octet scalar */ } /* echo_sig_subpkt_type(packet->packet_data[loop_index]); */ if(packet->packet_data[loop_index] == 0x03) { /* Signature Expiration Time */ /* int tmp_idx = 0; key_result->expiration_time = 0; tmp_idx = loop_index; tmp_idx++; echo_sig_subpkt_type(packet->packet_data[loop_index]); printf("Signature Expiration Time Detected.\n"); printf("Subpacket Length: %d\n", subpk_length); key_result->expiration_time = (packet->packet_data[tmp_idx] << 24); tmp_idx++; key_result->expiration_time += (packet->packet_data[tmp_idx] << 16); tmp_idx++; key_result->expiration_time += (packet->packet_data[tmp_idx] << 8); tmp_idx++; key_result->expiration_time += packet->packet_data[tmp_idx]; printf("%s\n",ctime(&(key_result->creation_time))); key_result->expiration_time += key_result->creation_time; printf("0x%0.8x\n", key_result->expiration_time); printf("%s\n",ctime(&(key_result->expiration_time))); fflush(0); */ } else if(packet->packet_data[loop_index] == 0x09) { int tmp_idx = 0; key_result->expiration_time = 0; tmp_idx = loop_index; tmp_idx++; key_result->expiration_time = (packet->packet_data[tmp_idx] << 24); tmp_idx++; key_result->expiration_time += (packet->packet_data[tmp_idx] << 16); tmp_idx++; key_result->expiration_time += (packet->packet_data[tmp_idx] << 8); tmp_idx++; key_result->expiration_time += packet->packet_data[tmp_idx]; key_result->expiration_time += key_result->creation_time; } else if(packet->packet_data[loop_index] == 0x10) { k = 0; l = 0; l = loop_index; l++; for(j=0;j<8;j++) { new_sig->key_id[k++] = packet->packet_data[l++]; } new_sig->lkeyid = (new_sig->key_id[4] << 24) | (new_sig->key_id[5] << 16) | (new_sig->key_id[6] << 8) | new_sig->key_id[7]; } else if(packet->packet_data[loop_index] == 23) /* Keyserver Prefs */ { if(packet->packet_data[loop_index+1] = 0x80) { /* key_result-> */ /* TODO FIXME we should set no modify here, but i'm not sure if we should do it on the pubkey or on individual keys and subkeys. */ } } else if(packet->packet_data[loop_index] == 29) { /* Reason For Revocation */ /* 0x00 - No reason specified (key revocations or cert revocations) 0x01 - Key is superceded (key revocations) 0x02 - Key material has been compromised (key revocations) 0x03 - Key is no longer used (key revocations) 0x20 - User id information is no longer valid (cert revocations) */ /* The Length of the subpackets is the length of the reason plus one */ } for(j=0;j<subpk_length;j++) { if(loop_index > total_lenbytes) { fprintf(stderr,"parse.c 1522: Error.\n"); fprintf(stderr,"Parse Faliled, invalid lengths\n"); fprintf(stderr,"loop_index: %lu total_lenbytes: %lu\n", loop_index,total_lenbytes); return -1; } loop_index++; } } /* Start Processing Unhashed subpacket Data. */ /* printf("Parsing Unhased subpacket Data %d\n", loop_index); */ /* while(i < packet->packet_length) { printf("%d: 0x%0.2x\n",i,packet->packet_data[i++]); }*/ /* printf("%d %d\n",loop_index, packet->packet_length); */ if(loop_index > packet->packet_length) { fprintf(stderr, _("Invalid Packet.\n")); do_error_page(_("Invalid Packet.")); key_result->key_status = -1; return -1; } total_lenbytes = 0; total_lenbytes = (packet->packet_data[loop_index++] << 8); total_lenbytes = total_lenbytes + packet->packet_data[loop_index++]; total_lenbytes = total_lenbytes + loop_index; while(loop_index < total_lenbytes) { if(packet->packet_data[loop_index] < 192) { subpk_length = packet->packet_data[loop_index++]; } else { subpk_length = ((packet->packet_data[loop_index++] << 8) + packet->packet_data[loop_index++]); } /* echo_sig_subpkt_type(packet->packet_data[loop_index]); */ if(packet->packet_data[loop_index] == 0x03) { /* int tmp_idx = 0; key_result->expiration_time = 0; tmp_idx = loop_index; tmp_idx++; echo_sig_subpkt_type(packet->packet_data[loop_index]); printf("Signature Expiration Time Detected.\n"); printf("Subpacket Length: %d\n", subpk_length); key_result->expiration_time = (packet->packet_data[tmp_idx] << 24); tmp_idx++; key_result->expiration_time += (packet->packet_data[tmp_idx] << 16); tmp_idx++; key_result->expiration_time += (packet->packet_data[tmp_idx] << 8); tmp_idx++; key_result->expiration_time += packet->packet_data[tmp_idx]; printf("%s\n",ctime(&(key_result->creation_time))); key_result->expiration_time += key_result->creation_time; printf("0x%0.8x\n", key_result->expiration_time); printf("%s\n",ctime(&(key_result->expiration_time))); fflush(0); */ } else if(packet->packet_data[loop_index] == 0x09) { int tmp_idx = 0; key_result->expiration_time = 0; tmp_idx = loop_index; tmp_idx++; key_result->expiration_time = (packet->packet_data[tmp_idx] << 24); tmp_idx++; key_result->expiration_time += (packet->packet_data[tmp_idx] << 16); tmp_idx++; key_result->expiration_time += (packet->packet_data[tmp_idx] << 8); tmp_idx++; key_result->expiration_time += packet->packet_data[tmp_idx]; key_result->expiration_time += key_result->creation_time; } else if(packet->packet_data[loop_index] == 0x10) { k = 0; l = 0; l = loop_index; l++; for(j=0;j<8;j++) { new_sig->key_id[k++] = packet->packet_data[l++]; } new_sig->lkeyid = (new_sig->key_id[4] << 24) | (new_sig->key_id[5] << 16) | (new_sig->key_id[6] << 8) | new_sig->key_id[7]; /* printf("\n0x%0.8x\n\n",new_sig->lkeyid); */ } loop_index=0; for(j=0;j<total_lenbytes;j++) { loop_index++; } } return 0; }