view common/certhelp.c @ 287:b033b16dd290

Add OutputDebugString macro This helps when debugging interprocess calls on Windows where you do not get stdout on console
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 02 Apr 2014 13:48:31 +0000
parents e7a8b70021b6
children 81a205fc651e
line wrap: on
line source
#include <stdlib.h>

#include "certhelp.h"
#include "logging.h"
#include "errorcodes.h"
#include "strhelp.h"

char *
get_oid_valstr(x509_name *namebuf, unsigned char *oid)
{
  char *str = NULL;
  size_t oid_len = strlen((char *)oid);
  while ( namebuf != NULL )
    {
      if ( (namebuf->oid.len == oid_len) &&
           (memcmp(namebuf->oid.p, oid, oid_len) == 0) )
        {
          str = xstrndup((char *)namebuf->val.p, namebuf->val.len);
          break;
        }
      namebuf = namebuf->next;
    }
  return str;
}

char *
x509_parse_subject(unsigned char *derdata, size_t derlen,
                   unsigned char *oid)
{
  x509_crt chain;
  char *str;

  x509_crt_init(&chain);
  if (x509_crt_parse_der(&chain, derdata, derlen) != 0)
    {
      DEBUGPRINTF("FATAL: Could not parse certificate!");
      exit(ERR_INVALID_CERT);
    }
  else
    {
      str = get_oid_valstr(&(chain.subject), oid);
      x509_crt_free(&chain);
    }
  return str;
}

http://wald.intevation.org/projects/trustbridge/