summaryrefslogtreecommitdiffstats
path: root/net/ssl/ssl_key_logger.h
blob: dcaf6c6a89b3d60ad79a32d7d706c45b274b66c8 (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
// Copyright 2015 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.

#ifndef NET_SSL_SSL_KEY_LOGGER_H_
#define NET_SSL_SSL_KEY_LOGGER_H_

#include <string>

#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"

namespace base {
class FilePath;
class SequencedTaskRunner;
}

namespace net {

// SSLKeyLogger logs SSL key material for debugging purposes. This should only
// be used when requested by the user, typically via the SSLKEYLOGFILE
// environment variable. See also
// https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format.
class SSLKeyLogger {
 public:
  // Creates a new SSLKeyLogger which writes to |path|, scheduling write
  // operations on |task_runner|.
  SSLKeyLogger(const base::FilePath& path,
               const scoped_refptr<base::SequencedTaskRunner>& task_runner);
  ~SSLKeyLogger();

  // Writes |line| followed by a newline. This may be called by multiple threads
  // simultaneously. If two calls race, the order of the lines is undefined, but
  // each line will be written atomically.
  void WriteLine(const std::string& line);

 private:
  class Core;

  scoped_refptr<base::SequencedTaskRunner> task_runner_;
  // Destroyed on |task_runner_|.
  scoped_ptr<Core> core_;

  DISALLOW_COPY_AND_ASSIGN(SSLKeyLogger);
};

}  // namespace net

#endif  // NET_SSL_SSL_KEY_LOGGER_H_