Python Forum
SystemError: initialization of integer failed without raising an exception
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SystemError: initialization of integer failed without raising an exception
#1
Executing run casb_process .py module case importing integer failed this the output
Code lines are follow. what is possible solution i am using Charm 0.50 python 3.9 Ubuntu21.10 virtual machine

import json
import hashlib
from charm.toolbox.pairinggroup import PairingGroup, ZR, G1, G2, GT, pair, extract_key
from charm.toolbox.symcrypto import SymmetricCryptoAbstraction
import pymysql as pm
from abenc_bsw07 import *


# This is the cpabe BSW07 scheme's cryptosystem.
# It provides the relevant methods for the objects
group = PairingGroup('SS512')
system = CPabe_BSW07(group)


class CASB:
    '''
    This is a Cloud Access Security Broker.
    '''

    def __init__(self):
        self.cdb = CDB()
        self.dk_name = None
        self.dk_score = None
        self.users = {}

    def store(self, name, buffer):
        '''
        buffer is a dict with information related to name.
        '''
        if name in self.users.keys():
            for key in buffer.keys():
                self.users[name][key] = buffer[key]
        else:
            self.users[name] = {}  # if this is a new user, new a dict for the user.
            for key in buffer.keys():
                self.users[name][key] = buffer[key]

    def setpolicy(self, name, policy):
        '''
        set policy on different columns;
        '''
        if name in self.users.keys():
            self.users[name]['policy'] = policy
        else:
            print('please return to "store"!!!')
            return -1
        print(self.users[name]['policy'])

    def upload(self, name, data):
        '''
        upload data to CDB.
        '''
        # generate dk for columns(name and score).
        if self.dk_name == None:
            dk_name = group.random(GT)
        if self.dk_score == None:
            dk_score = group.random(GT)

        # encrypt data with dk
        for i in range(0, len(data)):
            cipher_name = self.symmetric_encrypt(data[i][1], dk_name)
            cipher_score = self.symmetric_encrypt(data[i][2], dk_score)
            # store cipher in CDB
            self.cdb.cdb_insert(data[i][0], cipher_name, cipher_score)

        # encrypt dk with CP-ABE and store
        self.dk_name = system.encrypt(self.users[name]['pk'], dk_name, self.users[name]['policy']['name'])
        self.dk_score = system.encrypt(self.users[name]['pk'], dk_score, self.users[name]['policy']['score'])

    def accessdata(self, name, sql):
        '''
        sql is just for demonstration.
        '''
        # decrypt dk
        dk_name = system.decrypt(self.users[name]['pk'], self.users[name]['sk'], self.dk_name)
        dk_score = system.decrypt(self.users[name]['pk'], self.users[name]['sk'], self.dk_score)

        print('\n// {} //****** // {} //'.format(name, sql))
        datas = self.cdb.cdb_select()  # select data from CDB

        # decrypt data with dk
        newdatas = []
        for data in datas:
            temp = data[1]
            temp2 = data[2]
            if dk_name != False:
                temp = self.symmetric_decrypt(data[1], dk_name).decode('utf-8')
            if dk_score != False:
                temp2 = self.symmetric_decrypt(data[2], dk_score).decode('utf-8')

            newdata = [data[0], temp, temp2]
            newdatas.append(newdata)

        return newdatas

    def end(self):
        self.cdb.cdb_deleteall()

    def symmetric_encrypt(self, msg, dk):
        k = extract_key(dk)
        a = SymmetricCryptoAbstraction(k)
        c = a.encrypt(msg)
        return c

    def symmetric_decrypt(self, cipher, dk):
        k = extract_key(dk)
        a = SymmetricCryptoAbstraction(k)
        msg = a.decrypt(cipher)
        return msg


class CDB():
    '''
    This is Cloud DataBase.
    '''

    def __init__(self):
        self.conn = pm.connect(host="127.0.0.1",
                               port=3306,
                               user="ubuntu", password="ubuntu",
                               database="education",
                               charset="utf8",
                               autocommit=True)
        self.cursor = self.conn.cursor()

    def cdb_insert(self, number, name, score):
        sql = "INSERT INTO math (number, name, score) VALUES (%s, %s, %s);"
        try:
            self.cursor.execute(sql, [number, name, score])
            self.conn.commit()
        except Exception as e:
            print(repr(e))
            self.conn.rollback()  # Rollback in case there is any error

    def cdb_select(self):
        sql = "SELECT * FROM math;"
        try:
            self.cursor.execute(sql)
            self.conn.commit()
        except Exception as e:
            print(repr(e))
            self.conn.rollback()
        results = self.cursor.fetchall()
        return results

    def cdb_deleteall(self):
        sql = "DELETE FROM math;"
        try:
            self.cursor.execute(sql)
            self.conn.commit()
        except Exception as e:
            print(repr(e))
            self.conn.rollback()

    def cdb_close(self):
        self.conn.close()


