blob: 78fb9d0b6b46140799cad6966c261142656724c0 [file] [log] [blame]
Tom Joseph8e832ee2016-12-06 17:47:08 +05301#include "open_session.hpp"
2
Tom Joseph8e832ee2016-12-06 17:47:08 +05303#include "comm_module.hpp"
4#include "endian.hpp"
5#include "main.hpp"
6
Vernon Maueryfc37e592018-12-19 14:55:15 -08007#include <phosphor-logging/log.hpp>
8
9using namespace phosphor::logging;
Vernon Mauery9e801a22018-10-12 13:20:49 -070010
Tom Joseph8e832ee2016-12-06 17:47:08 +053011namespace command
12{
13
Tom Joseph18a45e92017-04-11 11:30:44 +053014std::vector<uint8_t> openSession(const std::vector<uint8_t>& inPayload,
Tom Joseph8e832ee2016-12-06 17:47:08 +053015 const message::Handler& handler)
16{
Tom Joseph8e832ee2016-12-06 17:47:08 +053017
18 std::vector<uint8_t> outPayload(sizeof(OpenSessionResponse));
Vernon Mauery9e801a22018-10-12 13:20:49 -070019 auto request =
20 reinterpret_cast<const OpenSessionRequest*>(inPayload.data());
Tom Joseph8e832ee2016-12-06 17:47:08 +053021 auto response = reinterpret_cast<OpenSessionResponse*>(outPayload.data());
22
23 // Check for valid Authentication Algorithms
Vernon Mauery9b307be2017-11-22 09:28:16 -080024 if (!cipher::rakp_auth::Interface::isAlgorithmSupported(
Vernon Mauery9e801a22018-10-12 13:20:49 -070025 static_cast<cipher::rakp_auth::Algorithms>(request->authAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053026 {
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
Vernon Mauery9b307be2017-11-22 09:28:16 -080033 if (!cipher::integrity::Interface::isAlgorithmSupported(
Vernon Mauery9e801a22018-10-12 13:20:49 -070034 static_cast<cipher::integrity::Algorithms>(request->intAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053035 {
36 response->status_code =
37 static_cast<uint8_t>(RAKP_ReturnCode::INVALID_INTEGRITY_ALGO);
38 return outPayload;
39 }
40
Tom Joseph4021b1f2019-02-12 10:10:12 +053041 session::Privilege priv;
42
43 // 0h in the requested maximum privilege role field indicates highest level
44 // matching proposed algorithms. The maximum privilege level the session
45 // can take is set to Administrator level. In the RAKP12 command sequence
46 // the session maximum privilege role is set again based on the user's
47 // permitted privilege level.
48 if (!request->maxPrivLevel)
49 {
50 priv = session::Privilege::ADMIN;
51 }
52 else
53 {
54 priv = static_cast<session::Privilege>(request->maxPrivLevel);
55 }
56
Tom Joseph8e832ee2016-12-06 17:47:08 +053057 // Check for valid Confidentiality Algorithms
Vernon Mauery9e801a22018-10-12 13:20:49 -070058 if (!cipher::crypt::Interface::isAlgorithmSupported(
59 static_cast<cipher::crypt::Algorithms>(request->confAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053060 {
61 response->status_code =
62 static_cast<uint8_t>(RAKP_ReturnCode::INVALID_CONF_ALGO);
63 return outPayload;
64 }
65
66 std::shared_ptr<session::Session> session;
67 try
68 {
69 // Start an IPMI session
Vernon Mauery9e801a22018-10-12 13:20:49 -070070 session =
Vernon Maueryae1fda42018-10-15 12:55:34 -070071 std::get<session::Manager&>(singletonPool)
72 .startSession(
Tom Joseph4021b1f2019-02-12 10:10:12 +053073 endian::from_ipmi<>(request->remoteConsoleSessionID), priv,
Vernon Maueryae1fda42018-10-15 12:55:34 -070074 static_cast<cipher::rakp_auth::Algorithms>(
75 request->authAlgo),
76 static_cast<cipher::integrity::Algorithms>(
77 request->intAlgo),
78 static_cast<cipher::crypt::Algorithms>(request->confAlgo));
Tom Joseph8e832ee2016-12-06 17:47:08 +053079 }
80 catch (std::exception& e)
81 {
Vernon Mauery9e801a22018-10-12 13:20:49 -070082 response->status_code =
83 static_cast<uint8_t>(RAKP_ReturnCode::INSUFFICIENT_RESOURCE);
Vernon Maueryfc37e592018-12-19 14:55:15 -080084 log<level::ERR>("openSession : Problem opening a session",
85 entry("EXCEPTION=%s", e.what()));
Tom Joseph8e832ee2016-12-06 17:47:08 +053086 return outPayload;
87 }
88
89 response->messageTag = request->messageTag;
90 response->status_code = static_cast<uint8_t>(RAKP_ReturnCode::NO_ERROR);
Tom Joseph4021b1f2019-02-12 10:10:12 +053091 response->maxPrivLevel = static_cast<uint8_t>(session->reqMaxPrivLevel);
Tom Joseph8e832ee2016-12-06 17:47:08 +053092 response->remoteConsoleSessionID = request->remoteConsoleSessionID;
Vernon Mauery9e801a22018-10-12 13:20:49 -070093 response->managedSystemSessionID =
94 endian::to_ipmi<>(session->getBMCSessionID());
Tom Joseph8e832ee2016-12-06 17:47:08 +053095
Vernon Mauery9e801a22018-10-12 13:20:49 -070096 response->authPayload = request->authPayload;
97 response->authPayloadLen = request->authPayloadLen;
Tom Joseph8e832ee2016-12-06 17:47:08 +053098 response->authAlgo = request->authAlgo;
99
Vernon Mauery9e801a22018-10-12 13:20:49 -0700100 response->intPayload = request->intPayload;
101 response->intPayloadLen = request->intPayloadLen;
Tom Joseph8e832ee2016-12-06 17:47:08 +0530102 response->intAlgo = request->intAlgo;
103
Vernon Mauery9e801a22018-10-12 13:20:49 -0700104 response->confPayload = request->confPayload;
105 response->confPayloadLen = request->confPayloadLen;
Tom Joseph8e832ee2016-12-06 17:47:08 +0530106 response->confAlgo = request->confAlgo;
107
108 session->updateLastTransactionTime();
109
110 // Session state is Setup in progress
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +0530111 session->state(static_cast<uint8_t>(session::State::setupInProgress));
Tom Joseph8e832ee2016-12-06 17:47:08 +0530112 return outPayload;
113}
114
115} // namespace command