def mutate(): try: fromEmail = sys.argv[2] toEmail = sys.argv[3] except (IndexError): print 'You need to supply a fromEmail, and toEmail!' print 'Ex: '+sys.argv[0]+' --mutate-key <fromEmail> <toEmail>' sys.exit(1) try: with open(KEYS_DB): pass except IOError: print 'No keys database (keys.db)' print 'initialize the database with '+sys.argv[0]+' --init' sys.exit(1) oldpassphrase = dhutils.genSharedSecret(fromEmail,toEmail,gpg,dbpassphrase) dhutils.mutateKey(fromEmail,toEmail,gpg,dbpassphrase) privkey, mypubkey, otherpubkey = dhutils.getKeys(fromEmail,toEmail,gpg,dbpassphrase) while len(mypubkey) < 50*50: mypubkey = '0'+mypubkey brokenkey = [mypubkey[i:i+50] for i in range(0, len(mypubkey), 50)] new_mypubkey = '' for line in brokenkey: new_mypubkey += line+'\n' passphrase = getpass('Signing key ('+fromEmail+') password: '******'DH Public Key:\n'+new_mypubkey+'\n', passphrase=passphrase, keyid=fromEmail) print '' print str(signed_data) ans = raw_input('Do you want to send this key anonymously? (y/N)') if ans == 'y': sendAnon = True else: sendAnon = False msg = gpg.encrypt(str(signed_data), recipients=None, symmetric=CIPHER, always_trust=True, passphrase=oldpassphrase) if sendAnon: iv = hsub.cryptorandom() hsubject = hsub.hash(oldpassphrase) with open('mutatedkey.asc', "w") as f: if sendAnon: f.write('To: [email protected],[email protected]\n') f.write('Subject: %s\n' % hsubject) f.write('Newsgroups: alt.anonymous.messages\n') f.write('X-No-Archive: Yes\n') f.write('\n') f.write(re.sub('\nV.*$', '', str(msg), count=1, flags=re.MULTILINE)) print 'New key encrypted with old DH shared secret is in "mutatedkey.asc"' print 'Get unencrypted, signed copy of new key with '+sys.argv[0]+' --sign-pub '+fromEmail+' '+toEmail
def hs(): try: file_name = sys.argv[2] fromEmail = sys.argv[3] toEmail = sys.argv[4] except (IndexError): print 'You need to supply a target file to be encrypted, fromEmail, and toEmail!' print 'Ex: ' + sys.argv[ 0] + ' --encode-email <file> <fromEmail> <toEMail>' sys.exit(1) try: with open(KEYS_DB): pass except IOError: print 'No keys database (keys.db)' print 'initialize the database with ' + sys.argv[0] + ' --init' sys.exit(1) ans = raw_input('Do you want to send this message anonymously? (y/N)') if ans == 'y': sendAnon = True else: sendAnon = False passphrase = dhutils.genSharedSecret(fromEmail, toEmail, gpg, dbpassphrase) with open(file_name, "rb") as f: msg = gpg.encrypt_file(f, recipients=None, symmetric=CIPHER, always_trust=True, passphrase=passphrase) if sendAnon: iv = hsub.cryptorandom() hsubject = hsub.hash(passphrase[:16]) # first 64 bits to calc hsub # A note here about using part of the passphrase as the hsub password. # We use 64 bits (16 ascii bytes hex encoded = 8 bytes binary entropy) # for the hsub passphrase. Assuming those 64 bits are completely # compromised (unlikekly, as it would require a rainbow table with # 3.4 x 10^38 entries) that leaves us with 192 bits of aes key entropy. # Still plenty strong. with open(file_name + '.asc', "w") as f: if sendAnon: f.write('To: [email protected],[email protected]\n') f.write('Subject: %s\n' % hsubject) f.write('Newsgroups: alt.anonymous.messages\n') f.write('X-No-Archive: Yes\n') f.write('\n') f.write(re.sub('\nV.*$', '', str(msg), count=1, flags=re.MULTILINE)) print 'The encrypted file is ' + file_name + '.asc' print 'Passphrase: %s' % passphrase
def hs(): try: file_name = sys.argv[2] fromEmail = sys.argv[3] toEmail = sys.argv[4] except (IndexError): print 'You need to supply a target file to be encrypted, fromEmail, and toEmail!' print 'Ex: '+sys.argv[0]+' --encode-email <file> <fromEmail> <toEMail>' sys.exit(1) try: with open(KEYS_DB): pass except IOError: print 'No keys database (keys.db)' print 'initialize the database with '+sys.argv[0]+' --init' sys.exit(1) ans = raw_input('Do you want to send this message anonymously? (y/N)') if ans == 'y': sendAnon = True else: sendAnon = False passphrase = dhutils.genSharedSecret(fromEmail,toEmail,gpg,dbpassphrase) with open(file_name, "rb") as f: msg = gpg.encrypt_file(f, recipients=None, symmetric=CIPHER, always_trust=True, passphrase=passphrase) if sendAnon: iv = hsub.cryptorandom() hsubject = hsub.hash(passphrase[:16]) # first 64 bits to calc hsub # A note here about using part of the passphrase as the hsub password. # We use 64 bits (16 ascii bytes hex encoded = 8 bytes binary entropy) # for the hsub passphrase. Assuming those 64 bits are completely # compromised (unlikekly, as it would require a rainbow table with # 3.4 x 10^38 entries) that leaves us with 192 bits of aes key entropy. # Still plenty strong. with open(file_name+'.asc', "w") as f: if sendAnon: f.write('To: [email protected],[email protected]\n') f.write('Subject: %s\n' % hsubject) f.write('Newsgroups: alt.anonymous.messages\n') f.write('X-No-Archive: Yes\n') f.write('\n') f.write(re.sub('\nV.*$', '', str(msg), count=1, flags=re.MULTILINE)) print 'The encrypted file is '+file_name+'.asc' print 'Passphrase: %s' % passphrase
def mutate(): try: fromEmail = sys.argv[2] toEmail = sys.argv[3] except (IndexError): print 'You need to supply a fromEmail, and toEmail!' print 'Ex: ' + sys.argv[0] + ' --mutate-key <fromEmail> <toEmail>' sys.exit(1) try: with open(KEYS_DB): pass except IOError: print 'No keys database (keys.db)' print 'initialize the database with ' + sys.argv[0] + ' --init' sys.exit(1) oldpassphrase = dhutils.genSharedSecret(fromEmail, toEmail, gpg, dbpassphrase) dhutils.mutateKey(fromEmail, toEmail, gpg, dbpassphrase) privkey, mypubkey, otherpubkey = dhutils.getKeys(fromEmail, toEmail, gpg, dbpassphrase) while len(mypubkey) < 50 * 50: mypubkey = '0' + mypubkey brokenkey = [mypubkey[i:i + 50] for i in range(0, len(mypubkey), 50)] new_mypubkey = '' for line in brokenkey: new_mypubkey += line + '\n' passphrase = getpass('Signing key (' + fromEmail + ') password: '******'DH Public Key:\n' + new_mypubkey + '\n', passphrase=passphrase, keyid=fromEmail) print '' print str(signed_data) ans = raw_input('Do you want to send this key anonymously? (y/N)') if ans == 'y': sendAnon = True else: sendAnon = False msg = gpg.encrypt(str(signed_data), recipients=None, symmetric=CIPHER, always_trust=True, passphrase=oldpassphrase) if sendAnon: iv = hsub.cryptorandom() hsubject = hsub.hash(oldpassphrase) with open('mutatedkey.asc', "w") as f: if sendAnon: f.write('To: [email protected],[email protected]\n') f.write('Subject: %s\n' % hsubject) f.write('Newsgroups: alt.anonymous.messages\n') f.write('X-No-Archive: Yes\n') f.write('\n') f.write(re.sub('\nV.*$', '', str(msg), count=1, flags=re.MULTILINE)) print 'New key encrypted with old DH shared secret is in "mutatedkey.asc"' print 'Get unencrypted, signed copy of new key with ' + sys.argv[ 0] + ' --sign-pub ' + fromEmail + ' ' + toEmail