예제 #1
0
def get_record(conn, id):                #retrieve record from db by id
    dec=scell.scell_token_protect(password);
    cur = conn.cursor();
    cur.execute("SELECT * FROM scell_data INNER JOIN scell_data_auth ON scell_data.id = %s AND scell_data.id=scell_data_auth.id;", (id,))
    x = cur.fetchone();
    print "stored data:", repr(str(x[1])), repr(str(x[4])), repr(str(x[2])), repr(str(x[5]));
    num=dec.decrypt(str(x[1]),str(x[4]));
    data=dec.decrypt(str(x[2]),str(x[5]));
    cur.close();
    return (num,data);
예제 #2
0
def add_record(conn, field1, field2):        #store record
    enc=scell.scell_token_protect(password);
    enc_field1, field1_auth_data = enc.encrypt(str(field1)); #encrypt field1
    enc_field2, field2_auth_data = enc.encrypt(str(field2)); #encrypt field2
    
    cur = conn.cursor();
    cur.execute("INSERT INTO scell_data (num, data) VALUES (%s, %s) RETURNING ID",(psycopg2.Binary(enc_field1), psycopg2.Binary(enc_field2))); #store main cryptomessage
    new_id_value=cur.fetchone()[0];
    cur.execute("INSERT INTO scell_data_auth (id, num, data) VALUES (%s, %s, %s)",(new_id_value, psycopg2.Binary(field1_auth_data), psycopg2.Binary(field2_auth_data))); #store additional auth values
    conn.commit();
    cur.close();
    return new_id_value;
예제 #3
0
def get_record(conn, id):  #retrieve record from db by id
    dec = scell.scell_token_protect(password)
    cur = conn.cursor()
    cur.execute(
        "SELECT * FROM scell_data INNER JOIN scell_data_auth ON scell_data.id = %s AND scell_data.id=scell_data_auth.id;",
        (id, ))
    x = cur.fetchone()
    print "stored data:", repr(str(x[1])), repr(str(x[4])), repr(str(
        x[2])), repr(str(x[5]))
    num = dec.decrypt(str(x[1]), str(x[4]))
    data = dec.decrypt(str(x[2]), str(x[5]))
    cur.close()
    return (num, data)
예제 #4
0
 def testTokenProtect(self):
     with self.assertRaises(themis_exception):
         scell.scell_token_protect("")
     with self.assertRaises(TypeError):
         scell.scell_token_protect(None)
     with self.assertRaises(TypeError):
         scell.scell_token_protect(112233)
     enc = scell.scell_token_protect(self.key)
     with self.assertRaises(themis_exception):
         enc.encrypt("")
     with self.assertRaises(TypeError):
         enc.encrypt(None)
     encrypted_message, token = enc.encrypt(self.message)
     with self.assertRaises(themis_exception):
         enc.decrypt(b"".join([encrypted_message, b"11"]), token)
     with self.assertRaises(TypeError):
         enc.decrypt(encrypted_message, None)
     decrypted_message = enc.decrypt(encrypted_message, token)
     self.assertEqual(self.message, decrypted_message)
예제 #5
0
def add_record(conn, field1, field2):  #store record
    enc = scell.scell_token_protect(password)
    enc_field1, field1_auth_data = enc.encrypt(str(field1))
    #encrypt field1
    enc_field2, field2_auth_data = enc.encrypt(str(field2))
    #encrypt field2

    cur = conn.cursor()
    cur.execute(
        "INSERT INTO scell_data (num, data) VALUES (%s, %s) RETURNING ID",
        (psycopg2.Binary(enc_field1), psycopg2.Binary(enc_field2)))
    #store main cryptomessage
    new_id_value = cur.fetchone()[0]
    cur.execute(
        "INSERT INTO scell_data_auth (id, num, data) VALUES (%s, %s, %s)",
        (new_id_value, psycopg2.Binary(field1_auth_data),
         psycopg2.Binary(field2_auth_data)))
    #store additional auth values
    conn.commit()
    cur.close()
    return new_id_value
예제 #6
0
 def testTokenProtect(self):
     with self.assertRaises(themis_exception):
         scell.scell_token_protect("")
     with self.assertRaises(TypeError):
         scell.scell_token_protect(None)
     with self.assertRaises(TypeError):
         scell.scell_token_protect(112233)
     enc = scell.scell_token_protect(self.key)
     with self.assertRaises(themis_exception):
         enc.encrypt("")
     with self.assertRaises(TypeError):
         enc.encrypt(None)
     encrypted_message, token = enc.encrypt(self.message)
     with self.assertRaises(themis_exception):
         enc.decrypt(b"".join([encrypted_message, b"11"]), token)
     with self.assertRaises(TypeError):
         enc.decrypt(encrypted_message, None)
     decrypted_message = enc.decrypt(encrypted_message, token)
     self.assertEqual(self.message, decrypted_message)