[PATCH v6 15/37] raop: Add BA (Basic) and DA (Digest) HTTP authentication helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Martin Blanchard <tchaik@xxxxxxx>

RAOP authentication is using standard HTTP challenge-response authentication
scheme. This patch adds two helper functions that generate the proper hash
(for both techniques) given a username, a password and session related tokens.
---
 src/modules/raop/raop_util.c | 40 ++++++++++++++++++++++++++++++++++++++++
 src/modules/raop/raop_util.h |  4 ++++
 2 files changed, 44 insertions(+)

diff --git a/src/modules/raop/raop_util.c b/src/modules/raop/raop_util.c
index 54f7c6d..d13b7ee 100644
--- a/src/modules/raop/raop_util.c
+++ b/src/modules/raop/raop_util.c
@@ -35,6 +35,7 @@
 
 #include <pulse/xmalloc.h>
 
+#include <pulsecore/core-util.h>
 #include <pulsecore/macro.h>
 
 #include "raop_util.h"
@@ -168,3 +169,42 @@ int pa_raop_md5_hash(const char *data, int len, char **str) {
     s[MD5_HASH_LENGTH] = 0;
     return strlen(s);
 }
+
+int pa_raop_basic_response(const char *user, const char *pwd, char **str) {
+    char *tmp, *B = NULL;
+
+    pa_assert(str);
+
+    tmp = pa_sprintf_malloc("%s:%s", user, pwd);
+    pa_raop_base64_encode(tmp, strlen(tmp), &B);
+    pa_xfree(tmp);
+
+    *str = B;
+    return strlen(B);
+}
+
+int pa_raop_digest_response(const char *user, const char *realm, const char *password,
+                            const char *nonce, const char *uri, char **str) {
+    char *A1, *HA1, *A2, *HA2;
+    char *tmp, *KD = NULL;
+
+    pa_assert(str);
+
+    A1 = pa_sprintf_malloc("%s:%s:%s", user, realm, password);
+    pa_raop_md5_hash(A1, strlen(A1), &HA1);
+    pa_xfree(A1);
+
+    A2 = pa_sprintf_malloc("OPTIONS:%s", uri);
+    pa_raop_md5_hash(A2, strlen(A2), &HA2);
+    pa_xfree(A2);
+
+    tmp = pa_sprintf_malloc("%s:%s:%s", HA1, nonce, HA2);
+    pa_raop_md5_hash(tmp, strlen(tmp), &KD);
+    pa_xfree(tmp);
+
+    pa_xfree(HA1);
+    pa_xfree(HA2);
+
+    *str = KD;
+    return strlen(KD);
+}
diff --git a/src/modules/raop/raop_util.h b/src/modules/raop/raop_util.h
index a95c822..a3f0dfa 100644
--- a/src/modules/raop/raop_util.h
+++ b/src/modules/raop/raop_util.h
@@ -25,4 +25,8 @@ int pa_raop_base64_decode(const char *str, void *data);
 
 int pa_raop_md5_hash(const char *data, int len, char **str);
 
+int pa_raop_basic_response(const char *user, const char *pwd, char **str);
+int pa_raop_digest_response(const char *user, const char *realm, const char *password,
+                            const char *nonce, const char *uri, char **str);
+
 #endif
-- 
2.5.0



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux