def decipher(message): message = b64decode(message) private_file = open(PATH + "/private.key", "r") private_key = importKey(private_file.read()) private_file.close() decrypted = private_key.decrypt(message) return decrypted
def encrypt_rsa(message, public_key_loc): # cifra el mensaje y lo codifica a base64 key_decode = b64decode(public_key_loc) key_perfect = importKey(key_decode, passphrase=None) cryptos = rsa.encrypt(message, key_perfect) crypto = cryptos.encode("base64") return crypto
def recview(request): password = request.session['password'] msg = recmail(request.user.email, password) file_key = open(f"private{request.user.email}.pem", "r") key = importKey(file_key.read(), passphrase=password) file_key.close() dec_msg = decrypt_message(msg, key) return HttpResponse(dec_msg)
def import_rsa_key(key): """ Extract an RSA key from a PEM-encoded certificate :param key: RSA key encoded in standard form :return: RSA key instance """ return importKey(key)
def get_pubkey_openssh_fingerprint(pubkey): # We import and export the key to make sure it is in OpenSSH format if not pycrypto_available: raise RuntimeError('pycrypto is not available') k = importKey(pubkey) pubkey = k.exportKey('OpenSSH')[7:] decoded = base64.decodestring(pubkey) return _to_md5_fingerprint(decoded)
def decrypt(modulus): for f in glob.glob('RSA_RW-20191119/*pubkeyRSA_RW*.pem'): aux = open(f) key = importKey(aux.read()) if(gcd(modulus, key.n) != 1): print("Clau compartida amb: " + str(aux.name)) print("key auxiliar: " + str(key.n)) return gcd(modulus, key.n) #trobat un dels primers que formen la clau return -1
def encode_id_token(payload): """ Represent the ID Token as a JSON Web Token (JWT). Return a hash. """ key_string = get_rsa_key().encode('utf-8') keys = [RSAKey(key=importKey(key_string), kid=md5(key_string).hexdigest())] _jws = JWS(payload, alg='RS256') return _jws.sign_compact(keys)
def encode_id_token(payload): """ Represent the ID Token as a JSON Web Token (JWT). Return a hash. """ key_string = get_rsa_key().encode('utf-8') keys = [ RSAKey(key=importKey(key_string), kid=md5(key_string).hexdigest()) ] _jws = JWS(payload, alg='RS256') return _jws.sign_compact(keys)
def sendemail(sender_email,sender_password,rec_email,subject,message,publickey): # print(publickey) # print(type(publickey)) pkey = importKey(publickey[2:len(publickey)-1]) encrypted_msg = encrypt_message("Subject:"+ subject + "\n\n\n" + message, pkey) # Create a secure SSL context context = ssl.create_default_context() with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server: server.login(sender_email, sender_password) server.sendmail(sender_email, rec_email, encrypted_msg)
def get_pubkey_ssh2_fingerprint(pubkey): # This is the format that EC2 shows for public key fingerprints in its # KeyPair mgmt API if not pycrypto_available: raise RuntimeError('pycrypto is not available') k = importKey(pubkey) derPK = DerSequence([k.n, k.e]) bitmap = DerObject('BIT STRING') bitmap.payload = bchr(0x00) + derPK.encode() der = DerSequence([algorithmIdentifier, bitmap.encode()]) return _to_md5_fingerprint(der.encode())
def encode_id_token(payload): """ Represent the ID Token as a JSON Web Token (JWT). Return a hash. """ keys = [ RSAKey(key=importKey(get_rsa_key())) ] _jws = JWS(payload, alg='RS256') _jwt = _jws.sign_compact(keys) return _jwt.decode('utf-8')
def verify_signature(self, signature): """ Verifies the provided signature corresponds to the transaction object signed by the public key. :param signature: <str> signature to verify :return: <bool> true if the verification succeeds, false otherwise """ try: private_key = importKey(unhexlify(signature)) public_key = importKey(unhexlify(self.sender)) signer = new(private_key) verifier = new(public_key) digest = SHA256.new() digest.update(str(self.dict).encode('utf8')) sig = signer.sign(digest) return verifier.verify(digest, sig) except TypeError: return False
def _get_cle(self) : if not self._cle : with sqlite3.connect(main.maconf.mabdd) as cnx : c = cnx.cursor() c.execute(""" SELECT cle FROM paire WHERE id = '{0.id}'; """.format(self)) try : resultat, = c.fetchone() self._cle = importKey(resultat) except TypeError : pass return self._cle
def test_authenticated_user(self): """Test if we can extract the user from a TokenCookie.""" key = importKey(_TEST_KEY) token = token_pb2.TokenCookie() token.basic_creds.user_name = 'testosteronius' token.basic_creds.scope.append('users') token.basic_creds.expires = calendar.timegm( datetime.utcnow().timetuple()) + 30 codec = token_cookie.TokenCookieCodec(token, privkey=key) cookie = codec.encode() auth = authenticator.Authenticator("Unit Test", cert=_TEST_CERT) self.assertEquals(auth.get_authenticated_user(cookie), 'testosteronius')
def encode_id_token(payload): """ Represent the ID Token as a JSON Web Token (JWT). Return a hash. """ keys = [] for rsakey in RSAKey.objects.all(): keys.append(jwk_RSAKey(key=importKey(rsakey.key), kid=rsakey.kid)) if not keys: raise Exception('You must add at least one RSA Key.') _jws = JWS(payload, alg='RS256') return _jws.sign_compact(keys)
def test_login_handler(self): """Check whether an authentication token response is handled and decoded correctly by the authenticator implementation.""" now = datetime.now() expires = now + timedelta(0, 300) pkey = importKey(_TEST_KEY) # We need a CA signed certificate, so we use the one # from above. cert = x509.parse_certificate(_TEST_CERT) cacert = x509.parse_certificate(_TEST_CA) # Sanity check for the above certificates. self.assertTrue(cert.check_signature(cacert)) auth = authenticator.Authenticator("Unit Test", cert=_TEST_CERT, key=_TEST_KEY, ca_bundle=_TEST_CA) atres = token_pb2.AuthTokenResponse() atres.basic_creds.user_name = 'testosteronius' atres.basic_creds.scope.extend(['one', 'two']) atres.basic_creds.expires = calendar.timegm(expires.utctimetuple()) atres.app_name = 'Unit Test' atres.original_uri = 'http://lolcathost:8080/foo/bar' atres.certificate = _TEST_CERT atres.granted = calendar.timegm(now.utctimetuple()) # FIXME(caoimhe): this should go away. atres.random = 'A' * 64 atrc = token_cookie.AuthTokenResponseCodec(atres, privkey=pkey) response = atrc.encode() data = auth.login_handler(response) self.assertEquals(2, len(data)) cookiedata = data[0] nexturl = data[1] self.assertEquals('http://lolcathost:8080/foo/bar', nexturl)
def active_cert(key): """ Verifies that a key is active that is present time is after not_before and before not_after. :param key: The Key :return: True if the key is active else False """ cert_str = pem_format(key) certificate = importKey(cert_str) try: not_before = to_time(str(certificate.get_not_before())) not_after = to_time(str(certificate.get_not_after())) assert not_before < utc_now() assert not_after > utc_now() return True except AssertionError: return False except AttributeError: return False
def __init__(self) : self._id = int() self._ip = str() self._port = int() self._sha256 = str() self._date = float() self._signature = long() self.cle = importKey("-----BEGIN PUBLIC KEY-----\n\ MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAmDRmI5HLoenaMc4J7fHC\n\ rhVYBqR3quZiBq4NMQrjIVv90yHVDrOp1y6M83gh2w7Ty1CL6wLIXiXoC81AnI1n\n\ m5no9l/wb33mCdFuyt7+8oMwrM1MFH/CX29Jiwgow2ZjkslX9eRRIhCClaaviM1d\n\ 7i4TWk5ucM5qmHy4K9Fd0H7PxgNNsTLUOoapyk5uAFCT3tPSiqHssM9HRwdBsWSr\n\ JaN80axWlWXp2nU0zTJVjIibHG+woLTXjVdUkJQrg7AWrfZgYIKFPVDwpSD1/RUt\n\ 6jEsIQDS7rYhwnrlbhCHa/YZQYy+cPCSY9MsX59YddAcxK8kkFrgFEM6WpRWJrKO\n\ drh3P3nmEVjprwQl18oIkz8gw2AOefZgS+h3B0zRSPWL+ER3ixHvzy/HMmqULwHt\n\ 9eAN4lhIRSWMubi/9bXtyyo4rU3YMGSvU80QRghxLqXXyQj8BBma/wOjNMvJ0RkS\n\ H86U0NHxTpaCZOPPQioTCTod93/i9eO66i/Hl0olsaPCdP50QCTmTjTHHEtvyZV3\n\ R+W4L8H/HYYP4PXFGKef/OnsPlm+girFKl3OjJBrB6dMG79mxuuQita1ii/3qCtJ\n\ n7XFnOx//it/FaCF2ondnXdFZF+jsz+4prMgZIlUryKIW1+9JH4pTIWP/p0VzKSN\n\ JK9A2LezGAOsyNSNZLw12F0CAwEAAQ==\n\ -----END PUBLIC KEY-----")
def test_login_handler(self): """Check whether an authentication token response is handled and decoded correctly by the authenticator implementation.""" now = datetime.now() expires = now + timedelta(0, 300) pkey = importKey(_TEST_KEY) # We need a CA signed certificate, so we use the one # from above. cert = x509.parse_certificate(_TEST_CERT) cacert = x509.parse_certificate(_TEST_CA) # Sanity check for the above certificates. self.assertTrue(cert.check_signature(cacert)) auth = authenticator.Authenticator("Unit Test", cert=_TEST_CERT, key=_TEST_KEY, ca_bundle=_TEST_CA) atres = token_pb2.AuthTokenResponse() atres.basic_creds.user_name = 'testosteronius' atres.basic_creds.scope.extend(['one', 'two']) atres.basic_creds.expires = calendar.timegm(expires.utctimetuple()) atres.app_name = 'Unit Test' atres.original_uri = 'http://lolcathost:8080/foo/bar' atres.certificate = _TEST_CERT atres.granted = calendar.timegm(now.utctimetuple()) # FIXME(tonnerre): this should go away. atres.random = 'A' * 64 atrc = token_cookie.AuthTokenResponseCodec(atres, privkey=pkey) response = atrc.encode() data = auth.login_handler(response) self.assertEquals(2, len(data)) cookiedata = data[0] nexturl = data[1] self.assertEquals('http://lolcathost:8080/foo/bar', nexturl)
def encode_id_token(payload, client): """ Represent the ID Token as a JSON Web Token (JWT). Return a hash. """ alg = client.jwt_alg if alg == 'RS256': keys = [] for rsakey in RSAKey.objects.all(): keys.append(jwk_RSAKey(key=importKey(rsakey.key), kid=rsakey.kid)) if not keys: raise Exception('You must add at least one RSA Key.') elif alg == 'HS256': keys = [SYMKey(key=client.client_secret, alg=alg)] else: raise Exception('Unsupported key algorithm.') _jws = JWS(payload, alg=alg) return _jws.sign_compact(keys)
# -*- coding: utf-8 -*- """ Created on Sun Nov 26 18:36:23 2017 @author: alcasser """ from Crypto.PublicKey import RSA from Crypto.PublicKey.RSA import importKey from math import gcd from glob import glob n = 25747548551694293442855127134507413839409760174426694340687906994315509868115948986472859343852141088119082418000653756880246181799442129897249018288615522880241723820673498084394582984667505015101496926221902584286921942833076158207013384371112952747040886614261710028603133862046494740372272362683728741797679853669464636738016563031657070715497560685330070280121885111384164060665239899689520825604041357942894282821596681352542026663294646933565034034752158140293605018863484101953727846700929176507137420356167169371491364907682752782587976306685048348346679214900983030767267634869313982553661426520937059176269 e = 65537 for filename in glob('*pubkeyRSA_RW*.pem'): f = open(filename) key = importKey(f.read()) if gcd(n, key.n) != 1: print(f.name) print("key.n = " + str(key.n)) p = gcd(n, key.n) break print("p = " + str(p)) d = int(input('d = ')) privateKey = RSA.construct((n, e, d)) f = open('key.pem', 'wb') f.write(privateKey.exportKey('PEM')) f.close
import Crypto from Crypto.PublicKey import RSA from Crypto.Signature import PKCS1_v1_5 from Crypto.Hash import SHA256 import hashlib from encryption import encrypt, decrypt, simple_encrypt, simple_decrypt from login_gui import Login from dir_handler import receive_files_and_write from binascii import hexlify, unhexlify import time import random HOST = '127.0.0.1' PORT = 8787 f = open("server_pub_key", "r") SERVER_PUB_KEY = importKey(f.read()) f.close() f = open("priv_key") PRV_KEY = importKey(f.read()) f.close() DH_KEY = "" def handshaking_protocol(s, user_name, password,count): global DH_KEY credentials = '{},{}'.format(user_name, password) credentials = bytes(credentials, "utf-8") cipher = SERVER_PUB_KEY.encrypt(credentials, 64)[0] base64txt = base64.b64encode(cipher) s.send(base64txt)
def read_key(file): return importKey(open(file, "r").read()).key
def decrypt_rsa(crypto, private_key): key_decode = b64decode(private_key) key_perfect = importKey(key_decode, passphrase=None) crypto = crypto.decode("base64") return rsa.decrypt(crypto, key_perfect)
#Modulus=96C326607D51A67E4A2C586A067163501E4BBA1E8CB1825AE9EDEEDAD6523F798A8F2CB329AE2F9FD5576FDF52206477B2592C36C2B7B1BE3E7B302EBBD892164E435AF5FB5B9B077DFEA0531ADB8026A28D003C087DEB2B7B6BCEA73923884989ECC0432B2A694630DC210A2397D97B5FC4E6C05639B1BA66621E138C54DF4D9BC1C0C012498D67CFD557E04D7CA263BD6CE8463496CD64A47FF2630453B164AAAD8DFEDB8A7BB89AC5F42B27EF676781C58906AD284CB25D970EA818848EFD5858C7B1C1A980663181E1AACBF4157E0A4E51D70636984FFE2C3052C0C70A983E4B903932593145C035189D8FFC54EA2C5955DDCF1AC48B66D0FAAE3A1F0C95 n = 19031977752053775433158924809140507039206404056424472273271188622157774199761631419592404130966729647526025764855138143073715356222955599247210922596791041047396376800139899774613720366922970272401903672933132635748592388016979721546356471020426013276329766039465318759029041086060680919505183730373784025075897893645848757498217337125191021543236168829229926869502668436749343510362317250166878453465538574128620807868941261042402239121539746440469968488061971193624777552817739359519167579901665112699695985350559979496219258864140146874900717281006959139268639863726956826644846228002118657899280178882607824440469 e = 65537 ''' https://news.ycombinator.com/item?id=3591429 Posting what I said in the other thread: As far as I can tell, this is what they're doing: if two different keys have a factor in common (i.e. A=PQ, B=PR), then you can use Euclid's algorithm (which just requires repeated subtraction, and is thus really easy) to find P (=gcd(A,B)), and then just use division to find Q (=A/P) and R (=B/P) easily. So what the researchers did, apparently, was to gather all the RSA public keys they could find (6 million or so) and then calculate the gcds of all pairs of keys. Whenever they found a gcd that wasn't equal to 1, they'd cracked (at least) 2 keys. ''' for filename in glob('*pubkeyRSA_RW*.pem'): f = open(filename) key = importKey(f.read()) if gcd(n, key.n) != 1: print (f.name) print ("key.n = " + str(key.n)) p = gcd(n, key.n) break print ("p = " + str(p)) d = int(input("d = ")) privateKey = RSA.construct((n,e,d)) f = open('key.pem', 'wb') f.write(privateKey.exportKey('PEM')) f.close print("The private key has been generated") '''
#!/usr/bin/python3 from Crypto.PublicKey.RSA import importKey from glob import glob from sys import argv if len(argv) == 1: print("Usage : ./read.py <file> <file> ...") exit() for i in argv[1:]: for j in glob(i): f = importKey(open(j, "r").read()) print("=" * 5 + " {} ".format(j) + "=" * 5) print(f"n = {f.n}") print(f"e = {f.e}") if f.has_private(): print(f"d = {f.d}")
def cipher(message): public_file = open(PATH + "/public.key", "r") public_key = importKey(public_file.read()) public_file.close() encrypted = public_key.encrypt(message, 32) return b64encode(encrypted[0])
#!/usr/python3 from sys import argv from fractions import gcd from Crypto.PublicKey.RSA import importKey, construct from glob import glob keys_dir = "RSA_RW-20181109/" user = "******" pub_key_ext = "_pubkeyRSA_RW.pem" target_key = importKey(open(keys_dir + user + pub_key_ext).read()) p = 1 # Find common divisor with other keys for filename in glob(keys_dir + '*pubkey*.pem'): if filename != keys_dir + user + pub_key_ext: candidate_key = importKey(open(filename).read()) p = gcd(target_key.n, candidate_key.n) if p != 1: #print("primer amb",filename) break q = target_key.n // p if p * q != target_key.n: raise "Error computing p and q" euler_n = target_key.n - (p + q - 1)
from sys import argv from fractions import gcd from Crypto.PublicKey.RSA import importKey, construct from glob import glob # Load target key target=importKey(open(argv[1]).read()) # Initialize p p = 1 # Find common divisor with other keys for filename in glob('*pubkey*.pem'): if filename != argv[1]: candidate = importKey(open(filename).read()) p = gcd(target.n, candidate.n) if p != 1: break q = target.n // p if p * q != target.n: raise "Error computing p and q" euler_n = target.n - (p + q - 1) def inverse(a, n): t = 0 r = n newt = 1
def attaque(ip, port) : """ Fonction """ # On demande le XML de la paire valeur = {"ip" : main.maconf.moi.ip, "port" : main.maconf.moi.port} retour = post(ip, port, "bdd.xml", valeur) # Si la paire est injoignable on arrête là try : retour_xml = minidom.parse(retour) except AttributeError : return None # On met à jour nos paramêtres try : e = retour_xml.getElementsByTagName('master')[0] unmaster = Master() unmaster.id = int(e.getElementsByTagName('id')[0].childNodes[0].nodeValue) unmaster.sha256 = str(e.getElementsByTagName('sha256')[0].childNodes[0].nodeValue) unmaster.date = float(e.getElementsByTagName('date')[0].childNodes[0].nodeValue) unmaster.signature = long(e.getElementsByTagName('signature')[0].childNodes[0].nodeValue) message = '{0.id}\n{0.sha256}\n{0.date}'.format(unmaster) if main.maconf.master.cle.verify(message, (unmaster.signature, )) \ and main.maconf.master.date < unmaster.date : main.maconf.master = unmaster main.maconf.master.save() log.debug("ICI", "mis à jour du master") main.status = "reload" except IndexError : pass # On enrichie notre liste de contacts for e in retour_xml.getElementsByTagName('paire') : unepaire = Paire() unepaire.id = int(e.getElementsByTagName('id')[0].childNodes[0].nodeValue) unepaire.ip = str(e.getElementsByTagName('ip')[0].childNodes[0].nodeValue) unepaire.port = int(e.getElementsByTagName('port')[0].childNodes[0].nodeValue) unepaire.espace = int(e.getElementsByTagName('espace')[0].childNodes[0].nodeValue) unepaire.espace_consome = int(e.getElementsByTagName('espace_consome')[0].childNodes[0].nodeValue) unepaire.privilege = str(e.getElementsByTagName('privilege')[0].childNodes[0].nodeValue) unepaire.systeme = str(e.getElementsByTagName('systeme')[0].childNodes[0].nodeValue) unepaire.arch = str(e.getElementsByTagName('arch')[0].childNodes[0].nodeValue) unepaire.sha256 = str(e.getElementsByTagName('sha256')[0].childNodes[0].nodeValue) unepaire.date = float(e.getElementsByTagName('date')[0].childNodes[0].nodeValue) unepaire.cle = importKey(e.getElementsByTagName('cle')[0].childNodes[0].nodeValue) unepaire.signature = long(e.getElementsByTagName('signature')[0].childNodes[0].nodeValue) unepaire.score = [int(f) for f in e.getElementsByTagName('score')[0].childNodes[0].nodeValue.split()] unepaire.date_score = float(e.getElementsByTagName('date_score')[0].childNodes[0].nodeValue) unepaire.signature_score = long(e.getElementsByTagName('signature_score')[0].childNodes[0].nodeValue) # Si la paire existe déjà et qu'elle authentifie ses modification message = '{0.id}\n{0.ip}\n{0.port}\n{0.espace}\n\ {0.espace_consome}\n{0.privilege}\n{0.systeme}\n\ {0.arch}\n{0.sha256}\n{0.date}'.format(unepaire) if main.maconf.paires.has_key(unepaire.id) : if main.maconf.paires[unepaire.id].date < unepaire.date \ and main.maconf.paires[unepaire.id].cle.verify(message1, (unepaire.signature, )) : main.maconf.paires[unepaire.id].id = unepaire.id main.maconf.paires[unepaire.id].ip = unepaire.ip main.maconf.paires[unepaire.id].port = unepaire.port main.maconf.paires[unepaire.id].espace = unepaire.espace main.maconf.paires[unepaire.id].espace_consome = unepaire.espace_consome main.maconf.paires[unepaire.id].privilege = unepaire.privilege main.maconf.paires[unepaire.id].systeme = unepaire.systeme main.maconf.paires[unepaire.id].arch = unepaire.arch main.maconf.paires[unepaire.id].sha256 = unepaire.sha256 main.maconf.paires[unepaire.id].date = unepaire.date main.maconf.paires[unepaire.id].signature = unepaire.signature # ou qu'on ne la posède pas mais que les paramêtres sont bon elif unepaire.cle.verify(message, (unepaire.signature, )) : main.maconf.paires[unepaire.id] = Paire() main.maconf.paires[unepaire.id].id = unepaire.id main.maconf.paires[unepaire.id].ip = unepaire.ip main.maconf.paires[unepaire.id].port = unepaire.port main.maconf.paires[unepaire.id].espace = unepaire.espace main.maconf.paires[unepaire.id].espace_consome = unepaire.espace_consome main.maconf.paires[unepaire.id].privilege = unepaire.privilege main.maconf.paires[unepaire.id].systeme = unepaire.systeme main.maconf.paires[unepaire.id].arch = unepaire.arch main.maconf.paires[unepaire.id].sha256 = unepaire.sha256 main.maconf.paires[unepaire.id].date = unepaire.date main.maconf.paires[unepaire.id].signature = unepaire.signature main.maconf.paires[unepaire.id].cle = unepaire.cle # On met à jour les scores if main.maconf.paires.has_key(unepaire.id) : message = '{0.id}\n{0.score}\n{0.date_score}'.format(unepaire) if main.maconf.paires[unepaire.id].date_score < unepaire.date_score \ and main.maconf.master.cle.verify(message, (unepaire.signature_score, )) : main.maconf.paires[unepaire.id].score = unepaire.score main.maconf.paires[unepaire.id].date_score = unepaire.date_score main.maconf.paires[unepaire.id].signature_score = unepaire.signature_score # On sauvegarde en base de données main.maconf.paires[unepaire.id].save() # On enrichie notre liste de fichier for e in retour_xml.getElementsByTagName('fichier') : unfichier = Fichier() unfichier.id = int(e.getElementsByTagName('id')[0].childNodes[0].nodeValue) unfichier.nom = str(e.getElementsByTagName('nom')[0].childNodes[0].nodeValue) unfichier.date = float(e.getElementsByTagName('date')[0].childNodes[0].nodeValue) unfichier.poids = int(e.getElementsByTagName('poids')[0].childNodes[0].nodeValue) unfichier.signature = long(e.getElementsByTagName('signature')[0].childNodes[0].nodeValue) message = '{0.id}\n{0.nom}\n{0.date}\n{0.poids}'.format(unfichier) if main.maconf.master.cle.verify(message, (unfichier.signature, )) : # On enregistre les chunks lié au fichier for f in e.getElementsByTagName('chunk') : unchunk = Chunk() unchunk.id = int(e.getElementsByTagName('id')[0].childNodes[0].nodeValue) unchunk.fichier_id = unfichier.id unchunk.date = float(e.getElementsByTagName('date')[0].childNodes[0].nodeValue) unchunk.signature = long(e.getElementsByTagName('signature')[0].childNodes[0].nodeValue) message = '{0.id}\n{0.fichier_id}\n{0.date}'.format(unchunk) if main.maconf.master.cle.verify(message, (unchunk.signature, )) : # On enregistre la paire qui stocke le chunk (directement en base de données) for id in f.getElementsByTagName('stockeur')[0].childNodes[0].nodeValue : unchunk.stockeurs.append(int(id)) unfichier.chunks[unchunk.id] = unchunk main.maconf.fichiers[unfichier.id] = unfichier main.maconf.fichiers[unfichier.id].save() # On enrichie notre liste de xor for e in retour_xml.getElementsByTagName('xor') : unxor = Xor() unxor.id,unxor.a,unxor.b = [int(f.nodeValue) for f in e.getElementsByTagName('chunk')[0].childNodes[0]] main.maconf.xors[unxor.id] = unxor main.maconf.xors[unxor.id].save() # On enrichie notre liste d'utilisateur for e in retour_xml.getElementsByTagName('utilisateur') : unutilisateur = Utilisateur() unutilisateur.id = str(e.getElementsByTagName('id')[0].childNodes[0].nodeValue) unutilisateur.mot_de_passe = str(e.getElementsByTagName('mot_de_passe')[0].childNodes[0].nodeValue) unutilisateur.courriel = str(e.getElementsByTagName('courriel')[0].childNodes[0].nodeValue) unutilisateur.date = float(e.getElementsByTagName('date')[0].childNodes[0].nodeValue) unutilisateur.signature = long(e.getElementsByTagName('signature')[0].childNodes[0].nodeValue) message = '{0.id}\n{0.mot_de_passe}\n{0.courriel}\n{0.date}'.format(unutilisateur) if ((main.maconf.utilisateurs.has_key(unutilisateur.id) \ and main.maconf.utilisateurs[unutilisateur.id].date < unutilisateur.date) \ or not main.maconf.utilisateurs.has_key(unutilisateur.id)) \ and main.maconf.master.cle.verify(message, (unutilisateur.signature, )) : main.maconf.xors[unutilisateur.id] = unutilisateur main.maconf.xors[unutilisateur.id].save()