gkdr / lurch

XEP-0384: OMEMO Encryption for libpurple.
GNU General Public License v3.0
286 stars 32 forks source link

Remove line feeds from Base64 encoded data #121

Open sualko opened 6 years ago

sualko commented 6 years ago

I discovered that lurch in version 0.6.7 adds newlines after a couple of characters to it's Base64 encoded data. This is probably a bug, according to RFC 4648:

Implementations MUST NOT add line feeds to base-encoded data unless the specification referring to this document explicitly directs base encoders to add line feeds after a specific number of characters.

Because in XEP-0384 I find no advice, regarding a max line length.

gkdr commented 5 years ago

Which data exactly? I didn't implement b64 myself and am generally using the glib function g_base64_encode(). I just checked and it doesn't have any options I might be misusing.

sualko commented 5 years ago

It's hard to remember after one year, but I think to every data (key, payload, signedPreKeySignature, ...). If you are using https://github.com/GNOME/glib/blob/e0e4968dca8ad737753c0d6f8034c6f08c5002e8/glib/gbase64.c#L261-L281 there should be no line breaks, because line_breaks is false.

gkdr commented 5 years ago

It's hard to remember after one year

I can imagine! Sorry, I got a bit overwhelmed with issues at the time and later falsely remembered that I was just waiting for more input on all of them until I had another look recently.

If you are using https://github.com/GNOME/glib/blob/e0e4968dca8ad737753c0d6f8034c6f08c5002e8/glib/gbase64.c#L261-L281 there should be no line breaks, because line_breaks is false.

I am (in the libomemo submodule), and that line has not changed for 12 years so I doubt it's a glib version issue either. I'm going to check whether I do anything weird with the resulting XML in this plugin itself - one thing that comes to mind is exporting a string and reimporting it because I didn't want to deal with libxml2 in libomemo and serializing was a quick and good enough solution so I can use mxml. First I'll look at the raw XMPP from the debug log to see if I can find the line breaks though, never really noticed such a thing.