raop: Add BA (Basic) and DA (Digest) HTTP authentication helpers

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.
This commit is contained in:
Martin Blanchard 2016-11-06 12:54:06 -06:00 committed by Tanu Kaskinen
parent a33c04c0cc
commit 5ff21c3bdd
6 changed files with 365 additions and 49 deletions

View file

@ -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);
}