IPhone push (push notification) Function Principle Analysis

Source: Internet
Author: User

Part 1: Push Principle
(The vast majority of the content below is from the iPhone OS reference library)
Mechanism Overview
The working mechanism of push can be summarized
In the figure,
Provider refers to the push server of an iPhone software.
Apns is the abbreviation of Apple push notification service (Apple push server. 
As a result, the entire process can be divided into three stages. Below we will describe the common chat client beejiveim. (Beejiveim is an iPhone chat client that supports multiple account logon and supports push, such as MSN and Google Talk)
The provider is the beejiveim server,We log on to MSN on beejiveim. In fact, the software first sends the login information to the beejiveim server, and then logs on to MSN through its server.. Therefore, when I close beejiveim, The beejiveim server will continue to log on to MSN for me. If someone sends a message to my MSN account, the push will be triggered. At this point:
Stage 1: The beejiveim server packs the message to be sent and the ID of the target iPhone and sends it to apns.
Stage 2: apns searches for the iPhone with the corresponding identifier in its registered PUSH Service iPhone list and sends the message to the iPhone.
Stage 3: The iPhone transmits the sent message to the corresponding application, and a push notification is displayed according to the settings.
Push Authentication
Many friends say that push cannot be used. Most of them are problems in the authentication phase. Want to know why? Please refer to the following details:
The authentication mechanism mentioned here actually contains two layers. Layer 1 isPhysical connection AuthenticationThe other layer involvesAuthentication of the iPhone device token.
Authentication on physical connections: SSL/TLS links
(If you know TLS, I hardly need to introduce it here .)
When push is enabled, the iPhone connects to apns to establish a TLS encrypted link. Each normal iPhone has a unique device certificate, and apns also has a server certificate. When the two are established, they will verify the validity of each other's certificates.
Once a TLS link is established and there is no data, you only need to perform a live handshake every 15 minutes, so there is almost no traffic.Once the link is interrupted due to unexpected reasons, the iPhone will try again to establish a TLS link until the connection is successful.
Higher level: Token-based authentication
In the mechanism introduction, I mentionedApns determines the iPhone to which push messages are sentIs a "target iPhone ID", which isDevice token).
How is a device token generated? It is the unique device certificate (unique device Certificate) of each normal iPhone that we mentioned in the previous layer (TLS layer) of apns each time a TLS connection is established ), encrypted with the token key.

After the token is generated, apns returns the device token to the iPhone, and the corresponding push ApplicationProgram(Such as beejiveim), the device token returned is directly sent to the provider (such as beejiveim server ). In this way,When the provider has a push message to send, it will send the device token of the corresponding account to apns together with the message, and apns then sends the device token according to the device token ), find the iPhone with the corresponding TLS link and send the corresponding push message.
The above complex process can be summarized into the following figure:

In the figure, the client app is a push application on the iPhone. (In the figure, a link from provider to apns is missing (when a push message exists)
The most important part is the unique device certificate and key of each iPhone.
After a normal iPhone has been flushed to the system, there is no device certificate or key. That's why the iPhone needs to be connected to iTunes for activation --During the activation process, Apple assigns a unique device certificate and key to each iPhone).
The above section only describes how to establish a connection from iPhone to apns. In fact, there is also a TLS link from provider to apns, but it has little to do with this article, so I will not discuss it more.
Where is the push problem?
I believe many of you have such questions.
As mentioned above, iPhone push requires apns to generate a device token for the corresponding iPhone, but generating this token requires a valid device certificate (device Certificate) on the iPhone) and key,:
Use blacksn0w for iPhone OS 3.xUnlockThe process does not go through iTunes,Blacksn0w itself does not generate the corresponding device certificate and key)Therefore, it is impossible for the unlocked iPhone to establish any TLS connection with apns, and the push is useless.
Various pushfix Patches
The only way to fix this problem isRegenerate the unique and valid device certificate and key).
But you need to know that the certificate is issued by the organization. A certificate that you just get will only be considered invalid by apns. (You can check the cost of an SSL certificate)
In addition, the corresponding file seems to be related to some content of the iPhone, not directly prepared files can be put in.
As a result, the dev team launched a beta version patch and pushed fix by dev team (published on Twitter, so there is no message on the official website ). This patch is effective at the initial stage. However, it is normal only on the iPhone 2G.
Then someone released pushfix 1.0. Different generation methods are used, so the new iPhone version works normally. So popular.
However, both patches have serious risks-they use a fixed certificate as a device certificate ). Therefore, the difference between different iPhones is that the generated keys are different.(To be confirmed)
As mentioned above, apns uses device certificate and key to generate a unique device token to identify each iPhone.
However, when the device certificates (device Certificate) of multiple iPhones are identical, there is a certain probability that multiple iPhones will receive the same device token)
As the number of users of these two patches increases, the number of iPhones with the same device token increases significantly.
When the push of the same application is enabled on these iPhone devices with the same device token, it is very likely that the push strings are sent to each other. -For example, N people in a forum complain that QQ is pushed to another iPhone.
Then, the author of pushfix claimed that he couldManually create a unique device certificate and key)And started to provide paid services, and finally launched the paid pushfix 2.0-the principle of its installation through cydia is, during installation, connect to the pushfix site online to check whether the IMEI of the corresponding iPhone is charged and then automatically download the corresponding certificate.
Although I don't know how he made these certificates. However, according to Xiao's verification, the certificate he created is indeed valid. The push problem is fixed.
After that, a patch called pushfix_d appeared on a forum, claiming that the problem can be fixed directly without payment. However,
-- Considering some situations, I decided to publish the pushfix_d judgment in English. Of course, the producer must be clear about the following :)
The same released Push keys from back in July 2009. everybody gets the same key, so it is going to have all the same problems of all the free push fixes. push isn' t going to work very long and it is going to drain your battery.
Other errors
Why can't I push my iPhone under cmwap ?!
Yes, this is completely normal. Within the WAP network, TLS connections cannot be successfully established.
Why can't I push my iPhone under Wi-Fi ?!
In fact, the iPhone is not compatible with some wireless routers. If the wireless router is enabledDNS forwardingIt is very likely that your iPhone cannot establish a TLS connection with the apns server.
Solution:
Disable the DNS forwarding function of the wireless router and manually set the DNS to 8.8.8.8 for the iPhone's wi-fi connection.
In fact, this is why the iPhone is hot and consumes a lot of power when it is connected to wi-fi and cannot receive a push. Because the iPhone willConstantly try to establish TLS links.
How do I know if my push is successfully cracked?
A simple method is to install twitbird pro. On its accounts page, the push registration status of the current software is displayed.
Or you can use software such as winscp to view
/Var/mobile/library/preferences/COM. Apple. APSD. plist
File status.
If the size is 119 bytes, it indicates that the iPhone has successfully obtained the device token and saved it in the file.
If it is smaller than the size, it indicates that the iPhone has been connected to apns, but the device token is not obtained ).
If this file does not exist, it indicates that the iPhone has not been successfully connected to apns.
Other noteworthy issues
The push mechanism of iPod Touch is different from that of iPhone. You can check the push mechanism once every 15 minutes after the screen is locked. Therefore, do not use the check mark above.
When apns sends a push message, if the corresponding iPhone link is interrupted, the push message will be sent several minutes later. After more than one time, the push message will be deleted. Therefore, pay attention to whether your network conditions affect normal push operations.
As mentioned above, device tokens for each iPhone are stored in the/var/mobile/library/preferences/COM. Apple. APSD. plist file. This is why we recommend that you delete the push program and delete the file every time you reinstall the push patch.
If you use the edge switch of sbsettings to disable edge, but do not disable push, the iPhone will constantly try to establish a TLS connection and eventually consume power. Therefore, if you do not plan or cannot use push, disable the push option.
For the push server (provider) of the software, Wi-Fi is the same as the mobile network, and there will be no difference in Push processing.
Although it has been explained clearly, it is still clear that as long as the TLS connection is normal, the PUSH Service is real-time and the speed is only dependent on the provider.
In other words, the directmail technology on the iPhone is completely different from the push technology described in this article. Please refer to the exchange direct push related content.
Benefits
In a word, if you think push is useless, it only means that you have little knowledge. On the following page, you can view some excellent push-supported software.
Http://appadvice.com/applists/show/definitive-list-of-push-capable-apps
Reference: iPhone OS Reference Library
From: http://xiaolife.com/wordpress/an-introduce-to-iphone-push/


