mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Compare commits
460 Commits
377_replac
...
beta-2017-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e51ddb767 | ||
|
|
36f02b36d9 | ||
|
|
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 | ||
|
|
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 | ||
|
|
6fc42f7296 | ||
|
|
55af22ca04 | ||
|
|
b37a7531ca | ||
|
|
6ab8219394 | ||
|
|
7d1ddb6d65 | ||
|
|
f1371f1db8 | ||
|
|
491e0adc9c | ||
|
|
2850763ec6 | ||
|
|
f10ac13350 | ||
|
|
e69139bc24 | ||
|
|
38f46a9c60 | ||
|
|
b0b932a01c | ||
|
|
20de6f1aa5 | ||
|
|
cbdeb0ad32 | ||
|
|
a60414517c | ||
|
|
988c3e4b58 | ||
|
|
b0098fb054 | ||
|
|
a7c28f04de | ||
|
|
4eec29a631 | ||
|
|
76504387ff | ||
|
|
ea0ad08f57 | ||
|
|
e4676517ef | ||
|
|
dbbeb37485 | ||
|
|
89a7f41a07 | ||
|
|
936ee5e95b | ||
|
|
1697c2af04 | ||
|
|
cb8e0beea9 | ||
|
|
98cb077dd9 | ||
|
|
e6a8ad5d49 | ||
|
|
5e4116efa0 | ||
|
|
a01eeafe4e | ||
|
|
c86d971166 | ||
|
|
d5f8808597 | ||
|
|
e98f4901f5 | ||
|
|
9b09b64ad3 | ||
|
|
20708bc156 | ||
|
|
0814458cb9 | ||
|
|
e32313c30b | ||
|
|
593152e7cd | ||
|
|
ab91520813 | ||
|
|
37e61c97ea | ||
|
|
303fcc9ece | ||
|
|
e2bbe7429b | ||
|
|
eaf17c054f | ||
|
|
f97f30ce42 | ||
|
|
f4c26d9cc7 | ||
|
|
68abf8ba1a | ||
|
|
58f6af513d | ||
|
|
c9170fa5a0 | ||
|
|
ec1f4dccdb | ||
|
|
8c3b598ab2 | ||
|
|
bd3bba6e8a | ||
|
|
11fcad89c6 | ||
|
|
007df4288b | ||
|
|
9798654c23 | ||
|
|
7b58d003a1 | ||
|
|
b60f6b0789 | ||
|
|
914b72505a | ||
|
|
24dd4fda69 | ||
|
|
52eb261a11 | ||
|
|
980a6d18bb | ||
|
|
c4a152b543 | ||
|
|
ed728e816e | ||
|
|
efbce95399 | ||
|
|
98c81f71b4 | ||
|
|
da543c1004 | ||
|
|
7ab4d12d83 | ||
|
|
59964c5087 | ||
|
|
b885e49ba2 | ||
|
|
63da860681 | ||
|
|
aa210fc555 | ||
|
|
68f0e91f32 | ||
|
|
3a2205123f | ||
|
|
2837bde774 | ||
|
|
411549dc0a | ||
|
|
ab16ee7465 | ||
|
|
eb66924e21 | ||
|
|
563d897651 | ||
|
|
98cf6b5bba | ||
|
|
ade7e50f65 | ||
|
|
ccc9d53ac7 | ||
|
|
d232529eb3 | ||
|
|
a532f03784 | ||
|
|
5e5bf7ec05 | ||
|
|
7414abd1ce | ||
|
|
dc76ce2be2 | ||
|
|
3eed0bfe81 | ||
|
|
ec8982438a | ||
|
|
501c2dab31 | ||
|
|
2fe69af6d8 | ||
|
|
b20c107010 | ||
|
|
f410e4eddd | ||
|
|
bb82bd70e2 | ||
|
|
138a6e11a7 | ||
|
|
178d72114b | ||
|
|
c1f1eb7dfa | ||
|
|
d2a3804cfe | ||
|
|
fb095c1f4d | ||
|
|
f89d8cbe38 | ||
|
|
d2434123a9 | ||
|
|
edbf5ff5b4 | ||
|
|
32f0b53d15 | ||
|
|
55ecdd9a13 | ||
|
|
e47e3242a6 | ||
|
|
4387bfc5bd | ||
|
|
d11ee5e43b | ||
|
|
ce53589c33 | ||
|
|
e96b3a8c68 | ||
|
|
62040d45b8 | ||
|
|
1809943f1d | ||
|
|
d204757395 | ||
|
|
c640ee8e51 | ||
|
|
04d4ecad05 | ||
|
|
c36bb3e60e | ||
|
|
7327029fca | ||
|
|
81d341374d | ||
|
|
7b884d2425 | ||
|
|
fbcf334941 | ||
|
|
238100bcac | ||
|
|
7c3805260d | ||
|
|
51bcf7b1b8 | ||
|
|
719a53dc94 | ||
|
|
3f9a254a0b | ||
|
|
e810a1265a | ||
|
|
c36f5c795b | ||
|
|
f52186ac8c | ||
|
|
e0f4be931d | ||
|
|
7536c00a34 | ||
|
|
847b6e4179 | ||
|
|
58793068c3 | ||
|
|
7125248677 | ||
|
|
4bad7076e7 | ||
|
|
2bb16bb75f | ||
|
|
b5a427f876 | ||
|
|
b34b4623ed | ||
|
|
f3b9214702 | ||
|
|
36f087c512 | ||
|
|
0c30f16d7e | ||
|
|
4d8a84a48d | ||
|
|
2650f3114e | ||
|
|
dfdde9799f | ||
|
|
114a2dc8f2 | ||
|
|
642fa7df18 | ||
|
|
c85767d2a0 | ||
|
|
55af1b954e | ||
|
|
88272c5d61 | ||
|
|
eaa393a7ed | ||
|
|
19080ad957 | ||
|
|
7eeeb5f1ed | ||
|
|
d55503ee92 | ||
|
|
8448d27d20 | ||
|
|
47d6fc526f | ||
|
|
3da879cfd9 | ||
|
|
8fdce5ba51 | ||
|
|
f759a7506f | ||
|
|
0b11aea7a2 | ||
|
|
aa954cee63 | ||
|
|
68024c264e | ||
|
|
78740a6942 | ||
|
|
9e553ef9c8 | ||
|
|
1147b8ffaf | ||
|
|
67866dbe66 | ||
|
|
8dac2d1ca6 | ||
|
|
b0a5a69b81 | ||
|
|
a18317e912 | ||
|
|
ad7d0d8e74 | ||
|
|
fe79131f4a | ||
|
|
cb61d91074 | ||
|
|
399a4890de | ||
|
|
656a947f5a | ||
|
|
7191967092 | ||
|
|
5ce8b1978d | ||
|
|
c0aa255bb6 | ||
|
|
c79ce61f6d | ||
|
|
0caabda303 | ||
|
|
679b54b2b4 | ||
|
|
349a34ffd8 | ||
|
|
2c8aaa215c | ||
|
|
4f4f1956eb | ||
|
|
e06726b2f9 | ||
|
|
a6e3827127 | ||
|
|
8dc529cc3f | ||
|
|
1e36f21cc8 | ||
|
|
2cc650d85f | ||
|
|
3407d0c0a8 | ||
|
|
ca8d3babaa | ||
|
|
7b627bb427 | ||
|
|
f027b832d4 | ||
|
|
42175dca7a | ||
|
|
5ffcdc4e46 | ||
|
|
e00219c15f | ||
|
|
96666273d3 | ||
|
|
a92f7e1c9f | ||
|
|
02a39f5694 | ||
|
|
a33d7d1663 | ||
|
|
8eeaf4e347 | ||
|
|
835bd86346 | ||
|
|
84b2a171ab | ||
|
|
1df00f5702 | ||
|
|
292e1c3e8e | ||
|
|
c8c0281efc | ||
|
|
e8c48ccf8d | ||
|
|
09baa2ebe1 | ||
|
|
1176741ea4 | ||
|
|
e6def70030 | ||
|
|
1a812f1327 | ||
|
|
8dc3bd2c4c | ||
|
|
c934ec30aa | ||
|
|
d5f6e71cba | ||
|
|
feed2581c9 | ||
|
|
bd1f3fc2bd | ||
|
|
d25f4d1fbe | ||
|
|
e84d1c5996 | ||
|
|
06831bafc3 | ||
|
|
9284167a2e | ||
|
|
df44015ccb | ||
|
|
c4716ca457 | ||
|
|
9bb16b424f | ||
|
|
e8ebdc2884 | ||
|
|
2140a290e4 | ||
|
|
50a70f7649 | ||
|
|
b3e5d1ff85 | ||
|
|
690142ce07 | ||
|
|
82eea6bb77 | ||
|
|
3ad3332649 | ||
|
|
5a0fa5dcc7 | ||
|
|
97223cce97 | ||
|
|
08b191d72e | ||
|
|
06335c2c30 | ||
|
|
8f882dc910 | ||
|
|
0523c4e718 | ||
|
|
7bf4aebdaf | ||
|
|
6db59ffce5 | ||
|
|
e0835ad460 | ||
|
|
c83d4bbb39 | ||
|
|
65b47bb5d2 | ||
|
|
9ce95d6de7 | ||
|
|
9d2c56e75f | ||
|
|
32c4f61e68 | ||
|
|
6e04664915 | ||
|
|
5674ee2d88 | ||
|
|
8637faf858 | ||
|
|
970cbbf557 | ||
|
|
57ac4a5374 | ||
|
|
2b91631ba5 | ||
|
|
b327122255 | ||
|
|
0b3ec9aa4c | ||
|
|
154e02723f | ||
|
|
b09e30a95f | ||
|
|
3ea36bbd40 | ||
|
|
cb983f02c2 | ||
|
|
f1730aa7d9 | ||
|
|
857665db79 | ||
|
|
7f2db71160 | ||
|
|
60dee5c4cb | ||
|
|
784561144a | ||
|
|
70d39d03bc | ||
|
|
48a3db46bc | ||
|
|
f52819f4ca | ||
|
|
457c30f3f2 | ||
|
|
1731369d7a | ||
|
|
064b920626 | ||
|
|
b2fa039474 | ||
|
|
9112d17a4b | ||
|
|
86fbb89637 | ||
|
|
b3bea1f945 | ||
|
|
543304973e | ||
|
|
fc38738428 | ||
|
|
d661fa0661 | ||
|
|
e2eda8fef0 | ||
|
|
604542c19b | ||
|
|
a727a0817e | ||
|
|
3fa84ec7a8 | ||
|
|
e5f5511112 | ||
|
|
16ecb2ce8d | ||
|
|
c49c888f9f | ||
|
|
6b3db67ef5 | ||
|
|
293c06fd61 | ||
|
|
1c55fae704 | ||
|
|
95670937c3 | ||
|
|
165deebb40 | ||
|
|
0b0cae06ae | ||
|
|
f8e0441de8 | ||
|
|
a422c626b3 | ||
|
|
6ece398a21 | ||
|
|
8b50cb1461 | ||
|
|
f28bc691a5 | ||
|
|
42056720fa | ||
|
|
0861ee1f10 | ||
|
|
a30de6309d | ||
|
|
d112b42d20 | ||
|
|
fd6719301a | ||
|
|
92f2e7b0fc | ||
|
|
ee98900613 | ||
|
|
747553f577 | ||
|
|
8a4c162bba | ||
|
|
7e806c8cf2 | ||
|
|
e466ed580c | ||
|
|
d058172429 | ||
|
|
1f0b305139 | ||
|
|
7a0db798d1 | ||
|
|
7e6a522eee | ||
|
|
33795e7046 | ||
|
|
2d59b9095c | ||
|
|
8fb820c967 | ||
|
|
53d0b8b21e | ||
|
|
d389f79a48 | ||
|
|
b278c7d9cb | ||
|
|
a85043efb5 | ||
|
|
133722dd2c | ||
|
|
9e3db12ea2 | ||
|
|
f461ec4ab0 | ||
|
|
e87c301e3a | ||
|
|
17bacc1116 | ||
|
|
401abf2c0c | ||
|
|
a4d08f4cf1 | ||
|
|
eb6189150f | ||
|
|
c917110e6a | ||
|
|
d5beca5351 | ||
|
|
1fdbe65dde | ||
|
|
1583163f88 | ||
|
|
ee35110167 | ||
|
|
72bf701345 | ||
|
|
fd4dbdc081 | ||
|
|
97937428bb | ||
|
|
4be1c1bb7d |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -21,3 +21,5 @@ local.properties
|
|||||||
.gradle
|
.gradle
|
||||||
build/
|
build/
|
||||||
*.iml
|
*.iml
|
||||||
|
.gitignore
|
||||||
|
src/test/
|
||||||
|
|||||||
2
.idea/codeStyleSettings.xml
generated
2
.idea/codeStyleSettings.xml
generated
@@ -31,6 +31,8 @@
|
|||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
<option name="RIGHT_MARGIN" value="100" />
|
<option name="RIGHT_MARGIN" value="100" />
|
||||||
|
<option name="JD_ALIGN_PARAM_COMMENTS" value="false" />
|
||||||
|
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false" />
|
||||||
<AndroidXmlCodeStyleSettings>
|
<AndroidXmlCodeStyleSettings>
|
||||||
<option name="USE_CUSTOM_SETTINGS" value="true" />
|
<option name="USE_CUSTOM_SETTINGS" value="true" />
|
||||||
</AndroidXmlCodeStyleSettings>
|
</AndroidXmlCodeStyleSettings>
|
||||||
|
|||||||
17
LICENSE.txt
17
LICENSE.txt
@@ -13,23 +13,6 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
All files under the directories briar-android/src, briar-api/src,
|
|
||||||
briar-core/src, briar-desktop/src and briar-test/src are licensed
|
|
||||||
under the Apache License, version 2.0 (the "License"); you may not
|
|
||||||
use these files except in compliance with the License.
|
|
||||||
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied. See the License for the specific language governing
|
|
||||||
permissions and limitations under the License.
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
bin
|
bin
|
||||||
gen
|
gen
|
||||||
build
|
build
|
||||||
local.properties
|
|
||||||
.settings
|
.settings
|
||||||
|
src/main/res/raw/*.zip
|
||||||
104
bramble-android/build.gradle
Normal file
104
bramble-android/build.gradle
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
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 23
|
||||||
|
buildToolsVersion "23.0.3"
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 14
|
||||||
|
targetSdkVersion 22
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
consumerProguardFiles 'proguard-rules.txt'
|
||||||
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_7
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile project(':bramble-core')
|
||||||
|
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
|
provided 'javax.annotation:jsr250-api:1.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
def torBinaryDir = 'src/main/res/raw'
|
||||||
|
|
||||||
|
task downloadTorGeoIp(type: Download) {
|
||||||
|
src 'https://briarproject.org/build/geoip-2015-12-01.zip'
|
||||||
|
dest "$torBinaryDir/geoip.zip"
|
||||||
|
onlyIfNewer true
|
||||||
|
}
|
||||||
|
|
||||||
|
task downloadTorBinaryArm(type: Download) {
|
||||||
|
src 'https://briarproject.org/build/tor-0.2.7.6-arm.zip'
|
||||||
|
dest "$torBinaryDir/tor_arm.zip"
|
||||||
|
onlyIfNewer true
|
||||||
|
}
|
||||||
|
|
||||||
|
task downloadTorBinaryArmPie(type: Download) {
|
||||||
|
src 'https://briarproject.org/build/tor-0.2.7.6-arm-pie.zip'
|
||||||
|
dest "$torBinaryDir/tor_arm_pie.zip"
|
||||||
|
onlyIfNewer true
|
||||||
|
}
|
||||||
|
|
||||||
|
task downloadTorBinaryX86(type: Download) {
|
||||||
|
src 'https://briarproject.org/build/tor-0.2.7.6-x86.zip'
|
||||||
|
dest "$torBinaryDir/tor_x86.zip"
|
||||||
|
onlyIfNewer true
|
||||||
|
}
|
||||||
|
|
||||||
|
task downloadTorBinaryX86Pie(type: Download) {
|
||||||
|
src 'https://briarproject.org/build/tor-0.2.7.6-x86-pie.zip'
|
||||||
|
dest "$torBinaryDir/tor_x86_pie.zip"
|
||||||
|
onlyIfNewer true
|
||||||
|
}
|
||||||
|
|
||||||
|
task verifyTorGeoIp(type: Verify, dependsOn: 'downloadTorGeoIp') {
|
||||||
|
src "$torBinaryDir/geoip.zip"
|
||||||
|
algorithm 'SHA-256'
|
||||||
|
checksum '9bcdaf0a7ba0933735328d8ec466c25c25dbb459efc2bce9e55c774eabea5162'
|
||||||
|
}
|
||||||
|
|
||||||
|
task verifyTorBinaryArm(type: Verify, dependsOn: 'downloadTorBinaryArm') {
|
||||||
|
src "$torBinaryDir/tor_arm.zip"
|
||||||
|
algorithm 'SHA-256'
|
||||||
|
checksum '83272962eda701cd5d74d2418651c4ff0f0b1dff51f558a292d1a1c42bf12146'
|
||||||
|
}
|
||||||
|
|
||||||
|
task verifyTorBinaryArmPie(type: Verify, dependsOn: 'downloadTorBinaryArmPie') {
|
||||||
|
src "$torBinaryDir/tor_arm_pie.zip"
|
||||||
|
algorithm 'SHA-256'
|
||||||
|
checksum 'd0300d1e45de11ebb24ed62b9c492be9c2e88590b7822195ab38c7a76ffcf646'
|
||||||
|
}
|
||||||
|
|
||||||
|
task verifyTorBinaryX86(type: Verify, dependsOn: 'downloadTorBinaryX86') {
|
||||||
|
src "$torBinaryDir/tor_x86.zip"
|
||||||
|
algorithm 'SHA-256'
|
||||||
|
checksum 'b8813d97b01ee1b9c9a4233c1b9bbe9f9f6b494ae6f9cbd84de8a3911911615e'
|
||||||
|
}
|
||||||
|
|
||||||
|
task verifyTorBinaryX86Pie(type: Verify, dependsOn: 'downloadTorBinaryX86Pie') {
|
||||||
|
src "$torBinaryDir/tor_x86_pie.zip"
|
||||||
|
algorithm 'SHA-256'
|
||||||
|
checksum '9c66e765aa196dc089951a1b2140cc8290305c2fcbf365121f99e01a233baf4e'
|
||||||
|
}
|
||||||
|
|
||||||
|
project.afterEvaluate {
|
||||||
|
preBuild.dependsOn {
|
||||||
|
[
|
||||||
|
'verifyTorGeoIp',
|
||||||
|
'verifyTorBinaryArm',
|
||||||
|
'verifyTorBinaryArmPie',
|
||||||
|
'verifyTorBinaryX86',
|
||||||
|
'verifyTorBinaryX86Pie'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
15
bramble-android/proguard-rules.txt
Normal file
15
bramble-android/proguard-rules.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
-keep,includedescriptorclasses class org.briarproject.** { *; }
|
||||||
|
|
||||||
|
-keep class org.h2.** { *; }
|
||||||
|
-dontwarn org.h2.**
|
||||||
|
-dontnote org.h2.**
|
||||||
|
|
||||||
|
-keep class dagger.** { *; }
|
||||||
|
-dontwarn dagger.**
|
||||||
|
-dontnote dagger.**
|
||||||
|
|
||||||
|
-dontwarn sun.misc.Unsafe
|
||||||
|
-dontnote com.google.common.**
|
||||||
|
|
||||||
|
# UPnP library isn't used
|
||||||
|
-dontwarn org.bitlet.weupnp.**
|
||||||
24
bramble-android/src/main/AndroidManifest.xml
Normal file
24
bramble-android/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<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"/>
|
||||||
|
<!-- Since API 23, this is needed to add contacts via Bluetooth -->
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||||
|
|
||||||
|
<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;
|
||||||
@@ -1,20 +1,21 @@
|
|||||||
package org.briarproject.plugins;
|
package org.briarproject.bramble.plugin;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.briarproject.android.api.AndroidExecutor;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.api.event.EventBus;
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
import org.briarproject.api.lifecycle.IoExecutor;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.BackoffFactory;
|
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||||
import org.briarproject.api.plugins.PluginConfig;
|
import org.briarproject.bramble.api.plugin.PluginConfig;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||||
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.AndroidExecutor;
|
||||||
import org.briarproject.plugins.droidtooth.DroidtoothPluginFactory;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.plugins.tcp.AndroidLanTcpPluginFactory;
|
import org.briarproject.bramble.plugin.droidtooth.DroidtoothPluginFactory;
|
||||||
import org.briarproject.plugins.tor.TorPluginFactory;
|
import org.briarproject.bramble.plugin.tcp.AndroidLanTcpPluginFactory;
|
||||||
|
import org.briarproject.bramble.plugin.tor.TorPluginFactory;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -28,10 +29,10 @@ import dagger.Module;
|
|||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
public class AndroidPluginsModule {
|
public class AndroidPluginModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
public PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
||||||
AndroidExecutor androidExecutor, SecureRandom random,
|
AndroidExecutor androidExecutor, SecureRandom random,
|
||||||
SocketFactory torSocketFactory, BackoffFactory backoffFactory,
|
SocketFactory torSocketFactory, BackoffFactory backoffFactory,
|
||||||
Application app, LocationUtils locationUtils, DevReporter reporter,
|
Application app, LocationUtils locationUtils, DevReporter reporter,
|
||||||
@@ -46,7 +47,8 @@ public class AndroidPluginsModule {
|
|||||||
backoffFactory, appContext);
|
backoffFactory, appContext);
|
||||||
final Collection<DuplexPluginFactory> duplex =
|
final Collection<DuplexPluginFactory> duplex =
|
||||||
Arrays.asList(bluetooth, tor, lan);
|
Arrays.asList(bluetooth, tor, lan);
|
||||||
return new PluginConfig() {
|
@NotNullByDefault
|
||||||
|
PluginConfig pluginConfig = new PluginConfig() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<DuplexPluginFactory> getDuplexFactories() {
|
public Collection<DuplexPluginFactory> getDuplexFactories() {
|
||||||
@@ -58,5 +60,6 @@ public class AndroidPluginsModule {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
return pluginConfig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.plugins.droidtooth;
|
package org.briarproject.bramble.plugin.droidtooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
@@ -9,21 +9,26 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
|
||||||
import org.briarproject.android.api.AndroidExecutor;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.android.util.AndroidUtils;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.crypto.PseudoRandom;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.api.crypto.PseudoRandom;
|
import org.briarproject.bramble.api.keyagreement.KeyAgreementConnection;
|
||||||
import org.briarproject.api.keyagreement.KeyAgreementConnection;
|
import org.briarproject.bramble.api.keyagreement.KeyAgreementListener;
|
||||||
import org.briarproject.api.keyagreement.KeyAgreementListener;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.api.keyagreement.TransportDescriptor;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.bramble.api.plugin.PluginException;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
@@ -36,6 +41,7 @@ import java.util.Map.Entry;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CompletionService;
|
import java.util.concurrent.CompletionService;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@@ -44,6 +50,8 @@ import java.util.concurrent.Future;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static android.bluetooth.BluetoothAdapter.ACTION_SCAN_MODE_CHANGED;
|
import static android.bluetooth.BluetoothAdapter.ACTION_SCAN_MODE_CHANGED;
|
||||||
import static android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED;
|
import static android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED;
|
||||||
import static android.bluetooth.BluetoothAdapter.EXTRA_SCAN_MODE;
|
import static android.bluetooth.BluetoothAdapter.EXTRA_SCAN_MODE;
|
||||||
@@ -57,24 +65,24 @@ import static android.bluetooth.BluetoothDevice.EXTRA_DEVICE;
|
|||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
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 org.briarproject.util.PrivacyUtils.scrubMacAddress;
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_BLUETOOTH;
|
||||||
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.ID;
|
||||||
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PROP_ADDRESS;
|
||||||
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PROP_UUID;
|
||||||
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.UUID_BYTES;
|
||||||
|
import static org.briarproject.bramble.util.PrivacyUtils.scrubMacAddress;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
class DroidtoothPlugin implements DuplexPlugin {
|
class DroidtoothPlugin implements DuplexPlugin {
|
||||||
|
|
||||||
// Share an ID with the J2SE Bluetooth plugin
|
|
||||||
static final TransportId ID = new TransportId("bt");
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(DroidtoothPlugin.class.getName());
|
Logger.getLogger(DroidtoothPlugin.class.getName());
|
||||||
private static final int UUID_BYTES = 16;
|
|
||||||
private static final String FOUND =
|
private static final String FOUND =
|
||||||
"android.bluetooth.device.action.FOUND";
|
"android.bluetooth.device.action.FOUND";
|
||||||
private static final String DISCOVERY_FINISHED =
|
private static final String DISCOVERY_FINISHED =
|
||||||
"android.bluetooth.adapter.action.DISCOVERY_FINISHED";
|
"android.bluetooth.adapter.action.DISCOVERY_FINISHED";
|
||||||
|
|
||||||
private static final String PROP_ADDRESS = "address";
|
|
||||||
private static final String PROP_UUID = "uuid";
|
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
private final AndroidExecutor androidExecutor;
|
private final AndroidExecutor androidExecutor;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
@@ -121,7 +129,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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();
|
||||||
// BluetoothAdapter.getDefaultAdapter() must be called on a thread
|
// BluetoothAdapter.getDefaultAdapter() must be called on a thread
|
||||||
// with a message queue, so submit it to the AndroidExecutor
|
// with a message queue, so submit it to the AndroidExecutor
|
||||||
@@ -135,13 +143,14 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
}).get();
|
}).get();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw new IOException("Interrupted while getting BluetoothAdapter");
|
LOG.warning("Interrupted while getting BluetoothAdapter");
|
||||||
|
throw new PluginException(e);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw new IOException(e);
|
throw new PluginException(e);
|
||||||
}
|
}
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
LOG.info("Bluetooth is not supported");
|
LOG.info("Bluetooth is not supported");
|
||||||
return false;
|
throw new PluginException();
|
||||||
}
|
}
|
||||||
running = true;
|
running = true;
|
||||||
// Listen for changes to the Bluetooth state
|
// Listen for changes to the Bluetooth state
|
||||||
@@ -163,7 +172,6 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
LOG.info("Not enabling Bluetooth");
|
LOG.info("Not enabling Bluetooth");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bind() {
|
private void bind() {
|
||||||
@@ -217,7 +225,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
return UUID.fromString(uuid);
|
return UUID.fromString(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryToClose(BluetoothServerSocket ss) {
|
private void tryToClose(@Nullable BluetoothServerSocket ss) {
|
||||||
try {
|
try {
|
||||||
if (ss != null) ss.close();
|
if (ss != null) ss.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -305,6 +313,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private BluetoothSocket connect(String address, String uuid) {
|
private BluetoothSocket connect(String address, String uuid) {
|
||||||
// Validate the address
|
// Validate the address
|
||||||
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
|
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
|
||||||
@@ -333,16 +342,18 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
LOG.info("Connected to " + scrubMacAddress(address));
|
LOG.info("Connected to " + scrubMacAddress(address));
|
||||||
return s;
|
return s;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO)) {
|
||||||
LOG.info("Failed to connect to " + scrubMacAddress(address));
|
LOG.info("Failed to connect to " + scrubMacAddress(address)
|
||||||
|
+ ": " + e);
|
||||||
|
}
|
||||||
tryToClose(s);
|
tryToClose(s);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryToClose(BluetoothSocket s) {
|
private void tryToClose(@Nullable Closeable c) {
|
||||||
try {
|
try {
|
||||||
if (s != null) s.close();
|
if (c != null) c.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
}
|
}
|
||||||
@@ -379,7 +390,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
BluetoothServerSocket ss;
|
BluetoothServerSocket ss;
|
||||||
try {
|
try {
|
||||||
ss = adapter.listenUsingInsecureRfcommWithServiceRecord(
|
ss = adapter.listenUsingInsecureRfcommWithServiceRecord(
|
||||||
"RFCOMM", getUuid());
|
"RFCOMM", uuid);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
return null;
|
return null;
|
||||||
@@ -420,7 +431,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void closeSockets(final List<Future<BluetoothSocket>> futures,
|
private void closeSockets(final List<Future<BluetoothSocket>> futures,
|
||||||
final BluetoothSocket chosen) {
|
@Nullable final BluetoothSocket chosen) {
|
||||||
ioExecutor.execute(new Runnable() {
|
ioExecutor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -454,6 +465,9 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public KeyAgreementListener createKeyAgreementListener(byte[] commitment) {
|
public KeyAgreementListener createKeyAgreementListener(byte[] commitment) {
|
||||||
if (!isRunning()) return null;
|
if (!isRunning()) return null;
|
||||||
|
// There's no point listening if we can't discover our own address
|
||||||
|
String address = AndroidUtils.getBluetoothAddress(appContext, adapter);
|
||||||
|
if (address.isEmpty()) return null;
|
||||||
// No truncation necessary because COMMIT_LENGTH = 16
|
// No truncation necessary because COMMIT_LENGTH = 16
|
||||||
UUID uuid = UUID.nameUUIDFromBytes(commitment);
|
UUID uuid = UUID.nameUUIDFromBytes(commitment);
|
||||||
if (LOG.isLoggable(INFO)) LOG.info("Key agreement UUID " + uuid);
|
if (LOG.isLoggable(INFO)) LOG.info("Key agreement UUID " + uuid);
|
||||||
@@ -461,28 +475,28 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
BluetoothServerSocket ss;
|
BluetoothServerSocket ss;
|
||||||
try {
|
try {
|
||||||
ss = adapter.listenUsingInsecureRfcommWithServiceRecord(
|
ss = adapter.listenUsingInsecureRfcommWithServiceRecord(
|
||||||
"RFCOMM", getUuid());
|
"RFCOMM", uuid);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
TransportProperties p = new TransportProperties();
|
BdfList descriptor = new BdfList();
|
||||||
String address = AndroidUtils.getBluetoothAddress(appContext, adapter);
|
descriptor.add(TRANSPORT_ID_BLUETOOTH);
|
||||||
if (!StringUtils.isNullOrEmpty(address))
|
descriptor.add(StringUtils.macToBytes(address));
|
||||||
p.put(PROP_ADDRESS, address);
|
return new BluetoothKeyAgreementListener(descriptor, ss);
|
||||||
TransportDescriptor d = new TransportDescriptor(ID, p);
|
|
||||||
return new BluetoothKeyAgreementListener(d, ss);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DuplexTransportConnection createKeyAgreementConnection(
|
public DuplexTransportConnection createKeyAgreementConnection(
|
||||||
byte[] commitment, TransportDescriptor d, long timeout) {
|
byte[] commitment, BdfList descriptor, long timeout) {
|
||||||
if (!isRunning()) return null;
|
if (!isRunning()) return null;
|
||||||
if (!ID.equals(d.getIdentifier())) return null;
|
String address;
|
||||||
TransportProperties p = d.getProperties();
|
try {
|
||||||
if (p == null) return null;
|
address = parseAddress(descriptor);
|
||||||
String address = p.get(PROP_ADDRESS);
|
} catch (FormatException e) {
|
||||||
if (StringUtils.isNullOrEmpty(address)) return null;
|
LOG.info("Invalid address in key agreement descriptor");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
// No truncation necessary because COMMIT_LENGTH = 16
|
// No truncation necessary because COMMIT_LENGTH = 16
|
||||||
UUID uuid = UUID.nameUUIDFromBytes(commitment);
|
UUID uuid = UUID.nameUUIDFromBytes(commitment);
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
@@ -492,6 +506,12 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
return new DroidtoothTransportConnection(this, s);
|
return new DroidtoothTransportConnection(this, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String parseAddress(BdfList descriptor) throws FormatException {
|
||||||
|
byte[] mac = descriptor.getRaw(1);
|
||||||
|
if (mac.length != 6) throw new FormatException();
|
||||||
|
return StringUtils.macToString(mac);
|
||||||
|
}
|
||||||
|
|
||||||
private class BluetoothStateReceiver extends BroadcastReceiver {
|
private class BluetoothStateReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -560,7 +580,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
private static class DiscoveryReceiver extends BroadcastReceiver {
|
private static class DiscoveryReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
private final CountDownLatch finished = new CountDownLatch(1);
|
private final CountDownLatch finished = new CountDownLatch(1);
|
||||||
private final List<String> addresses = new ArrayList<>();
|
private final List<String> addresses = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context ctx, Intent intent) {
|
public void onReceive(Context ctx, Intent intent) {
|
||||||
@@ -571,17 +591,19 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
finished.countDown();
|
finished.countDown();
|
||||||
} else if (action.equals(FOUND)) {
|
} else if (action.equals(FOUND)) {
|
||||||
BluetoothDevice d = intent.getParcelableExtra(EXTRA_DEVICE);
|
BluetoothDevice d = intent.getParcelableExtra(EXTRA_DEVICE);
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO)) {
|
||||||
LOG.info("Discovered device: " +
|
LOG.info("Discovered device: " +
|
||||||
scrubMacAddress(d.getAddress()));
|
scrubMacAddress(d.getAddress()));
|
||||||
|
}
|
||||||
addresses.add(d.getAddress());
|
addresses.add(d.getAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> waitForAddresses() throws InterruptedException {
|
private List<String> waitForAddresses() throws InterruptedException {
|
||||||
finished.await();
|
finished.await();
|
||||||
Collections.shuffle(addresses);
|
List<String> shuffled = new ArrayList<>(addresses);
|
||||||
return Collections.unmodifiableList(addresses);
|
Collections.shuffle(shuffled);
|
||||||
|
return shuffled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,7 +648,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
|
|
||||||
private final BluetoothServerSocket ss;
|
private final BluetoothServerSocket ss;
|
||||||
|
|
||||||
BluetoothKeyAgreementListener(TransportDescriptor descriptor,
|
private BluetoothKeyAgreementListener(BdfList descriptor,
|
||||||
BluetoothServerSocket ss) {
|
BluetoothServerSocket ss) {
|
||||||
super(descriptor);
|
super(descriptor);
|
||||||
this.ss = ss;
|
this.ss = ss;
|
||||||
@@ -1,18 +1,25 @@
|
|||||||
package org.briarproject.plugins.droidtooth;
|
package org.briarproject.bramble.plugin.droidtooth;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.briarproject.android.api.AndroidExecutor;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.TransportId;
|
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.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.bramble.api.system.AndroidExecutor;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.ID;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||||
@@ -38,7 +45,7 @@ public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransportId getId() {
|
public TransportId getId() {
|
||||||
return DroidtoothPlugin.ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
package org.briarproject.plugins.droidtooth;
|
package org.briarproject.bramble.plugin.droidtooth;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
class DroidtoothTransportConnection extends AbstractDuplexTransportConnection {
|
class DroidtoothTransportConnection extends AbstractDuplexTransportConnection {
|
||||||
|
|
||||||
private final BluetoothSocket socket;
|
private final BluetoothSocket 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;
|
||||||
@@ -7,16 +7,20 @@ import android.content.IntentFilter;
|
|||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
class AndroidLanTcpPlugin extends LanTcpPlugin {
|
class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
@@ -24,6 +28,7 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
|||||||
|
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private volatile BroadcastReceiver networkStateReceiver = null;
|
private volatile BroadcastReceiver networkStateReceiver = null;
|
||||||
|
|
||||||
AndroidLanTcpPlugin(Executor ioExecutor, Backoff backoff,
|
AndroidLanTcpPlugin(Executor ioExecutor, Backoff backoff,
|
||||||
@@ -34,14 +39,13 @@ 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(CONNECTIVITY_ACTION);
|
||||||
appContext.registerReceiver(networkStateReceiver, filter);
|
appContext.registerReceiver(networkStateReceiver, filter);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1,16 +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 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
|
||||||
@@ -32,7 +39,7 @@ public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransportId getId() {
|
public TransportId getId() {
|
||||||
return LanTcpPlugin.ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -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,26 +16,29 @@ 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.crypto.PseudoRandom;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.api.crypto.PseudoRandom;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.api.event.EventListener;
|
import org.briarproject.bramble.api.keyagreement.KeyAgreementListener;
|
||||||
import org.briarproject.api.event.SettingsUpdatedEvent;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.api.keyagreement.KeyAgreementListener;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.api.keyagreement.TransportDescriptor;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.PluginException;
|
||||||
import org.briarproject.api.plugins.TorConstants;
|
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||||
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.DuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.reporting.DevReporter;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.api.settings.Settings;
|
import org.briarproject.bramble.api.reporting.DevReporter;
|
||||||
import org.briarproject.api.system.LocationUtils;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.util.IoUtils;
|
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
|
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;
|
||||||
@@ -60,6 +64,7 @@ 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;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
import static android.content.Context.CONNECTIVITY_SERVICE;
|
import static android.content.Context.CONNECTIVITY_SERVICE;
|
||||||
@@ -73,9 +78,11 @@ 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.util.PrivacyUtils.scrubOnion;
|
||||||
|
|
||||||
|
@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 PROP_ONION = "onion";
|
||||||
@@ -156,14 +163,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
|
||||||
|
try {
|
||||||
cookieFile.getParentFile().mkdirs();
|
cookieFile.getParentFile().mkdirs();
|
||||||
cookieFile.createNewFile();
|
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();
|
||||||
@@ -176,8 +187,8 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
Process torProcess;
|
Process torProcess;
|
||||||
try {
|
try {
|
||||||
torProcess = Runtime.getRuntime().exec(cmd, env, torDirectory);
|
torProcess = Runtime.getRuntime().exec(cmd, env, torDirectory);
|
||||||
} 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)) {
|
||||||
@@ -191,19 +202,20 @@ 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();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
// Open a control connection and authenticate using the cookie file
|
// Open a control connection and authenticate using the cookie file
|
||||||
controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
|
controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
|
||||||
controlConnection = new TorControlConnection(controlSocket);
|
controlConnection = new TorControlConnection(controlSocket);
|
||||||
@@ -221,13 +233,15 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
LOG.info("Tor has already bootstrapped");
|
LOG.info("Tor has already bootstrapped");
|
||||||
connectionStatus.setBootstrapped();
|
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(CONNECTIVITY_ACTION);
|
||||||
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() {
|
||||||
@@ -240,7 +254,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 {
|
||||||
@@ -248,48 +262,54 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
// Unzip the Tor binary to the filesystem
|
// Unzip the Tor binary to the filesystem
|
||||||
in = getTorInputStream();
|
in = getTorInputStream();
|
||||||
out = new FileOutputStream(torFile);
|
out = new FileOutputStream(torFile);
|
||||||
IoUtils.copy(in, out);
|
IoUtils.copyAndClose(in, out);
|
||||||
// Make the Tor binary executable
|
// Make the Tor binary executable
|
||||||
if (!torFile.setExecutable(true, true)) throw new IOException();
|
if (!torFile.setExecutable(true, true)) throw new IOException();
|
||||||
// Unzip the GeoIP database to the filesystem
|
// Unzip the GeoIP database to the filesystem
|
||||||
in = getGeoIpInputStream();
|
in = getGeoIpInputStream();
|
||||||
out = new FileOutputStream(geoIpFile);
|
out = new FileOutputStream(geoIpFile);
|
||||||
IoUtils.copy(in, out);
|
IoUtils.copyAndClose(in, out);
|
||||||
// Copy the config file to the filesystem
|
// Copy the config file to the filesystem
|
||||||
in = getConfigInputStream();
|
in = getConfigInputStream();
|
||||||
out = new FileOutputStream(configFile);
|
out = new FileOutputStream(configFile);
|
||||||
IoUtils.copy(in, out);
|
IoUtils.copyAndClose(in, out);
|
||||||
doneFile.createNewFile();
|
doneFile.createNewFile();
|
||||||
} 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 void tryToClose(Closeable c) {
|
private int getResourceId(String filename) {
|
||||||
|
Resources res = appContext.getResources();
|
||||||
|
return res.getIdentifier(filename, "raw", appContext.getPackageName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryToClose(@Nullable Closeable c) {
|
||||||
try {
|
try {
|
||||||
if (c != null) c.close();
|
if (c != null) c.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -297,7 +317,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryToClose(Socket s) {
|
private void tryToClose(@Nullable Socket s) {
|
||||||
try {
|
try {
|
||||||
if (s != null) s.close();
|
if (s != null) s.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -306,8 +326,12 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void listFiles(File f) {
|
private void listFiles(File f) {
|
||||||
if (f.isDirectory()) for (File child : f.listFiles()) listFiles(child);
|
if (f.isDirectory()) {
|
||||||
else LOG.info(f.getAbsolutePath());
|
File[] children = f.listFiles();
|
||||||
|
if (children != null) for (File child : children) listFiles(child);
|
||||||
|
} else {
|
||||||
|
LOG.info(f.getAbsolutePath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] read(File f) throws IOException {
|
private byte[] read(File f) throws IOException {
|
||||||
@@ -322,7 +346,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
} finally {
|
} finally {
|
||||||
in.close();
|
tryToClose(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,7 +405,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryToClose(ServerSocket ss) {
|
private void tryToClose(@Nullable ServerSocket ss) {
|
||||||
try {
|
try {
|
||||||
if (ss != null) ss.close();
|
if (ss != null) ss.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -460,7 +484,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)
|
||||||
@@ -570,7 +594,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DuplexTransportConnection createKeyAgreementConnection(
|
public DuplexTransportConnection createKeyAgreementConnection(
|
||||||
byte[] commitment, TransportDescriptor d, long timeout) {
|
byte[] commitment, BdfList descriptor, long timeout) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,25 +1,29 @@
|
|||||||
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.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 =
|
||||||
@@ -81,7 +85,7 @@ 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);
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
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 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;
|
||||||
@@ -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;
|
||||||
@@ -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();
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.system;
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
@@ -6,13 +6,18 @@ import android.content.Context;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static android.provider.Settings.Secure.ANDROID_ID;
|
import static android.provider.Settings.Secure.ANDROID_ID;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
class AndroidSeedProvider extends LinuxSeedProvider {
|
class AndroidSeedProvider extends LinuxSeedProvider {
|
||||||
|
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
@@ -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.SeedProvider;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class AndroidSystemModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
SeedProvider provideSeedProvider(Application app) {
|
||||||
|
return new AndroidSeedProvider(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
LocationUtils provideLocationUtils(Application app) {
|
||||||
|
return new AndroidLocationUtils(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
AndroidExecutor provideAndroidExecutor(Application app) {
|
||||||
|
return new AndroidExecutorImpl(app);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package org.briarproject.bramble.util;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
|
||||||
|
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 (Build.VERSION.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
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>
|
||||||
41
bramble-api/build.gradle
Normal file
41
bramble-api/build.gradle
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
apply plugin: 'java'
|
||||||
|
sourceCompatibility = 1.6
|
||||||
|
targetCompatibility = 1.6
|
||||||
|
|
||||||
|
apply plugin: 'witness'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile "com.google.dagger:dagger:2.0.2"
|
||||||
|
compile 'com.google.dagger:dagger-compiler:2.0.2'
|
||||||
|
compile 'com.google.code.findbugs:jsr305:3.0.1'
|
||||||
|
|
||||||
|
testCompile 'junit:junit:4.12'
|
||||||
|
testCompile "org.jmock:jmock:2.8.1"
|
||||||
|
testCompile "org.jmock:jmock-junit4:2.8.1"
|
||||||
|
testCompile "org.jmock:jmock-legacy:2.8.1"
|
||||||
|
testCompile "org.hamcrest:hamcrest-library:1.3"
|
||||||
|
testCompile "org.hamcrest:hamcrest-core:1.3"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencyVerification {
|
||||||
|
verify = [
|
||||||
|
'com.google.dagger:dagger:84c0282ed8be73a29e0475d639da030b55dee72369e58dd35ae7d4fe6243dcf9',
|
||||||
|
'com.google.dagger:dagger-compiler:b74bc9de063dd4c6400b232231f2ef5056145b8fbecbf5382012007dd1c071b3',
|
||||||
|
'com.google.code.findbugs:jsr305:c885ce34249682bc0236b4a7d56efcc12048e6135a5baf7a9cde8ad8cda13fcd',
|
||||||
|
'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
|
||||||
|
'com.google.dagger:dagger-producers:99ec15e8a0507ba569e7655bc1165ee5e5ca5aa914b3c8f7e2c2458f724edd6b',
|
||||||
|
'com.google.guava:guava:d664fbfc03d2e5ce9cab2a44fb01f1d0bf9dfebeccc1a473b1f9ea31f79f6f99',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
package org.briarproject.api;
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
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();
|
||||||
@@ -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 {
|
||||||
|
}
|
||||||
@@ -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,36 @@
|
|||||||
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class BdfMessageContext {
|
||||||
|
|
||||||
|
private final BdfDictionary dictionary;
|
||||||
|
private final Collection<MessageId> dependencies;
|
||||||
|
|
||||||
|
public BdfMessageContext(BdfDictionary dictionary,
|
||||||
|
Collection<MessageId> dependencies) {
|
||||||
|
this.dictionary = dictionary;
|
||||||
|
this.dependencies = dependencies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BdfMessageContext(BdfDictionary dictionary) {
|
||||||
|
this(dictionary, Collections.<MessageId>emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BdfDictionary getDictionary() {
|
||||||
|
return dictionary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<MessageId> getDependencies() {
|
||||||
|
return dependencies;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,17 +1,21 @@
|
|||||||
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.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;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface ClientHelper {
|
public interface ClientHelper {
|
||||||
|
|
||||||
void addLocalMessage(Message m, BdfDictionary metadata, boolean shared)
|
void addLocalMessage(Message m, BdfDictionary metadata, boolean shared)
|
||||||
@@ -20,14 +24,21 @@ public interface ClientHelper {
|
|||||||
void addLocalMessage(Transaction txn, Message m, BdfDictionary metadata,
|
void addLocalMessage(Transaction txn, Message m, BdfDictionary metadata,
|
||||||
boolean shared) throws DbException, FormatException;
|
boolean shared) throws DbException, FormatException;
|
||||||
|
|
||||||
Message createMessage(GroupId g, long timestamp, BdfDictionary body)
|
|
||||||
throws FormatException;
|
|
||||||
|
|
||||||
Message createMessage(GroupId g, long timestamp, BdfList body)
|
Message createMessage(GroupId g, long timestamp, BdfList body)
|
||||||
throws FormatException;
|
throws FormatException;
|
||||||
|
|
||||||
|
Message createMessageForStoringMetadata(GroupId g);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
Message getMessage(MessageId m) throws DbException;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
Message getMessage(Transaction txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
BdfList getMessageAsList(MessageId m) throws DbException, FormatException;
|
BdfList getMessageAsList(MessageId m) throws DbException, FormatException;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
BdfList getMessageAsList(Transaction txn, MessageId m) throws DbException,
|
BdfList getMessageAsList(Transaction txn, MessageId m) throws DbException,
|
||||||
FormatException;
|
FormatException;
|
||||||
|
|
||||||
@@ -37,7 +48,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)
|
||||||
@@ -68,12 +80,6 @@ public interface ClientHelper {
|
|||||||
void mergeMessageMetadata(Transaction txn, MessageId m,
|
void mergeMessageMetadata(Transaction txn, MessageId m,
|
||||||
BdfDictionary metadata) throws DbException, FormatException;
|
BdfDictionary metadata) throws DbException, FormatException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks the given message as shared or unshared with other contacts.
|
|
||||||
*/
|
|
||||||
void setMessageShared(Transaction txn, MessageId m, boolean shared)
|
|
||||||
throws DbException;
|
|
||||||
|
|
||||||
byte[] toByteArray(BdfDictionary dictionary) throws FormatException;
|
byte[] toByteArray(BdfDictionary dictionary) throws FormatException;
|
||||||
|
|
||||||
byte[] toByteArray(BdfList list) throws FormatException;
|
byte[] toByteArray(BdfList list) throws FormatException;
|
||||||
@@ -85,6 +91,12 @@ public interface ClientHelper {
|
|||||||
|
|
||||||
BdfList toList(byte[] b) throws FormatException;
|
BdfList toList(byte[] b) throws FormatException;
|
||||||
|
|
||||||
byte[] sign(BdfList toSign, byte[] privateKey)
|
BdfList toList(Message m) throws FormatException;
|
||||||
|
|
||||||
|
byte[] sign(String label, BdfList toSign, byte[] privateKey)
|
||||||
throws FormatException, GeneralSecurityException;
|
throws FormatException, GeneralSecurityException;
|
||||||
|
|
||||||
|
void verifySignature(String label, byte[] sig, byte[] publicKey,
|
||||||
|
BdfList signed) throws FormatException, GeneralSecurityException;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a group for the given client to share with the given contact.
|
||||||
|
*/
|
||||||
|
Group createContactGroup(ClientId clientId, Contact contact);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a group for the given client to share between the given authors
|
||||||
|
* identified by their AuthorIds.
|
||||||
|
*/
|
||||||
|
Group createContactGroup(ClientId clientId, 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,22 @@
|
|||||||
|
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 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
@@ -10,14 +10,10 @@ public interface CryptoComponent {
|
|||||||
|
|
||||||
SecretKey generateSecretKey();
|
SecretKey generateSecretKey();
|
||||||
|
|
||||||
MessageDigest getMessageDigest();
|
|
||||||
|
|
||||||
PseudoRandom getPseudoRandom(int seed1, int seed2);
|
PseudoRandom getPseudoRandom(int seed1, int seed2);
|
||||||
|
|
||||||
SecureRandom getSecureRandom();
|
SecureRandom getSecureRandom();
|
||||||
|
|
||||||
Signature getSignature();
|
|
||||||
|
|
||||||
KeyPair generateAgreementKeyPair();
|
KeyPair generateAgreementKeyPair();
|
||||||
|
|
||||||
KeyParser getAgreementKeyParser();
|
KeyParser getAgreementKeyParser();
|
||||||
@@ -143,11 +139,40 @@ public interface CryptoComponent {
|
|||||||
/** Encodes the pseudo-random tag that is used to recognise a stream. */
|
/** Encodes the pseudo-random tag that is used to recognise a stream. */
|
||||||
void encodeTag(byte[] tag, SecretKey tagKey, long streamNumber);
|
void encodeTag(byte[] tag, SecretKey tagKey, long streamNumber);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signs the given byte[] with the given PrivateKey.
|
||||||
|
*
|
||||||
|
* @param label A label specific to this signature
|
||||||
|
* to ensure that the signature cannot be repurposed
|
||||||
|
*/
|
||||||
|
byte[] sign(String label, byte[] toSign, byte[] privateKey)
|
||||||
|
throws GeneralSecurityException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that the given signature is valid for the signedData
|
||||||
|
* and the given publicKey.
|
||||||
|
*
|
||||||
|
* @param label A label that was specific to this signature
|
||||||
|
* to ensure that the signature cannot be repurposed
|
||||||
|
* @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
|
* Returns the hash of the given inputs. The inputs are unambiguously
|
||||||
* combined by prefixing each input with its length.
|
* combined by prefixing each input with its length.
|
||||||
|
*
|
||||||
|
* @param label A label specific to this hash to ensure that hashes
|
||||||
|
* calculated for distinct purposes don't collide.
|
||||||
*/
|
*/
|
||||||
byte[] hash(byte[]... inputs);
|
byte[] hash(String label, byte[]... inputs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the length of hashes produced by
|
||||||
|
* the {@link CryptoComponent#hash(String, byte[]...)} method.
|
||||||
|
*/
|
||||||
|
int getHashLength();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a message authentication code with the given key over the
|
* Returns a message authentication code with the given key over the
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
import static java.lang.annotation.ElementType.FIELD;
|
||||||
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
|
import static java.lang.annotation.ElementType.PARAMETER;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotation for injecting the executor for long-running crypto tasks. Also
|
||||||
|
* used for annotating methods that should run on the crypto executor.
|
||||||
|
* <p>
|
||||||
|
* The contract of this executor is that tasks may be run concurrently, and
|
||||||
|
* submitting a task will never block. Tasks must not run indefinitely. Tasks
|
||||||
|
* submitted during shutdown are discarded.
|
||||||
|
*/
|
||||||
|
@Qualifier
|
||||||
|
@Target({FIELD, METHOD, PARAMETER})
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
public @interface CryptoExecutor {
|
||||||
|
}
|
||||||
@@ -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,5 +1,8 @@
|
|||||||
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;
|
||||||
@@ -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,12 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A deterministic pseudo-random number generator.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface PseudoRandom {
|
||||||
|
|
||||||
|
byte[] nextBytes(int bytes);
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.briarproject.api.transport.StreamContext;
|
@NotNullByDefault
|
||||||
|
|
||||||
public interface StreamDecrypterFactory {
|
public interface StreamDecrypterFactory {
|
||||||
|
|
||||||
/** Creates a {@link StreamDecrypter} for decrypting a transport stream. */
|
/**
|
||||||
|
* Creates a {@link StreamDecrypter} for decrypting a transport stream.
|
||||||
|
*/
|
||||||
StreamDecrypter createStreamDecrypter(InputStream in, StreamContext ctx);
|
StreamDecrypter createStreamDecrypter(InputStream in, StreamContext ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.briarproject.api.transport.StreamContext;
|
@NotNullByDefault
|
||||||
|
|
||||||
public interface StreamEncrypterFactory {
|
public interface StreamEncrypterFactory {
|
||||||
|
|
||||||
/** Creates a {@link StreamEncrypter} for encrypting a transport stream. */
|
/**
|
||||||
|
* Creates a {@link StreamEncrypter} for encrypting a transport stream.
|
||||||
|
*/
|
||||||
StreamEncrypter createStreamEncrypter(OutputStream out, StreamContext ctx);
|
StreamEncrypter createStreamEncrypter(OutputStream out, StreamContext ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
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.concurrent.ConcurrentSkipListMap;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
|
public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
|
||||||
|
|
||||||
public static final Object NULL_VALUE = new Object();
|
public static final Object NULL_VALUE = new Object();
|
||||||
@@ -39,6 +41,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
|
|||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Boolean getOptionalBoolean(String key) throws FormatException {
|
public Boolean getOptionalBoolean(String key) throws FormatException {
|
||||||
Object o = get(key);
|
Object o = get(key);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
@@ -61,6 +64,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
|
|||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Long getOptionalLong(String key) throws FormatException {
|
public Long getOptionalLong(String key) throws FormatException {
|
||||||
Object o = get(key);
|
Object o = get(key);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
@@ -87,6 +91,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
|
|||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Double getOptionalDouble(String key) throws FormatException {
|
public Double getOptionalDouble(String key) throws FormatException {
|
||||||
Object o = get(key);
|
Object o = get(key);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
@@ -108,6 +113,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
|
|||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getOptionalString(String key) throws FormatException {
|
public String getOptionalString(String key) throws FormatException {
|
||||||
Object o = get(key);
|
Object o = get(key);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
@@ -128,6 +134,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
|
|||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public byte[] getOptionalRaw(String key) throws FormatException {
|
public byte[] getOptionalRaw(String key) throws FormatException {
|
||||||
Object o = get(key);
|
Object o = get(key);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
@@ -149,6 +156,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
|
|||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public BdfList getOptionalList(String key) throws FormatException {
|
public BdfList getOptionalList(String key) throws FormatException {
|
||||||
Object o = get(key);
|
Object o = get(key);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
@@ -168,6 +176,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
|
|||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public BdfDictionary getOptionalDictionary(String key)
|
public BdfDictionary getOptionalDictionary(String key)
|
||||||
throws FormatException {
|
throws FormatException {
|
||||||
Object o = get(key);
|
Object o = get(key);
|
||||||
@@ -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,13 +1,15 @@
|
|||||||
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.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import static org.briarproject.api.data.BdfDictionary.NULL_VALUE;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
|
||||||
|
|
||||||
public class BdfList extends Vector<Object> {
|
public class BdfList extends Vector<Object> {
|
||||||
|
|
||||||
@@ -29,13 +31,20 @@ public class BdfList extends Vector<Object> {
|
|||||||
super(items);
|
super(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isInRange(int index) {
|
||||||
|
return index >= 0 && index < size();
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean getBoolean(int index) throws FormatException {
|
public Boolean getBoolean(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof Boolean) return (Boolean) o;
|
if (o instanceof Boolean) return (Boolean) o;
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Boolean getOptionalBoolean(int index) throws FormatException {
|
public Boolean getOptionalBoolean(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
if (o instanceof Boolean) return (Boolean) o;
|
if (o instanceof Boolean) return (Boolean) o;
|
||||||
@@ -43,12 +52,14 @@ public class BdfList extends Vector<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getBoolean(int index, Boolean defaultValue) {
|
public Boolean getBoolean(int index, Boolean defaultValue) {
|
||||||
|
if (!isInRange(index)) return defaultValue;
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof Boolean) return (Boolean) o;
|
if (o instanceof Boolean) return (Boolean) o;
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getLong(int index) throws FormatException {
|
public Long getLong(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof Long) return (Long) o;
|
if (o instanceof Long) return (Long) o;
|
||||||
if (o instanceof Integer) return ((Integer) o).longValue();
|
if (o instanceof Integer) return ((Integer) o).longValue();
|
||||||
@@ -57,7 +68,9 @@ public class BdfList extends Vector<Object> {
|
|||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Long getOptionalLong(int index) throws FormatException {
|
public Long getOptionalLong(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
if (o instanceof Long) return (Long) o;
|
if (o instanceof Long) return (Long) o;
|
||||||
@@ -68,6 +81,7 @@ public class BdfList extends Vector<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Long getLong(int index, Long defaultValue) {
|
public Long getLong(int index, Long defaultValue) {
|
||||||
|
if (!isInRange(index)) return defaultValue;
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof Long) return (Long) o;
|
if (o instanceof Long) return (Long) o;
|
||||||
if (o instanceof Integer) return ((Integer) o).longValue();
|
if (o instanceof Integer) return ((Integer) o).longValue();
|
||||||
@@ -77,13 +91,16 @@ public class BdfList extends Vector<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Double getDouble(int index) throws FormatException {
|
public Double getDouble(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof Double) return (Double) o;
|
if (o instanceof Double) return (Double) o;
|
||||||
if (o instanceof Float) return ((Float) o).doubleValue();
|
if (o instanceof Float) return ((Float) o).doubleValue();
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Double getOptionalDouble(int index) throws FormatException {
|
public Double getOptionalDouble(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
if (o instanceof Double) return (Double) o;
|
if (o instanceof Double) return (Double) o;
|
||||||
@@ -92,6 +109,7 @@ public class BdfList extends Vector<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Double getDouble(int index, Double defaultValue) {
|
public Double getDouble(int index, Double defaultValue) {
|
||||||
|
if (!isInRange(index)) return defaultValue;
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof Double) return (Double) o;
|
if (o instanceof Double) return (Double) o;
|
||||||
if (o instanceof Float) return ((Float) o).doubleValue();
|
if (o instanceof Float) return ((Float) o).doubleValue();
|
||||||
@@ -99,12 +117,15 @@ public class BdfList extends Vector<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getString(int index) throws FormatException {
|
public String getString(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof String) return (String) o;
|
if (o instanceof String) return (String) o;
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getOptionalString(int index) throws FormatException {
|
public String getOptionalString(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
if (o instanceof String) return (String) o;
|
if (o instanceof String) return (String) o;
|
||||||
@@ -112,19 +133,23 @@ public class BdfList extends Vector<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getString(int index, String defaultValue) {
|
public String getString(int index, String defaultValue) {
|
||||||
|
if (!isInRange(index)) return defaultValue;
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof String) return (String) o;
|
if (o instanceof String) return (String) o;
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getRaw(int index) throws FormatException {
|
public byte[] getRaw(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof byte[]) return (byte[]) o;
|
if (o instanceof byte[]) return (byte[]) o;
|
||||||
if (o instanceof Bytes) return ((Bytes) o).getBytes();
|
if (o instanceof Bytes) return ((Bytes) o).getBytes();
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public byte[] getOptionalRaw(int index) throws FormatException {
|
public byte[] getOptionalRaw(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
if (o instanceof byte[]) return (byte[]) o;
|
if (o instanceof byte[]) return (byte[]) o;
|
||||||
@@ -133,6 +158,7 @@ public class BdfList extends Vector<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getRaw(int index, byte[] defaultValue) {
|
public byte[] getRaw(int index, byte[] defaultValue) {
|
||||||
|
if (!isInRange(index)) return defaultValue;
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof byte[]) return (byte[]) o;
|
if (o instanceof byte[]) return (byte[]) o;
|
||||||
if (o instanceof Bytes) return ((Bytes) o).getBytes();
|
if (o instanceof Bytes) return ((Bytes) o).getBytes();
|
||||||
@@ -140,12 +166,15 @@ public class BdfList extends Vector<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BdfList getList(int index) throws FormatException {
|
public BdfList getList(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof BdfList) return (BdfList) o;
|
if (o instanceof BdfList) return (BdfList) o;
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public BdfList getOptionalList(int index) throws FormatException {
|
public BdfList getOptionalList(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
if (o instanceof BdfList) return (BdfList) o;
|
if (o instanceof BdfList) return (BdfList) o;
|
||||||
@@ -153,19 +182,23 @@ public class BdfList extends Vector<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BdfList getList(int index, BdfList defaultValue) {
|
public BdfList getList(int index, BdfList defaultValue) {
|
||||||
|
if (!isInRange(index)) return defaultValue;
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof BdfList) return (BdfList) o;
|
if (o instanceof BdfList) return (BdfList) o;
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BdfDictionary getDictionary(int index) throws FormatException {
|
public BdfDictionary getDictionary(int index) throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof BdfDictionary) return (BdfDictionary) o;
|
if (o instanceof BdfDictionary) return (BdfDictionary) o;
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public BdfDictionary getOptionalDictionary(int index)
|
public BdfDictionary getOptionalDictionary(int index)
|
||||||
throws FormatException {
|
throws FormatException {
|
||||||
|
if (!isInRange(index)) throw new FormatException();
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o == null || o == NULL_VALUE) return null;
|
if (o == null || o == NULL_VALUE) return null;
|
||||||
if (o instanceof BdfDictionary) return (BdfDictionary) o;
|
if (o instanceof BdfDictionary) return (BdfDictionary) o;
|
||||||
@@ -173,6 +206,7 @@ public class BdfList extends Vector<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BdfDictionary getDictionary(int index, BdfDictionary defaultValue) {
|
public BdfDictionary getDictionary(int index, BdfDictionary defaultValue) {
|
||||||
|
if (!isInRange(index)) return defaultValue;
|
||||||
Object o = get(index);
|
Object o = get(index);
|
||||||
if (o instanceof BdfDictionary) return (BdfDictionary) o;
|
if (o instanceof BdfDictionary) return (BdfDictionary) o;
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
@@ -1,47 +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;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface BdfReaderFactory {
|
||||||
|
|
||||||
|
BdfReader createReader(InputStream in);
|
||||||
|
|
||||||
|
BdfReader createReader(InputStream in, int nestedLimit);
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface ObjectReader<T> {
|
||||||
|
|
||||||
|
T readObject(BdfReader r) throws IOException;
|
||||||
|
}
|
||||||
@@ -1,10 +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 {
|
||||||
|
|
||||||
private static final long serialVersionUID = -6658762011691502411L;
|
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,38 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import org.briarproject.api.DeviceId;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.api.sync.Ack;
|
import org.briarproject.bramble.api.sync.Ack;
|
||||||
import org.briarproject.api.sync.ClientId;
|
import org.briarproject.bramble.api.sync.ClientId;
|
||||||
import org.briarproject.api.sync.Group;
|
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 {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,11 +56,17 @@ public interface DatabaseComponent {
|
|||||||
Transaction startTransaction(boolean readOnly) throws DbException;
|
Transaction startTransaction(boolean readOnly) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends a transaction. If the transaction is marked as complete, the
|
* Commits a transaction to the database.
|
||||||
* transaction is committed and any events attached to the transaction are
|
|
||||||
* broadcast; otherwise the transaction is aborted.
|
|
||||||
*/
|
*/
|
||||||
void endTransaction(Transaction txn) throws DbException;
|
void commitTransaction(Transaction txn) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ends a transaction. If the transaction has not been committed,
|
||||||
|
* it will be aborted. If the transaction has been committed,
|
||||||
|
* any events attached to the transaction are broadcast.
|
||||||
|
* The database lock will be released in either case.
|
||||||
|
*/
|
||||||
|
void endTransaction(Transaction txn);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a contact associated with the given local and remote pseudonyms,
|
* Stores a contact associated with the given local and remote pseudonyms,
|
||||||
@@ -198,13 +208,6 @@ public interface DatabaseComponent {
|
|||||||
Collection<ContactId> getContacts(Transaction txn, AuthorId a)
|
Collection<ContactId> getContacts(Transaction txn, AuthorId a)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the unique ID for this device.
|
|
||||||
* <p/>
|
|
||||||
* Read-only.
|
|
||||||
*/
|
|
||||||
DeviceId getDeviceId(Transaction txn) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the group with the given ID.
|
* Returns the group with the given ID.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -226,6 +229,15 @@ public interface DatabaseComponent {
|
|||||||
*/
|
*/
|
||||||
Collection<Group> getGroups(Transaction txn, ClientId c) throws DbException;
|
Collection<Group> getGroups(Transaction txn, ClientId c) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the given group's visibility to the given contact, or
|
||||||
|
* {@link Visibility INVISIBLE} if the group is not in the database.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
Visibility getGroupVisibility(Transaction txn, ContactId c, GroupId g)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the local pseudonym with the given ID.
|
* Returns the local pseudonym with the given ID.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -258,6 +270,15 @@ public interface DatabaseComponent {
|
|||||||
Collection<MessageId> getPendingMessages(Transaction txn, ClientId c)
|
Collection<MessageId> getPendingMessages(Transaction txn, ClientId c)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the IDs of any messages from the given client
|
||||||
|
* that have a shared dependent, but are still not shared themselves.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
Collection<MessageId> getMessagesToShare(Transaction txn,
|
||||||
|
ClientId c) 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
|
||||||
* the message has been deleted.
|
* the message has been deleted.
|
||||||
@@ -313,10 +334,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/>
|
||||||
@@ -373,14 +394,6 @@ public interface DatabaseComponent {
|
|||||||
void incrementStreamCounter(Transaction txn, ContactId c, TransportId t,
|
void incrementStreamCounter(Transaction txn, ContactId c, TransportId t,
|
||||||
long rotationPeriod) throws DbException;
|
long rotationPeriod) throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the given group is visible to the given contact.
|
|
||||||
* <p/>
|
|
||||||
* Read-only.
|
|
||||||
*/
|
|
||||||
boolean isVisibleToContact(Transaction txn, ContactId c, GroupId g)
|
|
||||||
throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges the given metadata with the existing metadata for the given
|
* Merges the given metadata with the existing metadata for the given
|
||||||
* group.
|
* group.
|
||||||
@@ -456,10 +469,15 @@ public interface DatabaseComponent {
|
|||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given message as shared or unshared.
|
* Sets the given group's visibility to the given contact.
|
||||||
*/
|
*/
|
||||||
void setMessageShared(Transaction txn, MessageId m, boolean shared)
|
void setGroupVisibility(Transaction txn, ContactId c, GroupId g,
|
||||||
throws DbException;
|
Visibility v) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the given message as shared.
|
||||||
|
*/
|
||||||
|
void setMessageShared(Transaction txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the validation and delivery state of the given message.
|
* Sets the validation and delivery state of the given message.
|
||||||
@@ -480,12 +498,6 @@ public interface DatabaseComponent {
|
|||||||
void setReorderingWindow(Transaction txn, ContactId c, TransportId t,
|
void setReorderingWindow(Transaction txn, ContactId c, TransportId t,
|
||||||
long rotationPeriod, long base, byte[] bitmap) throws DbException;
|
long rotationPeriod, long base, byte[] bitmap) throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a group visible or invisible to a contact.
|
|
||||||
*/
|
|
||||||
void setVisibleToContact(Transaction txn, ContactId c, GroupId g,
|
|
||||||
boolean visible) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the given transport keys, deleting any keys they have replaced.
|
* Stores the given transport keys, deleting any keys they have replaced.
|
||||||
*/
|
*/
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface DatabaseConfig {
|
||||||
|
|
||||||
|
boolean databaseExists();
|
||||||
|
|
||||||
|
File getDatabaseDirectory();
|
||||||
|
|
||||||
|
void setEncryptionKey(SecretKey key);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
SecretKey getEncryptionKey();
|
||||||
|
|
||||||
|
void setLocalAuthorName(String nickname);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
String getLocalAuthorName();
|
||||||
|
|
||||||
|
long getMaxSize();
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
import static java.lang.annotation.ElementType.FIELD;
|
||||||
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
|
import static java.lang.annotation.ElementType.PARAMETER;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotation for injecting the executor for database tasks. Also used for
|
||||||
|
* annotating methods that should run on the database executor.
|
||||||
|
* <p>
|
||||||
|
* The contract of this executor is that tasks are run in the order they're
|
||||||
|
* submitted, tasks are not run concurrently, and submitting a task will never
|
||||||
|
* block. Tasks must not run indefinitely. Tasks submitted during shutdown are
|
||||||
|
* discarded.
|
||||||
|
*/
|
||||||
|
@Qualifier
|
||||||
|
@Target({FIELD, METHOD, PARAMETER})
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
public @interface DatabaseExecutor {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when a database operation is attempted and the database is closed.
|
||||||
|
*/
|
||||||
|
public class DbClosedException extends DbException {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
|
public class DbException extends Exception {
|
||||||
|
|
||||||
|
public DbException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbException(Throwable t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
@ThreadSafe
|
||||||
public class Metadata extends Hashtable<String, byte[]> {
|
public class Metadata extends Hashtable<String, byte[]> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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,6 +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 {
|
||||||
|
|
||||||
private static final long serialVersionUID = -7048538231308207386L;
|
|
||||||
}
|
}
|
||||||
@@ -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,6 +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 {
|
||||||
|
|
||||||
private static final long serialVersionUID = -5494178507342571697L;
|
|
||||||
}
|
}
|
||||||
@@ -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,6 +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 {
|
||||||
|
|
||||||
private static final long serialVersionUID = 494398665376703860L;
|
|
||||||
}
|
}
|
||||||
@@ -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,6 +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 {
|
||||||
|
|
||||||
private static final long serialVersionUID = 9191508339698803848L;
|
|
||||||
}
|
}
|
||||||
@@ -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,6 +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 {
|
||||||
|
|
||||||
private static final long serialVersionUID = -6274982612759573100L;
|
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,24 @@
|
|||||||
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;
|
||||||
private final boolean readOnly;
|
private final boolean readOnly;
|
||||||
|
|
||||||
private List<Event> events = null;
|
private List<Event> events = null;
|
||||||
private boolean complete = false;
|
private boolean committed = false;
|
||||||
|
|
||||||
public Transaction(Object txn, boolean readOnly) {
|
public Transaction(Object txn, boolean readOnly) {
|
||||||
this.txn = txn;
|
this.txn = txn;
|
||||||
@@ -55,18 +58,18 @@ public class Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the transaction is ready to be committed.
|
* Returns true if the transaction has been committed.
|
||||||
*/
|
*/
|
||||||
public boolean isComplete() {
|
public boolean isCommitted() {
|
||||||
return complete;
|
return committed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the transaction as ready to be committed. This method must not be
|
* Marks the transaction as committed. This method should only be called
|
||||||
* called more than once.
|
* by the DatabaseComponent. It must not be called more than once.
|
||||||
*/
|
*/
|
||||||
public void setComplete() {
|
public void setCommitted() {
|
||||||
if (complete) throw new IllegalStateException();
|
if (committed) throw new IllegalStateException();
|
||||||
complete = true;
|
committed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -1,11 +1,19 @@
|
|||||||
package org.briarproject.api.identity;
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
/** A pseudonym for a user. */
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pseudonym for a user.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class Author {
|
public class Author {
|
||||||
|
|
||||||
public enum Status { ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED, OURSELVES }
|
public enum Status {ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED, OURSELVES}
|
||||||
|
|
||||||
private final AuthorId id;
|
private final AuthorId id;
|
||||||
private final String name;
|
private final String name;
|
||||||
@@ -25,17 +33,23 @@ public class Author {
|
|||||||
this.publicKey = publicKey;
|
this.publicKey = publicKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the author's unique identifier. */
|
/**
|
||||||
|
* Returns the author's unique identifier.
|
||||||
|
*/
|
||||||
public AuthorId getId() {
|
public AuthorId getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the author's name. */
|
/**
|
||||||
|
* Returns the author's name.
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the public key used to verify the pseudonym's signatures. */
|
/**
|
||||||
|
* Returns the public key used to verify the pseudonym's signatures.
|
||||||
|
*/
|
||||||
public byte[] getPublicKey() {
|
public byte[] getPublicKey() {
|
||||||
return publicKey;
|
return publicKey;
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package org.briarproject.api.identity;
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
public interface AuthorConstants {
|
public interface AuthorConstants {
|
||||||
|
|
||||||
/** The maximum length of an author's name in UTF-8 bytes. */
|
/**
|
||||||
|
* The maximum length of an author's name in UTF-8 bytes.
|
||||||
|
*/
|
||||||
int MAX_AUTHOR_NAME_LENGTH = 50;
|
int MAX_AUTHOR_NAME_LENGTH = 50;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
package org.briarproject.api.identity;
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface AuthorFactory {
|
public interface AuthorFactory {
|
||||||
|
|
||||||
Author createAuthor(String name, byte[] publicKey);
|
Author createAuthor(String name, byte[] publicKey);
|
||||||
@@ -1,20 +1,22 @@
|
|||||||
package org.briarproject.api.identity;
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
import org.briarproject.api.UniqueId;
|
import org.briarproject.bramble.api.UniqueId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type-safe wrapper for a byte array that uniquely identifies an
|
* Type-safe wrapper for a byte array that uniquely identifies an
|
||||||
* {@link org.briarproject.api.identity.Author Author}.
|
* {@link Author}.
|
||||||
*/
|
*/
|
||||||
|
@ThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
public class AuthorId extends UniqueId {
|
public class AuthorId extends UniqueId {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Label for hashing authors to calculate their identities.
|
* Label for hashing authors to calculate their identities.
|
||||||
*/
|
*/
|
||||||
public static final byte[] LABEL =
|
public static final String LABEL = "org.briarproject.bramble.AUTHOR_ID";
|
||||||
"AUTHOR_ID".getBytes(Charset.forName("US-ASCII"));
|
|
||||||
|
|
||||||
public AuthorId(byte[] id) {
|
public AuthorId(byte[] id) {
|
||||||
super(id);
|
super(id);
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.identity.Author.Status;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface IdentityManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the local pseudonym.
|
||||||
|
*/
|
||||||
|
void registerLocalAuthor(LocalAuthor a) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the cached main local identity, non-blocking, or loads it from
|
||||||
|
* the db, blocking
|
||||||
|
*/
|
||||||
|
LocalAuthor getLocalAuthor() throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the cached main local identity, non-blocking, or loads it from
|
||||||
|
* the db, blocking, within the given Transaction.
|
||||||
|
*/
|
||||||
|
LocalAuthor getLocalAuthor(Transaction txn) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the trust-level status of the author
|
||||||
|
*/
|
||||||
|
Status getAuthorStatus(AuthorId a) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the trust-level status of the author
|
||||||
|
*/
|
||||||
|
Status getAuthorStatus(Transaction txn, AuthorId a) throws DbException;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
package org.briarproject.api.identity;
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
/** A pseudonym for the local user. */
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pseudonym for the local user.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class LocalAuthor extends Author {
|
public class LocalAuthor extends Author {
|
||||||
|
|
||||||
private final byte[] privateKey;
|
private final byte[] privateKey;
|
||||||
@@ -13,7 +21,9 @@ public class LocalAuthor extends Author {
|
|||||||
this.created = created;
|
this.created = created;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the private key used to generate the pseudonym's signatures. */
|
/**
|
||||||
|
* Returns the private key used to generate the pseudonym's signatures.
|
||||||
|
*/
|
||||||
public byte[] getPrivateKey() {
|
public byte[] getPrivateKey() {
|
||||||
return privateKey;
|
return privateKey;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.briarproject.bramble.api.identity.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a local pseudonym is added.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class LocalAuthorAddedEvent extends Event {
|
||||||
|
|
||||||
|
private final AuthorId authorId;
|
||||||
|
|
||||||
|
public LocalAuthorAddedEvent(AuthorId authorId) {
|
||||||
|
this.authorId = authorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorId getAuthorId() {
|
||||||
|
return authorId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.briarproject.bramble.api.identity.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a local pseudonym is removed.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class LocalAuthorRemovedEvent extends Event {
|
||||||
|
|
||||||
|
private final AuthorId authorId;
|
||||||
|
|
||||||
|
public LocalAuthorRemovedEvent(AuthorId authorId) {
|
||||||
|
this.authorId = authorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorId getAuthorId() {
|
||||||
|
return authorId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.briarproject.bramble.api.invitation;
|
||||||
|
|
||||||
|
public interface InvitationConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The connection timeout in milliseconds.
|
||||||
|
*/
|
||||||
|
long CONNECTION_TIMEOUT = 60 * 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The confirmation timeout in milliseconds.
|
||||||
|
*/
|
||||||
|
long CONFIRMATION_TIMEOUT = 60 * 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of bits in an invitation or confirmation code. Codes must fit
|
||||||
|
* into six decimal digits.
|
||||||
|
*/
|
||||||
|
int CODE_BITS = 19;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.invitation;
|
package org.briarproject.bramble.api.invitation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for receiving updates about the state of an
|
* An interface for receiving updates about the state of an
|
||||||
@@ -1,5 +1,15 @@
|
|||||||
package org.briarproject.api.invitation;
|
package org.briarproject.bramble.api.invitation;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A snapshot of the state of an {@link InvitationTask}.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class InvitationState {
|
public class InvitationState {
|
||||||
|
|
||||||
private final int localInvitationCode, remoteInvitationCode;
|
private final int localInvitationCode, remoteInvitationCode;
|
||||||
@@ -7,13 +17,14 @@ public class InvitationState {
|
|||||||
private final boolean connected, connectionFailed;
|
private final boolean connected, connectionFailed;
|
||||||
private final boolean localCompared, remoteCompared;
|
private final boolean localCompared, remoteCompared;
|
||||||
private final boolean localMatched, remoteMatched;
|
private final boolean localMatched, remoteMatched;
|
||||||
|
@Nullable
|
||||||
private final String contactName;
|
private final String contactName;
|
||||||
|
|
||||||
public InvitationState(int localInvitationCode, int remoteInvitationCode,
|
public InvitationState(int localInvitationCode, int remoteInvitationCode,
|
||||||
int localConfirmationCode, int remoteConfirmationCode,
|
int localConfirmationCode, int remoteConfirmationCode,
|
||||||
boolean connected, boolean connectionFailed, boolean localCompared,
|
boolean connected, boolean connectionFailed, boolean localCompared,
|
||||||
boolean remoteCompared, boolean localMatched,
|
boolean remoteCompared, boolean localMatched,
|
||||||
boolean remoteMatched, String contactName) {
|
boolean remoteMatched, @Nullable String contactName) {
|
||||||
this.localInvitationCode = localInvitationCode;
|
this.localInvitationCode = localInvitationCode;
|
||||||
this.remoteInvitationCode = remoteInvitationCode;
|
this.remoteInvitationCode = remoteInvitationCode;
|
||||||
this.localConfirmationCode = localConfirmationCode;
|
this.localConfirmationCode = localConfirmationCode;
|
||||||
@@ -67,6 +78,7 @@ public class InvitationState {
|
|||||||
return remoteMatched;
|
return remoteMatched;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getContactName() {
|
public String getContactName() {
|
||||||
return contactName;
|
return contactName;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
package org.briarproject.api.invitation;
|
package org.briarproject.bramble.api.invitation;
|
||||||
|
|
||||||
/** A task for exchanging invitations with a remote peer. */
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A task for exchanging invitations with a remote peer.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
public interface InvitationTask {
|
public interface InvitationTask {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,10 +14,14 @@ public interface InvitationTask {
|
|||||||
*/
|
*/
|
||||||
InvitationState addListener(InvitationListener l);
|
InvitationState addListener(InvitationListener l);
|
||||||
|
|
||||||
/** Removes the given listener. */
|
/**
|
||||||
|
* Removes the given listener.
|
||||||
|
*/
|
||||||
void removeListener(InvitationListener l);
|
void removeListener(InvitationListener l);
|
||||||
|
|
||||||
/** Asynchronously starts the connection process. */
|
/**
|
||||||
|
* Asynchronously starts the connection process.
|
||||||
|
*/
|
||||||
void connect();
|
void connect();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.briarproject.bramble.api.invitation;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates tasks for exchanging invitations with remote peers.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface InvitationTaskFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a task using the given local and remote invitation codes.
|
||||||
|
*/
|
||||||
|
InvitationTask createTask(int localCode, int remoteCode);
|
||||||
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
package org.briarproject.api.keyagreement;
|
package org.briarproject.bramble.api.keyagreement;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class KeyAgreementConnection {
|
public class KeyAgreementConnection {
|
||||||
|
|
||||||
private final DuplexTransportConnection conn;
|
private final DuplexTransportConnection conn;
|
||||||
private final TransportId id;
|
private final TransportId id;
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package org.briarproject.bramble.api.keyagreement;
|
||||||
|
|
||||||
|
public interface KeyAgreementConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the BQP protocol.
|
||||||
|
*/
|
||||||
|
byte PROTOCOL_VERSION = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of the record header in bytes.
|
||||||
|
*/
|
||||||
|
int RECORD_HEADER_LENGTH = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The offset of the payload length in the record header, in bytes.
|
||||||
|
*/
|
||||||
|
int RECORD_HEADER_PAYLOAD_LENGTH_OFFSET = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of the BQP key commitment in bytes.
|
||||||
|
*/
|
||||||
|
int COMMIT_LENGTH = 16;
|
||||||
|
|
||||||
|
long CONNECTION_TIMEOUT = 20 * 1000; // Milliseconds
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The transport identifier for Bluetooth.
|
||||||
|
*/
|
||||||
|
int TRANSPORT_ID_BLUETOOTH = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The transport identifier for LAN.
|
||||||
|
*/
|
||||||
|
int TRANSPORT_ID_LAN = 1;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user