|
@@ -34,6 +34,7 @@ import android.view.View;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.nextcloud.client.account.User;
|
|
|
import com.owncloud.android.R;
|
|
|
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
|
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
|
@@ -70,15 +71,15 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
|
|
|
public static final String SETUP_ENCRYPTION_DIALOG_TAG = "SETUP_ENCRYPTION_DIALOG_TAG";
|
|
|
public static final String ARG_POSITION = "ARG_POSITION";
|
|
|
|
|
|
- private static String ARG_ACCOUNT = "ARG_ACCOUNT";
|
|
|
- private static String TAG = SetupEncryptionDialogFragment.class.getSimpleName();
|
|
|
+ private static final String ARG_USER = "ARG_USER";
|
|
|
+ private static final String TAG = SetupEncryptionDialogFragment.class.getSimpleName();
|
|
|
|
|
|
private static final String KEY_CREATED = "KEY_CREATED";
|
|
|
private static final String KEY_EXISTING_USED = "KEY_EXISTING_USED";
|
|
|
private static final String KEY_FAILED = "KEY_FAILED";
|
|
|
private static final String KEY_GENERATE = "KEY_GENERATE";
|
|
|
|
|
|
- private Account account;
|
|
|
+ private User user;
|
|
|
private TextView textView;
|
|
|
private TextView passphraseTextView;
|
|
|
private ArbitraryDataProvider arbitraryDataProvider;
|
|
@@ -94,10 +95,10 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
|
|
|
*
|
|
|
* @return Dialog ready to show.
|
|
|
*/
|
|
|
- public static SetupEncryptionDialogFragment newInstance(Account account, int position) {
|
|
|
+ public static SetupEncryptionDialogFragment newInstance(User user, int position) {
|
|
|
SetupEncryptionDialogFragment fragment = new SetupEncryptionDialogFragment();
|
|
|
Bundle args = new Bundle();
|
|
|
- args.putParcelable(ARG_ACCOUNT, account);
|
|
|
+ args.putParcelable(ARG_USER, user);
|
|
|
args.putInt(ARG_POSITION, position);
|
|
|
fragment.setArguments(args);
|
|
|
return fragment;
|
|
@@ -125,7 +126,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
|
|
|
@Override
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
|
int primaryColor = ThemeUtils.primaryColor(getContext());
|
|
|
- account = getArguments().getParcelable(ARG_ACCOUNT);
|
|
|
+ user = getArguments().getParcelable(ARG_USER);
|
|
|
|
|
|
arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
|
|
|
|
|
@@ -192,13 +193,13 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
|
|
|
String decryptedPrivateKey = EncryptionUtils.decryptPrivateKey(privateKey,
|
|
|
mnemonic);
|
|
|
|
|
|
- arbitraryDataProvider.storeOrUpdateKeyValue(account.name,
|
|
|
+ arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(),
|
|
|
EncryptionUtils.PRIVATE_KEY, decryptedPrivateKey);
|
|
|
|
|
|
dialog.dismiss();
|
|
|
Log_OC.d(TAG, "Private key successfully decrypted and stored");
|
|
|
|
|
|
- arbitraryDataProvider.storeOrUpdateKeyValue(account.name, EncryptionUtils.MNEMONIC,
|
|
|
+ arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), EncryptionUtils.MNEMONIC,
|
|
|
mnemonicUnchanged);
|
|
|
|
|
|
Intent intentExisting = new Intent();
|
|
@@ -254,23 +255,23 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
|
|
|
// - decrypt private key, store unencrypted private key in database
|
|
|
|
|
|
GetPublicKeyOperation publicKeyOperation = new GetPublicKeyOperation();
|
|
|
- RemoteOperationResult publicKeyResult = publicKeyOperation.execute(account, getContext());
|
|
|
+ RemoteOperationResult publicKeyResult = publicKeyOperation.execute(user.toPlatformAccount(), getContext());
|
|
|
|
|
|
if (publicKeyResult.isSuccess()) {
|
|
|
- Log_OC.d(TAG, "public key successful downloaded for " + account.name);
|
|
|
+ Log_OC.d(TAG, "public key successful downloaded for " + user.getAccountName());
|
|
|
|
|
|
String publicKeyFromServer = (String) publicKeyResult.getData().get(0);
|
|
|
- arbitraryDataProvider.storeOrUpdateKeyValue(account.name, EncryptionUtils.PUBLIC_KEY,
|
|
|
+ arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), EncryptionUtils.PUBLIC_KEY,
|
|
|
publicKeyFromServer);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
GetPrivateKeyOperation privateKeyOperation = new GetPrivateKeyOperation();
|
|
|
- RemoteOperationResult privateKeyResult = privateKeyOperation.execute(account, getContext());
|
|
|
+ RemoteOperationResult privateKeyResult = privateKeyOperation.execute(user.toPlatformAccount(), getContext());
|
|
|
|
|
|
if (privateKeyResult.isSuccess()) {
|
|
|
- Log_OC.d(TAG, "private key successful downloaded for " + account.name);
|
|
|
+ Log_OC.d(TAG, "private key successful downloaded for " + user.getAccountName());
|
|
|
|
|
|
keyResult = KEY_EXISTING_USED;
|
|
|
return (String) privateKeyResult.getData().get(0);
|
|
@@ -337,11 +338,11 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
|
|
|
|
|
|
// create CSR
|
|
|
AccountManager accountManager = AccountManager.get(getContext());
|
|
|
- String userId = accountManager.getUserData(account, AccountUtils.Constants.KEY_USER_ID);
|
|
|
+ String userId = accountManager.getUserData(user.toPlatformAccount(), AccountUtils.Constants.KEY_USER_ID);
|
|
|
String urlEncoded = CsrHelper.generateCsrPemEncodedString(keyPair, userId);
|
|
|
|
|
|
SendCSROperation operation = new SendCSROperation(urlEncoded);
|
|
|
- RemoteOperationResult result = operation.execute(account, getContext());
|
|
|
+ RemoteOperationResult result = operation.execute(user.toPlatformAccount(), getContext());
|
|
|
|
|
|
if (result.isSuccess()) {
|
|
|
Log_OC.d(TAG, "public key success");
|
|
@@ -359,22 +360,23 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
|
|
|
|
|
|
// upload encryptedPrivateKey
|
|
|
StorePrivateKeyOperation storePrivateKeyOperation = new StorePrivateKeyOperation(encryptedPrivateKey);
|
|
|
- RemoteOperationResult storePrivateKeyResult = storePrivateKeyOperation.execute(account, getContext());
|
|
|
+ RemoteOperationResult storePrivateKeyResult = storePrivateKeyOperation.execute(user.toPlatformAccount(),
|
|
|
+ getContext());
|
|
|
|
|
|
if (storePrivateKeyResult.isSuccess()) {
|
|
|
Log_OC.d(TAG, "private key success");
|
|
|
|
|
|
- arbitraryDataProvider.storeOrUpdateKeyValue(account.name, EncryptionUtils.PRIVATE_KEY,
|
|
|
+ arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), EncryptionUtils.PRIVATE_KEY,
|
|
|
privateKeyString);
|
|
|
- arbitraryDataProvider.storeOrUpdateKeyValue(account.name, EncryptionUtils.PUBLIC_KEY, publicKey);
|
|
|
- arbitraryDataProvider.storeOrUpdateKeyValue(account.name, EncryptionUtils.MNEMONIC,
|
|
|
+ arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), EncryptionUtils.PUBLIC_KEY, publicKey);
|
|
|
+ arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), EncryptionUtils.MNEMONIC,
|
|
|
generateMnemonicString(true));
|
|
|
|
|
|
keyResult = KEY_CREATED;
|
|
|
return (String) storePrivateKeyResult.getData().get(0);
|
|
|
} else {
|
|
|
DeletePublicKeyOperation deletePublicKeyOperation = new DeletePublicKeyOperation();
|
|
|
- deletePublicKeyOperation.execute(account, getContext());
|
|
|
+ deletePublicKeyOperation.execute(user.toPlatformAccount(), getContext());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
Log_OC.e(TAG, e.getMessage());
|