Пример #1
0
ya_result
output_stream_decode_base32hex(output_stream* os, const char * string, u32 length)
{
    char buffer[64];
    u8 buffer_bin[40];

    u32 needle = 0;

    ya_result return_code = OK;

    /*    ------------------------------------------------------------    */

    while(length-- > 0)
    {
        char c = *string++;

        if(isspace(c))
        {
            continue;
        }

        buffer[needle++] = c;

        if(needle == sizeof (buffer))
        {
            if(FAIL(return_code = base32hex_decode(buffer, needle, buffer_bin)))
            {
                return return_code;
            }

            if(FAIL(return_code = output_stream_write(os, buffer_bin, return_code)))
            {
                return return_code;
            }

            needle = 0;
        }
    }

    if(needle > 0)
    {
        if((needle & 7) != 0)
        {
            return PARSEB32H_ERROR;
        }

        if(FAIL(return_code = base32hex_decode(buffer, needle, buffer_bin)))
        {
            return return_code;
        }

        if(FAIL(return_code = output_stream_write(os, buffer_bin, return_code)))
        {
            return return_code;
        }
    }

    return return_code;
}
Пример #2
0
void
nsec3_remove_rrsig(zdb_zone* zone, zdb_packed_ttlrdata* nsec3param)
{
    nsec3_zone* n3 = zone->nsec.nsec3;

    while(n3 != NULL)
    {
        if(nsec3_zone_rdata_compare(n3->rdata, nsec3param->rdata_start) == 0)
        {
            u8 digest[256];

            ya_result digest_len = base32hex_decode((char*)&nsec3param->rdata_start[1], (u32)nsec3param->rdata_start[0], digest);

            if(ISOK(digest_len))
            {
                digest[0] = digest_len;

                nsec3_zone_item* item = nsec3_avl_find(&n3->items, digest);

                if(item != NULL)
                {
                    nsec3_zone_item_rrsig_delete_all(item);
                }
            }

            break;
        }

        n3 = n3->next;
    }
}
Пример #3
0
nsec3_zone_item*
nsec3_get_nsec3_by_name(zdb_zone* zone, const u8 *nsec3_label, const u8* nsec3_rdata)
{
    nsec3_zone* n3 = zone->nsec.nsec3;

    while(n3 != NULL)
    {
        if(nsec3_zone_rdata_compare(n3->rdata, nsec3_rdata) == 0)
        {
            u8 digest[256];

#ifndef NDEBUG
            memset(digest, 0xd1, sizeof(digest));
#endif

            ya_result digest_len = base32hex_decode((char*)&nsec3_label[1], nsec3_label[0], &digest[1]);

            if(ISOK(digest_len))
            {
                digest[0] = digest_len;

                nsec3_zone_item* item = nsec3_avl_find(&n3->items, digest);

                return item;
            }

            break;
        }

        n3 = n3->next;
    }

    return NULL;
}
Пример #4
0
ya_result
nsec3_load_add_rrsig(nsec3_load_context *context, const  u8 *digest_label, s32 ttl, const u8 *rdata, u16 rdata_size)
{
    u8 digest_len = BASE32HEX_DECODED_LEN(digest_label[0]);
    u8 digest[digest_len + 1];
    digest[0] = digest_len;
    if(ISOK(base32hex_decode((const char*)&digest_label[1], digest_label[0], &digest[1])))
    {
        zdb_packed_ttlrdata *rrsig;
        ZDB_RECORD_ZALLOC(rrsig,ttl,rdata_size,rdata);
                
        if(context->last_inserted_nsec3 != NULL)
        {
            nsec3_context_record* nsec3_r = (nsec3_context_record*)context->last_inserted_nsec3;
            if(memcmp(nsec3_r->digest_then_rdata, digest, 1 + digest[0]) == 0)
            {
                rrsig->next = nsec3_r->rrsig;
                nsec3_r->rrsig = rrsig;
                
                return SUCCESS;
            }
        }
        
        // the records are not nicely ordered : need to postpone the insertion of this record.
        
        ptr_node *node = ptr_set_avl_insert(&context->postponed_rrsig, digest);
                
        if(node->value == NULL)
        {
            u8 *key;
            ZALLOC_ARRAY_OR_DIE(u8*, key, digest_len + 1, N3LKEYDG_TAG);
            memcpy(key, digest, digest_len + 1);
            node->key = key;
        }
Пример #5
0
static nsec3_context_record*
nsec3_load_context_record_new(const u8 *digest, s32 ttl, const u8 *rdata, u16 rdata_size)
{
    u8 digest_len = BASE32HEX_DECODED_LEN(digest[0]);
 
    nsec3_context_record* record;
        
    ZALLOC_ARRAY_OR_DIE(nsec3_context_record*, record, sizeof(nsec3_context_record) + 1 + digest_len + rdata_size, N3LCTXRR_TAG);
    record->rrsig = NULL;
    record->ttl = ttl;
    record->rdata_size = rdata_size;
    
    //memcpy(&record->digest_then_rdata[0], digest, digest_len);
    record->digest_then_rdata[0] = digest_len;
    
    if(ISOK(base32hex_decode((const char*)&digest[1], digest[0], &record->digest_then_rdata[1])))
    {
        memcpy(&record->digest_then_rdata[digest_len + 1], rdata, rdata_size);    
        return record;
    }
    else
    {
        nsec3_load_context_record_delete(record);
        return NULL;
    }
}
Пример #6
0
void
nsec3_add_nsec3_by_name(zdb_zone* zone, const u8 *nsec3_label, const u8* nsec3_rdata, u16 nsec3_rdata_size)
{
    nsec3_zone* n3 = zone->nsec.nsec3;

    while(n3 != NULL)
    {
        if(nsec3_zone_rdata_compare(n3->rdata, nsec3_rdata) == 0)
        {
            u8 digest[256];

#ifndef NDEBUG
            memset(digest, 0xd1, sizeof(digest));
#endif

            ya_result digest_len = base32hex_decode((char*)&nsec3_label[1], nsec3_label[0], &digest[1]);

            if(ISOK(digest_len))
            {
                digest[0] = digest_len;

                nsec3_zone_item* item = nsec3_avl_find(&n3->items, digest);

                if(item == NULL)
                {
                    nsec3_zone_item *self = nsec3_avl_insert(&n3->items, (u8*)digest);
                    
                    self->flags = nsec3_rdata[1];
                    /*
                    self->rc = 0;
                    self->sc = 0;

                    self->type_bit_maps = NULL;
                    self->type_bit_maps_size = 0;
                    */
                    nsec3_zone_item_update_bitmap(self, nsec3_rdata, nsec3_rdata_size);
                }
                else
                {
                    /* exists already */
                    assert(FALSE);
                }
            }

            break;
        }

        n3 = n3->next;
    }
}
Пример #7
0
static void test_base32_random(void)
{
	string_t *str, *dest;
	char buf[10];
	unsigned int i, j, max;

	str = t_str_new(256);
	dest = t_str_new(256);

	test_begin("padded base32 encode/decode with random input");
	for (i = 0; i < 1000; i++) {
		max = rand() % sizeof(buf);
		for (j = 0; j < max; j++)
			buf[j] = rand();

		str_truncate(str, 0);
		str_truncate(dest, 0);
		base32_encode(TRUE, buf, max, str);
		test_assert(base32_decode(str_data(str), str_len(str), NULL, dest) >= 0);
		test_assert(str_len(dest) == max &&
			    memcmp(buf, str_data(dest), max) == 0);
	}
	test_end();

	test_begin("padded base32hex encode/decode with random input");
	for (i = 0; i < 1000; i++) {
		max = rand() % sizeof(buf);
		for (j = 0; j < max; j++)
			buf[j] = rand();

		str_truncate(str, 0);
		str_truncate(dest, 0);
		base32hex_encode(TRUE, buf, max, str);
		test_assert(base32hex_decode(str_data(str), str_len(str), NULL, dest) >= 0);
		test_assert(str_len(dest) == max &&
			    memcmp(buf, str_data(dest), max) == 0);
	}
	test_end();
}
Пример #8
0
void
nsec3_remove_nsec3_by_name(zdb_zone* zone, const u8 *nsec3_label, const u8* nsec3_rdata)
{
    nsec3_zone* n3 = zone->nsec.nsec3;

    while(n3 != NULL)
    {
        if(nsec3_zone_rdata_compare(n3->rdata, nsec3_rdata) == 0)
        {
            u8 digest[256];

#ifndef NDEBUG
            memset(digest, 0xd1, sizeof(digest));
#endif

            ya_result digest_len = base32hex_decode((char*)&nsec3_label[1], nsec3_label[0], &digest[1]);
            
            if(ISOK(digest_len))
            {
                digest[0] = digest_len;

                nsec3_zone_item* item = nsec3_avl_find(&n3->items, digest);

                if(item != NULL)
                {
                    int depth;

                    log_debug("nsec3_remove_nsec3_by_name: destroying %{digest32h}", item->digest);

					/*
					GOT IT : AN NSEC3 RECORD IS REMOVED BY IXFR BUT THE LABEL HAS NOT BEEN CHANGED
					I PRESUME IT IS BECAUSE THE AXFR CHAIN IS CHANGED
					I NEED A REPLACE FUNCTION, I NEED TO SORT THE IXFR NSEC(3) OPERATIONS
					*/

                    if(item->sc > 0)
                    {
                        nsec3_zone_item* prev = nsec3_avl_node_mod_prev(item);
                        if(prev != NULL)
                        {
                            nsec3_move_all_star(item, prev);
                        }
                        else
                        {
                            nsec3_remove_all_star(item);
                        }
                    }
                    nsec3_remove_all_owners(item);

                    zassert(item->rc == 0 && item->sc == 0);

                    ZFREE_ARRAY(item->type_bit_maps, item->type_bit_maps_size);

                    item->type_bit_maps = NULL;
                    item->type_bit_maps_size = 0;

                    nsec3_zone_item_rrsig_delete_all(item);

                    nsec3_avl_delete(&n3->items, item->digest);

                }
            }

            break;
        }

        n3 = n3->next;
    }
}