def aam(): GROUP = "alt.anonymous.messages" timeStamp, curTimeStamp = dhutils.getNewsTimestamp(gpg, dbpassphrase) YYMMDD = time.strftime('%y%m%d', time.gmtime(timeStamp)) HHMMSS = time.strftime('%H%M%S', time.gmtime(timeStamp)) passphrases = dhutils.getListOfKeys(gpg, dbpassphrase) # connect to server server = nntplib.NNTP(NEWSSERVER, NEWSPORT) server.newnews(GROUP, YYMMDD, HHMMSS, '.newnews') with open('.newnews', "r") as f: ids = f.read().splitlines() for msg_id in ids: try: resp, number, message_id, text = server.article(msg_id) except (nntplib.error_temp, nntplib.error_perm): pass # no such message (maybe it was deleted?) text = string.join(text, "\n") message = email.message_from_string(text) match = False for passphrase in passphrases: for label, item in message.items(): if label == 'Subject': match = hsub.check(passphrase[2][:16], item) #if match, decrypt if match: print '\nMail for: ' + passphrase[ 0] + ' from ' + passphrase[1] msg = gpg.decrypt(message.as_string(), passphrase=passphrase[2], always_trust=True) if not msg: print 'Bad shared secret!' sys.exit(1) print '\n' + unicode(msg) with open('message_' + message_id[1:6] + '.txt', "w") as f: f.write('X-encoDHer-Route: ' + passphrase[1] + '->' + passphrase[0] + '\n') f.write(message.as_string() + '\n') print 'encrypted message stored in message_' + message_id[ 1:6] + '.txt' dhutils.setNewsTimestamp(curTimeStamp, gpg, dbpassphrase) print 'End of messages.'
def aam(): try: hsubpassphrases = readDict("hsubpass.txt") try: timeStamp = float(hsubpassphrases['time']) del hsubpassphrases['time'] except KeyError: timeStamp = time.time() - 3600.0 print 'Reading messages from last hour (no timestamp in hsubpass.txt)' curTime = time.time() YYMMDD = time.strftime('%y%m%d', time.gmtime(timeStamp)) HHMMSS = time.strftime('%H%M%S', time.gmtime(timeStamp)) except IOError: print 'hsubpass.txt file not found - exiting!' sys.exit(1) # connect to server server = nntplib.NNTP(NEWSSERVER,NEWSPORT) server.newnews(GROUP, YYMMDD, HHMMSS, '.newnews') with open ('.newnews', 'r') as f: ids=f.read().splitlines() for msg_id in ids: try: resp, id, message_id, text = server.article(msg_id) except (nntplib.error_temp, nntplib.error_perm): pass # no such message (maybe it was deleted?) text = string.join(text, "\n") message = email.message_from_string(text) match = False for nick, passphrase in hsubpassphrases.items(): #print passphrase, msg_id for label, item in message.items(): if label == 'Subject': match = hsub.check(passphrase,item) #if match: write message to file if match: print 'Found a message for nickname '+nick with open('message_'+nick+'_'+message_id[1:6]+'.txt', "w") as f: f.write(message.as_string()+'\n') print 'encrypted message stored in message_'+nick+'_'+message_id[1:6]+'.txt' print 'End of messages.' hsubpassphrases['time'] = curTime writeDict('hsubpass.txt', hsubpassphrases)
def aam(): GROUP = "alt.anonymous.messages" timeStamp, curTimeStamp = dhutils.getNewsTimestamp(gpg,dbpassphrase) YYMMDD = time.strftime('%y%m%d', time.gmtime(timeStamp)) HHMMSS = time.strftime('%H%M%S', time.gmtime(timeStamp)) passphrases = dhutils.getListOfKeys(gpg,dbpassphrase) # connect to server server = nntplib.NNTP(NEWSSERVER,NEWSPORT) server.newnews(GROUP, YYMMDD, HHMMSS, '.newnews') with open ('.newnews', "r") as f: ids=f.read().splitlines() for msg_id in ids: try: resp, number, message_id, text = server.article(msg_id) except (nntplib.error_temp, nntplib.error_perm): pass # no such message (maybe it was deleted?) text = string.join(text, "\n") message = email.message_from_string(text) match = False for passphrase in passphrases: for label, item in message.items(): if label == 'Subject': match = hsub.check(passphrase[2][:16],item) #if match, decrypt if match: print '\nMail for: '+passphrase[0]+' from '+passphrase[1] msg = gpg.decrypt(message.as_string(), passphrase=passphrase[2], always_trust=True) if not msg: print 'Bad shared secret!' sys.exit(1) print '\n'+unicode(msg) with open('message_'+message_id[1:6]+'.txt', "w") as f: f.write('X-encoDHer-Route: '+passphrase[1]+'->'+passphrase[0]+'\n') f.write(message.as_string()+'\n') print 'encrypted message stored in message_'+message_id[1:6]+'.txt' dhutils.setNewsTimestamp(curTimeStamp,gpg,dbpassphrase) print 'End of messages.'