File: blink_key_handle.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (60 lines) | stat: -rw-r--r-- 2,288 bytes parent folder | download | duplicates (2)
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
// 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 COMPONENTS_WEBCRYPTO_BLINK_KEY_HANDLE_H_
#define COMPONENTS_WEBCRYPTO_BLINK_KEY_HANDLE_H_

#include <stdint.h>

#include <vector>

#include "third_party/WebKit/public/platform/WebCryptoKey.h"
#include "third_party/boringssl/src/include/openssl/base.h"

// Blink keys (blink::WebCryptoKey) have an associated key handle
// (blink::WebCryptoKeyHandle) used to store custom data. This is where the
// underlying EVP_PKEY is stored for asymmetric keys, or an std::vector
// containing the bytes for symmetric keys.
//
// This file contains helpers for creating the key handles, and extracting
// properties from it.

namespace webcrypto {

class CryptoData;

// Returns a reference to the symmetric key data wrapped by the given Blink
// key. The returned reference is owned by |key|. This function must only be
// called on secret keys (HMAC, AES, etc).
const std::vector<uint8_t>& GetSymmetricKeyData(const blink::WebCryptoKey& key);

// Returns the EVP_PKEY* wrapped by the given Blink key. The returned pointer
// is owned by |key|. This function must only be called on asymmetric keys
// (RSA, EC, etc).
EVP_PKEY* GetEVP_PKEY(const blink::WebCryptoKey& key);

// Returns a reference to the serialized key data. This reference is owned by
// |key|. This function can be called for any key type.
const std::vector<uint8_t>& GetSerializedKeyData(
    const blink::WebCryptoKey& key);

// Creates a symmetric key handle that can be passed to Blink. The caller takes
// ownership of the returned pointer.
blink::WebCryptoKeyHandle* CreateSymmetricKeyHandle(
    const CryptoData& key_bytes);

// Creates an asymmetric key handle that can be passed to Blink. The caller
// takes
// ownership of the returned pointer.
//
// TODO(eroman): This should _move_ input serialized_key_data rather than
// create a copy, since all the callers are passing in vectors that are later
// thrown away anyway.
blink::WebCryptoKeyHandle* CreateAsymmetricKeyHandle(
    bssl::UniquePtr<EVP_PKEY> pkey,
    const std::vector<uint8_t>& serialized_key_data);

}  // namespace webcrypto

#endif  // COMPONENTS_WEBCRYPTO_BLINK_KEY_HANDLE_H_