private void uploadKeyPairs() { List<ECKeyPair> keyPairs = getKeyPairs(); if (keyPairs.size() == 0) { CMAccountUtils.resetBackoff(mAuthClient.getEncryptionPreferences()); if (CMAccount.DEBUG) Log.d(TAG, "No keys to upload."); return; } if (CMAccountUtils.getCMAccountAccount(mContext) == null) { CMAccountUtils.resetBackoff(mAuthClient.getEncryptionPreferences()); if (CMAccount.DEBUG) Log.d(TAG, "No CMAccount Configured!"); return; } synchronized (mNetworkRequestLock) { if (mNetworkRequestInProgress) { if (CMAccount.DEBUG) Log.d(TAG, "Another network request is in progress, scheduling retry."); scheduleRetry(); return; } mNetworkRequestInProgress = true; } AddPublicKeysRequestBody requestBody = new AddPublicKeysRequestBody(mContext, keyPairs); mAuthClient.addPublicKeys(requestBody, this, this); }
private void storeKeyPair(ECKeyPair keyPair) { String privateKey = CMAccountUtils.encodeHex(keyPair.getPrivateKey().getD()); ECPoint publicKey = keyPair.getPublicKey().getQ(); ContentValues values = new ContentValues(); values.put(CMAccountProvider.ECDHKeyStoreColumns.PRIVATE, privateKey.toString()); values.put( CMAccountProvider.ECDHKeyStoreColumns.PUBLIC, CMAccountUtils.encodeHex(publicKey.getEncoded())); values.put(CMAccountProvider.ECDHKeyStoreColumns.KEY_ID, keyPair.getKeyId()); mContext.getContentResolver().insert(CMAccountProvider.ECDH_CONTENT_URI, values); }
@Override public void onResponse(AddPublicKeysResponse response) { if (response.statusCode == 200) { removePublicKeys(response); CMAccountUtils.resetBackoff(mAuthClient.getEncryptionPreferences()); } else { handleError(); } synchronized (mNetworkRequestLock) { mNetworkRequestInProgress = false; } }
private void scheduleRetry() { final Context context = mContext.getApplicationContext(); mIntent.putExtra(ECDHKeyService.EXTRA_RETRY, true); CMAccountUtils.scheduleRetry(context, mAuthClient.getEncryptionPreferences(), mIntent); }