From 887e67bc7deff5c8f82a68f588b9e14cc23d4863 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Fri, 24 Jul 2020 15:18:28 -0600 Subject: [PATCH] 404 on get returns empty object and right status --- view/.aes/main.go | 43 +++++++++++++++++++++++++++++++++++++++++++ view/who.go | 4 ++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 view/.aes/main.go diff --git a/view/.aes/main.go b/view/.aes/main.go new file mode 100644 index 0000000..bd2c25c --- /dev/null +++ b/view/.aes/main.go @@ -0,0 +1,43 @@ +package main + +import ( + "crypto/aes" + "crypto/cipher" + "encoding/base64" + "errors" + "log" + "os" + "strings" +) + +func main() { + key := os.Args[1] + value := os.Args[2] + log.Println(aesDec(key, value)) +} + +func aesDec(key, payload string) (string, error) { + if len(key) == 0 { + return "", errors.New("key required") + } + key = strings.Repeat(key, 32)[:32] + + ciphertext, err := base64.StdEncoding.DecodeString(payload) + if err != nil { + return "", err + } + + block, err := aes.NewCipher([]byte(key)) + if err != nil { + return "", err + } + gcm, err := cipher.NewGCM(block) + if err != nil { + return "", err + } + if len(ciphertext) < gcm.NonceSize() { + return "", errors.New("short ciphertext") + } + b, err := gcm.Open(nil, ciphertext[:gcm.NonceSize()], ciphertext[gcm.NonceSize():], nil) + return string(b), err +} diff --git a/view/who.go b/view/who.go index da2e680..b1f81b5 100644 --- a/view/who.go +++ b/view/who.go @@ -53,8 +53,8 @@ func whoGet(namespace string, g storage.Graph, w http.ResponseWriter, r *http.Re return err } if len(ones) == 0 { - http.NotFound(w, r) - return nil + w.WriteHeader(http.StatusNotFound) + return json.NewEncoder(w).Encode(entity.One{}) } if len(ones) > 1 { return errors.New("more than one result found matching " + id)