Helps visualize where I'm headed.
fort_SOURCES += types/delta.c types/delta.h
fort_SOURCES += types/router_key.c types/router_key.h
fort_SOURCES += types/serial.h types/serial.c
-fort_SOURCES += types/uri.h types/uri.c
+fort_SOURCES += types/map.h types/map.c
fort_SOURCES += types/vrp.c types/vrp.h
fort_SOURCES += cache/local_cache.c cache/local_cache.h
eof: end of file
err: error
fd: File Descriptor (see `man 2 accept`)
-guri: global URI
hdr: header
hh: hash (table) hook
ht: hash table
#include "rsync/rsync.h"
struct cache_node {
- struct rpki_uri *url;
+ struct cache_mapping *map;
struct {
time_t ts; /* Last download attempt's timestamp */
{
struct cache_node *node;
char const *type_str;
- enum uri_type type;
+ enum map_type type;
char const *url;
json_t *notif;
int error;
}
if (strcmp(type_str, TYPEVALUE_TA_RSYNC) == 0)
- type = UT_TA_RSYNC;
+ type = MAP_TA_RSYNC;
else if (strcmp(type_str, TYPEVALUE_TA_HTTP) == 0)
- type = UT_TA_HTTP;
+ type = MAP_TA_HTTP;
else if (strcmp(type_str, TYPEVALUE_RPP) == 0)
- type = UT_RPP;
+ type = MAP_RPP;
else if (strcmp(type_str, TYPEVALUE_NOTIF) == 0)
- type = UT_NOTIF;
+ type = MAP_NOTIF;
else {
pr_op_err("Unknown node type: %s", type_str);
goto fail;
goto fail;
}
- if (type == UT_NOTIF) {
+ if (type == MAP_NOTIF) {
error = json_get_object(json, TAGNAME_NOTIF, ¬if);
switch (error) {
case 0:
}
}
- error = uri_create(&node->url, type, NULL, url);
+ error = map_create(&node->map, type, NULL, url);
if (error) {
pr_op_err("Cannot parse '%s' into a URI.", url);
goto fail;
return node;
fail:
- uri_refput(node->url);
+ map_refput(node->map);
rrdp_notif_free(node->notif);
free(node);
return NULL;
}
static struct cache_node *
-find_node(struct rpki_cache *cache, struct rpki_uri *uri)
+find_node(struct rpki_cache *cache, struct cache_mapping *map)
{
char const *key;
struct cache_node *result;
- key = uri_get_global(uri);
+ key = map_get_url(map);
HASH_FIND_STR(cache->ht, key, result);
return result;
static void
add_node(struct rpki_cache *cache, struct cache_node *node)
{
- char const *key = uri_get_global(node->url);
+ char const *key = map_get_url(node->map);
size_t keylen = strlen(key);
HASH_ADD_KEYPTR(hh, cache->ht, key, keylen, node);
}
if (json == NULL)
return NULL;
- switch (uri_get_type(node->url)) {
- case UT_TA_RSYNC:
+ switch (map_get_type(node->map)) {
+ case MAP_TA_RSYNC:
type = TYPEVALUE_TA_RSYNC;
break;
- case UT_TA_HTTP:
+ case MAP_TA_HTTP:
type = TYPEVALUE_TA_HTTP;
break;
- case UT_RPP:
+ case MAP_RPP:
type = TYPEVALUE_RPP;
break;
- case UT_NOTIF:
+ case MAP_NOTIF:
type = TYPEVALUE_NOTIF;
break;
default:
if (json_add_str(json, TAGNAME_TYPE, type))
goto cancel;
- if (json_add_str(json, TAGNAME_URL, uri_get_global(node->url)))
+ if (json_add_str(json, TAGNAME_URL, map_get_url(node->map)))
goto cancel;
if (node->notif != NULL) {
notification = rrdp_notif2json(node->notif);
child = node2json(node);
if (child != NULL && json_array_append_new(root, child)) {
pr_op_err("Cannot push %s json node into json root; unknown cause.",
- uri_op_get_printable(node->url));
+ map_op_get_printable(node->map));
continue;
}
}
}
static int
-get_url(struct rpki_uri *uri, struct rpki_uri **url)
+fix_url(struct cache_mapping *map, struct cache_mapping **result)
{
- char const *guri, *c;
- char *gcopy;
+ char const *url, *c;
+ char *dup;
unsigned int slashes;
int error;
- if (uri_get_type(uri) != UT_RPP)
- goto reuse_uri;
+ if (map_get_type(map) != MAP_RPP)
+ goto reuse_mapping;
/*
* Careful with this code. rsync(1):
* not every RPP separately. The former is much faster.
*/
- guri = uri_get_global(uri);
+ url = map_get_url(map);
slashes = 0;
- for (c = guri; *c != '\0'; c++) {
+ for (c = url; *c != '\0'; c++) {
if (*c == '/') {
slashes++;
if (slashes == 4) {
if (c[1] == '\0')
- goto reuse_uri;
- gcopy = pstrndup(guri, c - guri + 1);
- goto gcopy2url;
+ goto reuse_mapping;
+ dup = pstrndup(url, c - url + 1);
+ goto dup2url;
}
}
}
if (slashes == 3 && c[-1] != '/') {
- gcopy = pmalloc(c - guri + 2);
- memcpy(gcopy, guri, c - guri);
- gcopy[c - guri] = '/';
- gcopy[c - guri + 1] = '\0';
- goto gcopy2url;
+ dup = pmalloc(c - url + 2);
+ memcpy(dup, url, c - url);
+ dup[c - url] = '/';
+ dup[c - url + 1] = '\0';
+ goto dup2url;
}
return pr_val_err("Can't rsync URL '%s': The URL seems to be missing a domain or rsync module.",
- guri);
+ url);
-reuse_uri:
- uri_refget(uri);
- *url = uri;
+reuse_mapping:
+ map_refget(map);
+ *result = map;
return 0;
-gcopy2url:
- error = uri_create(url, UT_RPP, NULL, gcopy);
- free(gcopy);
+dup2url:
+ error = map_create(result, MAP_RPP, NULL, dup);
+ free(dup);
return error;
}
}
static int
-cache_check(struct rpki_uri *url)
+cache_check(struct cache_mapping *url)
{
int error;
- error = file_exists(uri_get_local(url));
+ error = file_exists(map_get_path(url));
switch (error) {
case 0:
pr_val_debug("Offline mode, file is cached.");
* @changed can be NULL.
*/
int
-cache_download(struct rpki_cache *cache, struct rpki_uri *uri, bool *changed,
- struct cachefile_notification ***notif)
+cache_download(struct rpki_cache *cache, struct cache_mapping *map,
+ bool *changed, struct cachefile_notification ***notif)
{
- struct rpki_uri *url;
+ struct cache_mapping *map2;
struct cache_node *node;
int error;
if (changed != NULL)
*changed = false;
- error = get_url(uri, &url);
+ error = fix_url(map, &map2);
if (error)
return error;
- node = find_node(cache, url);
+ node = find_node(cache, map2);
if (node != NULL) {
if (was_recently_downloaded(cache, node)) {
error = node->attempt.result;
}
} else {
node = pzalloc(sizeof(struct cache_node));
- node->url = url;
- uri_refget(url);
+ node->map = map2;
+ map_refget(map2);
add_node(cache, node);
}
- switch (uri_get_type(url)) {
- case UT_TA_HTTP:
- case UT_NOTIF:
- case UT_TMP:
+ switch (map_get_type(map2)) {
+ case MAP_TA_HTTP:
+ case MAP_NOTIF:
+ case MAP_TMP:
error = config_get_http_enabled()
- ? http_download(url, node->success.ts, changed)
- : cache_check(url);
+ ? http_download(map2, node->success.ts, changed)
+ : cache_check(map2);
break;
- case UT_TA_RSYNC:
- case UT_RPP:
+ case MAP_TA_RSYNC:
+ case MAP_RPP:
error = config_get_rsync_enabled()
- ? rsync_download(uri_get_global(url), uri_get_local(url), true)
- : cache_check(url);
+ ? rsync_download(map_get_url(map2), map_get_path(map2), true)
+ : cache_check(map2);
break;
default:
- pr_crit("URI type not downloadable: %d", uri_get_type(url));
+ pr_crit("Mapping type not downloadable: %d", map_get_type(map2));
}
node->attempt.ts = time(NULL);
}
end:
- uri_refput(url);
+ map_refput(map2);
if (!error && (notif != NULL))
*notif = &node->notif;
return error;
}
static int
-download(struct rpki_cache *cache, struct rpki_uri *uri, uris_dl_cb cb, void *arg)
+download(struct rpki_cache *cache, struct cache_mapping *map, maps_dl_cb cb,
+ void *arg)
{
int error;
- pr_val_debug("Trying URL %s...", uri_get_global(uri));
+ pr_val_debug("Trying URL %s...", map_get_url(map));
- switch (uri_get_type(uri)) {
- case UT_TA_HTTP:
- case UT_TA_RSYNC:
- case UT_RPP:
- error = cache_download(cache, uri, NULL, NULL);
+ switch (map_get_type(map)) {
+ case MAP_TA_HTTP:
+ case MAP_TA_RSYNC:
+ case MAP_RPP:
+ error = cache_download(cache, map, NULL, NULL);
break;
- case UT_NOTIF:
- error = rrdp_update(uri);
+ case MAP_NOTIF:
+ error = rrdp_update(map);
break;
default:
- pr_crit("URI type is not a legal alt candidate: %u", uri_get_type(uri));
+ pr_crit("Mapping type is not a legal alt candidate: %u",
+ map_get_type(map));
}
- return error ? 1 : cb(uri, arg);
+ return error ? 1 : cb(map, arg);
}
static int
-download_uris(struct rpki_cache *cache, struct uri_list *uris,
- enum uri_type type, uris_dl_cb cb, void *arg)
+download_maps(struct rpki_cache *cache, struct map_list *maps,
+ enum map_type type, maps_dl_cb cb, void *arg)
{
- struct rpki_uri **uri;
+ struct cache_mapping **map;
int error;
- ARRAYLIST_FOREACH(uris, uri) {
- if (uri_get_type(*uri) == type) {
- error = download(cache, *uri, cb, arg);
+ ARRAYLIST_FOREACH(maps, map) {
+ if (map_get_type(*map) == type) {
+ error = download(cache, *map, cb, arg);
if (error <= 0)
return error;
}
}
/**
- * Assumes all the URIs are URLs, and represent different ways to access the
- * same content.
+ * Assumes the mappings represent different ways to access the same content.
*
* Sequentially (in the order dictated by their priorities) attempts to update
- * (in the cache) the content pointed by each URL.
+ * (in the cache) the content pointed by each mapping's URL.
* If a download succeeds, calls cb on it. If cb succeeds, returns without
* trying more URLs.
*
* that's already cached, and callbacks it.
*/
int
-cache_download_alt(struct rpki_cache *cache, struct uri_list *uris,
- enum uri_type http_type, enum uri_type rsync_type, uris_dl_cb cb, void *arg)
+cache_download_alt(struct rpki_cache *cache, struct map_list *maps,
+ enum map_type http_type, enum map_type rsync_type, maps_dl_cb cb, void *arg)
{
- struct rpki_uri **cursor, *uri;
+ struct cache_mapping **cursor, *map;
int error;
if (config_get_http_priority() > config_get_rsync_priority()) {
- error = download_uris(cache, uris, http_type, cb, arg);
+ error = download_maps(cache, maps, http_type, cb, arg);
if (error <= 0)
return error;
- error = download_uris(cache, uris, rsync_type, cb, arg);
+ error = download_maps(cache, maps, rsync_type, cb, arg);
if (error <= 0)
return error;
} else if (config_get_http_priority() < config_get_rsync_priority()) {
- error = download_uris(cache, uris, rsync_type, cb, arg);
+ error = download_maps(cache, maps, rsync_type, cb, arg);
if (error <= 0)
return error;
- error = download_uris(cache, uris, http_type, cb, arg);
+ error = download_maps(cache, maps, http_type, cb, arg);
if (error <= 0)
return error;
} else {
- ARRAYLIST_FOREACH(uris, cursor) {
+ ARRAYLIST_FOREACH(maps, cursor) {
error = download(cache, *cursor, cb, arg);
if (error <= 0)
return error;
}
}
- uri = cache_recover(cache, uris);
- return (uri != NULL) ? cb(uri, arg) : ESRCH;
+ map = cache_recover(cache, maps);
+ return (map != NULL) ? cb(map, arg) : ESRCH;
}
/*
return (difftime(old->success.ts, new->success.ts) < 0) ? new : old;
}
-struct uri_and_node {
- struct rpki_uri *uri;
+struct map_and_node {
+ struct cache_mapping *map;
struct cache_node *node;
};
/* Separated because of unit tests. */
static void
-__cache_recover(struct rpki_cache *cache, struct uri_list *uris,
- struct uri_and_node *best)
+__cache_recover(struct rpki_cache *cache, struct map_list *maps,
+ struct map_and_node *best)
{
- struct rpki_uri **uri;
- struct rpki_uri *url;
- struct uri_and_node cursor;
+ struct cache_mapping **map;
+ struct cache_mapping *fixed;
+ struct map_and_node cursor;
- ARRAYLIST_FOREACH(uris, uri) {
- cursor.uri = *uri;
+ ARRAYLIST_FOREACH(maps, map) {
+ cursor.map = *map;
- if (get_url(cursor.uri, &url) != 0)
+ if (fix_url(cursor.map, &fixed) != 0)
continue;
- cursor.node = find_node(cache, url);
- uri_refput(url);
+ cursor.node = find_node(cache, fixed);
+ map_refput(fixed);
if (cursor.node == NULL)
continue;
}
}
-struct rpki_uri *
-cache_recover(struct rpki_cache *cache, struct uri_list *uris)
+struct cache_mapping *
+cache_recover(struct rpki_cache *cache, struct map_list *maps)
{
- struct uri_and_node best = { 0 };
- __cache_recover(cache, uris, &best);
- return best.uri;
+ struct map_and_node best = { 0 };
+ __cache_recover(cache, maps, &best);
+ return best.map;
}
void
HASH_ITER(hh, cache->ht, node, tmp)
printf("- %s (%s): %ssuccess error:%d\n",
- uri_get_local(node->url),
- uri_get_global(node->url),
+ map_get_path(node->map),
+ map_get_url(node->map),
node->success.happened ? "" : "!",
node->attempt.result);
}
delete_node(struct rpki_cache *cache, struct cache_node *node)
{
HASH_DEL(cache->ht, node);
- uri_refput(node->url);
+ map_refput(node->map);
rrdp_notif_free(node->notif);
free(node);
}
static void
delete_node_and_cage(struct rpki_cache *cache, struct cache_node *node)
{
- struct rpki_uri *cage;
+ struct cache_mapping *cage;
- if (uri_get_type(node->url) == UT_NOTIF) {
- if (uri_create_cage(&cage, node->url) == 0) {
- pr_op_debug("Deleting cage %s.", uri_get_local(cage));
- file_rm_rf(uri_get_local(cage));
- uri_refput(cage);
+ if (map_get_type(node->map) == MAP_NOTIF) {
+ if (map_create_cage(&cage, node->map) == 0) {
+ pr_op_debug("Deleting cage %s.", map_get_path(cage));
+ file_rm_rf(map_get_path(cage));
+ map_refput(cage);
}
}
static void
cleanup_tmp(struct rpki_cache *cache, struct cache_node *node)
{
- enum uri_type type;
+ enum map_type type;
char const *path;
int error;
- type = uri_get_type(node->url);
- if (type != UT_NOTIF && type != UT_TMP)
+ type = map_get_type(node->map);
+ if (type != MAP_NOTIF && type != MAP_TMP)
return;
- path = uri_get_local(node->url);
+ path = map_get_path(node->map);
pr_op_debug("Deleting temporal file '%s'.", path);
error = file_rm_f(path);
if (error)
pr_op_err("Could not delete '%s': %s", path, strerror(error));
- if (type != UT_NOTIF)
+ if (type != MAP_NOTIF)
delete_node(cache, node);
}
char const *path;
int error;
- path = uri_get_local(node->url);
- if (uri_get_type(node->url) == UT_NOTIF)
+ path = map_get_path(node->map);
+ if (map_get_type(node->map) == MAP_NOTIF)
goto skip_file;
error = file_exists(path);
return;
default:
pr_op_err("Trouble cleaning '%s'; stat() returned errno %d: %s",
- uri_op_get_printable(node->url), error, strerror(error));
+ map_op_get_printable(node->map), error, strerror(error));
}
skip_file:
}
/*
- * "Do not clean." List of URIs that should not be deleted from the cache.
+ * "Do not clean." List of mappings that should not be deleted from the cache.
* Global because nftw doesn't have a generic argument.
*/
-static struct uri_list dnc;
+static struct map_list dnc;
static pthread_mutex_t dnc_lock = PTHREAD_MUTEX_INITIALIZER;
static bool
is_cached(char const *_fpath)
{
- struct rpki_uri **node;
+ struct cache_mapping **node;
char const *fpath, *npath;
size_t c;
/*
* This relies on paths being normalized, which is currently done by the
- * URI constructors.
+ * struct cache_mapping constructors.
*/
ARRAYLIST_FOREACH(&dnc, node) {
fpath = _fpath;
- npath = uri_get_local(*node);
+ npath = map_get_path(*node);
for (c = 0; fpath[c] == npath[c]; c++)
if (fpath[c] == '\0')
delete_unknown_files(struct rpki_cache *cache)
{
struct cache_node *node, *tmp;
- struct rpki_uri *cage;
+ struct cache_mapping *cage;
struct path_builder pb;
int error;
}
mutex_lock(&dnc_lock);
- uris_init(&dnc);
+ maps_init(&dnc);
- uris_add(&dnc, uri_create_cache(pb.string));
+ maps_add(&dnc, map_create_cache(pb.string));
HASH_ITER(hh, cache->ht, node, tmp) {
- uri_refget(node->url);
- uris_add(&dnc, node->url);
+ map_refget(node->map);
+ maps_add(&dnc, node->map);
- if (uri_get_type(node->url) != UT_NOTIF)
+ if (map_get_type(node->map) != MAP_NOTIF)
continue;
- if (uri_create_cage(&cage, node->url) != 0) {
+ if (map_create_cage(&cage, node->map) != 0) {
pr_op_err("Cannot generate %s's cage. I'm probably going to end up deleting it from the cache.",
- uri_op_get_printable(node->url));
+ map_op_get_printable(node->map));
continue;
}
- uris_add(&dnc, cage);
+ maps_add(&dnc, cage);
}
pb_pop(&pb, true);
pr_op_warn("The cache cleanup ended prematurely with error code %d (%s)",
error, strerror(error));
- uris_cleanup(&dnc);
+ maps_cleanup(&dnc);
mutex_unlock(&dnc_lock);
pb_cleanup(&pb);
#ifndef SRC_CACHE_LOCAL_CACHE_H_
#define SRC_CACHE_LOCAL_CACHE_H_
-#include "types/uri.h"
+#include "types/map.h"
struct rpki_cache;
struct cachefile_notification; /* FIXME */
-/* Downloads @uri into the cache */
-int cache_download(struct rpki_cache *, struct rpki_uri *uri, bool *,
+/* Downloads @map into the cache */
+int cache_download(struct rpki_cache *, struct cache_mapping *map, bool *,
struct cachefile_notification ***);
/*
* The callback should return
*
- * - 0 on success ("URI handled successfully")
- * - > 0 on soft errors ("Try another URI")
+ * - 0 on success ("Mapping handled successfully")
+ * - > 0 on soft errors ("Try another mapping")
* - < 0 on hard errors ("Abandon foreach")
*/
-typedef int (*uris_dl_cb)(struct rpki_uri *, void *);
-int cache_download_alt(struct rpki_cache *, struct uri_list *, enum uri_type,
- enum uri_type, uris_dl_cb, void *);
+typedef int (*maps_dl_cb)(struct cache_mapping *, void *);
+int cache_download_alt(struct rpki_cache *, struct map_list *, enum map_type,
+ enum map_type, maps_dl_cb, void *);
-/* Returns the most recent successfully cached URI of the list */
-struct rpki_uri *cache_recover(struct rpki_cache *, struct uri_list *);
+/* Returns the most recent successfully cached mapping of the list */
+struct cache_mapping *cache_recover(struct rpki_cache *, struct map_list *);
/* Prints the cache in standard output. */
void cache_print(struct rpki_cache *);
* Cached certificate data.
*/
struct metadata_node {
- struct rpki_uri *uri;
+ struct cache_mapping *map;
struct resources *resources;
/*
* Serial numbers of the children.
case DNT_SEPARATOR:
break;
case DNT_CERT:
- uri_refput(defer->deferred.uri);
+ map_refput(defer->deferred.map);
rpp_refput(defer->deferred.pp);
break;
}
static void
meta_destroy(struct metadata_node *meta)
{
- uri_refput(meta->uri);
+ map_refput(meta->map);
resources_destroy(meta->resources);
serial_numbers_cleanup(&meta->serials, serial_cleanup);
free(meta);
node->type = DNT_CERT;
node->deferred = *deferred;
- uri_refget(deferred->uri);
+ map_refget(deferred->map);
rpp_refget(deferred->pp);
SLIST_INSERT_HEAD(&stack->defers, node, next);
}
}
*result = node->deferred;
- uri_refget(node->deferred.uri);
+ map_refget(node->deferred.map);
rpp_refget(node->deferred.pp);
SLIST_REMOVE_HEAD(&stack->defers, next);
/** Steals ownership of @x509 on success. */
int
-x509stack_push(struct cert_stack *stack, struct rpki_uri *uri, X509 *x509,
+x509stack_push(struct cert_stack *stack, struct cache_mapping *map, X509 *x509,
enum rpki_policy policy, enum cert_type type)
{
struct metadata_node *meta;
meta = pmalloc(sizeof(struct metadata_node));
- meta->uri = uri_refget(uri);
+ meta->map = map_refget(map);
serial_numbers_init(&meta->serials);
error = init_resources(x509, policy, type, &meta->resources);
resources_destroy(meta->resources);
cleanup_serial:
serial_numbers_cleanup(&meta->serials, serial_cleanup);
- uri_refput(meta->uri);
+ map_refput(meta->map);
free(meta);
return error;
}
}
/** Does not grab reference. */
-struct rpki_uri *
-x509stack_peek_uri(struct cert_stack *stack)
+struct cache_mapping *
+x509stack_peek_map(struct cert_stack *stack)
{
struct metadata_node *meta = SLIST_FIRST(&stack->metas);
- return (meta != NULL) ? meta->uri : NULL;
+ return (meta != NULL) ? meta->map : NULL;
}
struct resources *
#include "object/certificate.h"
#include "object/name.h"
#include "resource.h"
-#include "types/uri.h"
+#include "types/map.h"
/*
* One certificate stack is allocated per validation cycle, and it is used
struct cert_stack;
struct deferred_cert {
- struct rpki_uri *uri;
+ struct cache_mapping *map;
struct rpp *pp;
};
int deferstack_pop(struct cert_stack *, struct deferred_cert *cert);
bool deferstack_is_empty(struct cert_stack *);
-int x509stack_push(struct cert_stack *, struct rpki_uri *, X509 *,
+int x509stack_push(struct cert_stack *, struct cache_mapping *, X509 *,
enum rpki_policy, enum cert_type);
void x509stack_cancel(struct cert_stack *);
X509 *x509stack_peek(struct cert_stack *);
-struct rpki_uri *x509stack_peek_uri(struct cert_stack *);
+struct cache_mapping *x509stack_peek_map(struct cert_stack *);
struct resources *x509stack_peek_resources(struct cert_stack *);
void x509stack_store_serial(struct cert_stack *, BIGNUM *);
typedef int (*subject_pk_check_cb)(bool *, char const *, void *);
{
free(refs->crldp);
if (refs->caIssuers != NULL)
- uri_refput(refs->caIssuers);
+ map_refput(refs->caIssuers);
if (refs->signedObject != NULL)
- uri_refput(refs->signedObject);
+ map_refput(refs->signedObject);
}
static int
validate_cdp(struct certificate_refs *refs, struct rpp const *pp)
{
- struct rpki_uri *pp_crl;
+ struct cache_mapping *pp_crl;
if (refs->crldp == NULL)
pr_crit("Certificate's CRL Distribution Point was not recorded.");
if (pp_crl == NULL)
pr_crit("Manifest's CRL was not recorded.");
- if (strcmp(refs->crldp, uri_get_global(pp_crl)) != 0) {
+ if (strcmp(refs->crldp, map_get_url(pp_crl)) != 0) {
return pr_val_err("Certificate's CRL Distribution Point ('%s') does not match manifest's CRL ('%s').",
- refs->crldp, uri_get_global(pp_crl));
+ refs->crldp, map_get_url(pp_crl));
}
return 0;
static int
validate_signedObject(struct certificate_refs *refs,
- struct rpki_uri *signedObject_uri)
+ struct cache_mapping *signedObject_map)
{
if (refs->signedObject == NULL)
pr_crit("Certificate's signedObject was not recorded.");
- if (!uri_equals(refs->signedObject, signedObject_uri)) {
+ if (!map_equals(refs->signedObject, signedObject_map)) {
return pr_val_err("Certificate's signedObject ('%s') does not match the URI of its own signed object (%s).",
- uri_val_get_printable(refs->signedObject),
- uri_val_get_printable(signedObject_uri));
+ map_val_get_printable(refs->signedObject),
+ map_val_get_printable(signedObject_map));
}
return 0;
if (refs->signedObject != NULL)
pr_crit("CA summary has a signedObject ('%s').",
- uri_op_get_printable(refs->signedObject));
+ map_op_get_printable(refs->signedObject));
return 0;
}
*
* @refs: References you want validated.
* @pp: Repository Publication Point, as described by the Manifest.
- * @uri: URL of the signed object that contains the EE certificate.
+ * @map: Mapping of the signed object that contains the EE certificate.
*/
int
refs_validate_ee(struct certificate_refs *refs, struct rpp const *pp,
- struct rpki_uri *uri)
+ struct cache_mapping *map)
{
int error;
if (error)
return error;
- return validate_signedObject(refs, uri);
+ return validate_signedObject(refs, map);
}
* AIA's caIssuers. Non-TA certificates only.
* RFC 6487, section 4.8.7.
*/
- struct rpki_uri *caIssuers;
+ struct cache_mapping *caIssuers;
/**
* SIA's signedObject. EE certificates only.
* RFC 6487, section 4.8.8.2.
*/
- struct rpki_uri *signedObject;
+ struct cache_mapping *signedObject;
};
void refs_init(struct certificate_refs *);
void refs_cleanup(struct certificate_refs *);
int refs_validate_ca(struct certificate_refs *, struct rpp const *);
int refs_validate_ee(struct certificate_refs *, struct rpp const *,
- struct rpki_uri *);
+ struct cache_mapping *);
#endif /* SRC_CERTIFICATE_REFS_H_ */
return 0;
}
-/* mkdir -p $path */
+/* mkdir -p $_path */
int
-mkdir_p(char const *path, bool include_basename)
+mkdir_p(char const *_path, bool include_basename)
{
- char *localuri, *last_slash;
+ char *path, *last_slash;
int i, result = 0;
- localuri = pstrdup(path); /* Remove const */
+ path = pstrdup(_path); /* Remove const */
if (!include_basename) {
- last_slash = strrchr(localuri, '/');
+ last_slash = strrchr(path, '/');
if (last_slash == NULL)
goto end;
*last_slash = '\0';
}
- result = dir_exists(localuri); /* short circuit */
+ result = dir_exists(path); /* short circuit */
if (result > 0) {
result = 0;
goto end;
goto end;
}
- for (i = 1; localuri[i] != '\0'; i++) {
- if (localuri[i] == '/') {
- localuri[i] = '\0';
- result = create_dir(localuri);
- localuri[i] = '/';
+ for (i = 1; path[i] != '\0'; i++) {
+ if (path[i] == '/') {
+ path[i] = '\0';
+ result = create_dir(path);
+ path[i] = '/';
if (result != 0)
goto end; /* error msg already printed */
}
}
- result = create_dir(localuri);
+ result = create_dir(path);
end:
- free(localuri);
+ free(path);
return result;
}
}
int
-hash_validate_file(struct hash_algorithm const *algorithm, struct rpki_uri *uri,
- unsigned char const *expected, size_t expected_len)
+hash_validate_file(struct hash_algorithm const *algorithm,
+ struct cache_mapping *map, unsigned char const *expected,
+ size_t expected_len)
{
unsigned char actual[EVP_MAX_MD_SIZE];
size_t actual_len;
int error;
- error = hash_file(algorithm, uri_get_local(uri), actual, &actual_len);
+ error = hash_file(algorithm, map_get_path(map), actual, &actual_len);
if (error)
return error;
fail:
return pr_val_err("File '%s' does not match its expected hash.",
- uri_val_get_printable(uri));
+ map_val_get_printable(map));
}
static int
#define SRC_HASH_H_
#include <openssl/evp.h>
-#include "types/uri.h"
+#include "types/map.h"
struct hash_algorithm;
int hash_file(struct hash_algorithm const *, char const *, unsigned char *,
size_t *);
-int hash_validate_file(struct hash_algorithm const *, struct rpki_uri *,
+int hash_validate_file(struct hash_algorithm const *, struct cache_mapping *,
unsigned char const *, size_t);
int hash_validate(struct hash_algorithm const *, unsigned char const *, size_t,
unsigned char const *, size_t);
#include <netdb.h>
-#include "types/uri.h"
+#include "types/map.h"
struct path_builder {
char *string;
}
/*
- * Download @uri->global into @uri->local; HTTP assumed.
+ * Download @map->url into @map->path; HTTP assumed.
*
* If @changed returns true, the file was downloaded normally.
* If @changed returns false, the file has not been modified since @ims.
* If @changed is not NULL, initialize it to false.
*/
int
-http_download(struct rpki_uri *uri, curl_off_t ims, bool *changed)
+http_download(struct cache_mapping *map, curl_off_t ims, bool *changed)
{
unsigned int r;
int error;
- pr_val_info("HTTP GET: %s -> %s", uri_get_global(uri), uri_get_local(uri));
+ pr_val_info("HTTP GET: %s -> %s", map_get_url(map), map_get_path(map));
- error = mkdir_p(uri_get_local(uri), false);
+ error = mkdir_p(map_get_path(map), false);
if (error)
return error;
for (r = 0; true; r++) {
pr_val_debug("Download attempt #%u...", r + 1);
- error = http_fetch(uri_get_global(uri), uri_get_local(uri),
+ error = http_fetch(map_get_url(map), map_get_path(map),
ims, changed);
switch (error) {
case 0:
#define SRC_HTTP_HTTP_H_
#include <curl/curl.h>
-#include "types/uri.h"
+#include "types/map.h"
int http_init(void);
void http_cleanup(void);
-int http_download(struct rpki_uri *, curl_off_t, bool *);
+int http_download(struct cache_mapping *, curl_off_t, bool *);
int http_download_direct(char const *, char const *);
#endif /* SRC_HTTP_HTTP_H_ */
};
struct sia_uris {
- struct uri_list rpp;
- struct rpki_uri *mft;
+ struct map_list rpp;
+ struct cache_mapping *mft;
};
struct bgpsec_ski {
struct ad_metadata {
char const *name;
char const *ia_name;
- enum uri_type type;
+ enum map_type type;
char const *type_str;
bool required;
};
static const struct ad_metadata CA_ISSUERS = {
.name = "caIssuers",
.ia_name = "AIA",
- .type = UT_AIA,
+ .type = MAP_AIA,
.type_str = "rsync",
.required = true,
};
static const struct ad_metadata SIGNED_OBJECT = {
.name = "signedObject",
.ia_name = "SIA",
- .type = UT_SO,
+ .type = MAP_SO,
.type_str = "rsync",
.required = true,
};
static const struct ad_metadata CA_REPOSITORY = {
.name = "caRepository",
.ia_name = "SIA",
- .type = UT_RPP,
+ .type = MAP_RPP,
.type_str = "rsync",
.required = false,
};
static const struct ad_metadata RPKI_NOTIFY = {
.name = "rpkiNotify",
.ia_name = "SIA",
- .type = UT_NOTIF,
+ .type = MAP_NOTIF,
.type_str = "HTTPS",
.required = false,
};
static const struct ad_metadata RPKI_MANIFEST = {
.name = "rpkiManifest",
.ia_name = "SIA",
- .type = UT_MFT,
+ .type = MAP_MFT,
.type_str = "rsync",
.required = true,
};
static void
sia_uris_init(struct sia_uris *uris)
{
- uris_init(&uris->rpp);
+ maps_init(&uris->rpp);
uris->mft = NULL;
}
static void
sia_uris_cleanup(struct sia_uris *uris)
{
- uris_cleanup(&uris->rpp);
- uri_refput(uris->mft);
+ maps_cleanup(&uris->rpp);
+ map_refput(uris->mft);
}
static void
}
static int
-certificate_load(struct rpki_uri *uri, X509 **result)
+certificate_load(struct cache_mapping *map, X509 **result)
{
X509 *cert = NULL;
BIO *bio;
bio = BIO_new(BIO_s_file());
if (bio == NULL)
return val_crypto_err("BIO_new(BIO_s_file()) returned NULL");
- if (BIO_read_filename(bio, uri_get_local(uri)) <= 0) {
+ if (BIO_read_filename(bio, map_get_path(map)) <= 0) {
error = val_crypto_err("Error reading certificate");
goto end;
}
}
static int
-handle_rpkiManifest(struct rpki_uri *uri, void *arg)
+handle_rpkiManifest(struct cache_mapping *map, void *arg)
{
struct sia_uris *uris = arg;
- uris->mft = uri_refget(uri);
+ uris->mft = map_refget(map);
return 0;
}
static int
-handle_caRepository(struct rpki_uri *uri, void *arg)
+handle_caRepository(struct cache_mapping *map, void *arg)
{
struct sia_uris *uris = arg;
- pr_val_debug("caRepository: %s", uri_val_get_printable(uri));
- uris_add(&uris->rpp, uri);
- uri_refget(uri);
+ pr_val_debug("caRepository: %s", map_val_get_printable(map));
+ maps_add(&uris->rpp, map);
+ map_refget(map);
return 0;
}
static int
-handle_rpkiNotify(struct rpki_uri *uri, void *arg)
+handle_rpkiNotify(struct cache_mapping *map, void *arg)
{
struct sia_uris *uris = arg;
- pr_val_debug("rpkiNotify: %s", uri_val_get_printable(uri));
- uris_add(&uris->rpp, uri);
- uri_refget(uri);
+ pr_val_debug("rpkiNotify: %s", map_val_get_printable(map));
+ maps_add(&uris->rpp, map);
+ map_refget(map);
return 0;
}
static int
-handle_signedObject(struct rpki_uri *uri, void *arg)
+handle_signedObject(struct cache_mapping *map, void *arg)
{
struct certificate_refs *refs = arg;
- pr_val_debug("signedObject: %s", uri_val_get_printable(uri));
- refs->signedObject = uri_refget(uri);
+ pr_val_debug("signedObject: %s", map_val_get_printable(map));
+ refs->signedObject = map_refget(map);
return 0;
}
}
/*
- * Create @uri from the @ad
+ * Create @map from the @ad
*/
static int
-uri_create_ad(struct rpki_uri **uri, ACCESS_DESCRIPTION *ad, enum uri_type type)
+map_create_ad(struct cache_mapping **map, ACCESS_DESCRIPTION *ad,
+ enum map_type type)
{
ASN1_STRING *asn1str;
char *str;
* URIs.
*
* Also, nobody seems to be using the other types, and handling them
- * would be a titanic pain in the ass. So this is what I'm committing
- * to.
+ * would be a titanic pain. So this is what I'm committing to.
*/
if (ptype != GEN_URI) {
pr_val_err("Unknown GENERAL_NAME type: %d", ptype);
str = pstrndup((char const *)ASN1_STRING_get0_data(asn1str),
ASN1_STRING_length(asn1str));
- error = uri_create(uri, type, NULL, str);
+ error = map_create(map, type, NULL, str);
free(str);
return error;
*/
static int
handle_ad(int nid, struct ad_metadata const *meta, SIGNATURE_INFO_ACCESS *ia,
- int (*cb)(struct rpki_uri *, void *), void *arg)
+ int (*cb)(struct cache_mapping *, void *), void *arg)
{
ACCESS_DESCRIPTION *ad;
- struct rpki_uri *uri;
+ struct cache_mapping *map;
bool found;
unsigned int i;
int error;
for (i = 0; i < sk_ACCESS_DESCRIPTION_num(ia); i++) {
ad = sk_ACCESS_DESCRIPTION_value(ia, i);
if (OBJ_obj2nid(ad->method) == nid) {
- error = uri_create_ad(&uri, ad, meta->type);
+ error = map_create_ad(&map, ad, meta->type);
switch (error) {
case 0:
break;
}
if (found) {
- uri_refput(uri);
+ map_refput(map);
return pr_val_err("Extension '%s' has multiple '%s' %s URIs.",
meta->ia_name, meta->name, meta->type_str);
}
- error = cb(uri, arg);
+ error = cb(map, arg);
if (error) {
- uri_refput(uri);
+ map_refput(map);
return error;
}
- uri_refput(uri);
+ map_refput(map);
found = true;
}
}
}
static int
-handle_caIssuers(struct rpki_uri *uri, void *arg)
+handle_caIssuers(struct cache_mapping *map, void *arg)
{
struct certificate_refs *refs = arg;
/*
* over here is too much trouble, so do the handle_cdp()
* hack.
*/
- refs->caIssuers = uri_refget(uri);
+ refs->caIssuers = map_refget(map);
return 0;
}
/**
* Validates the certificate extensions, Trust Anchor style.
- *
- * Depending on the Access Description preference at SIA, the rpki_uri's at
- * @sia_uris will be allocated.
*/
static int
certificate_validate_extensions_ta(X509 *cert, struct sia_uris *sia_uris,
* Validates the certificate extensions, (intermediate) Certificate Authority
* style.
*
- * Depending on the Access Description preference at SIA, the rpki_uri's at
- * @sia_uris will be allocated.
* Also initializes the fourth argument with the references found in the
* extensions.
*/
}
int
-certificate_validate_aia(struct rpki_uri *caIssuers, X509 *cert)
+certificate_validate_aia(struct cache_mapping *caIssuers, X509 *cert)
{
/*
* FIXME Compare the AIA to the parent's URI.
}
static int
-retrieve_uri(struct rpki_uri *uri, void *arg)
+retrieve_mapping(struct cache_mapping *map, void *arg)
{
- struct rpki_uri **result = arg;
- *result = uri;
+ struct cache_mapping **result = arg;
+ *result = map;
return 0;
}
-static struct rpki_uri *
+static struct cache_mapping *
download_rpp(struct sia_uris *uris)
{
- struct rpki_uri *uri;
+ struct cache_mapping *map;
int error;
if (uris->rpp.len == 0) {
}
error = cache_download_alt(validation_cache(state_retrieve()),
- &uris->rpp, UT_NOTIF, UT_RPP, retrieve_uri, &uri);
- return error ? NULL : uri;
+ &uris->rpp, MAP_NOTIF, MAP_RPP, retrieve_mapping, &map);
+ return error ? NULL : map;
}
/** Boilerplate code for CA certificate validation and recursive traversal. */
int
-certificate_traverse(struct rpp *rpp_parent, struct rpki_uri *cert_uri)
+certificate_traverse(struct rpp *rpp_parent, struct cache_mapping *cert_map)
{
struct validation *state;
int total_parents;
STACK_OF(X509_CRL) *rpp_parent_crl;
X509 *cert;
struct sia_uris sia_uris;
- struct rpki_uri *downloaded;
+ struct cache_mapping *downloaded;
enum rpki_policy policy;
enum cert_type certype;
struct rpp *pp;
/* Debug cert type */
if (rpp_parent == NULL)
pr_val_debug("TA Certificate '%s' {",
- uri_val_get_printable(cert_uri));
+ map_val_get_printable(cert_map));
else
pr_val_debug("Certificate '%s' {",
- uri_val_get_printable(cert_uri));
+ map_val_get_printable(cert_map));
- fnstack_push_uri(cert_uri);
+ fnstack_push_map(cert_map);
error = rpp_crl(rpp_parent, &rpp_parent_crl);
if (error)
goto revert_fnstack_and_debug;
/* -- Validate the certificate (@cert) -- */
- error = certificate_load(cert_uri, &cert);
+ error = certificate_load(cert_map, &cert);
if (error)
goto revert_fnstack_and_debug;
error = certificate_validate_chain(cert, rpp_parent_crl);
goto revert_uris;
}
- error = x509stack_push(validation_certstack(state), cert_uri, cert,
+ error = x509stack_push(validation_certstack(state), cert_map, cert,
policy, certype);
if (error)
goto revert_uris;
cert = NULL; /* Ownership stolen */
error = handle_manifest(sia_uris.mft,
- (uri_get_type(downloaded) == UT_NOTIF) ? downloaded : NULL,
+ (map_get_type(downloaded) == MAP_NOTIF) ? downloaded : NULL,
&pp);
if (error) {
x509stack_cancel(validation_certstack(state));
#include "certificate_refs.h"
#include "resource.h"
#include "rpp.h"
-#include "types/uri.h"
+#include "types/map.h"
/* Certificate types in the RPKI */
enum cert_type {
* Specific validation of AIA (rfc6487#section-4.8.7) extension, public so that
* CAs and EEs can access it.
*/
-int certificate_validate_aia(struct rpki_uri *, X509 *);
+int certificate_validate_aia(struct cache_mapping *, X509 *);
-int certificate_traverse(struct rpp *, struct rpki_uri *);
+int certificate_traverse(struct rpp *, struct cache_mapping *);
#endif /* SRC_OBJECT_CERTIFICATE_H_ */
#include "thread_var.h"
static int
-__crl_load(struct rpki_uri *uri, X509_CRL **result)
+__crl_load(struct cache_mapping *map, X509_CRL **result)
{
X509_CRL *crl;
BIO *bio;
bio = BIO_new(BIO_s_file());
if (bio == NULL)
return val_crypto_err("BIO_new(BIO_s_file()) returned NULL");
- if (BIO_read_filename(bio, uri_get_local(uri)) <= 0) {
+ if (BIO_read_filename(bio, map_get_path(map)) <= 0) {
error = val_crypto_err("Error reading CRL '%s'",
- uri_val_get_printable(uri));
+ map_val_get_printable(map));
goto end;
}
crl = d2i_X509_CRL_bio(bio, NULL);
if (crl == NULL) {
error = val_crypto_err("Error parsing CRL '%s'",
- uri_val_get_printable(uri));
+ map_val_get_printable(map));
goto end;
}
}
int
-crl_load(struct rpki_uri *uri, X509_CRL **result)
+crl_load(struct cache_mapping *map, X509_CRL **result)
{
int error;
- pr_val_debug("CRL '%s' {", uri_val_get_printable(uri));
+ pr_val_debug("CRL '%s' {", map_val_get_printable(map));
- error = __crl_load(uri, result);
+ error = __crl_load(map, result);
if (error)
goto end;
#include <openssl/x509.h>
-#include "types/uri.h"
+#include "types/map.h"
-int crl_load(struct rpki_uri *uri, X509_CRL **);
+int crl_load(struct cache_mapping *, X509_CRL **);
#endif /* SRC_OBJECT_CRL_H_ */
}
int
-ghostbusters_traverse(struct rpki_uri *uri, struct rpp *pp)
+ghostbusters_traverse(struct cache_mapping *map, struct rpp *pp)
{
static OID oid = OID_GHOSTBUSTERS;
struct oid_arcs arcs = OID2ARCS("ghostbusters", oid);
int error;
/* Prepare */
- pr_val_debug("Ghostbusters '%s' {", uri_val_get_printable(uri));
- fnstack_push_uri(uri);
+ pr_val_debug("Ghostbusters '%s' {", map_val_get_printable(map));
+ fnstack_push_map(map);
/* Decode */
- error = signed_object_decode(&sobj, uri);
+ error = signed_object_decode(&sobj, map);
if (error)
goto revert_log;
error = handle_vcard(&sobj);
if (error)
goto revert_args;
- error = refs_validate_ee(&ee.refs, pp, uri);
+ error = refs_validate_ee(&ee.refs, pp, map);
revert_args:
eecert_cleanup(&ee);
#define SRC_OBJECT_GHOSTBUSTERS_H_
#include "rpp.h"
-#include "types/uri.h"
+#include "types/map.h"
-int ghostbusters_traverse(struct rpki_uri *, struct rpp *);
+int ghostbusters_traverse(struct cache_mapping *, struct rpp *);
#endif /* SRC_OBJECT_GHOSTBUSTERS_H_ */
#include "thread_var.h"
static int
-cage(struct rpki_uri **uri, struct rpki_uri *notif)
+cage(struct cache_mapping **map, struct cache_mapping *notif)
{
if (notif == NULL) {
/* No need to cage */
- uri_refget(*uri);
+ map_refget(*map);
return 0;
}
- return uri_create_caged(uri, notif, uri_get_global(*uri));
+ return map_create_caged(map, notif, map_get_url(*map));
}
static int
}
/**
- * Computes the hash of the file @uri, and compares it to @expected (The
+ * Computes the hash of the file @map, and compares it to @expected (The
* "expected" hash).
*
* Returns:
* an incidence to ignore this).
*/
static int
-hash_validate_mft_file(struct rpki_uri *uri, BIT_STRING_t const *expected)
+hash_validate_mft_file(struct cache_mapping *map, BIT_STRING_t const *expected)
{
struct hash_algorithm const *algorithm;
size_t hash_size;
* hash_validate_file().
*/
- error = hash_file(algorithm, uri_get_local(uri), actual, NULL);
+ error = hash_file(algorithm, map_get_path(map), actual, NULL);
if (error) {
if (error == EACCES || error == ENOENT) {
/* FIXME .................. */
if (incidence(INID_MFT_FILE_NOT_FOUND,
"File '%s' listed at manifest doesn't exist.",
- uri_val_get_printable(uri)))
+ map_val_get_printable(map)))
return -EINVAL;
return error;
if (memcmp(expected->buf, actual, hash_size) != 0) {
return incidence(INID_MFT_FILE_HASH_NOT_MATCH,
"File '%s' does not match its manifest hash.",
- uri_val_get_printable(uri));
+ map_val_get_printable(map));
}
return 0;
}
static int
-build_rpp(struct Manifest *mft, struct rpki_uri *notif,
- struct rpki_uri *mft_uri, struct rpp **pp)
+build_rpp(struct Manifest *mft, struct cache_mapping *notif,
+ struct cache_mapping *mft_map, struct rpp **pp)
{
int i;
struct FileAndHash *fah;
- struct rpki_uri *uri;
+ struct cache_mapping *map;
int error;
*pp = rpp_create();
for (i = 0; i < mft->fileList.list.count; i++) {
fah = mft->fileList.list.array[i];
- error = uri_create_mft(&uri, notif, mft_uri, &fah->file);
+ error = map_create_mft(&map, notif, mft_map, &fah->file);
/*
* Not handling ENOTRSYNC is fine because the manifest URL
* should have been RSYNC. Something went wrong if an RSYNC URL
* - Positive value: file doesn't exist and keep validating
* manifest.
*/
- error = hash_validate_mft_file(uri, &fah->hash);
+ error = hash_validate_mft_file(map, &fah->hash);
if (error < 0) {
- uri_refput(uri);
+ map_refput(map);
goto fail;
}
if (error > 0) {
- uri_refput(uri);
+ map_refput(map);
continue;
}
- if (uri_has_extension(uri, ".cer"))
- rpp_add_cert(*pp, uri);
- else if (uri_has_extension(uri, ".roa"))
- rpp_add_roa(*pp, uri);
- else if (uri_has_extension(uri, ".crl"))
- error = rpp_add_crl(*pp, uri);
- else if (uri_has_extension(uri, ".gbr"))
- rpp_add_ghostbusters(*pp, uri);
+ if (map_has_extension(map, ".cer"))
+ rpp_add_cert(*pp, map);
+ else if (map_has_extension(map, ".roa"))
+ rpp_add_roa(*pp, map);
+ else if (map_has_extension(map, ".crl"))
+ error = rpp_add_crl(*pp, map);
+ else if (map_has_extension(map, ".gbr"))
+ rpp_add_ghostbusters(*pp, map);
else
- uri_refput(uri); /* ignore it. */
+ map_refput(map); /* ignore it. */
if (error) {
- uri_refput(uri);
+ map_refput(map);
goto fail;
} /* Otherwise ownership was transferred to @pp. */
}
}
/**
- * Validates the manifest pointed by @uri, returns the RPP described by it in
+ * Validates the manifest pointed by @map, returns the RPP described by it in
* @pp.
*/
int
-handle_manifest(struct rpki_uri *uri, struct rpki_uri *notif, struct rpp **pp)
+handle_manifest(struct cache_mapping *map, struct cache_mapping *notif,
+ struct rpp **pp)
{
static OID oid = OID_MANIFEST;
struct oid_arcs arcs = OID2ARCS("manifest", oid);
int error;
/* Prepare */
- error = cage(&uri, notif); /* ref++ */
+ error = cage(&map, notif); /* ref++ */
if (error)
return error;
- pr_val_debug("Manifest '%s' {", uri_val_get_printable(uri));
- fnstack_push_uri(uri);
+ pr_val_debug("Manifest '%s' {", map_val_get_printable(map));
+ fnstack_push_map(map);
/* Decode */
- error = signed_object_decode(&sobj, uri);
+ error = signed_object_decode(&sobj, map);
if (error)
goto revert_log;
error = decode_manifest(&sobj, &mft);
goto revert_sobj;
/* Initialize out parameter (@pp) */
- error = build_rpp(mft, notif, uri, pp);
+ error = build_rpp(mft, notif, map, pp);
if (error)
goto revert_manifest;
error = validate_manifest(mft);
if (error)
goto revert_args;
- error = refs_validate_ee(&ee.refs, *pp, uri);
+ error = refs_validate_ee(&ee.refs, *pp, map);
if (error)
goto revert_args;
revert_log:
pr_val_debug("}");
fnstack_pop();
- uri_refput(uri); /* ref-- */
+ map_refput(map); /* ref-- */
return error;
}
#include "rpp.h"
-int handle_manifest(struct rpki_uri *, struct rpki_uri *, struct rpp **);
+int handle_manifest(struct cache_mapping *, struct cache_mapping *, struct rpp **);
#endif /* SRC_OBJECT_MANIFEST_H_ */
}
int
-roa_traverse(struct rpki_uri *uri, struct rpp *pp)
+roa_traverse(struct cache_mapping *map, struct rpp *pp)
{
static OID oid = OID_ROA;
struct oid_arcs arcs = OID2ARCS("roa", oid);
int error;
/* Prepare */
- pr_val_debug("ROA '%s' {", uri_val_get_printable(uri));
- fnstack_push_uri(uri);
+ pr_val_debug("ROA '%s' {", map_val_get_printable(map));
+ fnstack_push_map(map);
/* Decode */
- error = signed_object_decode(&sobj, uri);
+ error = signed_object_decode(&sobj, map);
if (error)
goto revert_log;
error = decode_roa(&sobj, &roa);
error = __handle_roa(roa, ee.res);
if (error)
goto revert_args;
- error = refs_validate_ee(&ee.refs, pp, uri);
+ error = refs_validate_ee(&ee.refs, pp, map);
revert_args:
eecert_cleanup(&ee);
#include "rpp.h"
#include "types/address.h"
-#include "types/uri.h"
+#include "types/map.h"
-int roa_traverse(struct rpki_uri *, struct rpp *);
+int roa_traverse(struct cache_mapping *, struct rpp *);
#endif /* SRC_OBJECT_ROA_H_ */
#include "log.h"
int
-signed_object_decode(struct signed_object *sobj, struct rpki_uri *uri)
+signed_object_decode(struct signed_object *sobj, struct cache_mapping *map)
{
int error;
- error = content_info_load(uri_get_local(uri), &sobj->cinfo);
+ error = content_info_load(map_get_path(map), &sobj->cinfo);
if (error)
return error;
struct SignedData *sdata;
};
-int signed_object_decode(struct signed_object *, struct rpki_uri *);
+int signed_object_decode(struct signed_object *, struct cache_mapping *);
int signed_object_validate(struct signed_object *, struct oid_arcs const *,
struct ee_cert *);
void signed_object_cleanup(struct signed_object *);
#include "rtr/db/vrps.h"
#include "cache/local_cache.h"
-typedef int (*foreach_uri_cb)(struct tal *, struct rpki_uri *, void *);
+typedef int (*foreach_map_cb)(struct tal *, struct cache_mapping *, void *);
struct tal {
char const *file_name;
- struct uri_list uris;
+ struct map_list maps;
unsigned char *spki; /* Decoded; not base64. */
size_t spki_len;
}
static int
-add_uri(struct tal *tal, char *uri)
+add_url(struct tal *tal, char *url)
{
- struct rpki_uri *new = NULL;
+ struct cache_mapping *new = NULL;
int error;
- if (str_starts_with(uri, "rsync://"))
- error = uri_create(&new, UT_TA_RSYNC, NULL, uri);
- else if (str_starts_with(uri, "https://"))
- error = uri_create(&new, UT_TA_HTTP, NULL, uri);
+ if (str_starts_with(url, "rsync://"))
+ error = map_create(&new, MAP_TA_RSYNC, NULL, url);
+ else if (str_starts_with(url, "https://"))
+ error = map_create(&new, MAP_TA_HTTP, NULL, url);
else
- return pr_op_err("TAL has non-rsync/HTTPS URI: %s", uri);
+ return pr_op_err("TAL has non-rsync/HTTPS URI: %s", url);
if (error)
return error;
- uris_add(&tal->uris, new);
+ maps_add(&tal->maps, new);
return 0;
}
if (is_blank(fc))
break;
- error = add_uri(tal, fc);
+ error = add_url(tal, fc);
if (error)
return error;
return pr_op_err("The TAL seems to be missing the public key.");
} while (true);
- if (tal->uris.len == 0)
+ if (tal->maps.len == 0)
return pr_op_err("There seems to be an empty/blank line before the end of the URI section.");
/* subjectPublicKeyInfo section */
file_name = (file_name != NULL) ? (file_name + 1) : file_path;
tal->file_name = file_name;
- uris_init(&tal->uris);
+ maps_init(&tal->maps);
error = read_content((char *)file.buffer, tal);
if (error) {
- uris_cleanup(&tal->uris);
+ maps_cleanup(&tal->maps);
goto end;
}
{
cache_destroy(tal->cache);
free(tal->spki);
- uris_cleanup(&tal->uris);
+ maps_cleanup(&tal->maps);
}
char const *
}
/**
- * Performs the whole validation walkthrough on uri @uri, which is assumed to
- * have been extracted from TAL @tal.
+ * Performs the whole validation walkthrough on the @map mapping, which is
+ * assumed to have been extracted from TAL @tal.
*/
static int
-handle_tal_uri(struct tal *tal, struct rpki_uri *uri, struct db_table *db)
+handle_tal_map(struct tal *tal, struct cache_mapping *map, struct db_table *db)
{
struct validation_handler validation_handler;
struct validation *state;
struct deferred_cert deferred;
int error;
- pr_val_debug("TAL URI '%s' {", uri_val_get_printable(uri));
+ pr_val_debug("TAL URI '%s' {", map_val_get_printable(map));
validation_handler.handle_roa_v4 = handle_roa_v4;
validation_handler.handle_roa_v6 = handle_roa_v6;
if (error)
return ENSURE_NEGATIVE(error);
- if (!uri_is_certificate(uri)) {
+ if (!map_is_certificate(map)) {
pr_op_err("TAL URI does not point to a certificate. (Expected .cer, got '%s')",
- uri_op_get_printable(uri));
+ map_op_get_printable(map));
error = EINVAL;
goto end;
}
/* Handle root certificate. */
- error = certificate_traverse(NULL, uri);
+ error = certificate_traverse(NULL, map);
if (error) {
switch (validation_pubkey_state(state)) {
case PKS_INVALID:
* Ignore result code; remaining certificates are unrelated,
* so they should not be affected.
*/
- certificate_traverse(deferred.pp, deferred.uri);
+ certificate_traverse(deferred.pp, deferred.map);
- uri_refput(deferred.uri);
+ map_refput(deferred.map);
rpp_refput(deferred.pp);
} while (true);
}
static int
-__handle_tal_uri(struct rpki_uri *uri, void *arg)
+__handle_tal_map(struct cache_mapping *map, void *arg)
{
struct handle_tal_args *args = arg;
- return handle_tal_uri(&args->tal, uri, args->db);
+ return handle_tal_map(&args->tal, map, args->db);
}
static void *
goto end;
args.db = db_table_create();
- thread->error = cache_download_alt(args.tal.cache, &args.tal.uris,
- UT_TA_HTTP, UT_TA_RSYNC, __handle_tal_uri, &args);
+ thread->error = cache_download_alt(args.tal.cache, &args.tal.maps,
+ MAP_TA_HTTP, MAP_TA_RSYNC, __handle_tal_map, &args);
if (thread->error) {
pr_op_err("None of the URIs of the TAL '%s' yielded a successful traversal.",
thread->tal_file);
/* This is RFC 8630. */
#include "rtr/db/db_table.h"
-#include "types/uri.h"
+#include "types/map.h"
struct tal;
#include "log.h"
#include "rsync/rsync.h"
#include "types/bio_seq.h"
-#include "types/uri.h"
+#include "types/map.h"
#define HDRSIZE 32
static BIO *
rsync2bio_cache(char const *src)
{
- struct rpki_uri *uri = NULL;
+ struct cache_mapping *map = NULL;
BIO *bio;
int error;
/*
- * TODO (#82) maybe rename UT_TA_RSYNC into single rsync.
+ * TODO (#82) maybe rename MAP_TA_RSYNC into single rsync.
* If applies and it's going to survive.
*/
- error = uri_create(&uri, UT_TA_RSYNC, NULL, src);
+ error = map_create(&map, MAP_TA_RSYNC, NULL, src);
if (error) {
pr_op_err("Unparseable rsync URI: %s", strerror(abs(error)));
return NULL;
}
- bio = __rsync2bio(uri_get_global(uri), uri_get_local(uri));
+ bio = __rsync2bio(map_get_url(map), map_get_path(map));
- uri_refput(uri);
+ map_refput(map);
return bio;
}
#include "object/ghostbusters.h"
#include "object/roa.h"
#include "thread_var.h"
-#include "types/uri.h"
+#include "types/map.h"
/** A Repository Publication Point (RFC 6481), as described by some manifest. */
struct rpp {
- struct uri_list certs; /* Certificates */
+ struct map_list certs; /* Certificates */
/*
- * uri NULL implies stack NULL and error 0.
- * If uri is set, stack might or might not be set.
- * error is only relevant when uri is set and stack is unset.
+ * map NULL implies stack NULL and error 0.
+ * If map is set, stack might or might not be set.
+ * error is only relevant when map is set and stack is unset.
*/
struct { /* Certificate Revocation List */
- struct rpki_uri *uri;
+ struct cache_mapping *map;
/*
* CRL in libcrypto-friendly form.
* Initialized lazily; access via rpp_crl().
/* The Manifest is not needed for now. */
- struct uri_list roas; /* Route Origin Attestations */
+ struct map_list roas; /* Route Origin Attestations */
- struct uri_list ghostbusters;
+ struct map_list ghostbusters;
/*
* Note that the reference counting functions are not prepared for
result = pmalloc(sizeof(struct rpp));
- uris_init(&result->certs);
- result->crl.uri = NULL;
+ maps_init(&result->certs);
+ result->crl.map = NULL;
result->crl.stack = NULL;
result->crl.error = 0;
- uris_init(&result->roas);
- uris_init(&result->ghostbusters);
+ maps_init(&result->roas);
+ maps_init(&result->ghostbusters);
result->references = 1;
return result;
{
pp->references--;
if (pp->references == 0) {
- uris_cleanup(&pp->certs);
- if (pp->crl.uri != NULL)
- uri_refput(pp->crl.uri);
+ maps_cleanup(&pp->certs);
+ if (pp->crl.map != NULL)
+ map_refput(pp->crl.map);
if (pp->crl.stack != NULL)
sk_X509_CRL_pop_free(pp->crl.stack, X509_CRL_free);
- uris_cleanup(&pp->roas);
- uris_cleanup(&pp->ghostbusters);
+ maps_cleanup(&pp->roas);
+ maps_cleanup(&pp->ghostbusters);
free(pp);
}
}
-/** Steals ownership of @uri. */
+/** Steals ownership of @map. */
void
-rpp_add_cert(struct rpp *pp, struct rpki_uri *uri)
+rpp_add_cert(struct rpp *pp, struct cache_mapping *map)
{
- uris_add(&pp->certs, uri);
+ maps_add(&pp->certs, map);
}
-/** Steals ownership of @uri. */
+/** Steals ownership of @map. */
void
-rpp_add_roa(struct rpp *pp, struct rpki_uri *uri)
+rpp_add_roa(struct rpp *pp, struct cache_mapping *map)
{
- uris_add(&pp->roas, uri);
+ maps_add(&pp->roas, map);
}
-/** Steals ownership of @uri. */
+/** Steals ownership of @map. */
void
-rpp_add_ghostbusters(struct rpp *pp, struct rpki_uri *uri)
+rpp_add_ghostbusters(struct rpp *pp, struct cache_mapping *map)
{
- uris_add(&pp->ghostbusters, uri);
+ maps_add(&pp->ghostbusters, map);
}
-/** Steals ownership of @uri. */
+/** Steals ownership of @map. */
int
-rpp_add_crl(struct rpp *pp, struct rpki_uri *uri)
+rpp_add_crl(struct rpp *pp, struct cache_mapping *map)
{
/* rfc6481#section-2.2 */
- if (pp->crl.uri)
+ if (pp->crl.map)
return pr_val_err("Repository Publication Point has more than one CRL.");
- pp->crl.uri = uri;
+ pp->crl.map = map;
return 0;
}
-struct rpki_uri *
+struct cache_mapping *
rpp_get_crl(struct rpp const *pp)
{
- return pp->crl.uri;
+ return pp->crl.map;
}
static int
int error;
int idx;
- fnstack_push_uri(pp->crl.uri);
+ fnstack_push_map(pp->crl.map);
- error = crl_load(pp->crl.uri, &crl);
+ error = crl_load(pp->crl.map, &crl);
if (error)
goto end;
*result = NULL;
return 0;
}
- if (pp->crl.uri == NULL) {
+ if (pp->crl.map == NULL) {
/* rpp_crl() assumes the rpp has been populated already. */
pr_crit("RPP lacks a CRL.");
}
* intuitive.
*/
for (i = pp->certs.len - 1; i >= 0; i--) {
- deferred.uri = pp->certs.array[i];
+ deferred.map = pp->certs.array[i];
deferstack_push(certstack, &deferred);
}
void
rpp_traverse(struct rpp *pp)
{
- struct rpki_uri **uri;
+ struct cache_mapping **map;
/*
* A subtree should not invalidate the rest of the tree, so error codes
__cert_traverse(pp);
/* Validate ROAs, apply validation_handler on them. */
- ARRAYLIST_FOREACH(&pp->roas, uri)
- roa_traverse(*uri, pp);
+ ARRAYLIST_FOREACH(&pp->roas, map)
+ roa_traverse(*map, pp);
/*
* We don't do much with the ghostbusters right now.
* Just validate them.
*/
- ARRAYLIST_FOREACH(&pp->ghostbusters, uri)
- ghostbusters_traverse(*uri, pp);
+ ARRAYLIST_FOREACH(&pp->ghostbusters, map)
+ ghostbusters_traverse(*map, pp);
}
#include <openssl/safestack.h>
#include <openssl/x509.h>
-#include "types/uri.h"
+#include "types/map.h"
struct rpp;
void rpp_refget(struct rpp *pp);
void rpp_refput(struct rpp *pp);
-void rpp_add_cert(struct rpp *, struct rpki_uri *);
-int rpp_add_crl(struct rpp *, struct rpki_uri *);
-void rpp_add_roa(struct rpp *, struct rpki_uri *);
-void rpp_add_ghostbusters(struct rpp *, struct rpki_uri *);
+void rpp_add_cert(struct rpp *, struct cache_mapping *);
+int rpp_add_crl(struct rpp *, struct cache_mapping *);
+void rpp_add_roa(struct rpp *, struct cache_mapping *);
+void rpp_add_ghostbusters(struct rpp *, struct cache_mapping *);
-struct rpki_uri *rpp_get_crl(struct rpp const *);
+struct cache_mapping *rpp_get_crl(struct rpp const *);
int rpp_crl(struct rpp *, STACK_OF(X509_CRL) **);
void rpp_traverse(struct rpp *);
};
struct file_metadata {
- struct rpki_uri *uri;
+ struct cache_mapping *uri;
unsigned char *hash; /* Array. Sometimes omitted. */
size_t hash_len;
};
struct rrdp_session session;
struct file_metadata snapshot;
struct notification_deltas deltas;
- struct rpki_uri *uri;
+ struct cache_mapping *map;
};
/* A deserialized <publish> tag, from a snapshot or delta. */
/* Helpful context while reading a snapshot or delta. */
struct rrdp_ctx {
- struct rpki_uri *notif;
+ struct cache_mapping *notif;
struct rrdp_session session;
};
metadata_cleanup(struct file_metadata *meta)
{
free(meta->hash);
- uri_refput(meta->uri);
+ map_refput(meta->uri);
}
static void
static void
update_notification_init(struct update_notification *notif,
- struct rpki_uri *uri)
+ struct cache_mapping *map)
{
memset(¬if->session, 0, sizeof(notif->session));
memset(¬if->snapshot, 0, sizeof(notif->snapshot));
notification_deltas_init(¬if->deltas);
- notif->uri = uri_refget(uri);
+ notif->map = map_refget(map);
}
static void
{
metadata_cleanup(¬if->snapshot);
notification_deltas_cleanup(¬if->deltas, notification_delta_cleanup);
- uri_refput(notif->uri);
+ map_refput(notif->map);
}
static void
}
static int
-parse_uri(xmlTextReaderPtr reader, struct rpki_uri *notif,
- struct rpki_uri **result)
+parse_uri(xmlTextReaderPtr reader, struct cache_mapping *notif,
+ struct cache_mapping **result)
{
xmlChar *xmlattr;
int error;
if (xmlattr == NULL)
return -EINVAL;
- error = uri_create(result, (notif != NULL) ? UT_CAGED : UT_TMP, notif,
+ error = map_create(result, (notif != NULL) ? MAP_CAGED : MAP_TMP, notif,
(char const *)xmlattr);
xmlFree(xmlattr);
* 2. "hash" (optional, depending on @hr)
*/
static int
-parse_file_metadata(xmlTextReaderPtr reader, struct rpki_uri *notif,
+parse_file_metadata(xmlTextReaderPtr reader, struct cache_mapping *notif,
hash_requirement hr, struct file_metadata *meta)
{
int error;
error = parse_hash(reader, hr, &meta->hash, &meta->hash_len);
if (error) {
- uri_refput(meta->uri);
+ map_refput(meta->uri);
meta->uri = NULL;
return error;
}
}
static int
-parse_publish(xmlTextReaderPtr reader, struct rpki_uri *notif,
+parse_publish(xmlTextReaderPtr reader, struct cache_mapping *notif,
hash_requirement hr, struct publish *tag)
{
xmlChar *base64_str;
if (xmlTextReaderRead(reader) != 1) {
return pr_val_err(
"Couldn't read publish content of element '%s'",
- uri_get_global(tag->meta.uri)
+ map_get_url(tag->meta.uri)
);
}
}
static int
-parse_withdraw(xmlTextReaderPtr reader, struct rpki_uri *notif,
+parse_withdraw(xmlTextReaderPtr reader, struct cache_mapping *notif,
struct withdraw *tag)
{
int error;
}
static int
-write_file(struct rpki_uri *uri, unsigned char *content, size_t content_len)
+write_file(struct cache_mapping *map, unsigned char *content, size_t content_len)
{
FILE *out;
size_t written;
int error;
- error = mkdir_p(uri_get_local(uri), false);
+ error = mkdir_p(map_get_path(map), false);
if (error)
return error;
- error = file_write(uri_get_local(uri), "wb", &out);
+ error = file_write(map_get_path(map), "wb", &out);
if (error)
return error;
if (written != content_len) {
return pr_val_err(
"Couldn't write file '%s' (error code not available)",
- uri_get_local(uri)
+ map_get_path(map)
);
}
/* Remove a local file and its directory tree (if empty) */
static int
-delete_file(struct rpki_uri *uri)
+delete_file(struct cache_mapping *map)
{
/* Delete parent dirs only if empty. */
- return delete_dir_recursive_bottom_up(uri_get_local(uri));
+ return delete_dir_recursive_bottom_up(map_get_path(map));
}
static int
-handle_publish(xmlTextReaderPtr reader, struct rpki_uri *notif,
+handle_publish(xmlTextReaderPtr reader, struct cache_mapping *notif,
hash_requirement hr)
{
struct publish tag = { 0 };
}
static int
-handle_withdraw(xmlTextReaderPtr reader, struct rpki_uri *notif)
+handle_withdraw(xmlTextReaderPtr reader, struct cache_mapping *notif)
{
struct withdraw tag = { 0 };
int error;
if (error)
return error;
- if (!uri_same_origin(notif->uri, notif->snapshot.uri))
+ if (!map_same_origin(notif->map, notif->snapshot.uri))
return pr_val_err("Notification %s and Snapshot %s are not hosted by the same origin.",
- uri_get_global(notif->uri), uri_get_global(notif->snapshot.uri));
+ map_get_url(notif->map), map_get_url(notif->snapshot.uri));
return 0;
}
return error;
}
- if (!uri_same_origin(notif->uri, delta.meta.uri))
+ if (!map_same_origin(notif->map, delta.meta.uri))
return pr_val_err("Notification %s and Delta %s are not hosted by the same origin.",
- uri_get_global(notif->uri), uri_get_global(delta.meta.uri));
+ map_get_url(notif->map), map_get_url(delta.meta.uri));
notification_deltas_add(¬if->deltas, &delta);
return 0;
}
static int
-parse_notification(struct rpki_uri *uri, struct update_notification *result)
+parse_notification(struct cache_mapping *map, struct update_notification *result)
{
int error;
- update_notification_init(result, uri);
+ update_notification_init(result, map);
- error = relax_ng_parse(uri_get_local(uri), xml_read_notif, result);
+ error = relax_ng_parse(map_get_path(map), xml_read_notif, result);
if (error)
update_notification_cleanup(result);
}
static void
-delete_rpp(struct rpki_uri *notif)
+delete_rpp(struct cache_mapping *notif)
{
- char *path = uri_get_rrdp_workspace(notif);
+ char *path = map_get_rrdp_workspace(notif);
pr_val_debug("Snapshot: Deleting cached RPP '%s'.", path);
file_rm_rf(path);
free(path);
{
struct rrdp_ctx ctx;
- ctx.notif = notif->uri;
+ ctx.notif = notif->map;
ctx.session = notif->session;
- return relax_ng_parse(uri_get_local(notif->snapshot.uri),
+ return relax_ng_parse(map_get_path(notif->snapshot.uri),
xml_read_snapshot, &ctx);
}
static int
handle_snapshot(struct update_notification *notif)
{
- struct rpki_uri *uri;
+ struct cache_mapping *map;
int error;
- delete_rpp(notif->uri);
+ delete_rpp(notif->map);
- uri = notif->snapshot.uri;
+ map = notif->snapshot.uri;
- pr_val_debug("Processing snapshot '%s'.", uri_val_get_printable(uri));
- fnstack_push_uri(uri);
+ pr_val_debug("Processing snapshot '%s'.", map_val_get_printable(map));
+ fnstack_push_map(map);
/*
* TODO (performance) Is there a point in caching the snapshot?
* Maybe stream it instead.
* Same for deltas.
*/
- error = cache_download(validation_cache(state_retrieve()), uri, NULL,
+ error = cache_download(validation_cache(state_retrieve()), map, NULL,
NULL);
if (error)
goto end;
if (error)
goto end;
error = parse_snapshot(notif);
- delete_file(uri);
+ delete_file(map);
end:
fnstack_pop();
if (error)
return error;
- ctx.notif = notif->uri;
+ ctx.notif = notif->map;
ctx.session.session_id = notif->session.session_id;
ctx.session.serial = delta->serial;
- return relax_ng_parse(uri_get_local(delta->meta.uri), xml_read_delta,
+ return relax_ng_parse(map_get_path(delta->meta.uri), xml_read_delta,
&ctx);
}
static int
handle_delta(struct update_notification *notif, struct notification_delta *delta)
{
- struct rpki_uri *uri;
+ struct cache_mapping *map;
int error;
- uri = delta->meta.uri;
+ map = delta->meta.uri;
- pr_val_debug("Processing delta '%s'.", uri_val_get_printable(uri));
- fnstack_push_uri(uri);
+ pr_val_debug("Processing delta '%s'.", map_val_get_printable(map));
+ fnstack_push_map(map);
- error = cache_download(validation_cache(state_retrieve()), uri, NULL, NULL);
+ error = cache_download(validation_cache(state_retrieve()), map, NULL, NULL);
if (error)
goto end;
error = parse_delta(notif, delta);
- delete_file(uri);
+ delete_file(map);
end:
fnstack_pop();
}
/*
- * Downloads the Update Notification pointed by @uri, and updates the cache
+ * Downloads the Update Notification pointed by @map, and updates the cache
* accordingly.
*
* "Updates the cache accordingly" means it downloads the missing deltas or
* snapshot, and explodes them into the corresponding RPP's local directory.
*/
int
-rrdp_update(struct rpki_uri *uri)
+rrdp_update(struct cache_mapping *map)
{
struct cachefile_notification **cached, *old;
struct update_notification new;
int serial_cmp;
int error;
- fnstack_push_uri(uri);
+ fnstack_push_map(map);
pr_val_debug("Processing notification.");
- error = cache_download(validation_cache(state_retrieve()), uri,
+ error = cache_download(validation_cache(state_retrieve()), map,
&changed, &cached);
if (error)
goto end;
goto end;
}
- error = parse_notification(uri, &new);
+ error = parse_notification(map, &new);
if (error)
goto end;
pr_val_debug("New session/serial: %s/%s", new.session.session_id,
#ifndef SRC_RRDP_H_
#define SRC_RRDP_H_
-#include "types/uri.h"
+#include "types/map.h"
struct cachefile_notification;
-int rrdp_update(struct rpki_uri *);
+int rrdp_update(struct cache_mapping *);
json_t *rrdp_notif2json(struct cachefile_notification *);
int rrdp_json2notif(json_t *, struct cachefile_notification **);
struct validation_handler const *
validation_get_validation_handler(struct validation *);
-struct db_rrdp_uri *validation_get_rrdp_uris(struct validation *);
-
#endif /* SRC_STATE_H_ */
/**
* See fnstack_push().
*
- * This function cannot claim a reference for @uri, so @uri will have to outlive
+ * This function cannot claim a reference for @map, so @map will have to outlive
* the push/pop.
*/
void
-fnstack_push_uri(struct rpki_uri *uri)
+fnstack_push_map(struct cache_mapping *map)
{
- fnstack_push(uri_val_get_printable(uri));
+ fnstack_push(map_val_get_printable(map));
}
/* Returns the file name on the top of the file name stack. */
void fnstack_cleanup(void);
void fnstack_push(char const *);
-void fnstack_push_uri(struct rpki_uri *);
+void fnstack_push_map(struct cache_mapping *);
char const *fnstack_peek(void);
void fnstack_pop(void);
-#include "types/uri.h"
+#include "types/map.h"
#include "alloc.h"
#include "common.h"
/**
* Aside from the reference counter, instances are meant to be immutable.
*
- * TODO (fine) Needs rebranding. AFAIK, RPKI does not impose significant
- * restrictions to regular URIs (except for schema, I guess), "global URI" is
- * pretty much tautologic, and "local URI" is a misnomer. (Because it doesn't
- * have anything to do with 'interpretation is independent of access'.)
- * I can't even remember if this nomenclature made sense at some point.
- * It's more of a mapping than a URI.
- *
- * TODO (fine) Also, this structure is so intertwined with the cache module,
+ * TODO (fine) This structure is so intertwined with the cache module,
* nowadays it feels like it should be moved there.
*/
-struct rpki_uri {
+struct cache_mapping {
/**
- * "Global URI".
* The one that always starts with "rsync://" or "https://".
* Normalized, ASCII-only, NULL-terminated.
*/
- char *global;
+ char *url;
/**
- * "Local URI".
- * The file pointed by @global, but cached in the local filesystem.
+ * Cache location where we downloaded the file.
* Normalized, ASCII-only, NULL-terminated.
* Sometimes NULL, depending on @type.
*/
- char *local;
+ char *path;
- enum uri_type type;
+ enum map_type type;
unsigned int references; /* Reference counter */
};
* checking legal characters, anyway.
*
* What I really need this validation for is ensure that we won't get
- * any trouble later, when we attempt to convert the global URI to a
- * local file.
+ * any trouble later, when we attempt to map the URL to a path.
*
* Sample trouble: Getting UTF-8 characters. Why are they trouble?
* Because we don't have any guarantees that the system's file name
: pr_val_err("URL has non-printable character code '%d'.", character);
}
-static int append_guri(struct path_builder *, char const *, char const *,
- int, bool);
+static int normalize_url(struct path_builder *, char const *, char const *, int);
/**
- * Initializes @uri->global by building a normalized version of @str.
+ * Initializes @map->url by building a normalized version of @str.
*/
static int
-str2global(char const *str, struct rpki_uri *uri)
+init_url(struct cache_mapping *map, char const *str)
{
#define SCHEMA_LEN 8 /* strlen("rsync://"), strlen("https://") */
struct path_builder pb;
if (str == NULL){
- uri->global = NULL;
+ map->url = NULL;
return 0;
}
pfx = NULL;
error = 0;
- switch (uri->type) {
- case UT_TA_RSYNC:
- case UT_RPP:
- case UT_CAGED:
- case UT_AIA:
- case UT_SO:
- case UT_MFT:
+ switch (map->type) {
+ case MAP_TA_RSYNC:
+ case MAP_RPP:
+ case MAP_CAGED:
+ case MAP_AIA:
+ case MAP_SO:
+ case MAP_MFT:
pfx = "rsync://";
error = ENOTRSYNC;
break;
- case UT_TA_HTTP:
- case UT_NOTIF:
- case UT_TMP:
+ case MAP_TA_HTTP:
+ case MAP_NOTIF:
+ case MAP_TMP:
pfx = "https://";
error = ENOTHTTPS;
break;
}
if (pfx == NULL)
- pr_crit("Unknown URI type: %u", uri->type);
+ pr_crit("Unknown mapping type: %u", map->type);
__pb_init(&pb, SCHEMA_LEN - 1);
- error = append_guri(&pb, str, pfx, error, true);
+ error = normalize_url(&pb, str, pfx, error);
if (error) {
pb_cleanup(&pb);
return error;
}
- uri->global = strncpy(pb.string, str, SCHEMA_LEN);
+ map->url = strncpy(pb.string, str, SCHEMA_LEN);
return 0;
}
}
/**
- * Initializes @uri->global given manifest path @mft and its referenced file
- * @ia5.
+ * Initializes @map->url given manifest path @mft and its referenced file @ia5.
*
- * ie. if @mft is "rsync://a/b/c.mft" and @ia5 is "d.cer", @uri->global will
- * be "rsync://a/b/d.cer".
+ * ie. if @mft is "rsync://a/b/c.mft" and @ia5 is "d.cer", @map->url will be
+ * "rsync://a/b/d.cer".
*
- * Assumes that @mft is a "global" URL. (ie. extracted from rpki_uri.global.)
+ * Assumes @mft is already normalized.
*/
static int
-ia5str2global(struct rpki_uri *uri, char const *mft, IA5String_t *ia5)
+ia5str2url(struct cache_mapping *map, char const *mft, IA5String_t *ia5)
{
char *joined;
char const *slash_pos;
strncpy(joined + dir_len, (char *) ia5->buf, ia5->size);
joined[dir_len + ia5->size] = '\0';
- uri->global = joined;
+ map->url = joined;
return 0;
}
}
static int
-append_guri(struct path_builder *pb, char const *guri, char const *gprefix,
- int err, bool skip_schema)
+normalize_url(struct path_builder *pb, char const *url, char const *pfx,
+ int errnot)
{
struct path_parser parser;
size_t dot_dot_limit;
int error;
/* Schema */
- if (!str_starts_with(guri, gprefix)) {
- pr_val_err("URI '%s' does not begin with '%s'.", guri, gprefix);
- return err;
- }
-
- if (!skip_schema) {
- error = pb_appendn(pb, guri, 5);
- if (error)
- return error;
+ if (!str_starts_with(url, pfx)) {
+ pr_val_err("URL '%s' does not begin with '%s'.", url, pfx);
+ return errnot;
}
/* Domain */
- parser.slash = guri + 7;
+ parser.slash = url + 7;
if (!path_next(&parser))
- return pr_val_err("URI '%s' seems to lack a domain.", guri);
+ return pr_val_err("URL '%s' seems to lack a domain.", url);
if (path_is_dot(&parser)) {
/* Dumping files to the cache root is unsafe. */
- return pr_val_err("URI '%s' employs the root domain. This is not really cacheable, so I'm going to distrust it.",
- guri);
+ return pr_val_err("URL '%s' employs the root domain. This is not really cacheable, so I'm going to distrust it.",
+ url);
}
if (path_is_dotdots(&parser)) {
- return pr_val_err("URI '%s' seems to be dot-dotting past its own schema.",
- guri);
+ return pr_val_err("URL '%s' seems to be dot-dotting past its own schema.",
+ url);
}
error = pb_appendn(pb, parser.token, parser.len);
if (error)
if (error)
return error;
if (pb->len < dot_dot_limit) {
- return pr_val_err("URI '%s' seems to be dot-dotting past its own domain.",
- guri);
+ return pr_val_err("URL '%s' seems to be dot-dotting past its own domain.",
+ url);
}
} else if (!path_is_dot(&parser)) {
error = pb_appendn(pb, parser.token, parser.len);
}
static int
-get_rrdp_workspace(struct path_builder *pb, struct rpki_uri *notif)
+get_rrdp_workspace(struct path_builder *pb, struct cache_mapping *notif)
{
int error;
if (error)
return error;
- error = pb_append(pb, ¬if->global[SCHEMA_LEN]);
+ error = pb_append(pb, ¬if->url[SCHEMA_LEN]);
if (error)
pb_cleanup(pb);
* Maps "rsync://a.b.c/d/e.cer" into "<local-repository>/rsync/a.b.c/d/e.cer".
*/
static int
-map_simple(struct rpki_uri *uri, char const *subdir)
+map_simple(struct cache_mapping *map, char const *subdir)
{
struct path_builder pb;
int error;
if (error)
return error;
- error = pb_append(&pb, &uri->global[SCHEMA_LEN]);
+ error = pb_append(&pb, &map->url[SCHEMA_LEN]);
if (error) {
pb_cleanup(&pb);
return error;
}
- uri->local = pb.string;
+ map->path = pb.string;
return 0;
}
* "<local-repository>/rrdp/<notification-path>/a.b.c/d/e.cer".
*/
static int
-map_caged(struct rpki_uri *uri, struct rpki_uri *notif)
+map_caged(struct cache_mapping *map, struct cache_mapping *notif)
{
struct path_builder pb;
int error;
if (error)
return error;
- if (uri->global == NULL)
+ if (map->url == NULL)
goto success; /* Caller is only interested in the cage. */
- error = pb_append(&pb, &uri->global[SCHEMA_LEN]);
+ error = pb_append(&pb, &map->url[SCHEMA_LEN]);
if (error) {
pb_cleanup(&pb);
return error;
}
success:
- uri->local = pb.string;
+ map->path = pb.string;
return 0;
}
static int
-autocomplete_local(struct rpki_uri *uri, struct rpki_uri *notif)
+init_path(struct cache_mapping *map, struct cache_mapping *notif)
{
- switch (uri->type) {
- case UT_TA_RSYNC:
- case UT_RPP:
- case UT_MFT:
- return map_simple(uri, "rsync");
+ switch (map->type) {
+ case MAP_TA_RSYNC:
+ case MAP_RPP:
+ case MAP_MFT:
+ return map_simple(map, "rsync");
- case UT_TA_HTTP:
- return map_simple(uri, "https");
+ case MAP_TA_HTTP:
+ return map_simple(map, "https");
- case UT_NOTIF:
- case UT_TMP:
- return cache_tmpfile(&uri->local);
+ case MAP_NOTIF:
+ case MAP_TMP:
+ return cache_tmpfile(&map->path);
- case UT_CAGED:
- return map_caged(uri, notif);
+ case MAP_CAGED:
+ return map_caged(map, notif);
- case UT_AIA:
- case UT_SO:
- uri->local = NULL;
+ case MAP_AIA:
+ case MAP_SO:
+ map->path = NULL;
return 0;
}
- pr_crit("Unknown URI type: %u", uri->type);
+ pr_crit("Unknown URL type: %u", map->type);
}
int
-uri_create(struct rpki_uri **result, enum uri_type type, struct rpki_uri *notif,
- char const *guri)
+map_create(struct cache_mapping **result, enum map_type type,
+ struct cache_mapping *notif, char const *url)
{
- struct rpki_uri *uri;
+ struct cache_mapping *map;
int error;
- uri = pmalloc(sizeof(struct rpki_uri));
- uri->type = type;
- uri->references = 1;
+ map = pmalloc(sizeof(struct cache_mapping));
+ map->type = type;
+ map->references = 1;
- error = str2global(guri, uri);
+ error = init_url(map, url);
if (error) {
- free(uri);
+ free(map);
return error;
}
- error = autocomplete_local(uri, notif);
+ error = init_path(map, notif);
if (error) {
- free(uri->global);
- free(uri);
+ free(map->url);
+ free(map);
return error;
}
- *result = uri;
+ *result = map;
return 0;
}
* names. This function will infer the rest of the URL.
*/
int
-uri_create_mft(struct rpki_uri **result, struct rpki_uri *notif,
- struct rpki_uri *mft, IA5String_t *ia5)
+map_create_mft(struct cache_mapping **result, struct cache_mapping *notif,
+ struct cache_mapping *mft, IA5String_t *ia5)
{
- struct rpki_uri *uri;
+ struct cache_mapping *map;
int error;
- uri = pmalloc(sizeof(struct rpki_uri));
- uri->type = (notif == NULL) ? UT_RPP : UT_CAGED;
- uri->references = 1;
+ map = pmalloc(sizeof(struct cache_mapping));
+ map->type = (notif == NULL) ? MAP_RPP : MAP_CAGED;
+ map->references = 1;
- error = ia5str2global(uri, mft->global, ia5);
+ error = ia5str2url(map, mft->url, ia5);
if (error) {
- free(uri);
+ free(map);
return error;
}
- error = autocomplete_local(uri, notif);
+ error = init_path(map, notif);
if (error) {
- free(uri->global);
- free(uri);
+ free(map->url);
+ free(map);
return error;
}
- *result = uri;
+ *result = map;
return 0;
}
-/* Cache-only; global URI and type are meaningless. */
-struct rpki_uri *
-uri_create_cache(char const *path)
+/* Cache-only; url and type are meaningless. */
+struct cache_mapping *
+map_create_cache(char const *path)
{
- struct rpki_uri *uri;
+ struct cache_mapping *map;
- uri = pzalloc(sizeof(struct rpki_uri));
- uri->local = pstrdup(path);
- uri->references = 1;
+ map = pzalloc(sizeof(struct cache_mapping));
+ map->path = pstrdup(path);
+ map->references = 1;
- return uri;
+ return map;
}
-struct rpki_uri *
-uri_refget(struct rpki_uri *uri)
+struct cache_mapping *
+map_refget(struct cache_mapping *map)
{
- uri->references++;
- return uri;
+ map->references++;
+ return map;
}
void
-uri_refput(struct rpki_uri *uri)
+map_refput(struct cache_mapping *map)
{
- if (uri == NULL)
+ if (map == NULL)
return;
- uri->references--;
- if (uri->references == 0) {
- free(uri->global);
- free(uri->local);
- free(uri);
+ map->references--;
+ if (map->references == 0) {
+ free(map->url);
+ free(map->path);
+ free(map);
}
}
char const *
-uri_get_global(struct rpki_uri *uri)
+map_get_url(struct cache_mapping *map)
{
- return uri->global;
+ return map->url;
}
char const *
-uri_get_local(struct rpki_uri *uri)
+map_get_path(struct cache_mapping *map)
{
- return uri->local;
+ return map->path;
}
bool
-uri_equals(struct rpki_uri *u1, struct rpki_uri *u2)
+map_equals(struct cache_mapping *m1, struct cache_mapping *m2)
{
- return strcmp(u1->global, u2->global) == 0;
+ return strcmp(m1->url, m2->url) == 0;
}
bool
-str_same_origin(char const *g1, char const *g2)
+str_same_origin(char const *url1, char const *url2)
{
size_t c, slashes;
slashes = 0;
- for (c = 0; g1[c] == g2[c]; c++) {
- switch (g1[c]) {
+ for (c = 0; url1[c] == url2[c]; c++) {
+ switch (url1[c]) {
case '/':
slashes++;
if (slashes == 3)
}
}
- if (g1[c] == '\0')
- return (slashes == 2) && g2[c] == '/';
- if (g2[c] == '\0')
- return (slashes == 2) && g1[c] == '/';
+ if (url1[c] == '\0')
+ return (slashes == 2) && url2[c] == '/';
+ if (url2[c] == '\0')
+ return (slashes == 2) && url1[c] == '/';
return false;
}
bool
-uri_same_origin(struct rpki_uri *u1, struct rpki_uri *u2)
+map_same_origin(struct cache_mapping *m1, struct cache_mapping *m2)
{
- return str_same_origin(u1->global, u2->global);
+ return str_same_origin(m1->url, m2->url);
}
/* @ext must include the period. */
bool
-uri_has_extension(struct rpki_uri *uri, char const *ext)
+map_has_extension(struct cache_mapping *map, char const *ext)
{
- return str_ends_with(uri->global, ext);
+ return str_ends_with(map->url, ext);
}
bool
-uri_is_certificate(struct rpki_uri *uri)
+map_is_certificate(struct cache_mapping *map)
{
- return uri_has_extension(uri, ".cer");
+ return map_has_extension(map, ".cer");
}
-enum uri_type
-uri_get_type(struct rpki_uri *uri)
+enum map_type
+map_get_type(struct cache_mapping *map)
{
- return uri->type;
+ return map->type;
}
static char const *
}
static char const *
-uri_get_printable(struct rpki_uri *uri, enum filename_format format)
+map_get_printable(struct cache_mapping *map, enum filename_format format)
{
switch (format) {
case FNF_GLOBAL:
- return uri->global;
+ return map->url;
case FNF_LOCAL:
- return uri->local;
+ return map->path;
case FNF_NAME:
- return get_filename(uri->global);
+ return get_filename(map->url);
}
pr_crit("Unknown file name format: %u", format);
}
char const *
-uri_val_get_printable(struct rpki_uri *uri)
+map_val_get_printable(struct cache_mapping *map)
{
enum filename_format format;
format = config_get_val_log_filename_format();
- return uri_get_printable(uri, format);
+ return map_get_printable(map, format);
}
char const *
-uri_op_get_printable(struct rpki_uri *uri)
+map_op_get_printable(struct cache_mapping *map)
{
enum filename_format format;
format = config_get_op_log_filename_format();
- return uri_get_printable(uri, format);
+ return map_get_printable(map, format);
}
char *
-uri_get_rrdp_workspace(struct rpki_uri *notif)
+map_get_rrdp_workspace(struct cache_mapping *notif)
{
struct path_builder pb;
return (get_rrdp_workspace(&pb, notif) == 0) ? pb.string : NULL;
}
-DEFINE_ARRAY_LIST_FUNCTIONS(uri_list, struct rpki_uri *, static)
+DEFINE_ARRAY_LIST_FUNCTIONS(map_list, struct cache_mapping *, static)
void
-uris_init(struct uri_list *uris)
+maps_init(struct map_list *maps)
{
- uri_list_init(uris);
+ map_list_init(maps);
}
static void
-__uri_refput(struct rpki_uri **uri)
+__map_refput(struct cache_mapping **map)
{
- uri_refput(*uri);
+ map_refput(*map);
}
void
-uris_cleanup(struct uri_list *uris)
+maps_cleanup(struct map_list *maps)
{
- uri_list_cleanup(uris, __uri_refput);
+ map_list_cleanup(maps, __map_refput);
}
-/* Swallows @uri. */
+/* Swallows @map. */
void
-uris_add(struct uri_list *uris, struct rpki_uri *uri)
+maps_add(struct map_list *maps, struct cache_mapping *map)
{
- uri_list_add(uris, &uri);
+ map_list_add(maps, &map);
}
--- /dev/null
+#ifndef SRC_TYPES_MAP_H_
+#define SRC_TYPES_MAP_H_
+
+#include "asn1/asn1c/IA5String.h"
+#include "data_structure/array_list.h"
+
+/*
+ * "Long" time = seven days.
+ * Currently hardcoded, but queued for tweakability.
+ */
+enum map_type {
+ /*
+ * TAL's TA URL.
+ * The file is cached until it's untraversed for a "long" time.
+ */
+ MAP_TA_RSYNC,
+ MAP_TA_HTTP,
+
+ /*
+ * (rsync) Repository Publication Point. RFC 6481.
+ * The directory is cached until it's untraversed for a "long" time.
+ */
+ MAP_RPP,
+
+ /*
+ * An RRDP notification file; downloaded via HTTP.
+ * The file itself is not cached, but we preserve a handful of metadata
+ * that is needed in subsequent iterations.
+ * The metadata is cached until it's untraversed for a "long" time.
+ */
+ MAP_NOTIF,
+
+ /*
+ * RRDP Snapshot or Delta; downloaded via HTTP.
+ * The file itself is not cached, but we preserve some small metadata.
+ * The metadata is destroyed once the iteration finishes.
+ */
+ MAP_TMP,
+
+ /*
+ * Endangered species; bound to be removed once RFC 9286 is implemented.
+ */
+ MAP_CAGED,
+
+ MAP_AIA, /* caIssuers. Not directly downloaded. */
+ MAP_SO, /* signedObject. Not directly downloaded. */
+ MAP_MFT, /* rpkiManifest. Not directly downloaded. */
+};
+
+struct cache_mapping;
+
+int map_create(struct cache_mapping **, enum map_type, struct cache_mapping *,
+ char const *);
+int map_create_mft(struct cache_mapping **, struct cache_mapping *, struct cache_mapping *,
+ IA5String_t *);
+struct cache_mapping *map_create_cache(char const *);
+
+#define map_create_caged(map, notif, url) \
+ map_create(map, MAP_CAGED, notif, url)
+#define map_create_cage(map, notif) \
+ map_create_caged(map, notif, NULL)
+
+struct cache_mapping *map_refget(struct cache_mapping *);
+void map_refput(struct cache_mapping *);
+
+/*
+ * Note that, if you intend to print some mapping, you're likely supposed to use
+ * map_get_printable() instead.
+ */
+char const *map_get_url(struct cache_mapping *);
+char const *map_get_path(struct cache_mapping *);
+
+bool map_equals(struct cache_mapping *, struct cache_mapping *);
+bool str_same_origin(char const *, char const *);
+bool map_same_origin(struct cache_mapping *, struct cache_mapping *);
+bool map_has_extension(struct cache_mapping *, char const *);
+bool map_is_certificate(struct cache_mapping *);
+
+enum map_type map_get_type(struct cache_mapping *);
+
+char const *map_val_get_printable(struct cache_mapping *);
+char const *map_op_get_printable(struct cache_mapping *);
+
+char *map_get_rrdp_workspace(struct cache_mapping *);
+
+/* Plural */
+
+DEFINE_ARRAY_LIST_STRUCT(map_list, struct cache_mapping *);
+
+void maps_init(struct map_list *);
+void maps_cleanup(struct map_list *);
+
+void maps_add(struct map_list *, struct cache_mapping *);
+
+#endif /* SRC_TYPES_MAP_H_ */
+++ /dev/null
-#ifndef SRC_TYPES_URI_H_
-#define SRC_TYPES_URI_H_
-
-#include "asn1/asn1c/IA5String.h"
-#include "data_structure/array_list.h"
-
-/*
- * "Long" time = seven days.
- * Currently hardcoded, but queued for tweakability.
- */
-enum uri_type {
- /*
- * TAL's TA URL.
- * The file is cached until it's untraversed for a "long" time.
- */
- UT_TA_RSYNC,
- UT_TA_HTTP,
-
- /*
- * (rsync) Repository Publication Point. RFC 6481.
- * The directory is cached until it's untraversed for a "long" time.
- */
- UT_RPP,
-
- /*
- * An RRDP notification file; downloaded via HTTP.
- * The file itself is not cached, but we preserve a handful of metadata
- * that is needed in subsequent iterations.
- * The metadata is cached until it's untraversed for a "long" time.
- */
- UT_NOTIF,
-
- /*
- * RRDP Snapshot or Delta; downloaded via HTTP.
- * The file itself is not cached, but we preserve some small metadata.
- * The metadata is destroyed once the iteration finishes.
- */
- UT_TMP,
-
- /*
- * Endangered species; bound to be removed once RFC 9286 is implemented.
- */
- UT_CAGED,
-
- UT_AIA, /* caIssuers. Not directly downloaded. */
- UT_SO, /* signedObject. Not directly downloaded. */
- UT_MFT, /* rpkiManifest. Not directly downloaded. */
-};
-
-struct rpki_uri;
-
-int uri_create(struct rpki_uri **, enum uri_type, struct rpki_uri *,
- char const *);
-int uri_create_mft(struct rpki_uri **, struct rpki_uri *, struct rpki_uri *,
- IA5String_t *);
-struct rpki_uri *uri_create_cache(char const *);
-
-#define uri_create_caged(uri, notif, guri) \
- uri_create(uri, UT_CAGED, notif, guri)
-#define uri_create_cage(uri, notif) \
- uri_create_caged(uri, notif, NULL)
-
-struct rpki_uri *uri_refget(struct rpki_uri *);
-void uri_refput(struct rpki_uri *);
-
-/*
- * Note that, if you intend to print some URI, you're likely supposed to use
- * uri_get_printable() instead.
- */
-char const *uri_get_global(struct rpki_uri *);
-char const *uri_get_local(struct rpki_uri *);
-
-bool uri_equals(struct rpki_uri *, struct rpki_uri *);
-bool str_same_origin(char const *, char const *);
-bool uri_same_origin(struct rpki_uri *, struct rpki_uri *);
-bool uri_has_extension(struct rpki_uri *, char const *);
-bool uri_is_certificate(struct rpki_uri *);
-
-enum uri_type uri_get_type(struct rpki_uri *);
-
-char const *uri_val_get_printable(struct rpki_uri *);
-char const *uri_op_get_printable(struct rpki_uri *);
-
-char *uri_get_rrdp_workspace(struct rpki_uri *);
-
-/* Plural */
-
-DEFINE_ARRAY_LIST_STRUCT(uri_list, struct rpki_uri *);
-
-void uris_init(struct uri_list *);
-void uris_cleanup(struct uri_list *);
-
-void uris_add(struct uri_list *, struct rpki_uri *);
-
-#endif /* SRC_TYPES_URI_H_ */
check_PROGRAMS += serial.test
check_PROGRAMS += tal.test
check_PROGRAMS += thread_pool.test
-check_PROGRAMS += uri.test
+check_PROGRAMS += map.test
check_PROGRAMS += uthash.test
check_PROGRAMS += vcard.test
check_PROGRAMS += vrps.test
thread_pool_test_SOURCES = thread_pool_test.c
thread_pool_test_LDADD = ${MY_LDADD}
-uri_test_SOURCES = types/uri_test.c
-uri_test_LDADD = ${MY_LDADD}
+map_test_SOURCES = types/map_test.c
+map_test_LDADD = ${MY_LDADD}
uthash_test_SOURCES = data_structure/uthash_test.c
uthash_test_LDADD = ${MY_LDADD}
#include "json_util.c"
#include "mock.c"
#include "data_structure/path_builder.c"
-#include "types/uri.c"
+#include "types/map.c"
/* Mocks */
}
int
-http_download(struct rpki_uri *uri, curl_off_t ims, bool *changed)
+http_download(struct cache_mapping *map, curl_off_t ims, bool *changed)
{
int error;
https_counter++;
- error = pretend_download(uri_get_local(uri));
+ error = pretend_download(map_get_path(map));
if (changed != NULL)
*changed = error ? false : true;
return error;
}
-MOCK_ABORT_INT(rrdp_update, struct rpki_uri *uri)
+MOCK_ABORT_INT(rrdp_update, struct cache_mapping *map)
__MOCK_ABORT(rrdp_notif2json, json_t *, NULL, struct cachefile_notification *notif)
MOCK_VOID(rrdp_notif_free, struct cachefile_notification *notif)
MOCK_ABORT_INT(rrdp_json2notif, json_t *json, struct cachefile_notification **result)
run_cache_download(char const *url, int expected_error,
unsigned int rsync_calls, unsigned int https_calls)
{
- struct rpki_uri *uri;
- enum uri_type type;
+ struct cache_mapping *map;
+ enum map_type type;
if (str_starts_with(url, "https://"))
- type = UT_TA_HTTP;
+ type = MAP_TA_HTTP;
else if (str_starts_with(url, "rsync://"))
- type = UT_RPP;
+ type = MAP_RPP;
else
ck_abort_msg("Bad protocol: %s", url);
rsync_counter = 0;
https_counter = 0;
- ck_assert_int_eq(0, uri_create(&uri, type, NULL, url));
- ck_assert_int_eq(expected_error, cache_download(cache, uri, NULL, NULL));
+ ck_assert_int_eq(0, map_create(&map, type, NULL, url));
+ ck_assert_int_eq(expected_error, cache_download(cache, map, NULL, NULL));
ck_assert_uint_eq(rsync_calls, rsync_counter);
ck_assert_uint_eq(https_calls, https_counter);
- uri_refput(uri);
+ map_refput(map);
}
static struct cache_node *
node(char const *url, time_t attempt, int err, bool succeeded, time_t success,
bool is_notif)
{
- enum uri_type type;
+ enum map_type type;
struct cache_node *result;
if (str_starts_with(url, "https://"))
- type = is_notif ? UT_NOTIF : UT_TA_HTTP;
+ type = is_notif ? MAP_NOTIF : MAP_TA_HTTP;
else if (str_starts_with(url, "rsync://"))
- type = UT_RPP;
+ type = MAP_RPP;
else
ck_abort_msg("Bad protocol: %s", url);
result = pzalloc(sizeof(struct cache_node));
- ck_assert_int_eq(0, uri_create(&result->url, type, NULL, url));
+ ck_assert_int_eq(0, map_create(&result->map, type, NULL, url));
result->attempt.ts = attempt;
result->attempt.result = err;
result->success.happened = succeeded;
struct downloaded_path *path;
SLIST_FOREACH(path, &downloaded, hook)
- if (strcmp(uri_get_local(node->url), path->path) == 0) {
+ if (strcmp(map_get_path(node->map), path->path) == 0) {
if (path->visited)
return NULL;
else {
return;
}
- ck_assert_str_eq(uri_get_global(expected->url), uri_get_global(actual->url));
+ ck_assert_str_eq(map_get_url(expected->map), map_get_url(actual->map));
/* ck_assert_int_eq(expected->attempt.ts, actual->attempt.ts); */
ck_assert_int_eq(expected->attempt.result, actual->attempt.result);
ck_assert_int_eq(expected->success.happened, actual->success.happened);
va_start(args, trash);
while ((e = va_arg(args, struct cache_node *)) != NULL) {
printf("- %s %s error:%u success:%u\n",
- uri_get_global(e->url), uri_get_local(e->url),
+ map_get_url(e->map), map_get_path(e->map),
e->attempt.result, e->success.happened);
- key = uri_get_global(e->url);
+ key = map_get_url(e->map);
HASH_ADD_KEYPTR(hh, expected, key, strlen(key), e);
}
va_end(args);
printf("Actual nodes:\n");
HASH_ITER(hh, cache->ht, a, tmp)
printf("- %s %s attempt:%u success:%u\n",
- uri_get_global(a->url), uri_get_local(a->url),
+ map_get_url(a->map), map_get_path(a->map),
a->attempt.result, a->success.happened);
printf("\n");
if (e->attempt.ts) { /* "if should have cache file" */
if (path == NULL)
ck_abort_msg("Cached file is missing: %s",
- uri_get_local(e->url));
+ map_get_path(e->map));
path->visited = true;
} else {
if (path != NULL) {
/* Compare expected and actual */
HASH_ITER(hh, cache->ht, a, tmp) {
- key = uri_get_global(a->url);
+ key = map_get_url(a->map);
HASH_FIND_STR(expected, key, e);
if (e == NULL)
ck_abort_msg("Unexpected actual: %s", key);
validate_node(e, a);
HASH_DEL(expected, e);
- uri_refput(e->url);
+ map_refput(e->map);
free(e);
}
if (HASH_COUNT(expected) != 0)
ck_abort_msg("Actual node is mising: %s",
- uri_get_global(expected->url));
+ map_get_url(expected->map));
}
static void
END_TEST
static void
-prepare_uri_list(struct uri_list *uris, ...)
+prepare_map_list(struct map_list *maps, ...)
{
char const *str;
- enum uri_type type;
- struct rpki_uri *uri;
+ enum map_type type;
+ struct cache_mapping *map;
va_list args;
- uris_init(uris);
+ maps_init(maps);
- va_start(args, uris);
+ va_start(args, maps);
while ((str = va_arg(args, char const *)) != NULL) {
if (str_starts_with(str, "https://"))
- type = UT_TA_HTTP;
+ type = MAP_TA_HTTP;
else if (str_starts_with(str, "rsync://"))
- type = UT_RPP;
+ type = MAP_RPP;
else
ck_abort_msg("Bad protocol: %s", str);
- ck_assert_int_eq(0, uri_create(&uri, type, NULL, str));
- uris_add(uris, uri);
+ ck_assert_int_eq(0, map_create(&map, type, NULL, str));
+ maps_add(maps, map);
}
va_end(args);
}
-#define PREPARE_URI_LIST(uris, ...) prepare_uri_list(uris, ##__VA_ARGS__, NULL)
+#define PREPARE_MAP_LIST(maps, ...) prepare_map_list(maps, ##__VA_ARGS__, NULL)
START_TEST(test_recover)
{
- struct uri_list uris;
+ struct map_list maps;
setup_test();
/* Query on empty database */
- PREPARE_URI_LIST(&uris, "rsync://a.b.c/d", "https://a.b.c/d");
- ck_assert_ptr_eq(NULL, cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ PREPARE_MAP_LIST(&maps, "rsync://a.b.c/d", "https://a.b.c/d");
+ ck_assert_ptr_eq(NULL, cache_recover(cache, &maps));
+ maps_cleanup(&maps);
/* Only first URI is cached */
cache_reset(cache);
run_cache_download("rsync://a/b/c", 0, 1, 0);
- PREPARE_URI_LIST(&uris, "rsync://a/b/c", "https://d/e", "https://f");
- ck_assert_ptr_eq(uris.array[0], cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ PREPARE_MAP_LIST(&maps, "rsync://a/b/c", "https://d/e", "https://f");
+ ck_assert_ptr_eq(maps.array[0], cache_recover(cache, &maps));
+ maps_cleanup(&maps);
/* Only second URI is cached */
cache_reset(cache);
run_cache_download("https://d/e", 0, 0, 1);
- PREPARE_URI_LIST(&uris, "rsync://a/b/c", "https://d/e", "https://f");
- ck_assert_ptr_eq(uris.array[1], cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ PREPARE_MAP_LIST(&maps, "rsync://a/b/c", "https://d/e", "https://f");
+ ck_assert_ptr_eq(maps.array[1], cache_recover(cache, &maps));
+ maps_cleanup(&maps);
/* Only third URI is cached */
cache_reset(cache);
run_cache_download("https://f", 0, 0, 1);
- PREPARE_URI_LIST(&uris, "rsync://a/b/c", "https://d/e", "https://f");
- ck_assert_ptr_eq(uris.array[2], cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ PREPARE_MAP_LIST(&maps, "rsync://a/b/c", "https://d/e", "https://f");
+ ck_assert_ptr_eq(maps.array[2], cache_recover(cache, &maps));
+ maps_cleanup(&maps);
/* None was cached */
cache_reset(cache);
run_cache_download("rsync://d/e", 0, 1, 0);
- PREPARE_URI_LIST(&uris, "rsync://a/b/c", "https://d/e", "https://f");
- ck_assert_ptr_eq(NULL, cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ PREPARE_MAP_LIST(&maps, "rsync://a/b/c", "https://d/e", "https://f");
+ ck_assert_ptr_eq(NULL, cache_recover(cache, &maps));
+ maps_cleanup(&maps);
/*
* At present, cache_recover() can only be called after all of a
add_node(cache, node("rsync://b/6", 100, 1, 0, 200, 0));
/* Multiple successful caches: Prioritize the most recent one */
- PREPARE_URI_LIST(&uris, "rsync://a/1", "rsync://a/3", "rsync://a/5");
- ck_assert_ptr_eq(uris.array[2], cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ PREPARE_MAP_LIST(&maps, "rsync://a/1", "rsync://a/3", "rsync://a/5");
+ ck_assert_ptr_eq(maps.array[2], cache_recover(cache, &maps));
+ maps_cleanup(&maps);
- PREPARE_URI_LIST(&uris, "rsync://a/5", "rsync://a/1", "rsync://a/3");
- ck_assert_ptr_eq(uris.array[0], cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ PREPARE_MAP_LIST(&maps, "rsync://a/5", "rsync://a/1", "rsync://a/3");
+ ck_assert_ptr_eq(maps.array[0], cache_recover(cache, &maps));
+ maps_cleanup(&maps);
/* No successful caches: No viable candidates */
- PREPARE_URI_LIST(&uris, "rsync://b/2", "rsync://b/4", "rsync://b/6");
- ck_assert_ptr_eq(NULL, cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ PREPARE_MAP_LIST(&maps, "rsync://b/2", "rsync://b/4", "rsync://b/6");
+ ck_assert_ptr_eq(NULL, cache_recover(cache, &maps));
+ maps_cleanup(&maps);
/* Status: CNF_SUCCESS is better than 0. */
- PREPARE_URI_LIST(&uris, "rsync://b/1", "rsync://a/1");
- ck_assert_ptr_eq(uris.array[1], cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ PREPARE_MAP_LIST(&maps, "rsync://b/1", "rsync://a/1");
+ ck_assert_ptr_eq(maps.array[1], cache_recover(cache, &maps));
+ maps_cleanup(&maps);
/*
* If CNF_SUCCESS && error, Fort will probably run into a problem
* But it should still TRY to read it, as there's a chance the
* outdatedness is not that severe.
*/
- PREPARE_URI_LIST(&uris, "rsync://a/2", "rsync://b/2");
- ck_assert_ptr_eq(uris.array[0], cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ PREPARE_MAP_LIST(&maps, "rsync://a/2", "rsync://b/2");
+ ck_assert_ptr_eq(maps.array[0], cache_recover(cache, &maps));
+ maps_cleanup(&maps);
/* Parents of downloaded nodes */
- PREPARE_URI_LIST(&uris, "rsync://a", "rsync://b");
- ck_assert_ptr_eq(NULL, cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ PREPARE_MAP_LIST(&maps, "rsync://a", "rsync://b");
+ ck_assert_ptr_eq(NULL, cache_recover(cache, &maps));
+ maps_cleanup(&maps);
/* Try them all at the same time */
- PREPARE_URI_LIST(&uris,
+ PREPARE_MAP_LIST(&maps,
"rsync://a", "rsync://a/1", "rsync://a/2", "rsync://a/3",
"rsync://a/4", "rsync://a/5", "rsync://a/6",
"rsync://b", "rsync://b/1", "rsync://b/2", "rsync://b/3",
"rsync://b/4", "rsync://b/5", "rsync://b/6",
"rsync://e/1");
- ck_assert_ptr_eq(uris.array[5], cache_recover(cache, &uris));
- uris_cleanup(&uris);
+ ck_assert_ptr_eq(maps.array[5], cache_recover(cache, &maps));
+ maps_cleanup(&maps);
cleanup_test();
}
#include "file.c"
#include "mock.c"
#include "data_structure/path_builder.c"
-#include "types/uri.c"
+#include "types/map.c"
#include "crypto/hash.c"
MOCK_ABORT_INT(cache_tmpfile, char **filename)
struct hash_algorithm const *ha;
char const *name;
char const *input = "Fort";
- struct rpki_uri uri = { 0 };
+ struct cache_mapping map = { 0 };
hash_setup();
- uri.global = "https://example.com/resources/lorem-ipsum.txt";
- uri.local = "resources/lorem-ipsum.txt";
- uri.type = UT_TA_HTTP;
- uri.references = 1;
+ map.url = "https://example.com/resources/lorem-ipsum.txt";
+ map.path = "resources/lorem-ipsum.txt";
+ map.type = MAP_TA_HTTP;
+ map.references = 1;
ha = hash_get_sha1();
ck_assert_uint_eq(20, hash_get_size(ha));
FORT_SHA1[1] = 1;
ck_assert_int_eq(EINVAL, hash_validate(ha, (unsigned char *)input, strlen(input), FORT_SHA1, sizeof(FORT_SHA1)));
- ck_assert_int_eq(0, hash_validate_file(ha, &uri, FILE_SHA1, sizeof(FILE_SHA1)));
- ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &uri, FILE_SHA1, sizeof(FILE_SHA1) - 10));
+ ck_assert_int_eq(0, hash_validate_file(ha, &map, FILE_SHA1, sizeof(FILE_SHA1)));
+ ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &map, FILE_SHA1, sizeof(FILE_SHA1) - 10));
FILE_SHA1[19] = 0;
- ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &uri, FILE_SHA1, sizeof(FILE_SHA1)));
+ ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &map, FILE_SHA1, sizeof(FILE_SHA1)));
ha = hash_get_sha256();
ck_assert_uint_eq(32, hash_get_size(ha));
FORT_SHA256[10] = 0;
ck_assert_int_eq(EINVAL, hash_validate(ha, (unsigned char *)input, strlen(input), FORT_SHA256, sizeof(FORT_SHA256)));
- ck_assert_int_eq(0, hash_validate_file(ha, &uri, FILE_SHA256, sizeof(FILE_SHA256)));
- ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &uri, FILE_SHA256, sizeof(FILE_SHA256) - 1));
+ ck_assert_int_eq(0, hash_validate_file(ha, &map, FILE_SHA256, sizeof(FILE_SHA256)));
+ ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &map, FILE_SHA256, sizeof(FILE_SHA256) - 1));
FILE_SHA256[31] = 10;
- ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &uri, FILE_SHA256, sizeof(FILE_SHA256)));
+ ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &map, FILE_SHA256, sizeof(FILE_SHA256)));
hash_teardown();
}
END_TEST
/*
- * To assure myself I can hash nodes using an rpki_uri's global field as key.
+ * To assure myself I can hash nodes using an cache_mapping's url field as key.
* (Given that they're private.)
*
* ie. Neither the node nor the key contains the key, but the key points to it
* somewhere else.
*/
-START_TEST(test_uri)
+START_TEST(test_map)
{
struct test2_key {
char *outer_string;
static Suite *pdu_suite(void)
{
Suite *suite;
- TCase *core, *uri;
+ TCase *core, *map;
core = tcase_create("simple");
tcase_add_test(core, test_replace);
- uri = tcase_create("uri");
- tcase_add_test(uri, test_uri);
+ map = tcase_create("map");
+ tcase_add_test(map, test_map);
suite = suite_create("uthash");
suite_add_tcase(suite, core);
- suite_add_tcase(suite, uri);
+ suite_add_tcase(suite, map);
return suite;
}
#include "crypto/base64.c"
#include "crypto/hash.c"
#include "data_structure/path_builder.c"
-#include "types/uri.c"
+#include "types/map.c"
#include "xml/relax_ng.c"
/* Mocks */
return 0;
}
-MOCK_ABORT_INT(cache_download, struct rpki_cache *cache, struct rpki_uri *uri,
- bool *changed, struct cachefile_notification ***notif)
+MOCK_ABORT_INT(cache_download, struct rpki_cache *cache,
+ struct cache_mapping *map, bool *changed,
+ struct cachefile_notification ***notif)
MOCK_ABORT_VOID(fnstack_pop, void)
-MOCK_ABORT_VOID(fnstack_push_uri, struct rpki_uri *uri)
+MOCK_ABORT_VOID(fnstack_push_map, struct cache_mapping *map)
MOCK_ABORT_PTR(validation_cache, rpki_cache, struct validation *state)
MOCK(state_retrieve, struct validation *, NULL, void)
END_TEST
static void
-init_uri(struct rpki_uri *uri, char *global, char *local, enum uri_type type)
+init_map(struct cache_mapping *map, char *global, char *path, enum map_type type)
{
- uri->global = global;
- uri->local = local;
- uri->type = type;
- uri->references = 1;
+ map->url = global;
+ map->path = path;
+ map->type = type;
+ map->references = 1;
}
-#define init_notif_uri(u, g, l) init_uri(u, g, l, UT_NOTIF)
+#define init_notif_map(u, g, l) init_map(u, g, l, MAP_NOTIF)
START_TEST(test_parse_notification_ok)
{
- struct rpki_uri uri;
+ struct cache_mapping map;
struct update_notification notif;
ck_assert_int_eq(0, relax_ng_init());
- init_notif_uri(&uri, "https://host/notification.xml", "resources/rrdp/notif-ok.xml");
- ck_assert_int_eq(0, parse_notification(&uri, ¬if));
+ init_notif_map(&map, "https://host/notification.xml", "resources/rrdp/notif-ok.xml");
+ ck_assert_int_eq(0, parse_notification(&map, ¬if));
ck_assert_str_eq("9df4b597-af9e-4dca-bdda-719cce2c4e28", (char const *)notif.session.session_id);
ck_assert_str_eq("3", (char const *)notif.session.serial.str);
- ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->global);
+ ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->url);
ck_assert_uint_eq(32, notif.snapshot.hash_len);
validate_aaaa_hash(notif.snapshot.hash);
ck_assert_uint_eq(2, notif.deltas.len);
ck_assert_str_eq("2", (char const *)notif.deltas.array[0].serial.str);
- ck_assert_str_eq("https://host/9d-8/2/delta.xml", notif.deltas.array[0].meta.uri->global);
+ ck_assert_str_eq("https://host/9d-8/2/delta.xml", notif.deltas.array[0].meta.uri->url);
ck_assert_uint_eq(32, notif.deltas.array[0].meta.hash_len);
validate_01234_hash(notif.deltas.array[0].meta.hash);
ck_assert_str_eq("3", (char const *)notif.deltas.array[1].serial.str);
- ck_assert_str_eq("https://host/9d-8/3/delta.xml", notif.deltas.array[1].meta.uri->global);
+ ck_assert_str_eq("https://host/9d-8/3/delta.xml", notif.deltas.array[1].meta.uri->url);
ck_assert_uint_eq(32, notif.deltas.array[1].meta.hash_len);
validate_01234_hash(notif.deltas.array[0].meta.hash);
START_TEST(test_parse_notification_0deltas)
{
- struct rpki_uri uri;
+ struct cache_mapping map;
struct update_notification notif;
ck_assert_int_eq(0, relax_ng_init());
- init_notif_uri(&uri, "https://host/notification.xml", "resources/rrdp/notif-0deltas.xml");
- ck_assert_int_eq(0, parse_notification(&uri, ¬if));
+ init_notif_map(&map, "https://host/notification.xml", "resources/rrdp/notif-0deltas.xml");
+ ck_assert_int_eq(0, parse_notification(&map, ¬if));
ck_assert_str_eq("9df4b597-af9e-4dca-bdda-719cce2c4e28", (char const *)notif.session.session_id);
ck_assert_str_eq("3", (char const *)notif.session.serial.str);
- ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->global);
+ ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->url);
ck_assert_uint_eq(32, notif.snapshot.hash_len);
validate_01234_hash(notif.snapshot.hash);
START_TEST(test_parse_notification_large_serial)
{
- struct rpki_uri uri;
+ struct cache_mapping map;
struct update_notification notif;
ck_assert_int_eq(0, relax_ng_init());
- init_notif_uri(&uri, "https://host/notification.xml", "resources/rrdp/notif-large-serial.xml");
- ck_assert_int_eq(0, parse_notification(&uri, ¬if));
+ init_notif_map(&map, "https://host/notification.xml", "resources/rrdp/notif-large-serial.xml");
+ ck_assert_int_eq(0, parse_notification(&map, ¬if));
ck_assert_str_eq("9df4b597-af9e-4dca-bdda-719cce2c4e28", (char const *)notif.session.session_id);
/*
*/
ck_assert_str_eq("999999999999999999999999", (char const *)notif.session.serial.str);
- ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->global);
+ ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->url);
ck_assert_uint_eq(32, notif.snapshot.hash_len);
validate_01234_hash(notif.snapshot.hash);
static void
test_parse_notification_error(char *file)
{
- struct rpki_uri uri;
+ struct cache_mapping map;
struct update_notification notif;
ck_assert_int_eq(0, relax_ng_init());
- init_notif_uri(&uri, "https://host/notification.xml", file);
- ck_assert_int_eq(-EINVAL, parse_notification(&uri, ¬if));
+ init_notif_map(&map, "https://host/notification.xml", file);
+ ck_assert_int_eq(-EINVAL, parse_notification(&map, ¬if));
relax_ng_cleanup();
}
START_TEST(test_parse_snapshot_bad_publish)
{
struct update_notification notif = { 0 };
- struct rpki_uri notif_uri = { 0 };
- struct rpki_uri snapshot_uri = { 0 };
+ struct cache_mapping notif_map = { 0 };
+ struct cache_mapping snapshot_map = { 0 };
ck_assert_int_eq(0, relax_ng_init());
- init_notif_uri(¬if_uri, "https://example.com/notification.xml", "cache/example.com/notification.xml");
- init_uri(&snapshot_uri, "https://example.com/snapshot.xml", "resources/rrdp/snapshot-bad-publish.xml", UT_TMP);
+ init_notif_map(¬if_map, "https://example.com/notification.xml", "cache/example.com/notification.xml");
+ init_map(&snapshot_map, "https://example.com/snapshot.xml", "resources/rrdp/snapshot-bad-publish.xml", MAP_TMP);
notif.session.session_id = "9df4b597-af9e-4dca-bdda-719cce2c4e28";
notif.session.serial.str = "2";
notif.session.serial.num = BN_two();
- notif.snapshot.uri = &snapshot_uri;
- notif.uri = ¬if_uri;
+ notif.snapshot.uri = &snapshot_map;
+ notif.map = ¬if_map;
ck_assert_int_eq(-EINVAL, parse_snapshot(¬if));
MOCK_UINT(config_get_deltas_lifetime, deltas_lifetime, void)
MOCK_ABORT_ENUM(config_get_output_format, output_format, void)
-MOCK_ABORT_INT(hash_local_file, char const *uri, unsigned char *result)
/* Test functions */
#include "file.c"
#include "mock.c"
#include "data_structure/path_builder.c"
-#include "types/uri.c"
+#include "types/map.c"
#include "crypto/base64.c"
/* Mocks */
MOCK_ABORT_VOID(cache_setup, void)
MOCK(cache_create, struct rpki_cache *, NULL, void)
MOCK_VOID(cache_destroy, struct rpki_cache *cache)
-MOCK_ABORT_INT(cache_download, struct rpki_cache *cache, struct rpki_uri *uri,
- bool *changed, struct cachefile_notification ***notif)
+MOCK_ABORT_INT(cache_download, struct rpki_cache *cache,
+ struct cache_mapping *map, bool *changed,
+ struct cachefile_notification ***notif)
MOCK_ABORT_INT(cache_download_alt, struct rpki_cache *cache,
- struct uri_list *uris, enum uri_type http_type, enum uri_type rsync_type,
- uris_dl_cb cb, void *arg)
-MOCK_ABORT_PTR(cache_recover, rpki_uri, struct rpki_cache *cache,
- struct uri_list *uris)
+ struct map_list *maps, enum map_type http_type, enum map_type rsync_type,
+ maps_dl_cb cb, void *arg)
+MOCK_ABORT_PTR(cache_recover, cache_mapping, struct rpki_cache *cache,
+ struct map_list *maps)
MOCK_ABORT_INT(cache_tmpfile, char **filename)
MOCK_ABORT_VOID(cache_teardown, void)
MOCK_ABORT_INT(certificate_traverse, struct rpp *rpp_parent,
- struct rpki_uri *cert_uri)
+ struct cache_mapping *cert_map)
MOCK_ABORT_PTR(db_table_create, db_table, void)
MOCK_VOID(db_table_destroy, struct db_table *table)
MOCK_ABORT_INT(db_table_join, struct db_table *dst, struct db_table *src)
MOCK_ABORT_INT(handle_router_key, unsigned char const *ski,
struct asn_range const *asns, unsigned char const *spk, void *arg)
MOCK_ABORT_VOID(rpp_refput, struct rpp *pp)
-MOCK_ABORT_INT(rrdp_update, struct rpki_uri *uri)
+MOCK_ABORT_INT(rrdp_update, struct cache_mapping *map)
MOCK(state_retrieve, struct validation *, NULL, void)
MOCK_ABORT_PTR(validation_certstack, cert_stack, struct validation *state)
MOCK_ABORT_VOID(validation_destroy, struct validation *state)
ck_assert_int_eq(0, tal_init(&tal, file));
- ck_assert_uint_eq(1, tal.uris.len);
- ck_assert_str_eq("rsync://example.com/rpki/ta.cer", tal.uris.array[0]->global);
+ ck_assert_uint_eq(1, tal.maps.len);
+ ck_assert_str_eq("rsync://example.com/rpki/ta.cer", tal.maps.array[0]->url);
check_spki(&tal);
tal_cleanup(&tal);
ck_assert_int_eq(0, tal_init(&tal, file));
- ck_assert_uint_eq(4, tal.uris.len);
- ck_assert_str_eq("rsync://example.com/rpki/ta.cer", tal.uris.array[0]->global);
- ck_assert_str_eq("https://example.com/rpki/ta.cer", tal.uris.array[1]->global);
- ck_assert_str_eq("rsync://www.example.com/potato/ta.cer", tal.uris.array[2]->global);
- ck_assert_str_eq("https://wx3.example.com/tomato/ta.cer", tal.uris.array[3]->global);
+ ck_assert_uint_eq(4, tal.maps.len);
+ ck_assert_str_eq("rsync://example.com/rpki/ta.cer", tal.maps.array[0]->url);
+ ck_assert_str_eq("https://example.com/rpki/ta.cer", tal.maps.array[1]->url);
+ ck_assert_str_eq("rsync://www.example.com/potato/ta.cer", tal.maps.array[2]->url);
+ ck_assert_str_eq("https://wx3.example.com/tomato/ta.cer", tal.maps.array[3]->url);
check_spki(&tal);
--- /dev/null
+#include <check.h>
+#include <errno.h>
+#include <stdint.h>
+
+#include "alloc.c"
+#include "common.c"
+#include "mock.c"
+#include "types/map.c"
+#include "data_structure/path_builder.c"
+
+/* Mocks */
+
+static struct cache_mapping *notif;
+
+MOCK(state_retrieve, struct validation *, NULL, void)
+MOCK(validation_tal, struct tal *, NULL, struct validation *state)
+MOCK(tal_get_file_name, char const *, NULL, struct tal *tal)
+
+MOCK_ABORT_INT(rrdp_update, struct cache_mapping *map)
+
+int
+cache_tmpfile(char **filename)
+{
+ static unsigned int used = 1;
+
+ if (used > 2) {
+ ck_abort_msg("cache_tmpfile() called a third time!");
+ return -EINVAL;
+ }
+
+ *filename = pstrdup("tmp/tmp/0");
+ used = true;
+ return 0;
+}
+
+/* Tests */
+
+#define MAP_CREATE_HTTP(map, str) map_create(&map, MAP_TA_HTTP, NULL, str)
+#define MAP_CREATE(map, type, str) map_create(&map, type, NULL, str)
+
+START_TEST(test_constructor)
+{
+ struct cache_mapping *map;
+
+ ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, ""));
+ ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "h"));
+ ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "http"));
+ ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "https"));
+ ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "https:"));
+ ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "https:/"));
+ ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://"));
+
+ ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c"));
+ ck_assert_str_eq("https://a.b.c", map_get_url(map));
+ ck_assert_str_eq("tmp/https/a.b.c", map_get_path(map));
+ map_refput(map);
+
+ ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/"));
+ ck_assert_str_eq("https://a.b.c", map_get_url(map));
+ ck_assert_str_eq("tmp/https/a.b.c", map_get_path(map));
+ map_refput(map);
+
+ ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/d"));
+ ck_assert_str_eq("https://a.b.c/d", map_get_url(map));
+ ck_assert_str_eq("tmp/https/a.b.c/d", map_get_path(map));
+ map_refput(map);
+
+ ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/d/e"));
+ ck_assert_str_eq("https://a.b.c/d/e", map_get_url(map));
+ ck_assert_str_eq("tmp/https/a.b.c/d/e", map_get_path(map));
+ map_refput(map);
+
+ ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/d/.."));
+ ck_assert_str_eq("https://a.b.c", map_get_url(map));
+ ck_assert_str_eq("tmp/https/a.b.c", map_get_path(map));
+ map_refput(map);
+
+ ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/."));
+ ck_assert_str_eq("https://a.b.c", map_get_url(map));
+ ck_assert_str_eq("tmp/https/a.b.c", map_get_path(map));
+ map_refput(map);
+
+ ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/././d/././e/./."));
+ ck_assert_str_eq("https://a.b.c/d/e", map_get_url(map));
+ ck_assert_str_eq("tmp/https/a.b.c/d/e", map_get_path(map));
+ map_refput(map);
+
+ ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/a/b/.././.."));
+ ck_assert_str_eq("https://a.b.c", map_get_url(map));
+ ck_assert_str_eq("tmp/https/a.b.c", map_get_path(map));
+ map_refput(map);
+
+ ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://a.b.c/.."));
+ ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://a.b.c/../.."));
+ ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://a.b.c/d/../.."));
+ ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://a.b.c/d/../../.."));
+ ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://."));
+ ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://./."));
+ ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://.."));
+ ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://../.."));
+ ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://../../.."));
+
+ ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "rsync://a.b.c/d"));
+ ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "http://a.b.c/d"));
+ ck_assert_int_eq(ENOTRSYNC, MAP_CREATE(map, MAP_RPP, "https://a.b.c/d"));
+
+ ck_assert_int_eq(0, MAP_CREATE(map, MAP_RPP, "rsync://a.b.c/d"));
+ ck_assert_str_eq("rsync://a.b.c/d", map_get_url(map));
+ ck_assert_str_eq("tmp/rsync/a.b.c/d", map_get_path(map));
+ map_refput(map);
+
+ ck_assert_int_eq(0, MAP_CREATE(map, MAP_TA_RSYNC, "rsync://a.b.c/d.cer"));
+ ck_assert_str_eq("rsync://a.b.c/d.cer", map_get_url(map));
+ ck_assert_str_eq("tmp/rsync/a.b.c/d.cer", map_get_path(map));
+ map_refput(map);
+
+ ck_assert_int_eq(0, MAP_CREATE(map, MAP_NOTIF, "https://a.b.c/notification.xml"));
+ ck_assert_str_eq("https://a.b.c/notification.xml", map_get_url(map));
+ ck_assert_str_eq("tmp/tmp/0", map_get_path(map));
+ map_refput(map);
+
+ ck_assert_int_eq(0, MAP_CREATE(map, MAP_TMP, "https://a.b.c/snapshot.xml"));
+ ck_assert_str_eq("https://a.b.c/snapshot.xml", map_get_url(map));
+ ck_assert_str_eq("tmp/tmp/0", map_get_path(map));
+ map_refput(map);
+}
+END_TEST
+
+#define BUFFER_LEN 128
+static uint8_t buffer[BUFFER_LEN];
+
+static int
+__test_validate(char const *src, size_t len)
+{
+ IA5String_t dst;
+ unsigned int i;
+
+ memcpy(buffer, src, len);
+ for (i = len; i < BUFFER_LEN - 1; i++)
+ buffer[i] = '_';
+ buffer[BUFFER_LEN - 1] = 0;
+
+ dst.buf = buffer;
+ dst.size = len;
+
+ return validate_mft_file(&dst);
+}
+
+#define test_validate(str) __test_validate(str, sizeof(str) - 1)
+
+START_TEST(check_validate_current_directory)
+{
+ ck_assert_int_eq(-EINVAL, test_validate(""));
+ ck_assert_int_eq(-EINVAL, test_validate("."));
+ ck_assert_int_eq(-EINVAL, test_validate(".."));
+
+ ck_assert_int_eq(-EINVAL, test_validate("filename"));
+ ck_assert_int_eq(-EINVAL, test_validate("filename."));
+ ck_assert_int_eq(-EINVAL, test_validate("filename.a"));
+ ck_assert_int_eq(-EINVAL, test_validate("filename.ab"));
+ ck_assert_int_eq(0, test_validate("filename.abc"));
+ ck_assert_int_eq(-EINVAL, test_validate("file.abcd"));
+
+ ck_assert_int_eq(0, test_validate("file-name.ABC"));
+ ck_assert_int_eq(0, test_validate("file_name.123"));
+ ck_assert_int_eq(0, test_validate("file0name.aB2"));
+ ck_assert_int_eq(0, test_validate("file9name.---"));
+ ck_assert_int_eq(0, test_validate("FileName.A3_"));
+ ck_assert_int_eq(-EINVAL, test_validate("file.name.abc"));
+ ck_assert_int_eq(-EINVAL, test_validate("file/name.abc"));
+ ck_assert_int_eq(-EINVAL, test_validate("file\0name.abc"));
+ ck_assert_int_eq(-EINVAL, test_validate("filename.abc\0filename.abc"));
+ ck_assert_int_eq(-EINVAL, test_validate("filenameabc\0filename.abc"));
+ ck_assert_int_eq(0, test_validate("-.---"));
+
+ ck_assert_int_eq(0, test_validate("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890-_.-_-"));
+ ck_assert_int_eq(0, test_validate("vixxBTS_TVXQ-2pmGOT7.cer"));
+}
+END_TEST
+
+START_TEST(check_caged)
+{
+ struct cache_mapping *map;
+
+ ck_assert_int_eq(0, map_create(¬if, MAP_NOTIF, NULL, "https://a.b.c/d/e.xml"));
+ ck_assert_int_eq(0, map_create(&map, MAP_CAGED, notif, "rsync://x.y.z/v/w.cer"));
+ ck_assert_str_eq("tmp/rrdp/a.b.c/d/e.xml/x.y.z/v/w.cer", map_get_path(map));
+ map_refput(map);
+ map_refput(notif);
+
+ ck_assert_int_eq(0, map_create(¬if, MAP_NOTIF, NULL, "https://a.b.c"));
+ ck_assert_int_eq(0, map_create(&map, MAP_CAGED, notif, "rsync://w"));
+ ck_assert_str_eq("tmp/rrdp/a.b.c/w", map_get_path(map));
+ map_refput(map);
+ map_refput(notif);
+}
+END_TEST
+
+START_TEST(test_same_origin)
+{
+ ck_assert_int_eq(true, str_same_origin("https://a.b.c/d/e/f", "https://a.b.c/g/h/i"));
+ ck_assert_int_eq(false, str_same_origin("https://a.b.cc/d/e/f", "https://a.b.c/g/h/i"));
+ ck_assert_int_eq(false, str_same_origin("https://a.b.c/d/e/f", "https://a.b.cc/g/h/i"));
+ ck_assert_int_eq(true, str_same_origin("https://a.b.c", "https://a.b.c"));
+ ck_assert_int_eq(true, str_same_origin("https://a.b.c/", "https://a.b.c"));
+ ck_assert_int_eq(true, str_same_origin("https://a.b.c", "https://a.b.c/"));
+ ck_assert_int_eq(true, str_same_origin("https://", "https://"));
+ ck_assert_int_eq(false, str_same_origin("https://", "https://a"));
+ ck_assert_int_eq(false, str_same_origin("https://a", "https://b"));
+
+ /* Undefined, but manhandle the code anyway */
+ ck_assert_int_eq(false, str_same_origin("", ""));
+ ck_assert_int_eq(false, str_same_origin("ht", "ht"));
+ ck_assert_int_eq(false, str_same_origin("https:", "https:"));
+ ck_assert_int_eq(false, str_same_origin("https:/", "https:/"));
+ ck_assert_int_eq(false, str_same_origin("https:/a", "https:/a"));
+ ck_assert_int_eq(true, str_same_origin("https:/a/", "https:/a/"));
+}
+END_TEST
+
+static Suite *address_load_suite(void)
+{
+ Suite *suite;
+ TCase *core;
+
+ core = tcase_create("Core");
+ tcase_add_test(core, test_constructor);
+ tcase_add_test(core, check_validate_current_directory);
+ tcase_add_test(core, check_caged);
+ tcase_add_test(core, test_same_origin);
+
+ suite = suite_create("Encoding checking");
+ suite_add_tcase(suite, core);
+ return suite;
+}
+
+int main(void)
+{
+ Suite *suite;
+ SRunner *runner;
+ int tests_failed;
+
+ suite = address_load_suite();
+
+ runner = srunner_create(suite);
+ srunner_run_all(runner, CK_NORMAL);
+ tests_failed = srunner_ntests_failed(runner);
+ srunner_free(runner);
+
+ return (tests_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+++ /dev/null
-#include <check.h>
-#include <errno.h>
-#include <stdint.h>
-
-#include "alloc.c"
-#include "common.c"
-#include "mock.c"
-#include "types/uri.c"
-#include "data_structure/path_builder.c"
-
-/* Mocks */
-
-static struct rpki_uri *notif;
-
-MOCK(state_retrieve, struct validation *, NULL, void)
-MOCK(validation_tal, struct tal *, NULL, struct validation *state)
-MOCK(tal_get_file_name, char const *, NULL, struct tal *tal)
-
-MOCK_ABORT_INT(rrdp_update, struct rpki_uri *uri)
-
-int
-cache_tmpfile(char **filename)
-{
- static unsigned int used = 1;
-
- if (used > 2) {
- ck_abort_msg("cache_tmpfile() called a third time!");
- return -EINVAL;
- }
-
- *filename = pstrdup("tmp/tmp/0");
- used = true;
- return 0;
-}
-
-/* Tests */
-
-#define URI_CREATE_HTTP(uri, str) uri_create(&uri, UT_TA_HTTP, NULL, str)
-#define URI_CREATE(uri, type, str) uri_create(&uri, type, NULL, str)
-
-START_TEST(test_constructor)
-{
- struct rpki_uri *uri;
-
- ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, ""));
- ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "h"));
- ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "http"));
- ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "https"));
- ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "https:"));
- ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "https:/"));
- ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://"));
-
- ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c"));
- ck_assert_str_eq("https://a.b.c", uri_get_global(uri));
- ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
- uri_refput(uri);
-
- ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/"));
- ck_assert_str_eq("https://a.b.c", uri_get_global(uri));
- ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
- uri_refput(uri);
-
- ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/d"));
- ck_assert_str_eq("https://a.b.c/d", uri_get_global(uri));
- ck_assert_str_eq("tmp/https/a.b.c/d", uri_get_local(uri));
- uri_refput(uri);
-
- ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/d/e"));
- ck_assert_str_eq("https://a.b.c/d/e", uri_get_global(uri));
- ck_assert_str_eq("tmp/https/a.b.c/d/e", uri_get_local(uri));
- uri_refput(uri);
-
- ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/d/.."));
- ck_assert_str_eq("https://a.b.c", uri_get_global(uri));
- ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
- uri_refput(uri);
-
- ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/."));
- ck_assert_str_eq("https://a.b.c", uri_get_global(uri));
- ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
- uri_refput(uri);
-
- ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/././d/././e/./."));
- ck_assert_str_eq("https://a.b.c/d/e", uri_get_global(uri));
- ck_assert_str_eq("tmp/https/a.b.c/d/e", uri_get_local(uri));
- uri_refput(uri);
-
- ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/a/b/.././.."));
- ck_assert_str_eq("https://a.b.c", uri_get_global(uri));
- ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
- uri_refput(uri);
-
- ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://a.b.c/.."));
- ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://a.b.c/../.."));
- ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://a.b.c/d/../.."));
- ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://a.b.c/d/../../.."));
- ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://."));
- ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://./."));
- ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://.."));
- ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://../.."));
- ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://../../.."));
-
- ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "rsync://a.b.c/d"));
- ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "http://a.b.c/d"));
- ck_assert_int_eq(ENOTRSYNC, URI_CREATE(uri, UT_RPP, "https://a.b.c/d"));
-
- ck_assert_int_eq(0, URI_CREATE(uri, UT_RPP, "rsync://a.b.c/d"));
- ck_assert_str_eq("rsync://a.b.c/d", uri_get_global(uri));
- ck_assert_str_eq("tmp/rsync/a.b.c/d", uri_get_local(uri));
- uri_refput(uri);
-
- ck_assert_int_eq(0, URI_CREATE(uri, UT_TA_RSYNC, "rsync://a.b.c/d.cer"));
- ck_assert_str_eq("rsync://a.b.c/d.cer", uri_get_global(uri));
- ck_assert_str_eq("tmp/rsync/a.b.c/d.cer", uri_get_local(uri));
- uri_refput(uri);
-
- ck_assert_int_eq(0, URI_CREATE(uri, UT_NOTIF, "https://a.b.c/notification.xml"));
- ck_assert_str_eq("https://a.b.c/notification.xml", uri_get_global(uri));
- ck_assert_str_eq("tmp/tmp/0", uri_get_local(uri));
- uri_refput(uri);
-
- ck_assert_int_eq(0, URI_CREATE(uri, UT_TMP, "https://a.b.c/snapshot.xml"));
- ck_assert_str_eq("https://a.b.c/snapshot.xml", uri_get_global(uri));
- ck_assert_str_eq("tmp/tmp/0", uri_get_local(uri));
- uri_refput(uri);
-}
-END_TEST
-
-#define BUFFER_LEN 128
-static uint8_t buffer[BUFFER_LEN];
-
-static int
-__test_validate(char const *src, size_t len)
-{
- IA5String_t dst;
- unsigned int i;
-
- memcpy(buffer, src, len);
- for (i = len; i < BUFFER_LEN - 1; i++)
- buffer[i] = '_';
- buffer[BUFFER_LEN - 1] = 0;
-
- dst.buf = buffer;
- dst.size = len;
-
- return validate_mft_file(&dst);
-}
-
-#define test_validate(str) __test_validate(str, sizeof(str) - 1)
-
-START_TEST(check_validate_current_directory)
-{
- ck_assert_int_eq(-EINVAL, test_validate(""));
- ck_assert_int_eq(-EINVAL, test_validate("."));
- ck_assert_int_eq(-EINVAL, test_validate(".."));
-
- ck_assert_int_eq(-EINVAL, test_validate("filename"));
- ck_assert_int_eq(-EINVAL, test_validate("filename."));
- ck_assert_int_eq(-EINVAL, test_validate("filename.a"));
- ck_assert_int_eq(-EINVAL, test_validate("filename.ab"));
- ck_assert_int_eq(0, test_validate("filename.abc"));
- ck_assert_int_eq(-EINVAL, test_validate("file.abcd"));
-
- ck_assert_int_eq(0, test_validate("file-name.ABC"));
- ck_assert_int_eq(0, test_validate("file_name.123"));
- ck_assert_int_eq(0, test_validate("file0name.aB2"));
- ck_assert_int_eq(0, test_validate("file9name.---"));
- ck_assert_int_eq(0, test_validate("FileName.A3_"));
- ck_assert_int_eq(-EINVAL, test_validate("file.name.abc"));
- ck_assert_int_eq(-EINVAL, test_validate("file/name.abc"));
- ck_assert_int_eq(-EINVAL, test_validate("file\0name.abc"));
- ck_assert_int_eq(-EINVAL, test_validate("filename.abc\0filename.abc"));
- ck_assert_int_eq(-EINVAL, test_validate("filenameabc\0filename.abc"));
- ck_assert_int_eq(0, test_validate("-.---"));
-
- ck_assert_int_eq(0, test_validate("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890-_.-_-"));
- ck_assert_int_eq(0, test_validate("vixxBTS_TVXQ-2pmGOT7.cer"));
-}
-END_TEST
-
-START_TEST(check_caged)
-{
- struct rpki_uri *uri;
-
- ck_assert_int_eq(0, uri_create(¬if, UT_NOTIF, NULL, "https://a.b.c/d/e.xml"));
- ck_assert_int_eq(0, uri_create(&uri, UT_CAGED, notif, "rsync://x.y.z/v/w.cer"));
- ck_assert_str_eq("tmp/rrdp/a.b.c/d/e.xml/x.y.z/v/w.cer", uri_get_local(uri));
- uri_refput(uri);
- uri_refput(notif);
-
- ck_assert_int_eq(0, uri_create(¬if, UT_NOTIF, NULL, "https://a.b.c"));
- ck_assert_int_eq(0, uri_create(&uri, UT_CAGED, notif, "rsync://w"));
- ck_assert_str_eq("tmp/rrdp/a.b.c/w", uri_get_local(uri));
- uri_refput(uri);
- uri_refput(notif);
-}
-END_TEST
-
-START_TEST(test_same_origin)
-{
- ck_assert_int_eq(true, str_same_origin("https://a.b.c/d/e/f", "https://a.b.c/g/h/i"));
- ck_assert_int_eq(false, str_same_origin("https://a.b.cc/d/e/f", "https://a.b.c/g/h/i"));
- ck_assert_int_eq(false, str_same_origin("https://a.b.c/d/e/f", "https://a.b.cc/g/h/i"));
- ck_assert_int_eq(true, str_same_origin("https://a.b.c", "https://a.b.c"));
- ck_assert_int_eq(true, str_same_origin("https://a.b.c/", "https://a.b.c"));
- ck_assert_int_eq(true, str_same_origin("https://a.b.c", "https://a.b.c/"));
- ck_assert_int_eq(true, str_same_origin("https://", "https://"));
- ck_assert_int_eq(false, str_same_origin("https://", "https://a"));
- ck_assert_int_eq(false, str_same_origin("https://a", "https://b"));
-
- /* Undefined, but manhandle the code anyway */
- ck_assert_int_eq(false, str_same_origin("", ""));
- ck_assert_int_eq(false, str_same_origin("ht", "ht"));
- ck_assert_int_eq(false, str_same_origin("https:", "https:"));
- ck_assert_int_eq(false, str_same_origin("https:/", "https:/"));
- ck_assert_int_eq(false, str_same_origin("https:/a", "https:/a"));
- ck_assert_int_eq(true, str_same_origin("https:/a/", "https:/a/"));
-}
-END_TEST
-
-static Suite *address_load_suite(void)
-{
- Suite *suite;
- TCase *core;
-
- core = tcase_create("Core");
- tcase_add_test(core, test_constructor);
- tcase_add_test(core, check_validate_current_directory);
- tcase_add_test(core, check_caged);
- tcase_add_test(core, test_same_origin);
-
- suite = suite_create("Encoding checking");
- suite_add_tcase(suite, core);
- return suite;
-}
-
-int main(void)
-{
- Suite *suite;
- SRunner *runner;
- int tests_failed;
-
- suite = address_load_suite();
-
- runner = srunner_create(suite);
- srunner_run_all(runner, CK_NORMAL);
- tests_failed = srunner_ntests_failed(runner);
- srunner_free(runner);
-
- return (tests_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}