Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed (hopefully) all literal 0xfc prefix checks

  • Loading branch information...
commit 920e908a339e9d93b3c0f17a4de1ab65f0aff10a 1 parent fb67b28
@marcuswanner marcuswanner authored
View
3  admin/angel/Core.c
@@ -23,6 +23,7 @@
#include "benc/Int.h"
#include "benc/serialization/BencSerializer.h"
#include "benc/serialization/standard/StandardBencSerializer.h"
+#include "crypto/AddressCalc.h"
#include "crypto/Random.h"
#include "dht/ReplyModule.h"
#include "dht/SerializationModule.h"
@@ -93,7 +94,7 @@ static void parsePrivateKey(uint8_t privateKey[32],
{
crypto_scalarmult_curve25519_base(addr->key, privateKey);
AddressCalc_addressForPublicKey(addr->ip6.bytes, addr->key);
- if (addr->ip6.bytes[0] != 0xFC) {
+ if (!AddressCalc_validAddress(addr->ip6.bytes)) {
Except_raise(eh, -1, "Ip address outside of the FC00/8 range, invalid private key.");
}
}
View
2  crypto/Key.c
@@ -48,7 +48,7 @@ int Key_parse(String* key, uint8_t keyBytesOut[32], uint8_t ip6Out[16])
}
if (ip6Out) {
AddressCalc_addressForPublicKey(ip6Out, keyBytesOut);
- if (ip6Out[0] != 0xfc) {
+ if (!AddressCalc_validAddress(ip6Out)) {
return Key_parse_INVALID;
}
}
View
3  dht/dhtcore/NodeStore.c
@@ -21,6 +21,7 @@
#include "benc/Dict.h"
#include "benc/String.h"
#include "benc/Object.h"
+#include "crypto/AddressCalc.h"
#include "dht/Address.h"
#include "dht/CJDHTConstants.h"
#include "dht/dhtcore/DistanceNodeCollector.h"
@@ -155,7 +156,7 @@ struct Node* NodeStore_addNode(struct NodeStore* store,
printf("got introduced to ourselves\n");
return NULL;
}
- if (addr->ip6.bytes[0] != 0xfc) {
+ if (!AddressCalc_validAddress(addr->ip6.bytes)) {
uint8_t address[60];
Address_print(address, addr);
Log_critical(store->logger,
View
3  dht/dhtcore/RouterModule.c
@@ -16,6 +16,7 @@
#include "benc/Int.h"
#include "benc/Object.h"
+#include "crypto/AddressCalc.h"
#include "dht/Address.h"
#include "dht/dhtcore/Janitor.h"
#include "dht/dhtcore/RouterModule_pvt.h"
@@ -823,7 +824,7 @@ static inline int handleReply(struct DHTMessage* message, struct RouterModule* m
}
uint32_t newNodePrefix = Address_getPrefix(&addr);
- if (addr.ip6.bytes[0] != 0xfc) {
+ if (!AddressCalc_validAddress(addr.ip6.bytes)) {
Log_debug(module->logger, "Was told garbage.\n");
// This should never happen, badnode.
break;
View
3  net/DefaultInterfaceController.c
@@ -12,6 +12,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "crypto/AddressCalc.h"
#include "crypto/CryptoAuth_pvt.h"
#include "net/DefaultInterfaceController.h"
#include "memory/Allocator.h"
@@ -410,7 +411,7 @@ static struct Endpoint* insertEndpoint(uint8_t key[InterfaceController_KEY_SIZE]
uint8_t ip6[16];
if (herPublicKey) {
AddressCalc_addressForPublicKey(ip6, herPublicKey);
- if (ip6[0] != 0xfc) {
+ if (!AddressCalc_validAddress(ip6)) {
return NULL;
}
}
View
9 net/Ducttape.c
@@ -12,6 +12,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "crypto/AddressCalc.h"
#include "crypto/CryptoAuth.h"
#include "util/log/Log.h"
#include "dht/Address.h"
@@ -385,8 +386,8 @@ static inline bool validEncryptedIP6(struct Message* message)
struct Headers_IP6Header* header = (struct Headers_IP6Header*) message->bytes;
// Empty ipv6 headers are tolerated at this stage but dropped later.
return message->length >= Headers_IP6Header_SIZE
- && header->sourceAddr[0] == 0xFC
- && header->destinationAddr[0] == 0xFC;
+ && AddressCalc_validAddress(header->sourceAddr)
+ && AddressCalc_validAddress(header->destinationAddr);
}
static inline bool isForMe(struct Message* message, struct Ducttape_pvt* context)
@@ -403,7 +404,7 @@ static inline uint8_t incomingFromTun(struct Message* message,
struct Headers_IP6Header* header = (struct Headers_IP6Header*) message->bytes;
int version = Headers_getIpVersion(message->bytes);
- if (version == 4 || (version == 6 && header->sourceAddr[0] != 0xfc)) {
+ if (version == 4 || (version == 6 && !AddressCalc_validAddress(header->sourceAddr))) {
return context->ipTunnel->tunInterface.sendMessage(message,
&context->ipTunnel->tunInterface);
} else if (version != 6) {
@@ -905,7 +906,7 @@ static inline uint8_t* extractPublicKey(struct Message* message,
}
AddressCalc_addressForPublicKey(ip6, caHeader->handshake.publicKey);
- if (ip6[0] != 0xfc) {
+ if (!AddressCalc_validAddress(ip6)) {
*version = *version - 1;
return extractPublicKey(message, version, ip6);
}
Please sign in to comment.
Something went wrong with that request. Please try again.