trafficcontrol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dewr...@apache.org
Subject [2/2] incubator-trafficcontrol git commit: Add experimental Go Traffic Ops cookie creator
Date Fri, 07 Jul 2017 14:29:48 GMT
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 <robert.o.butts@gmail.com>
Authored: Thu Jul 6 14:06:55 2017 -0600
Committer: Dewayne Richardson <dewrich@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))
+}


Mime
View raw message