Пример #1
0
    def __init__(self, symbol_graph):
        '''
        Constructor
        '''
        # initialize CPABE object
        self._group = PairingGroup('SS512')
        self._cpabe = CPabe_BSW07(self._group)
        self._hyb_abe = HybridABEnc(self._cpabe, self._group)
        #access_policy = '(ar and bc)'
        #message = "hello world this is an important message."
        #(pk, mk) = self._hyb_abe.setup()
        #sk = self._hyb_abe.keygen(pk, mk, ['AR', 'BC'])
        #ct = self._hyb_abe.encrypt(pk, message, access_policy)
        #try:
        #    result = self._hyb_abe.decrypt(pk, sk, ct)
        #    print result
        #except Exception:
        #    pass

        # attributes should be vertices
        # since its diDraph, the query of two vertices sequence matters
        # row and col symbol is interpreted differently
        self._symbol_graph = symbol_graph
        symbols = self._symbol_graph.get_keys()
        for i in symbols:
            # r means row attributes
            self._attributes.append(symbols[i] + 'r')
            # c means column attributes
            self._attributes.append(symbols[i] + 'c')
Пример #2
0
def test_charm_crypto():
    # instantiate a bilinear pairing map
    pairing_group = PairingGroup('MNT224')

    cpabe = CPabe_BSW07(pairing_group)
    hyb_abe = HybridABEnc(cpabe, pairing_group)
    # run the set up
    (pk, msk) = hyb_abe.setup()  # Public Key and Master SECRET Key

    # generate a key
    attr_list = ['U-11890454', 'D-46', 'D-46-GUEST']
    key = hyb_abe.keygen(pk, msk, attr_list)

    serialized_pk = serialize_charm_object(pk, pairing_group)
    pk = deserialize_charm_object(serialized_pk, pairing_group)

    serialized_key = serialize_charm_object(key, pairing_group)
    key = deserialize_charm_object(serialized_key, pairing_group)

    # choose a random message
    msg = "Hello World"

    # generate a ciphertext
    policy_str = '(u-11890454 OR d-46 OR d-46-GUEST)'  # evaluates to "((U-11890454 or D-46) or D-46-GUEST)" - see upper chars
    ctxt = hyb_abe.encrypt(pk, msg, policy_str)

    policy_str = '(u-1 AND d-46 AND d-46-GUEST)'  # Re-encrypted data with new policy
    ctxt2 = hyb_abe.encrypt(pk, msg, policy_str)

    # decryption
    rec_msg = hyb_abe.decrypt(pk, key, ctxt).decode("utf-8")
    with pytest.raises(Exception):
        hyb_abe.decrypt(pk, key, ctxt2)
    assert rec_msg == msg, "Failed."  # "First successfully decrypted, second not."
Пример #3
0
    def decrypt(self, master_public_key, sk, cipher_matrix, vertices):
        '''
        Decryption requires master_public_key, user secret key, and cipher
        '''
        group = PairingGroup('SS512')
        cpabe = CPabe_BSW07(group)
        hyb_abe = HybridABEnc(cpabe, group)

        N = len(vertices)

        resMat = [None] * N
        for i in range(0, N):
            resMat[i] = [None] * N
            for j in range(0, N):
                #convert to lower case
                s = vertices[i].lower()
                s2 = vertices[j].lower()

                cipher = cipher_matrix.get_cell_by_symbol(s, s2)
                resMat[i][j] = hyb_abe.decrypt(master_public_key, sk, cipher)
                if resMat[i][j] == False:
                    return False

        result = AdjMatrixDiGraph(mat=resMat)
        return SymbolDiGraphMat(vertices, G=result)
Пример #4
0
    def __init__(self, group = "SS512"):
        self._group = PairingGroup(group)
        self._cpabe = CPabe09(self._group)
        self._hybrid_abe = HybridABEnc(self._cpabe, self._group)

        # TODO: Master keys should be generated once and stored securely 
        #       somewhere else.
        self._master_secret, self._master_public = self._cpabe.setup()
Пример #5
0
 def testHybridABEnc(self):
     groupObj = PairingGroup('SS512')
     cpabe = CPabe_BSW07(groupObj)
     hyb_abe = HybridABEnc(cpabe, groupObj)
     access_policy = '((four or three) and (two or one))'
     message = b"hello world this is an important message."
     (pk, mk) = hyb_abe.setup()
     if debug: print("pk => ", pk)
     if debug: print("mk => ", mk)
     sk = hyb_abe.keygen(pk, mk, ['ONE', 'TWO', 'THREE'])
     if debug: print("sk => ", sk)
     ct = hyb_abe.encrypt(pk, message, access_policy)
     mdec = hyb_abe.decrypt(pk, sk, ct)
     assert mdec == message, "Failed Decryption!!!"
     if debug: print("Successful Decryption!!!")
