Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development/websocket #1796

Draft
wants to merge 83 commits into
base: master
Choose a base branch
from
Draft

Development/websocket #1796

wants to merge 83 commits into from

Conversation

msieben
Copy link
Contributor

@msieben msieben commented Nov 22, 2024

No description provided.

msieben and others added 22 commits November 6, 2024 15:23
…m item

- Rename 'WEBSERVER' to 'WEBSERVICE' as both client and server utilize state information

- Unsollicited 'Pong' may act as a heart beat
…ructure are not yet contructed, and, improve SSL read and write use

- SSL read and write methods should only be used if the handshake is successfull

- Do not return error values for SSL read and write methods as number of read or written bytes
…en opened but context has not been contructed.
…arily) propagate to SSL structure after construction.

- Context should exist

- Options should be set
…ocket/WebSocketLink] : cherry pick from 'master'
Context settings do not (necessarily) propagate to the SSL structure
…SL read and write

Only read or written bytes have values >= 0, otherwise it indicates an error and does not reflect the actual amount
@@ -72,19 +72,26 @@ namespace Crypto {
};

public:
// Type of underlying socket
Copy link
Contributor

@pwielders pwielders Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enum, together with the enum class context_t split up into server and client do not add any functionality. They are currently used to "determine" the initial state of the _handshaking in the handler but the handler, in the initialize will override the set state, by definition, through the IsOpen() state, which indeed is the only valid way to determine if you are a server, so why all this additional code?
I suggest setting the initial state at ERROR and if during normal runtime you use this state and it is still ERROR, assert where you would not expect it..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good observation. It was not the intended goal to have it overwritten.

, _handShaking(CONNECTING) {
}
, _handShaking(type == sockettype_t::CLIENT_SOCKET ? CONNECTING : ACCEPTING)
, _type{type}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the sockettype_t type -> _type is not used anwhere, just drop it, it just confuses..

: Core::SocketPort(args...)
, _parent(parent)
, _context(nullptr)
, _ssl(nullptr)
, _callback(nullptr)
, _handShaking(CONNECTING) {
}
, _handShaking(type == sockettype_t::CLIENT_SOCKET ? CONNECTING : ACCEPTING)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_handShaking is properly initialized during the Initialize() call t CONNECTING or ACCEPTING, based on the state of the socket if it is being called. Suggest to set it to ERROR here to assert in the INITIALIZE if, for example, it does not have this vale if we "Initialize()". Making sure the Initialize is called only once..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not the intended goal as mentioned here #1796 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the state of the socket as in open or closed. The intent is to differentiate between and identify the owner of the socket: a server using the accept method to construct it, or, a client that creates it to connect to a server, Handler::ACCEPTING, Handler::CONNECTING respectively.

CLIENT_SOCKET
, SERVER_SOCKET
};

Handler(Handler&&) = delete;
Handler(const Handler&) = delete;
Handler& operator=(const Handler&) = delete;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the:
Handler& operator=(Handler&&) = delete;
for upgrading code we should add it now...

@@ -107,6 +114,7 @@ namespace Crypto {

// Signal a state change, Opened, Closed or Accepted
void StateChange() override {
// ASSERT(_context != nullptr && _ssl != nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that this ASSERT fires... Maybe during the Close Sequence? Please investigate and remove the assert or make sure that under normal conditions it does not fire (IsClosed() == false) || ((_context != nullptr) && (_ssl != nullptr)));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting. In a previous draft PR you did not wanted such solution but promoted the use of ASSERT. Update() already includes a check and ASSERT.

@@ -135,17 +143,31 @@ namespace Crypto {
void* _ssl;
IValidator* _callback;
mutable state _handShaking;
const sockettype_t _type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As described above, I think we can drop this..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? _handShaking is initially used to identify the server or client side of the connection, but will loose that information once connected or in error.

@msieben msieben requested a review from rdkcmf-jenkins January 7, 2025 10:47

uint32_t result = SSL_write(_ssl, buffer, length);
ASSERT( !IsNarrowing(std::numeric_limits<uint32_t>::max(), std::numeric_limits<time_t>::max())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Operands don't affect result

"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical second operand of "&&".

Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT

if (_handShaking != OPEN) {
Update();
}
ASSERT( !IsNarrowing(std::numeric_limits<uint32_t>::max(), std::numeric_limits<suseconds_t>::max())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Operands don't affect result

"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical second operand of "&&".

Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT

@msieben msieben force-pushed the development/websocket branch from ad058f5 to 1e7c32b Compare January 7, 2025 13:02
using common_time_t VARIABLE_IS_NOT_USED = std::common_type<time_t, uint32_t>::type;
using common_seconds_t VARIABLE_IS_NOT_USED = std::common_type<suseconds_t, uint32_t>::type;

ASSERT(static_cast<common_time_t>(std::numeric_limits<time_t>::max()) >= static_cast<common_time_t>(waitTime));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Operands don't affect result

"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical operand of "!".

Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT

using common_seconds_t VARIABLE_IS_NOT_USED = std::common_type<suseconds_t, uint32_t>::type;

ASSERT(static_cast<common_time_t>(std::numeric_limits<time_t>::max()) >= static_cast<common_time_t>(waitTime));
ASSERT(static_cast<common_time_t>(std::numeric_limits<suseconds_t>::max()) >= static_cast<common_time_t>(waitTime));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Operands don't affect result

"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical operand of "!".

Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT

@msieben msieben force-pushed the development/websocket branch 2 times, most recently from 150d47d to 8d44d48 Compare January 7, 2025 13:42
if (_handShaking != OPEN) {
Update();
}
ASSERT( !IsNarrowing(std::numeric_limits<uint32_t>::max(), std::numeric_limits<suseconds_t>::max())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Operands don't affect result

"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical second operand of "&&".

Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT

@msieben msieben force-pushed the development/websocket branch 2 times, most recently from 20cea57 to 52f07c9 Compare January 7, 2025 14:36
@msieben msieben requested a review from rdkcmf-jenkins January 7, 2025 14:50

uint32_t result = SSL_write(_ssl, buffer, length);
ASSERT( !IsNarrowing(std::numeric_limits<uint32_t>::max(), std::numeric_limits<time_t>::max())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Operands don't affect result

"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical second operand of "&&".

Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT

if (_handShaking != OPEN) {
Update();
}
ASSERT( !IsNarrowing(std::numeric_limits<uint32_t>::max(), std::numeric_limits<suseconds_t>::max())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Operands don't affect result

"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical second operand of "&&".

Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT

@msieben msieben force-pushed the development/websocket branch from 52f07c9 to 2f2be2d Compare January 7, 2025 15:20
… (compile-time) between 'client' and 'server' type sockets

Compile-time differentiation allows for use case available signatures
return 0; // 0 - Failurre, 1 - OK
}

template <typename TYPE = std::false_type>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity Issue - Parse recovery warning

a default template argument cannot be specified on the definition of a member of a class template outside the template

Low Impact, CWE-none
RW.DEFAULT_ARG_ON_MEMBER_DECL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants