]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add routines to compare and check pubkeys
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 May 2016 09:09:06 +0000 (10:09 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 May 2016 09:09:06 +0000 (10:09 +0100)
src/libcryptobox/keypair.c
src/libcryptobox/keypair.h
src/libutil/http.c
src/libutil/http.h

index 1568293e3bf64622b8bbe56e136dc2b6597c0e6b..51e0231284c5ad2e7ebafadb17a375587b04c956 100644 (file)
@@ -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;
+}
index 6c30c51344b0d7967b1bd50fd900dd11381ceb8a..b50bc84db74e5e3e41a8b951fc1304accbc02981 100644 (file)
@@ -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_ */
index fef9cb73cc56aef49d060d8172e88698ca00a766..0e0f30eafa7576d00e34bcdfdc0aed26201c6d54 100644 (file)
@@ -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)
 {
index 9793e577bbdbfb4adde979de8b984312b9303816..d9fb73b825885852075ccb9472cfd29a1ab57f7a 100644 (file)
@@ -165,6 +165,14 @@ struct rspamd_http_connection * rspamd_http_connection_new (
 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