From 1f1fb4c6e374a8efb691d150490878f1cd2c08f4 Mon Sep 17 00:00:00 2001 From: Laura Date: Fri, 20 Jun 2025 18:11:26 +0200 Subject: [PATCH] improve logging --- client/certificates.go | 2 +- client/main.go | 14 +++++++------- client/progress.go | 2 +- server/main.go | 3 +-- server/protocol.go | 20 ++++++++++---------- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/client/certificates.go b/client/certificates.go index 85d8f2d..4284c91 100644 --- a/client/certificates.go +++ b/client/certificates.go @@ -156,7 +156,7 @@ func NewPinnedClient(store *CertificateStore) *http.Client { return nil } - log.Printf("Server fingerprint (%s): %s\n", name, fingerprint) + log.Printf("Server fingerprint for %s: %s\n", name, fingerprint) log.Print("Accept? [y/N]: ") var confirm string diff --git a/client/main.go b/client/main.go index 380b4e3..88c9f14 100644 --- a/client/main.go +++ b/client/main.go @@ -54,7 +54,7 @@ func main() { } func run(_ context.Context, cmd *cli.Command) error { - log.Println("loading certificate store") + log.Println("Loading certificate store...") store, err := LoadCertificateStore() if err != nil { @@ -73,7 +73,7 @@ func run(_ context.Context, cmd *cli.Command) error { return fmt.Errorf("failed to get key path: %v", err) } - log.Printf("using key %s\n", kPath) + log.Printf("Using key: %s\n", kPath) path = cmd.String("file") if path == "" { @@ -85,7 +85,7 @@ func run(_ context.Context, cmd *cli.Command) error { return fmt.Errorf("failed to get file path: %v", err) } - log.Printf("using file %s\n", fPath) + log.Printf("Using file: %s\n", fPath) file, err := os.OpenFile(fPath, os.O_RDONLY, 0) if err != nil { @@ -101,9 +101,9 @@ func run(_ context.Context, cmd *cli.Command) error { target = fmt.Sprintf("https://%s", target) - log.Printf("using target %s\n", target) + log.Printf("Using target: %s\n", target) - log.Printf("loading key") + log.Printf("Loading key...") private, err := LoadPrivateKey(kPath) if err != nil { @@ -112,14 +112,14 @@ func run(_ context.Context, cmd *cli.Command) error { public := base64.StdEncoding.EncodeToString(private.PublicKey().Marshal()) - log.Println("requesting challenge") + log.Println("Requesting challenge...") challenge, err := RequestChallenge(client, target, public) if err != nil { return err } - log.Println("completing challenge") + log.Println("Completing challenge...") response, err := CompleteChallenge(client, target, public, private, challenge) if err != nil { diff --git a/client/progress.go b/client/progress.go index d262471..5ddd7f2 100644 --- a/client/progress.go +++ b/client/progress.go @@ -25,7 +25,7 @@ func (pr *ProgressReader) Read(p []byte) (int, error) { pr.read += int64(n) percentage := float64(pr.read) / float64(pr.total) * 100 - log.Printf("\r%s %.1f%%", pr.label, percentage) + log.Printf("\r%s: %.1f%%", pr.label, percentage) return n, err } diff --git a/server/main.go b/server/main.go index f243632..181a959 100644 --- a/server/main.go +++ b/server/main.go @@ -38,8 +38,6 @@ func main() { r.Post("/receive", HandleReceiveRequest) - log.Println("Listening on :7966") - srv := &http.Server{ Addr: ":7966", Handler: r, @@ -48,5 +46,6 @@ func main() { }, } + log.Println("Server listening on :7966") srv.ListenAndServeTLS("cert.pem", "key.pem") } diff --git a/server/protocol.go b/server/protocol.go index 1122349..558dbb7 100644 --- a/server/protocol.go +++ b/server/protocol.go @@ -32,14 +32,14 @@ func IsSignatureFormatValid(format string) bool { } func HandleChallengeRequest(w http.ResponseWriter, r *http.Request, authorized map[string]ssh.PublicKey) { - log.Printf("request: new request from %s\n", r.RemoteAddr) + log.Printf("request: received new request from %s\n", r.RemoteAddr) var request internal.AuthRequest if err := msgpack.NewDecoder(r.Body).Decode(&request); err != nil { w.WriteHeader(http.StatusBadRequest) - log.Warning("request: failed to decode request") + log.Warning("request: failed to decode request payload") log.WarningE(err) return @@ -49,7 +49,7 @@ func HandleChallengeRequest(w http.ResponseWriter, r *http.Request, authorized m if err != nil { w.WriteHeader(http.StatusBadRequest) - log.Warning("request: failed to parse/authorize public key") + log.Warning("request: failed to parse or authorize public key") log.WarningE(err) return @@ -77,14 +77,14 @@ func HandleChallengeRequest(w http.ResponseWriter, r *http.Request, authorized m } func HandleCompleteRequest(w http.ResponseWriter, r *http.Request, authorized map[string]ssh.PublicKey) { - log.Printf("complete: new completion from %s\n", r.RemoteAddr) + log.Printf("complete: received completion from %s\n", r.RemoteAddr) var response internal.AuthResponse if err := msgpack.NewDecoder(r.Body).Decode(&response); err != nil { w.WriteHeader(http.StatusBadRequest) - log.Warning("complete: failed to decode response") + log.Warning("complete: failed to decode response payload") log.WarningE(err) return @@ -94,7 +94,7 @@ func HandleCompleteRequest(w http.ResponseWriter, r *http.Request, authorized ma if err != nil { w.WriteHeader(http.StatusBadRequest) - log.Warning("complete: failed to parse/authorize public key") + log.Warning("complete: failed to parse or authorize public key") log.WarningE(err) return @@ -170,7 +170,7 @@ func HandleCompleteRequest(w http.ResponseWriter, r *http.Request, authorized ma PublicKey: public, }, cache.DefaultExpiration) - log.Printf("complete: completed auth for %s\n", r.RemoteAddr) + log.Printf("complete: authentication completed for %s\n", r.RemoteAddr) w.Header().Set("Content-Type", "application/msgpack") msgpack.NewEncoder(w).Encode(internal.AuthResult{ @@ -179,7 +179,7 @@ func HandleCompleteRequest(w http.ResponseWriter, r *http.Request, authorized ma } func HandleReceiveRequest(w http.ResponseWriter, r *http.Request) { - log.Printf("receive: request from %s\n", r.RemoteAddr) + log.Printf("receive: received request from %s\n", r.RemoteAddr) token := r.Header.Get("Authorization") if token == "" { @@ -250,12 +250,12 @@ func HandleReceiveRequest(w http.ResponseWriter, r *http.Request) { if err != nil { w.WriteHeader(http.StatusInternalServerError) - log.Warning("receive: failed to copy sent file") + log.Warning("receive: failed to save uploaded file") return } - log.Printf("receive: stored %s from %s (%d bytes)\n", name, r.RemoteAddr, read) + log.Printf("receive: stored file %s from %s (%d bytes)\n", name, r.RemoteAddr, read) w.WriteHeader(http.StatusOK) }