00001
00002
00003
00004 #include "asm_message_parser.h"
00005 #include "../include/xml_helper.h"
00006 #ifndef _WIN32
00007 #include "config.h"
00008 #else
00009 #include "../winconfig.h"
00010 #endif
00011 #ifdef MC_SECURITY
00012
00013 error_code_t
00014 asm_message_parse(asm_node_p asm_node)
00015 {
00016 xml_parser_t xml_parser;
00017 xml_parser.root = asm_node->xml_encrypt_root;
00018 xml_parser.node = asm_node->xml_encrypt_root;
00019 return asm_message_parse__encryption_data(asm_node, &xml_parser);
00020 }
00021
00022 error_code_t
00023 asm_message_parse__encryption_data
00024 (
00025 asm_node_p asm_node,
00026 xml_parser_p xml_parser
00027 )
00028 {
00029 int ret;
00030 const mxml_node_t *encryption_data_node;
00031 const char* attribute;
00032
00033 if (
00034 strcmp(
00035 (const char*)xml_get_element_name((const mxml_node_t*)xml_parser->node),
00036 "ENCRYPTION_DATA"
00037 )
00038 )
00039 {
00040 return MC_ERR_PARSE;
00041 }
00042 encryption_data_node = xml_parser->node;
00043
00044 attribute = mxmlElementGetAttr
00045 (
00046 (mxml_node_t*)xml_parser->node,
00047 "protocol"
00048 );
00049 if (!strcmp(attribute, "diffie-hellman")) {
00050 xml_parser->node = xml_get_child
00051 (
00052 encryption_data_node,
00053 "P",
00054 1
00055 );
00056 ret = asm_message_parse__p(asm_node, xml_parser);
00057 if (ret)
00058 return ret;
00059 xml_parser->node = xml_get_child
00060 (
00061 encryption_data_node,
00062 "G",
00063 1
00064 );
00065 ret = asm_message_parse__g(asm_node, xml_parser);
00066 if(ret)
00067 return ret;
00068 xml_parser->node = xml_get_child
00069 (
00070 encryption_data_node,
00071 "Y",
00072 1
00073 );
00074 ret = asm_message_parse__y(asm_node, xml_parser);
00075 if(ret) return ret;
00076 } else {
00077
00078 return MC_ERR_PARSE;
00079 }
00080 return MC_SUCCESS;
00081 }
00082
00083 error_code_t
00084 asm_message_parse__p(asm_node_p asm_node, xml_parser_p xml_parser)
00085 {
00086 char* P;
00087 error_code_t ret = MC_SUCCESS;
00088 if (xml_parser->node == NULL) {
00089 return MC_ERR_PARSE;
00090 }
00091 P = xml_get_text(xml_parser->node);
00092 if (P != NULL) {
00093 if (mpi_read_string(&(asm_node->data.dh_data->dhm.P), 16, P)) {
00094 fprintf(stderr, "Parse error. %s:%d\n", __FILE__, __LINE__);
00095 ret = MC_ERR_PARSE;
00096 }
00097 goto cleanup;
00098 } else {
00099 ret = MC_ERR_PARSE;
00100 return ret;
00101 }
00102
00103 cleanup:
00104 if(P!=NULL)
00105 free(P);
00106 return ret;
00107 }
00108
00109 error_code_t
00110 asm_message_parse__g(asm_node_p asm_node, xml_parser_p xml_parser)
00111 {
00112 char* G;
00113 error_code_t ret = MC_SUCCESS;
00114 if (xml_parser->node == NULL) {
00115 return MC_ERR_PARSE;
00116 }
00117 G = xml_get_text(xml_parser->node);
00118 if (G == NULL) { ret = MC_ERR_PARSE; goto cleanup; }
00119
00120 if(mpi_read_string(&(asm_node->data.dh_data->dhm.G), 16, G)) {
00121 fprintf(stderr, "Parse error. %s:%d\n", __FILE__, __LINE__);
00122 ret = MC_ERR_PARSE;
00123 }
00124
00125 cleanup:
00126 if(G!=NULL)
00127 free(G);
00128 return ret;
00129 }
00130
00131 error_code_t
00132 asm_message_parse__y(asm_node_p asm_node, xml_parser_p xml_parser)
00133 {
00134 char* Y;
00135 error_code_t ret = MC_SUCCESS;
00136 if (xml_parser->node == NULL) {
00137 return MC_ERR_PARSE;
00138 }
00139 Y = xml_get_text(xml_parser->node);
00140 if(Y == NULL) {ret = MC_ERR_PARSE; goto cleanup;}
00141 if(mpi_read_string(&(asm_node->data.dh_data->dhm.GY), 16, Y)) {
00142 fprintf(stderr, "Parse error. %s:%d\n", __FILE__, __LINE__);
00143 ret = MC_ERR_PARSE;
00144 }
00145
00146 cleanup:
00147 if(Y!=NULL)
00148 free(Y);
00149 return ret;
00150 }
00151 #endif