Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 1 | #include "rakp12.hpp" |
| 2 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 3 | #include "comm_module.hpp" |
| 4 | #include "endian.hpp" |
| 5 | #include "guid.hpp" |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 6 | #include "sessions_manager.hpp" |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 7 | |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 8 | #include <openssl/rand.h> |
| 9 | |
George Liu | bc8958f | 2022-07-04 09:29:49 +0800 | [diff] [blame] | 10 | #include <ipmid/types.hpp> |
| 11 | #include <phosphor-logging/log.hpp> |
| 12 | |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 13 | #include <algorithm> |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 14 | #include <cstring> |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 15 | #include <iomanip> |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 16 | |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 17 | using namespace phosphor::logging; |
| 18 | |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 19 | namespace command |
| 20 | { |
| 21 | |
AppaRao Puli | ecb32fb | 2020-07-01 22:55:38 +0530 | [diff] [blame] | 22 | bool isChannelAccessModeEnabled(const uint8_t accessMode) |
| 23 | { |
| 24 | return accessMode != |
| 25 | static_cast<uint8_t>(ipmi::EChannelAccessMode::disabled); |
| 26 | } |
| 27 | |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 28 | void logInvalidLoginRedfishEvent(const std::string& journalMsg, |
| 29 | const std::optional<std::string>& messageArgs) |
| 30 | { |
| 31 | static constexpr std::string_view openBMCMessageRegistryVersion = "0.1."; |
| 32 | std::string messageID = "OpenBMC." + |
| 33 | std::string(openBMCMessageRegistryVersion) + |
| 34 | "InvalidLoginAttempted"; |
| 35 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 36 | journalMsg.c_str(), |
| 37 | phosphor::logging::entry("REDFISH_MESSAGE_ID=%s", messageID.c_str()), |
| 38 | phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s", |
| 39 | messageArgs.value().c_str())); |
| 40 | } |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 41 | std::vector<uint8_t> RAKP12(const std::vector<uint8_t>& inPayload, |
Vernon Mauery | 41ff9b5 | 2021-06-11 11:37:40 -0700 | [diff] [blame] | 42 | std::shared_ptr<message::Handler>& handler) |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 43 | { |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 44 | auto request = reinterpret_cast<const RAKP1request*>(inPayload.data()); |
Zhikui Ren | 2b1edef | 2020-07-24 14:32:13 -0700 | [diff] [blame] | 45 | // verify inPayload minimum size |
| 46 | if (inPayload.size() < (sizeof(*request) - userNameMaxLen)) |
| 47 | { |
| 48 | std::vector<uint8_t> errorPayload{IPMI_CC_REQ_DATA_LEN_INVALID}; |
| 49 | return errorPayload; |
| 50 | } |
| 51 | |
| 52 | std::vector<uint8_t> outPayload(sizeof(RAKP2response)); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 53 | auto response = reinterpret_cast<RAKP2response*>(outPayload.data()); |
| 54 | |
| 55 | // Session ID zero is reserved for Session Setup |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 56 | if (endian::from_ipmi(request->managedSystemSessionID) == |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 57 | session::sessionZero) |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 58 | { |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 59 | log<level::INFO>("RAKP12: BMC invalid Session ID"); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 60 | response->rmcpStatusCode = |
| 61 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_SESSION_ID); |
| 62 | return outPayload; |
| 63 | } |
| 64 | |
| 65 | std::shared_ptr<session::Session> session; |
| 66 | try |
| 67 | { |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 68 | session = session::Manager::get().getSession( |
| 69 | endian::from_ipmi(request->managedSystemSessionID)); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 70 | } |
Patrick Williams | 12d199b | 2021-10-06 12:36:48 -0500 | [diff] [blame] | 71 | catch (const std::exception& e) |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 72 | { |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 73 | log<level::ERR>("RAKP12 : session not found", |
| 74 | entry("EXCEPTION=%s", e.what())); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 75 | response->rmcpStatusCode = |
| 76 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_SESSION_ID); |
| 77 | return outPayload; |
| 78 | } |
| 79 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 80 | auto rakp1Size = |
| 81 | sizeof(RAKP1request) - (userNameMaxLen - request->user_name_len); |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 82 | |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 83 | std::string message = "Invalid login attempted via RCMPP interface "; |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 84 | // Validate user name length in the message |
| 85 | if (request->user_name_len > userNameMaxLen || |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 86 | inPayload.size() != rakp1Size) |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 87 | { |
| 88 | response->rmcpStatusCode = |
| 89 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_NAME_LENGTH); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 90 | logInvalidLoginRedfishEvent(message); |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 91 | return outPayload; |
| 92 | } |
| 93 | |
| 94 | session->userName.assign(request->user_name, request->user_name_len); |
| 95 | |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 96 | // Update transaction time |
| 97 | session->updateLastTransactionTime(); |
| 98 | |
| 99 | auto rcSessionID = endian::to_ipmi(session->getRCSessionID()); |
| 100 | auto bmcSessionID = endian::to_ipmi(session->getBMCSessionID()); |
| 101 | auto authAlgo = session->getAuthAlgo(); |
| 102 | |
| 103 | /* |
| 104 | * Generate Key Authentication Code - RAKP 2 |
| 105 | * |
| 106 | * 1) Remote Console Session ID - 4 bytes |
| 107 | * 2) Managed System Session ID - 4 bytes |
| 108 | * 3) Remote Console Random Number - 16 bytes |
| 109 | * 4) Managed System Random Number - 16 bytes |
| 110 | * 5) Managed System GUID - 16 bytes |
| 111 | * 6) Requested Privilege Level - 1 byte |
| 112 | * 7) User Name Length Byte - 1 byte (0 for 'null' username) |
| 113 | * 8) User Name - variable (absent for 'null' username) |
| 114 | */ |
| 115 | |
| 116 | std::vector<uint8_t> input; |
| 117 | input.resize(sizeof(rcSessionID) + sizeof(bmcSessionID) + |
| 118 | cipher::rakp_auth::REMOTE_CONSOLE_RANDOM_NUMBER_LEN + |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 119 | cipher::rakp_auth::BMC_RANDOM_NUMBER_LEN + BMC_GUID_LEN + |
| 120 | sizeof(request->req_max_privilege_level) + |
| 121 | sizeof(request->user_name_len) + session->userName.size()); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 122 | |
| 123 | auto iter = input.begin(); |
| 124 | |
| 125 | // Remote Console Session ID |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 126 | std::copy_n(reinterpret_cast<uint8_t*>(&rcSessionID), sizeof(rcSessionID), |
| 127 | iter); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 128 | std::advance(iter, sizeof(rcSessionID)); |
| 129 | |
| 130 | // Managed System Session ID |
| 131 | std::copy_n(reinterpret_cast<uint8_t*>(&bmcSessionID), sizeof(bmcSessionID), |
| 132 | iter); |
| 133 | std::advance(iter, sizeof(bmcSessionID)); |
| 134 | |
| 135 | // Copy the Remote Console Random Number from the RAKP1 request to the |
| 136 | // Authentication Algorithm |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 137 | std::copy_n( |
| 138 | reinterpret_cast<const uint8_t*>(request->remote_console_random_number), |
| 139 | cipher::rakp_auth::REMOTE_CONSOLE_RANDOM_NUMBER_LEN, |
| 140 | authAlgo->rcRandomNum.begin()); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 141 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 142 | std::copy(authAlgo->rcRandomNum.begin(), authAlgo->rcRandomNum.end(), iter); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 143 | std::advance(iter, cipher::rakp_auth::REMOTE_CONSOLE_RANDOM_NUMBER_LEN); |
| 144 | |
| 145 | // Generate the Managed System Random Number |
| 146 | if (!RAND_bytes(input.data() + sizeof(rcSessionID) + sizeof(bmcSessionID) + |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 147 | cipher::rakp_auth::REMOTE_CONSOLE_RANDOM_NUMBER_LEN, |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 148 | cipher::rakp_auth::BMC_RANDOM_NUMBER_LEN)) |
| 149 | { |
| 150 | response->rmcpStatusCode = |
| 151 | static_cast<uint8_t>(RAKP_ReturnCode::INSUFFICIENT_RESOURCE); |
| 152 | return outPayload; |
| 153 | } |
Richard Marian Thomaiyar | d5a4f45 | 2019-01-16 12:15:44 +0530 | [diff] [blame] | 154 | // As stated in Set Session Privilege Level command in IPMI Spec, when |
jayaprakash Mutyala | 2555e2e | 2019-12-24 22:51:46 +0000 | [diff] [blame] | 155 | // creating a session through Activate command / RAKP 1 message, it must |
| 156 | // be established with USER privilege as well as all other sessions are |
| 157 | // initially set to USER privilege, regardless of the requested maximum |
| 158 | // privilege. |
| 159 | if (!(static_cast<session::Privilege>(request->req_max_privilege_level & |
| 160 | session::reqMaxPrivMask) > |
| 161 | session::Privilege::CALLBACK)) |
Richard Marian Thomaiyar | d5a4f45 | 2019-01-16 12:15:44 +0530 | [diff] [blame] | 162 | { |
jayaprakash Mutyala | 2555e2e | 2019-12-24 22:51:46 +0000 | [diff] [blame] | 163 | response->rmcpStatusCode = |
| 164 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_ROLE_PRIV); |
| 165 | return outPayload; |
Richard Marian Thomaiyar | d5a4f45 | 2019-01-16 12:15:44 +0530 | [diff] [blame] | 166 | } |
jayaprakash Mutyala | 2555e2e | 2019-12-24 22:51:46 +0000 | [diff] [blame] | 167 | session->currentPrivilege(static_cast<uint8_t>(session::Privilege::USER)); |
| 168 | |
Tom Joseph | 4021b1f | 2019-02-12 10:10:12 +0530 | [diff] [blame] | 169 | session->reqMaxPrivLevel = |
| 170 | static_cast<session::Privilege>(request->req_max_privilege_level); |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 171 | if (request->user_name_len == 0) |
Richard Marian Thomaiyar | 127748a | 2018-09-06 07:08:51 +0530 | [diff] [blame] | 172 | { |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 173 | // Bail out, if user name is not specified. |
| 174 | // Yes, NULL user name is not supported for security reasons. |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 175 | response->rmcpStatusCode = |
| 176 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 177 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 178 | return outPayload; |
Richard Marian Thomaiyar | d2563c5 | 2018-11-29 11:49:10 +0530 | [diff] [blame] | 179 | } |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 180 | |
| 181 | // Perform user name based lookup |
| 182 | std::string userName(request->user_name, request->user_name_len); |
Jayaprakash Mutyala | 05c1447 | 2020-10-19 10:26:24 +0000 | [diff] [blame] | 183 | ipmi::SecureString passwd; |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 184 | uint8_t userId = ipmi::ipmiUserGetUserId(userName); |
| 185 | if (userId == ipmi::invalidUserId) |
| 186 | { |
| 187 | response->rmcpStatusCode = |
| 188 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 189 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 190 | return outPayload; |
| 191 | } |
| 192 | // check user is enabled before proceeding. |
| 193 | bool userEnabled = false; |
| 194 | ipmi::ipmiUserCheckEnabled(userId, userEnabled); |
| 195 | if (!userEnabled) |
| 196 | { |
| 197 | response->rmcpStatusCode = |
| 198 | static_cast<uint8_t>(RAKP_ReturnCode::INACTIVE_ROLE); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 199 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 200 | return outPayload; |
| 201 | } |
Richard Marian Thomaiyar | 4c4694e | 2019-06-20 16:36:49 +0530 | [diff] [blame] | 202 | // Get the user password for RAKP message authenticate |
| 203 | passwd = ipmi::ipmiUserGetPassword(userName); |
| 204 | if (passwd.empty()) |
| 205 | { |
| 206 | response->rmcpStatusCode = |
| 207 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 208 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 4c4694e | 2019-06-20 16:36:49 +0530 | [diff] [blame] | 209 | return outPayload; |
| 210 | } |
Ayushi Smriti | b31e969 | 2019-05-15 12:06:51 +0000 | [diff] [blame] | 211 | // Check whether user is already locked for failed attempts |
| 212 | if (!ipmi::ipmiUserPamAuthenticate(userName, passwd)) |
| 213 | { |
| 214 | log<level::ERR>("Authentication failed - user already locked out", |
| 215 | entry("USER-ID=%d", static_cast<uint8_t>(userId))); |
| 216 | |
| 217 | response->rmcpStatusCode = |
| 218 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 219 | logInvalidLoginRedfishEvent(message); |
Ayushi Smriti | b31e969 | 2019-05-15 12:06:51 +0000 | [diff] [blame] | 220 | return outPayload; |
| 221 | } |
Saravanan Palanisamy | d9c86bb | 2019-08-07 17:57:37 +0000 | [diff] [blame] | 222 | |
| 223 | uint8_t chNum = static_cast<uint8_t>(getInterfaceIndex()); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 224 | // Get channel based access information |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 225 | if ((ipmi::ipmiUserGetPrivilegeAccess( |
| 226 | userId, chNum, session->sessionUserPrivAccess) != IPMI_CC_OK) || |
| 227 | (ipmi::getChannelAccessData(chNum, session->sessionChannelAccess) != |
| 228 | IPMI_CC_OK)) |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 229 | { |
| 230 | response->rmcpStatusCode = |
| 231 | static_cast<uint8_t>(RAKP_ReturnCode::INACTIVE_ROLE); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 232 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 233 | return outPayload; |
| 234 | } |
AppaRao Puli | ecb32fb | 2020-07-01 22:55:38 +0530 | [diff] [blame] | 235 | if (!isChannelAccessModeEnabled(session->sessionChannelAccess.accessMode)) |
| 236 | { |
| 237 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 238 | "Channel access mode disabled."); |
| 239 | response->rmcpStatusCode = |
| 240 | static_cast<uint8_t>(RAKP_ReturnCode::INACTIVE_ROLE); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 241 | logInvalidLoginRedfishEvent(message); |
AppaRao Puli | ecb32fb | 2020-07-01 22:55:38 +0530 | [diff] [blame] | 242 | return outPayload; |
| 243 | } |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 244 | if (session->sessionUserPrivAccess.privilege > |
| 245 | static_cast<uint8_t>(session::Privilege::OEM)) |
Richard Marian Thomaiyar | 7e5d38d | 2019-03-02 22:11:41 +0530 | [diff] [blame] | 246 | { |
| 247 | response->rmcpStatusCode = |
| 248 | static_cast<uint8_t>(RAKP_ReturnCode::INACTIVE_ROLE); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 249 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | 7e5d38d | 2019-03-02 22:11:41 +0530 | [diff] [blame] | 250 | return outPayload; |
| 251 | } |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 252 | session->channelNum(chNum); |
| 253 | session->userID(userId); |
jayaprakash Mutyala | 2555e2e | 2019-12-24 22:51:46 +0000 | [diff] [blame] | 254 | // minimum privilege of Channel / User / session::privilege::USER |
Richard Marian Thomaiyar | d5a4f45 | 2019-01-16 12:15:44 +0530 | [diff] [blame] | 255 | // has to be used as session current privilege level |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 256 | uint8_t minPriv = 0; |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 257 | if (session->sessionChannelAccess.privLimit < |
| 258 | session->sessionUserPrivAccess.privilege) |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 259 | { |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 260 | minPriv = session->sessionChannelAccess.privLimit; |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 261 | } |
| 262 | else |
| 263 | { |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 264 | minPriv = session->sessionUserPrivAccess.privilege; |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 265 | } |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 266 | if (session->currentPrivilege() > minPriv) |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 267 | { |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 268 | session->currentPrivilege(static_cast<uint8_t>(minPriv)); |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 269 | } |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 270 | // For username / privilege lookup, fail with UNAUTH_NAME, if requested |
Richard Marian Thomaiyar | d8e92fe | 2019-01-16 11:56:23 +0530 | [diff] [blame] | 271 | // max privilege does not match user privilege |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 272 | if (((request->req_max_privilege_level & userNameOnlyLookupMask) == |
| 273 | userNamePrivLookup) && |
Richard Marian Thomaiyar | d8e92fe | 2019-01-16 11:56:23 +0530 | [diff] [blame] | 274 | ((request->req_max_privilege_level & session::reqMaxPrivMask) != |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 275 | session->sessionUserPrivAccess.privilege)) |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 276 | { |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 277 | log<level::INFO>( |
| 278 | "Username/Privilege lookup failed for requested privilege"); |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 279 | response->rmcpStatusCode = |
| 280 | static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME); |
sunitakx | 0e0546f | 2021-06-15 08:57:10 +0000 | [diff] [blame] | 281 | |
| 282 | logInvalidLoginRedfishEvent(message); |
Richard Marian Thomaiyar | d91fd9d | 2018-12-06 12:03:50 +0530 | [diff] [blame] | 283 | return outPayload; |
| 284 | } |
Richard Marian Thomaiyar | 99b8784 | 2018-12-06 21:35:43 +0530 | [diff] [blame] | 285 | |
| 286 | std::fill(authAlgo->userKey.data(), |
| 287 | authAlgo->userKey.data() + authAlgo->userKey.size(), 0); |
| 288 | std::copy_n(passwd.c_str(), passwd.size(), authAlgo->userKey.data()); |
| 289 | |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 290 | // Copy the Managed System Random Number to the Authentication Algorithm |
| 291 | std::copy_n(iter, cipher::rakp_auth::BMC_RANDOM_NUMBER_LEN, |
| 292 | authAlgo->bmcRandomNum.begin()); |
| 293 | std::advance(iter, cipher::rakp_auth::BMC_RANDOM_NUMBER_LEN); |
| 294 | |
| 295 | // Managed System GUID |
Tom Joseph | 83029cb | 2017-09-01 16:37:31 +0530 | [diff] [blame] | 296 | std::copy_n(cache::guid.data(), cache::guid.size(), iter); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 297 | std::advance(iter, BMC_GUID_LEN); |
| 298 | |
| 299 | // Requested Privilege Level |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 300 | std::copy_n(&(request->req_max_privilege_level), |
| 301 | sizeof(request->req_max_privilege_level), iter); |
| 302 | std::advance(iter, sizeof(request->req_max_privilege_level)); |
| 303 | |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 304 | // User Name Length Byte |
| 305 | std::copy_n(&(request->user_name_len), sizeof(request->user_name_len), |
| 306 | iter); |
Tom Joseph | 56527b9 | 2018-03-21 19:31:58 +0530 | [diff] [blame] | 307 | std::advance(iter, sizeof(request->user_name_len)); |
| 308 | |
| 309 | std::copy_n(session->userName.data(), session->userName.size(), iter); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 310 | |
| 311 | // Generate Key Exchange Authentication Code - RAKP2 |
| 312 | auto output = authAlgo->generateHMAC(input); |
| 313 | |
| 314 | response->messageTag = request->messageTag; |
| 315 | response->rmcpStatusCode = static_cast<uint8_t>(RAKP_ReturnCode::NO_ERROR); |
| 316 | response->reserved = 0; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 317 | response->remoteConsoleSessionID = rcSessionID; |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 318 | |
| 319 | // Copy Managed System Random Number to the Response |
| 320 | std::copy(authAlgo->bmcRandomNum.begin(), authAlgo->bmcRandomNum.end(), |
| 321 | response->managed_system_random_number); |
| 322 | |
| 323 | // Copy System GUID to the Response |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 324 | std::copy_n(cache::guid.data(), cache::guid.size(), |
Tom Joseph | 83029cb | 2017-09-01 16:37:31 +0530 | [diff] [blame] | 325 | response->managed_system_guid); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 326 | |
| 327 | // Insert the HMAC output into the payload |
| 328 | outPayload.insert(outPayload.end(), output.begin(), output.end()); |
Tom Joseph | 8bb10b7 | 2016-12-06 17:47:56 +0530 | [diff] [blame] | 329 | return outPayload; |
| 330 | } |
| 331 | |
| 332 | } // namespace command |