Skip to content

Commit

Permalink
SSL clang-tidy fixes (#3281)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone authored Dec 18, 2024
1 parent e3343a2 commit 5f38d62
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 70 deletions.
2 changes: 1 addition & 1 deletion config/Make.rules.Darwin
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mcpp_ldflags := $(MCPP_HOME)/lib/libmcpp.a
# the compiler.
cppflags = -fvisibility=hidden -Wall -Wextra -Wshadow -Wshadow-all -Wredundant-decls -Wno-shadow-field \
-Wdeprecated -Wstrict-prototypes -Werror -Wconversion -Wdocumentation -Wno-shadow-uncaptured-local \
-pthread \
-Wreorder-init-list -pthread \
$(if $(filter yes,$(OPTIMIZE)),-O2 -DNDEBUG,-g)

ifeq ($(MAXWARN),yes)
Expand Down
9 changes: 5 additions & 4 deletions cpp/src/Ice/SSL/OpenSSLEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ namespace Ice::SSL::OpenSSL

void initialize() final;
void destroy() final;
std::string sslErrors() const;
std::string password() const { return _password; }
Ice::SSL::ClientAuthenticationOptions createClientAuthenticationOptions(const std::string&) const final;
Ice::SSL::ServerAuthenticationOptions createServerAuthenticationOptions() const final;
[[nodiscard]] std::string sslErrors() const;
[[nodiscard]] std::string password() const { return _password; }
[[nodiscard]] Ice::SSL::ClientAuthenticationOptions
createClientAuthenticationOptions(const std::string&) const final;
[[nodiscard]] Ice::SSL::ServerAuthenticationOptions createServerAuthenticationOptions() const final;

private:
bool validationCallback(bool, X509_STORE_CTX*, const Ice::SSL::ConnectionInfoPtr&) const;
Expand Down
19 changes: 10 additions & 9 deletions cpp/src/Ice/SSL/OpenSSLTransceiverI.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ namespace Ice::SSL::OpenSSL
const Ice::SSL::ClientAuthenticationOptions&);

~TransceiverI();
IceInternal::NativeInfoPtr getNativeInfo() final;
[[nodiscard]] IceInternal::NativeInfoPtr getNativeInfo() final;

IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&) final;
IceInternal::SocketOperation closing(bool, std::exception_ptr) final;
[[nodiscard]] IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&) final;
[[nodiscard]] IceInternal::SocketOperation closing(bool, std::exception_ptr) final;
void close() final;
IceInternal::SocketOperation write(IceInternal::Buffer&) final;
IceInternal::SocketOperation read(IceInternal::Buffer&) final;
std::string protocol() const final;
std::string toString() const final;
std::string toDetailedString() const final;
Ice::ConnectionInfoPtr getInfo(bool incoming, std::string adapterName, std::string connectionId) const final;
[[nodiscard]] IceInternal::SocketOperation write(IceInternal::Buffer&) final;
[[nodiscard]] IceInternal::SocketOperation read(IceInternal::Buffer&) final;
[[nodiscard]] std::string protocol() const final;
[[nodiscard]] std::string toString() const final;
[[nodiscard]] std::string toDetailedString() const final;
[[nodiscard]] Ice::ConnectionInfoPtr
getInfo(bool incoming, std::string adapterName, std::string connectionId) const final;
void checkSendSize(const IceInternal::Buffer&) final;
void setBufferSize(int rcvSize, int sndSize) final;

Expand Down
25 changes: 13 additions & 12 deletions cpp/src/Ice/SSL/SSLEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ namespace Ice::SSL
SSLEngine(const IceInternal::InstancePtr&);
~SSLEngine();

Ice::LoggerPtr getLogger() const;
Ice::PropertiesPtr getProperties() const;
Ice::InitializationData getInitializationData() const;
[[nodiscard]] Ice::LoggerPtr getLogger() const;
[[nodiscard]] Ice::PropertiesPtr getProperties() const;
[[nodiscard]] Ice::InitializationData getInitializationData() const;

IceInternal::InstancePtr instance() const { return _instance; }
[[nodiscard]] IceInternal::InstancePtr instance() const { return _instance; }

// Setup the engine.
virtual void initialize() = 0;
Expand All @@ -42,15 +42,16 @@ namespace Ice::SSL
// Verify peer certificate.
virtual void verifyPeer(const ConnectionInfoPtr&) const;

virtual ClientAuthenticationOptions createClientAuthenticationOptions(const std::string&) const = 0;
virtual ServerAuthenticationOptions createServerAuthenticationOptions() const = 0;
[[nodiscard]] virtual ClientAuthenticationOptions
createClientAuthenticationOptions(const std::string&) const = 0;
[[nodiscard]] virtual ServerAuthenticationOptions createServerAuthenticationOptions() const = 0;

