--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Définition des fonctions de base de communication du client
+# Pour l'instant ce script sert essentiellement à les charger en mémoire pour les utiliser à la main
+
+import os, sys, string, time, random
+import socket, ssl
+import threading
+
+import json
+import hashlib
+
+import client_config
+reload(client_config)
+
+from pprint import pprint
+
+sys.path.append(client_config.rsa_path)
+import monRSA
+
+def connect(sock,where="ici"):
+ port=client_config.port
+ ip={"ici":"localhost","vent":"vent.crans.org","eva":"eva.crans.org"}[where]
+ sock.connect((ip,port))
+ return ssl.wrap_socket(sock,ca_certs=client_config.ca_certfile,
+ cert_reqs=ssl.CERT_OPTIONAL,ciphers="AES256-SHA")
+
+def checkidentity(a):
+ c=a.getpeercert()
+ print c
+ c=dict([i[0] for i in c["subject"]])
+ awaited={'commonName': u'note.crans.org',
+ 'countryName': u'FR',
+ 'emailAddress': u'legallic@crans.org',
+ 'localityName': u'Cachan',
+ 'organizationName': u'BDE ENS Cachan',
+ 'organizationalUnitName': u'Kfet',
+ 'stateOrProvinceName': u'\xc3\x8ele de France'}
+ if all([c[cle]==awaited[cle] for cle in awaited.keys()]):
+ return
+ else:
+ raise KeyboardInterrupt("Imposteur !")
+
+def hello(socket,version):
+ socket.send('hello "%s"'%(version))
+ return json.loads(a.read())
+
+def login(socket,user,mdp="",typ="bdd"):
+ if user in ["20-100","moibdd"]:
+ a.write('login ["20-100","mdp","bdd"]')
+ elif user in ["vincent","moi"]:
+ a.write('login ["vincent","mdp","special"]')
+ else:
+ a.write('login ["%s","%s","%s"]'%(user,mdp,typ))
+ return json.loads(a.read())
+
+def search(socket,term):
+ a.write("search %s"%(term))
+ return json.loads(a.read())
+
+def lit(socket,noprint=False):
+ try:
+ t=a.read()
+ if noprint:
+ return json.loads(t)
+ else:
+ obj=json.loads(t)
+ if type(obj)==unicode:
+ print obj
+ else:
+ pprint(obj)
+ except ssl.SSLError:
+ print "Rien à lire"
+ except ValueError:
+ print "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__":
+ a=socket.socket()
+ a=connect(a)
+ a.settimeout(0.5)
+ checkidentity(a)
+ print hello(a,"Python Client alpha")
+ print login(a,"20-100","mdp")
+ print "Socket créée dans la variable \"a\""
--- /dev/null
+-----BEGIN CERTIFICATE-----
+MIIEHzCCA4igAwIBAgIJAPuPFCLL9lQtMA0GCSqGSIb3DQEBBQUAMIG8MQswCQYD
+VQQGEwJGUjEXMBUGA1UECBQOw45sZSBkZSBGcmFuY2UxDzANBgNVBAcTBkNhY2hh
+bjEXMBUGA1UEChMOQkRFIEVOUyBDYWNoYW4xKzApBgNVBAsUIkF1dG9yaXTDqSBk
+ZSBDZXJ0aWZpY2F0aW9uIE1hw650cmUxGjAYBgNVBAMTEUJERSBFTlMgQ2FjaGFu
+IENBMSEwHwYJKoZIhvcNAQkBFhJsZWdhbGxpY0BjcmFucy5vcmcwHhcNMTExMjI2
+MjIwNjQ4WhcNMjExMjIzMjIwNjQ4WjCBvDELMAkGA1UEBhMCRlIxFzAVBgNVBAgU
+DsOObGUgZGUgRnJhbmNlMQ8wDQYDVQQHEwZDYWNoYW4xFzAVBgNVBAoTDkJERSBF
+TlMgQ2FjaGFuMSswKQYDVQQLFCJBdXRvcml0w6kgZGUgQ2VydGlmaWNhdGlvbiBN
+YcOudHJlMRowGAYDVQQDExFCREUgRU5TIENhY2hhbiBDQTEhMB8GCSqGSIb3DQEJ
+ARYSbGVnYWxsaWNAY3JhbnMub3JnM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