Commit Graph
41 Commits
Author SHA1 Message Date
Hugo Wetterberg f2921a396f Add missing error handling
Error handling is currently missing is a couple of places. Most of
them are i/o related.

This change adds checks, an therefore sometimes also has to change
function signatures by adding an error return value. In the case of
the response writer the status and meta handling is changed and this
also breaks the API.

In some places where we don't have any reasonable I've added
assignment to a blank identifier to make it clear that we're ignoring
an error.

text: read the Err() that can be set by the scanner.

client: check if conn.SetDeadline() returns an error.

client: check if req.Write() returns an error.

fs: panic if mime type registration fails.

server: stop performing i/o in Header/Status functions

By deferring the actual header write to the first Write() or Flush()
call we don't have to do any error handling in Header() or Status().

As Server.respond() now defers a ResponseWriter.Flush() instead of
directly flushing the underlying bufio.Writer this has the added
benefit of ensuring that we always write a header
to the client, even if the responder is a complete NOOP.

tofu: return an error if we fail to write to the known hosts writer.
2021-01-09 23:53:07 -05:00
Adnan Maolood 28c5c857dc Decouple Client from KnownHostsFile 2020-12-17 19:50:26 -05:00
Adnan Maolood a1dd8de337 Fix locking up of KnownHostsFile and CertificateDir 2020-12-17 17:15:24 -05:00
Adnan Maolood 7be0715d39 Use RWMutex instead of Mutex 2020-12-17 17:08:45 -05:00
Adnan Maolood 4704b8fbcf Add missing imports 2020-12-17 17:07:00 -05:00
Adnan Maolood e687a05170 Make KnownHostsFile safe for concurrent use 2020-12-17 16:49:59 -05:00
Adnan Maolood 611a7d54c0 Revert to using hexadecimal to encode fingerprints 2020-12-16 23:58:02 -05:00
Adnan Maolood 3c7940f153 Fix known hosts expiration timestamps 2020-11-25 14:24:49 -05:00
Adnan Maolood 7ee0ea8b7f Use base64 to encode fingerprints 2020-11-25 14:16:51 -05:00
Adnan Maolood 0c75e5d5ad Expose KnownHosts and CertificateStore internals 2020-11-23 12:17:54 -05:00
Adnan Maolood f6b0443a62 Update KnownHosts documentation 2020-11-09 13:57:30 -05:00
Adnan Maolood 9338681256 Add (*KnownHosts).SetOutput function 2020-11-09 12:26:08 -05:00
Adnan Maolood 46cbcfcaa4 Remove top-level Get and Do functions 2020-11-09 12:04:53 -05:00
Adnan Maolood 76dfe257f1 Remove (*KnownHosts).LoadDefault function 2020-11-09 09:28:44 -05:00
Adnan Maolood ff6c95930b Fix TOFU 2020-11-05 22:30:13 -05:00
Adnan Maolood b76080c863 Refactor KnownHosts 2020-11-05 15:27:12 -05:00
Adnan Maolood 65a5065250 Refactor client.TrustCertificate workflow 2020-10-31 22:34:51 -04:00
Adnan Maolood 34ae2a9066 Use strings.Builder in Fingerprint 2020-10-28 15:14:24 -04:00
Adnan Maolood f0345f3495 Rename repository to go-gemini 2020-10-24 15:15:32 -04:00
adnano 2c1081966d KnownHosts: use map instead of slice for underlying storage 2020-10-13 19:54:48 -04:00
adnano 3d1e9e5519 Move certificate verification code to VerifyConnection 2020-10-13 16:44:46 -04:00
adnano db89a34935 examples/server: Generate new certificates when they expire 2020-10-13 14:22:15 -04:00
adnano 4770ad9112 Rename (*KnownHosts).Load to LoadDefault 2020-10-12 16:56:55 -04:00
adnano b7340aef27 Remove tilde from comment 2020-09-27 22:19:24 -04:00
adnano 38fe1f21dc Change package name to gmi 2020-09-27 20:20:59 -04:00
adnano 73e4ef0689 Reject invalid status codes 2020-09-27 19:56:33 -04:00
adnano 8009de81eb Add function to add a host temporarily 2020-09-27 17:41:41 -04:00
adnano 32a9fcba0c Fix hosts not being added to known hosts file 2020-09-27 16:06:17 -04:00
adnano e01d59f8f6 Don't store wildcards in the known hosts file 2020-09-27 15:03:46 -04:00
adnano f0ce4576e1 Handle multiple DNS names
Each DNS name gets its own entry in the known hosts file
2020-09-27 14:22:41 -04:00
adnano 013b2a4d3e Add function to write known hosts to io.Writer 2020-09-27 14:18:30 -04:00
adnano 769b6ff4d9 Implement default known hosts path 2020-09-26 13:35:56 -04:00
adnano 1b3f9a0655 Remove (*KnownHosts).Has function 2020-09-26 13:29:29 -04:00
adnano bf3e6b3c5c Differentiate between unknown and untrusted certificates 2020-09-26 13:27:03 -04:00
adnano 927dfd29c5 Refactor TOFU 2020-09-25 23:18:14 -04:00
adnano b4295dd2dc Implement basic TOFU 2020-09-25 21:43:13 -04:00
adnano 4a95fe4a90 Add KnownHost.Write function 2020-09-25 20:55:37 -04:00
adnano be55224f89 Fix known host expires check 2020-09-25 20:31:07 -04:00
adnano eaa034204a Add method to check if hostname is found in KnownHosts 2020-09-25 20:22:48 -04:00
adnano 2f43c191cc Reorganize 2020-09-25 19:09:49 -04:00
adnano ace3e682de Remove TLSConfig fields 2020-09-25 18:53:20 -04:00