unet-cli: strip initial newline in usage message
[project/unetd.git] / auth-data.c
index c262c5432c8ac7752723f7320321ea59635c2c3e..cd07958c456bfcd193b4aa5a7fbf599877048923 100644 (file)
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2022 Felix Fietkau <nbd@nbd.name>
  */
@@ -7,7 +7,7 @@
 #include "auth-data.h"
 
 int unet_auth_data_validate(const uint8_t *key, const void *buf, size_t len,
-                           const char **json_data)
+                           uint64_t *timestamp, const char **json_data)
 {
        const struct unet_auth_hdr *hdr = buf;
        const struct unet_auth_data *data = net_data_auth_data_hdr(buf);
@@ -23,7 +23,7 @@ int unet_auth_data_validate(const uint8_t *key, const void *buf, size_t len,
            data->timestamp == 0)
                return -1;
 
-       if (memcmp(data->pubkey, key, EDSIGN_PUBLIC_KEY_SIZE) != 0)
+       if (key && memcmp(data->pubkey, key, EDSIGN_PUBLIC_KEY_SIZE) != 0)
                return -2;
 
        edsign_verify_init(&vst, hdr->signature, data->pubkey);
@@ -31,9 +31,12 @@ int unet_auth_data_validate(const uint8_t *key, const void *buf, size_t len,
        if (!edsign_verify(&vst, hdr->signature, data->pubkey))
                return -3;
 
-       if (*(char *)(data + len - 1) != 0)
+       if (((char *)data)[len - 1] != 0)
                return -2;
 
+       if (timestamp)
+               *timestamp = be64_to_cpu(data->timestamp);
+
        if (json_data)
                *json_data = (const char *)(data + 1);