Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Aug 30, 2023
1 parent bbf611d commit f22cb87
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
if (share != null) {
OCFile file = getStorageManager().getFileByEncryptedRemotePath(remotePath);

if (file.isEncrypted()) {
if (file.isEncrypted() && share.getShareType() != ShareType.PUBLIC_LINK) {
// E2E: lock folder
try {
token = EncryptionUtils.lockFolder(file, client, file.getE2eCounter() + 1);
Expand Down Expand Up @@ -128,9 +128,11 @@ protected RemoteOperationResult run(OwnCloudClient client) {

if (result.isSuccess()) {
// E2E: unlock folder
RemoteOperationResult<Void> unlockResult = EncryptionUtils.unlockFolder(file, client, token);
if (!unlockResult.isSuccess()) {
return new RemoteOperationResult<>(new RuntimeException("Unlock failed"));
if (file.isEncrypted() && share.getShareType() != ShareType.PUBLIC_LINK) {
RemoteOperationResult<Void> unlockResult = EncryptionUtils.unlockFolder(file, client, token);
if (!unlockResult.isSuccess()) {
return new RemoteOperationResult<>(new RuntimeException("Unlock failed"));
}
}

Log_OC.d(TAG, "Share id = " + share.getRemoteId() + " deleted");
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ private void setupE2EKeysExist(PreferenceCategory preferenceCategoryMore) {
}

private void setupE2EMnemonicPreference(PreferenceCategory preferenceCategoryMore) {
String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC);
String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC).trim();

Preference pMnemonic = findPreference("mnemonic");
if (pMnemonic != null) {
Expand Down Expand Up @@ -991,7 +991,7 @@ public void handleMnemonicRequest(Intent data) {
RequestCredentialsActivity.KEY_CHECK_RESULT_TRUE) {

ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProviderImpl(this);
String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC);
String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC).trim();

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.FallbackTheming_Dialog);
AlertDialog alertDialog = builder.setTitle(R.string.prefs_e2e_mnemonic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ private Dialog createDialog(View v) {
mnemonic);

arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(),
EncryptionUtils.PRIVATE_KEY, decryptedPrivateKey);
EncryptionUtils.PRIVATE_KEY,
decryptedPrivateKey);

dialog1.dismiss();
Log_OC.d(TAG, "Private key successfully decrypted and stored");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,18 @@ private void setupView() {

if (file.canReshare()) {
if (file.isEncrypted() || (parentFile != null && parentFile.isEncrypted())) {
binding.searchView.setQueryHint(getResources().getString(R.string.secure_share_search));
if (file.getE2eCounter() == -1) {
// V1 cannot share
binding.searchContainer.setVisibility(View.GONE);
} else {
binding.searchView.setQueryHint(getResources().getString(R.string.secure_share_search));

if (file.isSharedViaLink()) {
binding.searchView.setQueryHint(getResources().getString(R.string.share_not_allowed_when_file_drop));
binding.searchView.setInputType(InputType.TYPE_NULL);
disableSearchView(binding.searchView);
}
}
} else {
binding.searchView.setQueryHint(getResources().getString(R.string.share_search));
}
Expand Down Expand Up @@ -429,6 +440,7 @@ public void refreshCapabilitiesFromDB() {
* before reading database.
*/
public void refreshSharesFromDB() {
file = fileDataStorageManager.getFileById(file.getFileId());
ShareeListAdapter adapter = (ShareeListAdapter) binding.sharesList.getAdapter();

if (adapter == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.owncloud.android.lib.resources.e2ee.StoreMetadataRemoteOperation;
import com.owncloud.android.lib.resources.e2ee.StoreMetadataV2RemoteOperation;
import com.owncloud.android.lib.resources.e2ee.UnlockFileRemoteOperation;
import com.owncloud.android.lib.resources.e2ee.UnlockFileV1RemoteOperation;
import com.owncloud.android.lib.resources.e2ee.UpdateMetadataRemoteOperation;
import com.owncloud.android.lib.resources.e2ee.UpdateMetadataV2RemoteOperation;
import com.owncloud.android.lib.resources.status.E2EVersion;
Expand Down Expand Up @@ -234,7 +235,7 @@ public static EncryptedFolderMetadataFileV1 encryptFolderMetadata(
}

// set checksum
String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC);
String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC).trim();
String checksum = EncryptionUtils.generateChecksum(decryptedFolderMetadata, mnemonic);
encryptedFolderMetadata.getMetadata().setChecksum(checksum);

Expand Down Expand Up @@ -1421,6 +1422,14 @@ public static RemoteOperationResult<Void> unlockFolder(OCFile parentFolder, OwnC
}
}

public static RemoteOperationResult<Void> unlockFolderV1(OCFile parentFolder, OwnCloudClient client, String token) {
if (token != null) {
return new UnlockFileV1RemoteOperation(parentFolder.getLocalId(), token).execute(client);
} else {
return new RemoteOperationResult<>(new Exception("No token available"));
}
}

public static X509Certificate convertCertFromString(String string) throws CertificateException {
String trimmedCert = string.replace("-----BEGIN CERTIFICATE-----\n", "")
.replace("-----END CERTIFICATE-----\n", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,6 @@ class EncryptionUtilsV2 {
ocFile.setE2eCounter(metadataFile.metadata.counter)
fileDataStorageManager.saveFile(ocFile)

// TODO change metadata key always?

return metadataFile
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1116,4 +1116,5 @@
<string name="sub_folder_rule_day">Year/Month/Day</string>
<string name="secure_sharing_failed">Secure sharing failed</string>
<string name="secure_share_not_set_up">Secure sharing is not set up for this user</string>
<string name="share_not_allowed_when_file_drop">Resharing is not allowed during secure file drop</string>
</resources>

0 comments on commit f22cb87

Please sign in to comment.