aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libcryptobox/keypair.c22
-rw-r--r--src/libcryptobox/keypair.h9
-rw-r--r--src/libutil/http.c15
-rw-r--r--src/libutil/http.h8
4 files changed, 53 insertions, 1 deletions
diff --git a/src/libcryptobox/keypair.c b/src/libcryptobox/keypair.c
index 1568293e3..51e023128 100644
--- a/src/libcryptobox/keypair.c
+++ b/src/libcryptobox/keypair.c
@@ -92,7 +92,7 @@ rspamd_cryptobox_keypair_pk (struct rspamd_cryptobox_keypair *kp,
}
static void *
-rspamd_cryptobox_pubkey_pk (struct rspamd_cryptobox_pubkey *kp,
+rspamd_cryptobox_pubkey_pk (const struct rspamd_cryptobox_pubkey *kp,
guint *len)
{
g_assert (kp != NULL);
@@ -880,3 +880,23 @@ rspamd_keypair_verify (struct rspamd_cryptobox_pubkey *pk,
return TRUE;
}
+
+gboolean
+rspamd_pubkey_equal (const struct rspamd_cryptobox_pubkey *k1,
+ const struct rspamd_cryptobox_pubkey *k2)
+{
+ guchar *p1 = NULL, *p2 = NULL;
+ guint len1, len2;
+
+
+ if (k1->alg == k2->alg && k1->type == k2->type) {
+ p1 = rspamd_cryptobox_pubkey_pk (k1, &len1);
+ p2 = rspamd_cryptobox_pubkey_pk (k2, &len2);
+
+ if (len1 == len2) {
+ return (memcmp (p1, p2, len1) == 0);
+ }
+ }
+
+ return FALSE;
+}
diff --git a/src/libcryptobox/keypair.h b/src/libcryptobox/keypair.h
index 6c30c5134..b50bc84db 100644
--- a/src/libcryptobox/keypair.h
+++ b/src/libcryptobox/keypair.h
@@ -261,5 +261,14 @@ gboolean rspamd_keypair_verify (struct rspamd_cryptobox_pubkey *pk,
const void *data, gsize len, guchar *sig, gsize siglen,
GError **err);
+/**
+ * Compares two public keys
+ * @param k1 key to compare
+ * @param k2 key to compare
+ * @return TRUE if two keys are equal
+ */
+gboolean rspamd_pubkey_equal (const struct rspamd_cryptobox_pubkey *k1,
+ const struct rspamd_cryptobox_pubkey *k2);
+
#endif /* SRC_LIBCRYPTOBOX_KEYPAIR_H_ */
diff --git a/src/libutil/http.c b/src/libutil/http.c
index fef9cb73c..0e0f30eaf 100644
--- a/src/libutil/http.c
+++ b/src/libutil/http.c
@@ -2391,6 +2391,21 @@ rspamd_http_connection_set_key (struct rspamd_http_connection *conn,
priv->local_key = rspamd_keypair_ref (key);
}
+const struct rspamd_cryptobox_pubkey*
+rspamd_http_connection_get_peer_key (struct rspamd_http_connection *conn)
+{
+ struct rspamd_http_connection_private *priv = conn->priv;
+
+ if (priv->peer_key) {
+ return priv->peer_key;
+ }
+ else if (priv->msg) {
+ return priv->msg->peer_key;
+ }
+
+ return NULL;
+}
+
gboolean
rspamd_http_connection_is_encrypted (struct rspamd_http_connection *conn)
{
diff --git a/src/libutil/http.h b/src/libutil/http.h
index 9793e577b..d9fb73b82 100644
--- a/src/libutil/http.h
+++ b/src/libutil/http.h
@@ -166,6 +166,14 @@ void rspamd_http_connection_set_key (struct rspamd_http_connection *conn,
struct rspamd_cryptobox_keypair *key);
/**
+ * Get peer's public key
+ * @param conn connection structure
+ * @return pubkey structure or NULL
+ */
+const struct rspamd_cryptobox_pubkey* rspamd_http_connection_get_peer_key (
+ struct rspamd_http_connection *conn);
+
+/**
* Returns TRUE if a connection is encrypted
* @param conn
* @return