Fix handling of file transfer content key.

This commit is contained in:
Ghislain MARY 2018-04-25 14:52:25 +02:00
parent db15df1b2d
commit 86614b1a15
4 changed files with 7 additions and 17 deletions

View file

@ -40,7 +40,6 @@ L_DECLARE_C_CLONABLE_OBJECT_IMPL_WITH_XTORS(Content,
void *cryptoContext; // Used to encrypt file for RCS file transfer.
mutable size_t size;
mutable char *key;
struct Cache {
string name;
@ -213,15 +212,12 @@ const char *linphone_content_get_custom_header (const LinphoneContent *content,
}
const char *linphone_content_get_key (const LinphoneContent *content) {
if (content->key) bctbx_free(content->key);
const LinphonePrivate::Content *c = L_GET_CPP_PTR_FROM_C_OBJECT(content);
if (c->isFileTransfer()) {
const LinphonePrivate::FileTransferContent *ftc = static_cast<const LinphonePrivate::FileTransferContent *>(c);
content->key = bctbx_strdup(ftc->getFileKeyAsString());
return ftc->getFileKey().data();
}
return content->key;
return nullptr;
}
size_t linphone_content_get_key_size (const LinphoneContent *content) {

View file

@ -318,9 +318,9 @@ void FileTransferChatMessageModifier::processResponseFromPostFile (const belle_h
const char *body = belle_sip_message_get_body((belle_sip_message_t *)event->response);
if (body && strlen(body) > 0) {
// if we have an encryption key for the file, we must insert it into the msg and restore the correct filename
const char *content_key = fileTransferContent->getFileKeyAsString();
size_t content_key_size = fileTransferContent->getFileKey().size();
if (content_key_size > 0) {
const unsigned char *contentKey = reinterpret_cast<const unsigned char *>(fileTransferContent->getFileKey().data());
size_t contentKeySize = fileTransferContent->getFileKeySize();
if (contentKeySize > 0) {
// parse the msg body
xmlDocPtr xmlMessageBody = xmlParseDoc((const xmlChar *)body);
@ -337,11 +337,11 @@ void FileTransferChatMessageModifier::processResponseFromPostFile (const belle_h
xmlNodePtr fileInfoNodeChildren = cur->xmlChildrenNode;
// convert key to base64
size_t b64Size;
bctbx_base64_encode(nullptr, &b64Size, (unsigned char *)content_key, content_key_size);
bctbx_base64_encode(nullptr, &b64Size, contentKey, contentKeySize);
unsigned char *keyb64 = (unsigned char *)ms_malloc0(b64Size + 1);
int xmlStringLength;
bctbx_base64_encode(keyb64, &b64Size, (unsigned char *)content_key, content_key_size);
bctbx_base64_encode(keyb64, &b64Size, contentKey, contentKeySize);
keyb64[b64Size] = '\0'; // libxml need a null terminated string
// add the node containing the key to the file-info node

View file

@ -164,11 +164,6 @@ const vector<char> &FileTransferContent::getFileKey () const {
return d->fileKey;
}
const char *FileTransferContent::getFileKeyAsString() const {
L_D();
return d->fileKey.data();
}
size_t FileTransferContent::getFileKeySize() const {
L_D();
return d->fileKey.size();

View file

@ -59,7 +59,6 @@ public:
void setFileKey (const char *key, size_t size);
const std::vector<char> &getFileKey () const;
const char *getFileKeyAsString () const;
size_t getFileKeySize() const;
bool isFile () const override;