当前位置: 首页>>代码示例>>Python>>正文


Python Util.saveKeys方法代码示例

本文整理汇总了Python中Tardis.Util.saveKeys方法的典型用法代码示例。如果您正苦于以下问题:Python Util.saveKeys方法的具体用法?Python Util.saveKeys怎么用?Python Util.saveKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tardis.Util的用法示例。


在下文中一共展示了Util.saveKeys方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: moveKeys

# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import saveKeys [as 别名]
def moveKeys(db, crypt):
    try:
        if args.keys is None:
            logger.error("Must specify key file for key manipulation")
            return 1
        clientId = db.getConfigValue("ClientID")
        token = crypt.createToken()
        (db, _) = getDB(crypt)
        if args.extract:
            (f, c) = db.getKeys()
            if not (f and c):
                raise Exception("Unable to retrieve keys from server.  Aborting.")
            Util.saveKeys(args.keys, clientId, f, c)
            if args.deleteKeys:
                db.setKeys(token, None, None)
        elif args.insert:
            (f, c) = Util.loadKeys(args.keys, clientId)
            logger.info("Keys: F: %s C: %s", f, c)
            if not (f and c):
                raise Exception("Unable to retrieve keys from key database.  Aborting.")
            db.setKeys(token, f, c)
            if args.deleteKeys:
                Util.saveKeys(args.keys, clientId, None, None)
        return 0
    except Exception as e:
        logger.error(e)
        logger.exception(e)
        return 1
开发者ID:daleathan,项目名称:Tardis,代码行数:30,代码来源:Sonic.py

示例2: changePassword

# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import saveKeys [as 别名]
def changePassword(crypt, crypt2):
    try:
        (db, _) = getDB(crypt)
        # Load the keys, and insert them into the crypt object, to decyrpt them
        if args.keys:
            (f, c) = Util.loadKeys(args.keys, db.getConfigValue("ClientID"))
        else:
            (f, c) = db.getKeys()
        crypt.setKeys(f, c)

        # Grab the keys from one crypt object.
        # Need to do this because getKeys/setKeys assumes they're encrypted, and we need the raw
        # versions
        crypt2._filenameKey = crypt._filenameKey
        crypt2._contentKey = crypt._contentKey
        # Now get the encrypted versions
        (f, c) = crypt2.getKeys()
        if args.keys:
            db.beginTransaction()
            db.setToken(crypt2.createToken())
            Util.saveKeys(args.keys, db.getConfigValue("ClientID"), f, c)
            db.commit()
        else:
            db.setKeys(crypt2.createToken(), f, c)
        db.close()
        return 0
    except Exception as e:
        logger.error(e)
        return 1
开发者ID:daleathan,项目名称:Tardis,代码行数:31,代码来源:Sonic.py

示例3: moveKeys

# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import saveKeys [as 别名]
def moveKeys(db, crypt):
    try:
        if args.keys is None:
            logger.error("Must specify key file for key manipulation")
            return 1
        clientId = db.getConfigValue('ClientID')
        salt, vkey = db.getSrpValues()
        #(db, _) = getDB(crypt)
        if args.extract:
            (f, c) = db.getKeys()
            if not (f and c):
                raise Exception("Unable to retrieve keys from server.  Aborting.")
            Util.saveKeys(args.keys, clientId, f, c)
            if args.deleteKeys:
                db.setKeys(salt, vkey, None, None)
        elif args.insert:
            (f, c) = Util.loadKeys(args.keys, clientId)
            logger.info("Keys: F: %s C: %s", f, c)
            if not (f and c):
                raise Exception("Unable to retrieve keys from key database.  Aborting.")
            db.setKeys(salt, vkey, f, c)
            if args.deleteKeys:
                Util.saveKeys(args.keys, clientId, None, None)
        return 0
    except TardisDB.AuthenticationException as e:
        logger.error("Authentication failed.  Bad password")
        return 1
    except Exception as e:
        logger.error(e)
        if args.exceptions:
            logger.exception(e)
        return 1
