From 56bb1a7c83f2c498f4cc308786a4f253e8a5d9b5 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Sun, 13 May 2001 04:40:44 +0000 Subject: Move the password reading functions completely away from the DES section. Add ui_compat.h for inclusion by those who want the old functions and provide all of them, not just the higher-level ones, in ui_compat.c. --- crypto/ui/Makefile.ssl | 2 +- crypto/ui/ui_compat.c | 36 ++++++++++++++-------- crypto/ui/ui_compat.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 crypto/ui/ui_compat.h (limited to 'crypto/ui') diff --git a/crypto/ui/Makefile.ssl b/crypto/ui/Makefile.ssl index 8c9a4acf07..77467b8486 100644 --- a/crypto/ui/Makefile.ssl +++ b/crypto/ui/Makefile.ssl @@ -32,7 +32,7 @@ LIBOBJ= ui_err.o ui_lib.o ui_openssl.o $(COMPATOBJ) SRC= $(LIBSRC) -EXHEADER= ui.h +EXHEADER= ui.h ui_compat.h HEADER= $(EXHEADER) ui_locl.h ALL= $(GENERAL) $(SRC) $(HEADER) diff --git a/crypto/ui/ui_compat.c b/crypto/ui/ui_compat.c index 44392d70c2..f328bdc6c0 100644 --- a/crypto/ui/ui_compat.c +++ b/crypto/ui/ui_compat.c @@ -1,4 +1,5 @@ -/* crypto/ui/ui_compat.c */ /* This was previously crypto/des/read2pwd.c */ +/* crypto/ui/ui_compat.c -*- mode:C; c-file-style: "eay" -*- */ +/* This was previously crypto/des/read2pwd.c and partly crypto/des/read_pwd.c */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -63,15 +64,9 @@ int des_read_password(des_cblock *key, const char *prompt, int verify) { int ok; char buf[BUFSIZ],buff[BUFSIZ]; - UI *ui; - ui = UI_new(); - UI_add_input_string(ui,prompt,0,buf,0,BUFSIZ-1); - if (verify) - UI_add_verify_string(ui,prompt,0,buff,0,BUFSIZ-1,buf); - if ((ok=UI_process(ui)) == 0) + if ((ok=des_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0) des_string_to_key(buf,key); - UI_free(ui); memset(buf,0,BUFSIZ); memset(buff,0,BUFSIZ); return(ok); @@ -82,16 +77,33 @@ int des_read_2passwords(des_cblock *key1, des_cblock *key2, const char *prompt, { int ok; char buf[BUFSIZ],buff[BUFSIZ]; + + if ((ok=des_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0) + des_string_to_2keys(buf,key1,key2); + memset(buf,0,BUFSIZ); + memset(buff,0,BUFSIZ); + return(ok); + } + +int des_read_pw_string(char *buf,int length,const char *prompt,int verify) + { + char buff[BUFSIZ]; + int ret; + + ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify); + memset(buff,0,BUFSIZ); + return(ret); + } + +int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify) + { UI *ui; ui = UI_new(); UI_add_input_string(ui,prompt,0,buf,0,BUFSIZ-1); if (verify) UI_add_verify_string(ui,prompt,0,buff,0,BUFSIZ-1,buf); - if ((ok=UI_process(ui)) == 0) - des_string_to_2keys(buf,key1,key2); + ok=UI_process(ui); UI_free(ui); - memset(buf,0,BUFSIZ); - memset(buff,0,BUFSIZ); return(ok); } diff --git a/crypto/ui/ui_compat.h b/crypto/ui/ui_compat.h new file mode 100644 index 0000000000..3b19b82072 --- /dev/null +++ b/crypto/ui/ui_compat.h @@ -0,0 +1,81 @@ +/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */ +/* Written by Richard Levitte (levitte@stacken.kth.se) for the OpenSSL + * project 2000. + */ +/* ==================================================================== + * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_UI_COMPAT_H +#define HEADER_UI_COMPAT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* The following functions were previously part of the DES section, + and are provided here for backward compatibility reasons. */ + +int des_read_password(des_cblock *key,const char *prompt,int verify); +int des_read_2passwords(des_cblock *key1,des_cblock *key2, + const char *prompt,int verify); + +int des_read_pw_string(char *buf,int length,const char *prompt,int verify); +int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify); + +#ifdef __cplusplus +} +#endif +#endif -- cgit v1.2.1