blob: 27074cfb4212f50df57399dd9ac6a17ce9d19056 [file] [log] [blame]
eromand62cb472015-09-18 18:24:231// Copyright 2015 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
eromanab1308a2015-10-01 19:38:045#ifndef COMPONENTS_WEBCRYPTO_BLINK_KEY_HANDLE_H_
6#define COMPONENTS_WEBCRYPTO_BLINK_KEY_HANDLE_H_
eromand62cb472015-09-18 18:24:237
eromand62cb472015-09-18 18:24:238#include <stdint.h>
9
10#include <vector>
11
eromand62cb472015-09-18 18:24:2312#include "third_party/WebKit/public/platform/WebCryptoKey.h"
tfarina29a3a1742016-10-28 18:47:3313#include "third_party/boringssl/src/include/openssl/base.h"
eromand62cb472015-09-18 18:24:2314
eromanab1308a2015-10-01 19:38:0415// Blink keys (blink::WebCryptoKey) have an associated key handle
16// (blink::WebCryptoKeyHandle) used to store custom data. This is where the
17// underlying EVP_PKEY is stored for asymmetric keys, or an std::vector
18// containing the bytes for symmetric keys.
19//
20// This file contains helpers for creating the key handles, and extracting
21// properties from it.
22
eromand62cb472015-09-18 18:24:2323namespace webcrypto {
24
25class CryptoData;
26
27// Returns a reference to the symmetric key data wrapped by the given Blink
28// key. The returned reference is owned by |key|. This function must only be
29// called on secret keys (HMAC, AES, etc).
30const std::vector<uint8_t>& GetSymmetricKeyData(const blink::WebCryptoKey& key);
31
32// Returns the EVP_PKEY* wrapped by the given Blink key. The returned pointer
33// is owned by |key|. This function must only be called on asymmetric keys
34// (RSA, EC, etc).
35EVP_PKEY* GetEVP_PKEY(const blink::WebCryptoKey& key);
36
37// Returns a reference to the serialized key data. This reference is owned by
38// |key|. This function can be called for any key type.
39const std::vector<uint8_t>& GetSerializedKeyData(
40 const blink::WebCryptoKey& key);
41
42// Creates a symmetric key handle that can be passed to Blink. The caller takes
43// ownership of the returned pointer.
44blink::WebCryptoKeyHandle* CreateSymmetricKeyHandle(
45 const CryptoData& key_bytes);
46
47// Creates an asymmetric key handle that can be passed to Blink. The caller
48// takes
49// ownership of the returned pointer.
50//
51// TODO(eroman): This should _move_ input serialized_key_data rather than
52// create a copy, since all the callers are passing in vectors that are later
53// thrown away anyway.
54blink::WebCryptoKeyHandle* CreateAsymmetricKeyHandle(
davidben7e7722812016-10-11 00:29:0655 bssl::UniquePtr<EVP_PKEY> pkey,
eromand62cb472015-09-18 18:24:2356 const std::vector<uint8_t>& serialized_key_data);
57
58} // namespace webcrypto
59
eromanab1308a2015-10-01 19:38:0460#endif // COMPONENTS_WEBCRYPTO_BLINK_KEY_HANDLE_H_