You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2017/07/07 14:29:48 UTC
[2/2] incubator-trafficcontrol git commit: Add experimental Go
Traffic Ops cookie creator
Add experimental Go Traffic Ops cookie creator
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/7ffd2bbb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/7ffd2bbb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/7ffd2bbb
Branch: refs/heads/master
Commit: 7ffd2bbb749629f3a83d384d8b4f07e57a98bef7
Parents: 7ce236f
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Jul 6 14:06:55 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Fri Jul 7 08:29:45 2017 -0600
----------------------------------------------------------------------
traffic_ops/experimental/tocookie/tocookie.go | 15 +++++++++++++++
1 file changed, 15 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7ffd2bbb/traffic_ops/experimental/tocookie/tocookie.go
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/tocookie/tocookie.go b/traffic_ops/experimental/tocookie/tocookie.go
index e00b52b..4dd319b 100644
--- a/traffic_ops/experimental/tocookie/tocookie.go
+++ b/traffic_ops/experimental/tocookie/tocookie.go
@@ -80,3 +80,18 @@ func Parse(secret, cookie string) (*Cookie, error) {
return &cookieData, nil
}
+
+func NewRawMsg(msg, key []byte) string {
+ base64Msg := base64.RawURLEncoding.WithPadding('-').EncodeToString(msg)
+ mac := hmac.New(sha1.New, []byte(key))
+ mac.Write([]byte(base64Msg))
+ encMac := mac.Sum(nil)
+ base64Sig := hex.EncodeToString(encMac)
+ return base64Msg + "--" + base64Sig
+}
+
+func New(user string, expiration time.Time, key string) string {
+ cookieMsg := Cookie{AuthData: user, ExpiresUnix: expiration.Unix()}
+ msg, _ := json.Marshal(cookieMsg)
+ return NewRawMsg(msg, []byte(key))
+}