sys.path.append(client_config.rsa_path)
import monRSA
-def connect(sock,where="cerebro",port=None):
+def full_read(sock):
+ """Lit sur la socket jusqu'à ce que l'output soit déJSON-izable"""
+ output=""
+ while True:
+ output+=sock.read()
+ try:
+ return json.loads(output)
+ except:
+ pass
+
+def connect(sock,where,port=None):
if port==None:
port=client_config.port
- ip={"ici":"localhost","vent":"vent.crans.org","eva":"eva.crans.org","cerebro":"cerebro.crans.org"}[where]
+ try:
+ ip={"ici":"localhost","vent":"vent.crans.org","eva":"eva.crans.org","cerebro":"cerebro.crans.org"}[where]
+ except:
+ ip=where
sock.connect((ip,port))
return ssl.wrap_socket(sock,ca_certs=client_config.ca_certfile)
# cert_reqs=ssl.CERT_NONE,ciphers="AES256-SHA")
def search(socket,term):
a.write("search %s"%(term))
- return json.loads(a.read())
+ return lit(a)
def lit(socket):
try:
- t=a.read(4096)
- obj=json.loads(t)
+ obj=full_read(socket)
if obj["retcode"]==0:
return obj['msg']
else:
except ValueError:
return "Serveur mort ?"
-def challenge(a):
- _,pub=monRSA.litcles(None,client_config.server_rsa_pub_key)
- chall=str(time.time())
- chall+="".join(["azertyuiopqsdfghjklmwxcvbn"[random.randrange(0,26)] for i in range(20)])
- coded=monRSA.crypte(chall,pub)
- a.send('challenge "%s"'%(coded))
- a.setblocking(True)
- result=a.read()
- a.settimeout(0.5)
- if json.loads(result)==chall:
- print "Recognized"
- elif json.loads(result)==u"Challenge tenté il y a moins de 10 minutes ! =p":
- print "Top tôt. Réessaye plus tard."
- else:
- print "Imposteur !"
-
if __name__=="__main__":
where=raw_input("quel serveur ?")
#port=int(raw_input("port ? "))