class KMS:
    '''
    This is KMS(Key Management Server), which provides key management service for users.
    '''

    def __init__(self):
        pass

    def setup(self):
        '''
        Execute "Setup" in CP-ABE.
        '''
        (master_public_key, master_key) = system.setup()
        return master_public_key, master_key


class UE():
    '''
    This is UE(user edge). There is two attributes('admin' and 'user') in it.
    '''

    def __init__(self, name, attributes):  # init a ue
        self.pk = None
        self.mk = None
        self.sk = None
        self.name = name
        self.attributes = attributes

    def show(self, datas):
        print('number\tname\tscore')
        for data in datas:
            for column in data:
                print(column, end='\t')
            print('\n')


def main():
    '''
    In this function, I'll show you the process.
    '''
    # init
    kms = KMS()
    casb = CASB()

    # 1.GENERATE USER MASTER KEY AND SECRET KEYS
    alice = UE('alice', ['ADMIN'])
    bob = UE('bob', ['USER'])
    alice.pk, alice.mk = kms.setup()  # kms setup publickey and master key for alice(admin).
    # generate secret keys for alice and bob
    alice.sk = system.keygen(alice.pk, alice.mk, alice.attributes)
    bob.sk = system.keygen(alice.pk, alice.mk, bob.attributes)
    # store pk, sk and mk in CASB
    casb.store(alice.name, {'pk': alice.pk, 'sk': alice.sk, 'mk': alice.mk})
    casb.store(bob.name, {'pk': alice.pk, 'sk': bob.sk, 'mk': alice.mk})

    # 2.CUSTOMIZE ACCESS POLICIES
    alice.policy = {'name': '((user and admin) or admin)', 'score': '(user or admin)'}
    casb.setpolicy(alice.name, alice.policy)  # set access policy on different columns.

    # 3.UPLOAD DATA
    alice.data = [['1', 'bob', '99'], ['2', 'charles', '98'], ['3', 'david', '96'], ['4', 'emily', '100']]
    casb.upload(alice.name, alice.data)  # upload data to CASB

    # 4.ACCESS DATA
    # alice access data
    alicedatas = casb.accessdata(alice.name, 'SELECT * FROM math')
    alice.show(alicedatas)
    # bob access data
    bobdatas = casb.accessdata(bob.name, 'SELECT * FROM math')
    bob.show(bobdatas)

    casb.end()  # delete all the data in table math for next round
main()
Error:
/usr/bin/python3.9 /home/ali/Documents/test/casb_process.py ERROR: module load failed! Traceback (most recent call last): File "/home/ali/Documents/test/casb_process.py", line 8, in <module> from charm.toolbox.symcrypto import SymmetricCryptoAbstraction File "/home/ali/Documents/test/charm/toolbox/symcrypto.py", line 1, in <module> from charm.toolbox.paddingschemes import PKCS7Padding File "/home/ali/Documents/test/charm/toolbox/paddingschemes.py", line 3, in <module> from charm.toolbox.securerandom import SecureRandomFactory File "/home/ali/Documents/test/charm/toolbox/securerandom.py", line 6, in <module> from charm.toolbox.conversion import Conversion File "/home/ali/Documents/test/charm/toolbox/conversion.py", line 7, in <module> from charm.core.math.integer import integer SystemError: initialization of integer failed without raising an exception
The Debeging error screenshot URL https://ibb.co/pzFM49V
Reply
#2
This does run with Python 3.7

https://github.com/JHUISI/charm/issues/239

The last update was 2015, so 7 years ago (2022).
This is a very long time for crypto libraries.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
@DeaD_EyE yes I find this solution on https://github.com/JHUISI/charm/issues/239 to downgrade pyton3.9 to python3.6 or 3.7 but I am trying to find any other solution but am unable to do so.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SystemError: <method-wrapper '__getattribute__' of EnumMeta object sciloop 4 1,496 Jul-23-2022, 07:57 PM
Last Post: sciloop
  Raising numbers to power ** GJG 3 2,423 Mar-23-2021, 03:43 PM
Last Post: deanhystad
  A dynamic link library (DLL) initialization routine failed ish93 0 1,774 Jan-11-2021, 08:22 PM
Last Post: ish93
  Matrix indexing and initialization in " for in" loop QuintenR 2 1,841 Dec-23-2020, 05:59 PM
Last Post: QuintenR
  SystemError: error return without exception set!!! faryad13 3 3,641 Oct-23-2020, 02:32 PM
Last Post: ATARI_LIVE
  Array initialization anomaly JohnPie 1 1,489 Jul-09-2020, 01:48 PM
Last Post: deanhystad
  During handling of the above exception, another exception occurred Skaperen 7 26,854 Dec-21-2018, 10:58 AM
Last Post: Gribouillis
  raising multiple exceptions Skaperen 10 9,252 Mar-19-2017, 06:32 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020