Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

canonicalize_string is broken #40

Closed
wyllys66 opened this issue Apr 15, 2013 · 4 comments
Closed

canonicalize_string is broken #40

wyllys66 opened this issue Apr 15, 2013 · 4 comments

Comments

@wyllys66
Copy link
Contributor

The canonicalize_string function is broken, it does not properly preserve parameters and does not have the correct keywords list.

@wyllys66
Copy link
Contributor Author

Suggested fix:


def canonical_string(req):
    """
    Canonicalize a request to a token that can be signed.
    """
    amz_headers = {}
    buf = "%s\n%s\n%s\n" % (req.method, req.headers.get('Content-MD5', ''),
                            req.headers.get('Content-Type') or '')
    for amz_header in sorted((key.lower() for key in req.headers
                              if key.lower().startswith('x-amz-'))):
        amz_headers[amz_header] = req.headers[amz_header]
    if 'x-amz-date' in amz_headers:
        buf += "\n"
    elif 'Date' in req.headers:
        buf += "%s\n" % req.headers['Date']
    for k in sorted(key.lower() for key in amz_headers):
        buf += "%s:%s\n" % (k, amz_headers[k])
    # RAW_PATH_INFO is enabled in later version than eventlet 0.9.17.
    # When using older version, swift3 uses req.path of swob instead
    # of it.
    path = req.environ.get('RAW_PATH_INFO', req.path)
    if req.query_string:
        path += '?' + req.query_string
    if '?' in path:
        path, args = path.split('?', 1)
    qstr = ''
    qdict = dict(urlparse.parse_qsl(args, keep_blank_values=True))
    #
    # List of  sub-resources that must be maintained as part of the HMAC signature string.
    # from http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationRequestCanonicalization
    #
    keywords = sorted(['acl', 'delete', 'lifecycle', 'location', 'logging', 'notification', 'partNumber',
                        'policy', 'requestPayment', 'torrent', 'uploads', 'uploadId', 'versionId',
                        'versioning', 'versions ', 'website'])
        for key in qdict:
            if key in keywords:
        newstr = key
        if qdict[key]:
            newstr = newstr + '=%s' % qdict[key]
        if qstr == '': 
            qstr = newstr
        else:
            qstr = qstr + '&%s' % newstr
    if qstr != '':
        return "%s%s?%s" % (buf, path, qstr)
    return buf + path

@fujita
Copy link
Owner

fujita commented Apr 15, 2013

Can you create a patch and send a pull request?

@wyllys66
Copy link
Contributor Author

Ok, ill try to get that to you later this week.

Are you at openstack summit this week? If so, we should meet up.

Wyllys

On Apr 15, 2013, at 1:44 PM, "FUJITA Tomonori" <[email protected]mailto:[email protected]> wrote:

Can you create a patch and send a pull request?


Reply to this email directly or view it on GitHubhttps://github.com//issues/40#issuecomment-16410266.

@fujita
Copy link
Owner

fujita commented Apr 16, 2013

I'm not but my colleagues who work on swift and swift3 are. Can you contact me by e-mail? I'll send the addresses of them.

@fujita fujita closed this as completed May 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants