1. Why sign
If i could only answer this question in a simple phrase, i would say, “this is what the android system requires”。
Application signature is a process whereby a given application is signed using a private key number for three purposes:
Identify the author of the code
Check if the application has changed
Building trust between applications
Based on this trust relationship, applications can safely share codes and data. If a permission is protected at the level of protection, only applications with the same digital certificate as the permission's program can obtain that permission. Android uses the mechanism associated with java's digital certificates to add digital certificates to apk. To understand the digital certificates ofandroid, it is necessary to understand the following concepts of digital certificates and the java digital certification mechanism. Android requires that each application installed in the system be signed with a digital certificate, the private key of which is kept in the program's developer's hands. Which means if an android application is not digitally signed, there's no way to install it in the system! Android identified the author of the application through digital signatures and built a trust relationship between the application, not to determine which applications the end-user could install. This number of signatures is done by the author of the application and does not require an authoritative digital certificate signing authority to authenticate, but only for the application package。
Of particular note is the fact that, unlike other uses of digital certificates in the area of information security, android uses digital certificates to identify the author of the application and to build trust between the application, rather than to determine which applications the end-user can install. This number does not require an authoritative digital certificate signature authority to authenticate it, but only to enable the application package to authenticate itself. In other words, the certificate is entirely controlled and used by the developers。
Developers can generate different certificates, and we suggest that multiple processes with the same developers use the same digital certificate as far as possible, which can bring the following benefits:
Facilitates process upgrades when digital certificates for new and old versions when the same happens, the android system will consider the two applications to be different versions of the same program. If the new version and the old version of the digital certificate are different, the android system considers them different and conflicts and will require the new version to change the name of the package。
Modularization design and development of the program is facilitated. The android system allows the program with the same digital signature to run in a process, and the android program considers them to be the same program. So the developers can develop their own sub-modules, and the users only need to download the appropriate modules when they need them。
Data and codes can be shared among multiple programs by access. Android provided a power-given mechanism based on digital certificates, which applications could share with other programs, or give data to those who own the same digital certificates. If the level of protection for a given authority (permission) is signature, this competence can only be granted to those who have the same digital certificate as the package where the authority is located。
2. Signing-related issues
When signing, the validity period of a digital certificate is considered:
The validity period of a digital certificate shall include the expected life cycle of the procedure, and once the digital certificate has expired, the procedure for holding the digital certificate will not be properly upgraded。
If multiple programs use the same digital certificate, the validity period of the digital certificate must include the expected life cycle of all programs。
Android market made it mandatory that all application digital certificates remain valid beyond 22 october 2033。
In addition, the android digital certificate contains the following elements:
All applications must have a digital certificate and the android system will not install an application without a digital certificate。
The digital certificate used in the android package may be self-signed and does not require the signature of an authoritative digital certificate body。
If an android is to be officially published, a digital certificate generated by a suitable private key must be used to sign the application, instead of a debugging certificate generated by an adt plugin or ant tool。
Digital certificates are valid, and android only checks the validity of certificates when the application is installed. If the program is installed in the system, even if the certificate expires, it will not affect the normal functioning of the program。
Android uses the standard java tool keytool and jarsigner to generate digital certificates and sign application packages
3. Two models
Debugging and publishing mode can be used to construct android applications:
(1) an application constructed using the android build tool (command line and eclipse adt) is automatically signed with a debugging private key; these applications are called debugging mode applications. Debug mode applications are used for testing and cannot be published. Note that applications that are not signed or that use debugging private key signatures cannot be published through android market. In debugging mode, android's development tool will be signed with a pilot digital certificate at each compiler without the developer's concern。
(2) when preparing to publish its own application, a version of the distribution mode must be constructed, which means signing the application with a private key. When the program is to be published, the developers will need to sign the apk package using their own digital certificates, which can be done in two ways。
Under the command line, both jdk and keytool (for generating digital certificates) and jarsigner (for signing digital certificates) are used to sign apk packages。