Part 1: Push Principle
(The vast majority of the content below is from the iPhone OS reference library)
Mechanism Overview
The working mechanism of push can be summarized
In the figure,
Provider refers to the push server of an iPhone software.
Apns is the abbreviation of Apple push notification service (Apple push server. 
As a result, the entire process can be divided into three stages. Below we will describe the common chat client beejiveim. (Beejiveim is an iPhone chat client that supports multiple account logon and supports push, such as MSN and Google Talk)
The provider is the beejiveim server, We log on to MSN on beejiveim. In fact, the software first sends the login information to the beejiveim server, and then logs on to MSN through its server.. Therefore, when I close beejiveim, The beejiveim server will continue to log on to MSN for me. If someone sends a message to my MSN account, the push will be triggered. At this point:
Stage 1: The beejiveim server packs the message to be sent and the ID of the target iPhone and sends it to apns.
Stage 2: apns searches for the iPhone with the corresponding identifier in its registered PUSH Service iPhone list and sends the message to the iPhone.
Stage 3: The iPhone transmits the sent message to the corresponding application, and a push notification is displayed according to the settings.
Push Authentication
Many friends say that push cannot be used. Most of them are problems in the authentication phase. Want to know why? Please refer to the following details:
The authentication mechanism mentioned here actually contains two layers. Layer 1 is Physical connection AuthenticationThe other layer involves Authentication of the iPhone device token.
Authentication on physical connections: SSL/TLS links
(If you know TLS, I hardly need to introduce it here .)
When push is enabled, the iPhone connects to apns to establish a TLS encrypted link. Each normal iPhone has a unique device certificate, and apns also has a server certificate. When the two are established, they will verify the validity of each other's certificates.
Once a TLS link is established and there is no data, you only need to perform a live handshake every 15 minutes, so there is almost no traffic.Once the link is interrupted due to unexpected reasons, the iPhone will try again to establish a TLS link until the connection is successful.
Higher level: Token-based authentication
In the mechanism introduction, I mentioned Apns determines the iPhone to which push messages are sentIs a "target iPhone ID", which is Device token).
How is a device token generated? It is the unique device certificate (unique device Certificate) of each normal iPhone that we mentioned in the previous layer (TLS layer) of apns each time a TLS connection is established ), encrypted with the token key.

After the token is generated, apns returns the device token to the iPhone, and the corresponding push application (such as beejiveim ), the device token returned is directly sent to the provider (such as beejiveim server ). In this way,When the provider has a push message to send, it will send the device token of the corresponding account to apns together with the message, and apns then sends the device token according to the device token ), find the iPhone with the corresponding TLS link and send the corresponding push message.
The above complex process can be summarized into the following figure:

