Skip to content

Commit 8c5556a

Browse files
author
Erika Perugachi
authored
Merge pull request #1217 from Hirobreak/alice-new
Criptext Encryption Service
2 parents a027231 + 1d77d02 commit 8c5556a

File tree

94 files changed

+7398
-530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+7398
-530
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
# dependencies
44
/node_modules
55
*/node_modules
6+
*_interface/deps
67

78
# testing
89
*/coverage
910
electron_app/src/__integrations__/**@criptext.com/
1011

1112
#dev
1213
electron_app/userData/
14+
electron_app/src/userData/
15+
valgrind-out.txt
1316

1417
# production
18+
*_interface/build
1519
email_*/build
1620
*/dist
1721
*/src/**/*.css
@@ -21,6 +25,7 @@ email_*/build
2125
electron_app/build/Certificates.p12
2226
electron_app/build/Criptext_Mail_Distribution.provisionprofile
2327
electron_app/dev-app-update.yml
28+
binding.gyp
2429

2530
# misc
2631
*/.env*
@@ -34,4 +39,4 @@ electron_app/dev-app-update.yml
3439
*/yarn-debug.log*
3540
*/yarn-error.log*
3641
*.db
37-
.vscode
42+
.vscode

db_interface/linux_setup.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!bin/bash
2+
tempBuildFolder='deps'
3+
4+
function PSM() {
5+
tput setaf 2;tput bold; echo "$1"; tput sgr0;
6+
}
7+
function PEM() {
8+
tput setaf 1;tput setab 7; echo "$1"; tput sgr0;
9+
}
10+
function removeTempFolder1() {
11+
cd ..; rm -rf "${tempBuildFolder}"; return;
12+
}
13+
function removeTempFolder2() {
14+
cd ../..; rm -rf "${tempBuildFolder}"; return;
15+
}
16+
17+
# Update repos list
18+
sudo apt-get update > /dev/null;
19+
if [ $? -ne 0 ]; then
20+
PEM " Failed to update repos list"
21+
fi
22+
printf "\n\n"
23+
24+
echo "-----------------------------------------"
25+
PSM " DB Interface";
26+
echo "-----------------------------------------"
27+
28+
printf " - Checking latest repos... \n";
29+
30+
31+
# Install deps
32+
printf " - Installing build dependencies... \n";
33+
INSTALL_DEPS_ERROR=$( { sudo apt-get install gcc cmake git pkg-config sqlite3 libsqlite3-dev -y > /dev/null; } 2>&1 )
34+
35+
if [ $? -ne 0 ]; then
36+
PEM " Failed to install deps"
37+
echo "Reason: "; PEM $INSTALL_DEPS_ERROR;
38+
return;
39+
fi
40+
41+
# Temp folder
42+
printf " - Preparing build... \n";
43+
mkdir "${tempBuildFolder}" > /dev/null;
44+
cd "${tempBuildFolder}" > /dev/null;
45+
46+
# Download && build SQLite
47+
printf " - Downloading SQLite Modern Cpp... \n";
48+
git clone https://github.com/SqliteModernCpp/sqlite_modern_cpp.git --quiet;
49+
if [ $? -ne 0 ]; then
50+
PEM " Failed to download SQLite Modern Cpp";
51+
removeTempFolder1;
52+
fi
53+
54+
printf " - Configurating... \n";
55+
cd ./sqlite_modern_cpp > /dev/null;
56+
./configure;
57+
58+
make > /dev/null;
59+
if [ $? -ne 0 ]; then
60+
PEM " Failed to make SQLite Modern Cpp";
61+
removeTempFolder2;
62+
fi
63+
64+
sudo make install > /dev/null;
65+
if [ $? -ne 0 ]; then
66+
PEM " Failed to install SQLite Modern Cpp";
67+
removeTempFolder2;
68+
fi
69+
70+
# Exit to tempBuildFolder's parent and remove
71+
removeTempFolder2;
72+
PSM " Done.";
73+
printf "\n"

