Android Digital Signature

Source: Internet
Author: User

In an Android system, all applications installed to the system must have a digital certificate that identifies the author of the application and establishes a trust relationship between the applications, if a permission ProtectionLevel is signature, Then only applications that have the same digital certificate as the program where the permission resides can get that permission. Android uses a Java digital certificate-related mechanism to give the APK a digital certificate, to understand the digital certificate of Android, you need to first understand the following digital certificate concepts and Java digital certificate mechanism. The Android system requires that every application installed into the system is signed with a digital certificate, and the private key of the digital certificate is stored in the programmer's hands. Android uses digital certificates to identify the author of an application and to establish a trust relationship between applications, not to determine which applications the end user can install. This digital certificate does not require an authoritative digital certificate signing Authority authentication, it is only used to make the application package self-certified.

1, multiple programs of the same developer use the same digital certificate as much as possible, this can bring the following benefits.
    • In favor of the program upgrade, when the new version of the program and the old program's digital certificate, the Android system will think that the two programs are different versions of the same program. If the new program and the old version of the digital certificate is not the same, then the Android system think they are different programs, and create a conflict, will require the newly-created program to change the package name.
    • facilitates the modular design and development of the program. Android allows programs with the same digital signature to run in one process, and the Android program treats them as the same program. So developers can develop their own programs into modules, and users only need to download the appropriate modules when needed.
    • You can share data and code among multiple programs through permissions (permission). Android provides a digital certificate-based permission-granting mechanism that allows applications to share overviews or data with other programs to those that have the same digital credentials as themselves. If the ProtectionLevel of a permission (permission) is signature, this permission can only be granted to programs that have the same digital certificate as the package in which the permission resides.
2, when signing, you need to consider the number Validity period of the certificate
    • The validity period of a digital certificate is to include the program's expected life cycle, and once the digital certificate expires, the program that holds the digital certificate will not upgrade properly.
    • If multiple programs use the same digital certificate, the validity period of the digital certificate includes the expected life cycle of all programs.
    • Android market enforces that all application digital certificates remain valid until October 22, 2033.
3. The Android digital certificate contains the following points:
    • all applications must have a digital certificate and the Android system will not install an application without a digital certificate
    • The digital certificate used by the Android package can be self-signed and does not require an authoritative digital certificate Authority signature Authentication
    • If you want to formally publish an Android, you must sign the program with a digital certificate generated by a suitable private key , rather than using the ADT plugin or the debug certificate generated by the Ant tool to publish.
    • Digital certificates are valid , and Android only checks the validity of the certificate when the application is installed. If the program is already installed on the system, it does not affect the normal functionality of the program, even if the certificate expires.
    • Android uses standard Java tools Keytool and Jarsigner to generate digital certificates and to sign application packages.
    • Use the zipalign Optimizer.
4. Signature mode

Android does not install an APK program that runs without a digital signature, either on the emulator or on the actual physical device. Android's development tools (ADT plugin and ANT) can help developers sign the APK program in two modes: Debug mode and Release mode.

In debug mode, Android's development tools use a debug digital certificate to sign the program each time they compile, and developers don't need to worry about it.

When you want to publish a program, developers need to use their own digital certificate to sign the APK package, there are two ways to do it.

    1. Sign the APK package using the and Keytool in the JDK (for generating digital certificates) and Jarsigner (for signing with a digital certificate) at the command line.
    2. Use the ADT Export Wizard to sign (if you do not have a digital certificate you may need to generate a digital certificate).
5. Optimize APK 5.1 using Zipalign to optimize APK

According to the official documentation, the application data in the Android system is stored in its apk file and can be accessed by multiple processes, including the following steps:

    • Installer Get permissions information associated with the current application through each APK's manifest file
    • Home application Read the current APK name and icon information.
    • System server will read some information related to application operations, such as obtaining and processing application notifications requests.
    • Finally, the APK contains content that is not limited to the current application and can be called by other application to improve the reusability of the system resources.

The most fundamental purpose of zipalign optimization is to help the operating system more efficiently according to the request index resources, will resource-handling code unified data Structure alignment (data structure alignment standard: DSA) limited to 4-byte Boundaries. Without the alignment criteria, the processor cannot accurately and quickly locate related resources in the memory address. The current system uses the fallback mechanism mechanism to handle applications that do not have the DSA standard, which makes it much easier for ordinary developers to focus on cumbersome memory operations. But on the contrary, for such an application will give ordinary users a certain amount of trouble, not only affect the efficiency of the operation of the program, but also the overall performance of the system to reduce the efficiency and consumption of unnecessary memory resources, and even consume a certain amount of battery resources (battery life).

5.2 Manual optimization by command line mode
    • Use the Zipalign tool under the Tools folder. First bring up the cmd command line, then execute:zipalign-v 4 source.apk androidres.apk. This method is not limited by the API level and can perform align optimizations on any version of the APK.
    • You can also use the Zipalign tool to check if the current apk has performed align optimizations. Command:zipalign-c-V 4 androidres.apk
5.3 Automatic optimization using ADT:
    • Starting with the ADT 0.9.3 release, you can automatically perform align operations on the published application packages through the Export Wizard. Setup method: Right-click Project and select "Android Tools" > "Export signed Applicationpackage ...".  
6, cover the installation

If your previous program is using the default signature (debug signature), once the new signature application will not overwrite the installation, the original program must be uninstalled before it can be installed.

Because the program covers the installation main check two points:

    1. The entry activity for both programs is the same. Two programs if the package name is not the same, even if all the other code is exactly the same, it will not be considered a different version of the same program;
    2. Whether the signatures used by the two programs are the same. If the signatures of the two programs are different, even if the package name is the same, it will not be treated as a different version of the same program and cannot overwrite the installation.
7. Debug signed Application

In addition, someone may think that the debug signature application can be installed anyway, there is no need to sign their own. Don't think so, debug signed applications have such two limitations, or risk:

    1. Debug signed applications cannot be sold on Android Market, it will force you to use your own signature, and the certificate used in debug mode (default is Eclipse/adt and ant compilation) will expire 1 years from the date it was created.
    2. Debug.keystore on different machines may not be the same, which means that if you change the machine for APK version upgrade, then the above program will not cover the installation of the problem. Do not belittle this problem, if you develop the program only you use, of course, no matter, uninstall and install it. But if your software has a lot of customer use, this is a big problem, the equivalent of software does not have upgrade features!
8. Summary

In summary, you can use Keytool, Jarsigner, zipalign to sign the program and optimize the program, which requires three different tools:

    1. Keytool-genkey-v-keystore android.keystore-alias android-keyalg rsa-validity 20000
    2. Jarsigner-verbose-keystore Android.keystore-signedjar android123_signed.apk android123.apk Android
    3. Zipalign-v 4 android123_signed.apk android123_signed_aligned.apk

Of course, you can also use the ADT plugin in the export signed application package ... To execute, the graphical interface is more simple, image, and intuitive.

Http://www.cnblogs.com/maxinliang/p/3169335.html

Android Digital Signature

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.