In the figure, the client app is a push application on the iPhone. (In the figure, a link from provider to apns is missing (when a push message exists)
The most important part is the unique device certificate and key of each iPhone.
After a normal iPhone has been flushed to the system, there is no device certificate or key. That's why the iPhone needs to be connected to iTunes for activation --During the activation process, Apple assigns a unique device certificate and key to each iPhone).
The above section only describes how to establish a connection from iPhone to apns. In fact, there is also a TLS link from provider to apns, but it has little to do with this article, so I will not discuss it more.
Where is the push problem?
I believe many of you have such questions.
As mentioned above, iPhone push requires apns to generate a device token for the corresponding iPhone, but generating this token requires a valid device certificate (device Certificate) on the iPhone) and key,:
Use blacksn0w for iPhone OS 3.xUnlockThe process does not go through iTunes,Blacksn0w itself does not generate the corresponding device certificate and key)Therefore, it is impossible for the unlocked iPhone to establish any TLS connection with apns, and the push is useless.
Various pushfix Patches
The only way to fix this problem isRegenerate the unique and valid device certificate and key).
But you need to know that the certificate is issued by the organization. A certificate that you just get will only be considered invalid by apns. (You can check the cost of an SSL certificate)
In addition, the corresponding file seems to be related to some content of the iPhone, not directly prepared files can be put in.
As a result, the dev team launched a beta version patch and pushed fix by dev team (published on Twitter, so there is no message on the official website ). This patch is effective at the initial stage. However, it is normal only on the iPhone 2G.
Then someone released pushfix 1.0. Different generation methods are used, so the new iPhone version works normally. So popular.
However, both patches have serious risks-they use a fixed certificate as a device certificate ). Therefore, the difference between different iPhones is that the generated keys are different.(To be confirmed)
As mentioned above, apns uses device certificate and key to generate a unique device token to identify each iPhone.
However, when the device certificates (device Certificate) of multiple iPhones are identical, there is a certain probability that multiple iPhones will receive the same device token)
As the number of users of these two patches increases, the number of iPhones with the same device token increases significantly.
When the push of the same application is enabled on these iPhone devices with the same device token, it is very likely that the push strings are sent to each other. -For example, N people in a forum complain that QQ is pushed to another iPhone.
Then, the author of pushfix claimed that he couldManually create a unique device certificate and key)And started to provide paid services, and finally launched the paid pushfix 2.0-the principle of its installation through cydia is, during installation, connect to the pushfix site online to check whether the IMEI of the corresponding iPhone is charged and then automatically download the corresponding certificate.
Although I don't know how he made these certificates. However, according to Xiao's verification, the certificate he created is indeed valid. The push problem is fixed.
After that, a patch called pushfix_d appeared on a forum, claiming that the problem can be fixed directly without payment. However,
-- Considering some situations, I decided to publish the pushfix_d judgment in English. Of course, the producer must be clear about the following :)
The same released Push keys from back in July 2009. everybody gets the same key, so it is going to have all the same problems of all the free push fixes. push isn' t going to work very long and it is going to drain your battery.
Other errors
Why can't I push my iPhone under cmwap ?!
Yes, this is completely normal. Within the WAP network, TLS connections cannot be successfully established.
Why can't I push my iPhone under Wi-Fi ?!
In fact, the iPhone is not compatible with some wireless routers. If the wireless router is enabledDNS forwardingIt is very likely that your iPhone cannot establish a TLS connection with the apns server.
Solution:
Disable the DNS forwarding function of the wireless router and manually set the DNS to 8.8.8.8 for the iPhone's wi-fi connection.
In fact, this is why the iPhone is hot and consumes a lot of power when it is connected to wi-fi and cannot receive a push. Because the iPhone willConstantly try to establish TLS links.
How do I know if my push is successfully cracked?
A simple method is to install twitbird pro. On its accounts page, the push registration status of the current software is displayed.
Or you can use software such as winscp to view
/Var/mobile/library/preferences/COM. Apple. APSD. plist
File status.
If the size is 119 bytes, it indicates that the iPhone has successfully obtained the device token and saved it in the file.
If it is smaller than the size, it indicates that the iPhone has been connected to apns, but the device token is not obtained ).
If this file does not exist, it indicates that the iPhone has not been successfully connected to apns.
Other noteworthy issues
The push mechanism of iPod Touch is different from that of iPhone. You can check the push mechanism once every 15 minutes after the screen is locked. Therefore, do not use the check mark above.
When apns sends a push message, if the corresponding iPhone link is interrupted, the push message will be sent several minutes later. After more than one time, the push message will be deleted. Therefore, pay attention to whether your network conditions affect normal push operations.
As mentioned above, device tokens for each iPhone are stored in the/var/mobile/library/preferences/COM. Apple. APSD. plist file. This is why we recommend that you delete the push program and delete the file every time you reinstall the push patch.
If you use the edge switch of sbsettings to disable edge, but do not disable push, the iPhone will constantly try to establish a TLS connection and eventually consume power. Therefore, if you do not plan or cannot use push, disable the push option.
For the push server (provider) of the software, Wi-Fi is the same as the mobile network, and there will be no difference in Push processing.
Although it has been explained clearly, it is still clear that as long as the TLS connection is normal, the PUSH Service is real-time and the speed is only dependent on the provider.
In other words, the directmail technology on the iPhone is completely different from the push technology described in this article. Please refer to the exchange direct push related content.
Benefits
In a word, if you think push is useless, it only means that you have little knowledge. On the following page, you can view some excellent push-supported software.
Http://appadvice.com/applists/show/definitive-list-of-push-capable-apps
Reference: iPhone OS Reference Library
From: http://xiaolife.com/wordpress/an-introduce-to-iphone-push/

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.