1
0
Fork 0
mirror of https://git.sr.ht/~sircmpwn/gmni synced 2024-05-07 13:36:03 +02:00
Commit Graph

140 Commits

Author SHA1 Message Date
Ondřej Fiala 74c086156f gmnlm: treat invalid cert and cert mismatch similarly
gmnlm already allows overriding invalid cert error, so it makes little
sense not to allow the same for cert mismatch one. I have also reversed
the offered options for both to reflect the suggested course of action
and added a warning for invalid cert as the possibility of MitM is quite
similar to cert mismatch.
2022-12-19 12:01:22 +01:00
Ondřej Fiala e4d39847f1 gmnlm: make ./ prefix mandatory for relative URLs
Interpreting everything that isn't a command as relative URL wasn't
very intuitive and lead to accidental commands or requests being made.
This commit aims to clearly separate relative URLs from commands, which
also allows us to add basic error reporting for commands.

The only exception that had to be made was in regards to /whatever URLs
as those are impossible to support without changing the search command.
2022-08-15 15:51:17 +02:00
Ondřej Fiala 74d0652125 gmnlm: prompt for redirects, make max redirects configurable
Redirects are currently the most reliable way of tracking users in
geminispace. To mitigate this, similar approach as used with server
certificates is adopted -- users are prompted by default, but this
can be easily overriden with a command line flag if convenience is
preferred to tracking-resistance.
2022-07-02 11:39:07 +02:00
Ondřej Fiala 584544ff7f gmnlm: tidy up help message
* make marking of mandatory arguments consistent
* document the 'i' command
* don't document commands explained by the prompt
* unify alignment
* minor wording adjustments
2022-07-02 11:38:02 +02:00
Ondřej Fiala 861d2e2cbf gmnlm: don't assume everything starting with b/f is b/f command
It was impossible to enter a file:// URL because it got interpreted
as a 'f' command without any warning about invalid argument. The same
thing happened with relative addresses beginning with 'b' or 'f'.
2022-07-01 09:19:38 +02:00
Ondřej Fiala bf7975dd44 gmnlm: save non-sensitive input requests in history
Currently, followup requests to both INPUT and SENSITIVE INPUT responses are
omitted from history. However, the intended use of INPUT is for searching, and
there is SENSITIVE INPUT for sensitive information, so omitting regular INPUT
from history doesn't make much sense and only makes searching annoying as one
needs to re-enter the query when going back.
2022-06-22 08:56:17 +02:00
Sebastiano Tronto eb5c5470e8 Add d[N] to download Nth link
I wanted to add an optional [N] to 'd' and '|' to download/pipe the
Nth link instead of the current page. After getting the first one done,
I found out that '|' already has this option, so I fixed the relative
help line without changing that command.

All in all I don't know how useful this patch is, considering that
'[N]|' was already there. Feel free to discard it and just keep the
documentation change.

Cheers!
2022-05-23 10:32:28 +02:00
Sebastian LaVine 8c623936de gmni: fix -d truncation
Previously, the last character of the provided input would not be read.
For example, `gmni -d termfmt gemini://godocs.io/-/search` would search
for "termfm".
2022-04-21 10:15:56 +02:00
Ondřej Fiala b0ef37a5c0 gmnlm: fix memory leak in do_requests 2022-02-07 12:53:43 +01:00
Ondřej Fiala d5421dd9e0 gmnlm: strip control sequences from plaintext rendering 2022-02-07 12:53:41 +01:00
Ondřej Fiala 4f04fb45e2 gmnlm: d <path> -> d [path]
The argument is optional, the 'd' command works without it.
2022-01-26 08:32:39 +01:00
Ondřej Fiala b31e6551cf fix null dereference 2022-01-14 15:59:37 +01:00
Ondřej Fiala 0603755a00 gmnlm: add optional custom bookmark titles
It is often useful to title a bookmark differently from how the page's
author titled it.
2022-01-12 19:54:59 +01:00
Ondřej Fiala 5f4c617262 gmnlm: output newline when quiting via Control-D
It is common practice to quit programs reading from stdin by sending
EOF to their input. This commit ensures such an exit is functionally
equivalent to a regular exit via the 'q' command.
2022-01-10 08:30:36 +01:00
Ondřej Fiala 07965631f7 gmnlm: update usage to match man page 2022-01-03 14:20:29 +01:00
René Wagner fcc5c1d374 clear client certificate when none is required
Otherwise we end up using the client certificate
of a previous request and the current request will
fail with a SSL error 26.
2021-11-10 18:40:06 +01:00
René Wagner 78fe3fbb2b fix wrong path length check and error message 2021-11-03 16:26:00 +01:00
René Wagner ff46c840c5 allow ~ as home alias in file path for downloads
This works for gmni and gmnlm respectively.
2021-11-03 14:30:52 +01:00
René Wagner 17a27041c0 fix missing last line in gmnlm in some cases
closes ~sircmpwn/gmni#64
2021-10-29 13:16:57 +02:00
René Wagner 1a9aa3e252 fix downloading of files
due to the wrong handling in download_resp() files may get
broken (last chunk missing) and file descriptors have not
been closed correctly.

