Skip to content

Commit 1603c9c

Browse files
committed
Add getters for RFC 3779 extensions to FFI
1 parent fcaafca commit 1603c9c

6 files changed

Lines changed: 665 additions & 0 deletions

File tree

doc/api_ref/ffi.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,70 @@ X.509 Certificates
21182118
Return a (statically allocated) string associated with the verification
21192119
result, or NULL if the code is not known.
21202120

2121+
.. cpp:function:: int botan_x509_ext_ip_addr_blocks_get_counts(botan_x509_cert_t cert, \
2122+
size_t* v4_count, \
2123+
size_t* v6_count)
2124+
2125+
Get info about the IP Address Blocks extension from `RFC 3779 <https://www.rfc-editor.org/rfc/rfc3779>`_.
2126+
``v4_count`` is set to the number of v4 families contained in the extension,
2127+
``v6_count`` to the number of v6 families. If the extension is not present, :cpp:enumerator:`BOTAN_FFI_ERROR_NO_VALUE` is returned.
2128+
2129+
.. cpp:function:: int botan_x509_ext_ip_addr_blocks_get_family(botan_x509_cert_t cert, \
2130+
size_t v4_count, \
2131+
int ipv6, \
2132+
size_t i, \
2133+
int* has_safi, \
2134+
uint8_t* safi, \
2135+
int* present, \
2136+
size_t* count)
2137+
2138+
Get info about a specific family in the extension.
2139+
``v4_count`` is obtained from :cpp:func:`botan_x509_ext_ip_addr_blocks_get_counts`, ``ipv6`` should be set to 0 for v4 families,
2140+
1 for v6 families. ``i`` is the local index for each family type, the first v4 family is at ``i = 0``,
2141+
``ipv6 = 0``, the first v6 family is at ``i = 0``, ``ipv6 = 1``.
2142+
``has_safi`` is set to 1 if the family has an associated SAFI, else 0.
2143+
``safi`` contains the SAFI if the family has one, otherwise its value is undefined.
2144+
``present`` is set to 1 if the family has range values, 0 if it is marked as "inherit".
2145+
``count`` is set to the number of ranges contained if any, otherwise its value is undefined.
2146+
2147+
.. cpp:function:: int botan_x509_ext_ip_addr_blocks_get_address(botan_x509_cert_t cert, \
2148+
size_t v4_count, \
2149+
int ipv6, \
2150+
size_t i, \
2151+
size_t entry, \
2152+
uint8_t min_out[], \
2153+
uint8_t max_out[], \
2154+
size_t* out_len)
2155+
2156+
Get info about a specific range in the extension.
2157+
``v4_count``, ``ipv6`` and ``i`` behave as in `botan_x509_ext_ip_addr_blocks_get_family`.
2158+
``entry`` is the index to the range in the family, between 0 and (not including) ``count``.
2159+
``min_out`` and ``max_out`` are set to the min and max addresses of the range respectively.
2160+
``out_len`` should be set to 4 for v4 families, 16 for v6 families, the two arrays must also be that size.
2161+
2162+
.. cpp:function:: int botan_x509_ext_as_blocks_get_info(botan_x509_cert_t cert, \
2163+
int asnum, \
2164+
int* present, \
2165+
size_t* count)
2166+
2167+
Get info about the AS Blocks extension from `RFC 3779 <https://www.rfc-editor.org/rfc/rfc3779>`_.
2168+
``asnum`` should be set to 1 to get info about the ASNUM part of the extension, 0 for RDI.
2169+
``present`` is set to 1 if a value is contained, 0 if that part of the extension is marked as "inherit".
2170+
If the part is not present at all, :cpp:enumerator:`BOTAN_FFI_ERROR_NO_VALUE` will be returned.
2171+
``count`` is set to the number of entries for that part if any, otherwise its value is undefined.
2172+
2173+
2174+
.. cpp:function:: int botan_x509_ext_as_blocks_get_entry_at(botan_x509_cert_t cert, \
2175+
int asnum, \
2176+
size_t i, \
2177+
uint32_t* min, \
2178+
uint32_t* max)
2179+
2180+
Get info about a specific entry from the extension.
2181+
``asnum`` behaves as in :cpp:func:`botan_x509_ext_as_blocks_get_info`, ``i`` is the index for that part,
2182+
between 0 and (not including) ``count``.
2183+
``min`` and ``max`` will be set to the minimum and maximum AS numbers of the range respectively.
2184+
21212185
X.509 Certificate Revocation Lists
21222186
----------------------------------------
21232187

