summaryrefslogtreecommitdiff
path: root/louloulibs/xmpp/xmpp_component.cpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-10-26 21:19:53 +0200
committerlouiz’ <louiz@louiz.org>2016-10-26 21:19:53 +0200
commit021f025cb039011ad07158b0d94f1b430a409e49 (patch)
tree188231fe10edbf0f9198aa112348bf62842765c7 /louloulibs/xmpp/xmpp_component.cpp
parent3fdae6b6249dd2727578fba8bf84e3a7593d9009 (diff)
downloadbiboumi-021f025cb039011ad07158b0d94f1b430a409e49.tar.gz
biboumi-021f025cb039011ad07158b0d94f1b430a409e49.tar.bz2
biboumi-021f025cb039011ad07158b0d94f1b430a409e49.tar.xz
biboumi-021f025cb039011ad07158b0d94f1b430a409e49.zip
Refactor the sha1 digest into its own function, and do not use sprintf
Diffstat (limited to 'louloulibs/xmpp/xmpp_component.cpp')
-rw-r--r--louloulibs/xmpp/xmpp_component.cpp17
1 files changed, 3 insertions, 14 deletions
diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp
index 6690567..17fde20 100644
--- a/louloulibs/xmpp/xmpp_component.cpp
+++ b/louloulibs/xmpp/xmpp_component.cpp
@@ -5,15 +5,14 @@
#include <xmpp/xmpp_component.hpp>
#include <config/config.hpp>
-#include <xmpp/jid.hpp>
-#include <utils/sha1.hpp>
#include <utils/time.hpp>
+#include <xmpp/auth.hpp>
+#include <xmpp/jid.hpp>
#include <stdexcept>
#include <iostream>
#include <set>
-#include <stdio.h>
#include <uuid/uuid.h>
#include <cstdlib>
@@ -139,17 +138,7 @@ void XmppComponent::on_remote_stream_open(const XmlNode& node)
}
// Try to authenticate
- char digest[HASH_LENGTH * 2 + 1];
- sha1nfo sha1;
- sha1_init(&sha1);
- sha1_write(&sha1, this->stream_id.data(), this->stream_id.size());
- sha1_write(&sha1, this->secret.data(), this->secret.size());
- const uint8_t* result = sha1_result(&sha1);
- for (int i=0; i < HASH_LENGTH; i++)
- sprintf(digest + (i*2), "%02x", result[i]);
- digest[HASH_LENGTH * 2] = '\0';
-
- auto data = "<handshake xmlns='" COMPONENT_NS "'>"s + digest + "</handshake>";
+ auto data = "<handshake xmlns='" COMPONENT_NS "'>"s + get_handshake_digest(this->stream_id, this->secret) + "</handshake>";
log_debug("XMPP SENDING: ", data);
this->send_data(std::move(data));
}