diff options
Diffstat (limited to 'crypto/ui')
-rw-r--r-- | crypto/ui/Makefile.ssl | 109 | ||||
-rw-r--r-- | crypto/ui/ui.h | 257 | ||||
-rw-r--r-- | crypto/ui/ui_compat.c | 97 | ||||
-rw-r--r-- | crypto/ui/ui_err.c | 104 | ||||
-rw-r--r-- | crypto/ui/ui_lib.c | 506 | ||||
-rw-r--r-- | crypto/ui/ui_locl.h | 110 | ||||
-rw-r--r-- | crypto/ui/ui_openssl.c | 575 |
7 files changed, 1758 insertions, 0 deletions
diff --git a/crypto/ui/Makefile.ssl b/crypto/ui/Makefile.ssl new file mode 100644 index 0000000000..21221555f4 --- /dev/null +++ b/crypto/ui/Makefile.ssl @@ -0,0 +1,109 @@ +# +# OpenSSL/crypto/ui/Makefile +# + +DIR= ui +TOP= ../.. +CC= cc +INCLUDES= -I.. -I$(TOP) -I../../include +CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl +INSTALLTOP=/usr/local/ssl +MAKE= make -f Makefile.ssl +MAKEDEPPROG= makedepend +MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) +MAKEFILE= Makefile.ssl +AR= ar r + +CFLAGS= $(INCLUDES) $(CFLAG) + +GENERAL=Makefile +TEST= uitest.c +APPS= + +COMPATSRC= ui_compat.c +COMPATOBJ= ui_compat.o + +LIB=$(TOP)/libcrypto.a +LIBSRC= ui_err.c ui_lib.c ui_openssl.c $(COMPATSRC) +LIBOBJ= ui_err.o ui_lib.o ui_openssl.o $(COMPATOBJ) + +SRC= $(LIBSRC) + +EXHEADER= ui.h +HEADER= $(EXHEADER) ui_locl.h + +ALL= $(GENERAL) $(SRC) $(HEADER) + +top: + (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) + +all: lib + +lib: $(LIBOBJ) + $(AR) $(LIB) $(LIBOBJ) + $(RANLIB) $(LIB) + @touch lib + +files: + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + +links: + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) + +install: + @for i in $(EXHEADER) ; \ + do \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ + done; + +tags: + ctags $(SRC) + +tests: + +lint: + lint -DLINT $(INCLUDES) $(SRC)>fluff + +depend: + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) + +dclean: + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + mv -f Makefile.new $(MAKEFILE) + +clean: + rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +ui_compat.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +ui_compat.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +ui_compat.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +ui_compat.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h +ui_compat.o: ../../include/openssl/ui.h ui_compat.c +ui_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h +ui_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +ui_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h +ui_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +ui_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h +ui_err.o: ../../include/openssl/ui.h ui_err.c +ui_lib.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h +ui_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +ui_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h +ui_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +ui_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h +ui_lib.o: ../../include/openssl/ui.h ui_lib.c ui_locl.h +ui_openssl.o: ../../e_os.h ../../include/openssl/bio.h +ui_openssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +ui_openssl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +ui_openssl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h +ui_openssl.o: ../../include/openssl/opensslv.h +ui_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +ui_openssl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h +ui_openssl.o: ../cryptlib.h ui_locl.h ui_openssl.c diff --git a/crypto/ui/ui.h b/crypto/ui/ui.h new file mode 100644 index 0000000000..9a03e8a9ec --- /dev/null +++ b/crypto/ui/ui.h @@ -0,0 +1,257 @@ +/* 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_H +#define HEADER_UI_H + +#include <openssl/crypto.h> +#include <openssl/safestack.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* The UI type is a holder for a specific user interface session. It can + contain an illimited number of informational or error strings as well + as things to prompt for, both passwords (noecho mode) and others (echo + mode), and verification of the same. All of these are called strings, + and are further described below. */ +typedef struct ui_st UI; + +/* All instances of UI have a reference to a method structure, which is a + ordered vector of functions that implement the lower level things to do. + There is an instruction on the implementation further down, in the section + for method implementors. */ +typedef struct ui_method_st UI_METHOD; + + +/* All the following functions return -1 or NULL on error. When everything is + fine, they return 0, a positive value or a non-NULL pointer, all depending + on their purpose. */ + +/* Creators and destructor. */ +UI *UI_new(void); +UI *UI_new_method(const UI_METHOD *method); +void UI_free(UI *ui); + +/* The following functions are used to add strings to be printed and prompt + strings to prompt for data. The names are UI_{add,dup}_<function>_string, + with the following meanings: + add add a text or prompt string. The pointers given to these + functions are used verbatim, no copying is done. + dup make a copy of the text or prompt string, then add the copy + to the collection of strings in the user interface. + <function> + The function is a name for the functionality that the given + string shall be used for. It can be one of: + input use the string as data prompt. + verify use the string as verification prompt. This + is used to verify a previous input. + info use the string for informational output. + error use the string for error output. + Honestly, there's currently no difference between info and error for the + moment. + + All of the functions in this group take a UI and a string. The input and + verify addition functions also take an echo flag, a buffer for the result + to end up with, a minimum input size and a maximum input size (the result + buffer MUST be large enough to be able to contain the maximum number of + characters). Additionally, the verify addition functions takes another + buffer to compare the result against. + + On success, the all return an index of the added information. That index + is usefull when retrieving results with UI_get0_result(). */ +int UI_add_input_string(UI *ui, const char *prompt, int echo_p, + char *result_buf, int minsize, int maxsize); +int UI_dup_input_string(UI *ui, const char *prompt, int echo_p, + char *result_buf, int minsize, int maxsize); +int UI_add_verify_string(UI *ui, const char *prompt, int echo_p, + char *result_buf, int minsize, int maxsize, const char *test_buf); +int UI_dup_verify_string(UI *ui, const char *prompt, int echo_p, + char *result_buf, int minsize, int maxsize, const char *test_buf); +int UI_add_info_string(UI *ui, const char *text); +int UI_dup_info_string(UI *ui, const char *text); +int UI_add_error_string(UI *ui, const char *text); +int UI_dup_error_string(UI *ui, const char *text); + +/* Return the result associated with a prompt given with the index i. */ +const char *UI_get0_result(UI *ui, int i); + +/* When all strings have been added, process the whole thing. */ +int UI_process(UI *ui); + +/* Some methods may use extra data */ +#define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg) +#define UI_get_app_data(s) UI_get_ex_data(s,0) +int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); +int UI_set_ex_data(UI *r,int idx,void *arg); +void *UI_get_ex_data(UI *r, int idx); + +/* Use specific methods instead of the built-in one */ +void UI_set_default_method(const UI_METHOD *meth); +const UI_METHOD *UI_get_default_method(void); +const UI_METHOD *UI_get_method(UI *ui); +const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth); + +/* The method with all the built-in thingies */ +UI_METHOD *UI_OpenSSL(void); + + +/* ---------- For method writers ---------- */ +/* A method contains a number of functions that implement the low level + of the User Interface. The functions are: + + an opener This function starts a session, maybe by opening + a channel to a tty, or by opening a window. + a writer This function is called to write a given string, + maybe to the tty, maybe as a field label in a + window. + a reader This function is called to read a given prompt, + maybe from the tty, maybe from a field in a + window. Note that it's called wth all string + structures, not only the prompt ones, so it must + check such things itself. + a closer This function closes the session, maybe by closing + the channel to the tty, or closing the window. + + The way this is used, the opener is first called, then the writer for all + strings, then the reader for all strings and finally the closer. Note that + if you want to prompt from a terminal or other command line interface, the + best is to have the reader also write the prompts instead of having the + writer do it. + All method functions take a UI as argument. Additionally, the writer and + the reader take a UI_STRING. */ + +/* The UI_STRING type is the data structure that contains all the needed info + about a string or a prompt, including test data for a verification prompt. +*/ +DECLARE_STACK_OF(UI_STRING) +typedef struct ui_string_st UI_STRING; + +/* The different types of strings that are currently supported. + This is only needed by method authors. */ +enum UI_string_types + { + UI_NONE=0, + UI_STRING_ECHO, /* Prompt for a string */ + UI_STRING_NOECHO, /* Prompt for a hidden string */ + UI_VERIFY_ECHO, /* Prompt for a string and verify */ + UI_VERIFY_NOECHO, /* Prompt for a hidden string and verify */ + UI_INFO, /* Send info to the user */ + UI_ERROR /* Send an error message to the user */ + }; + +/* Create and manipulate methods */ +UI_METHOD *UI_create_method(void); +int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)); +int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)); +int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)); +int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)); +int (*UI_method_get_opener(UI_METHOD *method))(UI*); +int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*); +int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*); +int (*UI_method_get_closer(UI_METHOD *method))(UI*); + +/* The following functions are helpers for method writers to access relevant + data from a UI_STRING. */ + +/* Return type type of the UI_STRING */ +enum UI_string_types UI_get_string_type(UI_STRING *uis); +/* Return the actual string to output (the prompt, info or error) */ +const char *UI_get0_output_string(UI_STRING *uis); +/* Return the result of a prompt */ +const char *UI_get0_result_string(UI_STRING *uis); +/* Return the string to test the result against. Only useful with verifies. */ +const char *UI_get0_test_string(UI_STRING *uis); +/* Return the required minimum size of the result */ +int UI_get_result_minsize(UI_STRING *uis); +/* Return the required maximum size of the result */ +int UI_get_result_maxsize(UI_STRING *uis); +/* Set the result of a UI_STRING. */ +int UI_set_result(UI_STRING *uis, char *result); + + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +void ERR_load_UI_strings(void); + +/* Error codes for the UI functions. */ + +/* Function codes. */ +#define UI_F_GENERAL_ALLOCATE_STRING 100 +#define UI_F_UI_DUP_ERROR_STRING 101 +#define UI_F_UI_DUP_INFO_STRING 102 +#define UI_F_UI_DUP_INPUT_STRING 103 +#define UI_F_UI_DUP_VERIFY_STRING 106 +#define UI_F_UI_GET0_RESULT 107 +#define UI_F_UI_NEW_METHOD 104 +#define UI_F_UI_SET_RESULT 105 + +/* Reason codes. */ +#define UI_R_INDEX_TOO_LARGE 102 +#define UI_R_INDEX_TOO_SMALL 103 +#define UI_R_RESULT_TOO_LARGE 100 +#define UI_R_RESULT_TOO_SMALL 101 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/crypto/ui/ui_compat.c b/crypto/ui/ui_compat.c new file mode 100644 index 0000000000..44392d70c2 --- /dev/null +++ b/crypto/ui/ui_compat.c @@ -0,0 +1,97 @@ +/* crypto/ui/ui_compat.c */ /* This was previously crypto/des/read2pwd.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * 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 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 acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS 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 AUTHOR OR 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. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include <openssl/des.h> +#include <openssl/ui.h> + +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) + des_string_to_key(buf,key); + UI_free(ui); + memset(buf,0,BUFSIZ); + memset(buff,0,BUFSIZ); + return(ok); + } + +int des_read_2passwords(des_cblock *key1, des_cblock *key2, 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) + des_string_to_2keys(buf,key1,key2); + UI_free(ui); + memset(buf,0,BUFSIZ); + memset(buff,0,BUFSIZ); + return(ok); + } diff --git a/crypto/ui/ui_err.c b/crypto/ui/ui_err.c new file mode 100644 index 0000000000..ca50be6be4 --- /dev/null +++ b/crypto/ui/ui_err.c @@ -0,0 +1,104 @@ +/* crypto/ui/ui_err.c */ +/* ==================================================================== + * Copyright (c) 1999 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). + * + */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file, + * only reason strings will be preserved. + */ + +#include <stdio.h> +#include <openssl/err.h> +#include <openssl/ui.h> + +/* BEGIN ERROR CODES */ +#ifndef OPENSSL_NO_ERR +static ERR_STRING_DATA UI_str_functs[]= + { +{ERR_PACK(0,UI_F_GENERAL_ALLOCATE_STRING,0), "GENERAL_ALLOCATE_STRING"}, +{ERR_PACK(0,UI_F_UI_DUP_ERROR_STRING,0), "UI_dup_error_string"}, +{ERR_PACK(0,UI_F_UI_DUP_INFO_STRING,0), "UI_dup_info_string"}, +{ERR_PACK(0,UI_F_UI_DUP_INPUT_STRING,0), "UI_dup_input_string"}, +{ERR_PACK(0,UI_F_UI_DUP_VERIFY_STRING,0), "UI_dup_verify_string"}, +{ERR_PACK(0,UI_F_UI_GET0_RESULT,0), "UI_get0_result"}, +{ERR_PACK(0,UI_F_UI_NEW_METHOD,0), "UI_new_method"}, +{ERR_PACK(0,UI_F_UI_SET_RESULT,0), "UI_set_result"}, +{0,NULL} + }; + +static ERR_STRING_DATA UI_str_reasons[]= + { +{UI_R_INDEX_TOO_LARGE ,"index too large"}, +{UI_R_INDEX_TOO_SMALL ,"index too small"}, +{UI_R_RESULT_TOO_LARGE ,"result too large"}, +{UI_R_RESULT_TOO_SMALL ,"result too small"}, +{0,NULL} + }; + +#endif + +void ERR_load_UI_strings(void) + { + static int init=1; + + if (init) + { + init=0; +#ifndef OPENSSL_NO_ERR + ERR_load_strings(ERR_LIB_UI,UI_str_functs); + ERR_load_strings(ERR_LIB_UI,UI_str_reasons); +#endif + + } + } diff --git a/crypto/ui/ui_lib.c b/crypto/ui/ui_lib.c new file mode 100644 index 0000000000..132236fe65 --- /dev/null +++ b/crypto/ui/ui_lib.c @@ -0,0 +1,506 @@ +/* crypto/ui/ui_lib.c -*- 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). + * + */ + +#include <string.h> + +#include <openssl/ui.h> +#include <openssl/err.h> +#include "ui_locl.h" + +IMPLEMENT_STACK_OF(UI_STRING_ST) + +static const UI_METHOD *default_UI_meth=NULL; +static int ui_meth_num=0; +static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ui_meth=NULL; + +UI *UI_new(void) + { + return(UI_new_method(NULL)); + } + +UI *UI_new_method(const UI_METHOD *method) + { + UI *ret; + + ret=(UI *)OPENSSL_malloc(sizeof(UI)); + if (ret == NULL) + { + UIerr(UI_F_UI_NEW_METHOD,ERR_R_MALLOC_FAILURE); + return NULL; + } + if (method == NULL) + ret->meth=UI_get_default_method(); + else + ret->meth=method; + + ret->strings=NULL; + return ret; + } + +static void free_string(void *data) + { + UI_STRING *uis = (UI_STRING *)data; + if (uis->flags & OUT_STRING_FREEABLE) + OPENSSL_free((char *)uis->out_string); + OPENSSL_free(uis); + } + +void UI_free(UI *ui) + { + sk_UI_STRING_pop_free(ui->strings,free_string); + OPENSSL_free(ui); + } + +static int allocate_string_stack(UI *ui) + { + if (ui->strings == NULL) + { + ui->strings=sk_UI_STRING_new_null(); + if (ui->strings == NULL) + { + return -1; + } + } + return 0; + } + +static int general_allocate_string(UI *ui, const char *prompt, + int prompt_freeable, enum UI_string_types type, + char *result_buf, int minsize, int maxsize, const char *test_buf) + { + int ret=-1; + + if (prompt == NULL) + { + UIerr(UI_F_GENERAL_ALLOCATE_STRING,ERR_R_PASSED_NULL_PARAMETER); + } + else if (allocate_string_stack(ui) >= 0) + { + UI_STRING *s=(UI_STRING *)OPENSSL_malloc(sizeof(UI_STRING)); + s->out_string=prompt; + s->flags=prompt_freeable ? OUT_STRING_FREEABLE : 0; + s->type=type; + s->result_buf=result_buf; + s->result_minsize=minsize; + s->result_maxsize=maxsize; + s->test_buf=test_buf; + ret=sk_UI_STRING_push(ui->strings, s); + } + return ret; + } + +/* Returns the index to the place in the stack or 0 for error. Uses a + direct reference to the prompt. */ +int UI_add_input_string(UI *ui, const char *prompt, int echo_p, + char *result_buf, int minsize, int maxsize) + { + return general_allocate_string(ui, prompt, 0, + echo_p?UI_STRING_ECHO:UI_STRING_NOECHO, + result_buf, minsize, maxsize, NULL); + } + +/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */ +int UI_dup_input_string(UI *ui, const char *prompt, int echo_p, + char *result_buf, int minsize, int maxsize) + { + char *prompt_copy=NULL; + + if (prompt) + { + prompt_copy=strdup(prompt); + if (prompt_copy == NULL) + { + UIerr(UI_F_UI_DUP_INPUT_STRING,ERR_R_MALLOC_FAILURE); + return 0; + } + } + + return general_allocate_string(ui, prompt, 1, + echo_p?UI_STRING_ECHO:UI_STRING_NOECHO, + result_buf, minsize, maxsize, NULL); + } + +int UI_add_verify_string(UI *ui, const char *prompt, int echo_p, + char *result_buf, int minsize, int maxsize, const char *test_buf) + { + return general_allocate_string(ui, prompt, 0, + echo_p?UI_VERIFY_ECHO:UI_VERIFY_NOECHO, + result_buf, minsize, maxsize, test_buf); + } + +int UI_dup_verify_string(UI *ui, const char *prompt, int echo_p, + char *result_buf, int minsize, int maxsize, const char *test_buf) + { + char *prompt_copy=NULL; + + if (prompt) + { + prompt_copy=strdup(prompt); + if (prompt_copy == NULL) + { + UIerr(UI_F_UI_DUP_VERIFY_STRING,ERR_R_MALLOC_FAILURE); + return -1; + } + } + + return general_allocate_string(ui, prompt, 1, + echo_p?UI_VERIFY_ECHO:UI_VERIFY_NOECHO, + result_buf, minsize, maxsize, test_buf); + } + +int UI_add_info_string(UI *ui, const char *text) + { + return general_allocate_string(ui, text, 0, UI_INFO, NULL, 0, 0, NULL); + } + +int UI_dup_info_string(UI *ui, const char *text) + { + char *text_copy=NULL; + + if (text) + { + text_copy=strdup(text); + if (text_copy == NULL) + { + UIerr(UI_F_UI_DUP_INFO_STRING,ERR_R_MALLOC_FAILURE); + return -1; + } + } + + return general_allocate_string(ui, text, 1, UI_INFO, NULL, 0, 0, NULL); + } + +int UI_add_error_string(UI *ui, const char *text) + { + return general_allocate_string(ui, text, 0, UI_ERROR, NULL, 0, 0, + NULL); + } + +int UI_dup_error_string(UI *ui, const char *text) + { + char *text_copy=NULL; + + if (text) + { + text_copy=strdup(text); + if (text_copy == NULL) + { + UIerr(UI_F_UI_DUP_ERROR_STRING,ERR_R_MALLOC_FAILURE); + return -1; + } + } + return general_allocate_string(ui, text_copy, 1, UI_ERROR, NULL, 0, 0, + NULL); + } + +const char *UI_get0_result(UI *ui, int i) + { + if (i < 0) + { + UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_SMALL); + return NULL; + } + if (i >= sk_UI_STRING_num(ui->strings)) + { + UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_LARGE); + return NULL; + } + return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i)); + } + +int UI_process(UI *ui) + { + int i, ok=0; + + if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui)) + return -1; + + for(i=0; i<sk_UI_STRING_num(ui->strings); i++) + { + if (ui->meth->ui_write_string + && !ui->meth->ui_write_string(ui, + sk_UI_STRING_value(ui->strings, i))) + { + ok=-1; + goto err; + } + } + + for(i=0; i<sk_UI_STRING_num(ui->strings); i++) + { + if (ui->meth->ui_read_string + && !ui->meth->ui_read_string(ui, + sk_UI_STRING_value(ui->strings, i))) + { + ok=-1; + goto err; + } + } + err: + if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui)) + return -1; + return ok; + } + +int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) + { + ui_meth_num++; + return(CRYPTO_get_ex_new_index(ui_meth_num-1, + &ui_meth,argl,argp,new_func,dup_func,free_func)); + } + +int UI_set_ex_data(UI *r, int idx, void *arg) + { + return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); + } + +void *UI_get_ex_data(UI *r, int idx) + { + return(CRYPTO_get_ex_data(&r->ex_data,idx)); + } + +void UI_set_default_method(const UI_METHOD *meth) + { + default_UI_meth=meth; + } + +const UI_METHOD *UI_get_default_method(void) + { + if (default_UI_meth == NULL) + { + default_UI_meth=UI_OpenSSL(); + } + return default_UI_meth; + } + +const UI_METHOD *UI_get_method(UI *ui) + { + return ui->meth; + } + +const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth) + { + ui->meth=meth; + return ui->meth; + } + + +UI_METHOD *UI_create_method(void) + { + return (UI_METHOD *)OPENSSL_malloc(sizeof(UI_METHOD)); + } + +int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)) + { + if (method) + { + method->ui_open_session = opener; + return 0; + } + else + return -1; + } + +int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)) + { + if (method) + { + method->ui_write_string = writer; + return 0; + } + else + return -1; + } + +int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)) + { + if (method) + { + method->ui_read_string = reader; + return 0; + } + else + return -1; + } + +int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)) + { + if (method) + { + method->ui_close_session = closer; + return 0; + } + else + return -1; + } + +int (*UI_method_get_opener(UI_METHOD *method))(UI*) + { + if (method) + return method->ui_open_session; + else + return NULL; + } + +int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*) |