Exemplo n.º 1
0
    def read_oauth2_tok_sec(cls, email):
        """
           Read oauth2 refresh token secret
           Look by default to ~/.gmvault
           Look for file ~/.gmvault/email.oauth2
        """
        gmv_dir = gmvault_utils.get_home_dir_path()

        #look for email.passwed in GMV_DIR
        user_oauth_file_path = "%s/%s.oauth2" % (gmv_dir, email)

        oauth_result = None

        if os.path.exists(user_oauth_file_path):
            LOG.critical("Get OAuth2 credential from %s.\n" %
                         user_oauth_file_path)

            try:
                with open(user_oauth_file_path) as oauth_file:
                    oauth_result = json.load(oauth_file)
            except Exception, _:  #pylint: disable-msg=W0703
                LOG.critical(
                    "Cannot read oauth credentials from %s. Force oauth credentials renewal."
                    % user_oauth_file_path)
                LOG.critical("=== Exception traceback ===")
                LOG.critical(gmvault_utils.get_exception_traceback())
                LOG.critical("=== End of Exception traceback ===\n")
Exemplo n.º 2
0
    def store_oauth2_credentials(cls, email, access_token, refresh_token,
                                 validity, type):
        """
           store oauth_credentials
        """
        oauth_file = '%s/%s.oauth2' % (gmvault_utils.get_home_dir_path(),
                                       email)

        # Open a file
        fdesc = os.open(oauth_file, os.O_RDWR | os.O_CREAT)

        #write new content
        fobj = os.fdopen(fdesc, "w")

        #empty file
        fobj.truncate()
        fobj.seek(0, os.SEEK_SET)

        the_obj = {
            "access_token": access_token,
            "refresh_token": refresh_token,
            "validity": validity,
            "access_creation": gmvault_utils.get_utcnow_epoch(),
            "type": type
        }

        json.dump(the_obj, fobj)

        fobj.close()
Exemplo n.º 3
0
    def store_oauth2_credentials(cls, email, access_token, refresh_token, validity, type):
        """
           store oauth_credentials
        """
        oauth_file = '%s/%s.oauth2' % (gmvault_utils.get_home_dir_path(), email)

        # Open a file
        fdesc = os.open(oauth_file, os.O_RDWR|os.O_CREAT )

        #write new content
        fobj = os.fdopen(fdesc, "w")

        #empty file
        fobj.truncate()
        fobj.seek(0, os.SEEK_SET)


        the_obj = { "access_token"    : access_token,
                    "refresh_token"   : refresh_token,
                    "validity"        : validity,
                    "access_creation" : gmvault_utils.get_utcnow_epoch(),
                    "type"            : type}

        json.dump(the_obj, fobj)

        fobj.close()
Exemplo n.º 4
0
 def store_passwd(cls, email, passwd):
     """
        Encrypt and store gmail password
     """
     passwd_file = '%s/%s.passwd' % (gmvault_utils.get_home_dir_path(), email)
 
     fdesc = os.open(passwd_file, os.O_CREAT|os.O_WRONLY, 0600)
     
     cipher       = blowfish.Blowfish(cls.get_secret_key(cls.SECRET_FILEPATH % (gmvault_utils.get_home_dir_path())))
     cipher.initCTR()
 
     encrypted = cipher.encryptCTR(passwd)
     the_bytes = os.write(fdesc, encrypted)
 
     os.close(fdesc)
     
     if the_bytes < len(encrypted):
         raise Exception("Error: Cannot write password in %s" % (passwd_file))
Exemplo n.º 5
0
    def read_password(cls, email):
        """
           Read password credentials
           Look by default to ~/.gmvault
           Look for file ~/.gmvault/email.passwd
        """
        gmv_dir = gmvault_utils.get_home_dir_path()

        #look for email.passwed in GMV_DIR
        user_passwd_file_path = "%s/%s.passwd" % (gmv_dir, email)

        password = None
        if os.path.exists(user_passwd_file_path):
            with open(user_passwd_file_path) as f:
                password = f.read()
            cipher = blowfish.Blowfish(
                cls.get_secret_key(cls.SECRET_FILEPATH %
                                   (gmvault_utils.get_home_dir_path())))
            cipher.initCTR()
            password = cipher.decryptCTR(password)

        return password
