S17/S18: send success and failure routes; Sphinx HTML/PDF
Python router + Go sm-leaf reject missing to, empty ct, plaintext body. Summary logs never include ciphertext. MODULE.md.
This commit is contained in:
parent
f4da7ff446
commit
43cbf51d3e
75 changed files with 14878 additions and 9 deletions
|
|
@ -64,8 +64,7 @@ func (n *Node) subscribe() error {
|
|||
}
|
||||
}
|
||||
if _, err := n.nc.Subscribe("verae.sm.send", func(msg *nats.Msg) {
|
||||
// Passthrough: do not log ciphertext.
|
||||
ack(msg, []byte(`{"accepted":true}`))
|
||||
n.handleSend(msg)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -82,6 +81,12 @@ func (n *Node) subscribe() error {
|
|||
if _, err := n.nc.Subscribe("verae.sm.log.summary", func(msg *nats.Msg) {
|
||||
var hdr map[string]any
|
||||
_ = json.Unmarshal(msg.Data, &hdr)
|
||||
// Summary only: never log ciphertext or recipient payload.
|
||||
if _, ok := hdr["ct"]; ok {
|
||||
log.Printf("sm-summary rejected body-like field")
|
||||
ack(msg, []byte(`{"logged":false,"error":"body-like fields present"}`))
|
||||
return
|
||||
}
|
||||
log.Printf("sm-summary code=%v lookup=%v class=%v", hdr["error_code"], hdr["lookup_id"], hdr["dest_class"])
|
||||
ack(msg, []byte(`{"logged":true}`))
|
||||
}); err != nil {
|
||||
|
|
@ -90,6 +95,57 @@ func (n *Node) subscribe() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (n *Node) handleSend(msg *nats.Msg) {
|
||||
var env map[string]any
|
||||
if err := json.Unmarshal(msg.Data, &env); err != nil {
|
||||
n.fail(msg, "SM-BAD-JSON", "parse", "")
|
||||
return
|
||||
}
|
||||
to, _ := env["to"].(string)
|
||||
alg, _ := env["alg"].(string)
|
||||
ct, _ := env["ct"].(string)
|
||||
lid, _ := env["from_lookup_id"].(string)
|
||||
if _, hasBody := env["body"]; hasBody {
|
||||
n.fail(msg, "SM-PLAINTEXT-BODY", "mailbox", lid)
|
||||
return
|
||||
}
|
||||
if to == "" {
|
||||
n.fail(msg, "SM-MISSING-TO", "mailbox", lid)
|
||||
return
|
||||
}
|
||||
if alg != "" && alg != "npe" && alg != "lab-xor" && alg != "plain-lab" {
|
||||
n.fail(msg, "SM-BAD-ALG", "mailbox", lid)
|
||||
return
|
||||
}
|
||||
if alg != "plain-lab" && ct == "" {
|
||||
n.fail(msg, "SM-EMPTY-CT", "mailbox", lid)
|
||||
return
|
||||
}
|
||||
ack, _ := json.Marshal(map[string]any{"accepted": true, "lookup_id": lid})
|
||||
if msg.Reply != "" {
|
||||
_ = n.nc.Publish(msg.Reply, ack)
|
||||
}
|
||||
}
|
||||
|
||||
func (n *Node) fail(msg *nats.Msg, code, destClass, lid string) {
|
||||
summary, _ := json.Marshal(map[string]any{
|
||||
"error_code": code,
|
||||
"lookup_id": lid,
|
||||
"dest_class": destClass,
|
||||
})
|
||||
_ = n.nc.Publish("verae.sm.log.summary", summary)
|
||||
_ = n.nc.Publish("verae.sm.error", summary)
|
||||
_ = n.nc.Publish("verae.sm.dead", summary)
|
||||
ack, _ := json.Marshal(map[string]any{
|
||||
"accepted": false,
|
||||
"error_code": code,
|
||||
"lookup_id": lid,
|
||||
})
|
||||
if msg.Reply != "" {
|
||||
_ = n.nc.Publish(msg.Reply, ack)
|
||||
}
|
||||
}
|
||||
|
||||
// HealthHandler is the loopback JSON health mux (does not expose NATS).
|
||||
func HealthHandler() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue