aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls/tls_channel.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-01-26 21:00:01 +0000
committerlloyd <[email protected]>2012-01-26 21:00:01 +0000
commit4b8786ad157e38b4143b0968c1ea1c83c2ee7388 (patch)
tree2a0272f0b6f5e14d738c5bfdb126f5e3ef45fb3b /src/tls/tls_channel.cpp
parent4b285bd51a48f78f41a14beb9626a8db59e65960 (diff)
Make Alert a first class object ala Version. Move the alert codes into
the Alert class for namespacing.
Diffstat (limited to 'src/tls/tls_channel.cpp')
-rw-r--r--src/tls/tls_channel.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/tls/tls_channel.cpp b/src/tls/tls_channel.cpp
index 801dfdfe3..4c8cc4fbf 100644
--- a/src/tls/tls_channel.cpp
+++ b/src/tls/tls_channel.cpp
@@ -6,7 +6,6 @@
*/
#include <botan/tls_channel.h>
-#include <botan/internal/tls_alerts.h>
#include <botan/internal/tls_handshake_state.h>
#include <botan/internal/tls_messages.h>
#include <botan/internal/assert.h>
@@ -67,7 +66,7 @@ size_t Channel::received_data(const byte buf[], size_t buf_size)
* following record. Avoid spurious callbacks.
*/
if(record.size() > 0)
- proc_fn(&record[0], record.size(), NULL_ALERT);
+ proc_fn(&record[0], record.size(), Alert::NULL_ALERT);
}
else
{
@@ -82,16 +81,16 @@ size_t Channel::received_data(const byte buf[], size_t buf_size)
{
Alert alert_msg(record);
- alert_notify(alert_msg.is_fatal(), alert_msg.type());
+ alert_notify(alert_msg);
proc_fn(0, 0, alert_msg.type());
- if(alert_msg.type() == CLOSE_NOTIFY)
+ if(alert_msg.type() == Alert::CLOSE_NOTIFY)
{
if(connection_closed)
reader.reset();
else
- alert(WARNING, CLOSE_NOTIFY); // reply in kind
+ send_alert(Alert(Alert::WARNING, Alert::CLOSE_NOTIFY)); // reply in kind
}
else if(alert_msg.is_fatal())
{
@@ -114,22 +113,22 @@ size_t Channel::received_data(const byte buf[], size_t buf_size)
}
catch(TLS_Exception& e)
{
- alert(FATAL, e.type());
+ send_alert(Alert(Alert::FATAL, e.type()));
throw;
}
catch(Decoding_Error& e)
{
- alert(FATAL, DECODE_ERROR);
+ send_alert(Alert(Alert::FATAL, Alert::DECODE_ERROR));
throw;
}
catch(Internal_Error& e)
{
- alert(FATAL, INTERNAL_ERROR);
+ send_alert(Alert(Alert::FATAL, Alert::INTERNAL_ERROR));
throw;
}
catch(std::exception& e)
{
- alert(FATAL, INTERNAL_ERROR);
+ send_alert(Alert(Alert::FATAL, Alert::INTERNAL_ERROR));
throw;
}
}
@@ -198,19 +197,18 @@ void Channel::send(const byte buf[], size_t buf_size)
writer.send(APPLICATION_DATA, buf, buf_size);
}
-void Channel::alert(Alert_Level alert_level, Alert_Type alert_code)
+void Channel::send_alert(const Alert& alert)
{
- if(alert_code != NULL_ALERT && !connection_closed)
+ if(alert.is_valid() && !connection_closed)
{
try
{
- writer.alert(alert_level, alert_code);
+ writer.send_alert(alert);
}
catch(...) { /* swallow it */ }
}
- if(!connection_closed &&
- (alert_code == CLOSE_NOTIFY || alert_level == FATAL))
+ if(!connection_closed && (alert.type() == Alert::CLOSE_NOTIFY || alert.is_fatal()))
{
connection_closed = true;
@@ -230,7 +228,7 @@ void Channel::Secure_Renegotiation_State::update(Client_Hello* client_hello)
else
{
if(secure_renegotiation != client_hello->secure_renegotiation())
- throw TLS_Exception(HANDSHAKE_FAILURE,
+ throw TLS_Exception(Alert::HANDSHAKE_FAILURE,
"Client changed its mind about secure renegotiation");
}
@@ -241,13 +239,13 @@ void Channel::Secure_Renegotiation_State::update(Client_Hello* client_hello)
if(initial_handshake)
{
if(!data.empty())
- throw TLS_Exception(HANDSHAKE_FAILURE,
+ throw TLS_Exception(Alert::HANDSHAKE_FAILURE,
"Client sent renegotiation data on initial handshake");
}
else
{
if(data != for_client_hello())
- throw TLS_Exception(HANDSHAKE_FAILURE,
+ throw TLS_Exception(Alert::HANDSHAKE_FAILURE,
"Client sent bad renegotiation data");
}
}
@@ -265,7 +263,7 @@ void Channel::Secure_Renegotiation_State::update(Server_Hello* server_hello)
else
{
if(secure_renegotiation != server_hello->secure_renegotiation())
- throw TLS_Exception(HANDSHAKE_FAILURE,
+ throw TLS_Exception(Alert::HANDSHAKE_FAILURE,
"Server changed its mind about secure renegotiation");
}
@@ -276,13 +274,13 @@ void Channel::Secure_Renegotiation_State::update(Server_Hello* server_hello)
if(initial_handshake)
{
if(!data.empty())
- throw TLS_Exception(HANDSHAKE_FAILURE,
+ throw TLS_Exception(Alert::HANDSHAKE_FAILURE,
"Server sent renegotiation data on initial handshake");
}
else
{
if(data != for_server_hello())
- throw TLS_Exception(HANDSHAKE_FAILURE,
+ throw TLS_Exception(Alert::HANDSHAKE_FAILURE,
"Server sent bad renegotiation data");
}
}