/home/dko/projects/mobilec/trunk/src/security/asm_message_composer.c

Go to the documentation of this file.
00001 #include "asm_message_composer.h"
00002 #include "config.h"
00003 #include "../include/mc_platform.h"
00004 #ifdef MC_SECURITY
00005 
00006 mxml_node_t*
00007 message_xml_compose__RequestEncryptionInit(mc_platform_p mc_platform)
00008 {
00009   char* buf;
00010   mxml_node_t* node;
00011   mxml_node_t* gaf_message_node;
00012   mxml_node_t* message_node;
00013   char xml_root_string[] = 
00014     "<?xml version=\"1.0\"?>";
00015   node = mxmlLoadString
00016     (
00017      NULL,
00018      xml_root_string,
00019      MXML_NO_CALLBACK
00020     );
00021 
00022   gaf_message_node = mxmlNewElement
00023     (
00024      node,
00025      "GAF_MESSAGE"
00026     );
00027   message_node = mxmlNewElement
00028     (
00029      gaf_message_node,
00030      "MESSAGE"
00031     );
00032   mxmlElementSetAttr
00033     (
00034      message_node,
00035      "message",
00036      "REQUEST_ENCRYPTION_INITIALIZE"
00037     );
00038   buf = (char*)malloc
00039     (
00040      sizeof(char) * 
00041      (strlen(mc_platform->hostname)+10)
00042     );
00043   sprintf(buf, "%s:%d", mc_platform->hostname, mc_platform->port);
00044   mxmlElementSetAttr
00045     (
00046      message_node,
00047      "from",
00048      buf
00049     );
00050   free(buf);
00051   return node;
00052 }
00053   
00054 mxml_node_t*
00055 message_xml_compose__EncryptionInitialize(mc_asm_p security_manager)
00056 {
00057   char* buf;
00058   mxml_node_t *node;
00059   mxml_node_t *gaf_message_node;
00060   mxml_node_t *message_node;
00061   node = mxmlLoadString
00062     (
00063      NULL,
00064      "<?xml version=\"1.0\"?>\n<!DOCTYPE myMessage SYSTEM \"gafmessage.dtd\">",
00065      MXML_NO_CALLBACK
00066     );
00067   gaf_message_node = mxmlNewElement
00068     (
00069      node,
00070      "GAF_MESSAGE"
00071     );
00072   message_node = mxmlNewElement
00073     (
00074      gaf_message_node,
00075      "MESSAGE"
00076     );
00077   mxmlElementSetAttr
00078     (
00079      message_node,
00080      "message",
00081      "ENCRYPTION_INITIALIZE"
00082     );
00083   buf = (char*)malloc
00084     (
00085      sizeof(char) * 
00086      (strlen(security_manager->mc_platform->hostname)+10)
00087     );
00088   sprintf
00089     (
00090      buf, 
00091      "%s:%d", 
00092      security_manager->mc_platform->hostname,
00093      security_manager->mc_platform->port
00094     );
00095   mxmlElementSetAttr
00096     (
00097      message_node,
00098      "from",
00099      buf
00100     );
00101   free(buf);
00102 
00103   mxmlAdd
00104     (
00105      message_node,
00106      MXML_ADD_AFTER,
00107      MXML_ADD_TO_PARENT,
00108      message_xml_compose__encryption_data(security_manager)
00109     );
00110   return node;
00111 }
00112 
00113 mxml_node_t*
00114 message_xml_compose__encryption_data(mc_asm_p security_manager)
00115 {
00116   mxml_node_t* node;
00117   node = mxmlNewElement
00118     (
00119      NULL,
00120      "ENCRYPTION_DATA"
00121     );
00122   mxmlElementSetAttr
00123     (
00124      node,
00125      "protocol",
00126      "diffie-hellman"
00127     );
00128   mxmlAdd
00129     (
00130      node,
00131      MXML_ADD_AFTER,
00132      MXML_ADD_TO_PARENT,
00133      message_xml_compose__p(security_manager)
00134     );
00135   mxmlAdd
00136     (
00137      node,
00138      MXML_ADD_AFTER,
00139      MXML_ADD_TO_PARENT,
00140      message_xml_compose__g(security_manager)
00141     );
00142   mxmlAdd
00143     (
00144      node,
00145      MXML_ADD_AFTER,
00146      MXML_ADD_TO_PARENT,
00147      message_xml_compose__y(security_manager)
00148     );
00149   return node;
00150 }
00151 
00152 mxml_node_t*
00153 message_xml_compose__p(mc_asm_p security_manager)
00154 {
00155   mxml_node_t* node = NULL;
00156   int p_len = 0;
00157   char *string = NULL;
00158   node = mxmlNewElement
00159     (
00160      NULL,
00161      "P"
00162     );
00163   mpi_write_string
00164     (
00165      &(security_manager->home_encryption_info->data.dh_data->dhm.P),
00166      16,
00167      string,
00168      &p_len
00169     );
00170   string = (char*) malloc
00171     (
00172      sizeof(char) * p_len
00173     );
00174   CHECK_NULL(string, exit(0););
00175   if
00176     (
00177      mpi_write_string
00178      (
00179       &(security_manager->home_encryption_info->data.dh_data->dhm.P),
00180       16,
00181       string,
00182       &p_len
00183      )
00184     )
00185     {
00186       goto err_cleanup;
00187     }
00188   mxmlNewText
00189     (
00190      node,
00191      0,
00192      string
00193     );
00194   free(string);
00195   return node;
00196 
00197 err_cleanup:
00198   fprintf(stderr, "Error. %s:%d\n", __FILE__,__LINE__);
00199   if(string) free(string);
00200   if(node) mxmlDelete(node);
00201   return NULL;
00202 }
00203 
00204 mxml_node_t*
00205 message_xml_compose__g(mc_asm_p security_manager)
00206 {
00207   mxml_node_t* node = NULL;
00208   int p_len = 0;
00209   char *string = NULL;
00210   node = mxmlNewElement
00211     (
00212      NULL,
00213      "G"
00214     );
00215   mpi_write_string
00216     (
00217      &(security_manager->home_encryption_info->data.dh_data->dhm.G),
00218      16,
00219      string,
00220      &p_len
00221     );
00222   string = (char*) malloc
00223     (
00224      sizeof(char) * p_len
00225     );
00226   CHECK_NULL(string, exit(0););
00227   if
00228     (
00229      mpi_write_string
00230      (
00231       &(security_manager->home_encryption_info->data.dh_data->dhm.G),
00232       16,
00233       string,
00234       &p_len
00235      )
00236     )
00237     {
00238       goto err_cleanup;
00239     }
00240   mxmlNewText
00241     (
00242      node,
00243      0,
00244      string
00245     );
00246   free(string);
00247   return node;
00248 
00249 err_cleanup:
00250   fprintf(stderr, "Error. %s:%d\n", __FILE__,__LINE__);
00251   if(string) free(string);
00252   if(node) mxmlDelete(node);
00253   return NULL;
00254 }
00255 
00256 mxml_node_t*
00257 message_xml_compose__y(mc_asm_p security_manager)
00258 {
00259   mxml_node_t* node = NULL;
00260   int p_len = 0;
00261   char *string = NULL;
00262   node = mxmlNewElement
00263     (
00264      NULL,
00265      "Y"
00266     );
00267   mpi_write_string
00268     (
00269      &(security_manager->home_encryption_info->data.dh_data->dhm.GX),
00270      16,
00271      string,
00272      &p_len
00273     );
00274   string = (char*) malloc
00275     (
00276      sizeof(char) * p_len
00277     );
00278   CHECK_NULL(string, exit(0););
00279   if
00280     (
00281      mpi_write_string
00282      (
00283       &(security_manager->home_encryption_info->data.dh_data->dhm.GX),
00284       16,
00285       string,
00286       &p_len
00287      )
00288     )
00289     {
00290       goto err_cleanup;
00291     }
00292   mxmlNewText
00293     (
00294      node,
00295      0,
00296      string
00297     );
00298   free(string);
00299   return node;
00300 
00301 err_cleanup:
00302   fprintf(stderr, "Error. %s:%d\n", __FILE__,__LINE__);
00303   if(string) free(string);
00304   if(node) mxmlDelete(node);
00305   return NULL;
00306 }
00307 
00308 #endif /* MC_SECURITY */

Generated on Fri May 16 14:49:55 2008 for Mobile-C by  doxygen 1.5.4