Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add IceSSL::getHost (#1277)
  • Loading branch information
pepone committed May 13, 2021
1 parent aa9ebdb commit e2ea3ee
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-3.7.md
Expand Up @@ -78,6 +78,10 @@ These are the changes since Ice 3.7.5.
failure from `IceSSL::ConnectionInfo`. To get the description of a `IceSSL::TrustError` pass it to
`IceSSL::getTrustErrorDescription`.

- Added `IceSSL::getHost` function to allow retrieving the host that was used to create an SSL connection from
the `IceSSL::ConnectionInfo` object. The returned host corresponds to the `Endpoint::host` member of the endpoint
that was used to create the connection.

# Changes in Ice 3.7.5

These are the changes since Ice 3.7.4.
Expand Down
1 change: 1 addition & 0 deletions cpp/include/IceSSL/Plugin.h
Expand Up @@ -87,6 +87,7 @@ enum TrustError

ICESSL_API TrustError getTrustError(const IceSSL::ConnectionInfoPtr&);
ICESSL_API std::string getTrustErrorDescription(TrustError);
ICESSL_API std::string getHost(const IceSSL::ConnectionInfoPtr&);

/**
* Thrown if the certificate cannot be read.
Expand Down
1 change: 1 addition & 0 deletions cpp/src/IceSSL/OpenSSLTransceiverI.cpp
Expand Up @@ -932,6 +932,7 @@ OpenSSL::TransceiverI::getInfo() const
info->certs = _certs;
info->verified = _verified;
info->errorCode = _trustError;
info->host = _incoming ? "" : _host;
return info;
}

Expand Down
7 changes: 7 additions & 0 deletions cpp/src/IceSSL/PluginI.cpp
Expand Up @@ -237,3 +237,10 @@ IceSSL::getTrustErrorDescription(TrustError error)
assert(false);
return "unknown failure";
}

std::string
IceSSL::getHost(const IceSSL::ConnectionInfoPtr& info)
{
ExtendedConnectionInfoPtr extendedInfo = ICE_DYNAMIC_CAST(ExtendedConnectionInfo, info);
return extendedInfo ? extendedInfo->host : "";
}
1 change: 1 addition & 0 deletions cpp/src/IceSSL/PluginI.h
Expand Up @@ -18,6 +18,7 @@ class ExtendedConnectionInfo : public ConnectionInfo
public:

TrustError errorCode;
std::string host;
};
ICE_DEFINE_PTR(ExtendedConnectionInfoPtr, ExtendedConnectionInfo);

Expand Down
1 change: 1 addition & 0 deletions cpp/src/IceSSL/SChannelTransceiverI.cpp
Expand Up @@ -1106,6 +1106,7 @@ SChannel::TransceiverI::getInfo() const
info->certs = _certs;
info->verified = _verified;
info->errorCode = _trustError;
info->host = _incoming ? "" : _host;
return info;
}

Expand Down
1 change: 1 addition & 0 deletions cpp/src/IceSSL/SecureTransportTransceiverI.cpp
Expand Up @@ -593,6 +593,7 @@ IceSSL::SecureTransport::TransceiverI::getInfo() const
info->certs = _certs;
info->verified = _verified;
info->errorCode = _trustError;
info->host = _incoming ? "" : _host;
return info;
}

Expand Down
9 changes: 9 additions & 0 deletions cpp/test/IceSSL/configuration/AllTests.cpp
Expand Up @@ -1241,6 +1241,7 @@ allTests(Test::TestHelper* helper, const string& /*testDir*/, bool p12)

info = ICE_DYNAMIC_CAST(IceSSL::ConnectionInfo, server->ice_getConnection()->getInfo());
test(info->verified);
test(getHost(info) == "localhost");
test(getTrustError(info) == IceSSL::ICE_ENUM(TrustError, NoError));

fact->destroyServer(server);
Expand All @@ -1262,6 +1263,7 @@ allTests(Test::TestHelper* helper, const string& /*testDir*/, bool p12)
info = ICE_DYNAMIC_CAST(IceSSL::ConnectionInfo, server->ice_getConnection()->getInfo());
test(!info->verified);
test(getTrustError(info) == IceSSL::ICE_ENUM(TrustError, HostNameMismatch));
test(getHost(info) == "localhost");

fact->destroyServer(server);
comm->destroy();
Expand Down Expand Up @@ -1290,6 +1292,7 @@ allTests(Test::TestHelper* helper, const string& /*testDir*/, bool p12)
{
test(info->verified);
}
test(getHost(info) == "localhost");

fact->destroyServer(server);
comm->destroy();
Expand All @@ -1311,6 +1314,7 @@ allTests(Test::TestHelper* helper, const string& /*testDir*/, bool p12)
info = ICE_DYNAMIC_CAST(IceSSL::ConnectionInfo, server->ice_getConnection()->getInfo());
test(!info->verified);
test(getTrustError(info) == IceSSL::ICE_ENUM(TrustError, HostNameMismatch));
test(getHost(info) == "localhost");

fact->destroyServer(server);
comm->destroy();
Expand All @@ -1332,6 +1336,7 @@ allTests(Test::TestHelper* helper, const string& /*testDir*/, bool p12)
info = ICE_DYNAMIC_CAST(IceSSL::ConnectionInfo, server->ice_getConnection()->getInfo());
test(!info->verified);
test(getTrustError(info) == IceSSL::ICE_ENUM(TrustError, HostNameMismatch));
test(getHost(info) == "localhost");

fact->destroyServer(server);
comm->destroy();
Expand All @@ -1356,6 +1361,7 @@ allTests(Test::TestHelper* helper, const string& /*testDir*/, bool p12)
info = ICE_DYNAMIC_CAST(IceSSL::ConnectionInfo, server->ice_getConnection()->getInfo());
test(info->verified);
test(getTrustError(info) == IceSSL::ICE_ENUM(TrustError, NoError));
test(getHost(info) == "127.0.0.1");

fact->destroyServer(server);
comm->destroy();
Expand All @@ -1376,6 +1382,7 @@ allTests(Test::TestHelper* helper, const string& /*testDir*/, bool p12)
info = ICE_DYNAMIC_CAST(IceSSL::ConnectionInfo, server->ice_getConnection()->getInfo());
test(!info->verified);
test(getTrustError(info) == IceSSL::ICE_ENUM(TrustError, HostNameMismatch));
test(getHost(info) == "127.0.0.1");

fact->destroyServer(server);
comm->destroy();
Expand All @@ -1401,6 +1408,7 @@ allTests(Test::TestHelper* helper, const string& /*testDir*/, bool p12)
info = ICE_DYNAMIC_CAST(IceSSL::ConnectionInfo, server->ice_getConnection()->getInfo());
test(!info->verified);
test(getTrustError(info) == IceSSL::ICE_ENUM(TrustError, HostNameMismatch));
test(getHost(info) == "127.0.0.1");
fact->destroyServer(server);
comm->destroy();
}
Expand Down Expand Up @@ -4100,6 +4108,7 @@ allTests(Test::TestHelper* helper, const string& /*testDir*/, bool p12)
ICE_DYNAMIC_CAST(Ice::WSConnectionInfo, p->ice_getConnection()->getInfo());
IceSSL::ConnectionInfoPtr sslInfo = ICE_DYNAMIC_CAST(IceSSL::ConnectionInfo, wsinfo->underlying);
test(sslInfo->verified);
test(getHost(sslInfo) == "zeroc.com");
break;
}
catch(const Ice::LocalException& ex)
Expand Down

0 comments on commit e2ea3ee

Please sign in to comment.