Home | History | Annotate | Download | only in base
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef NET_BASE_SSL_CLIENT_AUTH_CACHE_H_
      6 #define NET_BASE_SSL_CLIENT_AUTH_CACHE_H_
      7 
      8 #include <string>
      9 #include <map>
     10 
     11 #include "base/ref_counted.h"
     12 #include "net/base/x509_certificate.h"
     13 
     14 namespace net {
     15 
     16 // The SSLClientAuthCache class is a simple cache structure to store SSL
     17 // client certificates. Provides lookup, insertion, and deletion of entries.
     18 // The parameter for doing lookups, insertions, and deletions is the server's
     19 // host and port.
     20 //
     21 // TODO(wtc): This class is based on FtpAuthCache.  We can extract the common
     22 // code to a template class.
     23 class SSLClientAuthCache {
     24  public:
     25   SSLClientAuthCache() {}
     26   ~SSLClientAuthCache() {}
     27 
     28   // Check if we have a client certificate for SSL server at |server|.
     29   // Returns the client certificate (if found) or NULL (if not found).
     30   X509Certificate* Lookup(const std::string& server);
     31 
     32   // Add a client certificate for |server| to the cache. If there is already
     33   // a client certificate for |server|, it will be overwritten. Both parameters
     34   // are IN only.
     35   void Add(const std::string& server, X509Certificate* client_cert);
     36 
     37   // Remove the client certificate for |server| from the cache, if one exists.
     38   void Remove(const std::string& server);
     39 
     40  private:
     41   typedef std::string AuthCacheKey;
     42   typedef scoped_refptr<X509Certificate> AuthCacheValue;
     43   typedef std::map<AuthCacheKey, AuthCacheValue> AuthCacheMap;
     44 
     45   // internal representation of cache, an STL map.
     46   AuthCacheMap cache_;
     47 };
     48 
     49 }  // namespace net
     50 
     51 #endif  // NET_BASE_SSL_CLIENT_AUTH_CACHE_H_
     52