| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "google_apis/gaia/oauth_request_signer.h" | 5 #include "google_apis/gaia/oauth_request_signer.h" |
| 6 | 6 |
| 7 #include <cctype> | 7 #include <cctype> |
| 8 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <cstdlib> | 9 #include <cstdlib> |
| 10 #include <cstring> | 10 #include <cstring> |
| 11 #include <ctime> | 11 #include <ctime> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/base64.h" | 15 #include "base/base64.h" |
| 16 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "crypto/hmac.h" | 22 #include "crypto/hmac.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 static const int kHexBase = 16; | 27 const int kHexBase = 16; |
| 28 static char kHexDigits[] = "0123456789ABCDEF"; | 28 char kHexDigits[] = "0123456789ABCDEF"; |
| 29 static const size_t kHmacDigestLength = 20; | 29 const size_t kHmacDigestLength = 20; |
| 30 static const int kMaxNonceLength = 30; | 30 const int kMaxNonceLength = 30; |
| 31 static const int kMinNonceLength = 15; | 31 const int kMinNonceLength = 15; |
| 32 | 32 |
| 33 static const char kOAuthConsumerKeyLabel[] = "oauth_consumer_key"; | 33 const char kOAuthConsumerKeyLabel[] = "oauth_consumer_key"; |
| 34 static const char kOAuthConsumerSecretLabel[] = "oauth_consumer_secret"; | 34 const char kOAuthNonceCharacters[] = |
| 35 static const char kOAuthNonceCharacters[] = | |
| 36 "abcdefghijklmnopqrstuvwyz" | 35 "abcdefghijklmnopqrstuvwyz" |
| 37 "ABCDEFGHIJKLMNOPQRSTUVWYZ" | 36 "ABCDEFGHIJKLMNOPQRSTUVWYZ" |
| 38 "0123456789_"; | 37 "0123456789_"; |
| 39 static const char kOAuthNonceLabel[] = "oauth_nonce"; | 38 const char kOAuthNonceLabel[] = "oauth_nonce"; |
| 40 static const char kOAuthSignatureLabel[] = "oauth_signature"; | 39 const char kOAuthSignatureLabel[] = "oauth_signature"; |
| 41 static const char kOAuthSignatureMethodLabel[] = "oauth_signature_method"; | 40 const char kOAuthSignatureMethodLabel[] = "oauth_signature_method"; |
| 42 static const char kOAuthTimestampLabel[] = "oauth_timestamp"; | 41 const char kOAuthTimestampLabel[] = "oauth_timestamp"; |
| 43 static const char kOAuthTokenLabel[] = "oauth_token"; | 42 const char kOAuthTokenLabel[] = "oauth_token"; |
| 44 static const char kOAuthTokenSecretLabel[] = "oauth_token_secret"; | 43 const char kOAuthVersion[] = "1.0"; |
| 45 static const char kOAuthVersion[] = "1.0"; | 44 const char kOAuthVersionLabel[] = "oauth_version"; |
| 46 static const char kOAuthVersionLabel[] = "oauth_version"; | |
| 47 | 45 |
| 48 enum ParseQueryState { | 46 enum ParseQueryState { |
| 49 START_STATE, | 47 START_STATE, |
| 50 KEYWORD_STATE, | 48 KEYWORD_STATE, |
| 51 VALUE_STATE, | 49 VALUE_STATE, |
| 52 }; | 50 }; |
| 53 | 51 |
| 54 const std::string HttpMethodName(OAuthRequestSigner::HttpMethod method) { | 52 const std::string HttpMethodName(OAuthRequestSigner::HttpMethod method) { |
| 55 switch (method) { | 53 switch (method) { |
| 56 case OAuthRequestSigner::GET_METHOD: | 54 case OAuthRequestSigner::GET_METHOD: |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 signed_text += | 448 signed_text += |
| 451 base::StringPrintf( | 449 base::StringPrintf( |
| 452 "%s=\"%s\"", | 450 "%s=\"%s\"", |
| 453 OAuthRequestSigner::Encode(param->first).c_str(), | 451 OAuthRequestSigner::Encode(param->first).c_str(), |
| 454 OAuthRequestSigner::Encode(param->second).c_str()); | 452 OAuthRequestSigner::Encode(param->second).c_str()); |
| 455 } | 453 } |
| 456 *signed_text_return = signed_text; | 454 *signed_text_return = signed_text; |
| 457 } | 455 } |
| 458 return is_signed; | 456 return is_signed; |
| 459 } | 457 } |
| OLD | NEW |