1 #include "open_session.hpp" 2 3 #include "comm_module.hpp" 4 #include "endian.hpp" 5 #include "main.hpp" 6 7 #include <phosphor-logging/log.hpp> 8 9 using namespace phosphor::logging; 10 11 namespace command 12 { 13 14 std::vector<uint8_t> openSession(const std::vector<uint8_t>& inPayload, 15 const message::Handler& handler) 16 { 17 18 std::vector<uint8_t> outPayload(sizeof(OpenSessionResponse)); 19 auto request = 20 reinterpret_cast<const OpenSessionRequest*>(inPayload.data()); 21 auto response = reinterpret_cast<OpenSessionResponse*>(outPayload.data()); 22 23 // Check for valid Authentication Algorithms 24 if (!cipher::rakp_auth::Interface::isAlgorithmSupported( 25 static_cast<cipher::rakp_auth::Algorithms>(request->authAlgo))) 26 { 27 response->status_code = 28 static_cast<uint8_t>(RAKP_ReturnCode::INVALID_AUTH_ALGO); 29 return outPayload; 30 } 31 32 // Check for valid Integrity Algorithms 33 if (!cipher::integrity::Interface::isAlgorithmSupported( 34 static_cast<cipher::integrity::Algorithms>(request->intAlgo))) 35 { 36 response->status_code = 37 static_cast<uint8_t>(RAKP_ReturnCode::INVALID_INTEGRITY_ALGO); 38 return outPayload; 39 } 40 41 // Check for valid Confidentiality Algorithms 42 if (!cipher::crypt::Interface::isAlgorithmSupported( 43 static_cast<cipher::crypt::Algorithms>(request->confAlgo))) 44 { 45 response->status_code = 46 static_cast<uint8_t>(RAKP_ReturnCode::INVALID_CONF_ALGO); 47 return outPayload; 48 } 49 50 std::shared_ptr<session::Session> session; 51 try 52 { 53 // Start an IPMI session 54 session = 55 std::get<session::Manager&>(singletonPool) 56 .startSession( 57 endian::from_ipmi<>(request->remoteConsoleSessionID), 58 static_cast<session::Privilege>(request->maxPrivLevel), 59 static_cast<cipher::rakp_auth::Algorithms>( 60 request->authAlgo), 61 static_cast<cipher::integrity::Algorithms>( 62 request->intAlgo), 63 static_cast<cipher::crypt::Algorithms>(request->confAlgo)); 64 } 65 catch (std::exception& e) 66 { 67 response->status_code = 68 static_cast<uint8_t>(RAKP_ReturnCode::INSUFFICIENT_RESOURCE); 69 log<level::ERR>("openSession : Problem opening a session", 70 entry("EXCEPTION=%s", e.what())); 71 return outPayload; 72 } 73 74 response->messageTag = request->messageTag; 75 response->status_code = static_cast<uint8_t>(RAKP_ReturnCode::NO_ERROR); 76 response->maxPrivLevel = static_cast<uint8_t>(session->curPrivLevel); 77 response->remoteConsoleSessionID = request->remoteConsoleSessionID; 78 response->managedSystemSessionID = 79 endian::to_ipmi<>(session->getBMCSessionID()); 80 81 response->authPayload = request->authPayload; 82 response->authPayloadLen = request->authPayloadLen; 83 response->authAlgo = request->authAlgo; 84 85 response->intPayload = request->intPayload; 86 response->intPayloadLen = request->intPayloadLen; 87 response->intAlgo = request->intAlgo; 88 89 response->confPayload = request->confPayload; 90 response->confPayloadLen = request->confPayloadLen; 91 response->confAlgo = request->confAlgo; 92 93 session->updateLastTransactionTime(); 94 95 // Session state is Setup in progress 96 session->state = session::State::SETUP_IN_PROGRESS; 97 return outPayload; 98 } 99 100 } // namespace command 101