Esempio n. 1
0
def main(save=True, encrypt=True):
    if save is True:
        key = fernet.Fernet.generate_key()
        file = open('key\key.key', 'wb')
        file.write(key)
        file.close()
    else:
        file = open('key\key.key', 'rb')
        key = file.read()
        file.close()
    if encrypt:
        # Encrypt the file
        with open(FILE_PATH, 'rb') as f:
            data = f.read()

        f = fernet.Fernet(key)
        encrypted = f.encrypt(data)

        # Write the encrypted file
        with open(FILE_PATH + ".encrypted", 'wb') as f:
            f.write(encrypted)
    else:
        # Decode the file
        with open(FILE_PATH + ".encrypted", "rb") as f:
            image = f.read()
        f = fernet.Fernet(key)
        decrypted = f.decrypt(image)
        # Write the decrypted file
        with open(FILE_PATH, 'wb') as f:
            f.write(decrypted)
Esempio n. 2
0
def poll_google_token(device_code: str) -> bytes:
    """this is where we actually talk to google
    the Javascript pools us at the specified interval
    and we query Google for our authorization token.
    when we get it we send it to the process that will
    run the photogrammetry rig"""

    target_url = "https://www.googleapis.com/oauth2/v4/token"
    grant_type = "http://oauth.net/grant_type/device/1.0"

    arguments = "code=" + device_code + \
                "&client_id=" + google_api.CLIENT_ID + \
                "&client_secret=" + google_api.CLIENT_SECRET + \
                "&grant_type=" + grant_type
    rsp = requests.post(target_url,
                        data=arguments,
                        headers={'content-type': 'application/x-www-form-urlencoded'})
    if rsp.status_code == status.HTTP_200_OK:
        queue = configure_beanstalk()
        data_str = rsp.content.decode("utf-8")
        send_token(queue, data_str)
        key = machine_specific_key()
        f_obj = fernet.Fernet(key)
        token = f_obj.encrypt(data_str)
        return token

    return None
Esempio n. 3
0
def decrypt_authorization(encrypted_cookie_data: str) -> dict:
    """Decrypt a blob of data passed to us and return
    it as a dictionary"""
    key = machine_specific_key()
    f_obj = fernet.Fernet(key)
    dict_str = f_obj.decrypt(encrypted_cookie_data.encode()).decode("utf-8")
    dict_oauth = json.loads(dict_str)
    return dict_oauth
Esempio n. 4
0
 def save(self, *args):
     print(f"#02398723ß SomethingDing.save: {args}")
     migel = fernet.Fernet(base64.urlsafe_b64encode(
         self._initialize()[:32]))
     ding = "\n".join(args)
     dong = migel.encrypt(ding.encode())
     with open(self.file_name, "wb") as fh:
         fh.write(dong)
Esempio n. 5
0
 def __init__(self,
              secret_key: bytes,
              cookie_key: bytes = _COOKIE_KEY,
              domain: bytes = None,
              path: bytes = b'/',
              expires: datetime.datetime = None,
              max_age: int = None,
              http_only: bool = True,
              secure: bool = False):
     self._fernet = fernet.Fernet(base64.urlsafe_b64encode(secret_key))
     AbstractSessionStorage.__init__(self, cookie_key, domain, path,
                                     expires, max_age, http_only, secure)
Esempio n. 6
0
    def load(self):
        try:
            with open(self.file_name, "rb") as fh:
                dong = fh.read()
        except FileNotFoundError as e:
            print(
                f"{Fore.RED}ERROR #kas09u23ojbk23 --> keine zugangsdaten gespeichert {e.__traceback__.tb_lineno}, {repr(e.__traceback__)}, {repr(e)},  {e.__cause__}{Fore.RESET}"
            )

            return False
        migel = fernet.Fernet(base64.urlsafe_b64encode(
            self._initialize()[:32]))
        try:
            return migel.decrypt(dong,
                                 ttl=60 * 60 * 24 * 3).decode().split("\n")
        except fernet.InvalidToken as e:
            print(
                f"{Fore.RED}ERROR #90304ij2o3 -->  {e.__traceback__.tb_lineno}, {repr(e.__traceback__)}, {repr(e)},  {e.__cause__}{Fore.RESET}"
            )

            self.delete()
            return False