Exemplo n.º 1
0
    def readyToTransport(self):

        if self.nextip == "":
            print "ERROR: No next destination defined, exiting"
            return -1
        #TODO: Encrypt with self's priv key

        ### Encrypt with AES
        PADDING='{'
        BLOCK_SIZE= AES.block_size

        rf = Crypto.Random.new()
        _key = rf.read(BLOCK_SIZE) 
        iv = rf.read(BLOCK_SIZE)
        
        encryptor = AES.new(_key, AES.MODE_CBC, iv)

        ## Pad to make block size okay
        pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
         
        self.agent = iv + encryptor.encrypt(pad(cPickle.dumps(self.agent, -1)))
        
        ### Encrypt the key now 
        _pubkey = getPublicKey(self.nextip)
        self.key = _pubkey.encrypt(_key, b'')[0] 
Exemplo n.º 2
0
    def compute(self):
        import rsa, cPickle
        from KeyServer import getPublicKey
        from CompLocal import CompLocal

        print "Computation started"
        self.plusval += 1
        print "Plussed"
        # TODO: Verify integrity
        try:
            dump = cPickle.dumps(self.compLocal, 1)
            _serverPubKey = getPublicKey(self.masterip)
            _serverPubKey.verify(dump, (self.serverSignature,))
            if isinstance(self.compLocal, CompLocal):
                return self.compLocal.compute()
            else:
                return -1

        except rsa.pkcs1.VerificationError as e:
            print "Cannot trust the code, cowardly exiting"
            raise e

        except Exception as e:
            print "Last except excepted: ", str(e)
            raise e
Exemplo n.º 3
0
        masterip = cp.get("master", "masterip")
        print "Masterip:", masterip
        hops = cp.getint("itinerary", "hops")
        while hops > 0:
            attrname = "node" + str(i)
            groute.append(cp.get("itinerary", attrname))
            hops = hops - 1
            i = i + 1
    else:
        print "Can not find required configuration file\n"
        sys.exit(1)


#### main program starts
mafinit("maf.conf")

#### create new agent
agentx = DiskAgent(masterip, groute)
#### Sign the agent

binstr = cPickle.dumps(agentx.compLocal, 1)
_privkey = getPrivateKey(masterip)
_pubkey = getPublicKey(masterip)
agentx.serverSignature = _privkey.sign(binstr, b"")[0]

#### display some information related to this agent
agentx.dispInfo()

#### migrate this agent
migrate(agentx)