def json(self, indent=None): from base64 import b64encode as base64 from json import dumps as json return json( { "type": self.type, "curve": self.curve, "public": base64(self.public).decode("utf-8"), "secret": base64(self.secret).decode("utf-8"), "comment": self.comment, }, indent=indent, )
def __init__ (self, username, password, repo, branch): self.username = username self.password = password self.repo = repo self.branch = branch self.auth = 'Basic %s' % base64('%s:%s' % (username, password)).replace('\n', '') self.baseurl = "https://api.github.com/repos/" + username + "/" + repo + "/git/"
def create_hash_map(): """Create a hash map for all objects """ hashmap = {} from base64 import encodestring as base64 import pwd login_name = pwd.getpwuid(os.geteuid())[0] conn = http.client.HTTPSConnection("api.github.com") conn.request( "GET", "/repos/nipy/nipype", headers={ 'Authorization': 'Basic %s' % base64(login_name) }) try: conn.request("GET", "/repos/nipy/nipype/git/trees/master?recursive=1") except: pass else: r1 = conn.getresponse() if r1.reason != 'OK': raise Exception('HTTP Response %s:%s' % (r1.status, r1.reason)) payload = simplejson.loads(r1.read()) for infodict in payload['tree']: if infodict['type'] == "blob": hashmap[infodict['sha']] = infodict['path'] return hashmap
def sign(data): orig = data["RequestData"] orig += APP_KEY md5 = hashlib.md5() md5.update(orig.encode("utf-8")) data["DataSign"] = base64(md5.hexdigest().encode("utf-8")).decode("utf-8") return urlencode(data).encode("utf-8")
def SignWithKey(self, key_data): if key_data is None: # We'll cheat, and say this means "get rid of the signature" if SIGNATURE_KEY in self._dict: self._dict.pop(SIGNATURE_KEY) else: import OpenSSL.crypto as Crypto from base64 import b64encode as base64 # If it's a PKey, we don't need to load it if isinstance(key_data, Crypto.PKey): key = key_data else: # Load the key. This is most likely to fail. key = Crypto.load_privatekey(Crypto.FILETYPE_PEM, key_data) # Generate a canonical representation of the manifest temp = self.dict() if SIGNATURE_KEY in temp: temp.pop(SIGNATURE_KEY) tstr = MakeString(temp) # Sign it. signed_value = base64(Crypto.sign(key, tstr, "sha256")) # And now set the signature self._dict[SIGNATURE_KEY] = signed_value return
def SignWithKey(self, key_data): if key_data is None: # We'll cheat, and say this means "get rid of the signature" if SIGNATURE_KEY in self._dict: self._dict.pop(SIGNATURE_KEY) else: import OpenSSL.crypto as Crypto from base64 import b64encode as base64 # If it's a PKey, we don't need to load it if isinstance(key_data, Crypto.PKey): key = key_data else: # Load the key. This is most likely to fail. key = Crypto.load_privatekey(Crypto.FILETYPE_PEM, key_data) # Generate a canonical representation of the manifest temp = self.dict() temp.pop(SIGNATURE_KEY, None) tstr = MakeString(temp) # Sign it. signed_value = base64(Crypto.sign(key, tstr, "sha256")) # And now set the signature self._dict[SIGNATURE_KEY] = signed_value return
def create_hash_map(): """Create a hash map for all objects """ hashmap = {} from base64 import encodestring as base64 import pwd login_name = pwd.getpwuid(os.geteuid())[0] conn = http.client.HTTPSConnection("api.github.com") conn.request("GET", "/repos/nipy/nipype", headers={'Authorization': 'Basic %s' % base64(login_name)}) try: conn.request("GET", "/repos/nipy/nipype/git/trees/master?recursive=1") except: pass else: r1 = conn.getresponse() if r1.reason != 'OK': raise Exception('HTTP Response %s:%s' % (r1.status, r1.reason)) payload = simplejson.loads(r1.read()) for infodict in payload['tree']: if infodict['type'] == "blob": hashmap[infodict['sha']] = infodict['path'] return hashmap
def header_13(self): websocket_guid = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11' websocket_key = self.headers['Sec-WebSocket-Key'] websocket_accept = sha1(websocket_key + websocket_guid).digest() websocket_accept = base64(websocket_accept) self.send_response(101, 'Switching Protocols') self.send_header('Connection', 'Upgrade') self.send_header('Upgrade', 'WebSocket') self.send_header('Sec-WebSocket-Accept', websocket_accept) self.end_headers()
def binary(content: bytes, type: str): return { 'statusCode': 200, 'isBase64Encoded': True, 'headers': { 'Content-Type': type, 'Cache-Control': 'max-age=86400' }, 'body': base64(content).decode("utf-8"), }
def SignWithKey(self, key_data): if key_data is None: # We'll cheat, and say this means "get rid of the signature" self._signature = None else: import OpenSSL.crypto as Crypto from base64 import b64encode as base64 # Load the key. This is most likely to fail. key = Crypto.load_privatekey(Crypto.FILETYPE_PEM, key_data) # Generate a canonical representation of the manifest temp = self.dict() if SIGNATURE_KEY in temp: temp.pop(SIGNATURE_KEY) tstr = MakeString(temp) # Sign it. signed_value = base64(Crypto.sign(key, tstr, "sha256")) # And now set the signature self._signature = signed_value return
def create_hash_map(): """Create a hash map for all objects """ hashmap = {} from base64 import encodestring as base64 import pwd login_name = pwd.getpwuid(os.geteuid())[0] conn = httplib.HTTPSConnection("api.github.com") conn.request("GET", "/repos/nipy/nipype", headers={"Authorization": "Basic %s" % base64(login_name)}) try: conn.request("GET", "/repos/nipy/nipype/git/trees/master?recursive=1") except: pass else: r1 = conn.getresponse() if r1.reason != "OK": raise Exception("HTTP Response %s:%s" % (r1.status, r1.reason)) payload = json.loads(r1.read()) for infodict in payload["tree"]: if infodict["type"] == "blob": hashmap[infodict["sha"]] = infodict["path"] return hashmap
def publishIssues(self, user, repo, authUser, authPassword): '''Publish the issues to github In order to keep the redmine ticket ids we create dummy tickets and close the immediately. user: the github username for the repository repo: the github repository authUser: your github username authPassword: your github password ''' self.baseurl = "https://api.github.com/repos/%s/%s/" % (user, repo) self.authData = base64(bytes(('%s:%s' % (authUser, authPassword)), 'utf-8')).decode().replace('\n', '') # Load milestone data # Milestones are created on demand self.milestones = {} milestonesUrl = self.baseurl + "milestones" for state in ['open', 'closed']: req = urllib.request.Request(milestonesUrl + '?state=' + state) req.add_header('Authorization', 'Basic %s' % self.authData) res = urllib.request.urlopen(req) for milestonedata in json.loads(res.read().decode('utf-8')): self.milestones[milestonedata['title']] = milestonedata # Create label data # Labes are created upfront labels = [] for ilabels in map(lambda p: p.labels, self.githubIssues): for label in ilabels: if not label in labels: labels.append(label) for label in labels: self.createLabel(label) self.createLabel("Dummy-Ticket") currentIssue = 1 for issue in sorted(self.githubIssues, key=lambda p: int(p.id)): # Too keep the old redmine id's we have to create dummy # tickets while currentIssue < int(issue.id): if self.getIssue(currentIssue) == None: self.createIssue("Dummy ticket %d" % currentIssue, labels=["Dummy-Ticket"]) self.closeIssue(currentIssue) currentIssue += 1 # Check if milestone exists milestone = None if issue.milestone: if not issue.milestone in self.milestones: self.createMilestone(issue.milestone) milestone = self.milestones[issue.milestone]['number'] # Check if issue exists githubissuedata = self.getIssue(issue.id) if githubissuedata: print("Issue %d already exists." % int(issue.id)) if githubissuedata['body'] != issue.body: self.createComment(issue.id, issue.title + "\n\n" + issue.body) if githubissuedata['title'] != issue.title: self.editIssue(issue.id, issue.title, body=issue.body, milestone=milestone, labels=issue.labels, assignee=issue.assignee) else: self.createIssue(issue.title, body=issue.body, milestone=milestone, labels=issue.labels, assignee=issue.assignee) # Close tickets if issue.state == 'closed': self.closeIssue(issue.id)
def ssologin(request): code = request.GET.get('code', None) clientid = settings.SSO_CLIENT_ID clientkey = settings.SSO_SECRET_KEY authorization = base64(clientid + ":" + clientkey) redirect_url = settings.SSO_CALLBACK_URL if not code: base = "https://login.eveonline.com/oauth/authorize/?response_type=code" url = base + "&redirect_uri=" + redirect_url + "&client_id=" + clientid + "&scope=" return redirect(url) else: data = {"grant_type": "authorization_code", "code": code} headers = {"Authorization": authorization} data = urlencode(data) rq = urlrequest("https://login.eveonline.com/oauth/token", data, headers) try: result = urlopen(rq) result = json.loads(result.read()) except urllib2.HTTPError, e: r = e.read() return render( request, 'landing.html', { "error": "Your Login Token is invalid or expired. Please try again." }) headers = { "Authorization": "Bearer " + result["access_token"], "Host": "login.eveonline.com" } rq = urlrequest("https://login.eveonline.com/oauth/verify", headers=headers) result = urlopen(rq) result = result.read() result = json.loads(result) if not result["CharacterID"]: return render(request, 'landing.html', { "error": "Cannot get a valid answer from CCP. Please try again." }) try: char = Character.objects.get(charID=result["CharacterID"]) char.profile.user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, char.profile.user) token = request.session.get('appToken', False) if token: return redirect("applications:apply", token=token) return redirect("core:dashboard") except: return render( request, 'landing.html', { "error": "The selected Character is not in our Database. Please register using the link below." })
def digestline(a): hash = base64(self.__algos[a](content).digest()) return "%s-Digest: %s\n" % (a, hash)
def publishIssues(self, user, repo, authUser, authPassword): '''Publish the issues to github In order to keep the redmine ticket ids we create dummy tickets and close the immediately. user: the github username for the repository repo: the github repository authUser: your github username authPassword: your github password ''' self.baseurl = "https://api.github.com/repos/%s/%s/" % (user, repo) self.authData = base64(bytes(('%s:%s' % (authUser, authPassword)), 'utf-8')).decode().replace('\n', '') # Load milestone data # Milestones are created on demand self.milestones = {} milestonesUrl = self.baseurl + "milestones" for state in ['open', 'closed']: req = urllib.request.Request(milestonesUrl + '?state=' + state) req.add_header('Authorization', 'Basic %s' % self.authData) res = urllib.request.urlopen(req) for milestonedata in json.loads(res.read().decode('utf-8')): self.milestones[milestonedata['title']] = milestonedata # Create label data # Labes are created upfront labels = [] for ilabels in map(lambda p: p.labels, self.githubIssues): for label in ilabels: if not label in labels: labels.append(label) for label in labels: self.createLabel(label) self.createLabel("Dummy-Ticket") currentIssue = 1 for issue in sorted(self.githubIssues, key=lambda p: int(p.id)): # To keep the old redmine id's we have to create dummy # tickets # TODO: work around dummy issue creation (seems a bit tedious) while currentIssue < int(issue.id): if self.getIssue(currentIssue) == None: self.createIssue("Dummy ticket %d" % currentIssue, labels=["Dummy-Ticket"]) self.closeIssue(currentIssue) currentIssue += 1 # Check if milestone exists milestone = None if issue.milestone: if not issue.milestone in self.milestones: self.createMilestone(issue.milestone) milestone = self.milestones[issue.milestone]['number'] # Check if issue exists # TODO: since the ID is that originally from Redmine, we need to do the # lookup in a different way. Maybe by issue description instead? githubissuedata = self.getIssue(issue.id) if githubissuedata: print("Issue %d already exists." % int(issue.id)) if githubissuedata['body'] != issue.body: self.createComment(issue.id, issue.title + "\n\n" + issue.body) else: self.createIssue(issue.title, body=issue.body, milestone=milestone, labels=issue.labels, assignee=issue.assignee) # Close tickets if issue.state == 'closed': self.closeIssue(issue.id)
def encode_auth(username, password): auth = base64("%s:%s" % (username, password)).replace("\n", "") return auth
def _auth_headers(): basic_auth_creds = base64("usrname:secret".encode('ascii')) return { 'Authorization': 'Basic %s' % basic_auth_creds.decode('ascii'), 'Content-Type': 'application/json' }
from src.db.contributor_table import add_contributor from src.db.contributor_table import get_contributors_list as getcon from src.utils.login import login import requests import os from base64 import encodestring as base64 token = os.environ.get('GH_API_KEY') token = 'a8076a185ed1496d7d76526e16056b36e206d7f6' encoded_auth = base64('%s:%s' % ('testme45', '12345678d')).replace('\n', '') headers = {'Authorization': 'token ' + token} headers = {'Authorization': 'token %s' % encoded_auth} def get_full_name(username): url = "https://api.github.com/users/" + username.encode('utf8') r = requests.get(url, auth=('testme45', '12345678d')).json() # r=requests.get(url,headers=headers).json() try: fullname = r['name'] except Exception as e: print(r) return "NULL" return str(fullname) def get_contributors(org_name, project_name): # https://api.github.com/repos/KRSSG/robocup-stp/contributors?page=1 all_contributors = list() page_count = 1
def __init__(self, user, repo, authUser, authPassword): self.baseurl = "https://api.github.com/repos/%s/%s/" % (user, repo) self.authData = base64(bytes(('%s:%s' % (authUser, authPassword)), 'utf-8')).decode().replace('\n', '') self.fetchLabels()