Changeset 565

Show
Ignore:
Timestamp:
03/25/07 13:27:28 (2 years ago)
Author:
sacha
Message:

changed the way how to determine first mime part (soap message).
this version supports cases where the first mime part (soap message) has a Content-Id.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src-c/xmldsig-signing-ebXML-user-message/hefeweizen_sign_ebXML_user_message.c

    r549 r565  
    107107char* file_path; 
    108108 
    109 const debug = 1
     109const debug = 0
    110110 
    111111char* get_temp_filename(); 
     
    119119int replace_soap_header(const char* multipart_mime_file, xmlChar* signed_soap_mem, const char* output_file_name); 
    120120int replace_soap_header_y(const char* multipart_mime_file, const char* temp_output_file_name, const char* output_file_name); 
     121 
     122int foreach_callback_soap_soap_found = 0; 
     123int foreach_callback_payload_soap_passed = 0; 
    121124 
    122125/** 
     
    359362foreach_callback_soap(GMimeObject *part, gpointer user_data) 
    360363{ 
    361   const char* content_id = NULL; 
    362364  GMimeDataWrapper *content; 
    363365  const char *filename; 
     
    365367  int fd2; 
    366368 
    367   content_id = g_mime_part_get_content_id((GMimePart *)part);   
    368  
    369   /* The first mime part has no content id. That is where the SOAP message is. */ 
    370   if (content_id != NULL)
     369  if (foreach_callback_soap_soap_found == 0){ 
     370    foreach_callback_soap_soap_found = 1; 
     371  } 
     372  else
    371373    return; 
    372374  } 
    373    
     375 
    374376  if ((fd2 = open (soap_file_path, O_CREAT | O_WRONLY | O_TRUNC, 0666)) == -1) { 
    375377    fprintf(stdout, "ERRROR creating output file"); 
     
    392394} 
    393395 
    394 static void  
    395 foreach_callback_soapx(GMimeObject *part, gpointer user_data) 
    396 { 
    397   const char* content_id = NULL; 
    398   GMimeDataWrapper *content; 
    399   const char *filename; 
    400   GMimeStream *stream; 
    401   int fd2; 
    402  
    403   content_id = g_mime_part_get_content_id((GMimePart *)part);   
    404  
    405   /* The first mime part has no content id. That is where the SOAP message is. */ 
    406   if (content_id != NULL) { 
    407     return; 
    408   } 
    409    
    410   if ((fd2 = open (soap_file_path, O_CREAT | O_WRONLY | O_TRUNC, 0666)) == -1) { 
    411     fprintf(stdout, "ERRROR creating output file"); 
    412     return; 
    413   } 
    414    
    415   /* writing the content to the soap file path */ 
    416   stream = g_mime_stream_fs_new (fd2); 
    417   content = g_mime_part_get_content_object ((GMimePart*)part); 
    418   g_mime_data_wrapper_write_to_stream (content, stream); 
    419   g_mime_stream_flush (stream); 
    420    
    421   g_object_unref (content); 
    422   g_object_unref (stream); 
    423    
    424   close(fd2); 
    425    
    426   soap_message_read_done = 1; 
    427  
    428 } 
    429  
    430396 
    431397int replace_soap_header(const char* original_multipart_mime_file, xmlChar* signed_soap_mem, const char* final_output_file_name){ 
     
    447413  GMimePart* soap = (GMimePart*) g_mime_multipart_get_part(multipart, 0); 
    448414   
    449   fprintf(stdout, "Before strln: replace_soap_header"); 
     415  if (debug == 1) 
     416    fprintf(stdout, "Before strln: replace_soap_header"); 
     417 
    450418  g_mime_part_set_content(soap, (char*)signed_soap_mem, strlen(signed_soap_mem)); 
    451419  //  g_mime_multipart_set_boundary(multipart, "dddddddddddddddddddddddddd^M"); 
     
    454422  text = g_mime_message_to_string (message); 
    455423 
    456   fprintf(stdout, "Writing this mess: %s", text); 
     424  if (debug == 1) 
     425    fprintf(stdout, "Writing this mess: %s", text); 
     426 
     427  FILE* output_file = NULL; 
     428  //  char* file_name = "/tmp/final_output_soap_file"; 
     429  if ((output_file = fopen(final_output_file_name, "w")) == NULL) 
     430    fprintf(stderr, "Cannot open %s to write soap message.\n", final_output_file_name); 
     431 
     432  fprintf(output_file, "%s", text); 
     433 
     434  fclose(output_file); 
     435 
     436  g_free (text); 
     437  g_mime_object_unref (GMIME_OBJECT (message)); 
     438 
     439  xmlFree(signed_soap_mem); 
     440  return 0; 
     441   
     442
     443 
     444int replace_soap_header_y(const char* original_multipart_mime_file, const char* signed_soap_file_name, const char* final_output_file_name){ 
     445  GMimeMessage* message; 
     446  int fd; 
     447 
     448  if ((fd = open (multipart_mime_file, O_RDONLY)) == -1) { 
     449    fprintf (stderr, "Cannot open message `%s': %s to write soap message.\n", multipart_mime_file, strerror (errno)); 
     450    //    return -1; 
     451  } 
     452   
     453  message = parse_message(fd); 
     454  close(fd); 
     455 
     456  GMimeObject* part = NULL; 
     457  part = g_mime_message_get_mime_part(message); 
     458  GMimeMultipart* multipart = (GMimeMultipart*) part; 
     459 
     460  GMimePart* soap = (GMimePart*) g_mime_multipart_get_part(multipart, 0); 
     461   
     462  FILE * pFile; 
     463  long lSize; 
     464  char * buffer; 
     465  size_t result; 
     466 
     467  pFile = fopen ( signed_soap_file_name , "rb" ); 
     468  if (pFile==NULL) {fputs ("File error",stderr); return (-1);} 
     469 
     470  // obtain file size: 
     471  fseek (pFile , 0 , SEEK_END); 
     472  lSize = ftell (pFile); 
     473  rewind (pFile); 
     474 
     475  // allocate memory to contain the whole file: 
     476  buffer = (char*) malloc (sizeof(char)*lSize); 
     477  if (buffer == NULL) {fputs ("Memory error",stderr); return (-2);} 
     478 
     479  // copy the file into the buffer: 
     480  result = fread (buffer,1,lSize,pFile); 
     481  if (result != lSize) {fputs ("Reading error",stderr); return (-3);} 
     482 
     483  /* the whole file is now loaded in the memory buffer. */ 
     484   
     485  fprintf(stdout, "Before strlen: replace soap header_y"); 
     486  g_mime_part_set_content(soap, buffer, strlen(buffer)); 
     487 
     488  char* text; 
     489  text = g_mime_message_to_string (message); 
     490 
     491  if (debug == 1) 
     492    fprintf(stdout, "Writing this message: %s", text); 
    457493 
    458494  FILE* output_file = NULL; 
     
    466502  g_mime_object_unref (GMIME_OBJECT (message)); 
    467503 
    468   xmlFree(signed_soap_mem); 
    469   return 0; 
    470    
    471 } 
    472  
    473 int replace_soap_header_y(const char* original_multipart_mime_file, const char* signed_soap_file_name, const char* final_output_file_name){ 
    474   GMimeMessage* message; 
    475   int fd; 
    476  
    477   if ((fd = open (multipart_mime_file, O_RDONLY)) == -1) { 
    478     fprintf (stderr, "Cannot open message `%s': %s to write soap message.\n", multipart_mime_file, strerror (errno)); 
    479     //    return -1; 
    480   } 
    481    
    482   message = parse_message(fd); 
    483   close(fd); 
    484  
    485   GMimeObject* part = NULL; 
    486   part = g_mime_message_get_mime_part(message); 
    487   GMimeMultipart* multipart = (GMimeMultipart*) part; 
    488  
    489   GMimePart* soap = (GMimePart*) g_mime_multipart_get_part(multipart, 0); 
    490    
    491   fprintf(stdout, "HHHHHHHHHHHHHHHELO\n"); 
    492   fprintf(stdout, "HHHHHHHHHHHHHHHELO\n"); 
    493   fprintf(stdout, "HHHHHHHHHHHHHHHELO\n"); 
    494    
    495   FILE * pFile; 
    496   long lSize; 
    497   char * buffer; 
    498   size_t result; 
    499  
    500   pFile = fopen ( signed_soap_file_name , "rb" ); 
    501   if (pFile==NULL) {fputs ("File error",stderr); return (-1);} 
    502  
    503   // obtain file size: 
    504   fseek (pFile , 0 , SEEK_END); 
    505   lSize = ftell (pFile); 
    506   rewind (pFile); 
    507  
    508   // allocate memory to contain the whole file: 
    509   buffer = (char*) malloc (sizeof(char)*lSize); 
    510   if (buffer == NULL) {fputs ("Memory error",stderr); return (-2);} 
    511  
    512   // copy the file into the buffer: 
    513   result = fread (buffer,1,lSize,pFile); 
    514   if (result != lSize) {fputs ("Reading error",stderr); return (-3);} 
    515  
    516   /* the whole file is now loaded in the memory buffer. */ 
    517    
    518  
    519   fprintf(stdout, "HHHHHHHHHHHHHHHELO\n"); 
    520   fprintf(stdout, "Before strlen: replace soap header_y"); 
    521   g_mime_part_set_content(soap, buffer, strlen(buffer)); 
    522  
    523   char* text; 
    524   text = g_mime_message_to_string (message); 
    525  
    526   fprintf(stdout, "Writing this mess: %s", text); 
    527  
    528   FILE* output_file = NULL; 
    529   //  char* file_name = "/tmp/final_output_soap_file"; 
    530   if ((output_file = fopen(final_output_file_name, "w")) == NULL) 
    531     fprintf(stderr, "Cannot open %s to write soap message.\n", final_output_file_name); 
    532   fprintf(output_file, "%s", text); 
    533   fclose(output_file); 
    534  
    535   g_free (text); 
    536   g_mime_object_unref (GMIME_OBJECT (message)); 
    537  
    538504  // terminate 
    539505  fclose (pFile); 
     
    554520  int fd2; 
    555521 
     522  if (foreach_callback_payload_soap_passed == 0){ 
     523    foreach_callback_payload_soap_passed = 1; 
     524    return; 
     525  } 
     526 
    556527  if (debug == 1){ 
    557528    fprintf(stdout, "Getting content id of given mime part"); 
     
    559530  content_id = g_mime_part_get_content_id((GMimePart *)part); 
    560531 
    561   if (content_id == NULL) { 
    562     return; 
    563   } 
    564    
    565532  if (debug == 1) 
    566533    fprintf(stdout, "The content id is '%s' .\n", content_id ); 
     
    630597    fprintf(stdout, "new filename %s\n", payload_message_filename); 
    631598 
    632   //nnnnnnnnnnnnnnnnnnnnnn 
    633   fprintf(stdout, "Message %s", message); 
     599  if (debug == 1) 
     600    fprintf(stdout, "Message %s", message); 
     601 
     602  /* resetting the counter to find payload */ 
     603  foreach_callback_payload_soap_passed = 0; 
    634604 
    635605  g_mime_message_foreach_part (message, foreach_callback_payload, &count); 
  • trunk/src-c/xmldsig-validate-signature-ebXML-user-message/hefeweizen_validate_signature_ebXML_user_message.c

    r549 r565  
    7777static void foreach_callback_soap(GMimeObject *part, gpointer user_data); 
    7878 
     79int foreach_callback_soap_soap_found = 0; 
     80int foreach_callback_payload_soap_passed = 0; 
     81 
    7982xmlSecKeysMngrPtr load_trusted_certs(char** files, int files_size); 
    8083int verify_file(xmlSecKeysMngrPtr mngr, const char* xml_file, const char* temp_dir); 
     
    534537  int fd2; 
    535538 
     539  if (foreach_callback_payload_soap_passed == 0){ 
     540    foreach_callback_payload_soap_passed = 1; 
     541    return; 
     542  } 
     543 
     544  if (debug == 1){ 
     545    fprintf(stdout, "Getting content id of given mime part"); 
     546  } 
    536547  content_id = g_mime_part_get_content_id((GMimePart *)part); 
    537  
    538   if (content_id == NULL) { 
    539     return; 
    540   } 
    541548 
    542549  if (debug == 1){ 
     
    582589foreach_callback_soap(GMimeObject *part, gpointer user_data) 
    583590{ 
    584   const char* content_id = NULL; 
    585591  GMimeDataWrapper *content; 
    586592  const char *filename; 
     
    588594  int fd2; 
    589595 
    590   content_id = g_mime_part_get_content_id((GMimePart *)part);   
    591  
    592   /* The first mime part has no content id. That is where the SOAP message is. */ 
    593   if (content_id != NULL) { 
     596 
     597  if (foreach_callback_soap_soap_found == 0){ 
     598    foreach_callback_soap_soap_found = 1; 
     599  } 
     600  else{ 
    594601    return; 
    595602  } 
    596    
     603 
    597604  if ((fd2 = open (soap_file_path, O_CREAT | O_WRONLY | O_TRUNC, 0666)) == -1) { 
    598605    fprintf(stdout, "ERRROR creating output file"); 
     
    643650    fprintf(stdout, "new filename %s\n", payload_message_filename); 
    644651 
     652  /* resetting the counter to find payload */ 
     653  foreach_callback_payload_soap_passed = 0; 
    645654 
    646655  g_mime_message_foreach_part (message, foreach_callback_payload, &count);