db_interface/macos_setup.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!bin/bash
2+
if ! type "brew" > /dev/null; then
3+
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
4+
fi
5+
6+
brew install cmake > /dev/null;
7+
8+
tempBuildFolder='deps'
9+
10+
function PSM() {
11+
tput setaf 2;tput bold; echo "$1"; tput sgr0;
12+
}
13+
function PEM() {
14+
tput setaf 1;tput setab 7; echo "$1"; tput sgr0;
15+
}
16+
function removeTempFolder1() {
17+
cd ..; rm -rf "${tempBuildFolder}"; return;
18+
}
19+
function removeTempFolder2() {
20+
cd ../..; rm -rf "${tempBuildFolder}"; return;
21+
}
22+
23+
# Temp folder
24+
printf " - Preparing build... \n";
25+
mkdir "${tempBuildFolder}" > /dev/null;
26+
cd "${tempBuildFolder}" > /dev/null;
27+
28+
echo "-----------------------------------------"
29+
PSM " DB Interface";
30+
echo "-----------------------------------------"
31+
32+
# Download && build sqlite_modern_cpp
33+
printf " - Downloading sqlite_modern_cpp... \n";
34+
git clone https://github.com/SqliteModernCpp/sqlite_modern_cpp.git --quiet;
35+
if [ $? -ne 0 ]; then
36+
PEM " Failed to download sqlite_modern_cpp";
37+
removeTempFolder1;
38+
fi
39+
40+
printf " - Configuring and building sqlite_modern_cpp... \n";
41+
cd ./sqlite_modern_cpp > /dev/null;
42+
43+
./configure > /dev/null
44+
if [ $? -ne 0 ]; then
45+
PEM " Failed to configure sqlite_modern_cpp";
46+
removeTempFolder2;
47+
fi
48+
make > /dev/null
49+
if [ $? -ne 0 ]; then
50+
PEM " Failed to make sqlite_modern_cpp";
51+
removeTempFolder2;
52+
fi
53+
sudo make install > /dev/null
54+
if [ $? -ne 0 ]; then
55+
PEM " Failed to install sqlite_modern_cpp";
56+
removeTempFolder2;
57+
fi
58+
59+
# Exit to tempBuildFolder's parent and remove
60+
removeTempFolder2;
61+
PSM " Done.";
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include "Account.h"
2+
#include <iostream>
3+
4+
using namespace std;
5+
using namespace sqlite;
6+
7+
CriptextDB::Account CriptextDB::getAccount(string dbPath, char *recipientId) {
8+
sqlite_config config;
9+
config.flags = OpenFlags::FULLMUTEX | OpenFlags::SHAREDCACHE | OpenFlags::READONLY;
10+
database db(dbPath, config);
11+
12+
string myPrivKey;
13+
string myPubKey;
14+
int regId = 0;
15+
db << "select privKey, pubKey, registrationId from account where recipientId == ?;"
16+
<< recipientId
17+
>> [&] (string privKey, string pubKey, int registrationId) {
18+
myPrivKey = privKey;
19+
myPubKey = pubKey;
20+
regId = registrationId;
21+
};
22+
Account account = {
23+
.privKey = myPrivKey,
24+
.pubKey = myPubKey,
25+
.registrationId = regId
26+
};
27+
return account;
28+
}
29+
30+
int CriptextDB::createAccount(string dbPath, char* recipientId, char* name, int deviceId, char* pubKey, char* privKey, int registrationId) {
31+
try {
32+
bool hasRow = false;
33+
sqlite_config config;
34+
config.flags = OpenFlags::FULLMUTEX | OpenFlags::SHAREDCACHE | OpenFlags::READWRITE;
35+
database db(dbPath, config);
36+
db << "begin;";
37+
db << "Select recipientId from account where recipientId == ?;"
38+
<< recipientId
39+
>> [&] (string recipientId) {
40+
hasRow = true;
41+
};
42+
43+
if (hasRow) {
44+
db << "update account set name = ?, deviceId = ?, privKey = ?, pubKey = ?, registrationId = ? where recipientId == ?;"
45+
<< name
46+
<< deviceId
47+
<< privKey
48+
<< pubKey
49+
<< registrationId
50+
<< recipientId;
51+
} else {
52+
db << "insert into account (recipientId, name, deviceId, jwt, refreshToken, privKey, pubKey, registrationId) values (?,?,?,?,?,?,?,?);"
53+
<< recipientId
54+
<< name
55+
<< deviceId
56+
<< ""
57+
<< ""
58+
<< privKey
59+
<< pubKey
60+
<< registrationId;
61+
}
62+
db << "commit;";
63+
} catch (exception& e) {
64+
std::cout << "ERROR Creating Account : " << e.what() << std::endl;
65+
return false;
66+
}
67+
return true;
68+
}

