1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/*
* Copyright (C) 2012 KU Leuven
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of libdane.
*
* The libdane library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <unbound.h>
#include <gnutls/dane.h>
#include <gnutls/x509.h>
#include <gnutls/abstract.h>
typedef struct cert_type_entry
{
const char* name;
dane_cert_type_t type;
} cert_type_entry;
static const cert_type_entry dane_cert_types[] =
{
{"X.509", DANE_CERT_X509},
{"SubjectPublicKeyInfo", DANE_CERT_PK},
{NULL, 0}
};
typedef struct match_type_entry
{
const char* name;
dane_match_type_t type;
} match_type_entry;
static const match_type_entry dane_match_types[] =
{
{"Exact match", DANE_MATCH_EXACT},
{"SHA2-256 hash", DANE_MATCH_SHA2_256},
{"SHA2-512 hash", DANE_MATCH_SHA2_512},
{NULL, 0}
};
typedef struct cert_usage_entry
{
const char* name;
dane_cert_usage_t usage;
} cert_usage_entry;
static const cert_usage_entry dane_cert_usages[] =
{
{"CA", DANE_CERT_USAGE_CA},
{"End-entity", DANE_CERT_USAGE_EE},
{"Local CA", DANE_CERT_USAGE_LOCAL_CA},
{"Local end-entity", DANE_CERT_USAGE_LOCAL_EE},
{NULL, 0}
};
/**
* dane_cert_type_name:
* @type: is a DANE match type
*
* Convert a #dane_cert_type_t value to a string.
*
* Returns: a string that contains the name of the specified
* type, or %NULL.
**/
const char* dane_cert_type_name(dane_cert_type_t type)
{
const cert_type_entry* e = dane_cert_types;
while(e->name != NULL)
{
if (e->type == type)
return e->name;
e++;
}
return NULL;
}
/**
* dane_match_type_name:
* @type: is a DANE match type
*
* Convert a #dane_match_type_t value to a string.
*
* Returns: a string that contains the name of the specified
* type, or %NULL.
**/
const char* dane_match_type_name(dane_match_type_t type)
{
const match_type_entry* e = dane_match_types;
while(e->name != NULL)
{
if (e->type == type)
return e->name;
e++;
}
return NULL;
}
/**
* dane_cert_usage_name:
* @type: is a DANE match type
*
* Convert a #dane_cert_usage_t value to a string.
*
* Returns: a string that contains the name of the specified
* type, or %NULL.
**/
const char* dane_cert_usage_name(dane_cert_usage_t usage)
{
const cert_usage_entry* e = dane_cert_usages;
while(e->name != NULL)
{
if (e->usage == usage)
return e->name;
e++;
}
return NULL;
}
|