15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_PUBLIC_BROWSER_CERT_STORE_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_PUBLIC_BROWSER_CERT_STORE_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class X509Certificate;
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The purpose of the cert store is to provide an easy way to store/retrieve
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// X509Certificate objects.  When stored, an X509Certificate object is
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// associated with a RenderProcessHost.  If all the RenderProcessHosts
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// associated with the cert have exited, the cert is removed from the store.
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class is used by the SSLManager to keep track of the certs associated
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to loaded resources.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// It can be accessed from the UI and IO threads (it is thread-safe).
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Note that the cert ids will overflow if we register more than 2^32 - 1 certs
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in 1 browsing session (which is highly unlikely to happen).
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CertStore  {
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the singleton instance of the CertStore.
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CONTENT_EXPORT static CertStore* GetInstance();
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stores the specified cert and returns the id associated with it.  The cert
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is associated to the specified RenderProcessHost.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // When all the RenderProcessHosts associated with a cert have exited, the
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cert is removed from the store.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note: ids starts at 1.
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int StoreCert(net::X509Certificate* cert,
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        int render_process_host_id) = 0;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tries to retrieve the previously stored cert associated with the specified
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |cert_id|. Returns whether the cert could be found, and, if |cert| is
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // non-NULL, copies it in.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool RetrieveCert(int cert_id,
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            scoped_refptr<net::X509Certificate>* cert) = 0;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   virtual ~CertStore() {}
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CONTENT_PUBLIC_BROWSER_CERT_STORE_H_
52