URL retrieval

From OpenCA Labs WiKi

Introduction

LibPKI Implements a quite powerful URL retrieval interface. By using the provided functionalities, an application will be capable to retrieve data from:

  • File
  • MySQL
  • PostgreSQL
  • Web Server (HTTP and HTTPS)
  • LDAP
  • PKCS11 Device

Getting the Data

In order to get general data, a URL_get_data() or URL_get_data_url() functions are provided. These functions will return a PKI_MEM_STACK pointer. Some URLs may return multiple objects, that is why the returned argument is a stack. The function prototypes are:

PKI_MEM_STACK * URL_get_data( char *url_string, ssize_t size )
PKI_MEM_STACK * URL_get_data_url( URL *url, ssize_t size )

The size argument is used as an upper-bound of data size read from the URL. If 0 is passed as the argument, then no size limit will be imposed on the retrieved object.

The returned stack of PKI_MEM * can be browsed by using the PKI_STACK_* functions. Here it is an example on how you can browse through the stack:

   PKI_MEM_STACK *sk = NULL;
   PKI_MEM *elem = NULL;

   int i = 0;

   /* Here we assume you called the URL_get_data() function
      in order to fill the PKI_STACK */

   for ( i = 0; i < PKI_STACK_elements( sk ); i++ ) {
      elem = PKI_STACK_get_num( sk, i );
      printf("Got Element %d - size is %d\n");
   }


Supported URL types

To access the different type of data source different type of URLs have been defined. The general forma is as follows:

   [protocol://][usr[:pwd]@]address[:port][/path]

different URLs have specific ways to parse the URL to retrieve the needed options. Examples and explanations about the different URLs typy follow:

  • file - to access a file in the local filesystem. If the protocol in the URL is not provided, then it is assumed to be file://
  • http - to access resources from a web server (HTTP GET)
  • https - to access resources from a web server via SSLv3/TLS connections (HTTP GET)
  • ldap - to access resources from a Directory server (LDAPv3)
  • mysql - to access resources stored in a MySQL server
  • pg - to access resources stored in a PostgreSQL server
  • id - to access resources stored in a PKCS#11 device (eg., HSM, USB Token, etc.)