| 
									
										
										
										
											2016-05-18 03:38:09 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2002-02-06 01:15:18 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-05-18 03:38:09 +08:00
										 |  |  |  * Licensed under the OpenSSL license (the "License").  You may not use | 
					
						
							|  |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							| 
									
										
										
										
											2002-02-06 01:15:18 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2004-05-18 02:01:28 +08:00
										 |  |  | #include "ui_locl.h"
 | 
					
						
							| 
									
										
										
										
											2002-02-06 01:15:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-12 02:56:32 +08:00
										 |  |  | #ifndef BUFSIZ
 | 
					
						
							|  |  |  | #define BUFSIZ 256
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, | 
					
						
							|  |  |  |                            int verify) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     char buff[BUFSIZ]; | 
					
						
							|  |  |  |     int ret; | 
					
						
							| 
									
										
										
										
											2002-02-06 01:15:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     ret = | 
					
						
							|  |  |  |         UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length, | 
					
						
							|  |  |  |                         prompt, verify); | 
					
						
							|  |  |  |     OPENSSL_cleanse(buff, BUFSIZ); | 
					
						
							|  |  |  |     return (ret); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2002-02-06 01:15:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, | 
					
						
							|  |  |  |                     int verify) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int ok = 0; | 
					
						
							|  |  |  |     UI *ui; | 
					
						
							| 
									
										
										
										
											2002-02-06 01:15:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (size < 1) | 
					
						
							|  |  |  |         return -1; | 
					
						
							| 
									
										
										
										
											2002-07-11 17:12:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     ui = UI_new(); | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |     if (ui != NULL) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         ok = UI_add_input_string(ui, prompt, 0, buf, 0, size - 1); | 
					
						
							|  |  |  |         if (ok >= 0 && verify) | 
					
						
							|  |  |  |             ok = UI_add_verify_string(ui, prompt, 0, buff, 0, size - 1, buf); | 
					
						
							|  |  |  |         if (ok >= 0) | 
					
						
							|  |  |  |             ok = UI_process(ui); | 
					
						
							|  |  |  |         UI_free(ui); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (ok > 0) | 
					
						
							|  |  |  |         ok = 0; | 
					
						
							|  |  |  |     return (ok); | 
					
						
							|  |  |  | } |