Skip to content

Commit e793cf0

Browse files
committed
alice begins
1 parent a027231 commit e793cf0

24 files changed

+2574
-0
lines changed

db_interface/CMakeList.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!bin/bash
2+
3+
apt-get update
4+
apt-get install gcc -y
5+
apt-get install cmake -y
6+
apt-get install git -y
7+
apt-get install pkg-config -y
8+
9+
mkdir deps && pushd deps
10+
11+
git clone https://github.com/SRombauts/SQLiteCpp
12+
pushd SQLiteCpp
13+
cmake -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON ..
14+
cmake --build .
15+
popd
16+
17+
popd && rm -rf deps
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <SQLiteCpp/SQLiteCpp.h>
2+
#include <string>
3+
#include <memory>
4+
#include <vector>
5+
6+
using namespace std;
7+
8+
namespace CriptextDB {
9+
10+
struct IdentityKey {
11+
string recipientId;
12+
long int deviceId;
13+
string identityKey;
14+
}
15+
16+
unique_ptr<IdentityKey> getIdentityKey(string dbPath, string recipientId, long int deviceId, int accountId) {
17+
try {
18+
SQLITE::Database db(dbPath);
19+
20+
SQLITE::Statement query(db, 'Select * from identitykeyrecord where recipientId == ? and deviceId == ? and accountId == ?')
21+
query.bind(1, recipientId);
22+
query.bind(2, deviceId)
23+
query.bind(3, accountId)
24+
25+
query.executeStep();
26+
} catch (exception& e) {
27+
return NULL;
28+
}
29+
30+
IdentityKey identityKey = { query.getColumn(1).c_str(), query.getColumn(2).getInt(), query.getColumn(3).c_str() }
31+
32+
return identityKey
33+
}
34+
35+
bool createIdentityKey(string dbPath, string recipientId, int deviceId, string identityKey, int accountId) {
36+
try {
37+
SQLITE::Database db(dbPath);
38+
39+
SQLITE::Statement query(db, 'insert into identitykeyrecord (recipientId, deviceId, identityKey, accountId) values (?,?,?,?)')
40+
query.bind(1, recipientId);
41+
query.bind(2, deviceId);
42+
query.bind(3, identityKey);
43+
query.bind(4, accountId);
44+
45+
query.exec();
46+
} catch (exception& e) {
47+
return false
48+
}
49+
50+
return true
51+
}
52+
53+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <SQLiteCpp/SQLiteCpp.h>
2+
#include <string>
3+
#include <memory>
4+
#include <vector>
5+
6+
using namespace std;
7+
8+
namespace CriptextDB {
9+
10+
struct PreKey {
11+
short int id;
12+
string privKey;
13+
string pubKey;
14+
}
15+
16+
unique_ptr<PreKey> getPreKey(string dbPath, short int id, int accountId) {
17+
try {
18+
SQLITE::Database db(dbPath);
19+
20+
SQLITE::Statement query(db, 'Select * from prekeyrecord where preKeyId == ? and accountId == ?')
21+
query.bind(1, id);
22+
query.bind(2, accountId)
23+
24+
query.executeStep();
25+
} catch (exception& e) {
26+
return NULL;
27+
}
28+
29+
PreKey preKey = { query.getColumn(1).getInt(), query.getColumn(2).getString(), query.getColumn(3).getString() }
30+
31+
return preKey
32+
}
33+
34+
bool createPreKey(string dbPath, short int id, string privKey, string pubKey, int accountId) {
35+
try {
36+
SQLITE::Database db(dbPath);
37+
38+
SQLITE::Statement query(db, 'insert into prekey (preKeyId, preKeyPrivKey, preKeyPubKey, accountId) values (?,?,?,?)')
39+
query.bind(1, id);
40+
query.bind(2, privKey);
41+
query.bind(3, pubKey);
42+
query.bind(4, accountId);
43+
44+
query.exec();
45+
} catch (exception& e) {
46+
return false
47+
}
48+
49+
return true
50+
}
51+
52+
bool deletePreKey(string dbPath, short int id, int accountId) {
53+
try {
54+
SQLITE::Database db(dbPath);
55+
56+
SQLITE::Statement query(db, 'delete from prekeyrecord where preKeyId == ? and accountId == ?')
57+
query.bind(1, id);
58+
query.bind(2, accountId);
59+
60+
query.exec();
61+
} catch (exception& e) {
62+
return false
63+
}
64+
65+
return true
66+
}
67+
68+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#include <SQLiteCpp/SQLiteCpp.h>
2+
#include <string>
3+
#include <memory>
4+
#include <vector>
5+
6+
using namespace std;
7+
8+
namespace CriptextDB {
9+
10+
struct SessionRecord {
11+
string recipientId;
12+
long int deviceId;
13+
string record;
14+
}
15+
16+
unique_ptr<SessionRecord> getSessionRecord(string dbPath, int accountId, string recipientId, long int deviceId) {
17+
try {
18+
SQLITE::Database db(dbPath);
19+
20+
SQLITE::Statement query(db, 'Select * from sessionrecord where recipientId == ? and deviceId == ? and accountId == ?')
21+
query.bind(1, recipientId);
22+
query.bind(2, deviceId);
23+
query.bind(3, accountId)
24+
25+
query.executeStep();
26+
} catch (exception& e) {
27+
return NULL;
28+
}
29+
30+
SessionRecord sessionRecord = { query.getColumn(0).getString(), query.getColumn(1).getInt(), query.getColumn(2).getString() }
31+
32+
return sessionRecord
33+
}
34+
35+
vector<unique_ptr<SessionRecord>> getSessionRecords(string dbPath, int accountId, string recipientId) {
36+
37+
vector<unique_ptr<SessionRecord>> sessionRecords;
38+
39+
try {
40+
SQLITE::Database db(dbPath);
41+
42+
SQLITE::Statement query(db, 'Select * from sessionrecord where recipientId == ? and accountId == ?')
43+
query.bind(1, recipientId);
44+
query.bind(2, accountId)
45+
46+
while (query.executeStep()) {
47+
SessionRecord sessionRecord = { query.getColumn(0).getString(), query.getColumn(1).getInt(), query.getColumn(2).getString() }
48+
sessionRecords.push_back(sessionRecord)
49+
}
50+
} catch (exception& e) {
51+
return NULL;
52+
}
53+
54+
return sessionRecords
55+
}
56+
57+
bool createSessionRecord(string dbPath, int accountId, string recipientId, long int deviceId, string record) {
58+
try {
59+
SQLITE::Database db(dbPath);
60+
61+
SQLITE::Statement query(db, 'insert into sessionrecord (recipientId, deviceId, record, accountId) values (?,?,?,?)')
62+
query.bind(1, recipientId);
63+
query.bind(2, deviceId);
64+
query.bind(3, accountId);
65+
query.bind(4, record);
66+
67+
query.exec();
68+
} catch (exception& e) {
69+
return false
70+
}
71+
72+
return true
73+
}
74+
75+
bool deleteSessionRecord(string dbPath, int accountId, string recipientId, long int deviceId, string record) {
76+
try {
77+
SQLITE::Database db(dbPath);
78+
79+
SQLITE::Statement query(db, 'delete from sessionrecord where recipientId == ? and deviceId == ? and accountId == ?')
80+
query.bind(1, recipientId);
81+
query.bind(2, deviceId);
82+
query.bind(3, accountId);
83+
84+
query.exec();
85+
} catch (exception& e) {
86+
return false
87+
}
88+
89+
return true
90+
}
91+
92+
bool deleteSessionRecords(string dbPath, int accountId, string recipientId, string record) {
93+
try {
94+
SQLITE::Database db(dbPath);
95+
96+
SQLITE::Statement query(db, 'delete from sessionrecord where recipientId == ? and accountId == ?')
97+
query.bind(1, recipientId);
98+
query.bind(2, accountId);
99+
100+
query.exec();
101+
} catch (exception& e) {
102+
return false
103+
}
104+
105+
return true
106+
}
107+
108+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <SQLiteCpp/SQLiteCpp.h>
2+
#include <string>
3+
#include <memory>
4+
#include <vector>
5+
6+
using namespace std;
7+
8+
namespace CriptextDB {
9+
10+
struct SignedPreKey {
11+
short int id;
12+
string privKey;
13+
string pubKey;
14+
}
15+
16+
unique_ptr<SignedPreKey> getSignedPreKey(string dbPath, short int id, int accountId) {
17+
try {
18+
SQLITE::Database db(dbPath);
19+
20+
SQLITE::Statement query(db, 'Select * from signedprekeyrecord where signedPreKeyId == ? and accountId == ?')
21+
query.bind(1, id);
22+
query.bind(2, accountId)
23+
24+
query.executeStep();
25+
} catch (exception& e) {
26+
return NULL;
27+
}
28+
29+
SignedPreKey signedPreKey = { query.getColumn(1).getInt(), query.getColumn(2).c_str(), query.getColumn(3).c_str() }
30+
31+
return signedPreKey
32+
}
33+
34+
bool createSignedPreKey(string dbPath, short int id, string privKey, string pubKey, int accountId) {
35+
try {
36+
SQLITE::Database db(dbPath);
37+
38+
SQLITE::Statement query(db, 'insert into signedprekey (signedPreKeyId, signedPreKeyPrivKey, signedPreKeyPubKey, accountId) values (?,?,?,?)')
39+
query.bind(1, id);
40+
query.bind(2, privKey);
41+
query.bind(3, pubKey);
42+
query.bind(4, accountId);
43+
44+
query.exec();
45+
} catch (exception& e) {
46+
return false
47+
}
48+
49+
return true
50+
}
51+
52+
bool deletePreKey(string dbPath, short int id, int accountId) {
53+
try {
54+
SQLITE::Database db(dbPath);
55+
56+
SQLITE::Statement query(db, 'delete from signedPrekeyrecord where signedPreKeyId == ? and accountId == ?')
57+
query.bind(1, id);
58+
query.bind(2, accountId);
59+
60+
query.exec();
61+
} catch (exception& e) {
62+
return false
63+
}
64+
65+
return true
66+
}
67+
68+
}

db_interface/src/main.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <SQLiteCpp/SQLiteCpp.h>
2+
#include <string>
3+
#include <memory>
4+
#include <vector>
5+
6+
using namespace std;
7+
8+
namespace CriptextDB {
9+
struct Account {
10+
int id;
11+
string privKey;
12+
string pubKey;
13+
int registrationId;
14+
}
15+
16+
unique_ptr<Account> getAccount(int accountId) {
17+
try {
18+
SQLITE::Database db(dbPath);
19+
20+
SQLITE::Statement query(db, 'select * from account where accountId == ?')
21+
query.bind(1, accountId);
22+
23+
query.executeStep();
24+
} catch (exception& e) {
25+
return NULL;
26+
}
27+
28+
Account account = { query.getColumn(1).getInt(), query.getColumn(8).getString(), query.getColumn(9).getString(), query.getColumn(10).getInt() }
29+
30+
return account
31+
}
32+
}

signal_interface/Criptext_Decrypto.h

Whitespace-only changes.

0 commit comments

Comments
 (0)