Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 # include "config.h"
00025 #endif
00026
00027
00028 #include "printer.h"
00029
00030
00031 #include <stdlib.h>
00032
00033
00034 #include <stdio.h>
00035
00036
00037 #include <string.h>
00038
00039
00040 #include "validate.h"
00041
00042 static char *
00043 scram_escape (const char *str)
00044 {
00045 char *out = malloc (strlen (str) * 3 + 1);
00046 char *p = out;
00047
00048 if (!out)
00049 return NULL;
00050
00051 while (*str)
00052 {
00053 if (*str == ',')
00054 {
00055 memcpy (p, "=2C", 3);
00056 p += 3;
00057 }
00058 else if (*str == '=')
00059 {
00060 memcpy (p, "=3D", 3);
00061 p += 3;
00062 }
00063 else
00064 {
00065 *p = *str;
00066 p++;
00067 }
00068 str++;
00069 }
00070 *p = '\0';
00071
00072 return out;
00073 }
00074
00075
00076
00077
00078 int
00079 scram_print_client_first (struct scram_client_first *cf, char **out)
00080 {
00081 char *username = NULL;
00082 char *authzid = NULL;
00083 int n;
00084
00085
00086
00087 if (!scram_valid_client_first (cf))
00088 return -1;
00089
00090
00091
00092 username = scram_escape (cf->username);
00093 if (!username)
00094 return -2;
00095
00096 if (cf->authzid)
00097 {
00098 authzid = scram_escape (cf->authzid);
00099 if (!authzid)
00100 return -2;
00101 }
00102
00103 n = asprintf (out, "%c%s%s,%s%s,n=%s,r=%s",
00104 cf->cbflag,
00105 cf->cbflag == 'p' ? "=" : "",
00106 cf->cbflag == 'p' ? cf->cbname : "",
00107 authzid ? "a=" : "",
00108 authzid ? authzid : "",
00109 username,
00110 cf->client_nonce);
00111
00112 free (username);
00113 free (authzid);
00114
00115 if (n <= 0 || *out == NULL)
00116 return -1;
00117
00118 return 0;
00119 }
00120
00121
00122
00123
00124 int
00125 scram_print_server_first (struct scram_server_first *sf, char **out)
00126 {
00127 int n;
00128
00129
00130
00131 if (!scram_valid_server_first (sf))
00132 return -1;
00133
00134 n = asprintf (out, "r=%s,s=%s,i=%d",
00135 sf->nonce, sf->salt, sf->iter);
00136 if (n <= 0 || *out == NULL)
00137 return -1;
00138
00139 return 0;
00140 }
00141
00142
00143
00144
00145 int
00146 scram_print_client_final (struct scram_client_final *cl, char **out)
00147 {
00148 int n;
00149
00150
00151
00152 if (!scram_valid_client_final (cl))
00153 return -1;
00154
00155 n = asprintf (out, "c=%s,r=%s,p=%s",
00156 cl->cbind, cl->nonce, cl->proof);
00157 if (n <= 0 || *out == NULL)
00158 return -1;
00159
00160 return 0;
00161 }
00162
00163
00164
00165
00166 int
00167 scram_print_server_final (struct scram_server_final *sl, char **out)
00168 {
00169 int n;
00170
00171
00172
00173 if (!scram_valid_server_final (sl))
00174 return -1;
00175
00176 n = asprintf (out, "v=%s", sl->verifier);
00177 if (n <= 0 || *out == NULL)
00178 return -1;
00179
00180 return 0;
00181 }