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; |
| 24 | virtual ~Krb5Interface() = default; |
Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 25 | |
Lutz Justen | cb8399d | 2019-03-08 14:30:17 +0100 | [diff] [blame] | 26 | // Ticket-granting-ticket status, see GetTgtStatus(). |
| 27 | struct TgtStatus { |
| 28 | // For how many seconds the ticket is still valid. |
| 29 | int64_t validity_seconds = 0; |
| 30 | |
| 31 | // For how many seconds the ticket can be renewed. |
| 32 | int64_t renewal_seconds = 0; |
Lutz Justen | b6d3108 | 2019-06-27 17:21:43 +0200 | [diff] [blame] | 33 | |
| 34 | constexpr TgtStatus() = default; |
| 35 | |
| 36 | constexpr TgtStatus(int64_t validity_seconds, int64_t renewal_seconds) |
| 37 | : validity_seconds(validity_seconds), |
| 38 | renewal_seconds(renewal_seconds) {} |
Lutz Justen | e6784c0 | 2019-07-03 14:08:43 +0200 | [diff] [blame^] | 39 | |
| 40 | bool operator==(const TgtStatus& other) const { |
| 41 | return validity_seconds == other.validity_seconds && |
| 42 | renewal_seconds == other.renewal_seconds; |
| 43 | } |
| 44 | bool operator!=(const TgtStatus& other) const { return !(*this == other); } |
Lutz Justen | cb8399d | 2019-03-08 14:30:17 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 47 | // Gets a Kerberos ticket-granting-ticket for the given |principal_name| |
| 48 | // (user@REALM.COM). |password| is the password for the Kerberos account. |
| 49 | // |krb5cc_path| is the file path where the Kerberos credential cache (i.e. |
| 50 | // the TGT) is written to. |krb5conf_path| is the path to a Kerberos |
| 51 | // configuration file (krb5.conf). |
Lutz Justen | e39cbd4 | 2019-05-14 14:52:24 +0200 | [diff] [blame] | 52 | virtual ErrorType AcquireTgt(const std::string& principal_name, |
| 53 | const std::string& password, |
| 54 | const base::FilePath& krb5cc_path, |
| 55 | const base::FilePath& krb5conf_path) |
| 56 | WARN_UNUSED_RESULT = 0; |
Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 57 | |
Lutz Justen | cb8399d | 2019-03-08 14:30:17 +0100 | [diff] [blame] | 58 | // Renews an existing Kerberos ticket-granting-ticket for the given |
Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 59 | // |principal_name| (user@REALM.COM). |krb5cc_path| is the file path of the |
| 60 | // Kerberos credential cache. |krb5conf_path| is the path to a Kerberos |
| 61 | // configuration file (krb5.conf). |
Lutz Justen | e39cbd4 | 2019-05-14 14:52:24 +0200 | [diff] [blame] | 62 | virtual ErrorType RenewTgt(const std::string& principal_name, |
| 63 | const base::FilePath& krb5cc_path, |
| 64 | const base::FilePath& krb5conf_path) |
| 65 | WARN_UNUSED_RESULT = 0; |
Lutz Justen | cb8399d | 2019-03-08 14:30:17 +0100 | [diff] [blame] | 66 | |
| 67 | // Gets some stats about the ticket-granting-ticket in the credential cache |
| 68 | // at |krb5cc_path|. |
Lutz Justen | e39cbd4 | 2019-05-14 14:52:24 +0200 | [diff] [blame] | 69 | virtual ErrorType GetTgtStatus(const base::FilePath& krb5cc_path, |
| 70 | TgtStatus* status) WARN_UNUSED_RESULT = 0; |
| 71 | |
| 72 | private: |
| 73 | DISALLOW_COPY_AND_ASSIGN(Krb5Interface); |
Lutz Justen | 09cd1c3 | 2019-02-15 14:31:49 +0100 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace kerberos |
| 77 | |
| 78 | #endif // KERBEROS_KRB5_INTERFACE_H_ |