开发者ID:koldinger,项目名称:Tardis,代码行数:34,代码来源:Sonic.py

示例4: setPassword

# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import saveKeys [as 别名]
def setPassword(crypt, password):
    try:
        (db, _, _) = getDB(None, None)
        crypt.genKeys()
        (f, c) = crypt.getKeys()
        (salt, vkey) = srp.create_salted_verification_key(args.client, password)
        if args.keys:
            db.beginTransaction()
            db.setSrpValues(salt, vkey)
            Util.saveKeys(args.keys, db.getConfigValue('ClientID'), f, c)
            db.commit()
        else:
            db.setKeys(salt, vkey, f, c)
        return 0
    except TardisDB.NotAuthenticated:
        logger.error('Client %s already has a password', args.client)
        if args.exceptions:
            logger.exception(e)
        return 1
    except TardisDB.AuthenticationFailed as e:
        logger.error("Authentication failed.  Bad password")
        if args.exceptions:
            logger.exception(e)
        return 1
    except Exception as e:
        logger.error(str(e))
        if args.exceptions:
            logger.exception(e)
        return 1
开发者ID:koldinger,项目名称:Tardis,代码行数:31,代码来源:Sonic.py

示例5: changePassword

# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import saveKeys [as 别名]
def changePassword(crypt, oldpw) :
    try:
        (db, _, crypt) = getDB(crypt, oldpw)

        # Get the new password
        try:
            newpw = Util.getPassword(args.newpw, args.newpwf, args.newpwp, prompt="New Password for %s: " % (args.client),
                                     allowNone=False, confirm=True, strength=True)
        except Exception as e:
            logger.critical(str(e))
            if args.exceptions:
                logger.exception(e)
            return -1

        crypt2 = TardisCrypto.TardisCrypto(newpw, args.client)

        # Load the keys, and insert them into the crypt object, to decyrpt them
        if args.keys:
            (f, c) = Util.loadKeys(args.keys, db.getConfigValue('ClientID'))
            # No need to check here, loadKeys() throws exception if nothing set.
        else:
            (f, c) = db.getKeys()
            if f is None or c is None:
                logger.critical("No keys loaded from database.  Please specify --keys as appropriate")
                raise Exception("No keys loaded")
        crypt.setKeys(f, c)

        # Grab the keys from one crypt object.
        # Need to do this because getKeys/setKeys assumes they're encrypted, and we need the raw
        # versions
        crypt2._filenameKey = crypt._filenameKey
        crypt2._contentKey  = crypt._contentKey
        # Now get the encrypted versions
        (f, c) = crypt2.getKeys()

        (salt, vkey) = srp.create_salted_verification_key(args.client, newpw)

        if args.keys:
            db.beginTransaction()
            db.setSrpValues(salt, vkey)
            Util.saveKeys(args.keys, db.getConfigValue('ClientID'), f, c)
            db.commit()
        else:
            db.setKeys(salt, vkey, f, c)
        return 0
    except Exception as e:
        logger.error(str(e))
        if args.exceptions:
            logger.exception(e)
        return 1
开发者ID:koldinger,项目名称:Tardis,代码行数:52,代码来源:Sonic.py

示例6: setToken

# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import saveKeys [as 别名]
def setToken(crypt):
    try:
        # Must be no token specified yet
        (db, _) = getDB(None)
        crypt.genKeys()
        (f, c) = crypt.getKeys()
        token = crypt.createToken()
        if args.keys:
            db.beginTransaction()
            db.setToken(token)
            Util.saveKeys(args.keys, db.getConfigValue("ClientID"), f, c)
            db.commit()
        else:
            db.setKeys(token, f, c)
        db.close()
        return 0
    except Exception as e:
        logger.error(e)
        return 1
开发者ID:daleathan,项目名称:Tardis,代码行数:21,代码来源:Sonic.py


注:本文中的Tardis.Util.saveKeys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。