Exemplo n.º 1
0
def digest(un,
           pw,
           nonce=None,
           uri=None,
           method='GET',
           nc=1,
           qop='auth',
           realm=REALM,
           cnonce=None,
           algorithm='MD5',
           body=b'',
           modify=lambda x: None):
    'Create the payload for a digest based Authorization header'
    from calibre.srv.auth import DigestAuth
    templ = (
        'username="******", realm="{realm}", qop={qop}, method="{method}",'
        ' nonce="{nonce}", uri="{uri}", nc={nc}, algorithm="{algorithm}", cnonce="{cnonce}", response="{response}"'
    )
    h = templ.format(un=un,
                     realm=realm,
                     qop=qop,
                     uri=uri,
                     method=method,
                     nonce=nonce,
                     nc=nc,
                     cnonce=cnonce,
                     algorithm=algorithm,
                     response=None)
    da = DigestAuth(h)
    modify(da)
    pw = getattr(da, 'pw', pw)

    class Data(object):
        def __init__(self):
            self.method = method

        def peek(self):
            return body

    response = da.request_digest(pw, Data())
    return ('Digest ' + templ.format(un=un,
                                     realm=realm,
                                     qop=qop,
                                     uri=uri,
                                     method=method,
                                     nonce=nonce,
                                     nc=nc,
                                     cnonce=cnonce,
                                     algorithm=algorithm,
                                     response=response)).encode('ascii')
Exemplo n.º 2
0
def digest(un, pw, nonce=None, uri=None, method='GET', nc=1, qop='auth', realm=REALM, cnonce=None, algorithm='MD5', body=b'', modify=lambda x:None):
    'Create the payload for a digest based Authorization header'
    from calibre.srv.auth import DigestAuth
    templ = ('username="******", realm="{realm}", qop={qop}, method="{method}",'
    ' nonce="{nonce}", uri="{uri}", nc={nc}, algorithm="{algorithm}", cnonce="{cnonce}", response="{response}"')
    h = templ.format(un=un, realm=realm, qop=qop, uri=uri, method=method, nonce=nonce, nc=nc, cnonce=cnonce, algorithm=algorithm, response=None)
    da = DigestAuth(h)
    modify(da)
    pw = getattr(da, 'pw', pw)
    class Data(object):
        def __init__(self):
            self.method = method
        def peek():
            return body
    response = da.request_digest(pw, Data())
    return ('Digest ' + templ.format(
        un=un, realm=realm, qop=qop, uri=uri, method=method, nonce=nonce, nc=nc, cnonce=cnonce, algorithm=algorithm, response=response)).encode('ascii')