Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/common/privatebin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,17 @@ std::string paste(std::string_view server, std::string_view text, std::string_vi
if (reply_http.status != 200 || !reply.is_object() || reply.value("status", 1) != 0 ||
!reply.contains("id") || !reply["id"].is_string() || !valid_id(reply["id"].get<std::string>())) {
std::string why = reason(reply);
throw std::runtime_error(why.empty() ? "The upload service answered " + std::to_string(reply_http.status) + "."
: "The upload service refused it: " + why);
if (!why.empty()) throw std::runtime_error("The upload service refused it: " + why);
// Not a PrivateBin answer (a proxy or firewall in front of it): show how it began, in one line.
std::string excerpt;
for (char c : reply_http.body) {
if (excerpt.size() >= 120) break;
if (c == '\r' || c == '\n' || c == '\t') c = ' ';
if (static_cast<unsigned char>(c) >= 0x20 && static_cast<unsigned char>(c) < 0x7f && !(c == ' ' && (excerpt.empty() || excerpt.back() == ' ')))
excerpt += c;
}
throw std::runtime_error("The upload service answered " + std::to_string(reply_http.status) +
(excerpt.empty() ? "." : ": " + excerpt));
}
return std::string(server) + "/?" + reply["id"].get<std::string>() + "#" + sealed.fragment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,14 @@ public boolean hasSystemFeature(String name, int version) {
return false;
}
public int checkPermission(String permission, String pkg) {
if (!model.info.packageName.equals(pkg) || !model.permissions.contains(permission)) return -1;
if (!model.info.packageName.equals(pkg)) return -1;
// Android's implicit permission split: an app that declares WRITE_EXTERNAL_STORAGE is also
// treated as holding READ_EXTERNAL_STORAGE, so one that checks (or requests) READ alone, as
// media players do before listing a folder, is not refused for a permission it never needed
// to declare.
boolean impliedRead = "android.permission.READ_EXTERNAL_STORAGE".equals(permission)
&& model.permissions.contains("android.permission.WRITE_EXTERNAL_STORAGE");
if (!impliedRead && !model.permissions.contains(permission)) return -1;
// Runtime permissions the Quest permission dialog grants (RECORD_AUDIO).
if (com.venture.runtime.RuntimePermissions.granted(model, permission)) return 0;
return java.util.Set
Expand Down
10 changes: 10 additions & 0 deletions tests/java/FrameworkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,16 @@ public void onCapabilitiesChanged(android.net.Network network, android.net.Netwo
&& micPackages.checkPermission("android.permission.RECORD_AUDIO", "other.package") == -1
&& micPackages.checkPermission("android.permission.CAMERA", "test.mic") == -1,
"the permission dialog grants the microphone, not the camera");
var storageManifest = manifestNode("manifest", "package", "test.storage");
storageManifest.children.add(manifestNode("uses-permission", "name", "android.permission.WRITE_EXTERNAL_STORAGE"));
storageManifest.children.add(manifestNode("application"));
var storagePackages = new android.content.pm.PackageManager(new PackageModel(storageManifest));
check(storagePackages.checkPermission("android.permission.READ_EXTERNAL_STORAGE", "test.storage") == 0
&& storagePackages.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", "test.storage") == 0
&& storagePackages.checkPermission("android.permission.READ_EXTERNAL_STORAGE", "other.package") == -1,
"declaring WRITE_EXTERNAL_STORAGE also grants READ_EXTERNAL_STORAGE");
check(new android.content.pm.PackageManager(micModel).checkPermission("android.permission.READ_EXTERNAL_STORAGE", "test.mic") == -1,
"READ_EXTERNAL_STORAGE is not implied without WRITE_EXTERNAL_STORAGE");
var undeclaredMic = new PackageModel(manifest);
undeclaredMic.info.applicationInfo.targetSdkVersion = 32;
com.venture.runtime.RuntimePermissions.request(undeclaredMic, new String[] {"android.permission.RECORD_AUDIO"});
Expand Down
4 changes: 4 additions & 0 deletions tests/jre_modules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def test_tls_and_ec_crypto_are_in_the_jre(self):
# Android's EC KeyPairGenerator, KeyAgreement and Signature algorithms need it as well.
self.assertIn("jdk.crypto.ec", modules())

def test_extended_charsets_are_in_the_jre(self):
# Android has GB2312, Big5, Shift_JIS ... built in; SKYBOX's startup asks for GB2312 by name.
self.assertIn("jdk.charsets", modules())


if __name__ == "__main__":
sys.exit(unittest.main())
8 changes: 3 additions & 5 deletions tests/privatebin_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ TEST_CASE("PrivateBin encodings and paste round trip") {
CHECK(privatebin::base64(crypto::Bytes{'f', 'o', 'o'}) == "Zm9v");
CHECK(privatebin::base58(crypto::Bytes{0, 0, 1}) == "112");
CHECK(privatebin::base58(crypto::Bytes{'h', 'e', 'l', 'l', 'o'}) == "Cn8eVZg");
std::string text = "report café "quoted" \ tab
";
for (int i = 0; i < 2000; ++i) text += "12345.678 I [launch] repeated log line " + std::to_string(i) + "
";
std::string text = "report caf\xC3\xA9 \"quoted\" \\ tab\t\n";
for (int i = 0; i < 2000; ++i) text += "12345.678 I [launch] repeated log line " + std::to_string(i) + "\n";
auto enc = privatebin::encrypt(text, "1month");
CHECK(privatebin::decrypt(enc.body, enc.fragment) == text);
auto other = privatebin::encrypt(text, "1month");
CHECK_THROWS(privatebin::decrypt(enc.body, other.fragment));
auto odd = privatebin::encrypt("bad byte ÿþ here", "1day");
auto odd = privatebin::encrypt("bad byte \xFF\xFE here", "1day");
CHECK(privatebin::decrypt(odd.body, odd.fragment).starts_with("bad byte"));
}
5 changes: 4 additions & 1 deletion tools/dex/make_jre.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
# JSSE offers no ECDHE group, no ECDHE suite and no ECDSA signature, so Google, Firebase and most
# CDN servers answer every HTTPS ClientHello with handshake_failure (issue 168). Dev runs use the
# full JDK, so only the shipped JRE showed it.
# jdk.charsets: the extended charsets (GB2312, GBK, Big5, Shift_JIS, EUC-KR, ...). Android always has
# them, and apps ask for them by name: SKYBOX's native startup calls String.getBytes("GB2312") and
# died with UnsupportedEncodingException on the base-only JRE.
# No java.sql or java.net.http.
MODULES = "java.base,java.logging,java.xml,java.desktop,jdk.crypto.ec,jdk.unsupported"
MODULES = "java.base,java.logging,java.xml,java.desktop,jdk.charsets,jdk.crypto.ec,jdk.unsupported"


def main():
Expand Down
Loading