Additionally we now allow downloading of local ressources
as well - for what its worth.
2021-10-29 09:53:43 +02:00
René Wagner 0b55ef24a1 add hints to history for easier navigation
This commit adds simple hints in front of the URIs on the history
page to directly show what needs to be typed to jump to this page.
2021-07-02 08:59:56 -04:00
k1nkreet 9b95e38eef gmni: headers are not displayed for REDIRECT and INPUT responses in SHOW_HEADERS and ONLY_HEADERS modes
I've noticed headers are not displayed in some cases with -i/-I
specified. For example:

echo "printf" | gmni -i gemini://drewdevault.com/cgi-bin/man.sh
Output: empty

echo "printf" | gmni -IL gemini://drewdevault.com/cgi-bin/man.sh -
Output: 10 Search for a POSIX man page
INPUT header is here, but no REDIRECT header appeared.

The reason is headers processing is done after responses dispatch. So
some responses (redirect and input) are processed and dropped before.
Patch makes this logic a bit clearer imho: print response header before
any processing if mode is not OMIT_HEADERS and then process response body if mode
is not ONLY_HEADERS. It also deduplicates header printing as a bonus.
2021-06-18 12:00:59 -04:00
Andrew b46b312817 gmnlm: host freed too early, causing UAF
The host variable is freed too early. If a client certificate is not
found, the later error message in the
GEMINI_STATUS_CLASS_CLIENT_CERTIFICATE_REQUIRED case uses the freed host
variable to produce an incorrect openssl command. This fix just delays
the free to after the switch statement.

Test case:
gmnlm gemini://feeds.drewdevault.com

Prior:
The following OpenSSL command will generate a certificate for this host:

openssl req -x509 -newkey rsa:4096 \
 -keyout /home/andrew/.local/share/gmni/certs/€Ú-=öU.key \
 -out /home/andrew/.local/share/gmni/certs/€Ú-=öU.crt \
 -days 36500 -nodes

Now:
The following OpenSSL command will generate a certificate for this host:

openssl req -x509 -newkey rsa:4096 \
-keyout /home/andrew/.local/share/gmni/certs/feeds.drewdevault.com.key \
-out /home/andrew/.local/share/gmni/certs/feeds.drewdevault.com.crt \
-days 36500 -nodes
2021-06-12 12:13:29 -04:00
Zach DeCook e0993d4886 gmnlm: Include blank line to frame browser window when reading more 2021-04-02 12:49:07 -04:00
Zach DeCook a348eb906d gmnlm: Improve paging behavior on narrow terminals 2021-04-02 12:49:07 -04:00
Eyal Sawady 77b73efbcd all: use posix_dirname rather than dirname 2021-03-16 08:45:19 -04:00
Eyal Sawady 93f30522f0 gmnlm: create cert dir on 6x response
So that the OpenSSL command doesn't fail when the cert dir hasn't
already been created.
2021-03-09 08:08:45 -05:00
Drew DeVault 31dfd38681 Always take the last cert, CA or not 2021-03-07 12:21:15 -05:00
Drew DeVault 925d9e321d Implement basic client certs for gmnlm 2021-03-05 08:50:57 -05:00
Drew DeVault 1ed4f09532 Initial support for client side certificates
This is only supported with gmni for now - gmnlm support will come
later. A limitation with BearSSL prevents us from doing automated
certificate generation for now, unfortunately.
2021-03-05 08:29:02 -05:00
Drew DeVault 2017d26c41 TOFU: more improvements to new cert handling logic 2021-03-04 16:22:14 -05:00
Drew DeVault 06df35d004 Remove useless variable cast 2021-03-04 13:00:07 -05:00
Drew DeVault 10aace0d20 Discard CA certs unless there's no other 2021-03-04 12:58:50 -05:00
Drew DeVault ada6891e8f tofu: don't discard CA certs 2021-03-04 12:19:54 -05:00
Drew DeVault 57064dd01f all: rewrite with BearSSL rather than OpenSSL 2021-03-04 10:59:37 -05:00
René Wagner 863c41dba6 fix display of message on TOFU_FINGERPRINT_MISMATCH
Previously the message was never displayed to users
leaving them with a simple "Error: certificate is untrusted".

