blob: ad8d6215d59dd717ee79d4cbf3a159b3fd6aa921 [file] [log] [blame]
// 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.
#include <memory>
#include <vector>
#include "base/containers/span.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "net/ssl/ssl_private_key.h"
#include "starboard/types.h"
namespace base {
class SingleThreadTaskRunner;
namespace net {
// An SSLPrivateKey implementation which offloads key operations to a background
// task runner.
class ThreadedSSLPrivateKey : public SSLPrivateKey {
// Interface for consumers to implement to perform the actual signing
// operation.
class Delegate {
Delegate() {}
virtual ~Delegate() {}
// Returns the algorithms that are supported by the key in decreasing
// preference for TLS 1.2 and later. Note that
// |SSL_SIGN_RSA_PKCS1_MD5_SHA1| is only used by TLS 1.1 and earlier and
// should not be in this list.
virtual std::vector<uint16_t> GetAlgorithmPreferences() = 0;
// Signs an |input| with the specified TLS signing algorithm. |input| is
// the unhashed message to be signed. On success it returns OK and sets
// |signature| to the resulting signature. Otherwise it returns a net error
// code. It will only be called on the task runner passed to the owning
// ThreadedSSLPrivateKey.
virtual Error Sign(uint16_t algorithm,
base::span<const uint8_t> input,
std::vector<uint8_t>* signature) = 0;
std::unique_ptr<Delegate> delegate,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
// SSLPrivateKey implementation.
std::vector<uint16_t> GetAlgorithmPreferences() override;
void Sign(uint16_t algorithm,
base::span<const uint8_t> input,
SignCallback callback) override;
~ThreadedSSLPrivateKey() override;
class Core;
scoped_refptr<Core> core_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
base::WeakPtrFactory<ThreadedSSLPrivateKey> weak_factory_;
} // namespace net