diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-26 17:05:46 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-26 17:05:46 +0000 |
commit | 94973bee7b04e2cc9682d3ffb5b5dd65c87490aa (patch) | |
tree | 1303849e17eca0a8ebb3d3695c5748e23308705f /src | |
parent | 9935335d2d685592c0dd3543a9ef7c37b06f67e8 (diff) | |
download | gnunet-94973bee7b04e2cc9682d3ffb5b5dd65c87490aa.tar.gz gnunet-94973bee7b04e2cc9682d3ffb5b5dd65c87490aa.zip |
- use cstruct
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/plugin_block_gns.c | 41 | ||||
-rw-r--r-- | src/include/block_gns.h | 4 |
2 files changed, 18 insertions, 27 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 1a33b2d1a..7bf4e29cd 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -64,13 +64,13 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
64 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | 64 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) |
65 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 65 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
66 | 66 | ||
67 | struct GNUNET_CRYPTO_RsaSignature *signature; | ||
68 | struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose; | ||
69 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key; | 67 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key; |
70 | char* name; | 68 | char* name; |
71 | GNUNET_HashCode pkey_hash; | 69 | GNUNET_HashCode pkey_hash; |
72 | GNUNET_HashCode query_pkey; | 70 | GNUNET_HashCode query_pkey; |
73 | GNUNET_HashCode name_hash; | 71 | GNUNET_HashCode name_hash; |
72 | struct GNSNameRecordBlock *nrb; | ||
73 | struct GNSRecordBlock *rb; | ||
74 | 74 | ||
75 | uint32_t rd_num; | 75 | uint32_t rd_num; |
76 | uint32_t type; | 76 | uint32_t type; |
@@ -79,16 +79,11 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
79 | uint32_t flags; | 79 | uint32_t flags; |
80 | 80 | ||
81 | char* pos = (char*) reply_block; | 81 | char* pos = (char*) reply_block; |
82 | signature = pos; | 82 | nrb = reply_block; |
83 | pos += sizeof(struct GNUNET_CRYPTO_RsaSignature); | ||
84 | pos += sizeof(struct GNUNET_CRYPTO_RsaSignaturePurpose); | ||
85 | 83 | ||
86 | public_key = pos; | 84 | name = &nrb[1]; |
87 | pos += sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); | ||
88 | name = pos; | ||
89 | pos += namelen(name); //Off by 1? | ||
90 | 85 | ||
91 | GNUNET_CRYPTO_hash(public_key, | 86 | GNUNET_CRYPTO_hash(nrb->public_key, |
92 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 87 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
93 | &pkey_hash); | 88 | &pkey_hash); |
94 | 89 | ||
@@ -100,32 +95,28 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
100 | if (0 != GNUNET_CRYPTO_hash_cmp(&query_pkey, &pkey_hash)) | 95 | if (0 != GNUNET_CRYPTO_hash_cmp(&query_pkey, &pkey_hash)) |
101 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 96 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; |
102 | 97 | ||
103 | rd_count = ntohl(*pos); | 98 | rd_count = ntohl(nrb->rd_num); |
104 | pos += sizeof(uint32_t); | ||
105 | 99 | ||
106 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; | 100 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; |
107 | int i = 0; | 101 | int i = 0; |
102 | rb = &nrb[1] + strlen(name); | ||
108 | 103 | ||
109 | for (i=0; i<rd_count; i++) | 104 | for (i=0; i<rd_count; i++) |
110 | { | 105 | { |
111 | rd[i].type = ntohl(*pos); | 106 | rd[i].type = ntohl(rb->type); |
112 | pos += sizeof(uint32_t); | ||
113 | rd[i].expiration = | 107 | rd[i].expiration = |
114 | GNUNET_TIME_relative_ntoh(*((struct GNUNET_TIME_AbsoluteNBO*)pos)); | 108 | GNUNET_TIME_relative_ntoh(rb->expiration); |
115 | pos += sizeof(struct GNUNET_TIME_AbsoluteNBO); | 109 | rd[i].data_length = ntohl(rb->data_length); |
116 | rd[i].data_length = ntohl(*pos); | 110 | rd[i].flags = ntohl(rb->flags); |
117 | pos += sizeof(uint32_t); | 111 | rd[i].data = rb[1]; |
118 | rd[i].flags = ntohl(*pos); | 112 | rb = &rb[1] + rd[i].data_length; |
119 | pos += sizeof(uint32_t); | ||
120 | rd[i].data = pos; | ||
121 | pos += rd[i].data_length; | ||
122 | } | 113 | } |
123 | 114 | ||
124 | if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (public_key, | 115 | if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (nrb->public_key, |
125 | name, | 116 | name, |
126 | rd_count, | 117 | nrb->rd_count, |
127 | rd, | 118 | rd, |
128 | signature)) | 119 | nrb->signature)) |
129 | { | 120 | { |
130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n"); | 121 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n"); |
131 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 122 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; |
diff --git a/src/include/block_gns.h b/src/include/block_gns.h index d34e33c5d..99f019a11 100644 --- a/src/include/block_gns.h +++ b/src/include/block_gns.h | |||
@@ -79,11 +79,11 @@ struct GNSNameRecordBlock | |||
79 | */ | 79 | */ |
80 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; | 80 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; |
81 | 81 | ||
82 | /* 0-terminated name here */ | ||
83 | |||
84 | /* number of records that follow */ | 82 | /* number of records that follow */ |
85 | uint32_t rd_num GNUNET_PACKED; | 83 | uint32_t rd_num GNUNET_PACKED; |
86 | 84 | ||
85 | /* 0-terminated name here */ | ||
86 | |||
87 | /* variable-size GNSRecordBlocks follows here */ | 87 | /* variable-size GNSRecordBlocks follows here */ |
88 | 88 | ||
89 | 89 | ||