blob: 9ed0499bee6e9cb88bb9a3f40260d91c5989124a [file] [log] [blame]
Lutz Justen09cd1c32019-02-15 14:31:49 +01001// Copyright 2019 The Chromium OS 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
5#ifndef KERBEROS_KRB5_INTERFACE_H_
6#define KERBEROS_KRB5_INTERFACE_H_
7
Lutz Justene6784c02019-07-03 14:08:43 +02008#include <string>
9
Lutz Justen09cd1c32019-02-15 14:31:49 +010010#include <base/compiler_specific.h>
Lutz Justene39cbd42019-05-14 14:52:24 +020011#include <base/macros.h>
Lutz Justen09cd1c32019-02-15 14:31:49 +010012
13#include "kerberos/proto_bindings/kerberos_service.pb.h"
14
Lutz Justenb79da832019-03-08 14:52:53 +010015namespace base {
16class FilePath;
17}
18
Lutz Justen09cd1c32019-02-15 14:31:49 +010019namespace kerberos {
20
21class Krb5Interface {
22 public:
Lutz Justene39cbd42019-05-14 14:52:24 +020023 Krb5Interface() = default;
Qijiang Fan6bc59e12020-11-11 02:51:06 +090024 Krb5Interface(const Krb5Interface&) = delete;
25 Krb5Interface& operator=(const Krb5Interface&) = delete;
26
Lutz Justene39cbd42019-05-14 14:52:24 +020027 virtual ~Krb5Interface() = default;
Lutz Justen09cd1c32019-02-15 14:31:49 +010028
Lutz Justencb8399d2019-03-08 14:30:17 +010029 // Ticket-granting-ticket status, see GetTgtStatus().
30 struct TgtStatus {
31 // For how many seconds the ticket is still valid.
32 int64_t validity_seconds = 0;
33
34 // For how many seconds the ticket can be renewed.
35 int64_t renewal_seconds = 0;
Lutz Justenb6d31082019-06-27 17:21:43 +020036
37 constexpr TgtStatus() = default;
38
39 constexpr TgtStatus(int64_t validity_seconds, int64_t renewal_seconds)
40 : validity_seconds(validity_seconds),
41 renewal_seconds(renewal_seconds) {}
Lutz Justene6784c02019-07-03 14:08:43 +020042
43 bool operator==(const TgtStatus& other) const {
44 return validity_seconds == other.validity_seconds &&
45 renewal_seconds == other.renewal_seconds;
46 }
47 bool operator!=(const TgtStatus& other) const { return !(*this == other); }
Lutz Justencb8399d2019-03-08 14:30:17 +010048 };
49
Lutz Justen09cd1c32019-02-15 14:31:49 +010050 // Gets a Kerberos ticket-granting-ticket for the given |principal_name|
51 // (user@REALM.COM). |password| is the password for the Kerberos account.
52 // |krb5cc_path| is the file path where the Kerberos credential cache (i.e.
53 // the TGT) is written to. |krb5conf_path| is the path to a Kerberos
54 // configuration file (krb5.conf).
Lutz Justene39cbd42019-05-14 14:52:24 +020055 virtual ErrorType AcquireTgt(const std::string& principal_name,
56 const std::string& password,
57 const base::FilePath& krb5cc_path,
58 const base::FilePath& krb5conf_path)
59 WARN_UNUSED_RESULT = 0;
Lutz Justen09cd1c32019-02-15 14:31:49 +010060
Lutz Justencb8399d2019-03-08 14:30:17 +010061 // Renews an existing Kerberos ticket-granting-ticket for the given
Lutz Justen09cd1c32019-02-15 14:31:49 +010062 // |principal_name| (user@REALM.COM). |krb5cc_path| is the file path of the
63 // Kerberos credential cache. |krb5conf_path| is the path to a Kerberos
64 // configuration file (krb5.conf).
Lutz Justene39cbd42019-05-14 14:52:24 +020065 virtual ErrorType RenewTgt(const std::string& principal_name,
66 const base::FilePath& krb5cc_path,
67 const base::FilePath& krb5conf_path)
68 WARN_UNUSED_RESULT = 0;
Lutz Justencb8399d2019-03-08 14:30:17 +010069
70 // Gets some stats about the ticket-granting-ticket in the credential cache
71 // at |krb5cc_path|.
Lutz Justene39cbd42019-05-14 14:52:24 +020072 virtual ErrorType GetTgtStatus(const base::FilePath& krb5cc_path,
73 TgtStatus* status) WARN_UNUSED_RESULT = 0;
74
Lutz Justen90281402019-07-05 15:14:37 +020075 // Validates the Kerberos configuration data |krb5conf|. If the config has
76 // syntax errors or uses non-whitelisted options, returns ERROR_BAD_CONFIG
77 // and fills |error_info| with error information.
78 virtual ErrorType ValidateConfig(const std::string& krb5conf,
79 ConfigErrorInfo* error_info)
80 WARN_UNUSED_RESULT = 0;
Lutz Justen09cd1c32019-02-15 14:31:49 +010081};
82
83} // namespace kerberos
84
85#endif // KERBEROS_KRB5_INTERFACE_H_