-bool metakey_h(connection_t *c, char *request) {
- char hexkey[MAX_STRING_SIZE];
- int cipher, digest, maclength, compression;
- size_t len = rsa_size(&myself->connection->rsa);
- char enckey[len];
- char key[len];
-
- cp();
-
- if(sscanf(request, "%*d %d %d %d %d " MAX_STRING, &cipher, &digest, &maclength, &compression, hexkey) != 5) {
- logger(LOG_ERR, _("Got bad %s from %s (%s)"), "METAKEY", c->name, c->hostname);
- return false;
- }
-
- /* Check if the length of the meta key is all right */
-
- if(strlen(hexkey) != len * 2) {
- logger(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, "wrong keylength");
+static bool process_invitation(meshlink_handle_t *mesh, connection_t *c, const void *data) {
+ // Recover the filename from the cookie and the key
+ char *fingerprint = ecdsa_get_base64_public_key(mesh->invitation_key);
+ char hash[64];
+ char hashbuf[18 + strlen(fingerprint)];
+ char cookie[25];
+ memcpy(hashbuf, data, 18);
+ memcpy(hashbuf + 18, fingerprint, sizeof(hashbuf) - 18);
+ sha512(hashbuf, sizeof(hashbuf), hash);
+ b64encode_urlsafe(hash, cookie, 18);
+ free(fingerprint);
+
+ config_t config;
+
+ if(!invitation_read(mesh, "current", cookie, &config, mesh->config_key)) {
+ logger(mesh, MESHLINK_ERROR, "Error while trying to read invitation file\n");