dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 18943a6fddf7dfcaf4a573af453fbe78f4661b43
parent 93fd0d2d578822a7acb314a30d5c98fdda9e6799
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Fri, 27 Jan 2023 22:31:20 -0800

if we send a clearsign file to @0, return information about the signature

Diffstat:
Mpkg/web/handlers/api/v1/slashInterceptor.go | 37+++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+), 0 deletions(-)

diff --git a/pkg/web/handlers/api/v1/slashInterceptor.go b/pkg/web/handlers/api/v1/slashInterceptor.go @@ -7,9 +7,13 @@ import ( dutils "dkforest/pkg/database/utils" "dkforest/pkg/managers" "dkforest/pkg/utils" + "encoding/hex" "errors" "fmt" + "github.com/ProtonMail/go-crypto/openpgp/clearsign" + "github.com/ProtonMail/go-crypto/openpgp/packet" "github.com/asaskevich/govalidator" + "github.com/dustin/go-humanize" "github.com/sirupsen/logrus" "sort" "strconv" @@ -960,6 +964,39 @@ func handlePm0(c *Command, msg string) (handled bool) { c.zeroProcMsg(c.message) c.err = ErrRedirect return true + + } else if c.upload != nil { + + // If we sent a clearsign file to @0, the bot will reply with information about the signature + if c.upload.FileSize < config.MaxFileSizeBeforeDownload { + if file, err := database.GetUploadByFileName(c.upload.FileName); err == nil { + if _, by, err := file.GetContent(); err == nil { + if b, _ := clearsign.Decode(by); b != nil { + if p, err := packet.Read(b.ArmoredSignature.Body); err == nil { + if sig, ok := p.(*packet.Signature); ok { + fp := strings.ToUpper(hex.EncodeToString(sig.IssuerFingerprint)) + fpFmt := fmt.Sprintf("%s %s %s %s %s %s %s %s %s %s", + fp[0:4], fp[4:8], fp[8:12], fp[12:16], fp[16:20], + fp[20:24], fp[24:28], fp[28:32], fp[32:36], fp[36:40]) + msg := fmt.Sprintf("<br />"+ + "File: %s (%s)<br />"+ + "Signature made: %s<br />"+ + "Fingerprint: %s<br />"+ + "Issuer: %s", + c.upload.OrigFileName, + humanize.Bytes(uint64(c.upload.FileSize)), + sig.CreationTime.Format(time.RFC1123), + fpFmt, + utils.Ternary(sig.SignerUserId != nil, *sig.SignerUserId, "n/a")) + c.zeroMsg(msg) + c.err = ErrRedirect + return true + } + } + } + } + } + } } zeroUser := c.getZeroUser()