MCPcopy Create free account
hub / github.com/M66B/FairEmail / _call

Method _call

app/src/main/java/eu/faircode/email/CloudSync.java:631–762  ·  view source on GitHub ↗
(Context context, String user, String password, JSONObject jrequest)

Source from the content-addressed store, hash-verified

629 }
630
631 private static JSONObject _call(Context context, String user, String password, JSONObject jrequest)
632 throws GeneralSecurityException, JSONException, IOException, InvalidCipherTextException {
633 byte[] salt = getSalt(user);
634 String cloudUser = getCloudUser(salt);
635
636 Pair<byte[], byte[]> key;
637 String lookup = Helper.hex(salt) + ":" + password;
638 synchronized (keyCache) {
639 key = keyCache.get(lookup);
640 }
641 if (key == null) {
642 EntityLog.log(context, EntityLog.Type.Cloud, "Cloud generating key");
643 key = getKeyPair(salt, password);
644 synchronized (keyCache) {
645 keyCache.put(lookup, key);
646 }
647 } else {
648 EntityLog.log(context, EntityLog.Type.Cloud, "Cloud using cached key");
649 }
650
651 String cloudPassword = Base64.encodeToString(key.first, Base64.NO_PADDING | Base64.NO_WRAP);
652
653 jrequest.put("version", 1);
654 jrequest.put("username", cloudUser);
655 jrequest.put("password", cloudPassword);
656 jrequest.put("debug", BuildConfig.DEBUG);
657
658 if (jrequest.has("items")) {
659 JSONArray jitems = jrequest.getJSONArray("items");
660 for (int i = 0; i < jitems.length(); i++) {
661 JSONObject jitem = jitems.getJSONObject(i);
662 long revision = jitem.optLong("rev", 0);
663
664 String k = jitem.getString("key");
665 String v = null;
666 if (jitem.has("val") && !jitem.isNull("val")) {
667 v = jitem.getString("val");
668 jitem.put("val", transform(v, key.second, getIv(revision), getAd(k, revision), true));
669 }
670 v = (v == null ? null : "#" + v.length());
671
672 Log.i("Cloud > " + k + "=" + v + " @" + revision);
673 }
674 }
675
676 String request = jrequest.toString();
677 EntityLog.log(context, EntityLog.Type.Cloud,
678 "Cloud request length=" + request.length());
679
680 URL url = new URL(BuildConfig.CLOUD_URI);
681 HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
682 connection.setRequestMethod("POST");
683 connection.setDoInput(true);
684 connection.setDoOutput(true);
685 connection.setReadTimeout(CLOUD_TIMEOUT);
686 connection.setConnectTimeout(CLOUD_TIMEOUT);
687 ConnectionHelper.setUserAgent(context, connection);
688 connection.setRequestProperty("Accept", "application/json");

Callers 1

callMethod · 0.95

Calls 15

getSaltMethod · 0.95
getCloudUserMethod · 0.95
hexMethod · 0.95
logMethod · 0.95
getKeyPairMethod · 0.95
transformMethod · 0.95
getIvMethod · 0.95
getAdMethod · 0.95
iMethod · 0.95
setUserAgentMethod · 0.95
readStreamMethod · 0.95
eMethod · 0.95

Tested by

no test coverage detected