File: chaps_slot_session.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (84 lines) | stat: -rw-r--r-- 3,185 bytes parent folder | download | duplicates (8)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_CHAPS_UTIL_CHAPS_SLOT_SESSION_H_
#define CHROMEOS_ASH_COMPONENTS_CHAPS_UTIL_CHAPS_SLOT_SESSION_H_

#include <pkcs11t.h>

#include <memory>

#include "base/component_export.h"

namespace chromeos {

// A PKCS#11 session for a slot provided by the chaps daemon.
// This class provides a subset of PKCS#11 operations relevant for ChromeOS.
// When a ChapsSlotSession is destructed, the PKCS#11 session is closed.
// Operations on a ChapsSlotSession are blocking and expensive, so they may only
// be performed on a worker thread.
class ChapsSlotSession {
 public:
  virtual ~ChapsSlotSession() = default;

  // Close and re-open this session.
  virtual bool ReopenSession() = 0;

  // Calls C_CreateObject.
  // PKCS #11 v2.20 section 11.7 page 128.
  virtual CK_RV CreateObject(CK_ATTRIBUTE_PTR pTemplate,
                             CK_ULONG ulCount,
                             CK_OBJECT_HANDLE_PTR phObject) = 0;

  // Calls C_GenerateKeyPair.
  // PKCS #11 v2.20 section 11.14 page 176.
  virtual CK_RV GenerateKeyPair(CK_MECHANISM_PTR pMechanism,
                                CK_ATTRIBUTE_PTR pPublicKeyTemplate,
                                CK_ULONG ulPublicKeyAttributeCount,
                                CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
                                CK_ULONG ulPrivateKeyAttributeCount,
                                CK_OBJECT_HANDLE_PTR phPublicKey,
                                CK_OBJECT_HANDLE_PTR phPrivateKey) = 0;

  // Calls C_GetAttributeValue.
  // PKCS #11 v2.20 section 11.7 page 133.
  virtual CK_RV GetAttributeValue(CK_OBJECT_HANDLE hObject,
                                  CK_ATTRIBUTE_PTR pTemplate,
                                  CK_ULONG ulCount) = 0;

  // Calls C_SetAttributeValue.
  // PKCS #11 v2.20 section 11.7 page 135.
  virtual CK_RV SetAttributeValue(CK_OBJECT_HANDLE hObject,
                                  CK_ATTRIBUTE_PTR pTemplate,
                                  CK_ULONG ulCount) = 0;
};

// Creates ChapsSlotSession instances. The factory is used to replace
// ChapsSlotSession with fakes in tests.
class ChapsSlotSessionFactory {
 public:
  virtual ~ChapsSlotSessionFactory() = default;

  // Returns a ChapsSlotSession for the slot identified by slot ID |slot_id|.
  // If loading libchaps.so, resolving symbols, or opening the session fails,
  // returns nullptr.
  virtual std::unique_ptr<ChapsSlotSession> CreateChapsSlotSession(
      CK_SLOT_ID slot_id) = 0;
};

// This is the default implementation of the ChapsSlotSessionFactory.
// Creates ChapsSlotSession instances which call functions in libchaps.so.
class COMPONENT_EXPORT(CHAPS_UTIL) ChapsSlotSessionFactoryImpl
    : public ChapsSlotSessionFactory {
 public:
  ChapsSlotSessionFactoryImpl() = default;
  ~ChapsSlotSessionFactoryImpl() override = default;

  std::unique_ptr<ChapsSlotSession> CreateChapsSlotSession(
      CK_SLOT_ID slot_id) override;
};

}  // namespace chromeos

#endif  // CHROMEOS_ASH_COMPONENTS_CHAPS_UTIL_CHAPS_SLOT_SESSION_H_