diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2018-04-27 23:27:24 -0400 |
---|---|---|
committer | Sara Golemon <sara.golemon@mongodb.com> | 2018-04-30 15:32:16 -0400 |
commit | 963b7b0fa2b88eb492da7bd5959e9e534df1eac5 (patch) | |
tree | 2da68382a4e272b1f73d468f89b8a6f9622a0391 /src | |
parent | 71ac74d57ea94bc78cf5f0e432c13e77ea788389 (diff) | |
download | mongo-963b7b0fa2b88eb492da7bd5959e9e534df1eac5.tar.gz |
SERVER-34734 Make Secure Transport error messages more human readable
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/util/net/ssl/detail/impl/engine_apple.ipp | 39 | ||||
-rw-r--r-- | src/mongo/util/net/ssl/impl/error.ipp | 3 |
2 files changed, 19 insertions, 23 deletions
diff --git a/src/mongo/util/net/ssl/detail/impl/engine_apple.ipp b/src/mongo/util/net/ssl/detail/impl/engine_apple.ipp index 752e174a036..319061d0aae 100644 --- a/src/mongo/util/net/ssl/detail/impl/engine_apple.ipp +++ b/src/mongo/util/net/ssl/detail/impl/engine_apple.ipp @@ -48,26 +48,6 @@ namespace detail { namespace { -std::ostringstream& operator<<(std::ostringstream& ss, ::OSStatus status) { - apple::CFUniquePtr<::CFStringRef> errstr(::SecCopyErrorMessageString(status, nullptr)); - if (!errstr) { - ss << "Unknown Error: " << static_cast<int>(status); - return ss; - } - const auto len = ::CFStringGetMaximumSizeForEncoding(::CFStringGetLength(errstr.get()), - ::kCFStringEncodingUTF8); - std::string ret; - ret.resize(len + 1); - if (!::CFStringGetCString(errstr.get(), &ret[0], len, ::kCFStringEncodingUTF8)) { - ss << "Unknown Error: " << static_cast<int>(status); - return ss; - } - - ret.resize(strlen(ret.c_str())); - ss << ret; - return ss; -} - const class osstatus_category : public error_category { public: const char* name() const noexcept final { @@ -76,7 +56,22 @@ public: std::string message(int value) const noexcept final { const auto status = static_cast<::OSStatus>(value); - return mongo::str::stream() << "Secure.Transport: " << status; + apple::CFUniquePtr<::CFStringRef> errstr(::SecCopyErrorMessageString(status, nullptr)); + if (!errstr) { + return mongo::str::stream() << "Secure.Transport unknown error: " + << static_cast<int>(status); + } + const auto len = ::CFStringGetMaximumSizeForEncoding(::CFStringGetLength(errstr.get()), + ::kCFStringEncodingUTF8); + std::string ret; + ret.resize(len + 1); + if (!::CFStringGetCString(errstr.get(), &ret[0], len, ::kCFStringEncodingUTF8)) { + return mongo::str::stream() << "Secure.Transport unknown error: " + << static_cast<int>(status); + } + + ret.resize(strlen(ret.c_str())); + return mongo::str::stream() << "Secure.Transport: " << ret; } } OSStatus_category; @@ -151,8 +146,6 @@ bool engine::_initSSL(stream_base::handshake_type type, asio::error_code& ec) { auto status = ::SSLSetConnection(_ssl.get(), static_cast<void*>(this)); - // TODO: ::SSLSetPeerDomainName() - if (_certs && (status == ::errSecSuccess)) { status = ::SSLSetCertificate(_ssl.get(), _certs.get()); } diff --git a/src/mongo/util/net/ssl/impl/error.ipp b/src/mongo/util/net/ssl/impl/error.ipp index 5a4031b4cab..fd0574b6780 100644 --- a/src/mongo/util/net/ssl/impl/error.ipp +++ b/src/mongo/util/net/ssl/impl/error.ipp @@ -47,6 +47,9 @@ public: #elif MONGO_CONFIG_SSL_PROVIDER == SSL_PROVIDER_APPLE std::string message(int value) const { // engine_apple produces osstatus_errorcategory messages except for stream_truncated + if (value == asio::ssl::error::stream_truncated) { + return "asio.ssl stream truncated"; + } return "asio.ssl error"; } #else |