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