#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
+#include <cstdlib>
#include <list>
#include <string>
#include <vector>
/// @brief Local server port used for testing.
const unsigned short SERVER_PORT = 18123;
+/// @brief Name of the environment variable controlling the display
+/// (default off) of TLS error messages.
+const char KEA_TLS_CHECK_VERBOSE[] = "KEA_TLS_CHECK_VERBOSE";
+
/// @brief Test TLS context class exposing protected methods.
class TestTlsContext : public TlsContext {
public:
list_.push_back(Expected::createError(message));
}
+ /// @brief Display error messages.
+ ///
+ /// @return True if error messages are displayed.
+ static bool displayErrMsg() {
+ return (getenv(KEA_TLS_CHECK_VERBOSE));
+ }
+
/// @brief Has an error message.
///
/// @return True when there is a cached error message.
TestTlsContext ctx(TlsRole::CLIENT);
ctx.loadCaFile(ca);
});
- std::cout << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << exps.getErrMsg() << "\n";
+ }
}
// Test that a directory can be loaded.
TestTlsContext ctx(TlsRole::CLIENT);
ctx.loadCaFile(ca);
});
- std::cout << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << exps.getErrMsg() << "\n";
+ }
}
// Test if the end entity certificate can be loaded.
TestTlsContext ctx(TlsRole::CLIENT);
ctx.loadCertFile(cert);
});
- std::cout << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << exps.getErrMsg() << "\n";
+ }
}
// Test that a certificate is wanted.
TestTlsContext ctx(TlsRole::CLIENT);
ctx.loadCertFile(cert);
});
- std::cout << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << exps.getErrMsg() << "\n";
+ }
}
// Test if the private key can be loaded.
TestTlsContext ctx(TlsRole::CLIENT);
ctx.loadKeyFile(key);
});
- std::cout << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << exps.getErrMsg() << "\n";
+ }
}
// Test that a private key is wanted.
TestTlsContext ctx(TlsRole::CLIENT);
ctx.loadKeyFile(key);
});
- std::cout << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << exps.getErrMsg() << "\n";
+ }
}
// Test that the certificate and private key must match.
// The explicit check function is SSL_CTX_check_private_key.
ctx.loadKeyFile(key);
});
- std::cout << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << exps.getErrMsg() << "\n";
+ }
}
// Test the configure class method.
// The context is reseted on errors.
EXPECT_FALSE(ctx);
});
- std::cout << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << exps.getErrMsg() << "\n";
+ }
}
// Test if we can get a stream.
// OpenSSL error.
exps.addError("uninitialized");
exps.checkAsync("send", send_cb);
- std::cout << "send: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << "send: " << exps.getErrMsg() << "\n";
+ }
// Setup a second timeout.
IntervalTimer timer2(service);
// OpenSSL error,
exps.addError("uninitialized");
exps.checkAsync("receive", receive_cb);
- if (timeout) {
- std::cout << "receive timeout\n";
- } else {
- std::cout << "receive: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ if (timeout) {
+ std::cout << "receive timeout\n";
+ } else {
+ std::cout << "receive: " << exps.getErrMsg() << "\n";
+ }
}
// Close client and server.
// OpenSSL error.
exps.addError("sslv3 alert handshake failure");
exps.checkAsync("server", server_cb);
- std::cout << "server: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << "server: " << exps.getErrMsg() << "\n";
+ }
exps.clear();
// On Botan and some OpenSSL the client hangs.
// OpenSSL error.
exps.addError("sslv3 alert handshake failure");
exps.checkAsync("client", client_cb);
- if (timeout) {
- std::cout << "client timeout\n";
- } else {
- std::cout << "client: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ if (timeout) {
+ std::cout << "client timeout\n";
+ } else {
+ std::cout << "client: " << exps.getErrMsg() << "\n";
+ }
}
// Close client and server.
// OpenSSL error.
exps.addError("tlsv1 alert unknown ca");
exps.checkAsync("server", server_cb);
- if (timeout) {
- std::cout << "server timeout\n";
- } else {
- std::cout << "server: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ if (timeout) {
+ std::cout << "server timeout\n";
+ } else {
+ std::cout << "server: " << exps.getErrMsg() << "\n";
+ }
}
exps.clear();
exps.addError("certificate verify failed");
// The client should not hang.
exps.checkAsync("client", client_cb);
- std::cout << "client: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << "client: " << exps.getErrMsg() << "\n";
+ }
// Close client and server.
EXPECT_NO_THROW(client.lowest_layer().close());
// Another OpenSSL error (not all OpenSSL recognizes HTTP).
exps.addError("wrong version number");
exps.checkAsync("server", server_cb);
- if (timeout) {
- std::cout << "server timeout\n";
- } else {
- std::cout << "server: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ if (timeout) {
+ std::cout << "server timeout\n";
+ } else {
+ std::cout << "server: " << exps.getErrMsg() << "\n";
+ }
}
exps.clear();
// Recent OpenSSL error.
exps.addError("wrong version number");
exps.checkAsync("server", server_cb);
- std::cout << "server: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << "server: " << exps.getErrMsg() << "\n";
+ }
exps.clear();
// No error on the client side.
// error 20 at 0 depth lookup:unable to get local issuer certificate
exps.addError("certificate verify failed");
exps.checkAsync("server", server_cb);
- std::cout << "server: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << "server: " << exps.getErrMsg() << "\n";
+ }
exps.clear();
// Botan client hangs.
// Old OpenSSL error.
exps.addError("tlsv1 alert unknown ca");
exps.checkAsync("client", client_cb);
- if (timeout) {
- std::cout << "client timeout\n";
- } else if (exps.hasErrMsg()) {
- std::cout << "client: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ if (timeout) {
+ std::cout << "client timeout\n";
+ } else if (exps.hasErrMsg()) {
+ std::cout << "client: " << exps.getErrMsg() << "\n";
+ }
}
// Close client and server.
// error 18 at 0 depth lookup:self signed certificate
exps.addError("certificate verify failed");
exps.checkAsync("server", server_cb);
- std::cout << "server: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ std::cout << "server: " << exps.getErrMsg() << "\n";
+ }
exps.clear();
// Botan client hangs.
// Old OpenSSL error.
exps.addError("tlsv1 alert unknown ca");
exps.checkAsync("client", client_cb);
- if (timeout) {
- std::cout << "client timeout\n";
- } else if (exps.hasErrMsg()) {
- std::cout << "client: " << exps.getErrMsg() << "\n";
+ if (Expecteds::displayErrMsg()) {
+ if (timeout) {
+ std::cout << "client timeout\n";
+ } else if (exps.hasErrMsg()) {
+ std::cout << "client: " << exps.getErrMsg() << "\n";
+ }
}
// Close client and server.