gsasl  2.2.1
scram/validate.c
Go to the documentation of this file.
1 /* validate.c --- Validate consistency of SCRAM tokens.
2  * Copyright (C) 2009-2024 Simon Josefsson
3  *
4  * This file is part of GNU SASL Library.
5  *
6  * GNU SASL Library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * GNU SASL Library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with GNU SASL Library; if not, write to the Free
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include <config.h>
24 
25 /* Get prototypes. */
26 #include "validate.h"
27 
28 /* Get strcmp, strlen. */
29 #include <string.h>
30 
31 bool
33 {
34  /* Check that cbflag is one of permitted values. */
35  switch (cf->cbflag)
36  {
37  case 'p':
38  case 'n':
39  case 'y':
40  break;
41 
42  default:
43  return false;
44  }
45 
46  /* Check that cbname is only set when cbflag is p. */
47  if (cf->cbflag == 'p' && cf->cbname == NULL)
48  return false;
49  else if (cf->cbflag != 'p' && cf->cbname != NULL)
50  return false;
51 
52  if (cf->cbname)
53  {
54  const char *p = cf->cbname;
55 
56  while (*p && strchr ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
57  "abcdefghijklmnopqrstuvwxyz" "0123456789.-", *p))
58  p++;
59  if (*p)
60  return false;
61  }
62 
63  /* We require a non-zero username string. */
64  if (cf->username == NULL || *cf->username == '\0')
65  return false;
66 
67  /* We require a non-zero client nonce. */
68  if (cf->client_nonce == NULL || *cf->client_nonce == '\0')
69  return false;
70 
71  /* Nonce cannot contain ','. */
72  if (strchr (cf->client_nonce, ','))
73  return false;
74 
75  return true;
76 }
77 
78 bool
80 {
81  /* We require a non-zero nonce. */
82  if (sf->nonce == NULL || *sf->nonce == '\0')
83  return false;
84 
85  /* Nonce cannot contain ','. */
86  if (strchr (sf->nonce, ','))
87  return false;
88 
89  /* We require a non-zero salt. */
90  if (sf->salt == NULL || *sf->salt == '\0')
91  return false;
92 
93  /* FIXME check that salt is valid base64. */
94  if (strchr (sf->salt, ','))
95  return false;
96 
97  if (sf->iter == 0)
98  return false;
99 
100  return true;
101 }
102 
103 bool
105 {
106  /* We require a non-zero cbind. */
107  if (cl->cbind == NULL || *cl->cbind == '\0')
108  return false;
109 
110  /* FIXME check that cbind is valid base64. */
111  if (strchr (cl->cbind, ','))
112  return false;
113 
114  /* We require a non-zero nonce. */
115  if (cl->nonce == NULL || *cl->nonce == '\0')
116  return false;
117 
118  /* Nonce cannot contain ','. */
119  if (strchr (cl->nonce, ','))
120  return false;
121 
122  /* We require a non-zero proof. */
123  if (cl->proof == NULL || *cl->proof == '\0')
124  return false;
125 
126  /* FIXME check that proof is valid base64. */
127  if (strchr (cl->proof, ','))
128  return false;
129 
130  return true;
131 }
132 
133 bool
135 {
136  /* We require a non-zero verifier. */
137  if (sl->verifier == NULL || *sl->verifier == '\0')
138  return false;
139 
140  /* FIXME check that verifier is valid base64. */
141  if (strchr (sl->verifier, ','))
142  return false;
143 
144  return true;
145 }
bool scram_valid_client_first(struct scram_client_first *cf)
bool scram_valid_server_final(struct scram_server_final *sl)
bool scram_valid_server_first(struct scram_server_first *sf)
bool scram_valid_client_final(struct scram_client_final *cl)