MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / hmacSign

Function hmacSign

util.go:39–75  ·  view source on GitHub ↗
(args ...string)

Source from the content-addressed store, hash-verified

37}
38
39func hmacSign(args ...string) error {
40 if len(args) != 3 {
41 fmt.Fprintln(os.Stderr, "Usage:")
42 fmt.Fprintln(os.Stderr, "")
43 fmt.Fprintln(os.Stderr, "dumbproxy -hmac-sign <HMAC key> <username> <validity duration>")
44 fmt.Fprintln(os.Stderr, "")
45 return errors.New("bad command line arguments")
46 }
47
48 secret, err := hex.DecodeString(args[0])
49 if err != nil {
50 return fmt.Errorf("unable to hex-decode HMAC secret: %w", err)
51 }
52
53 validity, err := time.ParseDuration(args[2])
54 if err != nil {
55 return fmt.Errorf("unable to parse validity duration: %w", err)
56 }
57
58 expire := time.Now().Add(validity).Unix()
59 mac := auth.CalculateHMACSignature(secret, args[1], expire)
60 token := auth.HMACToken{
61 Expire: expire,
62 }
63 copy(token.Signature[:], mac)
64
65 var resBuf bytes.Buffer
66 enc := base64.NewEncoder(base64.RawURLEncoding, &resBuf)
67 if err := binary.Write(enc, binary.BigEndian, &token); err != nil {
68 return fmt.Errorf("token encoding failed: %w", err)
69 }
70 enc.Close()
71
72 fmt.Println("Username:", args[1])
73 fmt.Println("Password:", resBuf.String())
74 return nil
75}
76
77func list_ciphers() {
78 for _, cipher := range tls.CipherSuites() {

Callers 1

runFunction · 0.85

Calls 5

CalculateHMACSignatureFunction · 0.92
ErrorfMethod · 0.80
CloseMethod · 0.65
WriteMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected