OLD | NEW |
| (Empty) |
1 // Copyright 2008-2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 | |
17 #ifndef OMAHA_NET_PROXY_AUTH_H__ | |
18 #define OMAHA_NET_PROXY_AUTH_H__ | |
19 | |
20 #include <windows.h> | |
21 #include <tchar.h> | |
22 #include <atlsimpcoll.h> | |
23 #include <atlstr.h> | |
24 #include <vector> | |
25 #include "omaha/base/synchronized.h" | |
26 #include "omaha/common/goopdate_utils.h" | |
27 | |
28 #define UNKNOWN_AUTH_SCHEME 0x0000FFFF | |
29 const TCHAR* const kDefaultProxyServer = _T("<Default Proxy>"); | |
30 const uint32 kDefaultCancelPromptThreshold = 1; | |
31 | |
32 namespace omaha { | |
33 | |
34 struct ProxyAuthConfig { | |
35 ProxyAuthConfig(HWND hwnd, const CString& caption) | |
36 : parent_hwnd(hwnd), prompt_caption(caption) {} | |
37 | |
38 CString ToString() const { | |
39 CString result; | |
40 result.Format(_T("[ProxyAuthConfig][0x%x][%s]"), | |
41 parent_hwnd, prompt_caption); | |
42 return result; | |
43 } | |
44 | |
45 HWND parent_hwnd; | |
46 CString prompt_caption; | |
47 }; | |
48 | |
49 // A class that reads and stores the Internet Explorer saved proxy | |
50 // authentication info. Works with versions of IE up to and including 7. | |
51 class ProxyAuth { | |
52 public: | |
53 ProxyAuth() : prompt_cancelled_(0), | |
54 proxy_prompt_is_machine_( | |
55 goopdate_utils::IsRunningFromOfficialGoopdateDir(true)), | |
56 cancel_prompt_threshold_(kDefaultCancelPromptThreshold) {} | |
57 ~ProxyAuth() {} | |
58 | |
59 void ConfigureProxyAuth(bool is_machine, uint32 cancel_prompt_threshold); | |
60 | |
61 // Retrieves the saved proxy credentials for Internet Explorer currently. | |
62 // In the future, there may be other sources of credentials. | |
63 // | |
64 // @param allow_ui Whether to allow a ui prompt | |
65 // @param server The proxy server in domain:port format (e.g., foo.com:8080) | |
66 // @param username The stored username for this proxy server | |
67 // @param password The stored password for this proxy server | |
68 // @returns true if credentials were found, otherwise false | |
69 bool GetProxyCredentials(bool allow_ui, bool force_ui, const CString& server, | |
70 const ProxyAuthConfig& config, CString* username, | |
71 CString* password, uint32* auth_scheme); | |
72 | |
73 static CString ExtractProxy(const CString& proxy_settings, bool isHttps); | |
74 | |
75 // This function adds a credential entry, or updates an existing server's | |
76 // credential entry if it already exists | |
77 void AddCred(const CString& server, const CString& username, | |
78 const CString& password); | |
79 HRESULT SetProxyAuthScheme(const CString& server, uint32 scheme); | |
80 | |
81 bool IsPromptAllowed(); | |
82 void PromptCancelled(); | |
83 | |
84 private: | |
85 // The servers_, usernames_, and passwords_ lists form a map from server to | |
86 // (username, password) tuple. They're implemented here using SimplyArrays | |
87 // because the otherhead of a map is thought to be too much, since most | |
88 // users will have one proxy server at most, not dozens. Accesses are | |
89 // protected with the lock_. | |
90 omaha::LLock lock_; | |
91 CSimpleArray<CString> servers_; | |
92 CSimpleArray<CString> usernames_; | |
93 CSimpleArray<std::vector<uint8> > passwords_; | |
94 CSimpleArray<uint32> auth_schemes_; | |
95 | |
96 // counts how many times the user has cancelled the authentication prompt. | |
97 uint32 prompt_cancelled_; | |
98 | |
99 // after this many authentication prompt cancellations, stop prompting. | |
100 uint32 cancel_prompt_threshold_; | |
101 | |
102 bool proxy_prompt_is_machine_; | |
103 | |
104 bool ReadFromIE7(const CString& server); | |
105 bool ReadFromPreIE7(const CString& server); | |
106 bool PromptUser(const CString& server, const ProxyAuthConfig& config); | |
107 | |
108 DISALLOW_EVIL_CONSTRUCTORS(ProxyAuth); | |
109 }; | |
110 | |
111 } // namespace omaha | |
112 | |
113 #endif // OMAHA_NET_PROXY_AUTH_H__ | |
114 | |
OLD | NEW |