/src/gnutls/lib/profiles.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Copyright (C) 2019 Red Hat, Inc.  | 
3  |  |  *  | 
4  |  |  * Author: Nikos Mavrogiannopoulos  | 
5  |  |  *  | 
6  |  |  * This file is part of GnuTLS.  | 
7  |  |  *  | 
8  |  |  * The GnuTLS is free software; you can redistribute it and/or  | 
9  |  |  * modify it under the terms of the GNU Lesser General Public License  | 
10  |  |  * as published by the Free Software Foundation; either version 2.1 of  | 
11  |  |  * the License, or (at your option) any later version.  | 
12  |  |  *  | 
13  |  |  * This library is distributed in the hope that it will be useful, but  | 
14  |  |  * WITHOUT ANY WARRANTY; without even the implied warranty of  | 
15  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  | 
16  |  |  * Lesser General Public License for more details.  | 
17  |  |  *  | 
18  |  |  * You should have received a copy of the GNU Lesser General Public License  | 
19  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>  | 
20  |  |  *  | 
21  |  |  */  | 
22  |  |  | 
23  |  | #include "gnutls_int.h"  | 
24  |  | #include "algorithms.h"  | 
25  |  | #include "errors.h"  | 
26  |  | #include "x509/common.h"  | 
27  |  | #include "c-strcase.h"  | 
28  |  | #include "profiles.h"  | 
29  |  |  | 
30  |  | typedef struct { | 
31  |  |   const char *name;  | 
32  |  |   gnutls_certificate_verification_profiles_t profile;  | 
33  |  |   gnutls_sec_param_t sec_param;  | 
34  |  | } gnutls_profile_entry;  | 
35  |  |  | 
36  |  | static const gnutls_profile_entry profiles[] = { | 
37  |  |   { "Very weak", GNUTLS_PROFILE_VERY_WEAK, GNUTLS_SEC_PARAM_VERY_WEAK }, | 
38  |  |   { "Low", GNUTLS_PROFILE_LOW, GNUTLS_SEC_PARAM_LOW }, | 
39  |  |   { "Legacy", GNUTLS_PROFILE_LEGACY, GNUTLS_SEC_PARAM_LEGACY }, | 
40  |  |   { "Medium", GNUTLS_PROFILE_MEDIUM, GNUTLS_SEC_PARAM_MEDIUM }, | 
41  |  |   { "High", GNUTLS_PROFILE_HIGH, GNUTLS_SEC_PARAM_HIGH }, | 
42  |  |   { "Ultra", GNUTLS_PROFILE_ULTRA, GNUTLS_SEC_PARAM_ULTRA }, | 
43  |  |   { "Future", GNUTLS_PROFILE_FUTURE, GNUTLS_SEC_PARAM_FUTURE }, | 
44  |  |   { "SuiteB128", GNUTLS_PROFILE_SUITEB128, GNUTLS_SEC_PARAM_HIGH }, | 
45  |  |   { "SuiteB192", GNUTLS_PROFILE_SUITEB192, GNUTLS_SEC_PARAM_ULTRA }, | 
46  |  |   { NULL, 0, 0 } | 
47  |  | };  | 
48  |  |  | 
49  |  | gnutls_sec_param_t  | 
50  |  | _gnutls_profile_to_sec_level(gnutls_certificate_verification_profiles_t profile)  | 
51  | 0  | { | 
52  | 0  |   const gnutls_profile_entry *p;  | 
53  |  | 
  | 
54  | 0  |   for (p = profiles; p->name != NULL; p++) { | 
55  | 0  |     if (profile == p->profile)  | 
56  | 0  |       return p->sec_param;  | 
57  | 0  |   }  | 
58  |  |  | 
59  | 0  |   return GNUTLS_SEC_PARAM_UNKNOWN;  | 
60  | 0  | }  | 
61  |  |  | 
62  |  | /**  | 
63  |  |  * gnutls_certificate_verification_profile_get_id:  | 
64  |  |  * @name: is a profile name  | 
65  |  |  *  | 
66  |  |  * Convert a string to a #gnutls_certificate_verification_profiles_t value.  The names are  | 
67  |  |  * compared in a case insensitive way.  | 
68  |  |  *  | 
69  |  |  * Returns: a #gnutls_certificate_verification_profiles_t id of the specified profile,  | 
70  |  |  *   or %GNUTLS_PROFILE_UNKNOWN on failure.  | 
71  |  |  **/  | 
72  |  | gnutls_certificate_verification_profiles_t  | 
73  |  | gnutls_certificate_verification_profile_get_id(const char *name)  | 
74  | 0  | { | 
75  | 0  |   const gnutls_profile_entry *p;  | 
76  |  | 
  | 
77  | 0  |   if (name == NULL)  | 
78  | 0  |     return GNUTLS_PROFILE_UNKNOWN;  | 
79  |  |  | 
80  | 0  |   for (p = profiles; p->name != NULL; p++) { | 
81  | 0  |     if (c_strcasecmp(p->name, name) == 0)  | 
82  | 0  |       return p->profile;  | 
83  | 0  |   }  | 
84  |  |  | 
85  | 0  |   return GNUTLS_PROFILE_UNKNOWN;  | 
86  | 0  | }  | 
87  |  |  | 
88  |  | /**  | 
89  |  |  * gnutls_certificate_verification_profile_get_name:  | 
90  |  |  * @id: is a profile ID  | 
91  |  |  *  | 
92  |  |  * Convert a #gnutls_certificate_verification_profiles_t value to a string.  | 
93  |  |  *  | 
94  |  |  * Returns: a string that contains the name of the specified profile or %NULL.  | 
95  |  |  **/  | 
96  |  | const char *gnutls_certificate_verification_profile_get_name(  | 
97  |  |   gnutls_certificate_verification_profiles_t id)  | 
98  | 0  | { | 
99  | 0  |   const gnutls_profile_entry *p;  | 
100  |  | 
  | 
101  | 0  |   for (p = profiles; p->name != NULL; p++) { | 
102  | 0  |     if (p->profile == id)  | 
103  | 0  |       return p->name;  | 
104  | 0  |   }  | 
105  |  |  | 
106  | 0  |   return NULL;  | 
107  | 0  | }  |