Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Conversation

@ruslan-bikkinin
Copy link
Contributor

@ruslan-bikkinin ruslan-bikkinin commented Aug 11, 2017

Basic support for bundle's signature verification for android applications has been implemented.

By default, feature is disabled, so no need for clients not interested in code signing to worry about changing code-push sdk initialization code after update.

To use this feature, developers need to use brand new CodePushBuilder or advanced constructor with parameter publicKeyResourceDescriptor specified. Public key must be assisted in string.xml, so it can be available via R.string reference.

Initialization examples:

  • via CodePushBuilder
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
              new CodePushBuilder("deployment-key-here",getApplicationContext())
                      .setPublicKeyResourceDescriptor(R.string.publicKey /* string item in strings.xml */)
                      .build()
      );
    }
  • via constructor
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
              new CodePush(
                      "deployment-key-here",
                      getApplicationContext(),
                      BuildConfig.DEBUG,
                      "https://codepush.azurewebsites.net/"
                      R.string.publicKey /* string item in strings.xml */)
      );
    }

ruslan-bikkinin and others added 4 commits July 27, 2017 15:57
…tern

Add constructor with additional option PublicKeyFilePath
Add `com.auth0:java-jwt:3.2.0` to deps
Adapt changes from code-signing branch
Fix errors appeared due to jwt library update.
Replace publicKey by publicKeyResourceDescriptor in CodePush constructor
Downgrade jwt library to 2.2.2 due to issue with base64 decoding
@msftclas
Copy link

@ruslan-bikkinin,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by Microsoft. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

@ruslan-bikkinin
Copy link
Contributor Author

Description updated with more detailed information about feature usage.

@geof90
Copy link
Contributor

geof90 commented Aug 11, 2017

Awesome to finally see progress in this!

Copy link
Contributor

@max-mironov max-mironov left a comment

Choose a reason for hiding this comment

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

In general looks good to me, I believe we can postpone merging this (although it shouldn't break the existing code-base) unless the relevant code-push-service and code-push-cli changes would be published.

Also we should think about how we can improve code-push initialization with new code-signing feature via react-native link command (and this probably should be merged together with current PR).

private Context mContext;
private final boolean mIsDebugMode;

private String mPublicKey;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to mark this var as Static also in accordance with how you e.g. add this to mServerUrl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@max-mironov it is not so critical, but, yeah, i can do it

try {
mPublicKey = mContext.getString(publicKeyResourceDescriptor);
} catch (Resources.NotFoundException e) {
throw new CodePushUnknownException(
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that we have several places where we throw an UnknownException but why don't we add a more meaningful name to the exception class e.g. something like CodePushInvalidPublicKeyException?
The key point here from my side here - is this a really Unknown exception or do we know what kind of exception it is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@max-mironov good idea, thanks, i'll try to do it


if (isDiffUpdate) {
CodePushUpdateUtils.verifyHashForDiffUpdate(newUpdateFolderPath, newUpdateHash);
CodePushUtils.log("Applying diff update.");
Copy link
Contributor

@max-mironov max-mironov Aug 14, 2017

Choose a reason for hiding this comment

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

Don't think if we ever need this if block here due to we can move this log statement (and this is the only thing that this block is doing now) to Line 255 right after new if (isDiffUpdate) block begins.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@max-mironov no, we can't, because logging should be executed anyway regardless signature verification enabled or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha! May be we can also state what kind of update is applying currently with
isDiffUpdate ? CodePushUtils.log("Applying diff update.") : CodePushUtils.log("Applying full update.") but that is completely up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@max-mironov, good proposition, i think i'll do it your way ☝️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@max-mironov changes added, thx!

ruslan-bikkinin and others added 3 commits August 15, 2017 12:03
Replace CodePushUnknownException catch with
CodePushInvalidPublicKeyException in certain places
Make mPublicKey static
Add additional log for applying updates
Add additional checking for potential problems with code-signing
integration
Fix Public Key parsing from strings.xml
@sergey-akhalkov sergey-akhalkov merged commit 5e332bb into microsoft:master Sep 13, 2017
@ruslan-bikkinin ruslan-bikkinin deleted the code-signing-new branch September 19, 2017 14:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants