Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 1 | // 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 Justen | e6784c0 | 2019-07-03 14:08:43 +0200 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 10 | #include <base/compiler_specific.h> |
Lutz Justen | e39cbd4 | 2019-05-14 14:52:24 +0200 | [diff] [blame] | 11 | #include <base/macros.h> |
Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 12 | |
| 13 | #include "kerberos/proto_bindings/kerberos_service.pb.h" |
| 14 | |
Lutz Justen | b79da83 | 2019-03-08 14:52:53 +0100 | [diff] [blame] | 15 | namespace base { |
| 16 | class FilePath; |
| 17 | } |
| 18 | |
Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 19 | namespace kerberos { |
| 20 | |
| 21 | class Krb5Interface { |
| 22 | public: |
Lutz Justen | e39cbd4 | 2019-05-14 14:52:24 +0200 | [diff] [blame] | 23 | Krb5Interface() = default; |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame^] | 24 | Krb5Interface(const Krb5Interface&) = delete; |
| 25 | Krb5Interface& operator=(const Krb5Interface&) = delete; |
| 26 | |
Lutz Justen | e39cbd4 | 2019-05-14 14:52:24 +0200 | [diff] [blame] | 27 | virtual ~Krb5Interface() = default; |
Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 28 | |
Lutz Justen | cb8399d | 2019-03-08 14:30:17 +0100 | [diff] [blame] | 29 | // 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 Justen | b6d3108 | 2019-06-27 17:21:43 +0200 | [diff] [blame] | 36 | |
| 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 Justen | e6784c0 | 2019-07-03 14:08:43 +0200 | [diff] [blame] | 42 | |
| 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 Justen | cb8399d | 2019-03-08 14:30:17 +0100 | [diff] [blame] | 48 | }; |
| 49 | |
Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 50 | // 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 Justen | e39cbd4 | 2019-05-14 14:52:24 +0200 | [diff] [blame] | 55 | 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 Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 60 | |
Lutz Justen | cb8399d | 2019-03-08 14:30:17 +0100 | [diff] [blame] | 61 | // Renews an existing Kerberos ticket-granting-ticket for the given |
Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 62 | // |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 Justen | e39cbd4 | 2019-05-14 14:52:24 +0200 | [diff] [blame] | 65 | 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 Justen | cb8399d | 2019-03-08 14:30:17 +0100 | [diff] [blame] | 69 | |
| 70 | // Gets some stats about the ticket-granting-ticket in the credential cache |
| 71 | // at |krb5cc_path|. |
Lutz Justen | e39cbd4 | 2019-05-14 14:52:24 +0200 | [diff] [blame] | 72 | virtual ErrorType GetTgtStatus(const base::FilePath& krb5cc_path, |
| 73 | TgtStatus* status) WARN_UNUSED_RESULT = 0; |
| 74 | |
Lutz Justen | 9028140 | 2019-07-05 15:14:37 +0200 | [diff] [blame] | 75 | // 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 Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | } // namespace kerberos |
| 84 | |
| 85 | #endif // KERBEROS_KRB5_INTERFACE_H_ |