Skip to content

Commit 2bf1786

Browse files
committed
MINOR: add backwards-compatible bootstrap key expiry check
1 parent 338f5ec commit 2bf1786

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

configuration/misc.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ import (
2121
"fmt"
2222
"os"
2323
"path"
24+
"strconv"
2425
"syscall"
26+
"time"
2527

28+
"github.com/go-openapi/strfmt"
2629
"github.com/haproxytech/client-native/v4/misc"
2730
"github.com/haproxytech/client-native/v4/storage"
2831
jsoniter "github.com/json-iterator/go"
@@ -39,6 +42,25 @@ func DecodeBootstrapKey(key string) (map[string]string, error) {
3942
if err != nil {
4043
return nil, fmt.Errorf("%s - %w", key, err)
4144
}
45+
46+
var keySummary string
47+
if len(key) > 10 {
48+
keySummary = key[:4] + "..." + key[len(key)-5:]
49+
} else {
50+
keySummary = key
51+
}
52+
53+
if expiryUnixTS, ok := decodedKey["expiring-time"]; ok {
54+
tUnix, ok2 := strconv.ParseInt(expiryUnixTS, 10, 64)
55+
if ok2 != nil {
56+
return nil, fmt.Errorf("bootstrap key %s error, decoding expiry to int: %s", keySummary, expiryUnixTS)
57+
}
58+
expiryTime := time.Unix(tUnix, 0)
59+
if expiryTime.Before(time.Now()) {
60+
return nil, fmt.Errorf("refusing to use expired bootstrap key: %s expired on: %s", keySummary, strfmt.DateTime(expiryTime))
61+
}
62+
}
63+
4264
return decodedKey, nil
4365
}
4466

0 commit comments

Comments
 (0)