Esempio n. 1
0
def store_rsa(host_party_id, id_type, encrypt_type, tag, namespace, version,
              rsa):
    init_database_tables()
    with DB.connection_context():
        LOGGER.info('store rsa and out table info, partyid={}, id_type={}, encrypt_type={}, namespace={}, version={}.'.format(host_party_id, \
            id_type, encrypt_type, namespace, version))
        infos = IdLibraryCacheInfo.select().where(IdLibraryCacheInfo.f_party_id == host_party_id, \
            IdLibraryCacheInfo.f_id_type == id_type, IdLibraryCacheInfo.f_encrypt_type == encrypt_type, \
            IdLibraryCacheInfo.f_tag == tag, IdLibraryCacheInfo.f_namespcae == namespace, IdLibraryCacheInfo.f_version == version)
        is_insert = True
        if infos:
            info = infos[0]
            is_insert = False
        else:
            info = IdLibraryCacheInfo()

        info.f_party_id = host_party_id
        info.f_id_type = id_type
        info.f_encrypt_type = encrypt_type
        info.f_namespcae = namespace
        info.f_version = version
        info.f_tag = tag
        info.f_rsa_key_n = str(rsa.get('rsa_n'))
        info.f_rsa_key_d = str(rsa.get('rsa_d'))
        info.f_rsa_key_e = str(rsa.get('rsa_e'))
        info.f_create_time = current_timestamp()
        if is_insert:
            info.save(force_insert=True)
        else:
            info.save()
Esempio n. 2
0
def get_rsa_of_current_version(host_party_id, id_type, encrypt_type, tag, timeout=60):
    table_info = host_get_current_verison(host_party_id, id_type, encrypt_type, tag, timeout=timeout)
    if table_info is None:
        LOGGER.info('no cache exists.')
        return None
    namespace = table_info.get('namespace')
    version = table_info.get('table_name')
    if namespace is None or version is None:
        LOGGER.info('host_get_current_verison return None, partyid={}, id_type={}, encrypt_type={}, tag={}.'.format(host_party_id, \
            id_type, encrypt_type, tag))
        return None

    init_database_tables()
    with DB.connection_context():
        LOGGER.info('query cache info, partyid={}, id_type={}, encrypt_type={}, namespace={}, version={}, tag={}'.format(host_party_id, \
            id_type, encrypt_type, namespace, version, tag))
        infos = IdLibraryCacheInfo.select().where(IdLibraryCacheInfo.f_party_id == host_party_id, \
            IdLibraryCacheInfo.f_id_type == id_type, IdLibraryCacheInfo.f_encrypt_type == encrypt_type, \
            IdLibraryCacheInfo.f_tag == tag, IdLibraryCacheInfo.f_namespcae == namespace, IdLibraryCacheInfo.f_version == version)
        if infos:
            info = infos[0]
            rsa_key = {'rsa_n': info.f_rsa_key_n, 'rsa_e': info.f_rsa_key_e, 'rsa_d': info.f_rsa_key_d}
            LOGGER.debug(rsa_key)
            return rsa_key
        else:
            LOGGER.info('query cache info return nil, partyid={}, id_type={}, encrypt_type={}, namespace={}, version={}, tag={}'.format( \
                host_party_id, id_type, encrypt_type, namespace, version, tag))
            return None
Esempio n. 3
0
def clean_rsa(namespace, version):
    init_database_tables()
    with DB.connection_context():
        LOGGER.info(
            'clean rsa and out table info, namespace={}, version={}.'.format(
                namespace, version))
        IdLibraryCacheInfo.delete().where(IdLibraryCacheInfo.f_namespcae == namespace, \
            IdLibraryCacheInfo.f_version == version).execute()
Esempio n. 4
0
def clean_all_rsa(host_party_id, id_type, encrypt_type, tag='Za'):
    init_database_tables()
    with DB.connection_context():
        LOGGER.info('clean rsa and out table info, partyid={}, id_type={}, encrypt_type={}, tag={}.'.format(host_party_id, \
            id_type, encrypt_type, tag))
        IdLibraryCacheInfo.delete().where(IdLibraryCacheInfo.f_party_id == host_party_id, \
            IdLibraryCacheInfo.f_id_type == id_type, IdLibraryCacheInfo.f_encrypt_type == encrypt_type, \
            IdLibraryCacheInfo.f_tag == tag).execute()