Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implementing encrypted local storage for user sessions #1191

Closed
wants to merge 2 commits into from
Closed

feat: Implementing encrypted local storage for user sessions #1191

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 17, 2023

New Pull Request Checklist

Issue Description

User data can be copied on rooted devices.

Closes: #1192

Approach

Encrypting local user session using Jetpack security features to ensure better security for rooted devices.

TODOs before merging

  • Add tests
  • Add changes to documentation (guides, repository pages, in-code descriptions)

@parse-github-assistant
Copy link

parse-github-assistant bot commented Mar 17, 2023

Thanks for opening this pull request!

  • 🎉 We are excited about your hands-on contribution!

@mtrezza mtrezza requested a review from a team March 18, 2023 18:03
Copy link
Contributor

@azlekov azlekov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow @DrMimik! Many thanks for this contribution. It's highly appreciated! Looks very clean and nice!

I have the feeling that this is something working for a long time somewhere else, correct me if I'm wrong. I'm guessing that because of the copyright comments.

I left just few questions and small javadoc suggestions. I'm wondering @mtrezza if the migration mechanism should be here forever or there is some policy about that. But if @DrMimik say that already migrated stores are covered and there's no performance issue maybe can stay for a while.


import java.util.Arrays;

public class ParseObjectStoreMigrator<T extends ParseObject> implements ParseObjectStore<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add some Javadoc with comments.

Does this migrator needs to be here forever or just for about some migration period?

Copy link
Author

@ghost ghost Mar 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow @DrMimik! Many thanks for this contribution. It's highly appreciated! Looks very clean and nice!

I have the feeling that this is something working for a long time somewhere else, correct me if I'm wrong. I'm guessing that because of the copyright comments.

I left just few questions and small javadoc suggestions. I'm wondering @mtrezza if the migration mechanism should be here forever or there is some policy about that. But if @DrMimik say that already migrated stores are covered and there's no performance issue maybe can stay for a while.

Thank you guys for creating this awesome platform, I actuallty just copied the ParseObjectStore's logic for creating a new ObjectStore and used Jetpack's crypto library.

Since Robolectric doesn't mock Android's java.security.KeyStore I copied a couple files from this repo (with their copyright XD ) to create tests using Robolectric.

I am actually in a learning process, so please don't hesitate to edit or comment on anything in the code.

Copy link
Author

@ghost ghost Mar 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a specific policy for the duration of providing migration mechanisms. It depends on the type of change. In this case I'd see the mechanism staying for several years, so indefinite at this point. The reason is that it can be a years long process to migrate clientes once they are released to end-users.

I think the migrator should be available for old users until they migrate, or remove it on a major release.

import java.security.GeneralSecurityException;
import java.util.concurrent.Callable;

public class EncryptedFileObjectStore<T extends ParseObject> implements ParseObjectStore<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add Javadoc on the public classes and their public methods you have introduced?

this.legacy = legacy;
}

private static <T extends ParseObject> Task<T> migrate(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to check whenever migrate is needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If from is deleted and next time you call migrate the onSuccessTask what will happen? It will call again onSuccessTask? Is there chance onFailedTask or something similar to be called in such case?

Copy link
Author

@ghost ghost Mar 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out, that is actually a bug which is going to be calling from.getAsync() recursively, I'll fix it ASAP.


override fun generateKeyPair(): KeyPair = wrapped.generateKeyPair().also { keyPair ->
null
// AndroidKeyStore.storedKeys[lastSpec!!.keystoreAlias] = KeyStore.PrivateKeyEntry(keyPair.private, arrayOf(keyPair.toCertificate()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not have commented code.

If this is a TODO or a FIXME or something important for reference later on, please consider adding a descriptive comment instead of deleting it.

}

@Test
public void testGetAsync() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test covering the migrate? Pardon me if is covered already. If it is can you point it to me?

package com.parse

/*
* Copyright 2020 Appmattus Limited
Copy link
Member

@mtrezza mtrezza Mar 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure to consider the license implications. This repository is planned to be migrated to Apache 2, we should do that before merging this, otherwise we need to add this as a second license.

@mtrezza
Copy link
Member

mtrezza commented Mar 18, 2023

We don't have a specific policy for the duration of providing migration mechanisms. It depends on the type of change. In this case I'd see the mechanism staying for several years, so indefinite at this point. The reason is that it can be a years long process to migrate clientes once they are released to end-users.

Fix: migrate method was called recursively in EncryptedFileObjectStore
@azlekov
Copy link
Contributor

azlekov commented May 16, 2023

@mtrezza @DrMimik I believe here we are on the finish line, what do you think can we get this merged?

@rommansabbir
Copy link
Member

Hi, pardon me if my question is out of the context. Why we need to Encrypt the user session for Rooted Device? If a device is rooted, the device is compromised. And to decrypt the Session Token, someone have to decrypt the token by using decode method to get JSON payload. If so, then session token is already Encrypted, so why do we need to add an extra security layer for the Session Token?

@ghost ghost closed this by deleting the head repository Aug 3, 2024
@mtrezza
Copy link
Member

mtrezza commented Aug 5, 2024

@parse-community/android-sdk anyone wants to pick this up and submit a new PR? It seems this was almost ready for merge.

@rommansabbir
Copy link
Member

As it was almost ready for merge, I will work on the PR very soon. Thanks for the attention.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preventing Session Copy On Rooted Devices By Encrypting Current Session Files
3 participants