blob: 54a3df4281a274508ba5c6219b1d2c130b8d25fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/base/openssl_util.h"
#include <openssl/err.h>
#include <openssl/x509v3.h>
#include "base/logging.h"
namespace net {
X509_STORE* OpenSSLInitSingleton::x509_store() const {
return store_.get();
}
OpenSSLInitSingleton::OpenSSLInitSingleton()
: store_(X509_STORE_new()) {
CHECK(store_.get());
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
X509_STORE_set_default_paths(store_.get());
// TODO(bulach): Enable CRL (see X509_STORE_set_flags(X509_V_FLAG_CRL_CHECK)).
int num_locks = CRYPTO_num_locks();
for (int i = 0; i < num_locks; ++i)
locks_.push_back(new Lock());
CRYPTO_set_locking_callback(LockingCallback);
}
OpenSSLInitSingleton::~OpenSSLInitSingleton() {
CRYPTO_set_locking_callback(NULL);
EVP_cleanup();
ERR_free_strings();
}
OpenSSLInitSingleton* GetOpenSSLInitSingleton() {
return Singleton<OpenSSLInitSingleton>::get();
}
// static
void OpenSSLInitSingleton::LockingCallback(int mode,
int n,
const char* file,
int line) {
GetOpenSSLInitSingleton()->OnLockingCallback(mode, n, file, line);
}
void OpenSSLInitSingleton::OnLockingCallback(int mode,
int n,
const char* file,
int line) {
CHECK_LT(static_cast<size_t>(n), locks_.size());
if (mode & CRYPTO_LOCK)
locks_[n]->Acquire();
else
locks_[n]->Release();
}
} // namespace net
|