Skip to content

Instantly share code, notes, and snippets.

@karlentwistle
Last active December 16, 2015 06:49
Show Gist options
  • Save karlentwistle/5394220 to your computer and use it in GitHub Desktop.
Save karlentwistle/5394220 to your computer and use it in GitHub Desktop.
AWS Request Authentication (UNFINISHED)
// http://docs.aws.amazon.com/AWSMechTurk/latest/AWSMechanicalTurkRequester/MakingRequests_RequestAuthenticationArticle.html
// 1 The sender constructs a request to AWS.
// 2 The sender calculates a Keyed-Hashing for Message Authentication code (HMAC), the request signature using the his or her Secret Access Key and the values of the Service, Operation, and Timestamp parameters as input.
// 3 The sender of the request sends the request data, the signature, and Access Key ID (the key-identifier of the Secret Access Key used) to AWS.
// 4 AWS uses the Access Key ID to look up the Secret Access Key.
// 5 AWS generates a signature from the request data and the Secret Access Key using the same algorithm used to calculate the signature in the request.
// 6 If the signature generated by AWS matches the one sent in the request, the request is considered to be authentic. If the comparison fails, the request is discarded, and AWS returns an error response.
package main
import "fmt"
import "crypto/hmac"
import "crypto/sha256"
import "time"
import "encoding/base64"
func main() {
AWSAccessKeyId := "MHAPUBLICKEY"
AWSSecretKeyId := "MHAPRIVATEKEY"
sha256 := sha256.New
time := time.Now().UTC().Format(time.ANSIC)
hash := hmac.New(sha256, []byte(AWSSecretKeyId))
hash.Write([]byte(time))
sha := base64.URLEncoding.EncodeToString(hash.Sum(nil))
fmt.Println("Date", time)
fmt.Println("Content-Type","text/xml; charset=UTF-8")
fmt.Println("AWS3-HTTPS AWSAccessKeyId=",AWSAccessKeyId,"Algorithm=HmacSHA256,Signature=", sha)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment