mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Reformat HTTP get URL to AESGCM scheme
This commit is contained in:
parent
39c3290613
commit
e9d5875782
@ -95,6 +95,12 @@
|
|||||||
#ifdef HAVE_OMEMO
|
#ifdef HAVE_OMEMO
|
||||||
#include "omemo/omemo.h"
|
#include "omemo/omemo.h"
|
||||||
#include "xmpp/omemo.h"
|
#include "xmpp/omemo.h"
|
||||||
|
|
||||||
|
#define AESGCM_URL_SCHEME "aesgcm"
|
||||||
|
#define AESGCM_URL_NONCE_LEN 24
|
||||||
|
#define AESGCM_URL_KEY_LEN 64
|
||||||
|
#define AESGCM_URL_FRAGMENT_LEN \
|
||||||
|
(size_t)(AESGCM_URL_NONCE_LEN + AESGCM_URL_KEY_LEN)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_GTK
|
#ifdef HAVE_GTK
|
||||||
@ -4806,6 +4812,21 @@ cmd_disco(ProfWin* window, const char* const command, gchar** args)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *create_aesgcm_fragment(unsigned char *key, int key_size,
|
||||||
|
unsigned char *nonce, int nonce_size) {
|
||||||
|
char fragment[(nonce_size+key_size)*2+1];
|
||||||
|
|
||||||
|
for (int i = 0; i < nonce_size; i++) {
|
||||||
|
sprintf(&(fragment[i*2]), "%02x", nonce[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < key_size; i++) {
|
||||||
|
sprintf(&(fragment[(i+nonce_size)*2]), "%02x", key[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return strdup(fragment);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
||||||
{
|
{
|
||||||
@ -4849,6 +4870,8 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FILE *fh = fdopen(fd, "rb");
|
FILE *fh = fdopen(fd, "rb");
|
||||||
|
char *alt_scheme = NULL;
|
||||||
|
char *alt_fragment = NULL;
|
||||||
|
|
||||||
switch (window->type) {
|
switch (window->type) {
|
||||||
case WIN_MUC:
|
case WIN_MUC:
|
||||||
@ -4898,12 +4921,17 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
|||||||
fflush(tmpfh);
|
fflush(tmpfh);
|
||||||
rewind(tmpfh);
|
rewind(tmpfh);
|
||||||
|
|
||||||
fclose(fh);
|
fclose(fh); // Also closes descriptor.
|
||||||
|
|
||||||
// Switch original stream with temporary encrypted stream.
|
// Switch original stream with temporary encrypted stream.
|
||||||
fd = tmpfd;
|
fd = tmpfd;
|
||||||
fh = tmpfh;
|
fh = tmpfh;
|
||||||
|
|
||||||
|
alt_scheme = AESGCM_URL_SCHEME;
|
||||||
|
alt_fragment = create_aesgcm_fragment(
|
||||||
|
key, AES256_GCM_KEY_LENGTH,
|
||||||
|
nonce, AES256_GCM_NONCE_LENGTH);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4944,6 +4972,8 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
|||||||
upload->filehandle = fh;
|
upload->filehandle = fh;
|
||||||
upload->filesize = file_size(fd);
|
upload->filesize = file_size(fd);
|
||||||
upload->mime_type = file_mime_type(filename);
|
upload->mime_type = file_mime_type(filename);
|
||||||
|
upload->alt_scheme = alt_scheme;
|
||||||
|
upload->alt_fragment = alt_fragment;
|
||||||
|
|
||||||
iq_http_upload_request(upload);
|
iq_http_upload_request(upload);
|
||||||
|
|
||||||
|
@ -128,6 +128,33 @@ _data_callback(void* ptr, size_t size, size_t nmemb, void* data)
|
|||||||
return realsize;
|
return realsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int format_alt_url(char *original_url, char *new_scheme, char *new_fragment, char **new_url) {
|
||||||
|
int ret = 0;
|
||||||
|
CURLU *h = curl_url();
|
||||||
|
|
||||||
|
if ((ret = curl_url_set(h, CURLUPART_URL, original_url, 0)) != 0) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_scheme != NULL) {
|
||||||
|
if ((ret = curl_url_set(h, CURLUPART_SCHEME, new_scheme, CURLU_NON_SUPPORT_SCHEME)) != 0) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_fragment != NULL) {
|
||||||
|
if ((ret = curl_url_set(h, CURLUPART_FRAGMENT, new_fragment, 0)) != 0) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = curl_url_get(h, CURLUPART_URL, new_url, 0);
|
||||||
|
|
||||||
|
out:
|
||||||
|
curl_url_cleanup(h);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
http_file_put(void *userdata)
|
http_file_put(void *userdata)
|
||||||
{
|
{
|
||||||
@ -256,31 +283,41 @@ http_file_put(void* userdata)
|
|||||||
win_mark_received(upload->window, upload->put_url);
|
win_mark_received(upload->window, upload->put_url);
|
||||||
free(msg);
|
free(msg);
|
||||||
|
|
||||||
|
char *url = NULL;
|
||||||
|
if (format_alt_url(upload->get_url, upload->alt_scheme, upload->alt_fragment, &url) != 0) {
|
||||||
|
char *msg;
|
||||||
|
asprintf(&msg, "Uploading '%s' failed: Bad URL ('%s')", upload->filename, upload->get_url);
|
||||||
|
cons_show_error(msg);
|
||||||
|
free(msg);
|
||||||
|
} else {
|
||||||
switch (upload->window->type) {
|
switch (upload->window->type) {
|
||||||
case WIN_CHAT:
|
case WIN_CHAT:
|
||||||
{
|
{
|
||||||
ProfChatWin *chatwin = (ProfChatWin*)(upload->window);
|
ProfChatWin *chatwin = (ProfChatWin*)(upload->window);
|
||||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||||
cl_ev_send_msg(chatwin, upload->get_url, upload->get_url);
|
cl_ev_send_msg(chatwin, url, url);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WIN_PRIVATE:
|
case WIN_PRIVATE:
|
||||||
{
|
{
|
||||||
ProfPrivateWin *privatewin = (ProfPrivateWin*)(upload->window);
|
ProfPrivateWin *privatewin = (ProfPrivateWin*)(upload->window);
|
||||||
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
||||||
cl_ev_send_priv_msg(privatewin, upload->get_url, upload->get_url);
|
cl_ev_send_priv_msg(privatewin, url, url);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WIN_MUC:
|
case WIN_MUC:
|
||||||
{
|
{
|
||||||
ProfMucWin *mucwin = (ProfMucWin*)(upload->window);
|
ProfMucWin *mucwin = (ProfMucWin*)(upload->window);
|
||||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||||
cl_ev_send_muc_msg(mucwin, upload->get_url, upload->get_url);
|
cl_ev_send_muc_msg(mucwin, url, url);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
curl_free(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,8 @@ typedef struct http_upload_t {
|
|||||||
char *mime_type;
|
char *mime_type;
|
||||||
char *get_url;
|
char *get_url;
|
||||||
char *put_url;
|
char *put_url;
|
||||||
|
char *alt_scheme;
|
||||||
|
char *alt_fragment;
|
||||||
ProfWin *window;
|
ProfWin *window;
|
||||||
pthread_t worker;
|
pthread_t worker;
|
||||||
int cancel;
|
int cancel;
|
||||||
|
Loading…
Reference in New Issue
Block a user