From d2219464a16bf75a9fb0c60c1934cf5eddcf1909 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Mon, 20 Feb 2012 02:09:47 +0100 Subject: [PATCH] Initialisation avec quelques fichiers --- .gitignore | 39 ++++++++++++++++ client.py | 101 ++++++++++++++++++++++++++++++++++++++++ client_config.py | 14 ++++++ keys/ca.crt | 25 ++++++++++ keys/server_rsa_key.pub | 5 ++ send_photo.py | 12 +++++ 6 files changed, 196 insertions(+) create mode 100644 .gitignore create mode 100755 client.py create mode 100644 client_config.py create mode 100644 keys/ca.crt create mode 100644 keys/server_rsa_key.pub create mode 100644 send_photo.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f970c32 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +# Custom # +################### +*~ + +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so +*.pyc + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +#*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store* +*ehthumbs.db +Icon? +*Thumbs.db diff --git a/client.py b/client.py new file mode 100755 index 0000000..65a62a1 --- /dev/null +++ b/client.py @@ -0,0 +1,101 @@ +#!/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\"" diff --git a/client_config.py b/client_config.py new file mode 100644 index 0000000..26f848f --- /dev/null +++ b/client_config.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +basedir = "/usr/scripts/Note_Kfet_2015/" +clientdir = basedir + "client/" +ca_certfile = clientdir + "keys/ca.crt" +server_rsa_pub_key = clientdir + "keys/server_rsa_key.pub" + +# le module qui fait du rsa +rsa_path = "/usr/scripts/Note_Kfet_2015/rsa_source/" +# parce que le port est pour l'instant aléatoire, ça disparaîtra après +portfile=open(basedir+"serveur/port.txt","r") +port = int(portfile.read()) +portfile.close() diff --git a/keys/ca.crt b/keys/ca.crt new file mode 100644 index 0000000..d4d6918 --- /dev/null +++ b/keys/ca.crt @@ -0,0 +1,25 @@ +-----BEGIN CERTIFICATE----- +MIIEHzCCA4igAwIBAgIJAPuPFCLL9lQtMA0GCSqGSIb3DQEBBQUAMIG8MQswCQYD +VQQGEwJGUjEXMBUGA1UECBQOw45sZSBkZSBGcmFuY2UxDzANBgNVBAcTBkNhY2hh +bjEXMBUGA1UEChMOQkRFIEVOUyBDYWNoYW4xKzApBgNVBAsUIkF1dG9yaXTDqSBk +ZSBDZXJ0aWZpY2F0aW9uIE1hw650cmUxGjAYBgNVBAMTEUJERSBFTlMgQ2FjaGFu +IENBMSEwHwYJKoZIhvcNAQkBFhJsZWdhbGxpY0BjcmFucy5vcmcwHhcNMTExMjI2 +MjIwNjQ4WhcNMjExMjIzMjIwNjQ4WjCBvDELMAkGA1UEBhMCRlIxFzAVBgNVBAgU +DsOObGUgZGUgRnJhbmNlMQ8wDQYDVQQHEwZDYWNoYW4xFzAVBgNVBAoTDkJERSBF +TlMgQ2FjaGFuMSswKQYDVQQLFCJBdXRvcml0w6kgZGUgQ2VydGlmaWNhdGlvbiBN +YcOudHJlMRowGAYDVQQDExFCREUgRU5TIENhY2hhbiBDQTEhMB8GCSqGSIb3DQEJ +ARYSbGVnYWxsaWNAY3JhbnMub3JnMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB +gQCykkgrE+wbpaBiejCnnQajDYbhVmbgLSp9fTwVYKXTveQ5lNdDVoRqaXq9oavE +wGNfqOQKFNbwJCOQA2Oz8HikjleLZgynZXd2QPbCX+wwOkqNqWQ+Q7NaRFTfytN4 +srPgZBLyyKSGCGadOOV2ZNa5WQ9HcC3kVApdvAa48zl3ywIDAQABo4IBJTCCASEw +HQYDVR0OBBYEFPGk2qO0Ik/NrPfcCXrj+A2hVjF9MIHxBgNVHSMEgekwgeaAFPGk +2qO0Ik/NrPfcCXrj+A2hVjF9oYHCpIG/MIG8MQswCQYDVQQGEwJGUjEXMBUGA1UE +CBQOw45sZSBkZSBGcmFuY2UxDzANBgNVBAcTBkNhY2hhbjEXMBUGA1UEChMOQkRF +IEVOUyBDYWNoYW4xKzApBgNVBAsUIkF1dG9yaXTDqSBkZSBDZXJ0aWZpY2F0aW9u +IE1hw650cmUxGjAYBgNVBAMTEUJERSBFTlMgQ2FjaGFuIENBMSEwHwYJKoZIhvcN +AQkBFhJsZWdhbGxpY0BjcmFucy5vcmeCCQD7jxQiy/ZULTAMBgNVHRMEBTADAQH/ +MA0GCSqGSIb3DQEBBQUAA4GBABl+B4fa1vlVJmhfe2Q1d5UVtels8RctEeisOfVD ++OpzgkTggdlYbp/9RnlKlAX8XQF6r5J4zfg1oJqB7kjT5eJ65xL88ZS4yr8f3Vmg +4yus0TMRk/sLmdLDrXwBz0tmSYsCFqJbJqowAOyVn1UKZz0D4E2GFBN9/Fl0MVGf +lEEU +-----END CERTIFICATE----- diff --git a/keys/server_rsa_key.pub b/keys/server_rsa_key.pub new file mode 100644 index 0000000..5ffe356 --- /dev/null +++ b/keys/server_rsa_key.pub @@ -0,0 +1,5 @@ +-----BEGIN RSA PUBLIC KEY----- +MIGJAoGBAK3lNeaNyrt3FgSaHPLhZK+TL6RXnle2aeOVZvmoWuspZIdSgvDJM/ce +7CkSLZc+HL0DEXBiS1WYstiSMM6+LqUfSbDVVsbanFgqGIzFk4jz9HfMXh808nUI +rtNlZiguIIddnqmz8RikWh0oP51dctfXBhh9ZnXzgIzcqAHOC7k7AgMBAAE= +-----END RSA PUBLIC KEY----- diff --git a/send_photo.py b/send_photo.py new file mode 100644 index 0000000..550fc76 --- /dev/null +++ b/send_photo.py @@ -0,0 +1,12 @@ +import socket,time,base64 +def send_photo(where,port): + s=socket.socket() + s.connect(({"vent":"138.231.140.145","eva":"138.231.138.131"}[where],port)) + s.send('login ["20-100","mdp","clair"]\n') + time.sleep(1) + tof=base64.b64encode(open("photos/2850.jpg","r").read()) + s.send("set_photo [1,%s]\n"%(len(tof))) + time.sleep(1) + s.send(tof+'\n') + time.sleep(2) + s.close() -- 2.39.2