#ifndef NET_CERT_TEST_ROOT_CERTS_H_
#define NET_CERT_TEST_ROOT_CERTS_H_
#include "base/lazy_instance.h"
#include "base/memory/ref_counted.h"
#include "build/build_config.h"
#include "net/base/net_export.h"
#if defined(USE_NSS) || defined(OS_IOS)
#include <list>
#elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID)
#include <vector>
#elif defined(OS_WIN)
#include <windows.h>
#include <wincrypt.h>
#elif defined(OS_MACOSX)
#include <CoreFoundation/CFArray.h>
#include <Security/SecTrust.h>
#include "base/mac/scoped_cftyperef.h"
#endif
#if defined(USE_NSS)
typedef struct CERTCertificateStr CERTCertificate;
#elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID)
typedef struct x509_st X509;
#endif
namespace base {
class FilePath;
}
namespace net {
class X509Certificate;
class NET_EXPORT TestRootCerts {
public:
static TestRootCerts* GetInstance();
static bool HasInstance();
bool Add(X509Certificate* certificate);
bool AddFromFile(const base::FilePath& file);
void Clear();
bool IsEmpty() const;
#if defined(USE_NSS)
bool Contains(CERTCertificate* cert) const;
#elif defined(OS_MACOSX) && !defined(OS_IOS)
CFArrayRef temporary_roots() const { return temporary_roots_; }
OSStatus FixupSecTrustRef(SecTrustRef trust_ref) const;
void SetAllowSystemTrust(bool allow_system_trust);
#elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID)
const std::vector<scoped_refptr<X509Certificate> >&
temporary_roots() const { return temporary_roots_; }
bool Contains(X509* cert) const;
#elif defined(OS_WIN)
HCERTSTORE temporary_roots() const { return temporary_roots_; }
HCERTCHAINENGINE GetChainEngine() const;
#endif
private:
friend struct base::DefaultLazyInstanceTraits<TestRootCerts>;
TestRootCerts();
~TestRootCerts();
void Init();
#if defined(USE_NSS) || defined(OS_IOS)
class TrustEntry;
std::list<TrustEntry*> trust_cache_;
#elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID)
std::vector<scoped_refptr<X509Certificate> > temporary_roots_;
#elif defined(OS_WIN)
HCERTSTORE temporary_roots_;
#elif defined(OS_MACOSX)
base::ScopedCFTypeRef<CFMutableArrayRef> temporary_roots_;
bool allow_system_trust_;
#endif
#if defined(OS_WIN) || defined(OS_ANDROID)
bool empty_;
#endif
DISALLOW_COPY_AND_ASSIGN(TestRootCerts);
};
class NET_EXPORT_PRIVATE ScopedTestRoot {
public:
ScopedTestRoot();
explicit ScopedTestRoot(X509Certificate* cert);
~ScopedTestRoot();
void Reset(X509Certificate* cert);
private:
scoped_refptr<X509Certificate> cert_;
DISALLOW_COPY_AND_ASSIGN(ScopedTestRoot);
};
}
#endif