blob: 2eb273f1ab5408f875112becf7fab956d071f9b6 [file] [log] [blame]
Tom Joseph8e832ee2016-12-06 17:47:08 +05301#include "open_session.hpp"
2
3#include <iostream>
4
5#include "comm_module.hpp"
6#include "endian.hpp"
7#include "main.hpp"
8
9namespace command
10{
11
12std::vector<uint8_t> openSession(std::vector<uint8_t>& inPayload,
13 const message::Handler& handler)
14{
15 std::cout << ">> openSession\n";
16
17 std::vector<uint8_t> outPayload(sizeof(OpenSessionResponse));
18 auto request = reinterpret_cast<OpenSessionRequest*>(inPayload.data());
19 auto response = reinterpret_cast<OpenSessionResponse*>(outPayload.data());
20
21 // Check for valid Authentication Algorithms
22 if (request->authAlgo != static_cast<uint8_t>
23 (cipher::rakp_auth::Algorithms::RAKP_HMAC_SHA1))
24 {
25 response->status_code =
26 static_cast<uint8_t>(RAKP_ReturnCode::INVALID_AUTH_ALGO);
27 return outPayload;
28 }
29
30 // Check for valid Integrity Algorithms
Tom Joseph7949afc2017-01-10 16:38:32 +053031 if ((request->intAlgo !=
32 static_cast<uint8_t>(cipher::integrity::Algorithms::NONE)) &&
33 (request->intAlgo !=
34 static_cast<uint8_t>(cipher::integrity::Algorithms::HMAC_SHA1_96)))
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
41 // Check for valid Confidentiality Algorithms
42 if (request->confAlgo != 0)
43 {
44 response->status_code =
45 static_cast<uint8_t>(RAKP_ReturnCode::INVALID_CONF_ALGO);
46 return outPayload;
47 }
48
49 std::shared_ptr<session::Session> session;
50 try
51 {
52 // Start an IPMI session
53 session = (std::get<session::Manager&>(singletonPool).startSession(
54 endian::from_ipmi<>(request->remoteConsoleSessionID),
55 static_cast<session::Privilege>(request->maxPrivLevel),
Tom Joseph7949afc2017-01-10 16:38:32 +053056 static_cast<cipher::rakp_auth::Algorithms>(request->authAlgo),
Tom Josephba11f792017-01-24 18:21:45 +053057 static_cast<cipher::integrity::Algorithms>(request->intAlgo),
58 static_cast<cipher::crypt::Algorithms>(request->confAlgo)
Tom Joseph8e832ee2016-12-06 17:47:08 +053059 )).lock();
60 }
61 catch (std::exception& e)
62 {
63 std::cerr << e.what() << "\n";
64 response->status_code = static_cast<uint8_t>
65 (RAKP_ReturnCode::INSUFFICIENT_RESOURCE);
66 std::cerr << "openSession : Problem opening a session\n";
67 return outPayload;
68 }
69
70 response->messageTag = request->messageTag;
71 response->status_code = static_cast<uint8_t>(RAKP_ReturnCode::NO_ERROR);
72 response->maxPrivLevel = static_cast<uint8_t>(session->curPrivLevel);
73 response->remoteConsoleSessionID = request->remoteConsoleSessionID;
74 response->managedSystemSessionID = endian::to_ipmi<>
75 (session->getBMCSessionID());
76
77 response->authPayload = request->authPayload ;
78 response->authPayloadLen = request->authPayloadLen ;
79 response->authAlgo = request->authAlgo;
80
81 response->intPayload = request->intPayload ;
82 response->intPayloadLen = request->intPayloadLen ;
83 response->intAlgo = request->intAlgo;
84
85 response->confPayload = request->confPayload ;
86 response->confPayloadLen = request->confPayloadLen ;
87 response->confAlgo = request->confAlgo;
88
89 session->updateLastTransactionTime();
90
91 // Session state is Setup in progress
92 session->state = session::State::SETUP_IN_PROGRESS;
93
94 std::cout << "<< openSession\n";
95 return outPayload;
96}
97
98} // namespace command