Beispiel #1
0
 def __init__(self):
     self.profile = None
     self.message_handler = message.MessageHandler()
     self.session = session.Session()
     self.session.client_id = utilities.generate_client_id()
     self.session.private_key = donna25519.PrivateKey()
     self.session.public_key = self.session.private_key.get_public()
     self.phone_info = {}
     self.websocket = None
Beispiel #2
0
    def initialiser_configuration(self):
        # Charger les fichiers de configuration
        try:
            self.__reserve_dhcp.charger_fichier_dhcp()
        except FileNotFoundError:
            self.__logger.info("Initialiser fichier DHCP")
            self.__reserve_dhcp.sauvegarder_fichier_dhcp()

        try:
            with open(path.join(self.__path_configuration_reseau),
                      'r') as fichier:
                self.__configuration = json.load(fichier)
            self.__logger.info("Charge configuration:\n%s" %
                               json.dumps(self.__configuration, indent=4))

            adresses = self.__configuration['adresses']

            adresse_serveur = binascii.unhexlify(
                adresses['serveur'].encode('utf8'))
            adresse_reseau = binascii.unhexlify(
                adresses['reseau'].encode('utf8'))
            cle_privee_bytes = binascii.unhexlify(
                self.__configuration['cle_privee'].encode('utf8'))
            self.__cle_privee = donna25519.PrivateKey.load(cle_privee_bytes)

        except FileNotFoundError:
            self.__logger.info(
                "Creation d'une nouvelle configuration pour le serveur")

            adresse_serveur = urandom(
                3)  # Generer 3 bytes pour l'adresse serveur receiving pipe
            adresse_reseau = urandom(
                4)  # Generer 4 bytes pour l'adresse du reseau

            self.__cle_privee = donna25519.PrivateKey()

            configuration = {
                'adresses': {
                    'serveur':
                    binascii.hexlify(adresse_serveur).decode('utf8'),
                    'reseau': binascii.hexlify(adresse_reseau).decode('utf8'),
                },
                'cle_privee':
                binascii.hexlify(self.__cle_privee.private).decode('utf-8'),
            }
            self.__logger.debug("Configuration: %s" % str(configuration))
            with open(self.__path_configuration_reseau, 'w') as fichier:
                json.dump(configuration, fichier)
            self.__configuration = configuration

        self.__traitement_radio.set_adresse_serveur(adresse_serveur)
        self.__traitement_radio.set_adresse_reseau(adresse_reseau)
Beispiel #3
0
def gen_secret(device):
    privateKey = donna25519.PrivateKey()
    publicKey = privateKey.get_public()
    privateKeyBase64 = base64.b64encode(privateKey.private).decode('ascii')
    publicKeyBase64 = base64.b64encode(publicKey.public).decode('ascii')
    #print("private: " + privateKeyBase64)
    #print("public: " + publicKeyBase64)
        
    coolSwitchPublicKeyBase64 = run_command(device, "/secret?publicKey=" + publicKeyBase64)
    print("CoolSwitch Public: " + publicKeyBase64)
    
    coolSwitchPublicKey = donna25519.PublicKey(base64.b64decode(coolSwitchPublicKeyBase64))
    sharedSecret = privateKey.do_exchange(coolSwitchPublicKey)
    print("sharedSecret: " + base64.b64encode(sharedSecret).decode('ascii'))    
def compute_Gi(commitment_list):
    g_list = []
    for i in commitment_list:
        x = hashlib.sha256(str(i.auxiliar).encode('utf-8')).hexdigest()
        x = binascii.unhexlify(x)
        private = curve25519.PrivateKey(x)
        public = private.get_public()
        g_list.append(
            str(hex(int(binascii.hexlify(public.public),
                        16))).replace('0x', ''))

    g_list = list(set(g_list))

    print(len(g_list))
    return g_list
def exchange(stream):
    '''Exchange an ephemeral session key.'''

    # Generate an emphemeral ECDSA NIST P-256 private key
    private_key = donna25519.PrivateKey()
    public_key = private_key.get_public()

    # Write the public part on the wire
    _write_public_key(stream, public_key)

    # Read peer's public key from the wire
    peers_public_key = _read_public_key(stream)

    # Compute the scalar product of our private key with peer's
    shared_point = private_key.do_exchange(peers_public_key)

    # public key as our shared key.
    return shared_point
Beispiel #6
0
        f_hash = open('archivo_'+str(n+1)+'_rehashed.txt',"a")
        f_hash.write(password_hash+'\n')
        f_hash.close()
    f.close()
    end=timer()
    total=end-start
    print('Tiempo de rehasheo de archivo '+str(n+1)+': '+str(total)+' segundos.')'''

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 10000)
print('starting up on {} port {}'.format(*server_address))
sock.bind(server_address)

sock.listen(1)

private_key = donna25519.PrivateKey()
public_key = private_key.get_public()
print(public_key.public)

while True:
    # Wait for a connection
    print('waiting for a connection')
    connection, client_address = sock.accept()
    try:
        print('connection from', client_address)

        # Receive the data in small chunks and retransmit it
        while True:
            data = connection.recv(32)
            print('received {!r}'.format(data))
            if data:
Beispiel #7
0
import donna25519 as curve25519
import binascii
import hashlib

print()
print('指纹字符串为:010011011011011000011100000100')
x = hashlib.sha256('010011011011011000011100000100'.encode('utf-8')).hexdigest()
print('sha256加密后的32字节私钥为:', x)
x = binascii.unhexlify(x)

private = curve25519.PrivateKey(x)
public = private.get_public()
#print('Curve25519加密后的私钥为:', int(binascii.hexlify(private.private), 16))
print('Curve25519加密后的公钥为:', str(hex(int(binascii.hexlify(public.public), 16))).replace('0x',''))
Beispiel #8
0
def keygen():
    private = donna25519.PrivateKey()
    public = private.get_public()
    return (private.private, public.public)
Beispiel #9
0
def gen_keys():
    private_key = donna25519.PrivateKey()
    priv_key_bytes = private_key.private
    pub_key_bytes = private_key.get_public().public
    return priv_key_bytes, pub_key_bytes
 def __init__(self):
     self.bobs_private_key = curve25519.PrivateKey()
     self.bobs_public_key = self.bobs_private_key.get_public()