src/lib/ffi/ffi.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,82 @@ int botan_x509_cert_verify(int* validation_result,
26942694
*/
26952695
BOTAN_FFI_EXPORT(2, 8) const char* botan_x509_cert_validation_status(int code);
26962696

2697+
/*
2698+
* X.509 Extensions
2699+
*/
2700+
2701+
/**
2702+
* Get info about the IP Address Blocks extension
2703+
* @param v4_count is set to the number of v4 families contained in the extension
2704+
* @param v6_count is set to the number of v6 families
2705+
* @returns 0 on success, negative number on error
2706+
*/
2707+
BOTAN_FFI_EXPORT(3, 13)
2708+
int botan_x509_ext_ip_addr_blocks_get_counts(botan_x509_cert_t cert, size_t* v4_count, size_t* v6_count);
2709+
2710+
/**
2711+
* Get info about a specific family in the extension
2712+
* @param v4_count must be set to the number of v4 families contained in the cert, obtained from `botan_x509_ext_ip_addr_blocks_get_counts`
2713+
* @param ipv6 must be set to 1 if the family is an IPv6 family, 0 for IPv4 families
2714+
* @param i is the (local) index for this family kind (the first v4 family is at i = 0, ipv6 = 0; the first v6 family is at i = 0, ipv6 = 1)
2715+
* @param has_safi will be set to 1 if the family has an associated SAFI
2716+
* @param safi will be set to the families' SAFI, if it has one
2717+
* @param present is set to 1 if the family contains values (ranges), 0 if it is marked as "inherit"
2718+
* @param count is set to the number of values (ranges), if they were present
2719+
* @returns 0 on success, negative number on error
2720+
*/
2721+
BOTAN_FFI_EXPORT(3, 13)
2722+
int botan_x509_ext_ip_addr_blocks_get_family(botan_x509_cert_t cert,
2723+
size_t v4_count,
2724+
int ipv6,
2725+
size_t i,
2726+
int* has_safi,
2727+
uint8_t* safi,
2728+
int* present,
2729+
size_t* count);
2730+
2731+
/**
2732+
* Get info about a specific range in the extension
2733+
* @param v4_count must be set to the number of v4 families present
2734+
* @param ipv6 must be set to 1 if the family is an IPv6 family, 0 for IPv4 families
2735+
* @param i is the (local) index of the family, see `botan_x509_ext_ip_addr_blocks_get_family`
2736+
* @param entry is the index of the range
2737+
* @param min_out is set to the lower address of the range
2738+
* @param max_out is set to the upper address of the range
2739+
* @param out_len is set to the length of the addresses (4 for IPv4, 16 for IPv6)
2740+
* @returns 0 on success, negative number on error
2741+
*/
2742+
BOTAN_FFI_EXPORT(3, 13)
2743+
int botan_x509_ext_ip_addr_blocks_get_address(botan_x509_cert_t cert,
2744+
size_t v4_count,
2745+
int ipv6,
2746+
size_t i,
2747+
size_t entry,
2748+
uint8_t min_out[],
2749+
uint8_t max_out[],
2750+
size_t* out_len);
2751+
2752+
/**
2753+
* Get basic info about the AS Blocks extension
2754+
* @param asnum must be set to 1 to get info about AS numbers, 0 for RDIs (the type)
2755+
* @param present is set to 1 if the extension contains entries for the type, 0 if it is marked as "inherit"
2756+
* @param count is set to number of entries for this type, if it was present
2757+
* @returns 0 on success, negative number on error
2758+
*/
2759+
BOTAN_FFI_EXPORT(3, 13)
2760+
int botan_x509_ext_as_blocks_get_info(botan_x509_cert_t cert, int asnum, int* present, size_t* count);
2761+
2762+
/**
2763+
* Get a specific entry from the extension
2764+
* @param asnum Set to 1 to get info about AS numbers, 0 for RDIs (the type)
2765+
* @param i The index of the entry to get
2766+
* @param min is set to the min value of the range
2767+
* @param max is set to the max value of the range
2768+
* @returns 0 on success, negative number on error
2769+
*/
2770+
BOTAN_FFI_EXPORT(3, 13)
2771+
int botan_x509_ext_as_blocks_get_entry_at(botan_x509_cert_t cert, int asnum, size_t i, uint32_t* min, uint32_t* max);
2772+
26972773
/*
26982774
* X.509 CRL
26992775
**************************/

0 commit comments

Comments
 (0)