db_interface/src/axolotl/Account.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef ACCOUNT_H_
2+
#define ACCOUNT_H_
3+
4+
#include <sqlite_modern_cpp.h>
5+
#include <cstring>
6+
#include <string>
7+
#include <memory>
8+
#include <vector>
9+
10+
using namespace std;
11+
12+
namespace CriptextDB {
13+
struct Account {
14+
string privKey;
15+
string pubKey;
16+
int registrationId;
17+
char* dbPath;
18+
};
19+
20+
Account getAccount(string dbPath, char* recipientId);
21+
int createAccount(string dbPath, char* recipientId, char* name, int deviceId, char* pubKey, char* privKey, int registrationId);
22+
}
23+
24+
#endif
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "IdentityKey.h"
2+
#include <string>
3+
#include <iostream>
4+
5+
using namespace sqlite;
6+
using namespace std;
7+
8+
CriptextDB::IdentityKey CriptextDB::getIdentityKey(string dbPath, string recipientId, long int deviceId) {
9+
sqlite_config config;
10+
config.flags = OpenFlags::FULLMUTEX | OpenFlags::SHAREDCACHE | OpenFlags::READONLY;
11+
database db(dbPath, config);
12+
13+
IdentityKey identityKey;
14+
db << "Select * from identitykeyrecord where recipientId == ? and deviceId == ?;"
15+
<< recipientId
16+
<< deviceId
17+
>> [&] (string recipientId, int deviceId, string identity) {
18+
identityKey = {
19+
.recipientId = recipientId,
20+
.deviceId = deviceId,
21+
.identityKey = identity
22+
};
23+
};
24+
25+
if (identityKey.deviceId == 0 || identityKey.identityKey.empty()) {
26+
throw std::invalid_argument("row not available");
27+
}
28+
return identityKey;
29+
}
30+
31+
bool CriptextDB::createIdentityKey(string dbPath, string recipientId, int deviceId, char *identityKey) {
32+
try {
33+
bool hasRow = false;
34+
sqlite_config config;
35+
config.flags = OpenFlags::FULLMUTEX | OpenFlags::SHAREDCACHE | OpenFlags::READWRITE;
36+
37+
database db(dbPath, config);
38+
db << "begin;";
39+
db << "Select * from identitykeyrecord where recipientId == ? and deviceId == ?;"
40+
<< recipientId
41+
<< deviceId
42+
>> [&] (string recipientId, int deviceId, string identity) {
43+
hasRow = true;
44+
};
45+
if (hasRow) {
46+
db << "update identitykeyrecord set identityKey = ? where recipientId == ? and deviceId == ?;"
47+
<< identityKey
48+
<< recipientId
49+
<< deviceId;
50+
} else {
51+
db << "insert into identitykeyrecord (recipientId, deviceId, identityKey) values (?,?,?);"
52+
<< recipientId
53+
<< deviceId
54+
<< identityKey;
55+
}
56+
db << "commit;";
57+
} catch (exception& e) {
58+
std::cout << "ERROR Creating Identity Key: " << e.what() << std::endl;
59+
return false;
60+
}
61+
return true;
62+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef IDENTITYKEY_H_
2+
#define IDENTITYKEY_H_
3+
4+
#include <sqlite_modern_cpp.h>
5+
#include <string>
6+
#include <cstring>
7+
8+
using namespace std;
9+
10+
namespace CriptextDB {
11+
12+
struct IdentityKey {
13+
string recipientId;
14+
long int deviceId;
15+
string identityKey;
16+
};
17+
18+
IdentityKey getIdentityKey(string dbPath, string recipientId, long int deviceId);
19+
bool createIdentityKey(string dbPath, string recipientId, int deviceId, char *identityKey);
20+
}
21+
22+
#endif

0 commit comments

Comments
 (0)