diff options
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | Makefile.org | 2 | ||||
-rw-r--r-- | crypto/Makefile.ssl | 2 | ||||
-rw-r--r-- | crypto/cryptlib.c | 3 | ||||
-rw-r--r-- | crypto/crypto-lib.com | 4 | ||||
-rw-r--r-- | crypto/crypto.h | 3 | ||||
-rw-r--r-- | crypto/des/Makefile.ssl | 11 | ||||
-rw-r--r-- | crypto/err/err.h | 3 | ||||
-rw-r--r-- | crypto/err/openssl.ec | 1 | ||||
-rw-r--r-- | crypto/evp/evp_key.c | 19 | ||||
-rw-r--r-- | crypto/stack/safestack.h | 20 | ||||
-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 | ||||
-rwxr-xr-x | makevms.com | 3 | ||||
-rwxr-xr-x | util/mkdef.pl | 1 |
20 files changed, 1822 insertions, 15 deletions
@@ -11,6 +11,13 @@ *) applies to 0.9.6a (/0.9.6b) and 0.9.7 +) applies to 0.9.7 only + +) Add a general user interface API. This is designed to replace things + like des_read_password and friends (backward compatibility functions + using this new API are provided). The purpose is to remove prompting + functions from the DES code section as well as provide for prompting + through dialog boxes in a window system and the like. + [Richard Levitte] + *) In versions up to 0.9.6, RAND_file_name() resorted to file ".rnd" in the current directory if neither $RANDFILE nor $HOME was set. RAND_file_name() in 0.9.6a returned NULL in this case. This has diff --git a/Makefile.org b/Makefile.org index 0ed5a6ff2b..a792cbcdce 100644 --- a/Makefile.org +++ b/Makefile.org @@ -168,7 +168,7 @@ SDIRS= \ des rc2 rc4 rc5 idea bf cast \ bn ec rsa dsa dh dso engine rijndael \ buffer bio stack lhash rand err objects \ - evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp + evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp ui # tests to perform. "alltests" is a special word indicating that all tests # should be performed. diff --git a/crypto/Makefile.ssl b/crypto/Makefile.ssl index 0f522b4acc..3533ad8d3d 100644 --- a/crypto/Makefile.ssl +++ b/crypto/Makefile.ssl @@ -30,7 +30,7 @@ SDIRS= md2 md5 sha mdc2 hmac ripemd \ des rc2 rc4 rc5 idea bf cast \ bn ec rsa dsa dh dso engine rijndael \ buffer bio stack lhash rand err objects \ - evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp + evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp ui GENERAL=Makefile README crypto-lib.com install.com diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c index 11ac630c22..5871216b0b 100644 --- a/crypto/cryptlib.c +++ b/crypto/cryptlib.c @@ -101,7 +101,8 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] = "dso", "dynlock", "engine", -#if CRYPTO_NUM_LOCKS != 29 + "ui", +#if CRYPTO_NUM_LOCKS != 30 # error "Inconsistency between crypto.h and cryptlib.c" #endif }; diff --git a/crypto/crypto-lib.com b/crypto/crypto-lib.com index 6f18e43427..7c74b8745c 100644 --- a/crypto/crypto-lib.com +++ b/crypto/crypto-lib.com @@ -91,7 +91,7 @@ $ ENCRYPT_TYPES = "Basic,MD2,MD4,MD5,SHA,MDC2,HMAC,RIPEMD,"+ - "BN,EC,RSA,DSA,DH,DSO,ENGINE,RIJNDAEL,"+ - "BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,"+ - "EVP,EVP_2,ASN1,ASN1_2,PEM,X509,X509V3,"+ - - "CONF,TXT_DB,PKCS7,PKCS12,COMP,OCSP" + "CONF,TXT_DB,PKCS7,PKCS12,COMP,OCSP,UI" $ ENCRYPT_PROGRAMS = "DES,PKCS7" $! $! Check To Make Sure We Have Valid Command Line Parameters. @@ -269,6 +269,8 @@ $ LIB_COMP = "comp_lib,"+ - "c_rle,c_zlib" $ LIB_OCSP = "ocsp_asn,ocsp_ext,ocsp_ht,ocsp_lib,ocsp_cl,"+ - "ocsp_srv,ocsp_prn,ocsp_vfy,ocsp_err" +$ LIB_UI_COMPAT = "ui_compat" +$ LIB_UI = "ui_er,ui_lib,ui_openssl,"+LIB_UI_COMPAT $! $! Setup exceptional compilations $! diff --git a/crypto/crypto.h b/crypto/crypto.h index af678a7489..c54f471290 100644 --- a/crypto/crypto.h +++ b/crypto/crypto.h @@ -124,7 +124,8 @@ extern "C" { #define CRYPTO_LOCK_DSO 26 #define CRYPTO_LOCK_DYNLOCK 27 #define CRYPTO_LOCK_ENGINE 28 -#define CRYPTO_NUM_LOCKS 29 +#define CRYPTO_LOCK_UI 29 +#define CRYPTO_NUM_LOCKS 30 #define CRYPTO_LOCK 1 #define CRYPTO_UNLOCK 2 diff --git a/crypto/des/Makefile.ssl b/crypto/des/Makefile.ssl index 5658172583..f197fd788e 100644 --- a/crypto/des/Makefile.ssl +++ b/crypto/des/Makefile.ssl @@ -40,8 +40,8 @@ LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \ ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \ enc_read.o enc_writ.o ofb64enc.o \ ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \ - ${DES_ENC} read2pwd.o \ - fcrypt.o xcbc_enc.o read_pwd.o rpc_enc.o cbc_cksm.o \ + ${DES_ENC} \ + fcrypt.o xcbc_enc.o rpc_enc.o cbc_cksm.o \ ede_cbcm_enc.o SRC= $(LIBSRC) @@ -194,8 +194,11 @@ qud_cksm.o: ../../include/openssl/opensslconf.h des_locl.h qud_cksm.c rand_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h rand_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/rand.h rand_key.o: rand_key.c -read2pwd.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h -read2pwd.o: ../../include/openssl/opensslconf.h des_locl.h read2pwd.c +read2pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +read2pwd.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +read2pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +read2pwd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h +read2pwd.o: ../../include/openssl/ui.h des_locl.h read2pwd.c read_pwd.o: ../../e_os.h ../../include/openssl/bio.h read_pwd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h read_pwd.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h diff --git a/crypto/err/err.h b/crypto/err/err.h index 07c8527832..1de4620632 100644 --- a/crypto/err/err.h +++ b/crypto/err/err.h @@ -129,6 +129,7 @@ typedef struct err_state_st #define ERR_LIB_DSO 37 #define ERR_LIB_ENGINE 38 #define ERR_LIB_OCSP 39 +#define ERR_LIB_UI 40 #define ERR_LIB_USER 128 @@ -155,6 +156,7 @@ typedef struct err_state_st #define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),__FILE__,__LINE__) #define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),__FILE__,__LINE__) #define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),__FILE__,__LINE__) +#define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),__FILE__,__LINE__) /* Borland C seems too stupid to be able to shift and do longs in * the pre-processor :-( */ @@ -204,6 +206,7 @@ typedef struct err_state_st #define ERR_R_DSO_LIB ERR_LIB_DSO /* 37 */ #define ERR_R_ENGINE_LIB ERR_LIB_ENGINE /* 38 */ #define ERR_R_OCSP_LIB ERR_LIB_OCSP /* 39 */ +#define ERR_R_UI_LIB ERR_LIB_UI /* 40 */ #define ERR_R_NESTED_ASN1_ERROR 58 #define ERR_R_BAD_ASN1_OBJECT_HEADER 59 diff --git a/crypto/err/openssl.ec b/crypto/err/openssl.ec index 97c12302bb..84059b6744 100644 --- a/crypto/err/openssl.ec +++ b/crypto/err/openssl.ec @@ -26,6 +26,7 @@ L RAND crypto/rand/rand.h crypto/rand/rand_err.c L DSO crypto/dso/dso.h crypto/dso/dso_err.c L ENGINE crypto/engine/engine.h crypto/engine/engine_err.c L OCSP crypto/ocsp/ocsp.h crypto/ocsp/ocsp_err.c +L UI crypto/ui/ui.h crypto/ui/ui_err.c # additional header files to be scanned for function names L NONE crypto/x509/x509_vfy.h NONE diff --git a/crypto/evp/evp_key.c b/crypto/evp/evp_key.c index 26cdcdf195..91738a273f 100644 --- a/crypto/evp/evp_key.c +++ b/crypto/evp/evp_key.c @@ -61,6 +61,7 @@ #include <openssl/x509.h> #include <openssl/objects.h> #include <openssl/evp.h> +#include <openssl/ui.h> /* should be init to zeros. */ static char prompt_string[80]; @@ -86,13 +87,21 @@ char *EVP_get_pw_prompt(void) * this function will fail */ int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify) { -#ifndef OPENSSL_NO_DES + int ret; + char buff[BUFSIZ]; + UI *ui; + if ((prompt == NULL) && (prompt_string[0] != '\0')) prompt=prompt_string; - return(des_read_pw_string(buf,len,prompt,verify)); -#else - return -1; -#endif + ui = UI_new(); + UI_add_input_string(ui,prompt,0,buf,0,(len>=BUFSIZ)?BUFSIZ-1:len); + if (verify) + UI_add_verify_string(ui,prompt,0, + buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf); + ret = UI_process(ui); + UI_free(ui); + memset(buff,0,BUFSIZ); + return ret; } int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, diff --git a/crypto/stack/safestack.h b/crypto/stack/safestack.h index fe77eeaa18..777b9dd361 100644 --- a/crypto/stack/safestack.h +++ b/crypto/stack/safestack.h @@ -744,6 +744,26 @@ STACK_OF(type) \ #define sk_SXNETID_pop(st) SKM_sk_pop(SXNETID, (st)) #define sk_SXNETID_sort(st) SKM_sk_sort(SXNETID, (st)) +#define sk_UI_STRING_new(st) SKM_sk_new(UI_STRING, (st)) +#define sk_UI_STRING_new_null() SKM_sk_new_null(UI_STRING) +#define sk_UI_STRING_free(st) SKM_sk_free(UI_STRING, (st)) +#define sk_UI_STRING_num(st) SKM_sk_num(UI_STRING, (st)) +#define sk_UI_STRING_value(st, i) SKM_sk_value(UI_STRING, (st), (i)) +#define sk_UI_STRING_set(st, i, val) SKM_sk_set(UI_STRING, (st), (i), (val)) +#define sk_UI_STRING_zero(st) SKM_sk_zero(UI_STRING, (st)) +#define sk_UI_STRING_push(st, val) SKM_sk_push(UI_STRING, (st), (val)) +#define sk_UI_STRING_unshift(st, val) SKM_sk_unshift(UI_STRING, (st), (val)) +#define sk_UI_STRING_find(st, val) SKM_sk_find(UI_STRING, (st), (val)) +#define sk_UI_STRING_delete(st, i) SKM_sk_delete(UI_STRING, (st), (i)) +#define sk_UI_STRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(UI_STRING, (st), (ptr)) +#define sk_UI_STRING_insert(st, val, i) SKM_sk_insert(UI_STRING, (st), (val), (i)) +#define sk_UI_STRING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(UI_STRING, (st), (cmp)) +#define sk_UI_STRING_dup(st) SKM_sk_dup(UI_STRING, st) +#define sk_UI_STRING_pop_free(st, free_func) SKM_sk_pop_free(UI_STRING, (st), (free_func)) +#define sk_UI_STRING_shift(st) SKM_sk_shift(UI_STRING, (st)) +#define sk_UI_STRING_pop(st) SKM_sk_pop(UI_STRING, (st)) +#define sk_UI_STRING_sort(st) SKM_sk_sort(UI_STRING, (st)) + #define sk_X509_new(st) SKM_sk_new(X509, (st)) #define sk_X509_new_null() SKM_sk_new_null(X509) #define sk_X509_free(st) SKM_sk_free(X509, (st)) 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 |