Lime gives more explicit warning messages

This commit is contained in:
Johan Pascal 2014-07-13 00:31:58 +02:00
parent f6eb21ad82
commit cb4b534a4d
3 changed files with 34 additions and 2 deletions

View file

@ -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);

View file

@ -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";
}

View file

@ -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 */