aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-12-31 23:49:00 -0900
committerDavid M. Syzdek <david@syzdek.net>2022-12-31 23:49:00 -0900
commitcda97253ecc8794116cca2cb8b321be299fad027 (patch)
treefe5ce476c7d7c33aedf239c832c89e742146e584 /src
parent58db357d64ad596461acc8a9402d2d3d4e4eb7bc (diff)
downloadotputils-cda97253ecc8794116cca2cb8b321be299fad027.tar.gz
otputils-cda97253ecc8794116cca2cb8b321be299fad027.tar.bz2
otputils-cda97253ecc8794116cca2cb8b321be299fad027.tar.xz
otputils-cda97253ecc8794116cca2cb8b321be299fad027.zip
otputil: updating verbose output for hotp widget
Diffstat (limited to 'src')
-rw-r--r--src/widget-hotp.c59
1 files changed, 43 insertions, 16 deletions
diff --git a/src/widget-hotp.c b/src/widget-hotp.c
index 0213d98..dbaddd3 100644
--- a/src/widget-hotp.c
+++ b/src/widget-hotp.c
@@ -68,6 +68,13 @@ otputil_widget_hotp_code(
68 68
69 69
70static int 70static int
71otputil_widget_hotp_verbose(
72 otputil_config_t * cnf,
73 const char * code,
74 const char * status );
75
76
77static int
71otputil_widget_hotp_verify( 78otputil_widget_hotp_verify(
72 otputil_config_t * cnf ); 79 otputil_config_t * cnf );
73 80
@@ -114,7 +121,7 @@ otputil_widget_hotp(
114 cnf->pass = (cnf->argc > optind) ? cnf->argv[optind] : cnf->pass; 121 cnf->pass = (cnf->argc > optind) ? cnf->argv[optind] : cnf->pass;
115 122
116 if ((cnf->pass)) 123 if ((cnf->pass))
117 otputil_widget_hotp_verify(cnf); 124 return(otputil_widget_hotp_verify(cnf));
118 125
119 return(otputil_widget_hotp_code(cnf)); 126 return(otputil_widget_hotp_code(cnf));
120} 127}
@@ -124,18 +131,11 @@ int
124otputil_widget_hotp_code( 131otputil_widget_hotp_code(
125 otputil_config_t * cnf ) 132 otputil_config_t * cnf )
126{ 133{
127 uint64_t hotp_c;
128 const char * code; 134 const char * code;
129 static char buff[OTPUTIL_MAX_CODE_SIZE]; 135 static char buff[OTPUTIL_MAX_CODE_SIZE];
130 char * otp_kstr;
131 char * otp_desc;
132 136
133 assert(cnf != NULL); 137 assert(cnf != NULL);
134 138
135 otputil_get_param(NULL, OTPUTIL_OPT_TOTP_X, &hotp_c);
136 otputil_get_param(NULL, OTPUTIL_OPT_HOTP_KSTR, &otp_kstr);
137 otputil_get_param(NULL, OTPUTIL_OPT_DESC, &otp_desc);
138
139 if ((code = otputil_str(NULL, buff, sizeof(buff))) == NULL) 139 if ((code = otputil_str(NULL, buff, sizeof(buff))) == NULL)
140 { 140 {
141 fprintf(stderr, "%s: internal error\n", cnf->prog_name); 141 fprintf(stderr, "%s: internal error\n", cnf->prog_name);
@@ -149,12 +149,37 @@ otputil_widget_hotp_code(
149 }; 149 };
150 150
151 // print secret information 151 // print secret information
152 otputil_widget_hotp_verbose(cnf, code, NULL);
153
154 return(0);
155}
156
157
158int
159otputil_widget_hotp_verbose(
160 otputil_config_t * cnf,
161 const char * code,
162 const char * status )
163{
164 uint64_t hotp_c;
165 char * otp_kstr;
166 char * otp_desc;
167
168 otputil_get_param(NULL, OTPUTIL_OPT_TOTP_X, &hotp_c);
169 otputil_get_param(NULL, OTPUTIL_OPT_HOTP_KSTR, &otp_kstr);
170 otputil_get_param(NULL, OTPUTIL_OPT_DESC, &otp_desc);
171
172 // print secret information
152 printf("OTP Secret:\n"); 173 printf("OTP Secret:\n");
153 printf(" Description: %s\n", (((otp_desc)) ? otp_desc : "n/a") ); 174 printf(" Description: %s\n", (((otp_desc)) ? otp_desc : "n/a") );
154 printf(" Method: HOTP (RFC4226)\n"); 175 printf(" Method: HOTP (RFC4226)\n");
155 printf(" Shared Key: %s\n", otp_kstr ); 176 printf(" Shared Key: %s\n", otp_kstr );
156 printf(" Counter: %" PRIu64 "\n", hotp_c ); 177 printf(" Counter: %" PRIu64 "\n", hotp_c );
178 if ((cnf->pass))
179 printf(" Expected Code: %s\n", cnf->pass );
157 printf(" Code: %s\n", code ); 180 printf(" Code: %s\n", code );
181 if ((status))
182 printf(" Status: %s\n", status );
158 printf("\n"); 183 printf("\n");
159 184
160 return(0); 185 return(0);
@@ -166,7 +191,9 @@ otputil_widget_hotp_verify(
166 otputil_config_t * cnf ) 191 otputil_config_t * cnf )
167{ 192{
168 const char * code; 193 const char * code;
169 194 const char * status;
195 int rc;
196
170 assert(cnf != NULL); 197 assert(cnf != NULL);
171 198
172 if ((code = otputil_str(NULL, NULL, 0)) == NULL) 199 if ((code = otputil_str(NULL, NULL, 0)) == NULL)
@@ -175,15 +202,15 @@ otputil_widget_hotp_verify(
175 return(1); 202 return(1);
176 }; 203 };
177 204
178 if ((strcasecmp(cnf->pass, code))) 205 rc = ((strcasecmp(cnf->pass, code))) ? 2 : 0;
179 { 206 status = ((rc)) ? "invalid code" : "valid code";
180 printf("%s\n", "invalid code");
181 return(2);
182 };
183 207
184 printf("%s\n", "valid code"); 208 if ((cnf->verbose))
209 otputil_widget_hotp_verbose(cnf, code, status);
210 else
211 printf("%s\n", status);
185 212
186 return(0); 213 return(rc);
187} 214}
188 215
189 216