1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect2 id="zend.oauth.introduction.security-architecture">
4 <title>Security Architecture</title>
7 OAuth was designed specifically to operate over an insecure HTTP connection and so the use
8 of HTTPS is not required though obviously it would be desireable if available. Should a
9 HTTPS connection be feasible, OAuth offers a signature method implementation called
10 PLAINTEXT which may be utilised. Over a typical unsecured HTTP connection, the use of
11 PLAINTEXT must be avoided and an alternate scheme using. The OAuth specification defines two
12 such signature methods: HMAC-SHA1 and RSA-SHA1. Both are fully supported by
13 <classname>Zend_Oauth</classname>.
17 These signature methods are quite easy to understand. As you can imagine, a PLAINTEXT
18 signature method does nothing that bears mentioning since it relies on HTTPS. If you were to
19 use PLAINTEXT over HTTP, you are left with a significant problem: there's no way to be sure
20 that the content of any OAuth enabled request (which would include the OAuth Access Token)
21 was altered en route. This is because unsecured HTTP requests are always at risk of
22 eavesdropping, Man In The Middle (MITM) attacks, or other risks whereby a request can be
23 retooled so to speak to perform tasks on behalf of the attacker by masquerading as the
24 origin application without being noticed by the service provider.
28 HMAC-SHA1 and RSA-SHA1 alleviate this risk by digitally signing all OAuth requests with the
29 original application's registered Consumer Secret. Assuming only the Consumer and the
30 Provider know what this secret is, a middle-man can alter requests all they wish - but they
31 will not be able to validly sign them and unsigned or invalidly signed requests would be
32 discarded by both parties. Digital signatures therefore offer a guarantee that validly
33 signed requests do come from the expected party and have not been altered en route. This is
34 the core of why OAuth can operate over an unsecure connection.
38 How these digital signatures operate depends on the method used, i.e. HMAC-SHA1, RSA-SHA1 or
39 perhaps another method defined by the service provider. HMAC-SHA1 is a simple mechanism
40 which generates a Message Authentication Code (MAC) using a cryptographic hash function
41 (i.e. SHA1) in combination with a secret key known only to the message sender and receiver
42 (i.e. the OAuth Consumer Secret and the authorized Access Key combined). This hashing
43 mechanism is applied to the parameters and content of any OAuth requests which are
44 concatenated into a "base signature string" as defined by the OAuth specification.
48 RSA-SHA1 operates on similar principles except that the shared secret is, as you would
49 expect, each parties' RSA private key. Both sides would have the other's public key with
50 which to verify digital signatures. This does pose a level of risk compared to HMAC-SHA1
51 since the RSA method does not use the Access Key as part of the shared secret. This means
52 that if the RSA private key of any Consumer is compromised, then all Access Tokens assigned
53 to that Consumer are also. RSA imposes an all or nothing scheme. In general, the majority of
54 service providers offering OAuth authorization have therefore tended to use HMAC-SHA1 by
55 default, and those who offer RSA-SHA1 may offer fallback support to HMAC-SHA1.
59 While digital signatures add to OAuth's security they are still vulnerable to other forms of
60 attack, such as replay attacks which copy earlier requests which were intercepted and
61 validly signed at that time. An attacker can now resend the exact same request to a
62 Provider at will at any time and intercept its results. This poses a significant risk but it
63 is quiet simple to defend against - add a unique string (i.e. a nonce) to all requests which
64 changes per request (thus continually changing the signature string) but which can never be
65 reused because Providers actively track used nonces within the a certain window defined by
66 the timestamp also attached to a request. You might first suspect that once you stop
67 tracking a particular nonce, the replay could work but this ignore the timestamp which can
68 be used to determine a request's age at the time it was validly signed. One can assume that
69 a week old request used in an attempted replay should be summarily discarded!
73 As a final point, this is not an exhaustive look at the security architecture in OAuth. For
74 example, what if HTTP requests which contain both the Access Token and the Consumer Secret
75 are eavesdropped? The system relies on at one in the clear transmission of each unless HTTPS
76 is active, so the obvious conclusion is that where feasible HTTPS is to be preferred leaving
77 unsecured HTTP in place only where it is not possible or affordable to do so.