~ubuntu-branches/ubuntu/vivid/juju-core/vivid-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/goamz/iam/sign.go

  • Committer: Package Import Robot
  • Author(s): Curtis C. Hovey
  • Date: 2015-09-29 19:43:29 UTC
  • mfrom: (47.1.4 wily-proposed)
  • Revision ID: package-import@ubuntu.com-20150929194329-9y496tbic30hc7vp
Tags: 1.24.6-0ubuntu1~15.04.1
Backport of 1.24.6 from wily. (LP: #1500916, #1497087)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package iam
2
 
 
3
 
import (
4
 
        "crypto/hmac"
5
 
        "crypto/sha256"
6
 
        "encoding/base64"
7
 
        "launchpad.net/goamz/aws"
8
 
        "sort"
9
 
        "strings"
10
 
)
11
 
 
12
 
// ----------------------------------------------------------------------------
13
 
// Version 2 signing (http://goo.gl/RSRp5)
14
 
 
15
 
var b64 = base64.StdEncoding
16
 
 
17
 
func sign(auth aws.Auth, method, path string, params map[string]string, host string) {
18
 
        params["AWSAccessKeyId"] = auth.AccessKey
19
 
        params["SignatureVersion"] = "2"
20
 
        params["SignatureMethod"] = "HmacSHA256"
21
 
 
22
 
        var sarray []string
23
 
        for k, v := range params {
24
 
                sarray = append(sarray, aws.Encode(k)+"="+aws.Encode(v))
25
 
        }
26
 
        sort.StringSlice(sarray).Sort()
27
 
        joined := strings.Join(sarray, "&")
28
 
        payload := method + "\n" + host + "\n" + path + "\n" + joined
29
 
        hash := hmac.New(sha256.New, []byte(auth.SecretKey))
30
 
        hash.Write([]byte(payload))
31
 
        signature := make([]byte, b64.EncodedLen(hash.Size()))
32
 
        b64.Encode(signature, hash.Sum(nil))
33
 
 
34
 
        params["Signature"] = string(signature)
35
 
}