bool getCheckCertName() const;
int getVerifyPeer() const;
int securityTraceLevel() const;
bool getRevocationCheckCacheOnly() const;
int getRevocationCheck() const;
std::string securityTraceCategory() const;
[[nodiscard]] bool getCheckCertName() const;
[[nodiscard]] int getVerifyPeer() const;
[[nodiscard]] int securityTraceLevel() const;
[[nodiscard]] bool getRevocationCheckCacheOnly() const;
[[nodiscard]] int getRevocationCheck() const;
[[nodiscard]] std::string securityTraceCategory() const;

protected:
mutable std::mutex _mutex;
Expand Down
1 change: 0 additions & 1 deletion cpp/src/Ice/SSL/SSLUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "Ice/Config.h"
#include "Ice/SSL/Config.h"

#include <functional>
#include <optional>
#include <string>
#include <utility>
Expand Down
9 changes: 5 additions & 4 deletions cpp/src/Ice/SSL/SchannelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ namespace Ice::SSL::Schannel
//
void destroy() final;

std::string getCipherName(ALG_ID) const;
[[nodiscard]] std::string getCipherName(ALG_ID) const;

Ice::SSL::ClientAuthenticationOptions createClientAuthenticationOptions(const std::string&) const final;
Ice::SSL::ServerAuthenticationOptions createServerAuthenticationOptions() const final;
static bool
[[nodiscard]] Ice::SSL::ClientAuthenticationOptions
createClientAuthenticationOptions(const std::string&) const final;
[[nodiscard]] Ice::SSL::ServerAuthenticationOptions createServerAuthenticationOptions() const final;
[[nodiscard]] static bool
validationCallback(HCERTCHAINENGINE chainEngine, CtxtHandle, bool, const std::string&, bool, int, bool);

private:
Expand Down
31 changes: 16 additions & 15 deletions cpp/src/Ice/SSL/SchannelTransceiverI.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,32 @@ namespace Ice::SSL::Schannel
const std::string&,
const Ice::SSL::ClientAuthenticationOptions&);
~TransceiverI();
IceInternal::NativeInfoPtr getNativeInfo() final;
IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&) final;
IceInternal::SocketOperation closing(bool, std::exception_ptr) final;
[[nodiscard]] IceInternal::NativeInfoPtr getNativeInfo() final;
[[nodiscard]] IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&) final;
[[nodiscard]] IceInternal::SocketOperation closing(bool, std::exception_ptr) final;
void close();
IceInternal::SocketOperation write(IceInternal::Buffer&) final;
IceInternal::SocketOperation read(IceInternal::Buffer&) final;
bool startWrite(IceInternal::Buffer&) final;
[[nodiscard]] IceInternal::SocketOperation write(IceInternal::Buffer&) final;
[[nodiscard]] IceInternal::SocketOperation read(IceInternal::Buffer&) final;
[[nodiscard]] bool startWrite(IceInternal::Buffer&) final;
void finishWrite(IceInternal::Buffer&) final;
void startRead(IceInternal::Buffer&) final;
void finishRead(IceInternal::Buffer&) final;
std::string protocol() const final;
std::string toString() const final;
std::string toDetailedString() const final;
Ice::ConnectionInfoPtr getInfo(bool incoming, std::string adapterName, std::string connectionId) const final;
[[nodiscard]] std::string protocol() const final;
[[nodiscard]] std::string toString() const final;
[[nodiscard]] std::string toDetailedString() const final;
[[nodiscard]] Ice::ConnectionInfoPtr
getInfo(bool incoming, std::string adapterName, std::string connectionId) const final;
void checkSendSize(const IceInternal::Buffer&) final;
void setBufferSize(int rcvSize, int sndSize) final;

private:
IceInternal::SocketOperation sslHandshake(SecBuffer* initialBuffer = nullptr);
[[nodiscard]] IceInternal::SocketOperation sslHandshake(SecBuffer* initialBuffer = nullptr);

size_t decryptMessage(IceInternal::Buffer&);
size_t encryptMessage(IceInternal::Buffer&);
[[nodiscard]] size_t decryptMessage(IceInternal::Buffer&);
[[nodiscard]] size_t encryptMessage(IceInternal::Buffer&);

bool writeRaw(IceInternal::Buffer&);
bool readRaw(IceInternal::Buffer&);
[[nodiscard]] bool writeRaw(IceInternal::Buffer&);
[[nodiscard]] bool readRaw(IceInternal::Buffer&);

