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

Jimin/dev5 key #1123

Merged
merged 60 commits into from
Aug 11, 2022
Merged

Jimin/dev5 key #1123

merged 60 commits into from
Aug 11, 2022

Conversation

jiminwen-msft
Copy link
Member

@jiminwen-msft jiminwen-msft commented May 26, 2022

task:

  1. https://skype.visualstudio.com/SPOOL/_workitems/edit/2823275
  2. https://skype.visualstudio.com/SPOOL/_workitems/edit/2867798

Related PR: #1097

This PR tries to

  1. Introduce a reliable approach of refreshing push notification registration using worker manager. There are changes to both SDK and sample app. Contoso APP is required to make configuration change in order to run WorkManager in background. Otherwise, client faces RuntimeException.
  2. Introduce key-store to persist secrete keys. Secrete keys are used for push notification registration and decrypt push notification payloads. Using key-store ensure the keys are persisted even APP gets closed. And instead of storing two pairs of secrete keys. We change to store 10 pairs of keys. And try all of them when decrypt push notification payload.
  3. We set registration renewal work to repeat every 15 minutes. And set TTL of push notification registration as 45 minutes. So that we have 3 chances of execute worker before it expires.

More specific changes:

  • SDK side:
  1. RegistrationRenewalWorker: The worker that renews registration.
  2. RegistrationRenewalWorkerFactory : Factory for the worker. It is created because we could not rely on the default factory. We need customized factory which injects the CommunicationCredential. And this CommunicationCredential needs to be injected from Tontoso APP during the initiation phase of the APP.
  3. RegistrationDataContainer : Data container for updating and storing secrete keys shared by PushNotificationClient and RenewalTokenWorker. It wraps key-store inside. So that it could persist all pairs of secrete keys in file system.
    Gradle: inject worker related dependency

For Contoso. Configuration changes are required to use the WorkerManager.

  1. Create customized configuration to use RenewalTokenWorkerFactory
  2. manifest change to refer to the configuration
  3. Gradle: inject worker related dependency

@jiminwen-msft jiminwen-msft requested review from JianpingChen and a team as code owners May 26, 2022 18:03
@ghost ghost added the Communication label May 26, 2022
Copy link
Member

@vcolin7 vcolin7 left a comment

Choose a reason for hiding this comment

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

Added some comments in general and a couple about the use of KeyStore.


private boolean lastExecutionSucceeded = true;

//The duration we persist keys in key-store
public static final int EXPIRATION_TIME_MINUTES = 45;
public static final int EXPIRATION_TIME_MINUTES = 25;
Copy link
Member

Choose a reason for hiding this comment

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

I remember the previous expiry time was 45, was this changed on the server side as well or is there a particular reason it got client-side?

Copy link
Member

Choose a reason for hiding this comment

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

Not that I'm opposed to rotating keys earlier, I was simply curious.

@@ -56,6 +82,10 @@ public static RegistrationKeyManager instance() {
return registrationKeyManager;
}

private char[] getKeyStorePassword() {
return "com.azure.android.communication.chat.android".toCharArray();
Copy link
Member

Choose a reason for hiding this comment

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

Why are we using a hard-coded value as a password? Is this standard practice for KeyStore? I would be very surprised if that's the case.

Copy link
Member Author

Choose a reason for hiding this comment

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

The password field is actually optional. I am adding it here to slightly increase the difficulty of hack the system. Having a password that keeps changing is challenging to implement. Which way do you suggest? 1. Adding some transform function to make this password complex 2. Skipping the password 3. Alternative ways that I am not aware of.

Copy link
Member Author

Choose a reason for hiding this comment

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

Based on offline discussion. The password field will be empty/null. I am investigating changing keystore type from default "AES" to "AndroidKeyStore"

Comment on lines 133 to 134
Log.i("RenewRegistration", "crypto alias: " + crypAlias + ", crypto string: " + crypStr + ", time: " + timeDiff);
Log.i("RenewRegistration", "auth alias: " + auAlias + ", auth string: " + aKeyStr + ", time: " + timeDiff);
Copy link
Member

Choose a reason for hiding this comment

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

Remember to log using ClientLogger. Maybe this was left off from manual testing?

Copy link
Member

@vcolin7 vcolin7 left a comment

Choose a reason for hiding this comment

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

Added a suggestion for the new exception added for when the push notification configuration is incorrect.


public RegistrationRenewalWorker(@NonNull Context context, @NonNull WorkerParameters workerParameters) {
super(context, workerParameters);
throw new RuntimeException("Missing worker manager configurations. Please follow quick-start guidance to properly set it up: https://docs.microsoft.com/en-us/azure/communication-services/quickstarts/chat/get-started?pivots=programming-language-android");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
throw new RuntimeException("Missing worker manager configurations. Please follow quick-start guidance to properly set it up: https://docs.microsoft.com/en-us/azure/communication-services/quickstarts/chat/get-started?pivots=programming-language-android");
throw clientLogger.logExceptionAsError(new RuntimeException("Missing worker manager configuration for enabling push notifications. Please follow quick-start guidance to properly set it up: https://docs.microsoft.com/en-us/azure/communication-services/quickstarts/chat/get-started?pivots=programming-language-android"));

@vcolin7
Copy link
Member

vcolin7 commented Aug 11, 2022

/check-enforer evaluate

@vcolin7
Copy link
Member

vcolin7 commented Aug 11, 2022

/check-enforcer override.

@vcolin7
Copy link
Member

vcolin7 commented Aug 11, 2022

/check-enforcer override

@jiminwen-msft jiminwen-msft merged commit bccb27a into main Aug 11, 2022
@jiminwen-msft jiminwen-msft deleted the jimin/dev5_key branch August 11, 2022 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants