コード例 #1
0
 def testComparation2(self):
     alice = scomparator.scomparator(self.message)
     bob = scomparator.scomparator(self.message1)
     data = alice.begin_compare()
     while (alice.result() == scomparator.SCOMPARATOR_CODES.NOT_READY and
             bob.result() == scomparator.SCOMPARATOR_CODES.NOT_READY):
         data = alice.proceed_compare(bob.proceed_compare(data))
     self.assertEqual(alice.result(),
                      scomparator.SCOMPARATOR_CODES.NOT_MATCH)
     self.assertEqual(bob.result(), scomparator.SCOMPARATOR_CODES.NOT_MATCH)
コード例 #2
0
ファイル: server.py プロジェクト: cossacklabs/sesto
def on_auth1_message(msg, ws_response, session, comparator):
    p=get_user_password(msg[1]);
    if p is None:
        ws_response.send_str(base64.b64encode(session.wrap(b"INVALID_LOGIN")).decode("UTF-8"));
    else:
        comparator = scomparator.scomparator(p[0].encode("UTF-8"));
        try:
            data = base64.b64encode(comparator.proceed_compare(base64.b64decode(msg[2]))).decode("UTF-8");
            ws_response.send_str(base64.b64encode(session.wrap(("AUTH1 "+data).encode("UTF-8"))).decode("UTF-8"));
            return comparator;
        except Exception:
            ws_response.send_str(base64.b64encode(session.wrap(b"INVALID_LOGIN")).decode("UTF-8"));
コード例 #3
0
import requests;
from requests.auth import HTTPDigestAuth
from pythemis import scomparator;
import base64;
import time;
username = 'andrey';
password = 'password';

start = time.time();

for i in range(1,10000):
    with requests.Session() as s:
        comparator=scomparator.scomparator(password.encode("UTF-8"));
        dd=base64.b64encode(comparator.begin_compare()).decode("UTF-8")
        headers = {"Authorization": "Themis "+username+" "+dd, "Connection":"Keep-Alive"};
        r = s.get('http://127.0.0.1:8080/themis-sc-auth/', headers=headers);
        if r.status_code == 308:
            dd = comparator.proceed_compare(base64.b64decode(r.headers["Authorization"].encode("UTF-8")));
            headers = {"Authorization": "Themis "+base64.b64encode(dd).decode("UTF-8")};
            r = s.get("http://127.0.0.1:8080//themis-sc-auth/index.html", headers=headers);
#        print(r.status_code);
            if r.status_code == 200:
                dd = comparator.proceed_compare(base64.b64decode(r.headers["Authorization"].encode("UTF-8")));
                if comparator.result() == scomparator.SCOMPARATOR_CODES.NOT_MATCH:
                    print("error");
                else:
                    print(i, ",", time.time()-start);
        else:
           print(r.headers);
コード例 #4
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#echo server with handmade ssession wrappers (see ssession_wrappers.py) 
#for none event handled transport, like plain socket
from pythemis import scomparator;
import socket;

conn = socket.socket();
conn.bind(("127.0.0.1", 26260));
conn.listen(1);
socket, addr = conn.accept();

comparator=scomparator.scomparator(b"shared secret");
while comparator.result()==scomparator.SCOMPARATOR_CODES.NOT_READY:
    data=comparator.proceed_compare(socket.recv(1024));
    socket.sendall(data);

if comparator.result() == scomparator.SCOMPARATOR_CODES.NOT_MATCH:
    print("not match");
else :
    print("match");

socket.close();
conn.close();
コード例 #5
0
    def get_pub_key_by_id(self, user_id):                #necessary callback
        return user_id; 


start=time.time();
for i in range(1, 10000):
        transport_ = transport();
        alg="EC";
        obj = skeygen.themis_gen_key_pair(alg);
        session=ssession.ssession(obj.export_public_key(), obj.export_private_key(), transport_);
        data = session.connect();
        while session.is_established() != True:
            data = session.receive();


        comparator=scomparator.scomparator(b"password");
        data=comparator.begin_compare()
        session.send(("GET /themis-sc-auth/ HTTP/1.1\r\nUser-Agent: curl/7.38.0\r\nAuthorization: Themis andrey "+base64.b64encode(data).decode("UTF-8")+"\r\nHost: 127.0.0.1:8080\r\nAccept: */*\r\n\r\n").encode("UTF-8"));
        headers= session.receive().decode("UTF-8").split('\r\n');
        data = comparator.proceed_compare(base64.b64decode(dict(x.split(':') for x in headers[1:-4])["Authorization"]))
        session.send(("GET /themis-sc-auth/ HTTP/1.1\r\nUser-Agent: curl/7.38.0\r\nAuthorization: Themis "+base64.b64encode(data).decode("UTF-8")+"\r\nHost: 127.0.0.1:8080\r\nAccept: */*\r\n\r\n").encode("UTF-8"));
        headers= session.receive().decode("UTF-8").split('\r\n');
        data = comparator.proceed_compare(base64.b64decode(dict(x.split(':') for x in headers[1:-6])["Authorization"]))

        if comparator.result() == scomparator.SCOMPARATOR_CODES.NOT_MATCH:
            print("not match");
        else:
            print(i, ",", time.time()-start);
#    print(ii,",", time.clock()-start, file=sys.stderr);