annotate common/certhelp.c @ 382:124f08a85532

Rename instructions to choices
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 15 Apr 2014 17:46:16 +0200
parents 81a205fc651e
children 17e1c8f37d72
rev   line source
259
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
1 #include <stdlib.h>
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
2
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
3 #include "certhelp.h"
260
Sascha Wilde <wilde@intevation.de>
parents: 259
diff changeset
4 #include "logging.h"
259
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
5 #include "errorcodes.h"
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
6 #include "strhelp.h"
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
7
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
8 char *
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
9 get_oid_valstr(x509_name *namebuf, unsigned char *oid)
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
10 {
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
11 char *str = NULL;
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
12 size_t oid_len = strlen((char *)oid);
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
13 while ( namebuf != NULL )
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
14 {
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
15 if ( (namebuf->oid.len == oid_len) &&
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
16 (memcmp(namebuf->oid.p, oid, oid_len) == 0) )
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
17 {
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
18 str = xstrndup((char *)namebuf->val.p, namebuf->val.len);
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
19 break;
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
20 }
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
21 namebuf = namebuf->next;
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
22 }
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
23 return str;
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
24 }
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
25
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
26 char *
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
27 x509_parse_subject(unsigned char *derdata, size_t derlen,
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
28 unsigned char *oid)
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
29 {
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
30 x509_crt chain;
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
31 char *str;
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
32
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
33 x509_crt_init(&chain);
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
34 if (x509_crt_parse_der(&chain, derdata, derlen) != 0)
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
35 {
332
81a205fc651e Do not exit on error
Andre Heinecke <aheinecke@intevation.de>
parents: 260
diff changeset
36 ERRORPRINTF("Could not parse certificate!\n");
81a205fc651e Do not exit on error
Andre Heinecke <aheinecke@intevation.de>
parents: 260
diff changeset
37 return NULL;
259
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
38 }
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
39 else
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
40 {
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
41 str = get_oid_valstr(&(chain.subject), oid);
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
42 x509_crt_free(&chain);
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
43 }
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
44 return str;
20d515604daa Added new module with helper functions to parse certs.
Sascha Wilde <wilde@intevation.de>
parents:
diff changeset
45 }

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