Beispiel #1
0
// Used exclusively by S3 to the best of my knowledge...
func (self *Signer) SignRequestV1(req *http.Request, canon func(*http.Request) (string, os.Error), exp int64) (err os.Error) {
	qstring, err := http.ParseQuery(req.URL.RawQuery)

	if err != nil {
		return
	}

	if exp > 0 {
		qstring["Expires"] = []string{strconv.Itoa64(time.Seconds() + exp)}
	} else {
		qstring["Timestamp"] = []string{time.UTC().Format(ISO8601TimestampFormat)}
	}
	qstring["Signature"] = nil, false
	qstring["AWSAccessKeyId"] = []string{self.AccessKey}

	req.URL.RawQuery = http.Values(qstring).Encode()

	can, err := canon(req)
	if err != nil {
		return
	}

	var sig []byte
	sig, err = self.SignEncoded(crypto.SHA1, can, base64.StdEncoding)

	if err == nil {
		req.URL.RawQuery += "&" + http.Values{"Signature": []string{string(sig)}}.Encode()
	}

	return
}
// NewPOSTTask creates a Task that will POST to a path with the given form data.
func NewPOSTTask(path string, params map[string][]string) *Task {
	h := make(http.Header)
	h.Set("Content-Type", "application/x-www-form-urlencoded")
	return &Task{
		Path:    path,
		Payload: []byte(http.Values(params).Encode()),
		Header:  h,
		Method:  "POST",
	}
}
Beispiel #3
0
func postTweet(token *oauth.Credentials, url string, opt map[string]string) os.Error {
	param := make(web.Values)
	for k, v := range opt {
		param.Set(k, v)
	}
	oauthClient.SignParam(token, "POST", url, param)
	res, err := http.PostForm(url, http.Values(param))
	if err != nil {
		log.Println("failed to post tweet:", err)
		return err
	}
	defer res.Body.Close()
	if res.StatusCode != 200 {
		log.Println("failed to get timeline:", err)
		return err
	}
	return nil
}
Beispiel #4
0
// The V2 denotes amazon signing version 2, not version 2 of this particular function...
// V2 is used by all services but S3;
// Note, some services vary in their exact implementation of escaping w/r/t signatures,
// so it is recommended you use this function.
//
// Final note: if exp is set to 0, a Timestamp will be used, otherwise an expiration.
func (self *Signer) SignRequestV2(req *http.Request, canon func(*http.Request) (string, os.Error), api_ver string, exp int64) (err os.Error) {
	// log.Printf("Signing request...")

	qstring, err := http.ParseQuery(req.URL.RawQuery)
	if err != nil {
		return
	}
	qstring["SignatureVersion"] = []string{DEFAULT_SIGNATURE_VERSION}
	if _, ok := qstring["SignatureMethod"]; !ok || len(qstring["SignatureMethod"]) == 0 {
		qstring["SignatureMethod"] = []string{DEFAULT_SIGNATURE_METHOD}
	}
	qstring["Version"] = []string{api_ver}

	if exp > 0 {
		qstring["Expires"] = []string{strconv.Itoa64(time.Seconds() + exp)}
	} else {
		qstring["Timestamp"] = []string{time.UTC().Format(ISO8601TimestampFormat)}
	}
	qstring["Signature"] = nil, false
	qstring["AWSAccessKeyId"] = []string{self.AccessKey}

	var sig []byte
	req.URL.RawQuery = http.Values(qstring).Encode()
	can, err := canon(req)
	if err != nil {
		return
	}
	//log.Printf("String-to-sign: '%s'", can)

	switch qstring["SignatureMethod"][0] {
	case "HmacSHA256":
		sig, err = self.SignEncoded(crypto.SHA256, can, base64.StdEncoding)
	case "HmacSHA1":
		sig, err = self.SignEncoded(crypto.SHA1, can, base64.StdEncoding)
	default:
		err = os.NewError("Unknown SignatureMethod:" + req.Form.Get("SignatureMethod"))
	}

	if err == nil {
		req.URL.RawQuery += "&" + http.Values{"Signature": []string{string(sig)}}.Encode()
	}

	return
}