OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef NET_FTP_FTP_AUTH_CACHE_H_ | 5 #ifndef NET_BASE_SSL_CLIENT_AUTH_CACHE_H_ |
6 #define NET_FTP_FTP_AUTH_CACHE_H_ | 6 #define NET_BASE_SSL_CLIENT_AUTH_CACHE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "net/base/auth.h" | 11 #include "base/ref_counted.h" |
12 | 12 #include "net/base/x509_certificate.h" |
13 class GURL; | |
14 | 13 |
15 namespace net { | 14 namespace net { |
16 | 15 |
17 // The FtpAuthCache class is a simple cache structure to store authentication | 16 // The SSLClientAuthCache class is a simple cache structure to store SSL |
18 // information for ftp. Provides lookup, insertion, and deletion of entries. | 17 // client certificates. Provides lookup, insertion, and deletion of entries. |
19 // The parameter for doing lookups, insertions, and deletions is a GURL of the | 18 // The parameter for doing lookups, insertions, and deletions is the server's |
20 // server's address (not a full URL with path, since FTP auth isn't per path). | 19 // host and port. |
21 // For example: | 20 // |
22 // GURL("ftp://myserver") -- OK (implied port of 21) | 21 // TODO(wtc): This class is based on FtpAuthCache. We can extract the common |
23 // GURL("ftp://myserver:21") -- OK | 22 // code to a template class. |
24 // GURL("ftp://myserver/PATH") -- WRONG, paths not allowed | 23 class SSLClientAuthCache { |
25 class FtpAuthCache { | |
26 public: | 24 public: |
27 FtpAuthCache() {} | 25 SSLClientAuthCache() {} |
28 ~FtpAuthCache() {} | 26 ~SSLClientAuthCache() {} |
29 | 27 |
30 // Check if we have authentication data for ftp server at |origin|. | 28 // Check if we have a client certificate for SSL server at |server|. |
31 // Returns the address of corresponding AuthData object (if found) or NULL | 29 // Returns the client certificate (if found) or NULL (if not found). |
32 // (if not found). | 30 X509Certificate* Lookup(const std::string& server); |
33 AuthData* Lookup(const GURL& origin); | |
34 | 31 |
35 // Add an entry for |origin| to the cache. If there is already an | 32 // Add a client certificate for |server| to the cache. If there is already |
36 // entry for |origin|, it will be overwritten. Both parameters are IN only. | 33 // a client certificate for |server|, it will be overwritten. Both parameters |
37 void Add(const GURL& origin, AuthData* value); | 34 // are IN only. |
| 35 void Add(const std::string& server, X509Certificate* client_cert); |
38 | 36 |
39 // Remove the entry for |origin| from the cache, if one exists. | 37 // Remove the client certificate for |server| from the cache, if one exists. |
40 void Remove(const GURL& origin); | 38 void Remove(const std::string& server); |
41 | 39 |
42 private: | 40 private: |
43 typedef std::string AuthCacheKey; | 41 typedef std::string AuthCacheKey; |
44 typedef scoped_refptr<AuthData> AuthCacheValue; | 42 typedef scoped_refptr<X509Certificate> AuthCacheValue; |
45 typedef std::map<AuthCacheKey,AuthCacheValue> AuthCacheMap; | 43 typedef std::map<AuthCacheKey, AuthCacheValue> AuthCacheMap; |
46 | |
47 // Get the key in hash table |cache_| where entries for ftp server |origin| | |
48 // should be saved. | |
49 static AuthCacheKey MakeKey(const GURL& origin); | |
50 | 44 |
51 // internal representation of cache, an STL map. | 45 // internal representation of cache, an STL map. |
52 AuthCacheMap cache_; | 46 AuthCacheMap cache_; |
53 }; | 47 }; |
54 | 48 |
55 } // namespace net | 49 } // namespace net |
56 | 50 |
57 #endif // NET_FTP_FTP_AUTH_CACHE_H_ | 51 #endif // NET_BASE_SSL_CLIENT_AUTH_CACHE_H_ |
OLD | NEW |