Exemplo n.º 1
0
// Canonicalizes and signs the request.
func SignRequest(id cryptools.NamedSigner, req *http.Request) (err os.Error) {
	cstr := CanonicalizeRequest(req)
	//fmt.Printf("Canon String:\n==========\n{%s}\n=========\n", cstr)
	sig, err := cryptools.SignString64(id, base64.StdEncoding, cryptools.SignableString(cstr))
	if err == nil {
		req.Form["Signature"] = []string{sig}
	}
	return
}
Exemplo n.º 2
0
func (self *Request) Sign(id cryptools.NamedSigner) (err os.Error) {
	params := maptools.StringStringsJoin(self.Form, ",", true)
	cmap := maptools.StringStringEscape(params, aws.Escape, aws.Escape)
	cstr := strings.Join([]string{self.Method, self.Host, self.URL.Path,
		maptools.StringStringJoin(cmap, "=", "&", true)}, "\n")
	sig, err := cryptools.SignString64(id, base64.StdEncoding, cryptools.SignableString(cstr))
	if err == nil {
		self.Form["Signature"] = []string{sig}
	}
	return
}
Exemplo n.º 3
0
// Constructs a query request object;  This complex type implements
// both the Canonicalization and Signing methods necessary to access
// S3.
//
// For the most part, users are expected to use the exposed bucket/endpoint/obj
// functions
//
// If Expiration is < 1 year (in seconds), the expiration is assumed to
// mean seconds-from-now (local clock based).
func NewQueryRequest(id cryptools.NamedSigner, endpoint *awsconn.Endpoint,
	method, bucket, key, ctype, cmd5 string,
	params, hdrs map[string]string) (req *http.Request, err os.Error) {
	req = &http.Request{
		Method: method,
		Host:   endpoint.GetURL().Host,
		URL: &http.URL{
			Scheme: endpoint.GetURL().Scheme,
			Host:   endpoint.GetURL().Host,
			Path:   endpoint.GetURL().Path,
		},
		Header: hdrs,
		Form:   maptools.StringStringToStringStrings(params),
	}
	if req.Header == nil {
		req.Header = make(map[string]string)
	}
	if ctype != "" {
		req.Header["Content-Type"] = ctype
	}
	if cmd5 != "" {
		req.Header["Content-Md5"] = cmd5
	}
	if bucket != "" {
		req.URL.Path = "/" + bucket
		if key != "" {
			req.URL.Path += "/" + key
		}
	}
	req.Form["AWSAccessKeyId"] = []string{id.SignerName()}
	if len(req.Form["Expires"]) == 0 {
		req.Form["Expires"] = []string{strconv.Itoa64(time.Seconds() + 30)}
	}
	if len(req.Form["Signature"]) == 0 {
		sig, err := cryptools.SignString64(id, base64.StdEncoding, cryptools.SignableString(CanonicalString(req)))
		if err != nil {
			return
		}
		req.Form["Signature"] = []string{sig}
	}
	return
}