Network Working Group E. Hammer-Lahav Internet-Draft Yahoo! Intended status: Standards Track January 9, 2011 Expires: July 13, 2011 OAuth 2.0 MAC Token and Authentication draft-hammer-oauth-v2-mac-token-00 Abstract This document specifies the OAuth 2.0 MAC token type and authentication scheme. Status of this Memo This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet- Drafts is at http://datatracker.ietf.org/drafts/current/. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." This Internet-Draft will expire on July 13, 2011. Copyright Notice Copyright (c) 2011 IETF Trust and the persons identified as the document authors. All rights reserved. This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Hammer-Lahav Expires July 13, 2011 [Page 1] Internet-Draft OAuth 2.0 MAC Token January 2011 Table of Contents 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1. Example . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2. Notational Conventions . . . . . . . . . . . . . . . . . . 5 2. Issuing MAC-Type Access Tokens . . . . . . . . . . . . . . . . 5 3. Making Requests . . . . . . . . . . . . . . . . . . . . . . . 5 3.1. The Authorization Request Header . . . . . . . . . . . . . 6 3.2. Signature . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2.1. Normalized Request String . . . . . . . . . . . . . . 7 3.2.2. hmac-sha-1 . . . . . . . . . . . . . . . . . . . . . . 11 3.2.3. hmac-sha-256 . . . . . . . . . . . . . . . . . . . . . 12 4. Verifying Requests . . . . . . . . . . . . . . . . . . . . . . 12 5. Scheme Extensions . . . . . . . . . . . . . . . . . . . . . . 13 6. Security Considerations . . . . . . . . . . . . . . . . . . . 13 6.1. Secrets Transmission . . . . . . . . . . . . . . . . . . . 13 6.2. Confidentiality of Requests . . . . . . . . . . . . . . . 13 6.3. Spoofing by Counterfeit Servers . . . . . . . . . . . . . 13 6.4. Plaintext Storage of Credentials . . . . . . . . . . . . . 13 6.5. Entropy of Secrets . . . . . . . . . . . . . . . . . . . . 14 6.6. Denial of Service / Resource Exhaustion Attacks . . . . . 14 6.7. Coverage Limitations . . . . . . . . . . . . . . . . . . . 15 7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 15 7.1. The "secret" OAuth Parameter . . . . . . . . . . . . . . . 15 7.2. The "secret" OAuth Parameter . . . . . . . . . . . . . . . 15 8. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 15 Appendix A. Document History . . . . . . . . . . . . . . . . . . 16 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 16 9.1. Normative References . . . . . . . . . . . . . . . . . . . 16 9.2. Informative References . . . . . . . . . . . . . . . . . . 17 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 17 Hammer-Lahav Expires July 13, 2011 [Page 2] Internet-Draft OAuth 2.0 MAC Token January 2011 1. Introduction OAuth 2.0 ([I-D.ietf-oauth-v2]) defines a token-based authentication framework in which third-party applications (clients) access protected resources using access tokens. Access tokens are obtained via the resource owners' authorization from an authorization server. This specification defines the MAC token type for use with the OAuth 2.0 framework. It defines type-specific token attributes and provides a method for making authenticated HTTP requests with partial cryptographic verification of the request - covering the HTTP method, request URI, host, and in some cases the request body. This specification does not define methods for the client to specifically request a MAC-type token from the authorization server. Additionally, it does not include any discovery facilities for identifying which token types are supported by a resource server or how the client may go about obtaining access tokens. This specification assumes that the authorization server has issued the client a MAC-type token and describes how the client authenticates using that access token. The MAC token type is not compatible with the "HMAC-SHA1" signature method defined in OAuth 1.0 [RFC5849]. This specification is an extension of [I-D.ietf-oauth-v2] and uses its terminology. Please discuss this draft on the oauth@ietf.org [1] mailing list. 1.1. Example The client attempts to access a protected resource without authentication, making the following HTTP request to the resource server: GET /resource/1?b=1&a=2 HTTP/1.1 Host: example.com The resource server returns the following authentication challenge: HTTP/1.1 401 Unauthorized WWW-Authenticate: OAuth2 Date: Thu, 02 Dec 2010 21:39:45 GMT Hammer-Lahav Expires July 13, 2011 [Page 3] Internet-Draft OAuth 2.0 MAC Token January 2011 The client has previously obtained a set of token credentials for accessing resources on the "http://example.com/" resource server. The credentials issued to the client by the authorization server included the following attributes: Access token: h480djs93hd8 Token type: mac MAC algorithm: hmac-sha-1 Token secret: 489dks293j39 The client attempts the HTTP request again, this time using the token credentials issued by the authorization server earlier to authenticate. To construct the authentication header, the client calculates the current timestamp and a nonce. The nonce is unique to the timestamp used, typically a random string: Timestamp: 137131200 Nonce: dj83hs9s The client normalizes the request and constructs the signature base string (the new line separator character is represented by "\n" for display purposes only): h480djs93hd8\n 137131200\n dj83hs9s\n GET\n example.com\n 80\n /resource/1\n a=2\n b=1 The signature base string is signed using the specified MAC token algorithm "hmac-sha-1" with the signature base string as text and the token secret as key. The resulting digest is base64-encoded to produce the request signature: IdSrHQHTwCPWGrqzGGIR791ZJXE= Hammer-Lahav Expires July 13, 2011 [Page 4] Internet-Draft OAuth 2.0 MAC Token January 2011 The client includes the access token, timestamp, nonce, and signature with the request using the "Authorization" request header field: GET /resource/1 HTTP/1.1 Host: example.com Authorization: MAC token='h480djs93hd8', timestamp='137131200', nonce='dj83hs9s', signature='IdSrHQHTwCPWGrqzGGIR791ZJXE=' The resource server validates the request by calculating the signature again based on the request received and verifies the validity and scope of the access token. If valid, the resource server responds with the requested protected resource representation. 1.2. Notational Conventions The key words 'MUST', 'MUST NOT', 'REQUIRED', 'SHALL', 'SHALL NOT', 'SHOULD', 'SHOULD NOT', 'RECOMMENDED', 'MAY', and 'OPTIONAL' in this document are to be interpreted as described in [RFC2119]. This document uses the Augmented Backus-Naur Form (ABNF) notation of [I-D.ietf-httpbis-p1-messaging]. 2. Issuing MAC-Type Access Tokens Authorization servers issuing MAC-type access tokens MUST include the following parameters whenever a response includes the "access_token" parameter: secret REQUIRED. The token shared secret used as the MAC algorithm key. algorithm REQUIRED. The MAC algorithm used to calculate the request signature. Value MUST be one of "hmac-sha-1", "hmac-sha-256", or a registered extension algorithm name as described in Section 5. 3. Making Requests To make authenticated requests, the client must be in possession of a valid MAC-type access token, issued by an authorization server Hammer-Lahav Expires July 13, 2011 [Page 5] Internet-Draft OAuth 2.0 MAC Token January 2011 accepted by the resource server. The client constructs the request by calculating of a set of attributes, and adding them to the HTTP request using the Authorization header field (Section 3.1). Authenticated request can be sent in response to an authentication challenge or directly. 3.1. The Authorization Request Header The "Authorization" request header field uses the framework defined by [RFC2617] as follows: credentials = 'MAC' [ RWS 1#param ] param = access-token / timestamp / nonce / signature access-token = 'token' '=' quoted-string timestamp = 'timestamp' '=' <"> 1*DIGIT <"> nonce = 'nonce' '=' quoted-string signature = 'signature' '=' quoted-string The "token" attribute value is set to the access token received from the authorization server. The "timestamp" attribute value is set to the current time expressed in the number of seconds since January 1, 1970 00:00:00 GMT, and MUST be a positive integer. The "nonce" attribute value is set to a random string, uniquely generated by the client to allow the resource server to verify that a request has never been made before and helps prevent replay attacks when requests are made over an insecure channel. The nonce value MUST be unique across all requests with the same timestamp and access token combination. To avoid the need to retain an infinite number of nonce values for future checks, servers MAY choose to restrict the time period after which a request with an old timestamp is rejected. Such a restriction implies a level of synchronization between the client's and server's clocks. The client MAY use the "Date" response header field to synchronize its clock after a failed request. The "signature" attribute value is set as described in Section 3.2. Hammer-Lahav Expires July 13, 2011 [Page 6] Internet-Draft OAuth 2.0 MAC Token January 2011 Each of the four attributes MUST appear once, and only once. 3.2. Signature The client uses the MAC token algorithm and the access token secret - both provided by the authorization server - to calculate the request signature. This specification defines two algorithms: "hmac-sha-1" and "hmac-sha-256", and provides an extension registry for additional algorithms. 3.2.1. Normalized Request String The normalized request string is a consistent, reproducible concatenation of several of the HTTP request elements into a single string. By normalizing the request into a reproducible string, the client and resource server can both sign the same string. The string is constructed by concatenating together, in order, the following HTTP request elements: 1. The access token. 2. A new line character (ASCII code 10). 3. The timestamp value calculated for the request. 4. A new line character (ASCII code 10). 5. The nonce value generated for the request. 6. A new line character (ASCII code 10). 7. The HTTP request method in upper case. For example: "HEAD", "GET", "POST", etc. 8. A new line character (ASCII code 10). 9. The hostname included in the HTTP request using the "Host" request header field in lower case. 10. A new line character (ASCII code 10). 11. The port as included in the HTTP request using the "Host" request header field. If the header field does not include a port, the default value for the scheme MUST be used (e.g. 80 for HTTP and 443 for HTTPS). 12. A new line character (ASCII code 10). Hammer-Lahav Expires July 13, 2011 [Page 7] Internet-Draft OAuth 2.0 MAC Token January 2011 13. The path component of the HTTP request URI as defined by [RFC3986] section 3.3. 14. A new line character (ASCII code 10). 15. The query component of the HTTP request URI as defined by [RFC3986] section 3.4, normalized as described in Section 3.2.1.1. For example, the HTTP request: GET /request?b5=%3D%253D&a3=a&c%40=&a2=r%20b&c2&a3=2+q HTTP/1.1 Host: example.com using access token "kkk9d7dh3k39sjv7", timestamp "137131201", and nonce "7d8f3e4a" is normalized into the following string (the new line Separator character is represented by "\n" for display purposes only): kkk9d7dh3k39sjv7\n 137131201\n 7d8f3e4a\n GET\n example.com\n 80\n /request\n a2=r%20b\n a3=2%20q\n a3=a\n b5=%3D%253D\n c%40=\n c2= 3.2.1.1. Parameters Normalization The query component is parsed into a list of name/value parameter pairs by treating it as an "application/x-www-form-urlencoded" string, separating the names and values and decoding them as defined by [W3C.REC-html401-19991224] section 17.13.4. Once separated and decoded, the parameters are concatenated back together as follows: Hammer-Lahav Expires July 13, 2011 [Page 8] Internet-Draft OAuth 2.0 MAC Token January 2011 1. First, the name and value of each parameter are escaped using the [RFC3986] percent-encoding (%XX) mechanism. Characters in the unreserved character set as defined by [RFC3986] section 2.3 (ALPHA, DIGIT, "-", ".", "_", "~") MUST NOT be encoded. All other characters MUST be encoded. The two hexadecimal characters used to represent encoded characters MUST be upper case. 2. The parameters are sorted by name, using ascending byte value ordering. If two or more parameters share the same name, they are sorted by their value. 3. The name of each parameter is concatenated to its corresponding value using an "=" character (ASCII code 61) as separator, even if the value is empty. 4. The sorted name/value pairs are concatenated together into a single string by using an new line character (ASCII code 10) as separator. Note that the percent-encoding method described is different from the encoding scheme used by the "application/x-www-form-urlencoded" content-type (for example, it encodes space characters as "%20" instead of the "+" character). It MAY be different from the percent- encoding functions provided by web development frameworks (e.g. encode different characters, use lower case hexadecimal characters). For example, the HTTP request URI: /request?b5=%3D%253D&a3=a&c%40=&a2=r%20b&c2&a3=2+q Contains the following (fully decoded) parameters used in the signature base sting: +------+-------+ | Name | Value | +------+-------+ | b5 | =%3D | | a3 | a | | c@ | | | a2 | r b | | c2 | | | a3 | 2 q | +------+-------+ Note that the value of "b5" is "=%3D" and not "==". Both "c@" and "c2" have empty values. While the encoding rules specified in this Hammer-Lahav Expires July 13, 2011 [Page 9] Internet-Draft OAuth 2.0 MAC Token January 2011 specification for the purpose of constructing the signature base string exclude the use of a "+" character (ASCII code 43) to represent an encoded space character (ASCII code 32), this practice is widely used in "application/x-www-form-urlencoded" encoded values, and MUST be properly decoded, as demonstrated by one of the "a3" parameter instances (the "a3" parameter is used twice in this request). The parsed parameters are normalized as follows: Encoded: +------+----------+ | Name | Value | +------+----------+ | b5 | %3D%253D | | a3 | a | | c%40 | | | a2 | r%20b | | c2 | | | a3 | 2%20q | +------+----------+ Sorted: +------+----------+ | Name | Value | +------+----------+ | a2 | r%20b | | a3 | 2%20q | | a3 | a | | b5 | %3D%253D | | c%40 | | | c2 | | +------+----------+ Hammer-Lahav Expires July 13, 2011 [Page 10] Internet-Draft OAuth 2.0 MAC Token January 2011 Concatenated Pairs: +-------------+ | Name=Value | +-------------+ | a2=r%20b | | a3=2%20q | | a3=a | | b5=%3D%253D | | c%40= | | c2= | +-------------+ And concatenated together into a single string (the new line separator character is represented by "\n" for display purposes only): a2=r%20b\n a3=2%20q\n a3=a\n b5=%3D%253D\n c%40=\n c2= 3.2.2. hmac-sha-1 "hmac-sha-1" uses the HMAC-SHA1 algorithm as defined in [RFC2104]: digest = HMAC-SHA1 (key, text) Where: text is set to the value of the normalize request string as described in Section 3.2.1. key is set to the access token shared-secret provided by the authorization server. digest is used to set the value of the "signature" attribute, after the result octet string is base64-encoded per [RFC2045] section 6.8. Hammer-Lahav Expires July 13, 2011 [Page 11] Internet-Draft OAuth 2.0 MAC Token January 2011 3.2.3. hmac-sha-256 "hmac-sha-1" uses the HMAC algorithm as defined in [RFC2104] together with the SHA-256 hash function defined in [NIST FIPS-180-3]: digest = HMAC-SHA256 (key, text) Where: text is set to the value of the normalize request string as described in Section 3.2.1. key is set to the access token shared-secret provided by the authorization server. digest is used to set the value of the "signature" attribute, after the result octet string is base64-encoded per [RFC2045] section 6.8. 4. Verifying Requests A servers receiving an authenticated request validates it by performing the following REQUIRED steps: 1. Recalculate the request signature as described in Section 3.2 and compare it to the value received from the client via the "signature" attribute. 2. Ensure that the combination of nonce, timestamp, and access token received from the client has not been used before in a previous request (the server MAY reject requests with stale timestamps; the determination of staleness is left up to the server to define). 3. Verify the scope and status of the access token. If the request fails verification, the server SHOULD respond with an HTTP 401 (unauthorized) status code, and SHOULD include a token scheme authentication challenge using the WWW-Authenticate header field. The server MAY include further details about why the request was rejected using the error attribute. Hammer-Lahav Expires July 13, 2011 [Page 12] Internet-Draft OAuth 2.0 MAC Token January 2011 5. Scheme Extensions [[ TBD ]] 6. Security Considerations As stated in [RFC2617], the greatest sources of risks are usually found not in the core protocol itself but in policies and procedures surrounding its use. Implementers are strongly encouraged to assess how this protocol addresses their security requirements. 6.1. Secrets Transmission This specification does not describe any mechanism for obtaining or transmitting access token secrets. Methods used to obtain tokens should ensure that these transmissions are protected using transport- layer mechanisms such as TLS or SSL. 6.2. Confidentiality of Requests While this protocol provides a mechanism for verifying the integrity of requests, it provides no guarantee of request confidentiality. Unless further precautions are taken, eavesdroppers will have full access to request content. Servers should carefully consider the kinds of data likely to be sent as part of such requests, and should employ transport-layer security mechanisms to protect sensitive resources. 6.3. Spoofing by Counterfeit Servers This protocol makes no attempt to verify the authenticity of the resource server. A hostile party could take advantage of this by intercepting the client's requests and returning misleading or otherwise incorrect responses. Service providers should consider such attacks when developing services using this protocol, and should require transport-layer security for any requests where the authenticity of the resource server or of request responses is an issue. 6.4. Plaintext Storage of Credentials The access token shared-secret functions the same way passwords do in traditional authentication systems. In order to compute the signature, the server must have access to the secret in plaintext form. This is in contrast, for example, to modern operating systems, which store only a one-way hash of user credentials. Hammer-Lahav Expires July 13, 2011 [Page 13] Internet-Draft OAuth 2.0 MAC Token January 2011 If an attacker were to gain access to these secrets - or worse, to the server's database of all such secrets - he or she would be able to perform any action on behalf of any resource owner. Accordingly, it is critical that servers protect these secrets from unauthorized access. 6.5. Entropy of Secrets Unless a transport-layer security protocol is used, eavesdroppers will have full access to authenticated requests and signatures, and will thus be able to mount offline brute-force attacks to recover the secret used. Authorization servers should be careful to assign shared-secrets which are long enough, and random enough, to resist such attacks for at least the length of time that the shared-secrets are valid. For example, if shared-secrets are valid for two weeks, authorization servers should ensure that it is not possible to mount a brute force attack that recovers the shared-secret in less than two weeks. Of course, authorization servers are urged to err on the side of caution, and use the longest secrets reasonable. It is equally important that the pseudo-random number generator (PRNG) used to generate these secrets be of sufficiently high quality. Many PRNG implementations generate number sequences that may appear to be random, but which nevertheless exhibit patterns or other weaknesses which make cryptanalysis or brute force attacks easier. Implementers should be careful to use cryptographically secure PRNGs to avoid these problems. 6.6. Denial of Service / Resource Exhaustion Attacks This specification includes a number of features which may make resource exhaustion attacks against servers possible. For example, this protocol requires servers to track used nonces. If an attacker is able to use many nonces quickly, the resources required to track them may exhaust available capacity. And again, this protocol can require servers to perform potentially expensive computations in order to verify the signature on incoming requests. An attacker may exploit this to perform a denial of service attack by sending a large number of invalid requests to the server. Resource Exhaustion attacks are by no means specific to this specification. However, implementers should be careful to consider the additional avenues of attack that this protocol exposes, and design their implementations accordingly. For example, entropy starvation typically results in either a complete denial of service while the system waits for new entropy or else in weak (easily Hammer-Lahav Expires July 13, 2011 [Page 14] Internet-Draft OAuth 2.0 MAC Token January 2011 guessable) secrets. When implementing this protocol, servers should consider which of these presents a more serious risk for their application and design accordingly. 6.7. Coverage Limitations The normalized request string has been designed to support the authentication methods defined in this specification. Those designing additional methods, should evaluated the compatibility of the normalized request string with their security requirements. Since the normalized request string does not cover the entire HTTP request, servers should employ additional mechanisms to protect such elements. 7. IANA Considerations 7.1. The "secret" OAuth Parameter Parameter name: secret Parameter usage location: The end-user authorization endpoint response and the token endpoint response. Change controller: IETF Specification document(s): [[ this document ]] Related information: None 7.2. The "secret" OAuth Parameter Parameter name: secret Parameter usage location: The end-user authorization endpoint response and the token endpoint response. Change controller: IETF Specification document(s): [[ this document ]] Related information: None 8. Acknowledgments The author would like to thank [[ some people ]] for their suggestions, feedback, and continued support. Hammer-Lahav Expires July 13, 2011 [Page 15] Internet-Draft OAuth 2.0 MAC Token January 2011 Appendix A. Document History [[ To be removed by the RFC editor before publication as an RFC. ]] -00 o Initial draft. 9. References 9.1. Normative References [I-D.ietf-httpbis-p1-messaging] Fielding, R., Gettys, J., Mogul, J., Nielsen, H., Masinter, L., Leach, P., Berners-Lee, T., and J. Reschke, "HTTP/1.1, part 1: URIs, Connections, and Message Parsing", draft-ietf-httpbis-p1-messaging-08 (work in progress), October 2009. [I-D.ietf-oauth-v2] Hammer-Lahav, E., Recordon, D., and D. Hardt, "The OAuth 2.0 Protocol Framework", draft-ietf-oauth-v2-11 (work in progress), November 2010. [NIST FIPS-180-3] National Institute of Standards and Technology, "Secure Hash Standard (SHS). FIPS PUB 180-3, October 2008". [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies", RFC 2045, November 1996. [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed- Hashing for Message Authentication", RFC 2104, February 1997. [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997. [RFC2617] Franks, J., Hallam-Baker, P., Hostetler, J., Lawrence, S., Leach, P., Luotonen, A., and L. Stewart, "HTTP Authentication: Basic and Digest Access Authentication", RFC 2617, June 1999. [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax", STD 66, RFC 3986, January 2005. Hammer-Lahav Expires July 13, 2011 [Page 16] Internet-Draft OAuth 2.0 MAC Token January 2011 [W3C.REC-html401-19991224] Hors, A., Jacobs, I., and D. Raggett, "HTML 4.01 Specification", World Wide Web Consortium Recommendation REC-html401-19991224, December 1999, . 9.2. Informative References [RFC5849] Hammer-Lahav, E., "The OAuth 1.0 Protocol", RFC 5849, April 2010. URIs [1] Author's Address Eran Hammer-Lahav Yahoo! Email: eran@hueniverse.com URI: http://hueniverse.com Hammer-Lahav Expires July 13, 2011 [Page 17]