Tarsnap / tarsnap

Command-line client code for Tarsnap.
https://tarsnap.com
Other
871 stars 60 forks source link

Machine name doesn't work with accents ? #468

Closed remicorniere closed 3 years ago

remicorniere commented 3 years ago

Hello !
I came across a weird bug it seems. I tried to generate a key with the following command:

$ sudo tarsnap-keygen --keyfile /my/key/location/tarsnap.key --user my_email@my_domain.my_tld --machine dédié

And I got this:

tarsnap-keygen: Connection lost, waiting 1 seconds before reconnecting   
tarsnap-keygen: Connection lost, waiting 2 seconds before reconnecting
...

which I eventually killed.
I tried pinging the server with this, and it worked:

$ ping v1-0-0-server.tarsnap.com  
PING v1-0-0-server.tarsnap.com (75.101.135.185) 56(84) bytes of data.  
64 bytes from ec2-75-101-135-185.compute-1.amazonaws.com (75.101.135.185): icmp_seq=1 ttl=46 time=78.6 ms  

Then I tried simply changing the machine name to:

$ sudo tarsnap-keygen --keyfile /my/key/location/tarsnap.key --user my_email@my_domain.my_tld --machine dedicated

and it worked.
Is it possible that the machine name cannot have accents (UTF-8 chars, more widely) ? Sorry if it's in the docs and I missed it.

gperciva commented 3 years ago

Bonjour @remicorniere,

My first guess is machine names must be ASCII, but I'm investigating. (If that's the case, then we should at least give a warning.)

gperciva commented 3 years ago

Yes, the machine name must contain only "printable" characters, as checked by https://en.cppreference.com/w/c/string/byte/isprint. Unfortunately that function's behaviour varies by locale, but I'm 95% confident that we're using the "C" locale (I'm still investigating). So yes, you can only use typical ASCII characters.

I should definitely add this to our docs, as well as adding a sanity check in keygen/keygen_actual.c. Thanks for the report!

cperciva commented 3 years ago

Yes, right now it's limited to printable 7-bit ASCII characters. We should probably change that, but I don't know if all of the code which handles machine names is able to safely handle UTF-8... I'll keep this in mind the next time I revisit that code. In the mean time, as @gperciva says, we should just document and error out in the utility rather than sending a request which the server will reject.

remicorniere commented 3 years ago

Thanks for the replies, and thanks for tarsnap ! :)

gperciva commented 3 years ago

This was fixed back in April in https://github.com/Tarsnap/tarsnap/pull/479, and will be part of the next tarsnap release.