1// Copyright (c) 2011 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#include "net/base/cert_database.h"
6
7#include <openssl/x509.h>
8
9#include "base/logging.h"
10#include "net/base/crypto_module.h"
11#include "net/base/net_errors.h"
12#include "net/base/openssl_private_key_store.h"
13#include "net/base/x509_certificate.h"
14
15namespace net {
16
17CertDatabase::CertDatabase() {
18}
19
20int CertDatabase::CheckUserCert(X509Certificate* cert) {
21  if (!cert)
22    return ERR_CERT_INVALID;
23  if (cert->HasExpired())
24    return ERR_CERT_DATE_INVALID;
25
26  if (!OpenSSLPrivateKeyStore::GetInstance()->FetchPrivateKey(
27      X509_PUBKEY_get(X509_get_X509_PUBKEY(cert->os_cert_handle()))))
28    return ERR_NO_PRIVATE_KEY_FOR_CERT;
29
30  return OK;
31}
32
33int CertDatabase::AddUserCert(X509Certificate* cert) {
34  // TODO(bulach): implement me.
35  NOTIMPLEMENTED();
36  return ERR_NOT_IMPLEMENTED;
37}
38
39void CertDatabase::ListCerts(CertificateList* certs) {
40  // TODO(bulach): implement me.
41  NOTIMPLEMENTED();
42}
43
44CryptoModule* CertDatabase::GetPublicModule() const {
45  // TODO(bulach): implement me.
46  NOTIMPLEMENTED();
47  return NULL;
48}
49
50CryptoModule* CertDatabase::GetPrivateModule() const {
51  // TODO(bulach): implement me.
52  NOTIMPLEMENTED();
53  return NULL;
54}
55
56void CertDatabase::ListModules(CryptoModuleList* modules, bool need_rw) const {
57  // TODO(bulach): implement me.
58  NOTIMPLEMENTED();
59  modules->clear();
60}
61
62int CertDatabase::ImportFromPKCS12(CryptoModule* module,
63                                   const std::string& data,
64                                   const string16& password) {
65  // TODO(bulach): implement me.
66  NOTIMPLEMENTED();
67  return ERR_NOT_IMPLEMENTED;
68}
69
70int CertDatabase::ExportToPKCS12(const CertificateList& certs,
71                                 const string16& password,
72                                 std::string* output) const {
73  // TODO(bulach): implement me.
74  NOTIMPLEMENTED();
75  return 0;
76}
77
78bool CertDatabase::DeleteCertAndKey(const X509Certificate* cert) {
79  // TODO(bulach): implement me.
80  NOTIMPLEMENTED();
81  return false;
82}
83
84unsigned int CertDatabase::GetCertTrust(const X509Certificate* cert,
85                                        CertType type) const {
86  // TODO(bulach): implement me.
87  NOTIMPLEMENTED();
88  return 0;
89}
90
91bool CertDatabase::SetCertTrust(const X509Certificate* cert,
92                                CertType type,
93                                unsigned int trust_bits) {
94  // TODO(bulach): implement me.
95  NOTIMPLEMENTED();
96  return false;
97}
98
99}  // namespace net
100