blob: 5bfdce094a417cc3fb4ccc73f50adb6664819f3b [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
Jason M. Bills46bec0f2019-12-11 11:01:18 -080023 // Per the IPMI Spec, messageTag and remoteConsoleSessionID are always
24 // returned
25 response->messageTag = request->messageTag;
26 response->remoteConsoleSessionID = request->remoteConsoleSessionID;
27
Tom Joseph8e832ee2016-12-06 17:47:08 +053028 // Check for valid Authentication Algorithms
Vernon Mauery9b307be2017-11-22 09:28:16 -080029 if (!cipher::rakp_auth::Interface::isAlgorithmSupported(
Vernon Mauery9e801a22018-10-12 13:20:49 -070030 static_cast<cipher::rakp_auth::Algorithms>(request->authAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053031 {
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 Mauery9b307be2017-11-22 09:28:16 -080038 if (!cipher::integrity::Interface::isAlgorithmSupported(
Vernon Mauery9e801a22018-10-12 13:20:49 -070039 static_cast<cipher::integrity::Algorithms>(request->intAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053040 {
41 response->status_code =
42 static_cast<uint8_t>(RAKP_ReturnCode::INVALID_INTEGRITY_ALGO);
43 return outPayload;
44 }
45
Tom Joseph4021b1f2019-02-12 10:10:12 +053046 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 Joseph8e832ee2016-12-06 17:47:08 +053062 // Check for valid Confidentiality Algorithms
Vernon Mauery9e801a22018-10-12 13:20:49 -070063 if (!cipher::crypt::Interface::isAlgorithmSupported(
64 static_cast<cipher::crypt::Algorithms>(request->confAlgo)))
Tom Joseph8e832ee2016-12-06 17:47:08 +053065 {
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 Mauery9e801a22018-10-12 13:20:49 -070075 session =
Vernon Maueryae1fda42018-10-15 12:55:34 -070076 std::get<session::Manager&>(singletonPool)
77 .startSession(
Tom Joseph4021b1f2019-02-12 10:10:12 +053078 endian::from_ipmi<>(request->remoteConsoleSessionID), priv,
Vernon Maueryae1fda42018-10-15 12:55:34 -070079 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 Joseph8e832ee2016-12-06 17:47:08 +053084 }
85 catch (std::exception& e)
86 {
Vernon Mauery9e801a22018-10-12 13:20:49 -070087 response->status_code =
88 static_cast<uint8_t>(RAKP_ReturnCode::INSUFFICIENT_RESOURCE);
Vernon Maueryfc37e592018-12-19 14:55:15 -080089 log<level::ERR>("openSession : Problem opening a session",
90 entry("EXCEPTION=%s", e.what()));
Tom Joseph8e832ee2016-12-06 17:47:08 +053091 return outPayload;
92 }
93
Tom Joseph8e832ee2016-12-06 17:47:08 +053094 response->status_code = static_cast<uint8_t>(RAKP_ReturnCode::NO_ERROR);
Tom Joseph4021b1f2019-02-12 10:10:12 +053095 response->maxPrivLevel = static_cast<uint8_t>(session->reqMaxPrivLevel);
Vernon Mauery9e801a22018-10-12 13:20:49 -070096 response->managedSystemSessionID =
97 endian::to_ipmi<>(session->getBMCSessionID());
Tom Joseph8e832ee2016-12-06 17:47:08 +053098
Vernon Mauery9e801a22018-10-12 13:20:49 -070099 response->authPayload = request->authPayload;
100 response->authPayloadLen = request->authPayloadLen;
Tom Joseph8e832ee2016-12-06 17:47:08 +0530101 response->authAlgo = request->authAlgo;
102
Vernon Mauery9e801a22018-10-12 13:20:49 -0700103 response->intPayload = request->intPayload;
104 response->intPayloadLen = request->intPayloadLen;
Tom Joseph8e832ee2016-12-06 17:47:08 +0530105 response->intAlgo = request->intAlgo;
106
Vernon Mauery9e801a22018-10-12 13:20:49 -0700107 response->confPayload = request->confPayload;
108 response->confPayloadLen = request->confPayloadLen;
Tom Joseph8e832ee2016-12-06 17:47:08 +0530109 response->confAlgo = request->confAlgo;
110
111 session->updateLastTransactionTime();
112
113 // Session state is Setup in progress
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +0530114 session->state(static_cast<uint8_t>(session::State::setupInProgress));
Tom Joseph8e832ee2016-12-06 17:47:08 +0530115 return outPayload;
116}
117
118} // namespace command