示例#1
0
文件: webserver.py 项目: ligfx/sadm
def gh_oauth():
    args = bottle.request.query
    if 'code' not in args or 'r' not in args:
        raise bottle.HTTPError(404, 'Missing arguments')
    response = requests.post('https://github.com/login/oauth/access_token',
                             data={'client_id': cfg.github.oauth.client_id,
                                   'client_secret':
                                   cfg.github.oauth.client_secret,
                                   'code': args['code']},
                             headers={'Accept': 'application/json'}).json()
    if 'access_token' not in response:
        raise bottle.HTTPError(403, 'No response token from GitHub')

    token = utils.encrypt_data(response['access_token'].encode('ascii'),
                               cfg.github.oauth.client_secret)
    scope = utils.encrypt_data(response['scope'].encode('ascii'),
                               cfg.github.oauth.client_secret)
    bottle.response.set_cookie('gh_oauth_token',
                               token,
                               secure=True,
                               httponly=True,
                               path='/',
                               secret=cfg.github.oauth.client_secret)
    bottle.response.set_cookie('gh_oauth_scope',
                               scope,
                               secure=True,
                               httponly=True,
                               path='/',
                               secret=cfg.github.oauth.client_secret)

    bottle.redirect(args['r'])
示例#2
0
def gh_oauth():
    args = bottle.request.query
    if "code" not in args or "r" not in args:
        raise bottle.HTTPError(404, "Missing arguments")
    response = requests.post(
        "https://github.com/login/oauth/access_token",
        data={
            "client_id": cfg.github.oauth.client_id,
            "client_secret": cfg.github.oauth.client_secret,
            "code": args["code"],
        },
        headers={"Accept": "application/json"},
    ).json()
    if "access_token" not in response:
        raise bottle.HTTPError(403, "No response token from GitHub")

    token = utils.encrypt_data(response["access_token"].encode("ascii"), cfg.github.oauth.client_secret)
    scope = utils.encrypt_data(response["scope"].encode("ascii"), cfg.github.oauth.client_secret)
    bottle.response.set_cookie(
        "gh_oauth_token", token, secure=True, httponly=True, path="/", secret=cfg.github.oauth.client_secret
    )
    bottle.response.set_cookie(
        "gh_oauth_scope", scope, secure=True, httponly=True, path="/", secret=cfg.github.oauth.client_secret
    )

    bottle.redirect(args["r"])
示例#3
0
文件: krb.py 项目: 5l1v3r1/pykrb
 def send(self, sock, key, addr):
     """Creates a binary blob to send over the wire and then sends it encrypted"""
     p = pack("!h", len(self.user_id))
     p += self.user_id
     p += pack("!I", int(self.timestamp.strftime("%s")))
     p = pack("!b", CLI_AUTH) + encrypt_data(p, key)
     sock.sendto(p, addr)
示例#4
0
文件: krb.py 项目: wumb0/pykrb
 def send(self, sock, key, addr):
     """Creates a binary blob to send over the wire and then sends it encrypted"""
     p  = pack("!h", len(self.user_id))
     p += self.user_id
     p += pack("!I", int(self.timestamp.strftime("%s")))
     p = pack("!b", CLI_AUTH) + encrypt_data(p, key)
     sock.sendto(p, addr)
示例#5
0
文件: krb.py 项目: 5l1v3r1/pykrb
 def send(self, sock, key, addr):
     """Creates a binary blob to send over the wire and then sends it encrypted"""
     p = pack("!h", len(self.tgs_id))
     p += str(self.tgs_id)
     p += pack("!I", int(self.valid_until.strftime("%s")))
     p += pack("!I", int(self.timestamp.strftime("%s")))
     p += self.session_key
     p = pack("!b", TGS_SESS_KEY) + encrypt_data(p, key)
     sock.sendto(p, addr)
示例#6
0
文件: krb.py 项目: wumb0/pykrb
 def send(self, sock, key, addr):
     """Creates a binary blob to send over the wire and then sends it encrypted"""
     p  = pack("!h", len(self.tgs_id))
     p += str(self.tgs_id)
     p += pack("!I", int(self.valid_until.strftime("%s")))
     p += pack("!I", int(self.timestamp.strftime("%s")))
     p += self.session_key
     p  = pack("!b", TGS_SESS_KEY) + encrypt_data(p, key)
     sock.sendto(p, addr)
示例#7
0
文件: krb.py 项目: 5l1v3r1/pykrb
 def send(self, sock, key, addr):
     """Creates a binary blob to send over the wire and then sends it encrypted"""
     p = pack("!h", len(self.client_id))
     p += self.client_id
     p += pack("!h", len(self.svc_id))
     p += self.svc_id
     p += socket.inet_aton(self.net_addr)
     p = str(p)
     p += pack("!I", int(self.valid_until.strftime("%s")))
     p += pack("!I", int(self.timestamp.strftime("%s")))
     p += self.session_key
     p = pack("!b", SVC_TKT_RESP) + encrypt_data(p, key)
     sock.sendto(p, addr)
示例#8
0
文件: krb.py 项目: wumb0/pykrb
 def send(self, sock, key, addr):
     """Creates a binary blob to send over the wire and then sends it encrypted"""
     p  = pack("!h", len(self.client_id))
     p += self.client_id
     p += pack("!h", len(self.svc_id))
     p += self.svc_id
     p += socket.inet_aton(self.net_addr)
     p  = str(p)
     p += pack("!I", int(self.valid_until.strftime("%s")))
     p += pack("!I", int(self.timestamp.strftime("%s")))
     p += self.session_key
     p  = pack("!b", SVC_TKT_RESP) + encrypt_data(p, key)
     sock.sendto(p, addr)