+++ /dev/null
-/*
- This file is part of GNUnet.
- (C) 2012 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file include/block_gns.h
- * @brief fs block formats (shared between fs and block)
- * @author Martin Schanzenbach
- */
-#ifndef BLOCK_GNS_H
-#define BLOCK_GNS_H
-
-#include "gnunet_util_lib.h"
-
-GNUNET_NETWORK_STRUCT_BEGIN
-
-/**
- * @brief a simgle record inside a record block
- */
-struct GNSRecordBlock
-{
- /**
- * the record type
- */
- uint32_t type GNUNET_PACKED;
-
- /**
- * expiration time of the record
- */
- struct GNUNET_TIME_AbsoluteNBO expiration;
-
- /**
- * length of the data
- */
- uint32_t data_length GNUNET_PACKED;
-
- /* record flags */
- uint32_t flags GNUNET_PACKED;
-
- //Class of the record?
-
- /* followed by the record data */
-}
-
-/**
- * @brief a record block for a given name of a single authority
- */
-struct GNSNameRecordBlock
-{
-
- /**
- * GNUNET_RSA_Signature using RSA-key generated from the records.
- */
- struct GNUNET_CRYPTO_RsaSignature signature;
-
- /**
- * What is being signed and why?
- */
- struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
-
- /**
- * The public key of the authority
- */
- struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
-
- /* 0-terminated name here */
-
- /* number of records that follow */
- uint32_t rd_num GNUNET_PACKED;
-
- /* variable-size GNSRecordBlocks follows here */
-
-
-};
-
-GNUNET_NETWORK_STRUCT_END
-#endif
* operation that expects a reply
*
* @param cls closure
- * @param exp when will this value expire
- * @param key key of the result
- * @param get_path peers on reply path (or NULL if not recorded)
- * @param get_path_length number of entries in get_path
- * @param put_path peers on the PUT path (or NULL if not recorded)
- * @param put_path_length number of entries in get_path
- * @param type type of the result
- * @param size number of bytes in data
- * @param data pointer to the result data
+ * @param name name
+ * @param record a record
+ * @param num_records number of records
*/
static void
lookup_result_iterator (void *cls,
* Start DHT lookup for a name -> PKEY (compare NS) record in
* query->authority's zone
*
- * @param query the pending gns query
+ * @param rh the pending gns query
* @param name the name of the PKEY record
*/
void
* Start DHT lookup for a (name -> query->record_type) record in
* query->authority's zone
*
- * @param query the pending gns query
+ * @param rh the pending gns query context
* @param name the name to query record
*/
void
* @param expiration expiration date of the record data set in the namestore
* @param name the name for which we need an authority
* @param rd_count the number of records with 'name'
- * @param data the record data
+ * @param rd the record data
* @param signature the signature of the authority for the record data
*/
void
* @param expiration expiration date of the namestore entry
* @param name the name for which we need an authority
* @param rd_count the number of records with 'name'
- * @param data the record data
+ * @param rd the record data
* @param signature the signature of the authority for the record data
*/
static void
* If it is then try to resolve directly.
* If not then first have to resolve the authoritative entities.
*
- * @param query the pending lookup
+ * @param rh the pending lookup
* @param zone the zone we are currently resolving in
*/
void
*
* Setup a new query and try to resolve
*
- * @param rh the request handle of the DNS request from a client
+ * @param request the request handle of the DNS request from a client
* @param p the DNS query packet we received
* @param q the DNS query we received parsed from p
*/
size_t xquery_size, const void *reply_block,
size_t reply_block_size)
{
- if (type != GNUNET_BLOCK_TYPE_GNS_RECORD)
+ if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
+
+ struct GNUNET_CRYPTO_RsaSignature *signature;
+ struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose;
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key;
+ char* name;
+ GNUNET_HashCode pkey_hash;
+ GNUNET_HashCode query_pkey;
+ GNUNET_HashCode name_hash;
+
+ uint32_t rd_num;
+ uint32_t type;
+ struct GNUNET_TIME_AbsoluteNBO;
+ uint32_t data_length;
+ uint32_t flags;
+
+ char* pos = (char*) reply_block;
+ signature = pos;
+ pos += sizeof(struct GNUNET_CRYPTO_RsaSignature);
+ pos += sizeof(struct GNUNET_CRYPTO_RsaSignaturePurpose);
+
+ public_key = pos;
+ pos += sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);
+ name = pos;
+ pos += namelen(name); //Off by 1?
+
+ GNUNET_CRYPTO_hash(public_key,
+ sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &pkey_hash);
+
+ GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
+
+ GNUNET_CRYPTO_hash_xor(query, &name_hash, &query_pkey);
- //FIXME check signatures here
+ //Check query key against public key
+ if (0 != GNUNET_CRYPTO_hash_cmp(&query_pkey, &pkey_hash))
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+
+ rd_count = ntohl(*pos);
+ pos += sizeof(uint32_t);
+
+ struct GNUNET_NAMESTORE_RecordData rd[rd_count];
+ int i = 0;
+
+ for (i=0; i<rd_count; i++)
+ {
+ rd[i].type = ntohl(*pos);
+ pos += sizeof(uint32_t);
+ rd[i].expiration =
+ GNUNET_TIME_relative_ntoh(*((struct GNUNET_TIME_AbsoluteNBO*)pos));
+ pos += sizeof(struct GNUNET_TIME_AbsoluteNBO);
+ rd[i].data_length = ntohl(*pos);
+ pos += sizeof(uint32_t);
+ rd[i].flags = ntohl(*pos);
+ pos += sizeof(uint32_t);
+ rd[i].data = pos;
+ pos += rd[i].data_length;
+ }
+
+ if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (public_key,
+ name,
+ rd_count,
+ rd,
+ signature))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n");
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+ }
+
+ //Cache
+ GNUNET_NAMESTORE_record_put (handle, //FIXME where do i get this from?
+ &pkey_hash,
+ name,
+ expiration, //FIXME uh where do i get this from?
+ rd_count,
+ rd,
+ signature,
+ NULL, //cont
+ NULL); //cls
return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
}
--- /dev/null
+/*
+ This file is part of GNUnet.
+ (C) 2012 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file include/block_gns.h
+ * @brief fs block formats (shared between fs and block)
+ * @author Martin Schanzenbach
+ */
+#ifndef BLOCK_GNS_H
+#define BLOCK_GNS_H
+
+#include "gnunet_util_lib.h"
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * @brief a simgle record inside a record block
+ */
+struct GNSRecordBlock
+{
+ /**
+ * the record type
+ */
+ uint32_t type GNUNET_PACKED;
+
+ /**
+ * expiration time of the record
+ */
+ struct GNUNET_TIME_AbsoluteNBO expiration;
+
+ /**
+ * length of the data
+ */
+ uint32_t data_length GNUNET_PACKED;
+
+ /* record flags */
+ uint32_t flags GNUNET_PACKED;
+
+ //Class of the record?
+
+ /* followed by the record data */
+}
+
+/**
+ * @brief a record block for a given name of a single authority
+ */
+struct GNSNameRecordBlock
+{
+
+ /**
+ * GNUNET_RSA_Signature using RSA-key generated from the records.
+ */
+ struct GNUNET_CRYPTO_RsaSignature signature;
+
+ /**
+ * What is being signed and why?
+ */
+ struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
+
+ /**
+ * The public key of the authority
+ */
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
+
+ /* 0-terminated name here */
+
+ /* number of records that follow */
+ uint32_t rd_num GNUNET_PACKED;
+
+ /* variable-size GNSRecordBlocks follows here */
+
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+#endif
* @param handle handle to the GNS service
* @param timeout how long to wait for transmission of this request to the service
* // FIXME: what happens afterwards?
- * @param type expected type of the response object
+ * @param handle handle to the GNS service
+ * @param timeout timeout of request
* @param name the name to look up
* @param type the GNUNET_GNS_RecordType to look for
* @param iter function to call on each result
* @param iter_cls closure for iter
*
- * @return handle to stop the async get
+ * @return handle to stop the async lookup
*/
struct GNUNET_GNS_LookupHandle *
GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,