Exemplo n.º 6
0
 def store_oauth_credentials(cls, email, token, secret, type):
     """
        store oauth_credentials
     """
     oauth_file = '%s/%s.oauth' % (gmvault_utils.get_home_dir_path(), email)
 
     fdesc = os.open(oauth_file, os.O_CREAT|os.O_WRONLY, 0600)
     
     os.write(fdesc, token)
     os.write(fdesc, '::')
     os.write(fdesc, secret)
     os.write(fdesc, '::')
     os.write(fdesc, type)
 
     os.close(fdesc)
Exemplo n.º 7
0
    def read_password(cls, email):
        """
           Read password credentials
           Look by default to ~/.gmvault
           Look for file ~/.gmvault/email.passwd
        """
        gmv_dir = gmvault_utils.get_home_dir_path()

        #look for email.passwed in GMV_DIR
        user_passwd_file_path = "%s/%s.passwd" % (gmv_dir, email)

        password = None
        if os.path.exists(user_passwd_file_path):
            with open(user_passwd_file_path) as f:
                password = f.read()
            cipher       = blowfish.Blowfish(cls.get_secret_key(cls.SECRET_FILEPATH % (gmvault_utils.get_home_dir_path())))
            cipher.initCTR()
            password     = cipher.decryptCTR(password)

        return password
Exemplo n.º 8
0
    def read_oauth_tok_sec(cls, email):
        """
           Read oauth token secret credential
           Look by default to ~/.gmvault
           Look for file ~/.gmvault/email.oauth
        """
        gmv_dir = gmvault_utils.get_home_dir_path()
        
        #look for email.passwed in GMV_DIR
        user_oauth_file_path = "%s/%s.oauth" % (gmv_dir, email)

        token  = None
        secret = None
        type   = None
        if os.path.exists(user_oauth_file_path):
            LOG.critical("Get XOAuth credential from %s.\n" % (user_oauth_file_path))
            
            oauth_file  = open(user_oauth_file_path)
            
            try:
                oauth_result = oauth_file.read()
                if oauth_result:
                    oauth_result = oauth_result.split('::')
                    if len(oauth_result) == 2:
                        token  = oauth_result[0]
                        secret = oauth_result[1]
                        type   = "normal"
                    elif len(oauth_result) == 3:
                        token  = oauth_result[0]
                        secret = oauth_result[1]
                        type   = oauth_result[2]
            except Exception, _: #pylint: disable-msg=W0703              
                LOG.critical("Cannot read oauth credentials from %s. Force oauth credentials renewal." % (user_oauth_file_path))
                LOG.critical("=== Exception traceback ===")
                LOG.critical(gmvault_utils.get_exception_traceback())
                LOG.critical("=== End of Exception traceback ===\n")
Exemplo n.º 9
0
    def read_oauth2_tok_sec(cls, email):
        """
           Read oauth2 refresh token secret
           Look by default to ~/.gmvault
           Look for file ~/.gmvault/email.oauth2
        """
        gmv_dir = gmvault_utils.get_home_dir_path()

        #look for email.passwed in GMV_DIR
        user_oauth_file_path = "%s/%s.oauth2" % (gmv_dir, email)

        oauth_result = None

        if os.path.exists(user_oauth_file_path):
            LOG.critical("Get OAuth2 credential from %s.\n" % user_oauth_file_path)

            try:
                with open(user_oauth_file_path) as oauth_file:
                    oauth_result = json.load(oauth_file)
            except Exception, _: #pylint: disable-msg=W0703
                LOG.critical("Cannot read oauth credentials from %s. Force oauth credentials renewal." % user_oauth_file_path)
                LOG.critical("=== Exception traceback ===")
                LOG.critical(gmvault_utils.get_exception_traceback())
                LOG.critical("=== End of Exception traceback ===\n")