Пример #6
0
    def decrypt_query(self, master_public_key, sk, cipher_matrix, queries):
        '''
        Decryption requires master_public_key, user secret key, and cipher
        '''
        group = PairingGroup('SS512')
        cpabe = CPabe_BSW07(group)
        hyb_abe = HybridABEnc(cpabe, group)

        msg = ''
        for query in queries:
            #convert to lower case
            s1 = query[0].lower()
            s2 = query[1].lower()

            cipher = cipher_matrix.get_cell_by_symbol(s1, s2)
            msg += hyb_abe.decrypt(master_public_key, sk, cipher) + " "

        return msg
def main():
    groupObj = PairingGroup('SS512')
    cpabe = CPabe_BSW07(groupObj)
    abe = HybridABEnc(cpabe, groupObj)



    f1 = open("private/pk_bytes", "rb")
    f2 = open("private/mk_bytes", "rb")

    pk = f1.read()
    mk = f2.read()

    orig_pk = bytesToObject(pk, groupObj)
    orig_mk = bytesToObject(mk, groupObj)


    print(orig_pk)
    
    
    # (pk,mk) = create_pk_mk_abe(abe)
  
    
    attrs1 = ['CANHTUAN','DUY','MANH']
    attrs2 = ['CANHTUAN','DUY']
    msg = "canhtuan".encode('utf-8')
    # policy = create_policy_abe(attrs2)
    policy = '(CANHTUAN and DUY and MANH)'
    # print(policy)
    


    sk2 = create_scret_key(abe,orig_pk,orig_mk,attrs1)
    ct = encrypt_abe(abe,orig_pk,"tuan".encode('utf-8'), policy)
    # print(ct)
    ct =b'eJydV9tuFEcQ/ZXVPiXSSpme6Us1Eg+WgRjFxomAkIuj1d5srNjE8S5OiOV/z1TVOTMbnmIeMDs91XU9darmfroK0yeT++nhfHd5td7Y7/l8dbXYbufz/mm6/LTbbKezSX96t7j6uLHTX1OYTZLMJqFpZ5PazCax9gf9Yen6/0v/om31bZ5NpH+qvaiopL5p+oekb0PUP50eJZcxdaFRXb3OrNJBXLFeN6Up+YGJSYfTnNx26Q9jfy9naCsqGuClag1NLxb1Xqh+KgLPQoCYve1PSq+lVn3ofxT6pq5EgdumTo2Uht72YQkdDAGBqN4s8NaC0cg1mCL+thRoM9OhbXBblWs46mLShCZktkR6J27RUqixima2Ka5TCxApZvJNcC0pU5MqaPyfvbXQihpqA293cMqtRLzTXGnEFpt6r0pjYTjZ4RBZ5YSM6lv3RTxCTWi0IsCyFBgtzE2gYbWpPmnBNe5EU+aRZzkAKZn5GWKwgJNb1SyoBk2l1a2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kOcwG20VgmnPLncVKJKhl+yDpzolDKTlGOMctg0jsksCSThwSSJLdvgi5Ori61wlH8e9zySDRDNMkI7Ce3XTwt38cXW50p1yut3dPvmKlDlZfFhP+k60/7W4X2sZF7vd7eXyoxa1r6PdGDh25hq0e/HTMGHoWLWGjcXVBQ0dnRwczl8fHbQqfL0dzu/PpgfH3571j73XZ9OT02fP9aHVh5c/6s+zaXj952U5X9+9OL+9fv8yfvfh8Pt//rp4+vRsqlKHlzfvN7dvNn/vXLpcv/jh9OLu3Tf1+KdfTt8dL3/f7p6b9IPaXl9ebLY7ml+vz3PThFo3a1mcr2RRZJmkxLJOZZVWZbWspe3Cqp7Lsqs1rmPMZbFq16GGssx5+vDwL/EqTB0='
    

    giaima = decrypt_abe(abe,orig_pk, sk2, ct)
    print(giaima)

# main()
Пример #8
0
from config import *

import requests

from charm.toolbox.pairinggroup import PairingGroup
from charm.schemes.abenc.abenc_bsw07 import CPabe_BSW07
from charm.adapters.abenc_adapt_hybrid import HybridABEnc

from charm.core.engine.util import objectToBytes, bytesToObject

policy_length = 16
key_size = 8

groupObj = PairingGroup('SS512')
cpabe = CPabe_BSW07(groupObj)
hybrid_abe = HybridABEnc(cpabe, groupObj)

master_key_file_name = "master_key.json"
def init_abe():
    groupObj = PairingGroup('SS512')
    cpabe = CPabe_BSW07(groupObj)
    abe = HybridABEnc(cpabe, groupObj)
    print(abe)
    return (abe)
def initABE():
    groupObj = PairingGroup('SS512')
    cpabe = CPabe_BSW07(groupObj)
    abe = HybridABEnc(cpabe, groupObj)
    return abe
Пример #11
0
def create_cp_abe():
    pairing_group = create_pairing_group()
    cpabe = CPabe_BSW07(pairing_group)
    return HybridABEnc(cpabe, pairing_group)