Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix android secure cell wrapper in token protect mode #251

Merged
merged 4 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ android {

defaultConfig {
minSdkVersion 16
targetSdkVersion 16
}

sourceSets {
Expand Down
43 changes: 40 additions & 3 deletions docs/examples/python/scell_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import base64

from pythemis.scell import SCellTokenProtect
from pythemis.scell import SCellSeal
from pythemis.scell import SCellContextImprint

message = 'message to encrypt'
message = "i'm plain text message"
passwrd = b"pass"
context = b"somecontext"


print("running secure cell in seal mode...")

scell = SCellSeal(passwrd)

Expand All @@ -12,14 +18,45 @@
encrypted_message_string = base64.b64encode(encrypted_message)
print(encrypted_message_string)

print("decrypting from binary...")
print("decrypting from binary... --> ")
decrypted_message = scell.decrypt(encrypted_message).decode('utf-8')
print(decrypted_message)


print("decrypting from string...")
print("decrypting from string... --> ")
# check https://themis.cossacklabs.com/data-simulator/cell/
encrypted_message_string = "AAEBQAwAAAAQAAAADQAAACoEM9MbJzEu2RDuRoGzcQgN4jchys0q+LLcsbfUDV3M2eg/FhygH1ns"
decrypted_message_from_string = base64.b64decode(encrypted_message_string)
decrypted_message = scell.decrypt(decrypted_message_from_string).decode('utf-8')
print(decrypted_message)


print("----------------------")
print("running secure cell in token protect mode...")

scellTP = SCellTokenProtect(passwrd)

print("encrypting...")
encrypted_message, additional_auth_data = scellTP.encrypt(message.encode('utf-8'))
encrypted_message_string = base64.b64encode(encrypted_message)
print(encrypted_message_string)

print("decrypting from binary... --> ")
decrypted_message = scellTP.decrypt(encrypted_message, additional_auth_data).decode('utf-8')
print(decrypted_message)


print("----------------------")
print("running secure cell in context imprint mode...")


scellCI = SCellContextImprint(passwrd)

print("encrypting...")
encrypted_message = scellCI.encrypt(message.encode('utf-8'), context)
encrypted_message_string = base64.b64encode(encrypted_message)
print(encrypted_message_string)

print("decrypting from binary... --> ")
decrypted_message = scellCI.decrypt(encrypted_message, context).decode('utf-8')
print(decrypted_message)
1 change: 1 addition & 0 deletions jni/themis_cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_cossacklabs_themis_SecureCell_encrypt(JN
if (additional_data_length)
{
additional_data_buf = (*env)->GetByteArrayElements(env, additional_data, NULL);
if (!additional_data_buf)
{
goto err;
}
Expand Down
1 change: 1 addition & 0 deletions src/themis/secure_session_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <soter/soter_container.h>

#include <string.h>
#include <time.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang requires this header to be while building themis with boringssl :D


#include <arpa/inet.h>
#include "portable_endian.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ private byte[] generateTestData() {
@Override
public void runTest() {
try {
// testSeal();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you know, having tests commented... is kinda.. questionable :D

// testTokenProtect();
// testContextImprint();
testSeal();
testTokenProtect();
testContextImprint();
} catch (Exception e) {
String failMessage = e.getClass().getCanonicalName();

Expand All @@ -65,6 +65,8 @@ void testSeal() throws Exception {
byte[] data = generateTestData();

SecureCell cell = new SecureCell(key);
assertNotNull(cell);

SecureCellData protectedData = cell.protect(context, data);

assertNotNull(protectedData);
Expand All @@ -85,7 +87,9 @@ void testTokenProtect() throws Exception {
byte[] data = generateTestData();

SecureCell cell = new SecureCell(key, SecureCell.MODE_TOKEN_PROTECT);
SecureCellData protectedData = cell.protect(context, data);
assertNotNull(cell);

SecureCellData protectedData = cell.protect(key, context, data);

assertNotNull(protectedData);
assertNotNull(protectedData.getProtectedData());
Expand All @@ -105,6 +109,8 @@ void testContextImprint() throws Exception {
byte[] data = generateTestData();

SecureCell cell = new SecureCell(key, SecureCell.MODE_CONTEXT_IMPRINT);
assertNotNull(cell);

SecureCellData protectedData = cell.protect(context, data);

assertNotNull(protectedData);
Expand Down