コード例 #1
0
 def __init__(self,
              sid="test.security.sender.alice",
              rid="test.security.rec.bob",
              dummy=True):
     self.sid = sid
     self.rid = rid
     # 1. generate private/public key pairs for the certificate authority.
     # 2. Initially generate some X509 certificates for random public keys, for random ids and store them in a suitable format (a file or a database)
     if dummy:
         CA.get_instance().generateDummyCertificates(n=20)
コード例 #2
0
 def __init__(self, id, elgamal=None, persist=False):
     self.id = id
     self.lastRecInfo = {}
     self.persist = persist
     self.ca = CA.get_instance()
     self.caKey = self._loadCAKey()
     if(elgamal):
         self.elgSig = elgamal
     elif(os.path.exists(ELG_PARAMS_PATH)):
         self.elgSig = ElgamalDigitalSignature.from_file(ELG_PARAMS_PATH)
     else:
         self.elgSig = ElgamalDigitalSignature()
         self.elgSig.saveConfig(ELG_PARAMS_PATH)
     x = rsa.getAsymKey()
     self.privateKey = x
     self.publicKey = x.public_key()
     self._authenticateWithCA()
コード例 #3
0
    def __init__(self, id, elgamal=None, elgKeyPairs=None, persist=False):
        '''
        :param elgamal: elgamal object of Elgamal class type, if None a new one will be created with default params or will be restored from the file
        :param elgKeyPairs: key pairs generated from same parameters of elgamal object. if None they will be generated from elgamal object
        '''
        self.id = id
        self.lastSendInfo = {}
        self.persist = persist
        self.ca = CA.get_instance(
        )  # this should be called before loading cakey
        self.caKey = self._loadCAKey()
        if (elgamal):
            self.elgSig = elgamal
        elif (os.path.exists(ELG_PARAMS_PATH)):
            self.elgSig = ElgamalDigitalSignature.from_file(ELG_PARAMS_PATH)
        else:
            self.elgSig = ElgamalDigitalSignature()
            self.elgSig.saveConfig(ELG_PARAMS_PATH)

        x, y = elgKeyPairs or self.elgSig.generateUserKey()
        self.privateKey = x
        self.publicKey = y
        self._authenticateWithCA()