Fix bugs in the digest handling.
[deb_shairplay.git] / src / lib / raop.c
index 0eaace1bbc2c2fde1d2ef2fbeae6c6a78b3fdd27..1994ed373e833d18399ab079ac0fddcad17a29aa 100644 (file)
@@ -36,7 +36,7 @@
 #define MAX_PASSWORD_LEN 64
 
 /* MD5 as hex fits here */
-#define MAX_NONCE_LEN 33
+#define MAX_NONCE_LEN 32
 
 struct raop_s {
        /* Callbacks for audio */
@@ -143,9 +143,10 @@ conn_request(void *ptr, http_request_t *request, http_response_t **response)
 
                authorization = http_request_get_header(request, "Authorization");
                if (authorization) {
+                       logger_log(&conn->raop->logger, LOGGER_DEBUG, "Our nonce: %s\n", conn->nonce);
                        logger_log(&conn->raop->logger, LOGGER_DEBUG, "Authorization: %s\n", authorization);
                }
-               if (!digest_is_valid("AppleTV", raop->password, conn->nonce, method, authorization)) {
+               if (!digest_is_valid("AppleTV", raop->password, conn->nonce, method, http_request_get_url(request), authorization)) {
                        char *authstr;
                        int authstrlen;
 
@@ -439,18 +440,21 @@ raop_start(raop_t *raop, unsigned short *port, const char *hwaddr, int hwaddrlen
                return -1;
        }
 
-       /* Validate password */
-       if (strlen(password) > MAX_PASSWORD_LEN) {
-               return -1;
+       memset(raop->password, 0, sizeof(raop->password));
+       if (password) {
+               /* Validate password */
+               if (strlen(password) > MAX_PASSWORD_LEN) {
+                       return -1;
+               }
+
+               /* Copy password to the raop structure */
+               strncpy(raop->password, password, MAX_PASSWORD_LEN);
        }
 
        /* Copy hwaddr to the raop structure */
        memcpy(raop->hwaddr, hwaddr, hwaddrlen);
        raop->hwaddrlen = hwaddrlen;
 
-       /* Copy password to the raop structure */
-       strncpy(raop->password, password, MAX_PASSWORD_LEN);
-
        return httpd_start(raop->httpd, port);
 }