OpenVAS Libraries  6.0+beta5
Data Structures | Macros | Typedefs | Functions
nasl_cert.c File Reference

Implementation of an API for X.509 certificates. More...

#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <ksba.h>
#include "system.h"
#include "nasl_tree.h"
#include "nasl_global_ctxt.h"
#include "nasl_func.h"
#include "nasl_var.h"
#include "nasl_lex_ctxt.h"
#include "nasl_debug.h"
#include "nasl_cert.h"

Data Structures

struct  object_desc_s
 

Macros

#define DIM(v)   (sizeof(v)/sizeof((v)[0]))
 
#define DIMof(type, member)   DIM(((type *)0)->member)
 
#define spacep(p)   (*(p) == ' ' || *(p) == '\t')
 
#define digitp(p)   (*(p) >= '0' && *(p) <= '9')
 
#define hexdigitp(a)
 
#define atoi_1(p)   (*(p) - '0' )
 
#define atoi_2(p)   ((atoi_1(p) * 10) + atoi_1((p)+1))
 
#define atoi_4(p)   ((atoi_2(p) * 100) + atoi_2((p)+2))
 
#define xtoi_1(p)
 
#define xtoi_2(p)
 

Typedefs

typedef struct object_desc_sobject_desc_t
 

Functions

tree_cellnasl_cert_open (lex_ctxt *lexic)
 Create a certificate object. More...
 
tree_cellnasl_cert_close (lex_ctxt *lexic)
 Release a certificate object. More...
 
tree_cellnasl_cert_query (lex_ctxt *lexic)
 Query a certificate object. More...
 

Detailed Description

Implementation of an API for X.509 certificates.

This file contains the implementation of the cert_* NASL builtin functions.

Macro Definition Documentation

#define atoi_1 (   p)    (*(p) - '0' )
#define atoi_2 (   p)    ((atoi_1(p) * 10) + atoi_1((p)+1))
#define atoi_4 (   p)    ((atoi_2(p) * 100) + atoi_2((p)+2))
#define digitp (   p)    (*(p) >= '0' && *(p) <= '9')
#define DIM (   v)    (sizeof(v)/sizeof((v)[0]))
#define DIMof (   type,
  member 
)    DIM(((type *)0)->member)
#define hexdigitp (   a)
Value:
(digitp (a) \
|| (*(a) >= 'A' && *(a) <= 'F') \
|| (*(a) >= 'a' && *(a) <= 'f'))
#define spacep (   p)    (*(p) == ' ' || *(p) == '\t')
#define xtoi_1 (   p)
Value:
(*(p) <= '9'? (*(p)- '0'): \
*(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
#define xtoi_2 (   p)
Value:
((xtoi_1((const unsigned char *)(p)) * 16) \
+ xtoi_1((const unsigned char *)(p)+1))

Typedef Documentation

typedef struct object_desc_s* object_desc_t

Function Documentation

tree_cell* nasl_cert_close ( lex_ctxt lexic)

Release a certificate object.

NASL Function: cert_close

Takes a cert identifier as returned by cert_open and releases the associated resources.

NASL Unnamed Parameters:
  • Object id of the certificate. 0 acts as a NOP.
NASL Returns:
none
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
none
tree_cell* nasl_cert_open ( lex_ctxt lexic)

Create a certificate object.

NASL Function: cert_open

Takes a string/data as unnamed argument and returns an identifier used with the other cert functions. The data is usually the BER encoded certificate but the function will also try a PEM encoding on failure to parse BER encoded one.

NASL Unnamed Parameters:
  • String/data object with the certificate. Either binary or PEM encoded.
NASL Named Parameters:
  • errorvar Name of a variable used on error to return an error description.
NASL Returns:
An integer used as an id for the certificate; on error 0 is returned.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
On success the function returns a tree-cell with a non-zero object identifier for use with other cert functions; zero is returned on error.
tree_cell* nasl_cert_query ( lex_ctxt lexic)

Query a certificate object.

NASL Function: cert_query

Takes a cert identifier as first unnamed argument and a command string as second argument. That commonis used to select specific information from the certificate. For certain commandss the named argument idx is used as well. Depending on this command the return value may be a number, a string, or an array of strings. Supported commands are:

  • serial The serial number of the certificate.
  • subject Returns the subject. To query the subjectAltName the named parameters idx can be used. If idx is used the return value is an array, with the first element giving the type of the altSubjectName and the second element the actual data. Types may be one: "xxx", "xxx", "xxx".
  • not-before The notBefore time as UTC value in ISO time format (e.g. "20120930T143521").
  • not-after The notAfter time as UTC value in ISO time format (e.g. "20280929T143520").
  • all Return all available information in a human readable format. Not yet implemented.
  • hostnames Return an array with all hostnames listed in the certificates, i.e. the CN part of the subject and all dns-name type subjectAltNames.
NASL Unnamed Parameters:
  • Object id of the certificate.
  • A string with the command to select what to return; see above.
NASL Named Parameters:
  • idx Used by certain commands to select the n-th value of a set of values. If not given 0 is assumed.
NASL Returns:
A NASL type depending on the used command. NULL is returned on error.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
none