Solution 1 :
Google doesn’t just have the capability to modify .apk
files uploaded to it’s Google Play signing program- they already are.
Granted, this is at the moment a minor change and certainly a non-malicious one; but it remains an actual change of your .apk
. They add
<meta-data
android_name="com.android.vending.derived.apk.id"
android_value="1" />
to the AndroidManifest.xml
Below is a comparison that I made in 2018 while researching this topic. It has the apk before upload (signed with upload key), and the apk as downloaded from Google Play with Google play signing enabled.
As you can see from this graphic; there’s only two changes- the old signing (upload key) was removed, and replaced with Google signing. And also the AndroidManifest.xml was slightly appended (with the meta-data mentioned above)
I’ll also point out this Google IO video from 2017 where they’re introducing Google Play signing: https://www.youtube.com/watch?v=5tdGAP927dk&feature=youtu.be. From 11:25 in they’re talking about something called “App signing + optimizations”. The idea was that they could optimize apks for you, and generate sub-apks.
This was something that you could enable on a per-apk basis within Google Play. Today of course, you’ll find no mention of any of this in any documentation, other than in this video- That’s because they later came up with app bundles and essentially moved all this work into that. So, this is mostly relevant because the question was “What Stops Google From Modifying Our APKs That It Signs Via the App Signing Service?”, and this shows that even specifically for .apk
files they can; they intended to; and they were.
As others have pointed out; whoever has the signing keys and access to the Google Play account for the given app- can upload any .apk
or .aab
containing anything; as long as the packageName remains the same, and versionCode is incremented by one. The same applies of course to Google when Google Play signing is enabled. If they wanted, they could change, remove or add to any and all parts of the application.
It’s worth keeping in mind that while yes; Google could modify everything and anything within the Google Play signed .apk
file(s), those modifications aren’t necessarily evil or with a bad intent. Whether for optimization purposes, compatibility or hot-fixing; there are plenty of reasons Google could or would modify the uploaded apk and justify those modifications. And they wouldn’t necessarily warn the developers about this; nor would developers necessarily react to a discovery of this with an outcry.
I do believe that we’re very unlikely to see Google perform purposely malicious content changes to uploaded apps, mostly for business, reputation and ethical risks outlined well in the other answers here already. I just can’t picture this being a valuable attack vector for Google that outweighs the rather heavy cost-risk, and considering the other, often stronger vectors available to them.
Lastly, I’ll mention integrity checks as one way this would be discovered. There are several solutions in this space that goes further than signature checks to verify the integrity of the app. Whether app developers roll their own, or use an off-the-shelves solution- these checks typically run during runtime on device to verify the integrity of the apk; comparing against records taken during compile-time or near compile-time. Modifications performed to the apk during transit does get picked up by this, including whatever change Google Play might do.
Disclaimer: I work for a app-security company that performs such integrity checks (any many other checks and verifications) on the apps that we protect. We’ve had to map out and account for all changes Google Play might do to an app both for regular apk files and app bundles- so we can distinguish between Google Play doing optimizations and a malicious actor repackaging the app.
Solution 2 :
At some point, the processor needs to be able to read the instructions in your app to know what it’s supposed to do. The operating system itself needs to know what to do with your app.
Ignoring how an app is packaged for a moment, for the aforementioned reasons, it seems to me there is no technical reason why your app cannot be modified by Google or any technical entity that has the knowledge and resources to do so. Let me explain further why:
It doesn’t matter how the app is packaged – the moment the operating system loads the app, you know what the app does. If the operating system did not know how to handle an app, the app would be useless.
You can try to obfuscate it, the way some popular worms tried to hide their purpose, but it really just delays the inevitable. People have been disassembling and decompiling software right from the beginning, that’s why many licenses used to explicitly prohibit disassembly.
Knowing this, it should be apparent that if “Google” wanted to modify your app they could, because even if the package is obfuscated, when the app is ultimately executing you could see what its doing then, document it, and then modify the app as required. They also have all the technical skills and resources to do so.
Let’s step back for a moment:
The purpose of signing something with a signature, is so that one can determine if the copy of the app they have received is authentic – in this case, if the app that an end user has received matches what is on the play store. The purpose being to ensure the copy you have is the same as the one distributed to other users.
You’re asking if there is a technical reason why Google cannot modify the app – no there isn’t. You’ve mentioned yourself that an apk is just a zip file. If your app was signed by yourself, and that same signature was included in the copy of the app that the end user received, then the end user could verify if Google had tampered with your app. But if your signature is stripped, then the user is left with having to trust Google.
Your question is interesting, because it made me think of something else : I guess the context in which you asked your question was “would Google be able to modify the app before distribution”. With modern devices becoming increasingly powerful, what’s to stop the operating system (since a manufacturer can customise their version of android), from modifying the app after distribution, or in future, on the fly while it executes?
I’m leaving this paper here below:
https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_ReflectionsonTrustingTrust.pdf
The reason being it seems this will always be a perennial question, as it’s impossible for human beings to single handedly verify every piece of software in the kind of systems we use today.
I also find it a bit funny that people think that just because source code is available for an app, that it means they can trust the app which is actually running on their device – unless they’ve gone through the trouble of actually examining the app on their device, it technically is possible that the app running on their device is not the same as the source code describes – it could have been modified by both the developer themselves, or the store distributing the app for malicious or accidental reasons.
But trust has to begin somewhere ♂️. In future, with Quantum Computing, maybe the way we do things will change. But again, there are so few of us who actually understand how every piece of a system works, we will still have to place our trust somewhere. Even if we understand something, having the resources to verify it is another matter as well…
so what stops Google from modifying it?
- Do they really need to? It’s the developers which create value for Google Play by creating and submitting their apps.
- Would you trust Google if they modified your app without your permission? How would it affect your perception of them as a company, since privacy is already a major issue.
- In the event that a modification of theirs causes your app to behave incorrectly and cause damage to a customer, yourself or some third party entity, who will be held liable?
The above are just some of the reasons to think about when considering if Google will modify your app. It’s a can of worms. In the end, it boils down to cost-benefit & risk-reward analysis. What would they modify your app for, and is it worth any risk of repercussions?
In summation, there is no technical reason why they can’t. Why they don’t / won’t boils down to their business motivations and model. There is nothing to say why they will or won’t in future. But there is no reason to arbitrarily modify an app – there has to be a valid business reason which results in some kind of gain.
Solution 3 :
Simple answer: Google can, if they want to. In a digital signature scheme the signer has complete capability of modifying the document prior to signing.
Why they won’t: Because developer can easily detect it, and the payload which is of most importance – the classes*.dex, actually containing the code – can easily be decompiled by interested third parties (or the app creator) to figure out any added code. (Adding code into JNI libraries is even less likely). To clarify, the detection by the developer is as easy as unzipping the APK and comparing its contents to what the developer submitted.
The impact of adding code to an app without notifying the developer would likely cause quite a backlash if discovered. Of course, at any further date Google could decide to change their terms of use, migrate from DEX to LLVM bitcode, or do something else, which might change this behavior.
Clarification: It is true, that Google could in theory ship modified apps only to certain targets, but once again it suffices that one such incident be detected (maybe by a concerned app-user mailing his or her APK to the developer?) for the implications to be far reaching for Google.
This, btw, holds true for Apple as well, being the signer of all App-Store apps. In the Apple case it’s even more of a question, since apps may get recompiled by Apple (from BitCode to to the underlying ARMv8 variant), and apps deploy encrypted by FairPlay, which makes it virtually impossible to decrypt the app outside a jailbroken device.
As an anecdote, you could wonder if a malicious device vendor couldn’t change dex2oat (the on-device compiler) to inject arbitrary code when the app is installed and compiled on the device itself. This would be much harder to detect, since on a non rooted device there would not be an easy way to access the compiled art/oat files of the app. But then, malicious vendors can also directly modify the Android frameworks, as well.
Solution 4 :
Apologies for potential anachronism here.
When you say
the App Signing service strips away whatever signature that we have
are you sure this is what it does? One could imagine an alternative scheme, which could achieve everything noted in other answers / comments as actually occurring:
Assume that the dev has uploaded their artefacts (let’s say as an .obb) and signed it using their upload key. Google appends its additional metadata (think of it as a kind of diff file) and re-signs the resulting expanded payload. On receipt at the device, android checks that the payload it has received was correctly signed by Google (which it was), removes (but keeps) the metadata Google added, then checks the remaining payload (the dev’s .obb) against the dev’s signature. If that checks out, which it presumably will, it applies the change implicit in the added metadata to the original .obb
That .obb becomes the artifact which android installs. It isn’t what the dev uploaded.
Google hasn’t stripped the dev’s upload signature, they’ve just added extra payload in a way which doesn’t invalidate the original signature, then added some more payload and a signature of their own.
I’m not saying this is what they are doing, just that this is what they might be doing. You would be able to detect this once you had downloaded the payload and installed it on a device. Could it be made to happen or not according to which device the download was sent to? I expect that wouldn’t be hard. And in that case, you wouldn’t be able to detect it unless you had access to a device which had been targetted for the modification. It would be very difficult to detect the modification process while it was occurring. You could tell the difference between a modified payload and an unmodified payload immediately on receipt at the device because the presence or absence of the metadata “diff” would change the file size.
I don’t know whether bundletool
could support such a scheme. I guess that’s where you could look for clues.
They may just be stripping the dev’s upload signature and replacing it with their own. The only protection against signature stripping comes from checks done by the receiver.
When it comes down to it, you cannot trust any crypto scheme if you might consider the receiving endpoint to be compromised. Whether the payload is encrypted (which in this case it isn’t) or merely signed, if the endpoint is not going to enforce the scheme, the sender and the user are both potentially exposed.
Technically, in this case, the crypto on the endpoint is in the control of the device manufacturer, although it is questionable whether they would actually exercise that control against the will or interests of the OS provider – Google – assuming that manufacturers even check these things.
Problem :
As a follow-up to this question, I am trying to figure out what stops Google from modifying our apps that it signs and distributes. Regardless of whether we distribute an APK or an App Bundle, the App Signing service strips away whatever signature that we have and Google signs the APKs that it distributes. In the case of the App Bundle, this will result in several APKs, akin to what bundletool
generates.
But since an APK is just a ZIP archive with compiled code and resources, it seems as though Google could modify that as they see fit before signing, including adding or replacing code.
we don’t modify and distribute your application code without your knowledge and approval
and:
As stated before, Play will not modify the functionality of your application without your knowledge and approval.
Notably, Google used “don’t” and “will not”… as opposed to “can’t” and “cannot”. In fact, in the same post, we see:
For apps uploaded as app bundles, we will improve this security by introducing what is called a source stamp. This source metadata is inserted into the app’s manifest by
bundletool
.
So, we know of at least one modification, albeit to metadata.
Plus,
the Amazon AppStore for Android modifies APKs before re-signing them:
Regardless of whether you choose to apply Amazon DRM, Amazon wraps your app with code that enables the app to communicate with the Amazon Appstore client to collect analytics, evaluate and enforce program policies, and share aggregated information with you. Your app will always communicate with the Amazon Appstore client when it starts, even if you choose not to apply DRM.
Amazon removes your signature and re-signs your app with an Amazon signature that is unique to you, does not change, and is the same for all apps in your account.
Amazon has been doing this sort of thing for a decade.
It seems as though Google should have the same technical capability as does Amazon.
So, is there anything that I am missing that prevents Google from adding to or modifying the code in APKs that it re-signs and distributes?
Comments
Comment posted by Thomas
I think you’re quite right: by using Google’s App Signing service, you are trusting them not to make any malicious changes. That said, even if you do your own signing you’re already trusting Google, because they also control the Play Store application that (IIUC) is responsible for verifying app signatures before installation.
Comment posted by CommonsWare
@Thomas: “they also control the Play Store application that (IIUC) is responsible for verifying app signatures before installation” — that’s handled by the OS, not the distribution channel client.
Comment posted by Thomas
Fair enough. In a sense, Google also controls the OS though 😉 (Yeah I know it’s OSS and the mobile phone carrier is probably the one compiling the binaries that end up on your phone, so they have the last word, but Google still has a fair amount of power here.)
Comment posted by CommonsWare
@Thomas: “the mobile phone carrier is probably the one compiling the binaries that end up on your phone” — it would be the device manufacturer that does the compiling. For devices built and distributed by a carrier, then the carrier is the manufacturer, but that model is not as common as it once was AFAIK.
Comment posted by CommonsWare
@CaptainKenpachi: For the purposes of this question, I am not really concerned about other attack vectors, just this one.
Comment posted by Lalit Fauzdar
Beautifully written but is it the answer the questioner seeks? Is an answer to the actual question even technically feasible/possible? Even if there’s something to it, why would Google or even Amazon let it sit on public platforms? Isn’t that way we compromise the apps’s security which Google and other stores (try to) implement by their modification? If such a way to prevent google from modifying the apk is available then who will ensure the intentions (if malicious) of a developer? I agree that trust has to begin somewhere but what actually stops Google modifying apps’ code? Values? Morals?
Comment posted by CommonsWare
“I guess the context in which you asked your question was “would Google be able to modify the app before distribution” — well, yeah. I mean, the literal question was: “is there anything that I am missing that prevents Google from adding to or modifying the code in APKs that it re-signs and distributes?”. I’m familiar with the Thompson paper, etc. Your answer starting with the boldface “so what stops Google from modifying it?” is about where my head is — the reason I asked the SO question was to see if there was some technical impediment of which I was unaware. Thanks for the answer!
Comment posted by Rahul Iyer
@CommonsWare I answered that in the second paragraph. But if you feel this answer is off-topic or distracts from your question in some way I can delete it if you like.
Comment posted by Rahul Iyer
@CommonsWare also, with reference to your quote “I guess the context….”, the point I was making is that in future as processing power has increased it may be possible to modify the apk after distribution.
Comment posted by CommonsWare
“it may be possible to modify the apk after distribution” — for the purposes of this question, I am not really concerned about other attack vectors, just this one. “I answered that in the second paragraph” — I suspect that your analysis is correct. However, the question as written was aiming for either “this is the impediment” answers or no answers. Your analysis has an implicit “as far as I am aware” disclaimer, which is the reason I have not up-voted or accepted it, though I expect that you will get the bounty.
Comment posted by CommonsWare
“Because developer can easily detect it” — what % of Android developers do you think do this today? “Easily” implies that there is an existing tool or service to automate this sort of check, and I am not aware of either. Plus, you are assuming that the developer happens to be one that gets a modified app, which is not necessarily the case. “you could wonder if a malicious vendor couldn’t change dex2oat…” — for the purposes of this question, I am not really concerned about other attack vectors, just this one.
Comment posted by Technologeeks
Clarifications thus added.
Comment posted by CommonsWare
“the detection by the developer is as easy as unzipping the APK and comparing its contents to what the developer submitted” — it’s going to be more complicated than that, given app bundles and the resulting N APKs, both for cases where the developer gets the tampered app or where users get a tampered app and somehow send something to the developer. It’s not impossible, but IMHO “easy” is rather optimistic, which is why I expect that virtually no developers actually check for this sort of tampering. Thanks!
Comment posted by Technologeeks
The case I’m making is that with however many variants, it’s still the same *.dex. And those are (in IMMHO) easy to check for tampering. This is because I’ve done it from experience. However, I fully concur with you that most devs won’t bother checking. That said, the argument is that suffice it someone does and indeed can prove tampering, for the backlash on Google to be really, really bad – hence they won’t mess with anything without telling the developers.
Comment posted by CommonsWare
“This is because I’ve done it from experience” — have you ever written anything about the process that you use?
Comment posted by CommonsWare
“are you sure this is what it does?” — considering that the old signature is gone, yes. Not to mention the fact that Google themselves say that this is what they do.
Comment posted by JamesD
@commonsware : I saw in your original post that Amazon is saying in so many words that it is stripping the dev’s signature. I haven’t seen a similarly explicit statement from Google. The evidence posted by delkan is persuasive, but I’m not 100% sure whether his screenshot represents the artefacts as they are stored on Google Play (before download and install on a device) or whether it represents something which was installed from Google Play on a device in the normal course of business. If the former, it is decisive evidence of signature-stripping, if the latter, it is not.
Comment posted by Dellkan
@JamesD the artifacts from the picture in my post represents both: Before and after. With “after” being downloaded from Google Play onto device and installed.
Comment posted by JamesD
Thanks for clarifying. I declare myself convinced.