This also fixes the display of line numbers in the message.
2021-02-23 10:06:53 -05:00
René Wagner 529b1059af jump more than one entry back or forth in history
by giving an optional number to b & f commands.
The default behaviour of b & f commands has not
been changed.
2021-02-02 11:20:13 -05:00
Giuseppe Lumia 4fbc632b22 Fix OpenBSD compilation errors
Those changes fix the following compilation errors on OpenBSD:

src/tofu.c:128:28: error: format specifies type 'long' but the argument has type
      'time_t' (aka 'long long') [-Werror,-Wformat]
                        "SHA-512", fingerprint, expires);

src/gmnlm.c:341:31: error: missing sentinel in function call
      [-Werror,-Wsentinel]
                execlp("sh", "sh", "-c", cmd);
                                            ^
                                            , NULL
2021-01-07 11:22:23 -05:00
René Wagner ff8c869b5e preserve all bytes except spaces when wrapping
When wrapping the new line should not start with a space.
All other bytes must be preserved to avoid breaking unicode chars.

fix for ~sircmpwn/gmni#21
2021-01-05 11:24:38 -05:00
René Wagner 00f62ff578 fix premate line wrap
caused by mutlibyte unicode characters.
During column count unicode continuation bytes
are not counted as columns.
2021-01-05 08:11:08 -05:00
Eyal Sawady f5d540bc5d Implement <n>| command 2020-12-02 11:50:51 -05:00
Alexey Yerin d8f0870446 Refactor gmni to use Curl_URL
This also fixes relative redirects.

Signed-off-by: Alexey Yerin <yerinalexey98fd@gmail.com>
2020-11-22 13:02:20 -05:00
William Casarin 8a83030e5a Fix more strncpy bugs in gmnlm and tofu
>From gcc 9.3.0:

error: '__builtin_strncpy' specified bound 4097 equals destination size
[-Werror=stringop-truncation]

Signed-off-by: William Casarin <jb55@jb55.com>
2020-11-20 11:15:46 -05:00
Tommy Nguyen 8970adc23e Fix typo in error message. 2020-11-18 09:49:54 -05:00
Giuseppe Lumia cb63b8ddf0 Fix bug on mkdirs calls
On some systems dirname uses a static string for its return value, so
we were calling mkdirs recursively on a string that was continuosly changing.

A check was also added after the `snprintf` to make sure there's no
information loss since there is no limit to the length of the string
returned by `get_data_pathfmt`.

Closes #48.
2020-11-17 10:00:53 -05:00
William Casarin ec88f4558c gmnlm: fix a few strncpy compile errors on gcc 9.3
In file included from .../include/string.h:495,
                 from src/gmnlm.c:11:
In function ‘strncpy’,
    inlined from ‘do_prompts’ at src/gmnlm.c:627:3:
...glibc-2.31-dev/include/bits/string_fortified.h:106:10:
error: ‘__builtin_strncpy’ specified bound 1024 equals
destination size [-Werror=stringop-truncation]
return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In function ‘strncpy’,
    inlined from ‘do_prompts’ at src/gmnlm.c:612:3:
...glibc-2.31-dev/include/bits/string_fortified.h:106:10:
error: ‘__builtin_strncpy’ specified bound 1024 equals destination size
[-Werror=stringop-truncation]
return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: William Casarin <jb55@jb55.com>
2020-11-17 09:30:56 -05:00
Giuseppe Lumia ab66dd2be9 Simplify posix_dirname logic
dirname has two main problems:
1. It could change in place the string that is passed to it.
2. It uses a static string for its return value, so one should copy it
   somewhere else as soon as possible to avoid subsequent calls to
   dirname to corrupt his data (see #48).

We avoid 1. passing a copy of `path` to dirname and 2. copying it's
return value into `dname`.
2020-11-17 09:30:56 -05:00
René Wagner 61af57e302 fix typo in PERMANENT FAILURE response 2020-11-06 10:05:43 -05:00
Jon Higgs 021d8f8fdf Improve the -j usage 2020-11-02 16:37:42 -05:00
Connor Kuehl c036a43801 Initialize result if res != GEMINI_OK
My compiler barks about this unitialized variable:

CC	src/gmnlm.o
src/gmnlm.c:629:7: error: variable 'result' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                if (res != GEMINI_OK) {
                    ^~~~~~~~~~~~~~~~
src/gmnlm.c:673:9: note: uninitialized use occurs here
        return result;
               ^~~~~~
src/gmnlm.c:629:3: note: remove the 'if' if its condition is always false
                if (res != GEMINI_OK) {
                ^~~~~~~~~~~~~~~~~~~~~~~
src/gmnlm.c:482:2: note: variable 'result' is declared here
        enum prompt_result result;
        ^
1 error generated.
make: *** [src/gmnlm.o] Error 1
2020-10-31 19:00:28 -04:00