Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 1 | #include "open_session.hpp" |
| 2 | |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 3 | #include "comm_module.hpp" |
| 4 | #include "endian.hpp" |
| 5 | #include "main.hpp" |
| 6 | |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 7 | #include <phosphor-logging/log.hpp> |
| 8 | |
| 9 | using namespace phosphor::logging; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 10 | |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 11 | namespace command |
| 12 | { |
| 13 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 14 | std::vector<uint8_t> openSession(const std::vector<uint8_t>& inPayload, |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 15 | const message::Handler& handler) |
| 16 | { |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 17 | |
| 18 | std::vector<uint8_t> outPayload(sizeof(OpenSessionResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 19 | auto request = |
| 20 | reinterpret_cast<const OpenSessionRequest*>(inPayload.data()); |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 21 | auto response = reinterpret_cast<OpenSessionResponse*>(outPayload.data()); |
| 22 | |
Jason M. Bills | 46bec0f | 2019-12-11 11:01:18 -0800 | [diff] [blame^] | 23 | // Per the IPMI Spec, messageTag and remoteConsoleSessionID are always |
| 24 | // returned |
| 25 | response->messageTag = request->messageTag; |
| 26 | response->remoteConsoleSessionID = request->remoteConsoleSessionID; |
| 27 | |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 28 | // Check for valid Authentication Algorithms |
Vernon Mauery | 9b307be | 2017-11-22 09:28:16 -0800 | [diff] [blame] | 29 | if (!cipher::rakp_auth::Interface::isAlgorithmSupported( |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 30 | static_cast<cipher::rakp_auth::Algorithms>(request->authAlgo))) |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 31 | { |
| 32 | response->status_code = |
| 33 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_AUTH_ALGO); |
| 34 | return outPayload; |
| 35 | } |
| 36 | |
| 37 | // Check for valid Integrity Algorithms |
Vernon Mauery | 9b307be | 2017-11-22 09:28:16 -0800 | [diff] [blame] | 38 | if (!cipher::integrity::Interface::isAlgorithmSupported( |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 39 | static_cast<cipher::integrity::Algorithms>(request->intAlgo))) |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 40 | { |
| 41 | response->status_code = |
| 42 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_INTEGRITY_ALGO); |
| 43 | return outPayload; |
| 44 | } |
| 45 | |
Tom Joseph | 4021b1f | 2019-02-12 10:10:12 +0530 | [diff] [blame] | 46 | session::Privilege priv; |
| 47 | |
| 48 | // 0h in the requested maximum privilege role field indicates highest level |
| 49 | // matching proposed algorithms. The maximum privilege level the session |
| 50 | // can take is set to Administrator level. In the RAKP12 command sequence |
| 51 | // the session maximum privilege role is set again based on the user's |
| 52 | // permitted privilege level. |
| 53 | if (!request->maxPrivLevel) |
| 54 | { |
| 55 | priv = session::Privilege::ADMIN; |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | priv = static_cast<session::Privilege>(request->maxPrivLevel); |
| 60 | } |
| 61 | |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 62 | // Check for valid Confidentiality Algorithms |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 63 | if (!cipher::crypt::Interface::isAlgorithmSupported( |
| 64 | static_cast<cipher::crypt::Algorithms>(request->confAlgo))) |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 65 | { |
| 66 | response->status_code = |
| 67 | static_cast<uint8_t>(RAKP_ReturnCode::INVALID_CONF_ALGO); |
| 68 | return outPayload; |
| 69 | } |
| 70 | |
| 71 | std::shared_ptr<session::Session> session; |
| 72 | try |
| 73 | { |
| 74 | // Start an IPMI session |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 75 | session = |
Vernon Mauery | ae1fda4 | 2018-10-15 12:55:34 -0700 | [diff] [blame] | 76 | std::get<session::Manager&>(singletonPool) |
| 77 | .startSession( |
Tom Joseph | 4021b1f | 2019-02-12 10:10:12 +0530 | [diff] [blame] | 78 | endian::from_ipmi<>(request->remoteConsoleSessionID), priv, |
Vernon Mauery | ae1fda4 | 2018-10-15 12:55:34 -0700 | [diff] [blame] | 79 | static_cast<cipher::rakp_auth::Algorithms>( |
| 80 | request->authAlgo), |
| 81 | static_cast<cipher::integrity::Algorithms>( |
| 82 | request->intAlgo), |
| 83 | static_cast<cipher::crypt::Algorithms>(request->confAlgo)); |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 84 | } |
| 85 | catch (std::exception& e) |
| 86 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 87 | response->status_code = |
| 88 | static_cast<uint8_t>(RAKP_ReturnCode::INSUFFICIENT_RESOURCE); |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 89 | log<level::ERR>("openSession : Problem opening a session", |
| 90 | entry("EXCEPTION=%s", e.what())); |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 91 | return outPayload; |
| 92 | } |
| 93 | |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 94 | response->status_code = static_cast<uint8_t>(RAKP_ReturnCode::NO_ERROR); |
Tom Joseph | 4021b1f | 2019-02-12 10:10:12 +0530 | [diff] [blame] | 95 | response->maxPrivLevel = static_cast<uint8_t>(session->reqMaxPrivLevel); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 96 | response->managedSystemSessionID = |
| 97 | endian::to_ipmi<>(session->getBMCSessionID()); |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 98 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 99 | response->authPayload = request->authPayload; |
| 100 | response->authPayloadLen = request->authPayloadLen; |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 101 | response->authAlgo = request->authAlgo; |
| 102 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 103 | response->intPayload = request->intPayload; |
| 104 | response->intPayloadLen = request->intPayloadLen; |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 105 | response->intAlgo = request->intAlgo; |
| 106 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 107 | response->confPayload = request->confPayload; |
| 108 | response->confPayloadLen = request->confPayloadLen; |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 109 | response->confAlgo = request->confAlgo; |
| 110 | |
| 111 | session->updateLastTransactionTime(); |
| 112 | |
| 113 | // Session state is Setup in progress |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 114 | session->state(static_cast<uint8_t>(session::State::setupInProgress)); |
Tom Joseph | 8e832ee | 2016-12-06 17:47:08 +0530 | [diff] [blame] | 115 | return outPayload; |
| 116 | } |
| 117 | |
| 118 | } // namespace command |