Analysis of defense strategy of API replay attack

Source: Internet
Author: User


1       Preface1.1    background

front end for mobile APP applications, using https+restful protocol over the Internet with back-end API server cluster for communication, interface authentication based on OAuth2 agreement.

The simple architecture diagram is as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/40/05/wKioL1PN-g2yMOsOAACsRDJCncE280.png "title=" 123456.PNG "alt=" Wkiol1pn-g2ymosoaacsrdjcnce280.png "/>

1.2    Pain Point

Although API the interface transmission uses HTTPS encrypted transmission, but some of the interfaces still exist Replay Attack ( Replay Attack ), a number of different defense replay attack scenarios are analyzed below.

2       based onAPP-Side maintenance ofKeyfor Certification2.1    signing authentication with random numbers

APPMaintain aOAuth2 Serverthe user name/Password,APPevery time you register/before logging on to the interface request, start with theAPI Serverget a requestIDand a random number. ThenAPPusing this random number as the key, theAPPof theOAuth2User name/Password toHmacSHA256hash calculation, and useBase64The code generates a digital signature and then registers the user/login parameters and requestsIDand digital signatures are passed toAPI Server,API ServerAccording to this information to determine whether the request is legitimate.

Pros: No timestamp, no need for user phone and API Server clock synchronization;

Disadvantages: API Server Additional maintenance Required APP Request ID as well as random numbers, and APP require multiple calls to fetch requests ID and the random number of the interface.

2.2    Use digital signatures+time stamp for authentication

APPMaintain aOAuth2 Serverthe user name/Password,APPevery time you register/before logging on to the interface request, use theAPPof theOAuth2The password is for the requestHmacSHA256hash calculation, and useBase64The code generates a digital signature and then registers the user/login parameters, as well as digital signatures, timestamps (used to determine if the request is out of date, are generally set to theminutes expire) are delivered toAPI Server,API ServerAccording to this information to determine whether the request is legitimate.

Advantages: API Server no additional maintenance required APP Request ID and random numbers; APP no need to register / multiple calls to get requests before logging in ID and a random number interface;

Cons: Need to ensure that the user's phone and API Server clock synchronization, and there is still the possibility of a replay attack within the time when the request time has not expired.

2.3    APPProceed firstOAuth2authentication, and then passAccess_token

APPMaintain aOAuth2 Serverthe user name/Password,APPevery time you register/before logging on to the interface request, first call theOAuth2 Serverinterface for authentication and acquisitionAccess_token, and then register the user/login parameters and theAccess_tokendelivered toAPI Server,API ServerConfigure registration/the login interface needs to beOAuth2certification.

Advantages: Simple implementation, only a small change can be achieved;

Disadvantages: APP need to do more than once OAuth2 interface calls; APP of the Access_token there is still a possibility of replay attacks (other uses Access_token The same problem exists with the authentication interface).

3       withoutAPP-End MaintenanceKeythe way to certify3.1    time stamp Mode

" time Stamp "– represents the number of the current moment.

Basic Ideas ──a receives a message when and only if it contains a pair of A is close enough to the timestamp of the current moment.

principle – The replay timestamp will be relatively far away from the current moment.

Clock Requirements – The computer clocks of the communicating parties remain in sync.

processing Mode – set the appropriate size of the time window (interval), the larger the more tolerant network transmission delay, the smaller the more anti-replay attacks.

Applicability – for a non-connectivity conversation. In the case of a connection, if the clock is accidentally out of sync, the correct information may be wrongly discarded as replay information, and the incorrect replay information may be received as the latest information.

3.2    Serial number increment mode

Both sides of the communication use the serial number in the message to determine the freshness of the message.

It is required that both parties negotiate an initial serial number in advance and negotiate an incremental method.

for app Generate a unique encoding that represents the app

Key points: APP the encoding generation algorithm can only be APP and the service side, the serial number is incremented only by the APP and the service-side, you can consider the initial serial number and APP The encoding Association is generated.

3.3    How to answer questions

" At present "– One -time random number associated with the current event N (No Duplicates).

Basic Practice–expect fromBGet the messageAissued in advanceBA currentN, and askBthe message that is answered containsNorf (N),Fis aA,Bpre-agreed simple functions.

principle ──a through B Reply to the N or f (N) to decide whether the message is replayed or not is consistent with the issue itself.

Clock Requirements – None.

Applicability – a dialog for connectivity.


This article is from the "fireworks easy to cool" blog, please be sure to keep this source http://yuanhuan.blog.51cto.com/3367116/1441298

Analysis of defense strategy of API replay attack

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.