• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kn-lim / dreamingway-bot / 12593784322

03 Jan 2025 06:30AM UTC coverage: 0.0% (-22.8%) from 22.759%
12593784322

Pull #5

github

web-flow
Merge 4d7e57259 into 311f96742
Pull Request #5: Refactor

0 of 112 new or added lines in 6 files covered. (0.0%)

0 of 112 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/dreamingway/validate.go
1
package dreamingway
2

3
import (
4
        "crypto/ed25519"
5
        "encoding/base64"
6
        "encoding/hex"
7
        "errors"
8

9
        "github.com/aws/aws-lambda-go/events"
10
)
11

NEW
12
func ValidateRequest(request events.APIGatewayProxyRequest, publicKey string) error {
×
NEW
13
        publicKeyBytes, err := hex.DecodeString(publicKey)
×
NEW
14
        if err != nil {
×
NEW
15
                return err
×
NEW
16
        }
×
17

NEW
18
        var body []byte
×
NEW
19
        if request.IsBase64Encoded {
×
NEW
20
                body_bytes, err := base64.StdEncoding.DecodeString(request.Body)
×
NEW
21
                if err != nil {
×
NEW
22
                        return err
×
NEW
23
                }
×
24

NEW
25
                body = body_bytes
×
NEW
26
        } else {
×
NEW
27
                body = []byte(request.Body)
×
NEW
28
        }
×
29

NEW
30
        ed25519PublicKey := ed25519.PublicKey(publicKeyBytes)
×
NEW
31

×
NEW
32
        x_signature, ok := request.Headers["x-signature-ed25519"]
×
NEW
33
        if !ok {
×
NEW
34
                return errors.New("missing x-signature-ed25519 header")
×
NEW
35
        }
×
36

NEW
37
        x_signature_time, ok := request.Headers["x-signature-timestamp"]
×
NEW
38
        if !ok {
×
NEW
39
                return errors.New("missing x-signature-timestamp header")
×
NEW
40
        }
×
41

NEW
42
        x_signature_bytes, err := hex.DecodeString(x_signature)
×
NEW
43
        if err != nil {
×
NEW
44
                return err
×
NEW
45
        }
×
46

NEW
47
        signed_data := []byte(x_signature_time + string(body))
×
NEW
48

×
NEW
49
        if !ed25519.Verify(ed25519PublicKey, signed_data, x_signature_bytes) {
×
NEW
50
                return errors.New("invalid request signature")
×
NEW
51
        }
×
52

NEW
53
        return nil
×
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc