Exemplo n.º 1
0
def one_pass(pq, tw, start_id=None):

	# Ok, grab up the last 200 mentions - which is as many as Twitter will allow, apparently.
	#
	logging.debug('Requesting mentions timeline...')
	try:
		if start_id:
			mentions = tw.statuses.mentions(since_id=start_id)
		else:
			mentions = tw.statuses.mentions(count=20)
	except:
		logging.debug('We got an error from Twitter, sorry.')
		return False

	# Now grab the highest ID in that set, which becomes the new last_id value
	for mention in mentions:
		seq = test_mention_sequence(mention['text'])  # Attempt to dissassemble packet
		if (seq[0]):				# Valid sequence?
			logging.debug("We appear to have a sequence with id %d" % (mention['id'],))
			pq.addPacket(seq[1], seq[2], user_name=mention['user']['screen_name'], 
					data=seq[3], size=4, twid=mention['id'])

	# Now go through the PacketAssembler and fish out the assembled packets, if any.
	for pkt in pq.packets:
		if pkt.areWeThereYet():
			#print pkt.getString()
			f = json.loads(pkt.getString())
			uname = f[0]
			the_id = f[1]
			pubkey = rsa.PublicKey.load_pkcs1(f[2], format='PEM')
			keyring.add_key(pkt.uname, the_id, pubkey)
			logging.info("Key for %s added and twitter id of %d..." % (pkt.uname, pkt.twitter_id))
			pkt.processed = True		# This key has been processed and we know this
	return True
Exemplo n.º 2
0
def get_key_by_name(uname):
	pubkey = keyring.get_key_by_name(uname)
	if pubkey == None:
		print "No matching public key, checking the keyserver..."
		pubkey = key_from_server(uname)
		if pubkey != None:
			print 'Found the public key in the keyserver, adding to local keyring...'
			# Add the key to our local list of keys
			keyring.add_key(uname, 8118, pubkey)
		else:
			print 'Could not find a public key for %s, aborting...' % (uname,)
			return None
	return pubkey
Exemplo n.º 3
0
	def pickuser():
		global pubkey
		uname = bottle.request.forms.uname
		force_lookup = bottle.request.forms.force_lookup
		logging.debug(force_lookup)
		if force_lookup == 'on':
			pubkey = None
			logging.debug("Forcing public key retreival from server")
		else:
			pubkey = keyring.get_key_by_name(uname)
		if pubkey:
			return bottle.template('sendmsg', user=uname)
		else:
			pubkey = txrx.key_from_server(uname)
			if pubkey:
				#return 'Found the public key for %s in the keyserver, adding to local keyring...' % (uname, )
				# Add the key to our local list of keys
				keyring.add_key(uname, 8118, pubkey)
				return bottle.template('sendmsg', user=uname)
			else:
				return bottle.template('nouser', user=uname)
Exemplo n.º 4
0
#
# Get the username.  Try to find a matching public key for encyrption.
#
success = False
if uname == None:
	uname = raw_input("Twitter Username of Recipient: ")

# If we're forced to, go to the keyserver
#
if force_srv:
	print 'Forcing a search of the keyserver...'
	pubkey = key_from_server(uname)
	if pubkey != None:
		print 'Found the public key in the keyserver, adding to local keyring...'
		# Add the key to our local list of keys
		keyring.add_key(uname, 8118, pubkey)
	else:
		print 'Could not find a public key for %s, aborting...' % (uname,)
		sys.exit(0)
else:
	pubkey = get_key_by_name(uname)		# Do we have a key matching that name?

# Now get the message text, encrypt it, and convert to base64 representation
#
if pubkey != None:
	if msg == None:
		msg = raw_input('Message to encode: ')
	if len(msg) > 140:
		print 'DMs are limited to 140 characters -- message truncated!'
		msg = msg[0:139]	# Truncate the message