enum State
{
Expand Down
14 changes: 8 additions & 6 deletions cpp/src/Ice/SSL/SecureTransportEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ SecureTransport::SSLEngine::SSLEngine(const IceInternal::InstancePtr& instance)
{
}

SecureTransport::SSLEngine::~SSLEngine() {}
SecureTransport::SSLEngine::~SSLEngine() = default;

//
// Setup the engine.
Expand Down Expand Up @@ -681,6 +681,7 @@ SecureTransport::SSLEngine::createClientAuthenticationOptions(const string& host
}
return chain;
},
.sslNewSessionCallback = nullptr,
.trustedRootCertificates = _certificateAuthorities.get(),
.serverCertificateValidationCallback = [this, host](SecTrustRef trust, const Ice::SSL::ConnectionInfoPtr& info)
{ return validationCallback(trust, info, host); }};
Expand All @@ -706,10 +707,6 @@ SecureTransport::SSLEngine::createServerAuthenticationOptions() const
// It is safe to capture 'this' in the callbacks below as SSLEngine is managed by the communicator
// and is guaranteed to outlive all connections.
return ServerAuthenticationOptions{
.clientCertificateValidationCallback = [this](SecTrustRef trust, const Ice::SSL::ConnectionInfoPtr& info)
{ return validationCallback(trust, info, ""); },
.clientCertificateRequired = clientCertificateRequired,
.trustedRootCertificates = _certificateAuthorities.get(),
.serverCertificateSelectionCallback =
[this](const string&)
{
Expand All @@ -719,7 +716,12 @@ SecureTransport::SSLEngine::createServerAuthenticationOptions() const
CFRetain(chain);
}
return chain;
}};
},
.sslNewSessionCallback = nullptr,
.clientCertificateRequired = clientCertificateRequired,
.trustedRootCertificates = _certificateAuthorities.get(),
.clientCertificateValidationCallback = [this](SecTrustRef trust, const Ice::SSL::ConnectionInfoPtr& info)
{ return validationCallback(trust, info, ""); }};
}

SSLContextRef
Expand Down
14 changes: 8 additions & 6 deletions cpp/src/Ice/SSL/SecureTransportEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ namespace Ice::SSL::SecureTransport
void initialize() final;
void destroy() final;

Ice::SSL::ClientAuthenticationOptions createClientAuthenticationOptions(const std::string& host) const final;
Ice::SSL::ServerAuthenticationOptions createServerAuthenticationOptions() const final;
SSLContextRef newContext(bool) const;
bool validationCallback(SecTrustRef trust, const Ice::SSL::ConnectionInfoPtr&, const std::string&) const;

std::string getCipherName(SSLCipherSuite) const;
[[nodiscard]] Ice::SSL::ClientAuthenticationOptions
createClientAuthenticationOptions(const std::string& host) const final;
[[nodiscard]] Ice::SSL::ServerAuthenticationOptions createServerAuthenticationOptions() const final;
[[nodiscard]] SSLContextRef newContext(bool) const;
[[nodiscard]] bool
validationCallback(SecTrustRef trust, const Ice::SSL::ConnectionInfoPtr&, const std::string&) const;

[[nodiscard]] std::string getCipherName(SSLCipherSuite) const;

private:
IceInternal::UniqueRef<CFArrayRef> _certificateAuthorities;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/SSL/SecureTransportTransceiverI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ Ice::SSL::SecureTransport::TransceiverI::TransceiverI(
{
}

Ice::SSL::SecureTransport::TransceiverI::~TransceiverI() {}
Ice::SSL::SecureTransport::TransceiverI::~TransceiverI() = default;

OSStatus
Ice::SSL::SecureTransport::TransceiverI::writeRaw(const byte* data, size_t* length) const
Expand Down
24 changes: 13 additions & 11 deletions cpp/src/Ice/SSL/SecureTransportTransceiverI.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,25 @@ namespace Ice::SSL::SecureTransport
const std::string&,
const Ice::SSL::ClientAuthenticationOptions&);
~TransceiverI();
IceInternal::NativeInfoPtr getNativeInfo() final;

IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&) final;
IceInternal::SocketOperation closing(bool, std::exception_ptr) final;
[[nodiscard]] IceInternal::NativeInfoPtr getNativeInfo() final;

[[nodiscard]] IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&) final;
[[nodiscard]] IceInternal::SocketOperation closing(bool, std::exception_ptr) final;
void close() final;
IceInternal::SocketOperation write(IceInternal::Buffer&) final;
IceInternal::SocketOperation read(IceInternal::Buffer&) final;
[[nodiscard]] IceInternal::SocketOperation write(IceInternal::Buffer&) final;
[[nodiscard]] IceInternal::SocketOperation read(IceInternal::Buffer&) final;

std::string protocol() const final;
std::string toString() const final;
std::string toDetailedString() const final;
Ice::ConnectionInfoPtr getInfo(bool incoming, std::string adapterName, std::string connectionId) const final;
[[nodiscard]] std::string protocol() const final;
[[nodiscard]] std::string toString() const final;
[[nodiscard]] std::string toDetailedString() const final;
[[nodiscard]] Ice::ConnectionInfoPtr
getInfo(bool incoming, std::string adapterName, std::string connectionId) const final;
void checkSendSize(const IceInternal::Buffer&) final;
void setBufferSize(int rcvSize, int sndSize) final;

OSStatus writeRaw(const std::byte*, size_t*) const;
OSStatus readRaw(std::byte*, size_t*) const;
[[nodiscard]] OSStatus writeRaw(const std::byte*, size_t*) const;
[[nodiscard]] OSStatus readRaw(std::byte*, size_t*) const;

private:
const InstancePtr _instance;
Expand Down

0 comments on commit 5f38d62

Please sign in to comment.