triffid / pia-wg

Linux shell scripts for connecting to Private Internet Access VPN's Wireguard service
116 stars 14 forks source link

pia-wg.sh: parse error, then syntax error in `jq` #8

Closed DurvalMenezes closed 1 year ago

DurvalMenezes commented 1 year ago

Getting the following error when trying to use pia-config.sh: from the current master version from github (91bda8c // Aug 17):

 parse error: Invalid numeric literal at line 1, column 5

And then, further on:

jq: error: syntax error, unexpected '/', expecting $end (Unix shell quoting issues?) at <top-level>, line 1:

Perhaps the 2nd error is a consequence of the first?

This is on a Raspberry Pi 4B 8GB running Devuan Chimaera (systemd-less Debian Bullseye) with Linux kernel 5.15.65, bash version 5.1.4(1), jq version 1.6, and wireguard-tools 1.0.20210223-1.

Here's the complete session, with only the WG and local usernames redacted:

$ ./pia-wg.sh -c
Generating new private key
Setting default location: any
Setting default wireguard interface name: pia
Cannot read '/home/REDACTED/.config/pia-wg/pia-wg.conf', generating a default one
Please enter your privateinternetaccess.com username: REDACTED
Config saved
Fetching new generation server list from PIA
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  104k    0  104k    0     0  92497      0 --:--:--  0:00:01 --:--:-- 92497
Fetching PIA self-signed RSA certificate from github
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2718  100  2718    0     0   7878      0 --:--:-- --:--:-- --:--:--  7855
Selecting server 2 from 2 choices
A new auth token is required.
Your password will NOT be saved.
Please enter your privateinternetaccess.com password for p2774673:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    76    0    27  100    49     25     45  0:00:01  0:00:01 --:--:--    70
parse error: Invalid numeric literal at line 1, column 5
failed, trying meta server
Your password has been forgotten, please edit /home/REDACTED/.config/pia-wg/pia-wg.conf and set PIA_PASSWORD if you wish to store it permanently.
Functional DNS is no longer required.
If you're setting up in a region with heavy internet restrictions, you can disable your alternate VPN or connection method now
Registering public key with IT Milano 156.146.41.28
WG key registration failed - bad token?
jq: error: syntax error, unexpected '/', expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
/home/REDACTED/.config/pia-wg/remote.info.temp
jq: 1 compile error
If you see an auth error, consider deleting /home/REDACTED/.config/pia-wg/token and getting a new token
$
triffid commented 1 year ago

Please enter your privateinternetaccess.com password for p«number»: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 76 0 27 100 49 25 45 0:00:01 0:00:01 --:--:-- 70 parse error: Invalid numeric literal at line 1, column 5

Hmm, it says it got a weird response from the PIA's API when requesting a token then tried a meta server which apparently succeeded - perhaps it got a weird token from there too but the error checking didn't pick up the issue?

(it only checks if the token is empty, we're not supposed to assume that the token will match some arbitrary pattern)

May want to check if your token file has 128 hex chars and a newline in it, or something else - if they've changed the token format to something with quotes or newlines or something, I might have to construct some of the queries differently.

WG key registration failed - bad token? jq: error: syntax error, unexpected '/', expecting $end (Unix shell quoting issues?) at , line 1: /home/REDACTED/.config/pia-wg/remote.info.temp

Yeah, again that file comes from PIA's API, and jq thinks there's something weird in it - may want to paste it here in a codeblock (with anything potentially identifying obfuscated of course) so we can have a look at it.

jq complaining about forward slashes makes me wonder if the endpoint is throwing HTML at you instead of JSON, might be something useful if you just cat the file

DurvalMenezes commented 1 year ago

Thanks for the prompt reply, and sorry for the delay in getting back to you.

I tried to reproduce the issue to get you the data you requested, but it 'magically' disappeared -- perhaps PIA was replying weirdly to messages and now they fixed it at their end?

I will close the issue for now, if it ever repeats I will open it and attach the requested data.

triffid commented 1 year ago

Heh no worries, seems like you've still identified at least one spot in the code where we might want to retry instead of bailing - but it's complicated because we do want to bail and have the user remove the token so we can re-auth if the token is legitimately bad.

I'll have a poke around in that section and have a think about how best to handle a failure at that point