Hello all,

during development of application that uses ENGINE and UI I found out 
that UI provided by UI_OpenSSL() is almost perfect for me except for the 
"prompt_constructor". After short research I found prototype for 
"UI_construct_prompt" function in <openssl/ui.h> with following 
description "..if the ui_method doesn't contain a pointer to a 
user-defined prompt constructor, a default string is built.." So I wrote 
my own implementation of "prompt constructor" and then I found out that 
there is no easy way to set user-defined prompt constructor in the 
"ui_method_st" structure. This structure is not declared in public 
headers so 3rd party applications cannot access its members directly.

Definition of ui_method_st is:

struct ui_method_st
{
   char *name;
   int (*ui_open_session)(UI *ui);
   int (*ui_write_string)(UI *ui, UI_STRING *uis);
   int (*ui_flush)(UI *ui);
   int (*ui_read_string)(UI *ui, UI_STRING *uis);
   int (*ui_close_session)(UI *ui);
   char *(*ui_construct_prompt)(UI *ui, const char *object_desc, const 
char *object_name);
};

There are getter and setter functions available for all members except 
of "ui_construct_prompt" so I wrote them to solve my problem.

I am attaching patch for openssl-0.9.8m that adds setter and getter for 
"ui_construct_prompt". However I am not sure if this can be added to 
0.9.8 branch so please let me know if you need me to rewrite this patch 
for other version or branch.

-- 
Jaroslav Imrich

Disig, a.s.
Zahradnicka 151, 821 08 Bratislava 2

[email protected]
www.disig.sk



__________ Information from ESET NOD32 Antivirus, version of virus signature 
database 4928 (20100309) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


diff -ur openssl-0.9.8m/crypto/ui/ui.h openssl-0.9.8m-modified/crypto/ui/ui.h
--- openssl-0.9.8m/crypto/ui/ui.h       2005-03-31 11:26:35.000000000 +0200
+++ openssl-0.9.8m-modified/crypto/ui/ui.h      2010-03-09 09:49:37.000000000 
+0100
@@ -310,11 +310,13 @@
 int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui));
 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_set_prompt_constructor(UI_METHOD *method, char 
*(*prompt_constructor)(UI* ui, const char* object_desc, const char* 
object_name));
 int (*UI_method_get_opener(UI_METHOD *method))(UI*);
 int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*);
 int (*UI_method_get_flusher(UI_METHOD *method))(UI*);
 int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*);
 int (*UI_method_get_closer(UI_METHOD *method))(UI*);
+char* (*UI_method_get_prompt_constructor(UI_METHOD *method))(UI*, const char*, 
const char*);
 
 /* The following functions are helpers for method writers to access relevant
    data from a UI_STRING. */
diff -ur openssl-0.9.8m/crypto/ui/ui_lib.c 
openssl-0.9.8m-modified/crypto/ui/ui_lib.c
--- openssl-0.9.8m/crypto/ui/ui_lib.c   2009-02-16 16:17:26.000000000 +0100
+++ openssl-0.9.8m-modified/crypto/ui/ui_lib.c  2010-03-09 10:54:44.000000000 
+0100
@@ -693,6 +693,17 @@
                return -1;
        }
 
+int UI_method_set_prompt_constructor(UI_METHOD *method, char 
*(*prompt_constructor)(UI* ui, const char* object_desc, const char* 
object_name))
+       {
+       if (method)
+               {
+               method->ui_construct_prompt = prompt_constructor;
+               return 0;
+               }
+       else
+               return -1;
+       }
+
 int (*UI_method_get_opener(UI_METHOD *method))(UI*)
        {
        if (method)
@@ -733,6 +744,14 @@
                return NULL;
        }
 
+char* (*UI_method_get_prompt_constructor(UI_METHOD *method))(UI*, const char*, 
const char*)
+       {
+       if (method)
+               return method->ui_construct_prompt;
+       else
+               return NULL;
+       }
+
 enum UI_string_types UI_get_string_type(UI_STRING *uis)
        {
        if (!uis)
diff -ur openssl-0.9.8m/include/openssl/ui.h 
openssl-0.9.8m-modified/include/openssl/ui.h
--- openssl-0.9.8m/include/openssl/ui.h 2005-03-31 11:26:35.000000000 +0200
+++ openssl-0.9.8m-modified/include/openssl/ui.h        2010-03-09 
09:49:37.000000000 +0100
@@ -310,11 +310,13 @@
 int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui));
 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_set_prompt_constructor(UI_METHOD *method, char 
*(*prompt_constructor)(UI* ui, const char* object_desc, const char* 
object_name));
 int (*UI_method_get_opener(UI_METHOD *method))(UI*);
 int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*);
 int (*UI_method_get_flusher(UI_METHOD *method))(UI*);
 int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*);
 int (*UI_method_get_closer(UI_METHOD *method))(UI*);
+char* (*UI_method_get_prompt_constructor(UI_METHOD *method))(UI*, const char*, 
const char*);
 
 /* The following functions are helpers for method writers to access relevant
    data from a UI_STRING. */
Only in openssl-0.9.8m-modified/: Makefile.bak
Only in openssl-0.9.8m-modified/test: newkey.pem
Only in openssl-0.9.8m-modified/test: testkey.pem
Only in openssl-0.9.8m-modified/test: testreq.pem

Reply via email to