From cb4b534a4d4d68c630d70550ddac081172f1d794 Mon Sep 17 00:00:00 2001 From: Johan Pascal Date: Sun, 13 Jul 2014 00:31:58 +0200 Subject: [PATCH] Lime gives more explicit warning messages --- coreapi/bellesip_sal/sal_op_message.c | 4 ++-- coreapi/lime.c | 13 +++++++++++++ coreapi/lime.h | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/coreapi/bellesip_sal/sal_op_message.c b/coreapi/bellesip_sal/sal_op_message.c index 3e0100b4c..270bc0561 100644 --- a/coreapi/bellesip_sal/sal_op_message.c +++ b/coreapi/bellesip_sal/sal_op_message.c @@ -129,7 +129,7 @@ void sal_process_incoming_message(SalOp *op,const belle_sip_request_event_t *eve free(cacheString); int retval = lime_decryptMultipartMessage(cacheXml, (uint8_t *)belle_sip_message_get_body(BELLE_SIP_MESSAGE(req)), &decryptedMessage); if (retval != 0) { - ms_warning("Unable to decrypt message, reason %x", retval); + ms_warning("Unable to decrypt message, reason : %s - op [%p]", lime_error_code_to_string(retval), op); free(decryptedMessage); xmlFreeDoc(cacheXml); resp = belle_sip_response_create_from_request(req,488); @@ -266,7 +266,7 @@ int sal_message_send(SalOp *op, const char *from, const char *to, const char* co free(cacheString); int retval = lime_createMultipartMessage(cacheXml, (uint8_t *)msg, (uint8_t *)peer_uri, &multipartEncryptedMessage); if (retval != 0) { - ms_warning("Unable to encrypt message for %s error %x", peer_uri, retval); + ms_warning("Unable to encrypt message for %s : %s - op [%p]", peer_uri, lime_error_code_to_string(retval), op); xmlFreeDoc(cacheXml); free(multipartEncryptedMessage); sal_error_info_set(&op->error_info, SalReasonNotAcceptable, 488, "Unable to encrypt IM", NULL); diff --git a/coreapi/lime.c b/coreapi/lime.c index c9f499ede..045d4be5d 100644 --- a/coreapi/lime.c +++ b/coreapi/lime.c @@ -755,3 +755,16 @@ int lime_decryptMultipartMessage(xmlDocPtr cacheBuffer, uint8_t *message, uint8_ return 0; } + +char *lime_error_code_to_string(int errorCode) { + switch (errorCode) { + case LIME_INVALID_CACHE: return "Invalid ZRTP cache"; + case LIME_UNABLE_TO_DERIVE_KEY: return "Unable to derive Key"; + case LIME_UNABLE_TO_ENCRYPT_MESSAGE: return "Unable to encrypt message"; + case LIME_UNABLE_TO_DECRYPT_MESSAGE: return "Unable to decrypt message"; + case LIME_NO_VALID_KEY_FOUND_FOR_PEER: return "No valid key found"; + case LIME_INVALID_ENCRYPTED_MESSAGE: return "Invalid encrypted message"; + } + return "Unknow error"; + +} diff --git a/coreapi/lime.h b/coreapi/lime.h index dfaf3d866..861c9acd7 100644 --- a/coreapi/lime.h +++ b/coreapi/lime.h @@ -169,5 +169,24 @@ __attribute__ ((visibility ("default"))) int lime_decryptMessage(limeKey_t *key, * @return 0 on success, error code otherwise */ __attribute__ ((visibility ("default"))) int lime_createMultipartMessage(xmlDocPtr cacheBuffer, uint8_t *message, uint8_t *peerURI, uint8_t **output); + +/** + * @brief decrypt a multipart xml message + * Retrieve in cache the needed key which is then updated. Output buffer is allocated and must be freed by caller + * + * @param[in/out] cacheBuffer The xmlDoc containing current cache, get the key and selfZID from it, updated by this function with derivated keys + * @param[in] message The multipart message, contain one or several part identified by destination ZID, one shall match the self ZID retrieved from cache + * @param[out] output The output buffer, allocated and set with the decrypted message(null terminated string). Must be freed by caller + * + * @return 0 on success, error code otherwise + */ + __attribute__ ((visibility ("default"))) int lime_decryptMultipartMessage(xmlDocPtr cacheBuffer, uint8_t *message, uint8_t **output); + +/** + * @brief given a readable version of error code generated by Lime functions + * @param[in] errorCode The error code + * @return a string containing the error description + */ +char *lime_error_code_to_string(int errorCode); #endif /* LIME_H */