mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Compare commits
709 Commits
725-result
...
network-lo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f25b16e680 | ||
|
|
467fdb6468 | ||
|
|
c0840dc332 | ||
|
|
235183a3af | ||
|
|
701e51dfc8 | ||
|
|
3361922834 | ||
|
|
fcabf697d6 | ||
|
|
4d502576c9 | ||
|
|
5fe68e6f82 | ||
|
|
f725c7ab9a | ||
|
|
03b4907311 | ||
|
|
809b9f8919 | ||
|
|
85cc23444c | ||
|
|
c073c5c8bd | ||
|
|
976c8a9578 | ||
|
|
d52ca14ebe | ||
|
|
a178dbae9e | ||
|
|
9a4f0b8e89 | ||
|
|
db7dbfce68 | ||
|
|
80770b0216 | ||
|
|
9f02bbbba1 | ||
|
|
190aeef34e | ||
|
|
6fbaae0e5e | ||
|
|
5cc0f08b8f | ||
|
|
976460e0b7 | ||
|
|
9cdd537600 | ||
|
|
c44a3d01b9 | ||
|
|
a8ed86575d | ||
|
|
46406d8d1a | ||
|
|
05210257a0 | ||
|
|
d5c89640c1 | ||
|
|
3f1fb1ca1c | ||
|
|
bfdc79ac60 | ||
|
|
06897569d4 | ||
|
|
66e3f6deba | ||
|
|
528a52d0f7 | ||
|
|
d395f0866a | ||
|
|
363dfbc6aa | ||
|
|
c6f2941e74 | ||
|
|
a61cd01336 | ||
|
|
10f63ad60b | ||
|
|
0b781cf272 | ||
|
|
6dc7277771 | ||
|
|
d880b14e0c | ||
|
|
f88c68eff4 | ||
|
|
5fce8cbe0a | ||
|
|
439654e71d | ||
|
|
7fe502e3cc | ||
|
|
aa07d0cadd | ||
|
|
d9cca3d9eb | ||
|
|
94c5f61cc3 | ||
|
|
9cce0d8e15 | ||
|
|
44488b5187 | ||
|
|
4d6ac13338 | ||
|
|
ef3afa7832 | ||
|
|
687ea132f6 | ||
|
|
452e544ed1 | ||
|
|
6b60509122 | ||
|
|
e01e971822 | ||
|
|
186a7db8cb | ||
|
|
565452f7d3 | ||
|
|
de7e3dd225 | ||
|
|
8bdf04a289 | ||
|
|
56a5b8df87 | ||
|
|
ad241a14e3 | ||
|
|
2a7bdcd270 | ||
|
|
88c61ecfb5 | ||
|
|
bee9dbb9c4 | ||
|
|
36e0f97d82 | ||
|
|
8bb08a2af9 | ||
|
|
6bf2cb69c5 | ||
|
|
7a1247e325 | ||
|
|
ce5879bdb5 | ||
|
|
55221a5066 | ||
|
|
9e7f1df8e9 | ||
|
|
ec7e599143 | ||
|
|
e0a67d1eb9 | ||
|
|
a50ded2d50 | ||
|
|
dab9a3e73d | ||
|
|
dae8e6d759 | ||
|
|
60d38b034d | ||
|
|
863c908267 | ||
|
|
753068288f | ||
|
|
f9eda0b096 | ||
|
|
f4401ee524 | ||
|
|
3dbc3cef56 | ||
|
|
bf4ecd21aa | ||
|
|
ea3ada5573 | ||
|
|
9889f86f69 | ||
|
|
4d62447a86 | ||
|
|
7ec05ac0cd | ||
|
|
1b2a1d658d | ||
|
|
a2bbc5e455 | ||
|
|
006cb067ad | ||
|
|
a2e422a23e | ||
|
|
02cec9bacb | ||
|
|
fcd9b20161 | ||
|
|
204711e5db | ||
|
|
64c129d399 | ||
|
|
6bdb099aa9 | ||
|
|
3e55be8a82 | ||
|
|
8f37957a46 | ||
|
|
a5386e0183 | ||
|
|
117e88bf1f | ||
|
|
f47900c4d3 | ||
|
|
f641e16512 | ||
|
|
df0613f290 | ||
|
|
711475d45a | ||
|
|
3fd47fc1c7 | ||
|
|
a1a946edea | ||
|
|
699b037a3e | ||
|
|
e474042af7 | ||
|
|
68634e0f28 | ||
|
|
1d81110fe5 | ||
|
|
030b9ef053 | ||
|
|
7d8d169b0a | ||
|
|
11e2d4ecfb | ||
|
|
80ad5d8c7b | ||
|
|
53a15c05aa | ||
|
|
45bc6a51b0 | ||
|
|
db21dcedb1 | ||
|
|
96c8274091 | ||
|
|
0c7c465ef7 | ||
|
|
fd6bf42ea4 | ||
|
|
0c5976b287 | ||
|
|
1a4aa7f065 | ||
|
|
f11a97631f | ||
|
|
bf953012af | ||
|
|
2f049fbead | ||
|
|
49a6f2af3a | ||
|
|
3d6c02c27c | ||
|
|
a1cfc0ec1d | ||
|
|
2f584501fe | ||
|
|
b524cec6af | ||
|
|
0a7b810fce | ||
|
|
f7a3b0f6ca | ||
|
|
b095dab77a | ||
|
|
b6b7ab622d | ||
|
|
55e674624a | ||
|
|
88a799df45 | ||
|
|
4bb726ac9a | ||
|
|
5a53665e96 | ||
|
|
cf51a1e299 | ||
|
|
04802cc8cd | ||
|
|
d0c1be0c32 | ||
|
|
0b9894a0f6 | ||
|
|
1a912a29f8 | ||
|
|
596c140310 | ||
|
|
302ced1476 | ||
|
|
3178c16bac | ||
|
|
341d18656d | ||
|
|
074755c0a8 | ||
|
|
5d528fce74 | ||
|
|
c80edc99b2 | ||
|
|
33378d9920 | ||
|
|
85a6e394b9 | ||
|
|
f2f98f28a3 | ||
|
|
d92e042971 | ||
|
|
6d6e47409f | ||
|
|
0084e51263 | ||
|
|
32e0b39771 | ||
|
|
7bb51f77ec | ||
|
|
c777a57a7d | ||
|
|
def5966767 | ||
|
|
14b18e9d42 | ||
|
|
fcff8d92f3 | ||
|
|
ea0e00f4ac | ||
|
|
f199105f6c | ||
|
|
b23c0b599b | ||
|
|
0327d4f38a | ||
|
|
4397a45519 | ||
|
|
365e159539 | ||
|
|
8171dd8bc9 | ||
|
|
c4beb60c22 | ||
|
|
4b88f0d9f1 | ||
|
|
116419f505 | ||
|
|
87b2624aa8 | ||
|
|
71fe6f3148 | ||
|
|
21df6cb809 | ||
|
|
1f0c385a5c | ||
|
|
986ea05fb2 | ||
|
|
90e395506f | ||
|
|
cf54360a93 | ||
|
|
a5d4ea4477 | ||
|
|
030b52261d | ||
|
|
a50e13c2e3 | ||
|
|
c8326103b4 | ||
|
|
0f2beee813 | ||
|
|
d2348a4e7d | ||
|
|
cc87e6fd1f | ||
|
|
1843aea2a7 | ||
|
|
9f7021acd3 | ||
|
|
ddea031cbf | ||
|
|
f0d8532f71 | ||
|
|
4883d157dc | ||
|
|
a1bec1e927 | ||
|
|
48918f4727 | ||
|
|
303b5bd395 | ||
|
|
37d4d79c64 | ||
|
|
05bc3f6a71 | ||
|
|
8b3960781a | ||
|
|
97733a52c8 | ||
|
|
89dcbec599 | ||
|
|
6497809fe1 | ||
|
|
f3de4f53c5 | ||
|
|
166fc2948c | ||
|
|
9f3a63d8c4 | ||
|
|
748fa77d94 | ||
|
|
4ca86ee4eb | ||
|
|
ec2f372933 | ||
|
|
4267800db2 | ||
|
|
bb8cb9bcbb | ||
|
|
d5b9e15ee1 | ||
|
|
43ee3246f6 | ||
|
|
b56724dee5 | ||
|
|
92748ac872 | ||
|
|
b89686c287 | ||
|
|
a34692630b | ||
|
|
735208562a | ||
|
|
49826fdc56 | ||
|
|
e8c54a609c | ||
|
|
ece2c51358 | ||
|
|
3ec8af4661 | ||
|
|
77a08596fe | ||
|
|
879f699b2b | ||
|
|
d7383a3361 | ||
|
|
a5b321a93b | ||
|
|
5fa6b0ca1c | ||
|
|
27328afe3c | ||
|
|
2d26af1ae2 | ||
|
|
6db8f33e8f | ||
|
|
d6a7e6d52c | ||
|
|
df99b3b666 | ||
|
|
0f1c9f4fe2 | ||
|
|
5dcd5f79dc | ||
|
|
8a81171739 | ||
|
|
1c4f20f76f | ||
|
|
f84fa588f6 | ||
|
|
e30e34f342 | ||
|
|
fc93ced067 | ||
|
|
bb7df72d31 | ||
|
|
f8425658e4 | ||
|
|
53c8cf09b6 | ||
|
|
9f29bf4949 | ||
|
|
98e2adf794 | ||
|
|
2a43e0b0ed | ||
|
|
773ae73820 | ||
|
|
009db57bc5 | ||
|
|
5e98126e77 | ||
|
|
bd7ebfd83a | ||
|
|
10f41ef157 | ||
|
|
1dd4960109 | ||
|
|
75413b6c86 | ||
|
|
b2180582a7 | ||
|
|
8211ce7ae3 | ||
|
|
e6b1597fa7 | ||
|
|
8937d3cd9c | ||
|
|
51f320d147 | ||
|
|
e402a894bb | ||
|
|
9b577f1219 | ||
|
|
220f678403 | ||
|
|
4173fc4daa | ||
|
|
c6756d2145 | ||
|
|
6731f6eeb5 | ||
|
|
6f7f8b40e3 | ||
|
|
1a83b2c99b | ||
|
|
f641fae1c7 | ||
|
|
deb43d9872 | ||
|
|
cee4e1305e | ||
|
|
a1f989c43c | ||
|
|
b67abadbac | ||
|
|
8c29c85696 | ||
|
|
4fe4c298d7 | ||
|
|
13d35229d5 | ||
|
|
f0137b41b6 | ||
|
|
b221d21903 | ||
|
|
8bac202626 | ||
|
|
973151c949 | ||
|
|
ed26ab78a5 | ||
|
|
8454b2d235 | ||
|
|
91d0f89f60 | ||
|
|
e074672e86 | ||
|
|
6c1901fe5b | ||
|
|
49052be627 | ||
|
|
5b5b540630 | ||
|
|
9993bac3a1 | ||
|
|
3c95988693 | ||
|
|
fc5c3b470e | ||
|
|
53f05a72ba | ||
|
|
2c10ae7d06 | ||
|
|
6b9010c557 | ||
|
|
1bf0fdfa81 | ||
|
|
237759aac0 | ||
|
|
2a141e0a97 | ||
|
|
d6900be68e | ||
|
|
a35d7c7204 | ||
|
|
86287f9241 | ||
|
|
0b2e3dd96f | ||
|
|
90aa1d1ce7 | ||
|
|
ef2286ab53 | ||
|
|
47b25f3221 | ||
|
|
c30bfa12ce | ||
|
|
d0fc04251d | ||
|
|
dcbb41eb7a | ||
|
|
5c51259269 | ||
|
|
7eefa07052 | ||
|
|
999bdf8866 | ||
|
|
911c0c0fd9 | ||
|
|
99d8cc64a6 | ||
|
|
ba727d7568 | ||
|
|
ed01048f9f | ||
|
|
043ee3c58e | ||
|
|
6e0af7deda | ||
|
|
9591db2097 | ||
|
|
329a4c64f6 | ||
|
|
79015bc5ae | ||
|
|
27422ab9f9 | ||
|
|
abcb682498 | ||
|
|
5044127c46 | ||
|
|
0e4b8ca62e | ||
|
|
822017c69c | ||
|
|
eb6561b93d | ||
|
|
eb9d0c00a8 | ||
|
|
d24b1884a2 | ||
|
|
078534889e | ||
|
|
e92713006a | ||
|
|
18f43f3bc1 | ||
|
|
a4118b40e1 | ||
|
|
de29fbc324 | ||
|
|
3197dcf9b5 | ||
|
|
35aad409fd | ||
|
|
08ce6a7331 | ||
|
|
33a0099065 | ||
|
|
34d20fafda | ||
|
|
aafddcd0f0 | ||
|
|
0d6983b4ef | ||
|
|
69bfb72171 | ||
|
|
1aa33ec9b2 | ||
|
|
6702df1e22 | ||
|
|
c1748c9a86 | ||
|
|
9df624c62a | ||
|
|
0ee6197d7f | ||
|
|
b03a7dce3e | ||
|
|
6c59d7dd5f | ||
|
|
050191f0ef | ||
|
|
4b5a19ce5d | ||
|
|
7c4dd991b9 | ||
|
|
8455569e88 | ||
|
|
d25676559c | ||
|
|
a9437f7985 | ||
|
|
8141a97fc9 | ||
|
|
db842bd7e4 | ||
|
|
6dbec3a864 | ||
|
|
29f658cf4d | ||
|
|
ca83744a84 | ||
|
|
d91a9e2be4 | ||
|
|
8408c3f467 | ||
|
|
544c83a64c | ||
|
|
3800cd5e4f | ||
|
|
259f2cd419 | ||
|
|
20eb022c36 | ||
|
|
531e555b52 | ||
|
|
a9024aa34b | ||
|
|
d4e3b7842c | ||
|
|
167fddfbcc | ||
|
|
a48d642648 | ||
|
|
9a70f054c7 | ||
|
|
ca43d13bd6 | ||
|
|
5b71004179 | ||
|
|
63befccdbf | ||
|
|
4ecf7c02d0 | ||
|
|
f25badc18c | ||
|
|
6e931e9ba5 | ||
|
|
7e749124bf | ||
|
|
5822eb7808 | ||
|
|
7a7e086541 | ||
|
|
abab3167c2 | ||
|
|
8d08570568 | ||
|
|
2007078f13 | ||
|
|
dfb71a7978 | ||
|
|
480b0e3a03 | ||
|
|
8f8751f4ac | ||
|
|
de2ea112ee | ||
|
|
6f99a53fd9 | ||
|
|
a8a9b9032d | ||
|
|
6b15fb89de | ||
|
|
a711d6b8a1 | ||
|
|
5678f8aaa4 | ||
|
|
2fe37f6c26 | ||
|
|
a879747968 | ||
|
|
95e8fd7ee0 | ||
|
|
4416aaaa4c | ||
|
|
500d5f0efe | ||
|
|
fc8978fd90 | ||
|
|
73df126bd4 | ||
|
|
9146488c7d | ||
|
|
613a7fe376 | ||
|
|
ecb62f00d4 | ||
|
|
c4540a03cd | ||
|
|
3e31da99b5 | ||
|
|
098c1d0b1e | ||
|
|
178e908c86 | ||
|
|
ecf7cf14ae | ||
|
|
09e2a15a73 | ||
|
|
ab387860a6 | ||
|
|
f63fc94f2b | ||
|
|
41e5928cca | ||
|
|
8303175494 | ||
|
|
151eb6935b | ||
|
|
6a419c0c7b | ||
|
|
1795b32121 | ||
|
|
01971768ce | ||
|
|
ef7483ab01 | ||
|
|
527d11473d | ||
|
|
775dadc9a0 | ||
|
|
800b10a988 | ||
|
|
c977bf047d | ||
|
|
660a25f21d | ||
|
|
e7fd6d23af | ||
|
|
46982897f0 | ||
|
|
d24de68d64 | ||
|
|
7514c46a3f | ||
|
|
6632c0f8e3 | ||
|
|
79aafcda69 | ||
|
|
05af21e8dc | ||
|
|
0dc62cbbdc | ||
|
|
f3a084cfd2 | ||
|
|
8b32f82566 | ||
|
|
d598b6ed44 | ||
|
|
f5dc6f24b9 | ||
|
|
37454392da | ||
|
|
de7f9111d3 | ||
|
|
96d2889a6c | ||
|
|
f6412d1e9a | ||
|
|
b377cd6b1c | ||
|
|
f6cdbda5bb | ||
|
|
855c600a3e | ||
|
|
ea6e8303b0 | ||
|
|
d4934040d9 | ||
|
|
3449677b24 | ||
|
|
1ad3a6646e | ||
|
|
2d10f6b2bd | ||
|
|
5b05424d83 | ||
|
|
0826022d82 | ||
|
|
a901bfb9cb | ||
|
|
03cdce122a | ||
|
|
f2e0e16969 | ||
|
|
0c441e2ff3 | ||
|
|
21302304a5 | ||
|
|
6839d8b844 | ||
|
|
aee65a716c | ||
|
|
6a07d8f2c9 | ||
|
|
3c1ea81cd0 | ||
|
|
025f417bc7 | ||
|
|
c9dcd906c9 | ||
|
|
7024e04d15 | ||
|
|
0b8ac947db | ||
|
|
948410a064 | ||
|
|
2841339cac | ||
|
|
e8e82bd805 | ||
|
|
6876f40a0e | ||
|
|
5f4e1ecdfd | ||
|
|
044719432a | ||
|
|
d1a929da85 | ||
|
|
2a8978a60d | ||
|
|
c0afad7a26 | ||
|
|
37281c6c23 | ||
|
|
6de539a62d | ||
|
|
34704ec04d | ||
|
|
9fd6d46583 | ||
|
|
76a5e25656 | ||
|
|
3575b74837 | ||
|
|
f1c7996960 | ||
|
|
920f3581fa | ||
|
|
45e7af31fe | ||
|
|
67d5d8cdf1 | ||
|
|
9d8cadb7a9 | ||
|
|
6425c49d04 | ||
|
|
68d98b50f2 | ||
|
|
84986d393f | ||
|
|
115d488bc3 | ||
|
|
2eeb2213e3 | ||
|
|
1b48d661e8 | ||
|
|
49ba66dee9 | ||
|
|
46920f3bce | ||
|
|
4b955809f7 | ||
|
|
57d4d6546a | ||
|
|
9bfb58a764 | ||
|
|
0256ec0b8c | ||
|
|
b0b4a85d15 | ||
|
|
d40a058ef5 | ||
|
|
58b9efb24c | ||
|
|
17de785c12 | ||
|
|
c7ff1ba974 | ||
|
|
d17669f131 | ||
|
|
9755cd9ab4 | ||
|
|
6d2b18facc | ||
|
|
f8cf7034db | ||
|
|
a1e65c9fa7 | ||
|
|
499d2fe677 | ||
|
|
fe963edd9d | ||
|
|
96f006068f | ||
|
|
74f1fa5690 | ||
|
|
85c17b4cb0 | ||
|
|
6b3a1fd6d4 | ||
|
|
bcabcfce8c | ||
|
|
db0a3bf380 | ||
|
|
d5d9436e28 | ||
|
|
0827b067ec | ||
|
|
9d0dbe9210 | ||
|
|
1f7d1bf515 | ||
|
|
fb85ecf07b | ||
|
|
a931e6b316 | ||
|
|
3aa4644339 | ||
|
|
9a638c804a | ||
|
|
df3254c634 | ||
|
|
ba353b9f2b | ||
|
|
04c4e70dd1 | ||
|
|
d381e25e86 | ||
|
|
0c085f139a | ||
|
|
4123f4a5ce | ||
|
|
7bc269fda4 | ||
|
|
a22931bae6 | ||
|
|
403f886110 | ||
|
|
b7866be38d | ||
|
|
a1b415330e | ||
|
|
58318bb79f | ||
|
|
10bb30e190 | ||
|
|
199a2ffc46 | ||
|
|
f6ad2992f2 | ||
|
|
f039bd1239 | ||
|
|
da22d91ef3 | ||
|
|
cd360ec877 | ||
|
|
8e1ada4cdc | ||
|
|
ac063b4c79 | ||
|
|
10e6163e94 | ||
|
|
ebc3402307 | ||
|
|
d9c63bbcfe | ||
|
|
9c89e83c20 | ||
|
|
adc9bdeb68 | ||
|
|
ff7f0bdc63 | ||
|
|
c5f6980c69 | ||
|
|
2574354997 | ||
|
|
c4e42949cf | ||
|
|
1c5897f1cc | ||
|
|
510f99c7da | ||
|
|
1918346ae8 | ||
|
|
2a59515c72 | ||
|
|
7161152b41 | ||
|
|
b42660edab | ||
|
|
b405bbf98e | ||
|
|
c167938b61 | ||
|
|
24b531e6b2 | ||
|
|
9cffff715a | ||
|
|
804e912e19 | ||
|
|
d67e3900e3 | ||
|
|
e682f31898 | ||
|
|
a9053808b4 | ||
|
|
d9a62a0431 | ||
|
|
15ba73276d | ||
|
|
720dda784e | ||
|
|
0ae55404f5 | ||
|
|
9c41437870 | ||
|
|
da9cde083f | ||
|
|
ce3156c9fe | ||
|
|
be3752bf2f | ||
|
|
ef74db65aa | ||
|
|
867a233b6f | ||
|
|
36f02b36d9 | ||
|
|
59af25b2cd | ||
|
|
2fb11fba2a | ||
|
|
1d11857e75 | ||
|
|
04508a7431 | ||
|
|
5653c6d650 | ||
|
|
ab100ad19b | ||
|
|
c13eafef14 | ||
|
|
d5443e9651 | ||
|
|
d5f9a3280d | ||
|
|
09b2ecaecf | ||
|
|
dc6a6f27ab | ||
|
|
8d9ddeeeee | ||
|
|
baed2b8483 | ||
|
|
b3d3230549 | ||
|
|
deb8787668 | ||
|
|
7034ea28f3 | ||
|
|
51b78cf9b1 | ||
|
|
b4c669243b | ||
|
|
694e662028 | ||
|
|
409e0fb5a5 | ||
|
|
279f4d668a | ||
|
|
d2608e28ac | ||
|
|
8cf02c5f0e | ||
|
|
c5df2100da | ||
|
|
a6999a8197 | ||
|
|
da89f11419 | ||
|
|
a9663875f4 | ||
|
|
804966ede6 | ||
|
|
f0f22b42e5 | ||
|
|
59316ae3c4 | ||
|
|
79c78518fb | ||
|
|
460b524e4b | ||
|
|
48e949c9f8 | ||
|
|
924398c829 | ||
|
|
8619b044ce | ||
|
|
3c3731a562 | ||
|
|
b54984b542 | ||
|
|
2390f767f5 | ||
|
|
0a9840997f | ||
|
|
6a94785d9a | ||
|
|
79fc41477c | ||
|
|
efb89adf41 | ||
|
|
c04580e321 | ||
|
|
2ef9b8f4b6 | ||
|
|
d63d15329c | ||
|
|
5345db0b6b | ||
|
|
501980d8fe | ||
|
|
cc5c000278 | ||
|
|
3ce0131b8c | ||
|
|
008e4f760a | ||
|
|
fc44268b22 | ||
|
|
de0a7c75ed | ||
|
|
1c6be2fb78 | ||
|
|
09b0a8b161 | ||
|
|
a6d053a0ea | ||
|
|
e7a26c42a4 | ||
|
|
bb5fc35e17 | ||
|
|
ea4e2f09c8 | ||
|
|
ffc9fdbb92 | ||
|
|
074f5c2faf | ||
|
|
7666b210e4 | ||
|
|
ab3fcb6219 | ||
|
|
b7e35ff780 | ||
|
|
3c2428449d | ||
|
|
25a4caec2a | ||
|
|
db71472501 | ||
|
|
1081a08ea9 | ||
|
|
32be148c7a | ||
|
|
78000375df | ||
|
|
66f8978bb6 | ||
|
|
45b5040254 | ||
|
|
378a8f0a10 | ||
|
|
562866494b | ||
|
|
c9cb085a0a | ||
|
|
97d4c68f43 | ||
|
|
4226ba40c2 | ||
|
|
3df3d19a07 | ||
|
|
e3dcc62509 | ||
|
|
db3c3eee44 | ||
|
|
5a522d64df | ||
|
|
68b216d580 | ||
|
|
d5c6fcc85b | ||
|
|
a099104d08 | ||
|
|
787b3399f7 | ||
|
|
4e159bbb1f | ||
|
|
7c6232db9d | ||
|
|
6cf1480d2d | ||
|
|
2679e6932f | ||
|
|
17e149e517 | ||
|
|
d04dda1566 | ||
|
|
5588855667 | ||
|
|
7df6abbcbe | ||
|
|
001f5faeaa | ||
|
|
ba1a19d236 | ||
|
|
b7ce7de42a | ||
|
|
3f6a8f9341 | ||
|
|
9495163016 | ||
|
|
7f5a5d40dc | ||
|
|
98dd8ec7f7 | ||
|
|
27c2ee8d89 | ||
|
|
b98ab93e77 | ||
|
|
81337fe7ad | ||
|
|
cdd234dfe3 | ||
|
|
062ed4ef4b | ||
|
|
9c22ea8434 | ||
|
|
9458b185f8 | ||
|
|
c2b06536ad | ||
|
|
878b52ef2c | ||
|
|
a9ddb0019e | ||
|
|
2d7cb7b279 | ||
|
|
f25d33b0c8 | ||
|
|
906dd1bd06 | ||
|
|
ad6016d428 | ||
|
|
f6d23b4d1a | ||
|
|
aa064e853a | ||
|
|
8a139eaf5d | ||
|
|
d51f73151f | ||
|
|
6c90204c6e | ||
|
|
f8266d8a02 | ||
|
|
f245b04726 | ||
|
|
67d9f3a7c2 | ||
|
|
24d68c4f5b | ||
|
|
edbd7f4eeb | ||
|
|
2f7830e73f | ||
|
|
a82fdca3d4 | ||
|
|
050111a994 | ||
|
|
a22d1d811f | ||
|
|
90124e00ca | ||
|
|
04323856de | ||
|
|
cfcd36f21a | ||
|
|
2b9ccb4c42 | ||
|
|
6436e6688d | ||
|
|
8c7a532e2e | ||
|
|
47171f3e18 | ||
|
|
b37a7531ca | ||
|
|
2850763ec6 | ||
|
|
e69139bc24 | ||
|
|
b0b932a01c | ||
|
|
2837bde774 | ||
|
|
411549dc0a |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -9,15 +9,18 @@ Thumbs.db
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
# Eclipse project files
|
# Eclipse project files
|
||||||
#.classpath
|
.classpath
|
||||||
#.project
|
.project
|
||||||
|
.settings
|
||||||
|
|
||||||
# Local configuration file (sdk path, etc)
|
# Local configuration file (sdk path, etc)
|
||||||
local.properties
|
local.properties
|
||||||
|
|
||||||
# Android Studio
|
# Android Studio
|
||||||
.idea/*
|
.idea/*
|
||||||
|
!.idea/runConfigurations/
|
||||||
!.idea/codeStyleSettings.xml
|
!.idea/codeStyleSettings.xml
|
||||||
.gradle
|
.gradle
|
||||||
build/
|
build/
|
||||||
*.iml
|
*.iml
|
||||||
|
projectFilesBackup/
|
||||||
29
.gitlab-ci.yml
Normal file
29
.gitlab-ci.yml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
image: registry.gitlab.com/fdroid/ci-images-base:latest
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .gradle/wrapper
|
||||||
|
- .gradle/caches
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- set -e
|
||||||
|
- export GRADLE_USER_HOME=$PWD/.gradle
|
||||||
|
# Accept the license for the Android build tools
|
||||||
|
- echo y | /opt/android-sdk/tools/bin/sdkmanager "build-tools;26.0.2"
|
||||||
|
# Download OpenJDK 6 so we can compile against its standard library
|
||||||
|
- JDK_FILE=openjdk-6-jre-headless_6b38-1.13.10-1~deb7u1_amd64.deb
|
||||||
|
- if [ ! -d openjdk ]
|
||||||
|
- then
|
||||||
|
- wget -q http://ftp.uk.debian.org/debian/pool/main/o/openjdk-6/$JDK_FILE
|
||||||
|
- dpkg-deb -x $JDK_FILE openjdk
|
||||||
|
- fi
|
||||||
|
- export JAVA_6_HOME=$PWD/openjdk/usr/lib/jvm/java-6-openjdk-amd64
|
||||||
|
|
||||||
|
test:
|
||||||
|
script:
|
||||||
|
- ./gradlew test
|
||||||
|
|
||||||
|
after_script:
|
||||||
|
# this file changes every time but should not be cached
|
||||||
|
- rm -f $GRADLE_USER_HOME/caches/modules-2/modules-2.lock
|
||||||
|
- rm -fr $GRADLE_USER_HOME/caches/*/plugin-resolution/
|
||||||
28
.idea/runConfigurations/All_tests.xml
generated
Normal file
28
.idea/runConfigurations/All_tests.xml
generated
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="All tests" type="AndroidJUnit" factoryName="Android JUnit">
|
||||||
|
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
|
||||||
|
<module name="briar-android" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH" />
|
||||||
|
<option name="PACKAGE_NAME" value="" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="package" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/briar-android" />
|
||||||
|
<option name="ENV_VARIABLES" />
|
||||||
|
<option name="PASS_PARENT_ENVS" value="true" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="singleModule" />
|
||||||
|
</option>
|
||||||
|
<envs />
|
||||||
|
<patterns />
|
||||||
|
<method>
|
||||||
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="All tests in bramble-api" run_configuration_type="AndroidJUnit" />
|
||||||
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="All tests in bramble-core" run_configuration_type="AndroidJUnit" />
|
||||||
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="All tests in bramble-j2se" run_configuration_type="AndroidJUnit" />
|
||||||
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="All tests in briar-core" run_configuration_type="AndroidJUnit" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
23
.idea/runConfigurations/All_tests_in_bramble_api.xml
generated
Normal file
23
.idea/runConfigurations/All_tests_in_bramble_api.xml
generated
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="All tests in bramble-api" type="AndroidJUnit" factoryName="Android JUnit">
|
||||||
|
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
|
||||||
|
<module name="bramble-api" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH" />
|
||||||
|
<option name="PACKAGE_NAME" value="" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="package" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/bramble-api" />
|
||||||
|
<option name="ENV_VARIABLES" />
|
||||||
|
<option name="PASS_PARENT_ENVS" value="true" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="singleModule" />
|
||||||
|
</option>
|
||||||
|
<envs />
|
||||||
|
<patterns />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
23
.idea/runConfigurations/All_tests_in_bramble_core.xml
generated
Normal file
23
.idea/runConfigurations/All_tests_in_bramble_core.xml
generated
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="All tests in bramble-core" type="AndroidJUnit" factoryName="Android JUnit">
|
||||||
|
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
|
||||||
|
<module name="bramble-core" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH" />
|
||||||
|
<option name="PACKAGE_NAME" value="" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="package" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/bramble-core" />
|
||||||
|
<option name="ENV_VARIABLES" />
|
||||||
|
<option name="PASS_PARENT_ENVS" value="true" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="singleModule" />
|
||||||
|
</option>
|
||||||
|
<envs />
|
||||||
|
<patterns />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
23
.idea/runConfigurations/All_tests_in_bramble_j2se.xml
generated
Normal file
23
.idea/runConfigurations/All_tests_in_bramble_j2se.xml
generated
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="All tests in bramble-j2se" type="AndroidJUnit" factoryName="Android JUnit">
|
||||||
|
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
|
||||||
|
<module name="bramble-j2se" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH" />
|
||||||
|
<option name="PACKAGE_NAME" value="" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="package" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea -Djava.library.path=libs" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/bramble-j2se" />
|
||||||
|
<option name="ENV_VARIABLES" />
|
||||||
|
<option name="PASS_PARENT_ENVS" value="true" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="singleModule" />
|
||||||
|
</option>
|
||||||
|
<envs />
|
||||||
|
<patterns />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
23
.idea/runConfigurations/All_tests_in_briar_android.xml
generated
Normal file
23
.idea/runConfigurations/All_tests_in_briar_android.xml
generated
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="All tests in briar-android" type="AndroidJUnit" factoryName="Android JUnit">
|
||||||
|
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
|
||||||
|
<module name="briar-android" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH" />
|
||||||
|
<option name="PACKAGE_NAME" value="" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="package" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/briar-android" />
|
||||||
|
<option name="ENV_VARIABLES" />
|
||||||
|
<option name="PASS_PARENT_ENVS" value="true" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="singleModule" />
|
||||||
|
</option>
|
||||||
|
<envs />
|
||||||
|
<patterns />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
23
.idea/runConfigurations/All_tests_in_briar_core.xml
generated
Normal file
23
.idea/runConfigurations/All_tests_in_briar_core.xml
generated
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="All tests in briar-core" type="AndroidJUnit" factoryName="Android JUnit">
|
||||||
|
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
|
||||||
|
<module name="briar-core" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH" />
|
||||||
|
<option name="PACKAGE_NAME" value="" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="package" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/briar-core" />
|
||||||
|
<option name="ENV_VARIABLES" />
|
||||||
|
<option name="PASS_PARENT_ENVS" value="true" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="singleModule" />
|
||||||
|
</option>
|
||||||
|
<envs />
|
||||||
|
<patterns />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
23
.idea/runConfigurations/H2_Performance_Test.xml
generated
Normal file
23
.idea/runConfigurations/H2_Performance_Test.xml
generated
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="H2 Performance Test" type="AndroidJUnit" factoryName="Android JUnit">
|
||||||
|
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
|
||||||
|
<module name="bramble-core" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH" />
|
||||||
|
<option name="PACKAGE_NAME" value="org.briarproject.bramble.db" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="org.briarproject.bramble.db.H2DatabasePerformanceTest" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="class" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="" />
|
||||||
|
<option name="ENV_VARIABLES" />
|
||||||
|
<option name="PASS_PARENT_ENVS" value="true" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="singleModule" />
|
||||||
|
</option>
|
||||||
|
<envs />
|
||||||
|
<patterns />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
23
.idea/runConfigurations/HyperSQL_Performance_Test.xml
generated
Normal file
23
.idea/runConfigurations/HyperSQL_Performance_Test.xml
generated
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="HyperSQL Performance Test" type="AndroidJUnit" factoryName="Android JUnit">
|
||||||
|
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
|
||||||
|
<module name="bramble-core" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH" />
|
||||||
|
<option name="PACKAGE_NAME" value="org.briarproject.bramble.db" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="org.briarproject.bramble.db.HyperSqlDatabasePerformanceTest" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="class" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="" />
|
||||||
|
<option name="ENV_VARIABLES" />
|
||||||
|
<option name="PASS_PARENT_ENVS" value="true" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="singleModule" />
|
||||||
|
</option>
|
||||||
|
<envs />
|
||||||
|
<patterns />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
bin
|
bin
|
||||||
gen
|
gen
|
||||||
build
|
build
|
||||||
local.properties
|
|
||||||
.settings
|
.settings
|
||||||
|
src/main/res/raw/*.zip
|
||||||
96
bramble-android/build.gradle
Normal file
96
bramble-android/build.gradle
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import de.undercouch.gradle.tasks.download.Download
|
||||||
|
import de.undercouch.gradle.tasks.download.Verify
|
||||||
|
|
||||||
|
apply plugin: 'com.android.library'
|
||||||
|
apply plugin: 'witness'
|
||||||
|
apply plugin: 'de.undercouch.download'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 27
|
||||||
|
buildToolsVersion '26.0.2'
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 14
|
||||||
|
targetSdkVersion 26
|
||||||
|
versionCode 1700
|
||||||
|
versionName "0.17.0"
|
||||||
|
consumerProguardFiles 'proguard-rules.txt'
|
||||||
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(path: ':bramble-core', configuration: 'default')
|
||||||
|
implementation fileTree(dir: 'libs', include: '*.jar')
|
||||||
|
|
||||||
|
annotationProcessor 'com.google.dagger:dagger-compiler:2.0.2'
|
||||||
|
|
||||||
|
compileOnly 'javax.annotation:jsr250-api:1.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencyVerification {
|
||||||
|
verify = [
|
||||||
|
'com.google.code.findbugs:jsr305:3.0.2:jsr305-3.0.2.jar:766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7',
|
||||||
|
'com.google.dagger:dagger-compiler:2.0.2:dagger-compiler-2.0.2.jar:b74bc9de063dd4c6400b232231f2ef5056145b8fbecbf5382012007dd1c071b3',
|
||||||
|
'com.google.dagger:dagger-producers:2.0-beta:dagger-producers-2.0-beta.jar:99ec15e8a0507ba569e7655bc1165ee5e5ca5aa914b3c8f7e2c2458f724edd6b',
|
||||||
|
'com.google.dagger:dagger:2.0.2:dagger-2.0.2.jar:84c0282ed8be73a29e0475d639da030b55dee72369e58dd35ae7d4fe6243dcf9',
|
||||||
|
'com.google.guava:guava:18.0:guava-18.0.jar:d664fbfc03d2e5ce9cab2a44fb01f1d0bf9dfebeccc1a473b1f9ea31f79f6f99',
|
||||||
|
'com.h2database:h2:1.4.192:h2-1.4.192.jar:225b22e9857235c46c93861410b60b8c81c10dc8985f4faf188985ba5445126c',
|
||||||
|
'com.madgag.spongycastle:core:1.58.0.0:core-1.58.0.0.jar:199617dd5698c5a9312b898c0a4cec7ce9dd8649d07f65d91629f58229d72728',
|
||||||
|
'javax.annotation:jsr250-api:1.0:jsr250-api-1.0.jar:a1a922d0d9b6d183ed3800dfac01d1e1eb159f0e8c6f94736931c1def54a941f',
|
||||||
|
'javax.inject:javax.inject:1:javax.inject-1.jar:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
|
||||||
|
'net.i2p.crypto:eddsa:0.2.0:eddsa-0.2.0.jar:a7cb1b85c16e2f0730b9204106929a1d9aaae1df728adc7041a8b8b605692140',
|
||||||
|
'org.bitlet:weupnp:0.1.4:weupnp-0.1.4.jar:88df7e6504929d00bdb832863761385c68ab92af945b04f0770b126270a444fb',
|
||||||
|
'org.jacoco:org.jacoco.agent:0.7.4.201502262128:org.jacoco.agent-0.7.4.201502262128-runtime.jar:e357a0f1d573c2f702a273992b1b6cb661734f66311854efb3778a888515c5b5',
|
||||||
|
'org.jacoco:org.jacoco.agent:0.7.4.201502262128:org.jacoco.agent-0.7.4.201502262128.jar:47b4bec6df11a1118da3953da8b9fa1e7079d6fec857faa1a3cf912e53a6fd4e',
|
||||||
|
'org.jacoco:org.jacoco.ant:0.7.4.201502262128:org.jacoco.ant-0.7.4.201502262128.jar:013ce2a68ba57a3c59215ae0dec4df3498c078062a38c3b94c841fc14450f283',
|
||||||
|
'org.jacoco:org.jacoco.core:0.7.4.201502262128:org.jacoco.core-0.7.4.201502262128.jar:ec4c74554312fac5116350164786f91b35c9e082fa4ea598bfa42b5db05d7abb',
|
||||||
|
'org.jacoco:org.jacoco.report:0.7.4.201502262128:org.jacoco.report-0.7.4.201502262128.jar:7a3554c605e088e7e323b1084656243f0444fa353e2f2dee1f1a4204eb64ff09',
|
||||||
|
'org.ow2.asm:asm-debug-all:5.0.1:asm-debug-all-5.0.1.jar:4734de5b515a454b0096db6971fb068e5f70e6f10bbee2b3bd2fdfe5d978ed57',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.torBinaryDir = 'src/main/res/raw'
|
||||||
|
ext.torVersion = '0.2.9.14'
|
||||||
|
ext.geoipVersion = '2017-11-06'
|
||||||
|
ext.torDownloadUrl = 'https://briarproject.org/build/'
|
||||||
|
|
||||||
|
def torBinaries = [
|
||||||
|
"tor_arm" : '1710ea6c47b7f4c1a88bdf4858c7893837635db10e8866854eed8d61629f50e8',
|
||||||
|
"tor_arm_pie": '974e6949507db8fa2ea45231817c2c3677ed4ccf5488a2252317d744b0be1917',
|
||||||
|
"tor_x86" : '3a5e45b3f051fcda9353b098b7086e762ffe7ba9242f7d7c8bf6523faaa8b1e9',
|
||||||
|
"tor_x86_pie": 'd1d96d8ce1a4b68accf04850185780d10cd5563d3552f7e1f040f8ca32cb4e51',
|
||||||
|
"geoip" : '8239b98374493529a29096e45fc5877d4d6fdad0146ad8380b291f90d61484ea'
|
||||||
|
]
|
||||||
|
|
||||||
|
def downloadBinary(name) {
|
||||||
|
return tasks.create("downloadBinary${name}", Download) {
|
||||||
|
src "${torDownloadUrl}${name}.zip"
|
||||||
|
.replace('tor_', "tor-${torVersion}-")
|
||||||
|
.replace('geoip', "geoip-${geoipVersion}")
|
||||||
|
.replaceAll('_', '-')
|
||||||
|
dest "${torBinaryDir}/${name}.zip"
|
||||||
|
onlyIfNewer true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def verifyBinary(name, chksum) {
|
||||||
|
return tasks.create([
|
||||||
|
name : "verifyBinary${name}",
|
||||||
|
type : Verify,
|
||||||
|
dependsOn: downloadBinary(name)]) {
|
||||||
|
src "${torBinaryDir}/${name}.zip"
|
||||||
|
algorithm 'SHA-256'
|
||||||
|
checksum chksum
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project.afterEvaluate {
|
||||||
|
torBinaries.every { key, value ->
|
||||||
|
preBuild.dependsOn.add(verifyBinary(key, value))
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
bramble-android/libs/jtorctl-briar.jar
Normal file
BIN
bramble-android/libs/jtorctl-briar.jar
Normal file
Binary file not shown.
19
bramble-android/proguard-rules.txt
Normal file
19
bramble-android/proguard-rules.txt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
-keep,includedescriptorclasses class org.briarproject.** { *; }
|
||||||
|
|
||||||
|
-keep class org.h2.** { *; }
|
||||||
|
-dontwarn org.h2.**
|
||||||
|
-dontnote org.h2.**
|
||||||
|
|
||||||
|
-keep class dagger.** { *; }
|
||||||
|
-dontwarn dagger.**
|
||||||
|
-dontnote dagger.**
|
||||||
|
|
||||||
|
-keep class net.i2p.crypto.eddsa.** { *; }
|
||||||
|
|
||||||
|
-keep class org.whispersystems.curve25519.** { *; }
|
||||||
|
|
||||||
|
-dontwarn sun.misc.Unsafe
|
||||||
|
-dontnote com.google.common.**
|
||||||
|
|
||||||
|
# UPnP library isn't used
|
||||||
|
-dontwarn org.bitlet.weupnp.**
|
||||||
22
bramble-android/src/main/AndroidManifest.xml
Normal file
22
bramble-android/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<manifest
|
||||||
|
package="org.briarproject.bramble"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<uses-feature android:name="android.hardware.bluetooth"/>
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_LOGS"/>
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="false"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:supportsRtl="true">
|
||||||
|
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.briarproject.bramble;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.plugin.AndroidPluginModule;
|
||||||
|
import org.briarproject.bramble.system.AndroidSystemModule;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
|
||||||
|
@Module(includes = {
|
||||||
|
AndroidPluginModule.class,
|
||||||
|
AndroidSystemModule.class
|
||||||
|
})
|
||||||
|
public class BrambleAndroidModule {
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.android.api;
|
package org.briarproject.bramble.api.system;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package org.briarproject.bramble.plugin;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||||
|
import org.briarproject.bramble.api.plugin.PluginConfig;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||||
|
import org.briarproject.bramble.api.reporting.DevReporter;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
|
import org.briarproject.bramble.api.system.Scheduler;
|
||||||
|
import org.briarproject.bramble.plugin.bluetooth.AndroidBluetoothPluginFactory;
|
||||||
|
import org.briarproject.bramble.plugin.tcp.AndroidLanTcpPluginFactory;
|
||||||
|
import org.briarproject.bramble.plugin.tor.TorPluginFactory;
|
||||||
|
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class AndroidPluginModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
||||||
|
@Scheduler ScheduledExecutorService scheduler,
|
||||||
|
AndroidExecutor androidExecutor, SecureRandom random,
|
||||||
|
SocketFactory torSocketFactory, BackoffFactory backoffFactory,
|
||||||
|
Application app, LocationUtils locationUtils, DevReporter reporter,
|
||||||
|
EventBus eventBus) {
|
||||||
|
Context appContext = app.getApplicationContext();
|
||||||
|
DuplexPluginFactory bluetooth =
|
||||||
|
new AndroidBluetoothPluginFactory(ioExecutor, androidExecutor,
|
||||||
|
appContext, random, eventBus, backoffFactory);
|
||||||
|
DuplexPluginFactory tor = new TorPluginFactory(ioExecutor, scheduler,
|
||||||
|
appContext, locationUtils, reporter, eventBus,
|
||||||
|
torSocketFactory, backoffFactory);
|
||||||
|
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
|
||||||
|
backoffFactory, appContext);
|
||||||
|
Collection<DuplexPluginFactory> duplex =
|
||||||
|
Arrays.asList(bluetooth, tor, lan);
|
||||||
|
@NotNullByDefault
|
||||||
|
PluginConfig pluginConfig = new PluginConfig() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<DuplexPluginFactory> getDuplexFactories() {
|
||||||
|
return duplex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<SimplexPluginFactory> getSimplexFactories() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return pluginConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
package org.briarproject.bramble.plugin.bluetooth;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothServerSocket;
|
||||||
|
import android.bluetooth.BluetoothSocket;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
|
import org.briarproject.bramble.api.plugin.PluginException;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static android.bluetooth.BluetoothAdapter.ACTION_SCAN_MODE_CHANGED;
|
||||||
|
import static android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED;
|
||||||
|
import static android.bluetooth.BluetoothAdapter.EXTRA_SCAN_MODE;
|
||||||
|
import static android.bluetooth.BluetoothAdapter.EXTRA_STATE;
|
||||||
|
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE;
|
||||||
|
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||||
|
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_NONE;
|
||||||
|
import static android.bluetooth.BluetoothAdapter.STATE_OFF;
|
||||||
|
import static android.bluetooth.BluetoothAdapter.STATE_ON;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(AndroidBluetoothPlugin.class.getName());
|
||||||
|
|
||||||
|
private final AndroidExecutor androidExecutor;
|
||||||
|
private final Context appContext;
|
||||||
|
|
||||||
|
private volatile boolean wasEnabledByUs = false;
|
||||||
|
private volatile BluetoothStateReceiver receiver = null;
|
||||||
|
|
||||||
|
// Non-null if the plugin started successfully
|
||||||
|
private volatile BluetoothAdapter adapter = null;
|
||||||
|
|
||||||
|
AndroidBluetoothPlugin(Executor ioExecutor, AndroidExecutor androidExecutor,
|
||||||
|
Context appContext, SecureRandom secureRandom, Backoff backoff,
|
||||||
|
DuplexPluginCallback callback, int maxLatency) {
|
||||||
|
super(ioExecutor, secureRandom, backoff, callback, maxLatency);
|
||||||
|
this.androidExecutor = androidExecutor;
|
||||||
|
this.appContext = appContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() throws PluginException {
|
||||||
|
super.start();
|
||||||
|
// Listen for changes to the Bluetooth state
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(ACTION_STATE_CHANGED);
|
||||||
|
filter.addAction(ACTION_SCAN_MODE_CHANGED);
|
||||||
|
receiver = new BluetoothStateReceiver();
|
||||||
|
appContext.registerReceiver(receiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
super.stop();
|
||||||
|
if (receiver != null) appContext.unregisterReceiver(receiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void initialiseAdapter() throws IOException {
|
||||||
|
// BluetoothAdapter.getDefaultAdapter() must be called on a thread
|
||||||
|
// with a message queue, so submit it to the AndroidExecutor
|
||||||
|
try {
|
||||||
|
adapter = androidExecutor.runOnBackgroundThread(
|
||||||
|
BluetoothAdapter::getDefaultAdapter).get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
if (adapter == null)
|
||||||
|
throw new IOException("Bluetooth is not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isAdapterEnabled() {
|
||||||
|
return adapter != null && adapter.isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void enableAdapter() {
|
||||||
|
if (adapter != null && !adapter.isEnabled()) {
|
||||||
|
if (adapter.enable()) {
|
||||||
|
LOG.info("Enabling Bluetooth");
|
||||||
|
wasEnabledByUs = true;
|
||||||
|
} else {
|
||||||
|
LOG.info("Could not enable Bluetooth");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void disableAdapterIfEnabledByUs() {
|
||||||
|
if (isAdapterEnabled() && wasEnabledByUs) {
|
||||||
|
if (adapter.disable()) LOG.info("Disabling Bluetooth");
|
||||||
|
else LOG.info("Could not disable Bluetooth");
|
||||||
|
wasEnabledByUs = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void setEnabledByUs() {
|
||||||
|
wasEnabledByUs = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
String getBluetoothAddress() {
|
||||||
|
String address = AndroidUtils.getBluetoothAddress(appContext, adapter);
|
||||||
|
return address.isEmpty() ? null : address;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
BluetoothServerSocket openServerSocket(String uuid) throws IOException {
|
||||||
|
return adapter.listenUsingInsecureRfcommWithServiceRecord(
|
||||||
|
"RFCOMM", UUID.fromString(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void tryToClose(@Nullable BluetoothServerSocket ss) {
|
||||||
|
try {
|
||||||
|
if (ss != null) ss.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
DuplexTransportConnection acceptConnection(BluetoothServerSocket ss)
|
||||||
|
throws IOException {
|
||||||
|
return wrapSocket(ss.accept());
|
||||||
|
}
|
||||||
|
|
||||||
|
private DuplexTransportConnection wrapSocket(BluetoothSocket s) {
|
||||||
|
return new AndroidBluetoothTransportConnection(this, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isValidAddress(String address) {
|
||||||
|
return BluetoothAdapter.checkBluetoothAddress(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
DuplexTransportConnection connectTo(String address, String uuid)
|
||||||
|
throws IOException {
|
||||||
|
BluetoothDevice d = adapter.getRemoteDevice(address);
|
||||||
|
UUID u = UUID.fromString(uuid);
|
||||||
|
BluetoothSocket s = null;
|
||||||
|
try {
|
||||||
|
s = d.createInsecureRfcommSocketToServiceRecord(u);
|
||||||
|
s.connect();
|
||||||
|
return wrapSocket(s);
|
||||||
|
} catch (IOException e) {
|
||||||
|
tryToClose(s);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryToClose(@Nullable Closeable c) {
|
||||||
|
try {
|
||||||
|
if (c != null) c.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class BluetoothStateReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context ctx, Intent intent) {
|
||||||
|
int state = intent.getIntExtra(EXTRA_STATE, 0);
|
||||||
|
if (state == STATE_ON) onAdapterEnabled();
|
||||||
|
else if (state == STATE_OFF) onAdapterDisabled();
|
||||||
|
int scanMode = intent.getIntExtra(EXTRA_SCAN_MODE, 0);
|
||||||
|
if (scanMode == SCAN_MODE_NONE) {
|
||||||
|
LOG.info("Scan mode: None");
|
||||||
|
} else if (scanMode == SCAN_MODE_CONNECTABLE) {
|
||||||
|
LOG.info("Scan mode: Connectable");
|
||||||
|
} else if (scanMode == SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||||
|
LOG.info("Scan mode: Discoverable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package org.briarproject.bramble.plugin.bluetooth;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
|
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||||
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.ID;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
|
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||||
|
private static final int MIN_POLLING_INTERVAL = 60 * 1000; // 1 minute
|
||||||
|
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
|
||||||
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
|
private final Executor ioExecutor;
|
||||||
|
private final AndroidExecutor androidExecutor;
|
||||||
|
private final Context appContext;
|
||||||
|
private final SecureRandom secureRandom;
|
||||||
|
private final EventBus eventBus;
|
||||||
|
private final BackoffFactory backoffFactory;
|
||||||
|
|
||||||
|
public AndroidBluetoothPluginFactory(Executor ioExecutor,
|
||||||
|
AndroidExecutor androidExecutor, Context appContext,
|
||||||
|
SecureRandom secureRandom, EventBus eventBus,
|
||||||
|
BackoffFactory backoffFactory) {
|
||||||
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.androidExecutor = androidExecutor;
|
||||||
|
this.appContext = appContext;
|
||||||
|
this.secureRandom = secureRandom;
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
this.backoffFactory = backoffFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportId getId() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxLatency() {
|
||||||
|
return MAX_LATENCY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
|
AndroidBluetoothPlugin plugin = new AndroidBluetoothPlugin(ioExecutor,
|
||||||
|
androidExecutor, appContext, secureRandom, backoff, callback,
|
||||||
|
MAX_LATENCY);
|
||||||
|
eventBus.addListener(plugin);
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,22 @@
|
|||||||
package org.briarproject.plugins.droidtooth;
|
package org.briarproject.bramble.plugin.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothSocket;
|
import android.bluetooth.BluetoothSocket;
|
||||||
|
|
||||||
import org.briarproject.api.plugins.Plugin;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.duplex.AbstractDuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.Plugin;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.AbstractDuplexTransportConnection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
class DroidtoothTransportConnection extends AbstractDuplexTransportConnection {
|
@NotNullByDefault
|
||||||
|
class AndroidBluetoothTransportConnection
|
||||||
|
extends AbstractDuplexTransportConnection {
|
||||||
|
|
||||||
private final BluetoothSocket socket;
|
private final BluetoothSocket socket;
|
||||||
|
|
||||||
DroidtoothTransportConnection(Plugin plugin, BluetoothSocket socket) {
|
AndroidBluetoothTransportConnection(Plugin plugin, BluetoothSocket socket) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
package org.briarproject.bramble.plugin.tcp;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -6,10 +6,11 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -19,10 +20,15 @@ import javax.annotation.Nullable;
|
|||||||
import static android.content.Context.CONNECTIVITY_SERVICE;
|
import static android.content.Context.CONNECTIVITY_SERVICE;
|
||||||
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
||||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||||
|
import static android.net.wifi.WifiManager.EXTRA_WIFI_STATE;
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static org.briarproject.bramble.util.AndroidUtils.logNetworkState;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class AndroidLanTcpPlugin extends LanTcpPlugin {
|
class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||||
|
|
||||||
|
private static final String WIFI_AP_STATE_ACTION =
|
||||||
|
"android.net.wifi.WIFI_AP_STATE_CHANGED";
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(AndroidLanTcpPlugin.class.getName());
|
Logger.getLogger(AndroidLanTcpPlugin.class.getName());
|
||||||
|
|
||||||
@@ -39,14 +45,16 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean start() {
|
public void start() {
|
||||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||||
running = true;
|
running = true;
|
||||||
// Register to receive network status events
|
// Register to receive network status events
|
||||||
networkStateReceiver = new NetworkStateReceiver();
|
networkStateReceiver = new NetworkStateReceiver();
|
||||||
IntentFilter filter = new IntentFilter(CONNECTIVITY_ACTION);
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(CONNECTIVITY_ACTION);
|
||||||
|
filter.addAction(WIFI_AP_STATE_ACTION);
|
||||||
appContext.registerReceiver(networkStateReceiver, filter);
|
appContext.registerReceiver(networkStateReceiver, filter);
|
||||||
return true;
|
if (LOG.isLoggable(INFO)) logNetworkState(appContext, LOG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,10 +70,27 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context ctx, Intent i) {
|
public void onReceive(Context ctx, Intent i) {
|
||||||
if (!running) return;
|
if (!running) return;
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
if (CONNECTIVITY_ACTION.equals(i.getAction())) {
|
||||||
|
LOG.info("Connectivity change");
|
||||||
|
Bundle extras = i.getExtras();
|
||||||
|
if (extras != null) {
|
||||||
|
LOG.info("Extras:");
|
||||||
|
for (String key : extras.keySet())
|
||||||
|
LOG.info("\t" + key + ": " + extras.get(key));
|
||||||
|
}
|
||||||
|
} else if (WIFI_AP_STATE_ACTION.equals(i.getAction())) {
|
||||||
|
int state = i.getIntExtra(EXTRA_WIFI_STATE, 0);
|
||||||
|
if (state == 13) LOG.info("Wifi AP enabled");
|
||||||
|
else LOG.info("Wifi AP state " + state);
|
||||||
|
}
|
||||||
|
logNetworkState(appContext, LOG);
|
||||||
|
}
|
||||||
Object o = ctx.getSystemService(CONNECTIVITY_SERVICE);
|
Object o = ctx.getSystemService(CONNECTIVITY_SERVICE);
|
||||||
ConnectivityManager cm = (ConnectivityManager) o;
|
ConnectivityManager cm = (ConnectivityManager) o;
|
||||||
NetworkInfo net = cm.getActiveNetworkInfo();
|
NetworkInfo net = cm.getActiveNetworkInfo();
|
||||||
if (net != null && net.getType() == TYPE_WIFI && net.isConnected()) {
|
if (net != null && net.getType() == TYPE_WIFI
|
||||||
|
&& net.isConnected()) {
|
||||||
LOG.info("Connected to Wi-Fi");
|
LOG.info("Connected to Wi-Fi");
|
||||||
if (socket == null || socket.isClosed()) bind();
|
if (socket == null || socket.isClosed()) bind();
|
||||||
} else {
|
} else {
|
||||||
@@ -1,18 +1,23 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
package org.briarproject.bramble.plugin.tcp;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.plugins.BackoffFactory;
|
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import static org.briarproject.api.plugins.LanTcpConstants.ID;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
package org.briarproject.plugins.tor;
|
package org.briarproject.bramble.plugin.tor;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TorNetworkMetadata {
|
class TorNetworkMetadata {
|
||||||
|
|
||||||
// See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
// See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
||||||
// and https://trac.torproject.org/projects/tor/wiki/doc/OONI/censorshipwiki
|
// and https://trac.torproject.org/projects/tor/wiki/doc/OONI/censorshipwiki
|
||||||
// TODO: get a more complete list
|
// TODO: get a more complete list
|
||||||
private static final Set<String> BLOCKED_IN_COUNTRIES =
|
private static final Set<String> BLOCKED_IN_COUNTRIES =
|
||||||
new HashSet<String>(Arrays.asList("CN", "IR", "SY", "ZZ"));
|
new HashSet<>(Arrays.asList("CN", "IR", "SY", "ZZ"));
|
||||||
|
|
||||||
public static boolean isTorProbablyBlocked(String countryCode) {
|
static boolean isTorProbablyBlocked(String countryCode) {
|
||||||
return BLOCKED_IN_COUNTRIES.contains(countryCode);
|
return BLOCKED_IN_COUNTRIES.contains(countryCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.plugins.tor;
|
package org.briarproject.bramble.plugin.tor;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -7,6 +7,7 @@ import android.content.IntentFilter;
|
|||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.FileObserver;
|
import android.os.FileObserver;
|
||||||
@@ -15,27 +16,28 @@ import android.os.PowerManager;
|
|||||||
import net.freehaven.tor.control.EventHandler;
|
import net.freehaven.tor.control.EventHandler;
|
||||||
import net.freehaven.tor.control.TorControlConnection;
|
import net.freehaven.tor.control.TorControlConnection;
|
||||||
|
|
||||||
import org.briarproject.android.util.AndroidUtils;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.api.crypto.PseudoRandom;
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.api.data.BdfList;
|
import org.briarproject.bramble.api.keyagreement.KeyAgreementListener;
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.api.event.EventListener;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.api.event.SettingsUpdatedEvent;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.keyagreement.KeyAgreementListener;
|
import org.briarproject.bramble.api.plugin.PluginException;
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.plugins.TorConstants;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.reporting.DevReporter;
|
||||||
import org.briarproject.api.reporting.DevReporter;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.api.settings.Settings;
|
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
||||||
import org.briarproject.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.util.IoUtils;
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.bramble.util.IoUtils;
|
||||||
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
@@ -53,10 +55,16 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
@@ -67,21 +75,33 @@ import javax.net.SocketFactory;
|
|||||||
import static android.content.Context.CONNECTIVITY_SERVICE;
|
import static android.content.Context.CONNECTIVITY_SERVICE;
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
import static android.content.Context.POWER_SERVICE;
|
import static android.content.Context.POWER_SERVICE;
|
||||||
|
import static android.content.Intent.ACTION_SCREEN_OFF;
|
||||||
|
import static android.content.Intent.ACTION_SCREEN_ON;
|
||||||
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
||||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||||
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
import static android.os.PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED;
|
||||||
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static net.freehaven.tor.control.TorControlCommands.HS_ADDRESS;
|
import static net.freehaven.tor.control.TorControlCommands.HS_ADDRESS;
|
||||||
import static net.freehaven.tor.control.TorControlCommands.HS_PRIVKEY;
|
import static net.freehaven.tor.control.TorControlCommands.HS_PRIVKEY;
|
||||||
import static org.briarproject.api.plugins.TorConstants.CONTROL_PORT;
|
import static org.briarproject.bramble.api.plugin.TorConstants.CONTROL_PORT;
|
||||||
import static org.briarproject.util.PrivacyUtils.scrubOnion;
|
import static org.briarproject.bramble.api.plugin.TorConstants.ID;
|
||||||
|
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK;
|
||||||
|
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_ALWAYS;
|
||||||
|
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_NEVER;
|
||||||
|
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_WIFI;
|
||||||
|
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_PORT;
|
||||||
|
import static org.briarproject.bramble.api.plugin.TorConstants.PROP_ONION;
|
||||||
|
import static org.briarproject.bramble.util.PrivacyUtils.scrubOnion;
|
||||||
|
|
||||||
@NotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||||
|
|
||||||
private static final String PROP_ONION = "onion";
|
|
||||||
private static final String[] EVENTS = {
|
private static final String[] EVENTS = {
|
||||||
"CIRC", "ORCONN", "HS_DESC", "NOTICE", "WARN", "ERR"
|
"CIRC", "ORCONN", "HS_DESC", "NOTICE", "WARN", "ERR"
|
||||||
};
|
};
|
||||||
@@ -92,6 +112,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
Logger.getLogger(TorPlugin.class.getName());
|
Logger.getLogger(TorPlugin.class.getName());
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
|
private final ScheduledExecutorService scheduler;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final LocationUtils locationUtils;
|
private final LocationUtils locationUtils;
|
||||||
private final DevReporter reporter;
|
private final DevReporter reporter;
|
||||||
@@ -104,24 +125,24 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
private final File torDirectory, torFile, geoIpFile, configFile;
|
private final File torDirectory, torFile, geoIpFile, configFile;
|
||||||
private final File doneFile, cookieFile;
|
private final File doneFile, cookieFile;
|
||||||
private final PowerManager.WakeLock wakeLock;
|
private final PowerManager.WakeLock wakeLock;
|
||||||
|
private final Lock connectionStatusLock;
|
||||||
|
private final AtomicReference<Future<?>> connectivityCheck =
|
||||||
|
new AtomicReference<>();
|
||||||
private final AtomicBoolean used = new AtomicBoolean(false);
|
private final AtomicBoolean used = new AtomicBoolean(false);
|
||||||
|
|
||||||
private volatile boolean running = false;
|
private volatile boolean running = false;
|
||||||
@Nullable
|
|
||||||
private volatile ServerSocket socket = null;
|
private volatile ServerSocket socket = null;
|
||||||
@Nullable
|
|
||||||
private volatile Socket controlSocket = null;
|
private volatile Socket controlSocket = null;
|
||||||
@Nullable
|
|
||||||
private volatile TorControlConnection controlConnection = null;
|
private volatile TorControlConnection controlConnection = null;
|
||||||
@Nullable
|
|
||||||
private volatile BroadcastReceiver networkStateReceiver = null;
|
private volatile BroadcastReceiver networkStateReceiver = null;
|
||||||
|
|
||||||
TorPlugin(Executor ioExecutor, Context appContext,
|
TorPlugin(Executor ioExecutor, ScheduledExecutorService scheduler,
|
||||||
LocationUtils locationUtils, DevReporter reporter,
|
Context appContext, LocationUtils locationUtils,
|
||||||
SocketFactory torSocketFactory, Backoff backoff,
|
DevReporter reporter, SocketFactory torSocketFactory,
|
||||||
DuplexPluginCallback callback, String architecture, int maxLatency,
|
Backoff backoff, DuplexPluginCallback callback,
|
||||||
int maxIdleTime) {
|
String architecture, int maxLatency, int maxIdleTime) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.scheduler = scheduler;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
this.locationUtils = locationUtils;
|
this.locationUtils = locationUtils;
|
||||||
this.reporter = reporter;
|
this.reporter = reporter;
|
||||||
@@ -143,8 +164,10 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
cookieFile = new File(torDirectory, ".tor/control_auth_cookie");
|
cookieFile = new File(torDirectory, ".tor/control_auth_cookie");
|
||||||
Object o = appContext.getSystemService(POWER_SERVICE);
|
Object o = appContext.getSystemService(POWER_SERVICE);
|
||||||
PowerManager pm = (PowerManager) o;
|
PowerManager pm = (PowerManager) o;
|
||||||
wakeLock = pm.newWakeLock(PARTIAL_WAKE_LOCK, "TorPlugin");
|
// This tag will prevent Huawei's powermanager from killing us.
|
||||||
|
wakeLock = pm.newWakeLock(PARTIAL_WAKE_LOCK, "LocationManagerService");
|
||||||
wakeLock.setReferenceCounted(false);
|
wakeLock.setReferenceCounted(false);
|
||||||
|
connectionStatusLock = new ReentrantLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -163,14 +186,18 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean start() throws IOException {
|
public void start() throws PluginException {
|
||||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||||
// Install or update the assets if necessary
|
// Install or update the assets if necessary
|
||||||
if (!assetsAreUpToDate()) installAssets();
|
if (!assetsAreUpToDate()) installAssets();
|
||||||
LOG.info("Starting Tor");
|
LOG.info("Starting Tor");
|
||||||
// Watch for the auth cookie file being updated
|
// Watch for the auth cookie file being updated
|
||||||
cookieFile.getParentFile().mkdirs();
|
try {
|
||||||
cookieFile.createNewFile();
|
cookieFile.getParentFile().mkdirs();
|
||||||
|
cookieFile.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new PluginException(e);
|
||||||
|
}
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
FileObserver obs = new WriteObserver(cookieFile, latch);
|
FileObserver obs = new WriteObserver(cookieFile, latch);
|
||||||
obs.startWatching();
|
obs.startWatching();
|
||||||
@@ -178,19 +205,31 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
String torPath = torFile.getAbsolutePath();
|
String torPath = torFile.getAbsolutePath();
|
||||||
String configPath = configFile.getAbsolutePath();
|
String configPath = configFile.getAbsolutePath();
|
||||||
String pid = String.valueOf(android.os.Process.myPid());
|
String pid = String.valueOf(android.os.Process.myPid());
|
||||||
String[] cmd = {torPath, "-f", configPath, OWNER, pid};
|
|
||||||
String[] env = {"HOME=" + torDirectory.getAbsolutePath()};
|
|
||||||
Process torProcess;
|
Process torProcess;
|
||||||
|
ProcessBuilder pb =
|
||||||
|
new ProcessBuilder(torPath, "-f", configPath, OWNER, pid);
|
||||||
|
Map<String, String> env = pb.environment();
|
||||||
|
env.put("HOME", torDirectory.getAbsolutePath());
|
||||||
|
pb.directory(torDirectory);
|
||||||
try {
|
try {
|
||||||
torProcess = Runtime.getRuntime().exec(cmd, env, torDirectory);
|
torProcess = pb.start();
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException | IOException e) {
|
||||||
throw new IOException(e);
|
throw new PluginException(e);
|
||||||
}
|
}
|
||||||
// Log the process's standard output until it detaches
|
// Log the process's standard output until it detaches
|
||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
Scanner stdout = new Scanner(torProcess.getInputStream());
|
Scanner stdout = new Scanner(torProcess.getInputStream());
|
||||||
while (stdout.hasNextLine()) LOG.info(stdout.nextLine());
|
Scanner stderr = new Scanner(torProcess.getErrorStream());
|
||||||
|
while (stdout.hasNextLine() || stderr.hasNextLine()) {
|
||||||
|
if (stdout.hasNextLine()) {
|
||||||
|
LOG.info(stdout.nextLine());
|
||||||
|
}
|
||||||
|
if (stderr.hasNextLine()) {
|
||||||
|
LOG.info(stderr.nextLine());
|
||||||
|
}
|
||||||
|
}
|
||||||
stdout.close();
|
stdout.close();
|
||||||
|
stderr.close();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// Wait for the process to detach or exit
|
// Wait for the process to detach or exit
|
||||||
@@ -198,43 +237,50 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
if (exit != 0) {
|
if (exit != 0) {
|
||||||
if (LOG.isLoggable(WARNING))
|
if (LOG.isLoggable(WARNING))
|
||||||
LOG.warning("Tor exited with value " + exit);
|
LOG.warning("Tor exited with value " + exit);
|
||||||
return false;
|
throw new PluginException();
|
||||||
}
|
}
|
||||||
// Wait for the auth cookie file to be created/updated
|
// Wait for the auth cookie file to be created/updated
|
||||||
if (!latch.await(COOKIE_TIMEOUT, MILLISECONDS)) {
|
if (!latch.await(COOKIE_TIMEOUT, MILLISECONDS)) {
|
||||||
LOG.warning("Auth cookie not created");
|
LOG.warning("Auth cookie not created");
|
||||||
if (LOG.isLoggable(INFO)) listFiles(torDirectory);
|
if (LOG.isLoggable(INFO)) listFiles(torDirectory);
|
||||||
return false;
|
throw new PluginException();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOG.warning("Interrupted while starting Tor");
|
LOG.warning("Interrupted while starting Tor");
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
return false;
|
throw new PluginException();
|
||||||
}
|
}
|
||||||
// Open a control connection and authenticate using the cookie file
|
try {
|
||||||
controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
|
// Open a control connection and authenticate using the cookie file
|
||||||
controlConnection = new TorControlConnection(controlSocket);
|
controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
|
||||||
controlConnection.authenticate(read(cookieFile));
|
controlConnection = new TorControlConnection(controlSocket);
|
||||||
// Tell Tor to exit when the control connection is closed
|
controlConnection.authenticate(read(cookieFile));
|
||||||
controlConnection.takeOwnership();
|
// Tell Tor to exit when the control connection is closed
|
||||||
controlConnection.resetConf(Collections.singletonList(OWNER));
|
controlConnection.takeOwnership();
|
||||||
running = true;
|
controlConnection.resetConf(Collections.singletonList(OWNER));
|
||||||
// Register to receive events from the Tor process
|
running = true;
|
||||||
controlConnection.setEventHandler(this);
|
// Register to receive events from the Tor process
|
||||||
controlConnection.setEvents(Arrays.asList(EVENTS));
|
controlConnection.setEventHandler(this);
|
||||||
// Check whether Tor has already bootstrapped
|
controlConnection.setEvents(Arrays.asList(EVENTS));
|
||||||
String phase = controlConnection.getInfo("status/bootstrap-phase");
|
// Check whether Tor has already bootstrapped
|
||||||
if (phase != null && phase.contains("PROGRESS=100")) {
|
String phase = controlConnection.getInfo("status/bootstrap-phase");
|
||||||
LOG.info("Tor has already bootstrapped");
|
if (phase != null && phase.contains("PROGRESS=100")) {
|
||||||
connectionStatus.setBootstrapped();
|
LOG.info("Tor has already bootstrapped");
|
||||||
|
connectionStatus.setBootstrapped();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new PluginException(e);
|
||||||
}
|
}
|
||||||
// Register to receive network status events
|
// Register to receive network status events
|
||||||
networkStateReceiver = new NetworkStateReceiver();
|
networkStateReceiver = new NetworkStateReceiver();
|
||||||
IntentFilter filter = new IntentFilter(CONNECTIVITY_ACTION);
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(CONNECTIVITY_ACTION);
|
||||||
|
filter.addAction(ACTION_SCREEN_ON);
|
||||||
|
filter.addAction(ACTION_SCREEN_OFF);
|
||||||
|
if (SDK_INT >= 23) filter.addAction(ACTION_DEVICE_IDLE_MODE_CHANGED);
|
||||||
appContext.registerReceiver(networkStateReceiver, filter);
|
appContext.registerReceiver(networkStateReceiver, filter);
|
||||||
// Bind a server socket to receive incoming hidden service connections
|
// Bind a server socket to receive incoming hidden service connections
|
||||||
bind();
|
bind();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean assetsAreUpToDate() {
|
private boolean assetsAreUpToDate() {
|
||||||
@@ -247,7 +293,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void installAssets() throws IOException {
|
private void installAssets() throws PluginException {
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
OutputStream out = null;
|
OutputStream out = null;
|
||||||
try {
|
try {
|
||||||
@@ -270,30 +316,36 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
tryToClose(in);
|
tryToClose(in);
|
||||||
tryToClose(out);
|
tryToClose(out);
|
||||||
throw e;
|
throw new PluginException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream getTorInputStream() throws IOException {
|
private InputStream getTorInputStream() throws IOException {
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Installing Tor binary for " + architecture);
|
LOG.info("Installing Tor binary for " + architecture);
|
||||||
String filename = "tor-" + architecture + ".zip";
|
int resId = getResourceId("tor_" + architecture);
|
||||||
InputStream in = appContext.getResources().getAssets().open(filename);
|
InputStream in = appContext.getResources().openRawResource(resId);
|
||||||
ZipInputStream zin = new ZipInputStream(in);
|
ZipInputStream zin = new ZipInputStream(in);
|
||||||
if (zin.getNextEntry() == null) throw new IOException();
|
if (zin.getNextEntry() == null) throw new IOException();
|
||||||
return zin;
|
return zin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream getGeoIpInputStream() throws IOException {
|
private InputStream getGeoIpInputStream() throws IOException {
|
||||||
String filename = "geoip.zip";
|
int resId = getResourceId("geoip");
|
||||||
InputStream in = appContext.getResources().getAssets().open(filename);
|
InputStream in = appContext.getResources().openRawResource(resId);
|
||||||
ZipInputStream zin = new ZipInputStream(in);
|
ZipInputStream zin = new ZipInputStream(in);
|
||||||
if (zin.getNextEntry() == null) throw new IOException();
|
if (zin.getNextEntry() == null) throw new IOException();
|
||||||
return zin;
|
return zin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream getConfigInputStream() throws IOException {
|
private InputStream getConfigInputStream() throws IOException {
|
||||||
return appContext.getResources().getAssets().open("torrc");
|
int resId = getResourceId("torrc");
|
||||||
|
return appContext.getResources().openRawResource(resId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getResourceId(String filename) {
|
||||||
|
Resources res = appContext.getResources();
|
||||||
|
return res.getIdentifier(filename, "raw", appContext.getPackageName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryToClose(@Nullable Closeable c) {
|
private void tryToClose(@Nullable Closeable c) {
|
||||||
@@ -338,57 +390,45 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendDevReports() {
|
private void sendDevReports() {
|
||||||
ioExecutor.execute(new Runnable() {
|
ioExecutor.execute(() -> {
|
||||||
@Override
|
// TODO: Trigger this with a TransportEnabledEvent
|
||||||
public void run() {
|
File reportDir = AndroidUtils.getReportDir(appContext);
|
||||||
// TODO: Trigger this with a TransportEnabledEvent
|
reporter.sendReports(reportDir);
|
||||||
File reportDir = AndroidUtils.getReportDir(appContext);
|
|
||||||
reporter.sendReports(reportDir);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bind() {
|
private void bind() {
|
||||||
ioExecutor.execute(new Runnable() {
|
ioExecutor.execute(() -> {
|
||||||
@Override
|
// If there's already a port number stored in config, reuse it
|
||||||
public void run() {
|
String portString = callback.getSettings().get(PREF_TOR_PORT);
|
||||||
// If there's already a port number stored in config, reuse it
|
int port;
|
||||||
String portString = callback.getSettings().get("port");
|
if (StringUtils.isNullOrEmpty(portString)) port = 0;
|
||||||
int port;
|
else port = Integer.parseInt(portString);
|
||||||
if (StringUtils.isNullOrEmpty(portString)) port = 0;
|
// Bind a server socket to receive connections from Tor
|
||||||
else port = Integer.parseInt(portString);
|
ServerSocket ss = null;
|
||||||
// Bind a server socket to receive connections from Tor
|
try {
|
||||||
ServerSocket ss = null;
|
ss = new ServerSocket();
|
||||||
try {
|
ss.bind(new InetSocketAddress("127.0.0.1", port));
|
||||||
ss = new ServerSocket();
|
} catch (IOException e) {
|
||||||
ss.bind(new InetSocketAddress("127.0.0.1", port));
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
} catch (IOException e) {
|
tryToClose(ss);
|
||||||
if (LOG.isLoggable(WARNING))
|
return;
|
||||||
LOG.log(WARNING, e.toString(), e);
|
|
||||||
tryToClose(ss);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!running) {
|
|
||||||
tryToClose(ss);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
socket = ss;
|
|
||||||
// Store the port number
|
|
||||||
final String localPort = String.valueOf(ss.getLocalPort());
|
|
||||||
Settings s = new Settings();
|
|
||||||
s.put("port", localPort);
|
|
||||||
callback.mergeSettings(s);
|
|
||||||
// Create a hidden service if necessary
|
|
||||||
ioExecutor.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
publishHiddenService(localPort);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
backoff.reset();
|
|
||||||
// Accept incoming hidden service connections from Tor
|
|
||||||
acceptContactConnections(ss);
|
|
||||||
}
|
}
|
||||||
|
if (!running) {
|
||||||
|
tryToClose(ss);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
socket = ss;
|
||||||
|
// Store the port number
|
||||||
|
String localPort = String.valueOf(ss.getLocalPort());
|
||||||
|
Settings s = new Settings();
|
||||||
|
s.put(PREF_TOR_PORT, localPort);
|
||||||
|
callback.mergeSettings(s);
|
||||||
|
// Create a hidden service if necessary
|
||||||
|
ioExecutor.execute(() -> publishHiddenService(localPort));
|
||||||
|
backoff.reset();
|
||||||
|
// Accept incoming hidden service connections from Tor
|
||||||
|
acceptContactConnections(ss);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,7 +511,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws IOException {
|
public void stop() throws PluginException {
|
||||||
running = false;
|
running = false;
|
||||||
tryToClose(socket);
|
tryToClose(socket);
|
||||||
if (networkStateReceiver != null)
|
if (networkStateReceiver != null)
|
||||||
@@ -508,20 +548,21 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
public void poll(Collection<ContactId> connected) {
|
public void poll(Collection<ContactId> connected) {
|
||||||
if (!isRunning()) return;
|
if (!isRunning()) return;
|
||||||
backoff.increment();
|
backoff.increment();
|
||||||
// TODO: Pass properties to connectAndCallBack()
|
Map<ContactId, TransportProperties> remote =
|
||||||
for (ContactId c : callback.getRemoteProperties().keySet())
|
callback.getRemoteProperties();
|
||||||
if (!connected.contains(c)) connectAndCallBack(c);
|
for (Entry<ContactId, TransportProperties> e : remote.entrySet()) {
|
||||||
|
ContactId c = e.getKey();
|
||||||
|
if (!connected.contains(c)) connectAndCallBack(c, e.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void connectAndCallBack(final ContactId c) {
|
private void connectAndCallBack(ContactId c, TransportProperties p) {
|
||||||
ioExecutor.execute(new Runnable() {
|
ioExecutor.execute(() -> {
|
||||||
@Override
|
if (!isRunning()) return;
|
||||||
public void run() {
|
DuplexTransportConnection d = createConnection(p);
|
||||||
DuplexTransportConnection d = createConnection(c);
|
if (d != null) {
|
||||||
if (d != null) {
|
backoff.reset();
|
||||||
backoff.reset();
|
callback.outgoingConnectionCreated(c, d);
|
||||||
callback.outgoingConnectionCreated(c, d);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -529,8 +570,11 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public DuplexTransportConnection createConnection(ContactId c) {
|
public DuplexTransportConnection createConnection(ContactId c) {
|
||||||
if (!isRunning()) return null;
|
if (!isRunning()) return null;
|
||||||
TransportProperties p = callback.getRemoteProperties().get(c);
|
return createConnection(callback.getRemoteProperties(c));
|
||||||
if (p == null) return null;
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private DuplexTransportConnection createConnection(TransportProperties p) {
|
||||||
String onion = p.get(PROP_ONION);
|
String onion = p.get(PROP_ONION);
|
||||||
if (StringUtils.isNullOrEmpty(onion)) return null;
|
if (StringUtils.isNullOrEmpty(onion)) return null;
|
||||||
if (!ONION.matcher(onion).matches()) {
|
if (!ONION.matcher(onion).matches()) {
|
||||||
@@ -558,17 +602,6 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsInvitations() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DuplexTransportConnection createInvitationConnection(PseudoRandom r,
|
|
||||||
long timeout, boolean alice) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsKeyAgreement() {
|
public boolean supportsKeyAgreement() {
|
||||||
return false;
|
return false;
|
||||||
@@ -581,7 +614,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DuplexTransportConnection createKeyAgreementConnection(
|
public DuplexTransportConnection createKeyAgreementConnection(
|
||||||
byte[] commitment, BdfList descriptor, long timeout) {
|
byte[] commitment, BdfList descriptor) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -605,6 +638,8 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void orConnStatus(String status, String orName) {
|
public void orConnStatus(String status, String orName) {
|
||||||
if (LOG.isLoggable(INFO)) LOG.info("OR connection " + status);
|
if (LOG.isLoggable(INFO)) LOG.info("OR connection " + status);
|
||||||
|
if (status.equals("CLOSED") || status.equals("FAILED"))
|
||||||
|
updateConnectionStatus(); // Check whether we've lost connectivity
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -644,7 +679,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(int event, String path) {
|
public void onEvent(int event, @Nullable String path) {
|
||||||
stopWatching();
|
stopWatching();
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
@@ -653,7 +688,8 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void eventOccurred(Event e) {
|
public void eventOccurred(Event e) {
|
||||||
if (e instanceof SettingsUpdatedEvent) {
|
if (e instanceof SettingsUpdatedEvent) {
|
||||||
if (((SettingsUpdatedEvent) e).getNamespace().equals("tor")) {
|
SettingsUpdatedEvent s = (SettingsUpdatedEvent) e;
|
||||||
|
if (s.getNamespace().equals(ID.getString())) {
|
||||||
LOG.info("Tor settings updated");
|
LOG.info("Tor settings updated");
|
||||||
updateConnectionStatus();
|
updateConnectionStatus();
|
||||||
}
|
}
|
||||||
@@ -661,58 +697,74 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateConnectionStatus() {
|
private void updateConnectionStatus() {
|
||||||
ioExecutor.execute(new Runnable() {
|
ioExecutor.execute(() -> {
|
||||||
@Override
|
if (!running) return;
|
||||||
public void run() {
|
try {
|
||||||
if (!running) return;
|
connectionStatusLock.lock();
|
||||||
|
updateConnectionStatusLocked();
|
||||||
Object o = appContext.getSystemService(CONNECTIVITY_SERVICE);
|
} finally {
|
||||||
ConnectivityManager cm = (ConnectivityManager) o;
|
connectionStatusLock.unlock();
|
||||||
NetworkInfo net = cm.getActiveNetworkInfo();
|
|
||||||
boolean online = net != null && net.isConnected();
|
|
||||||
boolean wifi = online && net.getType() == TYPE_WIFI;
|
|
||||||
String country = locationUtils.getCurrentCountry();
|
|
||||||
boolean blocked = TorNetworkMetadata.isTorProbablyBlocked(
|
|
||||||
country);
|
|
||||||
Settings s = callback.getSettings();
|
|
||||||
boolean useMobileData = s.getBoolean("torOverMobile", true);
|
|
||||||
|
|
||||||
if (LOG.isLoggable(INFO)) {
|
|
||||||
LOG.info("Online: " + online + ", wifi: " + wifi);
|
|
||||||
if ("".equals(country)) LOG.info("Country code unknown");
|
|
||||||
else LOG.info("Country code: " + country);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!online) {
|
|
||||||
LOG.info("Disabling network, device is offline");
|
|
||||||
enableNetwork(false);
|
|
||||||
} else if (blocked) {
|
|
||||||
LOG.info("Disabling network, country is blocked");
|
|
||||||
enableNetwork(false);
|
|
||||||
} else if (!wifi && !useMobileData) {
|
|
||||||
LOG.info("Disabling network due to data setting");
|
|
||||||
enableNetwork(false);
|
|
||||||
} else {
|
|
||||||
LOG.info("Enabling network");
|
|
||||||
enableNetwork(true);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (LOG.isLoggable(WARNING))
|
|
||||||
LOG.log(WARNING, e.toString(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Locking: connectionStatusLock
|
||||||
|
private void updateConnectionStatusLocked() {
|
||||||
|
Object o = appContext.getSystemService(CONNECTIVITY_SERVICE);
|
||||||
|
ConnectivityManager cm = (ConnectivityManager) o;
|
||||||
|
NetworkInfo net = cm.getActiveNetworkInfo();
|
||||||
|
boolean online = net != null && net.isConnected();
|
||||||
|
boolean wifi = online && net.getType() == TYPE_WIFI;
|
||||||
|
String country = locationUtils.getCurrentCountry();
|
||||||
|
boolean blocked = TorNetworkMetadata.isTorProbablyBlocked(country);
|
||||||
|
Settings s = callback.getSettings();
|
||||||
|
int network = s.getInt(PREF_TOR_NETWORK, PREF_TOR_NETWORK_ALWAYS);
|
||||||
|
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("Online: " + online + ", wifi: " + wifi);
|
||||||
|
if ("".equals(country)) LOG.info("Country code unknown");
|
||||||
|
else LOG.info("Country code: " + country);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!online) {
|
||||||
|
LOG.info("Disabling network, device is offline");
|
||||||
|
enableNetwork(false);
|
||||||
|
} else if (blocked) {
|
||||||
|
LOG.info("Disabling network, country is blocked");
|
||||||
|
enableNetwork(false);
|
||||||
|
} else if (network == PREF_TOR_NETWORK_NEVER
|
||||||
|
|| (network == PREF_TOR_NETWORK_WIFI && !wifi)) {
|
||||||
|
LOG.info("Disabling network due to data setting");
|
||||||
|
enableNetwork(false);
|
||||||
|
} else {
|
||||||
|
LOG.info("Enabling network");
|
||||||
|
enableNetwork(true);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scheduleConnectionStatusUpdate() {
|
||||||
|
Future<?> newConnectivityCheck =
|
||||||
|
scheduler.schedule(this::updateConnectionStatus, 1, MINUTES);
|
||||||
|
Future<?> oldConnectivityCheck =
|
||||||
|
connectivityCheck.getAndSet(newConnectivityCheck);
|
||||||
|
if (oldConnectivityCheck != null) oldConnectivityCheck.cancel(false);
|
||||||
|
}
|
||||||
|
|
||||||
private class NetworkStateReceiver extends BroadcastReceiver {
|
private class NetworkStateReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context ctx, Intent i) {
|
public void onReceive(Context ctx, Intent i) {
|
||||||
if (!running) return;
|
if (!running) return;
|
||||||
if (CONNECTIVITY_ACTION.equals(i.getAction())) {
|
String action = i.getAction();
|
||||||
LOG.info("Detected connectivity change");
|
if (LOG.isLoggable(INFO)) LOG.info("Received broadcast " + action);
|
||||||
updateConnectionStatus();
|
updateConnectionStatus();
|
||||||
|
if (ACTION_SCREEN_ON.equals(action)
|
||||||
|
|| ACTION_SCREEN_OFF.equals(action)) {
|
||||||
|
scheduleConnectionStatusUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,30 @@
|
|||||||
package org.briarproject.plugins.tor;
|
package org.briarproject.bramble.plugin.tor;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import org.briarproject.android.util.AndroidUtils;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.event.EventBus;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||||
import org.briarproject.api.plugins.BackoffFactory;
|
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||||
import org.briarproject.api.plugins.TorConstants;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
import org.briarproject.api.reporting.DevReporter;
|
import org.briarproject.bramble.api.reporting.DevReporter;
|
||||||
import org.briarproject.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class TorPluginFactory implements DuplexPluginFactory {
|
public class TorPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
@@ -32,6 +37,7 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
|||||||
private static final double BACKOFF_BASE = 1.2;
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
|
private final ScheduledExecutorService scheduler;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final LocationUtils locationUtils;
|
private final LocationUtils locationUtils;
|
||||||
private final DevReporter reporter;
|
private final DevReporter reporter;
|
||||||
@@ -39,11 +45,13 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
|||||||
private final SocketFactory torSocketFactory;
|
private final SocketFactory torSocketFactory;
|
||||||
private final BackoffFactory backoffFactory;
|
private final BackoffFactory backoffFactory;
|
||||||
|
|
||||||
public TorPluginFactory(Executor ioExecutor, Context appContext,
|
public TorPluginFactory(Executor ioExecutor,
|
||||||
|
ScheduledExecutorService scheduler, Context appContext,
|
||||||
LocationUtils locationUtils, DevReporter reporter,
|
LocationUtils locationUtils, DevReporter reporter,
|
||||||
EventBus eventBus, SocketFactory torSocketFactory,
|
EventBus eventBus, SocketFactory torSocketFactory,
|
||||||
BackoffFactory backoffFactory) {
|
BackoffFactory backoffFactory) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.scheduler = scheduler;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
this.locationUtils = locationUtils;
|
this.locationUtils = locationUtils;
|
||||||
this.reporter = reporter;
|
this.reporter = reporter;
|
||||||
@@ -81,13 +89,13 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Use position-independent executable for SDK >= 16
|
// Use position-independent executable for SDK >= 16
|
||||||
if (Build.VERSION.SDK_INT >= 16) architecture += "-pie";
|
if (Build.VERSION.SDK_INT >= 16) architecture += "_pie";
|
||||||
|
|
||||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
TorPlugin plugin = new TorPlugin(ioExecutor, appContext, locationUtils,
|
TorPlugin plugin = new TorPlugin(ioExecutor, scheduler, appContext,
|
||||||
reporter, torSocketFactory, backoff, callback, architecture,
|
locationUtils, reporter, torSocketFactory, backoff, callback,
|
||||||
MAX_LATENCY, MAX_IDLE_TIME);
|
architecture, MAX_LATENCY, MAX_IDLE_TIME);
|
||||||
eventBus.addListener(plugin);
|
eventBus.addListener(plugin);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
package org.briarproject.plugins.tor;
|
package org.briarproject.bramble.plugin.tor;
|
||||||
|
|
||||||
import org.briarproject.api.plugins.Plugin;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.duplex.AbstractDuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.Plugin;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.AbstractDuplexTransportConnection;
|
||||||
|
import org.briarproject.bramble.util.IoUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
class TorTransportConnection extends AbstractDuplexTransportConnection {
|
class TorTransportConnection extends AbstractDuplexTransportConnection {
|
||||||
|
|
||||||
private final Socket socket;
|
private final Socket socket;
|
||||||
@@ -19,12 +22,12 @@ class TorTransportConnection extends AbstractDuplexTransportConnection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected InputStream getInputStream() throws IOException {
|
protected InputStream getInputStream() throws IOException {
|
||||||
return socket.getInputStream();
|
return IoUtils.getInputStream(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected OutputStream getOutputStream() throws IOException {
|
protected OutputStream getOutputStream() throws IOException {
|
||||||
return socket.getOutputStream();
|
return IoUtils.getOutputStream(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package org.briarproject.system;
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
import org.briarproject.android.api.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
@@ -27,14 +27,11 @@ class AndroidExecutorImpl implements AndroidExecutor {
|
|||||||
@Inject
|
@Inject
|
||||||
AndroidExecutorImpl(Application app) {
|
AndroidExecutorImpl(Application app) {
|
||||||
uiHandler = new Handler(app.getApplicationContext().getMainLooper());
|
uiHandler = new Handler(app.getApplicationContext().getMainLooper());
|
||||||
loop = new Runnable() {
|
loop = () -> {
|
||||||
@Override
|
Looper.prepare();
|
||||||
public void run() {
|
backgroundHandler = new Handler();
|
||||||
Looper.prepare();
|
startLatch.countDown();
|
||||||
backgroundHandler = new Handler();
|
Looper.loop();
|
||||||
startLatch.countDown();
|
|
||||||
Looper.loop();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.system;
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
@@ -6,7 +6,8 @@ import android.content.Context;
|
|||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.briarproject.api.system.LocationUtils;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -15,6 +16,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import static android.content.Context.TELEPHONY_SERVICE;
|
import static android.content.Context.TELEPHONY_SERVICE;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
class AndroidLocationUtils implements LocationUtils {
|
class AndroidLocationUtils implements LocationUtils {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
@@ -23,7 +25,7 @@ class AndroidLocationUtils implements LocationUtils {
|
|||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AndroidLocationUtils(Application app) {
|
AndroidLocationUtils(Application app) {
|
||||||
appContext = app.getApplicationContext();
|
appContext = app.getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +46,7 @@ class AndroidLocationUtils implements LocationUtils {
|
|||||||
* some reason - both that class and {@code Context.COUNTRY_CODE} are
|
* some reason - both that class and {@code Context.COUNTRY_CODE} are
|
||||||
* annotated {@code @hide}.
|
* annotated {@code @hide}.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
public String getCurrentCountry() {
|
public String getCurrentCountry() {
|
||||||
String countryCode = getCountryFromPhoneNetwork();
|
String countryCode = getCountryFromPhoneNetwork();
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.wifi.WifiConfiguration;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static android.content.Context.WIFI_SERVICE;
|
||||||
|
import static android.provider.Settings.Secure.ANDROID_ID;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
class AndroidSecureRandomProvider extends LinuxSecureRandomProvider {
|
||||||
|
|
||||||
|
private static final int SEED_LENGTH = 32;
|
||||||
|
|
||||||
|
private final Context appContext;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
AndroidSecureRandomProvider(Application app) {
|
||||||
|
appContext = app.getApplicationContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeToEntropyPool(DataOutputStream out) throws IOException {
|
||||||
|
super.writeToEntropyPool(out);
|
||||||
|
out.writeInt(android.os.Process.myPid());
|
||||||
|
out.writeInt(android.os.Process.myTid());
|
||||||
|
out.writeInt(android.os.Process.myUid());
|
||||||
|
if (Build.FINGERPRINT != null) out.writeUTF(Build.FINGERPRINT);
|
||||||
|
if (Build.SERIAL != null) out.writeUTF(Build.SERIAL);
|
||||||
|
ContentResolver contentResolver = appContext.getContentResolver();
|
||||||
|
String id = Settings.Secure.getString(contentResolver, ANDROID_ID);
|
||||||
|
if (id != null) out.writeUTF(id);
|
||||||
|
Parcel parcel = Parcel.obtain();
|
||||||
|
WifiManager wm =
|
||||||
|
(WifiManager) appContext.getSystemService(WIFI_SERVICE);
|
||||||
|
List<WifiConfiguration> configs = wm.getConfiguredNetworks();
|
||||||
|
if (configs != null) {
|
||||||
|
for (WifiConfiguration config : configs)
|
||||||
|
parcel.writeParcelable(config, 0);
|
||||||
|
}
|
||||||
|
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
if (bt != null) {
|
||||||
|
for (BluetoothDevice device : bt.getBondedDevices())
|
||||||
|
parcel.writeParcelable(device, 0);
|
||||||
|
}
|
||||||
|
out.write(parcel.marshall());
|
||||||
|
parcel.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeSeed() {
|
||||||
|
super.writeSeed();
|
||||||
|
if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT <= 18)
|
||||||
|
applyOpenSslFix();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Based on https://android-developers.googleblog.com/2013/08/some-securerandom-thoughts.html
|
||||||
|
private void applyOpenSslFix() {
|
||||||
|
byte[] seed = new LinuxSecureRandomSpi().engineGenerateSeed(
|
||||||
|
SEED_LENGTH);
|
||||||
|
try {
|
||||||
|
// Seed the OpenSSL PRNG
|
||||||
|
Class.forName("org.apache.harmony.xnet.provider.jsse.NativeCrypto")
|
||||||
|
.getMethod("RAND_seed", byte[].class)
|
||||||
|
.invoke(null, seed);
|
||||||
|
// Mix the output of the Linux PRNG into the OpenSSL PRNG
|
||||||
|
int bytesRead = (Integer) Class.forName(
|
||||||
|
"org.apache.harmony.xnet.provider.jsse.NativeCrypto")
|
||||||
|
.getMethod("RAND_load_file", String.class, long.class)
|
||||||
|
.invoke(null, "/dev/urandom", 1024);
|
||||||
|
if (bytesRead != 1024) throw new IOException();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SecurityException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
|
import org.briarproject.bramble.api.system.SecureRandomProvider;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class AndroidSystemModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
SecureRandomProvider provideSecureRandomProvider(Application app) {
|
||||||
|
return new AndroidSecureRandomProvider(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
LocationUtils provideLocationUtils(Application app) {
|
||||||
|
return new AndroidLocationUtils(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
AndroidExecutor provideAndroidExecutor(Application app) {
|
||||||
|
return new AndroidExecutorImpl(app);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,212 @@
|
|||||||
|
package org.briarproject.bramble.util;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.Network;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.wifi.WifiInfo;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.InterfaceAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static android.content.Context.CONNECTIVITY_SERVICE;
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
import static android.content.Context.WIFI_SERVICE;
|
||||||
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
import static java.net.NetworkInterface.getNetworkInterfaces;
|
||||||
|
import static java.util.Collections.list;
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static org.briarproject.bramble.util.StringUtils.ipToString;
|
||||||
|
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
||||||
|
|
||||||
|
@SuppressLint("HardwareIds")
|
||||||
|
public class AndroidUtils {
|
||||||
|
|
||||||
|
// Fake Bluetooth address returned by BluetoothAdapter on API 23 and later
|
||||||
|
private static final String FAKE_BLUETOOTH_ADDRESS = "02:00:00:00:00:00";
|
||||||
|
|
||||||
|
private static final String STORED_REPORTS = "dev-reports";
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static Collection<String> getSupportedArchitectures() {
|
||||||
|
List<String> abis = new ArrayList<>();
|
||||||
|
if (SDK_INT >= 21) {
|
||||||
|
abis.addAll(Arrays.asList(Build.SUPPORTED_ABIS));
|
||||||
|
} else {
|
||||||
|
abis.add(Build.CPU_ABI);
|
||||||
|
if (Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
|
||||||
|
}
|
||||||
|
return abis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getBluetoothAddress(Context ctx,
|
||||||
|
BluetoothAdapter adapter) {
|
||||||
|
// Return the adapter's address if it's valid and not fake
|
||||||
|
String address = adapter.getAddress();
|
||||||
|
if (isValidBluetoothAddress(address)) return address;
|
||||||
|
// Return the address from settings if it's valid and not fake
|
||||||
|
address = Settings.Secure.getString(ctx.getContentResolver(),
|
||||||
|
"bluetooth_address");
|
||||||
|
if (isValidBluetoothAddress(address)) return address;
|
||||||
|
// Let the caller know we can't find the address
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isValidBluetoothAddress(String address) {
|
||||||
|
return !StringUtils.isNullOrEmpty(address)
|
||||||
|
&& BluetoothAdapter.checkBluetoothAddress(address)
|
||||||
|
&& !address.equals(FAKE_BLUETOOTH_ADDRESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteAppData(Context ctx) {
|
||||||
|
File dataDir = new File(ctx.getApplicationInfo().dataDir);
|
||||||
|
File[] children = dataDir.listFiles();
|
||||||
|
if (children != null) {
|
||||||
|
for (File child : children) {
|
||||||
|
if (!child.getName().equals("lib"))
|
||||||
|
IoUtils.deleteFileOrDir(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Recreate the cache dir as some OpenGL drivers expect it to exist
|
||||||
|
new File(dataDir, "cache").mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getReportDir(Context ctx) {
|
||||||
|
return ctx.getDir(STORED_REPORTS, MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void logNetworkState(Context ctx, Logger logger) {
|
||||||
|
if (!logger.isLoggable(INFO)) return;
|
||||||
|
|
||||||
|
Object o = ctx.getSystemService(CONNECTIVITY_SERVICE);
|
||||||
|
if (o == null) throw new AssertionError();
|
||||||
|
ConnectivityManager cm = (ConnectivityManager) o;
|
||||||
|
o = ctx.getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||||
|
if (o == null) throw new AssertionError();
|
||||||
|
WifiManager wm = (WifiManager) o;
|
||||||
|
|
||||||
|
StringBuilder s = new StringBuilder();
|
||||||
|
logWifiInfo(s, wm.getConnectionInfo());
|
||||||
|
logNetworkInfo(s, cm.getActiveNetworkInfo(), true);
|
||||||
|
if (SDK_INT >= 21) {
|
||||||
|
for (Network network : cm.getAllNetworks())
|
||||||
|
logNetworkInfo(s, cm.getNetworkInfo(network), false);
|
||||||
|
} else {
|
||||||
|
for (NetworkInfo info : cm.getAllNetworkInfo())
|
||||||
|
logNetworkInfo(s, info, false);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
for (NetworkInterface iface : list(getNetworkInterfaces()))
|
||||||
|
logNetworkInterface(s, iface);
|
||||||
|
} catch (SocketException e) {
|
||||||
|
logger.log(WARNING, e.toString(), e);
|
||||||
|
}
|
||||||
|
logger.log(INFO, s.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void logWifiInfo(StringBuilder s, @Nullable WifiInfo info) {
|
||||||
|
if (info == null) {
|
||||||
|
s.append("Wifi info: null\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
s.append("Wifi info:\n");
|
||||||
|
s.append("\tSSID: ").append(info.getSSID()).append("\n");
|
||||||
|
s.append("\tBSSID: ").append(info.getBSSID()).append("\n");
|
||||||
|
s.append("\tMAC address: ").append(info.getMacAddress()).append("\n");
|
||||||
|
s.append("\tIP address: ")
|
||||||
|
.append(ipToString(info.getIpAddress())).append("\n");
|
||||||
|
s.append("\tSupplicant state: ")
|
||||||
|
.append(info.getSupplicantState()).append("\n");
|
||||||
|
s.append("\tNetwork ID: ").append(info.getNetworkId()).append("\n");
|
||||||
|
s.append("\tLink speed: ").append(info.getLinkSpeed()).append("\n");
|
||||||
|
s.append("\tRSSI: ").append(info.getRssi()).append("\n");
|
||||||
|
if (info.getHiddenSSID()) s.append("\tHidden SSID\n");
|
||||||
|
if (SDK_INT >= 21)
|
||||||
|
s.append("\tFrequency: ").append(info.getFrequency()).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void logNetworkInfo(StringBuilder s,
|
||||||
|
@Nullable NetworkInfo info, boolean active) {
|
||||||
|
if (info == null) {
|
||||||
|
if (active) s.append("Active network info: null\n");
|
||||||
|
else s.append("Network info: null\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (active) s.append("Active network info:\n");
|
||||||
|
else s.append("Network info:\n");
|
||||||
|
s.append("\tType: ").append(info.getTypeName())
|
||||||
|
.append(" (").append(info.getType()).append(")\n");
|
||||||
|
s.append("\tSubtype: ").append(info.getSubtypeName())
|
||||||
|
.append(" (").append(info.getSubtype()).append(")\n");
|
||||||
|
s.append("\tState: ").append(info.getState()).append("\n");
|
||||||
|
s.append("\tDetailed state: ")
|
||||||
|
.append(info.getDetailedState()).append("\n");
|
||||||
|
s.append("\tReason: ").append(info.getReason()).append("\n");
|
||||||
|
s.append("\tExtra info: ").append(info.getExtraInfo()).append("\n");
|
||||||
|
if (info.isAvailable()) s.append("\tAvailable\n");
|
||||||
|
if (info.isConnected()) s.append("\tConnected\n");
|
||||||
|
if (info.isConnectedOrConnecting())
|
||||||
|
s.append("\tConnected or connecting\n");
|
||||||
|
if (info.isFailover()) s.append("\tFailover\n");
|
||||||
|
if (info.isRoaming()) s.append("\tRoaming\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void logNetworkInterface(StringBuilder s,
|
||||||
|
NetworkInterface iface) throws SocketException {
|
||||||
|
s.append("Network interface:\n");
|
||||||
|
s.append("\tName: ").append(iface.getName()).append("\n");
|
||||||
|
s.append("\tDisplay name: ")
|
||||||
|
.append(iface.getDisplayName()).append("\n");
|
||||||
|
s.append("\tHardware address: ")
|
||||||
|
.append(hexOrNull(iface.getHardwareAddress())).append("\n");
|
||||||
|
if (iface.isLoopback()) s.append("\tLoopback\n");
|
||||||
|
if (iface.isPointToPoint()) s.append("\tPoint-to-point\n");
|
||||||
|
if (iface.isVirtual()) s.append("\tVirtual\n");
|
||||||
|
if (iface.isUp()) s.append("\tUp\n");
|
||||||
|
if (SDK_INT >= 19)
|
||||||
|
s.append("\tIndex: ").append(iface.getIndex()).append("\n");
|
||||||
|
for (InterfaceAddress addr : iface.getInterfaceAddresses()) {
|
||||||
|
s.append("\tInterface address:\n");
|
||||||
|
logInetAddress(s, addr.getAddress());
|
||||||
|
s.append("\t\tPrefix length: ")
|
||||||
|
.append(addr.getNetworkPrefixLength()).append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void logInetAddress(StringBuilder s, InetAddress addr) {
|
||||||
|
s.append("\t\tAddress: ")
|
||||||
|
.append(hexOrNull(addr.getAddress())).append("\n");
|
||||||
|
s.append("\t\tHost address: ")
|
||||||
|
.append(addr.getHostAddress()).append("\n");
|
||||||
|
if (addr.isLoopbackAddress()) s.append("\t\tLoopback\n");
|
||||||
|
if (addr.isLinkLocalAddress()) s.append("\t\tLink-local\n");
|
||||||
|
if (addr.isSiteLocalAddress()) s.append("\t\tSite-local\n");
|
||||||
|
if (addr.isAnyLocalAddress()) s.append("\t\tAny local (wildcard)\n");
|
||||||
|
if (addr.isMCNodeLocal()) s.append("\t\tMulticast node-local\n");
|
||||||
|
if (addr.isMCLinkLocal()) s.append("\t\tMulticast link-local\n");
|
||||||
|
if (addr.isMCSiteLocal()) s.append("\t\tMulticast site-local\n");
|
||||||
|
if (addr.isMCOrgLocal()) s.append("\t\tMulticast org-local\n");
|
||||||
|
if (addr.isMCGlobal()) s.append("\t\tMulticast global\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static String hexOrNull(@Nullable byte[] b) {
|
||||||
|
return b == null ? null : toHexString(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
3
bramble-android/src/main/res/values/strings.xml
Normal file
3
bramble-android/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">Bramble</string>
|
||||||
|
</resources>
|
||||||
55
bramble-api/build.gradle
Normal file
55
bramble-api/build.gradle
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
apply plugin: 'java-library'
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
|
apply plugin: 'witness'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "com.google.dagger:dagger:2.0.2"
|
||||||
|
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||||
|
|
||||||
|
testImplementation 'junit:junit:4.12'
|
||||||
|
testImplementation "org.jmock:jmock:2.8.2"
|
||||||
|
testImplementation "org.jmock:jmock-junit4:2.8.2"
|
||||||
|
testImplementation "org.jmock:jmock-legacy:2.8.2"
|
||||||
|
testImplementation "org.hamcrest:hamcrest-library:1.3"
|
||||||
|
testImplementation "org.hamcrest:hamcrest-core:1.3"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencyVerification {
|
||||||
|
verify = [
|
||||||
|
'cglib:cglib:3.2.0:cglib-3.2.0.jar:adb13bab79712ad6bdf1bd59f2a3918018a8016e722e8a357065afb9e6690861',
|
||||||
|
'com.google.code.findbugs:jsr305:3.0.2:jsr305-3.0.2.jar:766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7',
|
||||||
|
'com.google.dagger:dagger:2.0.2:dagger-2.0.2.jar:84c0282ed8be73a29e0475d639da030b55dee72369e58dd35ae7d4fe6243dcf9',
|
||||||
|
'javax.inject:javax.inject:1:javax.inject-1.jar:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
|
||||||
|
'junit:junit:4.12:junit-4.12.jar:59721f0805e223d84b90677887d9ff567dc534d7c502ca903c0c2b17f05c116a',
|
||||||
|
'org.apache.ant:ant-launcher:1.9.4:ant-launcher-1.9.4.jar:7bccea20b41801ca17bcbc909a78c835d0f443f12d639c77bd6ae3d05861608d',
|
||||||
|
'org.apache.ant:ant:1.9.4:ant-1.9.4.jar:649ae0730251de07b8913f49286d46bba7b92d47c5f332610aa426c4f02161d8',
|
||||||
|
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
|
||||||
|
'org.hamcrest:hamcrest-core:1.3:hamcrest-core-1.3.jar:66fdef91e9739348df7a096aa384a5685f4e875584cce89386a7a47251c4d8e9',
|
||||||
|
'org.hamcrest:hamcrest-library:1.3:hamcrest-library-1.3.jar:711d64522f9ec410983bd310934296da134be4254a125080a0416ec178dfad1c',
|
||||||
|
'org.jmock:jmock-junit4:2.8.2:jmock-junit4-2.8.2.jar:f7ee4df4f7bd7b7f1cafad3b99eb74d579f109d5992ff625347352edb55e674c',
|
||||||
|
'org.jmock:jmock-legacy:2.8.2:jmock-legacy-2.8.2.jar:f2b985a5c08a9edb7f37612330c058809da3f6a6d63ce792426ebf8ff0d6d31b',
|
||||||
|
'org.jmock:jmock-testjar:2.8.2:jmock-testjar-2.8.2.jar:8900860f72c474e027cf97fe78dcbf154a1aa7fc62b6845c5fb4e4f3c7bc8760',
|
||||||
|
'org.jmock:jmock:2.8.2:jmock-2.8.2.jar:6c73cb4a2e6dbfb61fd99c9a768539c170ab6568e57846bd60dbf19596b65b16',
|
||||||
|
'org.objenesis:objenesis:2.1:objenesis-2.1.jar:c74330cc6b806c804fd37e74487b4fe5d7c2750c5e15fbc6efa13bdee1bdef80',
|
||||||
|
'org.ow2.asm:asm:5.0.4:asm-5.0.4.jar:896618ed8ae62702521a78bc7be42b7c491a08e6920a15f89a3ecdec31e9a220',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// needed to make test output available to bramble-core and briar-core
|
||||||
|
configurations {
|
||||||
|
testOutput.extendsFrom(testCompile)
|
||||||
|
}
|
||||||
|
task jarTest(type: Jar, dependsOn: testClasses) {
|
||||||
|
from sourceSets.test.output
|
||||||
|
classifier = 'test'
|
||||||
|
}
|
||||||
|
artifacts {
|
||||||
|
testOutput jarTest
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a Java 6 JRE is available, check we're not using any Java 7 or 8 APIs
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
useJava6StandardLibrary(it)
|
||||||
|
}
|
||||||
@@ -1,11 +1,18 @@
|
|||||||
package org.briarproject.api;
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around a byte array, to allow it to be stored in maps etc.
|
* A wrapper around a byte array, to allow it to be stored in maps etc.
|
||||||
*/
|
*/
|
||||||
|
@ThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
public class Bytes implements Comparable<Bytes> {
|
public class Bytes implements Comparable<Bytes> {
|
||||||
|
|
||||||
public static final BytesComparator COMPARATOR = new BytesComparator();
|
public static final BytesComparator COMPARATOR = new BytesComparator();
|
||||||
@@ -47,6 +54,12 @@ public class Bytes implements Comparable<Bytes> {
|
|||||||
return aBytes.length - bBytes.length;
|
return aBytes.length - bBytes.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName() +
|
||||||
|
"(" + StringUtils.toHexString(getBytes()) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
public static class BytesComparator implements Comparator<Bytes> {
|
public static class BytesComparator implements Comparator<Bytes> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception that indicates an unrecoverable formatting error.
|
||||||
|
*/
|
||||||
|
public class FormatException extends IOException {
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
@NotThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
|
public class Multiset<T> {
|
||||||
|
|
||||||
|
private final Map<T, Integer> map = new HashMap<>();
|
||||||
|
|
||||||
|
private int total = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns how many items the multiset contains in total.
|
||||||
|
*/
|
||||||
|
public int getTotal() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns how many unique items the multiset contains.
|
||||||
|
*/
|
||||||
|
public int getUnique() {
|
||||||
|
return map.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns how many of the given item the multiset contains.
|
||||||
|
*/
|
||||||
|
public int getCount(T t) {
|
||||||
|
Integer count = map.get(t);
|
||||||
|
return count == null ? 0 : count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the given item to the multiset and returns how many of the item
|
||||||
|
* the multiset now contains.
|
||||||
|
*/
|
||||||
|
public int add(T t) {
|
||||||
|
Integer count = map.get(t);
|
||||||
|
if (count == null) count = 0;
|
||||||
|
map.put(t, count + 1);
|
||||||
|
total++;
|
||||||
|
return count + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the given item from the multiset and returns how many of the
|
||||||
|
* item the multiset now contains.
|
||||||
|
* @throws NoSuchElementException if the item is not in the multiset.
|
||||||
|
*/
|
||||||
|
public int remove(T t) {
|
||||||
|
Integer count = map.get(t);
|
||||||
|
if (count == null) throw new NoSuchElementException();
|
||||||
|
if (count == 1) map.remove(t);
|
||||||
|
else map.put(t, count - 1);
|
||||||
|
total--;
|
||||||
|
return count - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all occurrences of the given item from the multiset.
|
||||||
|
*/
|
||||||
|
public int removeAll(T t) {
|
||||||
|
Integer count = map.remove(t);
|
||||||
|
if (count == null) return 0;
|
||||||
|
total -= count;
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the multiset contains any occurrences of the given item.
|
||||||
|
*/
|
||||||
|
public boolean contains(T t) {
|
||||||
|
return map.containsKey(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all items from the multiset.
|
||||||
|
*/
|
||||||
|
public void clear() {
|
||||||
|
map.clear();
|
||||||
|
total = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the set of unique items the multiset contains. The returned set
|
||||||
|
* is unmodifiable.
|
||||||
|
*/
|
||||||
|
public Set<T> keySet() {
|
||||||
|
return Collections.unmodifiableSet(map.keySet());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
package org.briarproject.api;
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class StringMap extends Hashtable<String, String> {
|
public abstract class StringMap extends Hashtable<String, String> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 2497176435908100448L;
|
|
||||||
|
|
||||||
protected StringMap(Map<String, String> m) {
|
protected StringMap(Map<String, String> m) {
|
||||||
super(m);
|
super(m);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
@ThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
|
public abstract class UniqueId extends Bytes {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of a unique identifier in bytes.
|
||||||
|
*/
|
||||||
|
public static final int LENGTH = 32;
|
||||||
|
|
||||||
|
protected UniqueId(byte[] id) {
|
||||||
|
super(id);
|
||||||
|
if (id.length != LENGTH) throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception that indicates an unrecoverable version mismatch.
|
||||||
|
*/
|
||||||
|
public class UnsupportedVersionException extends IOException {
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.briarproject.api.clients;
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
import org.briarproject.api.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -23,7 +23,7 @@ public class BdfMessageContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BdfMessageContext(BdfDictionary dictionary) {
|
public BdfMessageContext(BdfDictionary dictionary) {
|
||||||
this(dictionary, Collections.<MessageId>emptyList());
|
this(dictionary, Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BdfDictionary getDictionary() {
|
public BdfDictionary getDictionary() {
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
|
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||||
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
|
import org.briarproject.bramble.api.sync.InvalidMessageException;
|
||||||
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageContext;
|
||||||
|
import org.briarproject.bramble.api.sync.ValidationManager.MessageValidator;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||||
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public abstract class BdfMessageValidator implements MessageValidator {
|
||||||
|
|
||||||
|
protected static final Logger LOG =
|
||||||
|
Logger.getLogger(BdfMessageValidator.class.getName());
|
||||||
|
|
||||||
|
protected final ClientHelper clientHelper;
|
||||||
|
protected final MetadataEncoder metadataEncoder;
|
||||||
|
protected final Clock clock;
|
||||||
|
|
||||||
|
protected BdfMessageValidator(ClientHelper clientHelper,
|
||||||
|
MetadataEncoder metadataEncoder, Clock clock) {
|
||||||
|
this.clientHelper = clientHelper;
|
||||||
|
this.metadataEncoder = metadataEncoder;
|
||||||
|
this.clock = clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract BdfMessageContext validateMessage(Message m, Group g,
|
||||||
|
BdfList body) throws InvalidMessageException, FormatException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageContext validateMessage(Message m, Group g)
|
||||||
|
throws InvalidMessageException {
|
||||||
|
// Reject the message if it's too far in the future
|
||||||
|
long now = clock.currentTimeMillis();
|
||||||
|
if (m.getTimestamp() - now > MAX_CLOCK_DIFFERENCE) {
|
||||||
|
throw new InvalidMessageException(
|
||||||
|
"Timestamp is too far in the future");
|
||||||
|
}
|
||||||
|
byte[] raw = m.getRaw();
|
||||||
|
if (raw.length <= MESSAGE_HEADER_LENGTH) {
|
||||||
|
throw new InvalidMessageException("Message is too short");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
BdfList body = clientHelper.toList(raw, MESSAGE_HEADER_LENGTH,
|
||||||
|
raw.length - MESSAGE_HEADER_LENGTH);
|
||||||
|
BdfMessageContext result = validateMessage(m, g, body);
|
||||||
|
Metadata meta = metadataEncoder.encode(result.getDictionary());
|
||||||
|
return new MessageContext(meta, result.getDependencies());
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new InvalidMessageException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
package org.briarproject.api.clients;
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
import org.briarproject.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.api.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
import org.briarproject.api.data.BdfList;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.sync.Message;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -48,7 +49,8 @@ public interface ClientHelper {
|
|||||||
BdfDictionary getGroupMetadataAsDictionary(Transaction txn, GroupId g)
|
BdfDictionary getGroupMetadataAsDictionary(Transaction txn, GroupId g)
|
||||||
throws DbException, FormatException;
|
throws DbException, FormatException;
|
||||||
|
|
||||||
BdfDictionary getMessageMetadataAsDictionary(MessageId m) throws DbException,
|
BdfDictionary getMessageMetadataAsDictionary(MessageId m)
|
||||||
|
throws DbException,
|
||||||
FormatException;
|
FormatException;
|
||||||
|
|
||||||
BdfDictionary getMessageMetadataAsDictionary(Transaction txn, MessageId m)
|
BdfDictionary getMessageMetadataAsDictionary(Transaction txn, MessageId m)
|
||||||
@@ -92,10 +94,13 @@ public interface ClientHelper {
|
|||||||
|
|
||||||
BdfList toList(Message m) throws FormatException;
|
BdfList toList(Message m) throws FormatException;
|
||||||
|
|
||||||
|
BdfList toList(Author a);
|
||||||
|
|
||||||
byte[] sign(String label, BdfList toSign, byte[] privateKey)
|
byte[] sign(String label, BdfList toSign, byte[] privateKey)
|
||||||
throws FormatException, GeneralSecurityException;
|
throws FormatException, GeneralSecurityException;
|
||||||
|
|
||||||
void verifySignature(String label, byte[] sig, byte[] publicKey,
|
void verifySignature(String label, byte[] sig, byte[] publicKey,
|
||||||
BdfList signed) throws FormatException, GeneralSecurityException;
|
BdfList signed) throws FormatException, GeneralSecurityException;
|
||||||
|
|
||||||
|
Author parseAndValidateAuthor(BdfList author) throws FormatException;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.ClientId;
|
||||||
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface ContactGroupFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a group that is not shared with any contacts.
|
||||||
|
*/
|
||||||
|
Group createLocalGroup(ClientId clientId, int clientVersion);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a group for the given client to share with the given contact.
|
||||||
|
*/
|
||||||
|
Group createContactGroup(ClientId clientId, int clientVersion,
|
||||||
|
Contact contact);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a group for the given client to share between the given authors
|
||||||
|
* identified by their AuthorIds.
|
||||||
|
*/
|
||||||
|
Group createContactGroup(ClientId clientId, int clientVersion,
|
||||||
|
AuthorId authorId1, AuthorId authorId2);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
package org.briarproject.api.contact;
|
package org.briarproject.bramble.api.contact;
|
||||||
|
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class Contact {
|
public class Contact {
|
||||||
|
|
||||||
private final ContactId id;
|
private final ContactId id;
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.briarproject.bramble.api.contact;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface ContactExchangeListener {
|
||||||
|
|
||||||
|
void contactExchangeSucceeded(Author remoteAuthor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The exchange failed because the contact already exists.
|
||||||
|
*/
|
||||||
|
void duplicateContact(Author remoteAuthor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A general failure.
|
||||||
|
*/
|
||||||
|
void contactExchangeFailed();
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package org.briarproject.bramble.api.contact;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A task for conducting a contact information exchange with a remote peer.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface ContactExchangeTask {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the contact exchange protocol
|
||||||
|
*/
|
||||||
|
int PROTOCOL_VERSION = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label for deriving Alice's header key from the master secret.
|
||||||
|
*/
|
||||||
|
String ALICE_KEY_LABEL =
|
||||||
|
"org.briarproject.bramble.contact/ALICE_HEADER_KEY";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label for deriving Bob's header key from the master secret.
|
||||||
|
*/
|
||||||
|
String BOB_KEY_LABEL = "org.briarproject.bramble.contact/BOB_HEADER_KEY";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label for deriving Alice's key binding nonce from the master secret.
|
||||||
|
*/
|
||||||
|
String ALICE_NONCE_LABEL = "org.briarproject.bramble.contact/ALICE_NONCE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label for deriving Bob's key binding nonce from the master secret.
|
||||||
|
*/
|
||||||
|
String BOB_NONCE_LABEL = "org.briarproject.bramble.contact/BOB_NONCE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exchanges contact information with a remote peer.
|
||||||
|
*/
|
||||||
|
void startExchange(ContactExchangeListener listener,
|
||||||
|
LocalAuthor localAuthor, SecretKey masterSecret,
|
||||||
|
DuplexTransportConnection conn, TransportId transportId,
|
||||||
|
boolean alice);
|
||||||
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
package org.briarproject.api.contact;
|
package org.briarproject.bramble.api.contact;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type-safe wrapper for an integer that uniquely identifies a contact within
|
* Type-safe wrapper for an integer that uniquely identifies a contact within
|
||||||
* the scope of a single node.
|
* the scope of a single node.
|
||||||
*/
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class ContactId {
|
public class ContactId {
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package org.briarproject.bramble.api.contact;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface ContactManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a hook to be called whenever a contact is added.
|
||||||
|
*/
|
||||||
|
void registerAddContactHook(AddContactHook hook);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a hook to be called whenever a contact is removed.
|
||||||
|
*/
|
||||||
|
void registerRemoveContactHook(RemoveContactHook hook);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a contact within the given transaction associated with the given
|
||||||
|
* local and remote pseudonyms, and returns an ID for the contact.
|
||||||
|
*/
|
||||||
|
ContactId addContact(Transaction txn, Author remote, AuthorId local,
|
||||||
|
SecretKey master, long timestamp, boolean alice, boolean verified,
|
||||||
|
boolean active) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a contact associated with the given local and remote pseudonyms,
|
||||||
|
* and returns an ID for the contact.
|
||||||
|
*/
|
||||||
|
ContactId addContact(Author remote, AuthorId local,
|
||||||
|
SecretKey master, long timestamp, boolean alice, boolean verified,
|
||||||
|
boolean active) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the contact with the given ID.
|
||||||
|
*/
|
||||||
|
Contact getContact(ContactId c) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the contact with the given remoteAuthorId
|
||||||
|
* that was added by the LocalAuthor with the given localAuthorId
|
||||||
|
*
|
||||||
|
* @throws org.briarproject.bramble.api.db.NoSuchContactException
|
||||||
|
*/
|
||||||
|
Contact getContact(AuthorId remoteAuthorId, AuthorId localAuthorId)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the contact with the given remoteAuthorId
|
||||||
|
* that was added by the LocalAuthor with the given localAuthorId
|
||||||
|
*
|
||||||
|
* @throws org.briarproject.bramble.api.db.NoSuchContactException
|
||||||
|
*/
|
||||||
|
Contact getContact(Transaction txn, AuthorId remoteAuthorId,
|
||||||
|
AuthorId localAuthorId) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all active contacts.
|
||||||
|
*/
|
||||||
|
Collection<Contact> getActiveContacts() throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a contact and all associated state.
|
||||||
|
*/
|
||||||
|
void removeContact(ContactId c) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a contact and all associated state.
|
||||||
|
*/
|
||||||
|
void removeContact(Transaction txn, ContactId c) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a contact as active or inactive.
|
||||||
|
*/
|
||||||
|
void setContactActive(Transaction txn, ContactId c, boolean active)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if a contact with this name and public key already exists
|
||||||
|
*/
|
||||||
|
boolean contactExists(Transaction txn, AuthorId remoteAuthorId,
|
||||||
|
AuthorId localAuthorId) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if a contact with this name and public key already exists
|
||||||
|
*/
|
||||||
|
boolean contactExists(AuthorId remoteAuthorId, AuthorId localAuthorId)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
|
interface AddContactHook {
|
||||||
|
void addingContact(Transaction txn, Contact c) throws DbException;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RemoveContactHook {
|
||||||
|
void removingContact(Transaction txn, Contact c) throws DbException;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.briarproject.bramble.api.contact.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a contact is added.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class ContactAddedEvent extends Event {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
private final boolean active;
|
||||||
|
|
||||||
|
public ContactAddedEvent(ContactId contactId, boolean active) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.briarproject.bramble.api.contact.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a contact is removed.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class ContactRemovedEvent extends Event {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
|
||||||
|
public ContactRemovedEvent(ContactId contactId) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.briarproject.bramble.api.contact.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a contact is marked active or inactive.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class ContactStatusChangedEvent extends Event {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
private final boolean active;
|
||||||
|
|
||||||
|
public ContactStatusChangedEvent(ContactId contactId, boolean active) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.briarproject.bramble.api.contact.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a contact is verified.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class ContactVerifiedEvent extends Event {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
|
||||||
|
public ContactVerifiedEvent(ContactId contactId) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface CryptoComponent {
|
||||||
|
|
||||||
|
SecretKey generateSecretKey();
|
||||||
|
|
||||||
|
SecureRandom getSecureRandom();
|
||||||
|
|
||||||
|
KeyPair generateAgreementKeyPair();
|
||||||
|
|
||||||
|
KeyParser getAgreementKeyParser();
|
||||||
|
|
||||||
|
KeyPair generateSignatureKeyPair();
|
||||||
|
|
||||||
|
KeyParser getSignatureKeyParser();
|
||||||
|
|
||||||
|
KeyParser getMessageKeyParser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Derives another secret key from the given secret key.
|
||||||
|
*
|
||||||
|
* @param label a namespaced label indicating the purpose of the derived
|
||||||
|
* key, to prevent it from being repurposed or colliding with a key derived
|
||||||
|
* for another purpose
|
||||||
|
*/
|
||||||
|
SecretKey deriveKey(String label, SecretKey k, byte[]... inputs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Derives a common shared secret from two public keys and one of the
|
||||||
|
* corresponding private keys.
|
||||||
|
*
|
||||||
|
* @param label a namespaced label indicating the purpose of this shared
|
||||||
|
* secret, to prevent it from being repurposed or colliding with a shared
|
||||||
|
* secret derived for another purpose
|
||||||
|
* @param theirPublicKey the public key of the remote party
|
||||||
|
* @param ourKeyPair the key pair of the local party
|
||||||
|
* @return the shared secret
|
||||||
|
*/
|
||||||
|
SecretKey deriveSharedSecret(String label, PublicKey theirPublicKey,
|
||||||
|
KeyPair ourKeyPair, byte[]... inputs)
|
||||||
|
throws GeneralSecurityException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signs the given byte[] with the given private key.
|
||||||
|
*
|
||||||
|
* @param label a namespaced label indicating the purpose of this
|
||||||
|
* signature, to prevent it from being repurposed or colliding with a
|
||||||
|
* signature created for another purpose
|
||||||
|
*/
|
||||||
|
byte[] sign(String label, byte[] toSign, byte[] privateKey)
|
||||||
|
throws GeneralSecurityException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that the given signature is valid for the signed data
|
||||||
|
* and the given public key.
|
||||||
|
*
|
||||||
|
* @param label a namespaced label indicating the purpose of this
|
||||||
|
* signature, to prevent it from being repurposed or colliding with a
|
||||||
|
* signature created for another purpose
|
||||||
|
* @return true if the signature was valid, false otherwise.
|
||||||
|
*/
|
||||||
|
boolean verify(String label, byte[] signedData, byte[] publicKey,
|
||||||
|
byte[] signature) throws GeneralSecurityException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the hash of the given inputs. The inputs are unambiguously
|
||||||
|
* combined by prefixing each input with its length.
|
||||||
|
*
|
||||||
|
* @param label a namespaced label indicating the purpose of this hash, to
|
||||||
|
* prevent it from being repurposed or colliding with a hash created for
|
||||||
|
* another purpose
|
||||||
|
*/
|
||||||
|
byte[] hash(String label, byte[]... inputs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a message authentication code with the given key over the
|
||||||
|
* given inputs. The inputs are unambiguously combined by prefixing each
|
||||||
|
* input with its length.
|
||||||
|
*
|
||||||
|
* @param label a namespaced label indicating the purpose of this MAC, to
|
||||||
|
* prevent it from being repurposed or colliding with a MAC created for
|
||||||
|
* another purpose
|
||||||
|
*/
|
||||||
|
byte[] mac(String label, SecretKey macKey, byte[]... inputs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypts and authenticates the given plaintext so it can be written to
|
||||||
|
* storage. The encryption and authentication keys are derived from the
|
||||||
|
* given password. The ciphertext will be decryptable using the same
|
||||||
|
* password after the app restarts.
|
||||||
|
*/
|
||||||
|
byte[] encryptWithPassword(byte[] plaintext, String password);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrypts and authenticates the given ciphertext that has been read from
|
||||||
|
* storage. The encryption and authentication keys are derived from the
|
||||||
|
* given password. Returns null if the ciphertext cannot be decrypted and
|
||||||
|
* authenticated (for example, if the password is wrong).
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
byte[] decryptWithPassword(byte[] ciphertext, String password);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypts the given plaintext to the given public key.
|
||||||
|
*/
|
||||||
|
byte[] encryptToKey(PublicKey publicKey, byte[] plaintext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes the given data as a hex string divided into lines of the given
|
||||||
|
* length. The line terminator is CRLF.
|
||||||
|
*/
|
||||||
|
String asciiArmour(byte[] b, int lineLength);
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
public interface CryptoConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum length of an agreement public key in bytes.
|
||||||
|
*/
|
||||||
|
int MAX_AGREEMENT_PUBLIC_KEY_BYTES = 32;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum length of a signature public key in bytes.
|
||||||
|
*/
|
||||||
|
int MAX_SIGNATURE_PUBLIC_KEY_BYTES = 32;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum length of a signature in bytes.
|
||||||
|
*/
|
||||||
|
int MAX_SIGNATURE_BYTES = 64;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crypto operations for the key agreement protocol - see
|
||||||
|
* https://code.briarproject.org/akwizgran/briar-spec/blob/master/protocols/BQP.md
|
||||||
|
*/
|
||||||
|
public interface KeyAgreementCrypto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hash label for public key commitment.
|
||||||
|
*/
|
||||||
|
String COMMIT_LABEL = "org.briarproject.bramble.keyagreement/COMMIT";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key derivation label for confirmation record.
|
||||||
|
*/
|
||||||
|
String CONFIRMATION_KEY_LABEL =
|
||||||
|
"org.briarproject.bramble.keyagreement/CONFIRMATION_KEY";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MAC label for confirmation record.
|
||||||
|
*/
|
||||||
|
String CONFIRMATION_MAC_LABEL =
|
||||||
|
"org.briarproject.bramble.keyagreement/CONFIRMATION_MAC";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Derives a commitment to the provided public key.
|
||||||
|
*
|
||||||
|
* @param publicKey the public key
|
||||||
|
* @return the commitment to the provided public key.
|
||||||
|
*/
|
||||||
|
byte[] deriveKeyCommitment(PublicKey publicKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Derives the content of a confirmation record.
|
||||||
|
*
|
||||||
|
* @param sharedSecret the common shared secret
|
||||||
|
* @param theirPayload the key exchange payload of the remote party
|
||||||
|
* @param ourPayload the key exchange payload of the local party
|
||||||
|
* @param theirPublicKey the ephemeral public key of the remote party
|
||||||
|
* @param ourKeyPair our ephemeral key pair of the local party
|
||||||
|
* @param alice true if the local party is Alice
|
||||||
|
* @param aliceRecord true if the confirmation record is for use by Alice
|
||||||
|
* @return the confirmation record
|
||||||
|
*/
|
||||||
|
byte[] deriveConfirmationRecord(SecretKey sharedSecret,
|
||||||
|
byte[] theirPayload, byte[] ourPayload,
|
||||||
|
PublicKey theirPublicKey, KeyPair ourKeyPair,
|
||||||
|
boolean alice, boolean aliceRecord);
|
||||||
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
/** A key pair consisting of a {@link PublicKey} and a {@link PrivateKey). */
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A key pair consisting of a {@link PublicKey} and a {@link PrivateKey).
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class KeyPair {
|
public class KeyPair {
|
||||||
|
|
||||||
private final PublicKey publicKey;
|
private final PublicKey publicKey;
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface KeyParser {
|
public interface KeyParser {
|
||||||
|
|
||||||
PublicKey parsePublicKey(byte[] encodedKey) throws GeneralSecurityException;
|
PublicKey parsePublicKey(byte[] encodedKey) throws GeneralSecurityException;
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface PasswordStrengthEstimator {
|
public interface PasswordStrengthEstimator {
|
||||||
|
|
||||||
float NONE = 0;
|
float NONE = 0;
|
||||||
float WEAK = 0.4f;
|
float WEAK = 0.25f;
|
||||||
float QUITE_WEAK = 0.6f;
|
float QUITE_WEAK = 0.5f;
|
||||||
float QUITE_STRONG = 0.8f;
|
float QUITE_STRONG = 0.75f;
|
||||||
float STRONG = 1;
|
float STRONG = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The private half of a public/private {@link KeyPair}.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface PrivateKey {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the encoded representation of this key.
|
||||||
|
*/
|
||||||
|
byte[] getEncoded();
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The public half of a public/private {@link KeyPair}.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface PublicKey {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the encoded representation of this key.
|
||||||
|
*/
|
||||||
|
byte[] getEncoded();
|
||||||
|
}
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
/** A secret key used for encryption and/or authentication. */
|
/**
|
||||||
|
* A secret key used for encryption and/or authentication.
|
||||||
|
*/
|
||||||
public class SecretKey {
|
public class SecretKey {
|
||||||
|
|
||||||
public static final int LENGTH = 32; // Bytes
|
/**
|
||||||
|
* The length of a secret key in bytes.
|
||||||
|
*/
|
||||||
|
public static final int LENGTH = 32;
|
||||||
|
|
||||||
private final byte[] key;
|
private final byte[] key;
|
||||||
|
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface StreamDecrypter {
|
public interface StreamDecrypter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a frame, decrypts its payload into the given buffer and returns
|
* Reads a frame, decrypts its payload into the given buffer and returns
|
||||||
* the payload length, or -1 if no more frames can be read from the stream.
|
* the payload length, or -1 if no more frames can be read from the stream.
|
||||||
* @throws java.io.IOException if an error occurs while reading the frame,
|
*
|
||||||
|
* @throws IOException if an error occurs while reading the frame,
|
||||||
* or if authenticated decryption fails.
|
* or if authenticated decryption fails.
|
||||||
*/
|
*/
|
||||||
int readFrame(byte[] payload) throws IOException;
|
int readFrame(byte[] payload) throws IOException;
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface StreamDecrypterFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link StreamDecrypter} for decrypting a transport stream.
|
||||||
|
*/
|
||||||
|
StreamDecrypter createStreamDecrypter(InputStream in, StreamContext ctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link StreamDecrypter} for decrypting a contact exchange
|
||||||
|
* stream.
|
||||||
|
*/
|
||||||
|
StreamDecrypter createContactExchangeStreamDecrypter(InputStream in,
|
||||||
|
SecretKey headerKey);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface StreamEncrypter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypts the given frame and writes it to the stream.
|
||||||
|
*/
|
||||||
|
void writeFrame(byte[] payload, int payloadLength, int paddingLength,
|
||||||
|
boolean finalFrame) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flushes the stream.
|
||||||
|
*/
|
||||||
|
void flush() throws IOException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface StreamEncrypterFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link StreamEncrypter} for encrypting a transport stream.
|
||||||
|
*/
|
||||||
|
StreamEncrypter createStreamEncrypter(OutputStream out, StreamContext ctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link StreamEncrypter} for encrypting a contact exchange
|
||||||
|
* stream.
|
||||||
|
*/
|
||||||
|
StreamEncrypter createContactExchangeStreamDecrypter(OutputStream out,
|
||||||
|
SecretKey headerKey);
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crypto operations for the transport security protocol - see
|
||||||
|
* https://code.briarproject.org/akwizgran/briar-spec/blob/master/protocols/BTP.md
|
||||||
|
*/
|
||||||
|
public interface TransportCrypto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Derives initial transport keys for the given transport in the given
|
||||||
|
* rotation period from the given master secret.
|
||||||
|
*
|
||||||
|
* @param alice whether the keys are for use by Alice or Bob.
|
||||||
|
*/
|
||||||
|
TransportKeys deriveTransportKeys(TransportId t, SecretKey master,
|
||||||
|
long rotationPeriod, boolean alice);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotates the given transport keys to the given rotation period. If the
|
||||||
|
* keys are for the given period or any later period they are not rotated.
|
||||||
|
*/
|
||||||
|
TransportKeys rotateTransportKeys(TransportKeys k, long rotationPeriod);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes the pseudo-random tag that is used to recognise a stream.
|
||||||
|
*/
|
||||||
|
void encodeTag(byte[] tag, SecretKey tagKey, int protocolVersion,
|
||||||
|
long streamNumber);
|
||||||
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
import org.briarproject.api.Bytes;
|
import org.briarproject.bramble.api.Bytes;
|
||||||
import org.briarproject.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
|
@NotThreadSafe
|
||||||
|
public class BdfDictionary extends TreeMap<String, Object> {
|
||||||
|
|
||||||
public static final Object NULL_VALUE = new Object();
|
public static final Object NULL_VALUE = new Object();
|
||||||
|
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class BdfEntry implements Entry<String, Object>, Comparable<BdfEntry> {
|
public class BdfEntry implements Entry<String, Object>, Comparable<BdfEntry> {
|
||||||
|
|
||||||
private final String key;
|
private final String key;
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
import org.briarproject.api.Bytes;
|
import org.briarproject.bramble.api.Bytes;
|
||||||
import org.briarproject.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import static org.briarproject.api.data.BdfDictionary.NULL_VALUE;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
public class BdfList extends Vector<Object> {
|
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
|
||||||
|
|
||||||
|
@NotThreadSafe
|
||||||
|
public class BdfList extends ArrayList<Object> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method for constructing lists inline.
|
* Factory method for constructing lists inline.
|
||||||
@@ -1,49 +1,75 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface BdfReader {
|
public interface BdfReader {
|
||||||
|
|
||||||
int DEFAULT_NESTED_LIMIT = 5;
|
int DEFAULT_NESTED_LIMIT = 5;
|
||||||
|
|
||||||
boolean eof() throws IOException;
|
boolean eof() throws IOException;
|
||||||
|
|
||||||
void close() throws IOException;
|
void close() throws IOException;
|
||||||
|
|
||||||
boolean hasNull() throws IOException;
|
boolean hasNull() throws IOException;
|
||||||
|
|
||||||
void readNull() throws IOException;
|
void readNull() throws IOException;
|
||||||
|
|
||||||
void skipNull() throws IOException;
|
void skipNull() throws IOException;
|
||||||
|
|
||||||
boolean hasBoolean() throws IOException;
|
boolean hasBoolean() throws IOException;
|
||||||
|
|
||||||
boolean readBoolean() throws IOException;
|
boolean readBoolean() throws IOException;
|
||||||
|
|
||||||
void skipBoolean() throws IOException;
|
void skipBoolean() throws IOException;
|
||||||
|
|
||||||
boolean hasLong() throws IOException;
|
boolean hasLong() throws IOException;
|
||||||
|
|
||||||
long readLong() throws IOException;
|
long readLong() throws IOException;
|
||||||
|
|
||||||
void skipLong() throws IOException;
|
void skipLong() throws IOException;
|
||||||
|
|
||||||
boolean hasDouble() throws IOException;
|
boolean hasDouble() throws IOException;
|
||||||
|
|
||||||
double readDouble() throws IOException;
|
double readDouble() throws IOException;
|
||||||
|
|
||||||
void skipDouble() throws IOException;
|
void skipDouble() throws IOException;
|
||||||
|
|
||||||
boolean hasString() throws IOException;
|
boolean hasString() throws IOException;
|
||||||
|
|
||||||
String readString(int maxLength) throws IOException;
|
String readString(int maxLength) throws IOException;
|
||||||
|
|
||||||
void skipString() throws IOException;
|
void skipString() throws IOException;
|
||||||
|
|
||||||
boolean hasRaw() throws IOException;
|
boolean hasRaw() throws IOException;
|
||||||
|
|
||||||
byte[] readRaw(int maxLength) throws IOException;
|
byte[] readRaw(int maxLength) throws IOException;
|
||||||
|
|
||||||
void skipRaw() throws IOException;
|
void skipRaw() throws IOException;
|
||||||
|
|
||||||
boolean hasList() throws IOException;
|
boolean hasList() throws IOException;
|
||||||
|
|
||||||
BdfList readList() throws IOException;
|
BdfList readList() throws IOException;
|
||||||
|
|
||||||
void readListStart() throws IOException;
|
void readListStart() throws IOException;
|
||||||
|
|
||||||
boolean hasListEnd() throws IOException;
|
boolean hasListEnd() throws IOException;
|
||||||
|
|
||||||
void readListEnd() throws IOException;
|
void readListEnd() throws IOException;
|
||||||
|
|
||||||
void skipList() throws IOException;
|
void skipList() throws IOException;
|
||||||
|
|
||||||
boolean hasDictionary() throws IOException;
|
boolean hasDictionary() throws IOException;
|
||||||
|
|
||||||
BdfDictionary readDictionary() throws IOException;
|
BdfDictionary readDictionary() throws IOException;
|
||||||
|
|
||||||
void readDictionaryStart() throws IOException;
|
void readDictionaryStart() throws IOException;
|
||||||
|
|
||||||
boolean hasDictionaryEnd() throws IOException;
|
boolean hasDictionaryEnd() throws IOException;
|
||||||
|
|
||||||
void readDictionaryEnd() throws IOException;
|
void readDictionaryEnd() throws IOException;
|
||||||
|
|
||||||
void skipDictionary() throws IOException;
|
void skipDictionary() throws IOException;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface BdfReaderFactory {
|
public interface BdfReaderFactory {
|
||||||
|
|
||||||
BdfReader createReader(InputStream in);
|
BdfReader createReader(InputStream in);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -7,20 +7,30 @@ import java.util.Map;
|
|||||||
public interface BdfWriter {
|
public interface BdfWriter {
|
||||||
|
|
||||||
void flush() throws IOException;
|
void flush() throws IOException;
|
||||||
|
|
||||||
void close() throws IOException;
|
void close() throws IOException;
|
||||||
|
|
||||||
void writeNull() throws IOException;
|
void writeNull() throws IOException;
|
||||||
|
|
||||||
void writeBoolean(boolean b) throws IOException;
|
void writeBoolean(boolean b) throws IOException;
|
||||||
|
|
||||||
void writeLong(long l) throws IOException;
|
void writeLong(long l) throws IOException;
|
||||||
|
|
||||||
void writeDouble(double d) throws IOException;
|
void writeDouble(double d) throws IOException;
|
||||||
|
|
||||||
void writeString(String s) throws IOException;
|
void writeString(String s) throws IOException;
|
||||||
|
|
||||||
void writeRaw(byte[] b) throws IOException;
|
void writeRaw(byte[] b) throws IOException;
|
||||||
|
|
||||||
void writeList(Collection<?> c) throws IOException;
|
void writeList(Collection<?> c) throws IOException;
|
||||||
|
|
||||||
void writeListStart() throws IOException;
|
void writeListStart() throws IOException;
|
||||||
|
|
||||||
void writeListEnd() throws IOException;
|
void writeListEnd() throws IOException;
|
||||||
|
|
||||||
void writeDictionary(Map<?, ?> m) throws IOException;
|
void writeDictionary(Map<?, ?> m) throws IOException;
|
||||||
|
|
||||||
void writeDictionaryStart() throws IOException;
|
void writeDictionaryStart() throws IOException;
|
||||||
|
|
||||||
void writeDictionaryEnd() throws IOException;
|
void writeDictionaryEnd() throws IOException;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface BdfWriterFactory {
|
||||||
|
|
||||||
|
BdfWriter createWriter(OutputStream out);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface MetadataEncoder {
|
||||||
|
|
||||||
|
Metadata encode(BdfDictionary d) throws FormatException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface MetadataParser {
|
||||||
|
|
||||||
|
BdfDictionary parse(Metadata m) throws FormatException;
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a duplicate contact is added to the database. This exception may
|
* Thrown when a duplicate contact is added to the database. This exception may
|
||||||
* occur due to concurrent updates and does not indicate a database error.
|
* occur due to concurrent updates and does not indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class ContactExistsException extends DbException {
|
public class ContactExistsException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when the database uses a newer schema than the current code.
|
||||||
|
*/
|
||||||
|
public class DataTooNewException extends DbException {
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when the database uses an older schema than the current code and
|
||||||
|
* cannot be migrated.
|
||||||
|
*/
|
||||||
|
public class DataTooOldException extends DbException {
|
||||||
|
}
|
||||||
@@ -1,40 +1,49 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.settings.Settings;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.sync.Ack;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.api.sync.ClientId;
|
import org.briarproject.bramble.api.sync.Ack;
|
||||||
import org.briarproject.api.sync.Group;
|
import org.briarproject.bramble.api.sync.ClientId;
|
||||||
import org.briarproject.api.sync.Group.Visibility;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.Group.Visibility;
|
||||||
import org.briarproject.api.sync.Message;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.api.sync.MessageStatus;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.api.sync.Offer;
|
import org.briarproject.bramble.api.sync.MessageStatus;
|
||||||
import org.briarproject.api.sync.Request;
|
import org.briarproject.bramble.api.sync.Offer;
|
||||||
import org.briarproject.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.sync.Request;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.briarproject.bramble.api.sync.ValidationManager;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.briarproject.api.sync.ValidationManager.State;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.sync.ValidationManager.State;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates the database implementation and exposes high-level operations
|
* Encapsulates the database implementation and exposes high-level operations
|
||||||
* to other components.
|
* to other components.
|
||||||
*/
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
public interface DatabaseComponent {
|
public interface DatabaseComponent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the database and returns true if the database already existed.
|
* Opens the database and returns true if the database already existed.
|
||||||
|
*
|
||||||
|
* @throws DataTooNewException if the data uses a newer schema than the
|
||||||
|
* current code
|
||||||
|
* @throws DataTooOldException if the data uses an older schema than the
|
||||||
|
* current code and cannot be migrated
|
||||||
*/
|
*/
|
||||||
boolean open() throws DbException;
|
boolean open(@Nullable MigrationListener listener) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for any open transactions to finish and closes the database.
|
* Waits for any open transactions to finish and closes the database.
|
||||||
@@ -118,8 +127,9 @@ public interface DatabaseComponent {
|
|||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the message with the given ID. The message ID and any other
|
* Deletes the message with the given ID. Unlike
|
||||||
* associated data are not deleted.
|
* {@link #removeMessage(Transaction, MessageId)}, the message ID and any
|
||||||
|
* other associated data are not deleted.
|
||||||
*/
|
*/
|
||||||
void deleteMessage(Transaction txn, MessageId m) throws DbException;
|
void deleteMessage(Transaction txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
@@ -249,31 +259,30 @@ public interface DatabaseComponent {
|
|||||||
Collection<LocalAuthor> getLocalAuthors(Transaction txn) throws DbException;
|
Collection<LocalAuthor> getLocalAuthors(Transaction txn) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the IDs of any messages that need to be validated by the given
|
* Returns the IDs of any messages that need to be validated.
|
||||||
* client.
|
|
||||||
* <p/>
|
* <p/>
|
||||||
* Read-only.
|
* Read-only.
|
||||||
*/
|
*/
|
||||||
Collection<MessageId> getMessagesToValidate(Transaction txn, ClientId c)
|
Collection<MessageId> getMessagesToValidate(Transaction txn)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the IDs of any messages that are valid but pending delivery due
|
* Returns the IDs of any messages that are pending delivery due to
|
||||||
* to dependencies on other messages for the given client.
|
* dependencies on other messages.
|
||||||
* <p/>
|
* <p/>
|
||||||
* Read-only.
|
* Read-only.
|
||||||
*/
|
*/
|
||||||
Collection<MessageId> getPendingMessages(Transaction txn, ClientId c)
|
Collection<MessageId> getPendingMessages(Transaction txn)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the IDs of any messages from the given client
|
* Returns the IDs of any messages that have shared dependents but have
|
||||||
* that have a shared dependent, but are still not shared themselves.
|
* not yet been shared themselves.
|
||||||
* <p/>
|
* <p/>
|
||||||
* Read-only.
|
* Read-only.
|
||||||
*/
|
*/
|
||||||
Collection<MessageId> getMessagesToShare(Transaction txn,
|
Collection<MessageId> getMessagesToShare(Transaction txn)
|
||||||
ClientId c) throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the message with the given ID, in serialised form, or null if
|
* Returns the message with the given ID, in serialised form, or null if
|
||||||
@@ -330,10 +339,10 @@ public interface DatabaseComponent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the IDs and states of all dependencies of the given message.
|
* Returns the IDs and states of all dependencies of the given message.
|
||||||
* Missing dependencies have the state {@link
|
* Missing dependencies have the state
|
||||||
* org.briarproject.api.sync.ValidationManager.State UNKNOWN}.
|
* {@link ValidationManager.State UNKNOWN}.
|
||||||
* Dependencies in other groups have the state {@link
|
* Dependencies in other groups have the state
|
||||||
* org.briarproject.api.sync.ValidationManager.State INVALID}.
|
* {@link ValidationManager.State INVALID}.
|
||||||
* Note that these states are not set on the dependencies themselves; the
|
* Note that these states are not set on the dependencies themselves; the
|
||||||
* returned states should only be taken in the context of the given message.
|
* returned states should only be taken in the context of the given message.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -368,6 +377,16 @@ public interface DatabaseComponent {
|
|||||||
MessageStatus getMessageStatus(Transaction txn, ContactId c, MessageId m)
|
MessageStatus getMessageStatus(Transaction txn, ContactId c, MessageId m)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the next time (in milliseconds since the Unix epoch) when a
|
||||||
|
* message is due to be sent to the given contact. The returned value may
|
||||||
|
* be zero if a message is due to be sent immediately, or Long.MAX_VALUE if
|
||||||
|
* no messages are scheduled to be sent.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
long getNextSendTime(Transaction txn, ContactId c) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all settings in the given namespace.
|
* Returns all settings in the given namespace.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -448,6 +467,11 @@ public interface DatabaseComponent {
|
|||||||
*/
|
*/
|
||||||
void removeLocalAuthor(Transaction txn, AuthorId a) throws DbException;
|
void removeLocalAuthor(Transaction txn, AuthorId a) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a message (and all associated state) from the database.
|
||||||
|
*/
|
||||||
|
void removeMessage(Transaction txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a transport (and all associated state) from the database.
|
* Removes a transport (and all associated state) from the database.
|
||||||
*/
|
*/
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface DatabaseConfig {
|
public interface DatabaseConfig {
|
||||||
|
|
||||||
boolean databaseExists();
|
boolean databaseExists();
|
||||||
@@ -12,10 +16,12 @@ public interface DatabaseConfig {
|
|||||||
|
|
||||||
void setEncryptionKey(SecretKey key);
|
void setEncryptionKey(SecretKey key);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
SecretKey getEncryptionKey();
|
SecretKey getEncryptionKey();
|
||||||
|
|
||||||
void setLocalAuthorName(String nickname);
|
void setLocalAuthorName(String nickname);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
String getLocalAuthorName();
|
String getLocalAuthorName();
|
||||||
|
|
||||||
long getMaxSize();
|
long getMaxSize();
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
@@ -20,6 +20,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||||||
* discarded.
|
* discarded.
|
||||||
*/
|
*/
|
||||||
@Qualifier
|
@Qualifier
|
||||||
@Target({ FIELD, METHOD, PARAMETER })
|
@Target({FIELD, METHOD, PARAMETER})
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
public @interface DatabaseExecutor {}
|
public @interface DatabaseExecutor {
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted and the database is closed.
|
* Thrown when a database operation is attempted and the database is closed.
|
||||||
*/
|
*/
|
||||||
public class DbClosedException extends DbException {
|
public class DbClosedException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
public class DbException extends Exception {
|
public class DbException extends Exception {
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
@NotThreadSafe
|
||||||
|
public class Metadata extends TreeMap<String, byte[]> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special value to indicate that a key is being removed.
|
||||||
|
*/
|
||||||
|
public static final byte[] REMOVE = new byte[0];
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
|
public interface MigrationListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is called when a migration is started while opening the database.
|
||||||
|
* It will be called once for each migration being applied.
|
||||||
|
*/
|
||||||
|
void onMigrationRun();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted for a contact that is not in
|
* Thrown when a database operation is attempted for a contact that is not in
|
||||||
@@ -6,5 +6,4 @@ package org.briarproject.api.db;
|
|||||||
* not indicate a database error.
|
* not indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class NoSuchContactException extends DbException {
|
public class NoSuchContactException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted for a group that is not in the
|
* Thrown when a database operation is attempted for a group that is not in the
|
||||||
@@ -6,5 +6,4 @@ package org.briarproject.api.db;
|
|||||||
* indicate a database error.
|
* indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class NoSuchGroupException extends DbException {
|
public class NoSuchGroupException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted for a pseudonym that is not in
|
* Thrown when a database operation is attempted for a pseudonym that is not in
|
||||||
@@ -6,5 +6,4 @@ package org.briarproject.api.db;
|
|||||||
* not indicate a database error.
|
* not indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class NoSuchLocalAuthorException extends DbException {
|
public class NoSuchLocalAuthorException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted for a message that is not in
|
* Thrown when a database operation is attempted for a message that is not in
|
||||||
@@ -6,5 +6,4 @@ package org.briarproject.api.db;
|
|||||||
* not indicate a database error.
|
* not indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class NoSuchMessageException extends DbException {
|
public class NoSuchMessageException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted for a transport that is not in
|
* Thrown when a database operation is attempted for a transport that is not in
|
||||||
@@ -6,5 +6,4 @@ package org.briarproject.api.db;
|
|||||||
* not indicate a database error.
|
* not indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class NoSuchTransportException extends DbException {
|
public class NoSuchTransportException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around a database transaction. Transactions are not thread-safe.
|
* A wrapper around a database transaction. Transactions are not thread-safe.
|
||||||
*/
|
*/
|
||||||
|
@NotThreadSafe
|
||||||
public class Transaction {
|
public class Transaction {
|
||||||
|
|
||||||
private final Object txn;
|
private final Object txn;
|
||||||
@@ -42,7 +45,7 @@ public class Transaction {
|
|||||||
* committed.
|
* committed.
|
||||||
*/
|
*/
|
||||||
public void attach(Event e) {
|
public void attach(Event e) {
|
||||||
if (events == null) events = new ArrayList<Event>();
|
if (events == null) events = new ArrayList<>();
|
||||||
events.add(e);
|
events.add(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package org.briarproject.bramble.api.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract superclass for events.
|
||||||
|
*/
|
||||||
|
public abstract class Event {
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.briarproject.bramble.api.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface EventBus {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a listener to be notified when events occur.
|
||||||
|
*/
|
||||||
|
void addListener(EventListener l);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a listener.
|
||||||
|
*/
|
||||||
|
void removeListener(EventListener l);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies all listeners of an event.
|
||||||
|
*/
|
||||||
|
void broadcast(Event e);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.briarproject.bramble.api.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for receiving notifications when events occur.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface EventListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an event is broadcast. Implementations of this method must
|
||||||
|
* not block.
|
||||||
|
*/
|
||||||
|
void eventOccurred(Event e);
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pseudonym for a user.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class Author {
|
||||||
|
|
||||||
|
public enum Status {
|
||||||
|
NONE, ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED, OURSELVES
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the author structure.
|
||||||
|
*/
|
||||||
|
public static final int FORMAT_VERSION = 1;
|
||||||
|
|
||||||
|
private final AuthorId id;
|
||||||
|
private final int formatVersion;
|
||||||
|
private final String name;
|
||||||
|
private final byte[] publicKey;
|
||||||
|
|
||||||
|
public Author(AuthorId id, int formatVersion, String name,
|
||||||
|
byte[] publicKey) {
|
||||||
|
int nameLength = StringUtils.toUtf8(name).length;
|
||||||
|
if (nameLength == 0 || nameLength > MAX_AUTHOR_NAME_LENGTH)
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
if (publicKey.length == 0 || publicKey.length > MAX_PUBLIC_KEY_LENGTH)
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
this.id = id;
|
||||||
|
this.formatVersion = formatVersion;
|
||||||
|
this.name = name;
|
||||||
|
this.publicKey = publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the author's unique identifier.
|
||||||
|
*/
|
||||||
|
public AuthorId getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the version of the author structure used to create the author.
|
||||||
|
*/
|
||||||
|
public int getFormatVersion() {
|
||||||
|
return formatVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the author's name.
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the public key used to verify the pseudonym's signatures.
|
||||||
|
*/
|
||||||
|
public byte[] getPublicKey() {
|
||||||
|
return publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return id.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
return o instanceof Author && id.equals(((Author) o).id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_BYTES;
|
||||||
|
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_PUBLIC_KEY_BYTES;
|
||||||
|
|
||||||
|
public interface AuthorConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum length of an author's name in UTF-8 bytes.
|
||||||
|
*/
|
||||||
|
int MAX_AUTHOR_NAME_LENGTH = 50;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum length of a public key in bytes. This applies to the
|
||||||
|
* signature algorithm used by the current {@link Author format version}.
|
||||||
|
*/
|
||||||
|
int MAX_PUBLIC_KEY_LENGTH = MAX_SIGNATURE_PUBLIC_KEY_BYTES;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum length of a signature in bytes. This applies to the
|
||||||
|
* signature algorithm used by the current {@link Author format version}.
|
||||||
|
*/
|
||||||
|
int MAX_SIGNATURE_LENGTH = MAX_SIGNATURE_BYTES;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user