Example #1
0
 def __init__(self, firstname, lastname, username, password, email, id):
     self.id = id
     self._balance = 0
     self.username = username
     self._password = encrypt.encrypt(password, 'c')
     self.firstname = firstname
     self.lastname = lastname
     self.email = email
     self.coalition = None
     self.session_id = 'none'
     self.transaction_history = []
     self.messages = []
     self.sent_messages = []
     self.shell = False
     self.validator = self.get_new_validator()
     self.total_hunts = 0
     self.active_hunts = 0
     self.my_hunts = []
     self.working_hunts = []
     self.last_activity = 'Unused'
     self.date_of_creation = time.strftime('%c')
     self.admin = False
     self.blacklisted = False
     self.ip_addresses = set()
     self.settings = {}
     self.requested_coalition = False
     self.coal_pct_loaned = 0.0
     self.signup_data = dict()
     self.my_sales = []
Example #2
0
    def handler(self, hostname=None):
        print('agent')
        # 资产采集
        info = get_server_info(self, hostname)

        # 数据分析

        if not os.path.exists(settings.CERT_PATH):
            # 新增
            info['type'] = 'create'


        else:
            with open(settings.CERT_PATH, 'r', encoding='utf-8') as f:
                cert = f.read()

            hostname = info['basic']['data']['hostname']

            if cert == hostname:
                # 主机名没变 更新资产信息
                info['type'] = 'update'

            else:
                # 主机名变了,更新资产信息,并提交旧的主机名
                info['type'] = 'host_change'
                info['cert'] = cert

        # 资产上报

        ctime = time.time()
        r1 = requests.post(
            url='http://127.0.0.1:8000/api/asset/',
            params={'key':gen_key(ctime),'ctime':ctime},
            data=encrypt(json.dumps(info).encode('utf-8')),
            headers={
                'content-type': 'application/json'
            }
        )

        # 保存唯一标识

        data = r1.json()
        print(data)

        if data.get('status'):
            with open(settings.CERT_PATH, 'w', encoding='utf-8')as f:
                f.write(data.get('hostname'))
Example #3
0
def create(key,
           purpose: str,
           claims: dict,
           exp_seconds=None,
           footer=None,
           encoder=JsonEncoder):
    """
    Creates a new paseto token using the provided key, purpose, and claims.

    The exp claim is registered. To set it manually, leave the `exp_seconds`
    parameter as None, and manually put it into your claims dict. Otherwise,
    it acts as a number-of-seconds-from-now and is dynamically calculated when
    the token is made.

    You may pass an alternative encoder if you don't want to use JSON. It
    should have loads/dumps methods available, and output a bytes object (not
    a str).
    :param key:
    :param purpose:
    :param claims: dict of the claims to include in the token
    :param exp_seconds: number of seconds from now before expiration
    :param footer: dict of footer that will be authenticated but notencrypted
    :param encoder: encoder to use if you don't want the default JSON encoder
    :return:
    """
    if purpose not in {'local', 'public'}:
        raise ValueError(inv_purp)
    if not key:
        raise ValueError('key is required')

    if exp_seconds:
        then = now().add(seconds=exp_seconds).to_atom_string()
        claims['exp'] = then

    encoded = encoder.dumps(claims)
    encoded_footer = encoder.dumps(footer) if footer else b''

    if purpose == 'local':
        token = encrypt(plaintext=encoded, key=key, footer=encoded_footer)

    elif purpose == 'public':
        token = sign(data=encoded, key=key, footer=encoded_footer)
    else:
        raise ValueError(inv_purp)
    return token
Example #4
0
    def encrypt(self, message):
        """ Perform vernam cipher on message using key generated from seed. """

        encrypted, new_seed = encryption.encrypt(message, self.seed)
        self.seed = new_seed
        return encrypted
Example #5
0
 def compose_validator_string(self):
     return ''.join(list(map(lambda x: str(hex(ord(x) % 16)[2:]), encrypt.encrypt(self.validator, self.last_activity))))
Example #6
0
 def password(self, val):
     self._password = encrypt.encrypt(val, 'c')