1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci#ifndef OSSL_CRYPTO_UI_LOCAL_H 11e1051a39Sopenharmony_ci# define OSSL_CRYPTO_UI_LOCAL_H 12e1051a39Sopenharmony_ci 13e1051a39Sopenharmony_ci# include <openssl/ui.h> 14e1051a39Sopenharmony_ci# include <openssl/crypto.h> 15e1051a39Sopenharmony_ci 16e1051a39Sopenharmony_ci# ifdef _ 17e1051a39Sopenharmony_ci# undef _ 18e1051a39Sopenharmony_ci# endif 19e1051a39Sopenharmony_ci 20e1051a39Sopenharmony_cistruct ui_method_st { 21e1051a39Sopenharmony_ci char *name; 22e1051a39Sopenharmony_ci /* 23e1051a39Sopenharmony_ci * All the functions return 1 or non-NULL for success and 0 or NULL for 24e1051a39Sopenharmony_ci * failure 25e1051a39Sopenharmony_ci */ 26e1051a39Sopenharmony_ci /* 27e1051a39Sopenharmony_ci * Open whatever channel for this, be it the console, an X window or 28e1051a39Sopenharmony_ci * whatever. This function should use the ex_data structure to save 29e1051a39Sopenharmony_ci * intermediate data. 30e1051a39Sopenharmony_ci */ 31e1051a39Sopenharmony_ci int (*ui_open_session) (UI *ui); 32e1051a39Sopenharmony_ci int (*ui_write_string) (UI *ui, UI_STRING *uis); 33e1051a39Sopenharmony_ci /* 34e1051a39Sopenharmony_ci * Flush the output. If a GUI dialog box is used, this function can be 35e1051a39Sopenharmony_ci * used to actually display it. 36e1051a39Sopenharmony_ci */ 37e1051a39Sopenharmony_ci int (*ui_flush) (UI *ui); 38e1051a39Sopenharmony_ci int (*ui_read_string) (UI *ui, UI_STRING *uis); 39e1051a39Sopenharmony_ci int (*ui_close_session) (UI *ui); 40e1051a39Sopenharmony_ci /* 41e1051a39Sopenharmony_ci * Duplicate the ui_data that often comes alongside a ui_method. This 42e1051a39Sopenharmony_ci * allows some backends to save away UI information for later use. 43e1051a39Sopenharmony_ci */ 44e1051a39Sopenharmony_ci void *(*ui_duplicate_data) (UI *ui, void *ui_data); 45e1051a39Sopenharmony_ci void (*ui_destroy_data) (UI *ui, void *ui_data); 46e1051a39Sopenharmony_ci /* 47e1051a39Sopenharmony_ci * Construct a prompt in a user-defined manner. object_desc is a textual 48e1051a39Sopenharmony_ci * short description of the object, for example "pass phrase", and 49e1051a39Sopenharmony_ci * object_name is the name of the object (might be a card name or a file 50e1051a39Sopenharmony_ci * name. The returned string shall always be allocated on the heap with 51e1051a39Sopenharmony_ci * OPENSSL_malloc(), and need to be free'd with OPENSSL_free(). 52e1051a39Sopenharmony_ci */ 53e1051a39Sopenharmony_ci char *(*ui_construct_prompt) (UI *ui, const char *object_desc, 54e1051a39Sopenharmony_ci const char *object_name); 55e1051a39Sopenharmony_ci /* 56e1051a39Sopenharmony_ci * UI_METHOD specific application data. 57e1051a39Sopenharmony_ci */ 58e1051a39Sopenharmony_ci CRYPTO_EX_DATA ex_data; 59e1051a39Sopenharmony_ci}; 60e1051a39Sopenharmony_ci 61e1051a39Sopenharmony_cistruct ui_string_st { 62e1051a39Sopenharmony_ci enum UI_string_types type; /* Input */ 63e1051a39Sopenharmony_ci const char *out_string; /* Input */ 64e1051a39Sopenharmony_ci int input_flags; /* Flags from the user */ 65e1051a39Sopenharmony_ci /* 66e1051a39Sopenharmony_ci * The following parameters are completely irrelevant for UIT_INFO, and 67e1051a39Sopenharmony_ci * can therefore be set to 0 or NULL 68e1051a39Sopenharmony_ci */ 69e1051a39Sopenharmony_ci char *result_buf; /* Input and Output: If not NULL, 70e1051a39Sopenharmony_ci * user-defined with size in result_maxsize. 71e1051a39Sopenharmony_ci * Otherwise, it may be allocated by the UI 72e1051a39Sopenharmony_ci * routine, meaning result_minsize is going 73e1051a39Sopenharmony_ci * to be overwritten. */ 74e1051a39Sopenharmony_ci size_t result_len; 75e1051a39Sopenharmony_ci union { 76e1051a39Sopenharmony_ci struct { 77e1051a39Sopenharmony_ci int result_minsize; /* Input: minimum required size of the 78e1051a39Sopenharmony_ci * result. */ 79e1051a39Sopenharmony_ci int result_maxsize; /* Input: maximum permitted size of the 80e1051a39Sopenharmony_ci * result */ 81e1051a39Sopenharmony_ci const char *test_buf; /* Input: test string to verify against */ 82e1051a39Sopenharmony_ci } string_data; 83e1051a39Sopenharmony_ci struct { 84e1051a39Sopenharmony_ci const char *action_desc; /* Input */ 85e1051a39Sopenharmony_ci const char *ok_chars; /* Input */ 86e1051a39Sopenharmony_ci const char *cancel_chars; /* Input */ 87e1051a39Sopenharmony_ci } boolean_data; 88e1051a39Sopenharmony_ci } _; 89e1051a39Sopenharmony_ci 90e1051a39Sopenharmony_ci# define OUT_STRING_FREEABLE 0x01 91e1051a39Sopenharmony_ci int flags; /* flags for internal use */ 92e1051a39Sopenharmony_ci}; 93e1051a39Sopenharmony_ci 94e1051a39Sopenharmony_cistruct ui_st { 95e1051a39Sopenharmony_ci const UI_METHOD *meth; 96e1051a39Sopenharmony_ci STACK_OF(UI_STRING) *strings; /* We might want to prompt for more than 97e1051a39Sopenharmony_ci * one thing at a time, and with different 98e1051a39Sopenharmony_ci * echoing status. */ 99e1051a39Sopenharmony_ci void *user_data; 100e1051a39Sopenharmony_ci CRYPTO_EX_DATA ex_data; 101e1051a39Sopenharmony_ci# define UI_FLAG_REDOABLE 0x0001 102e1051a39Sopenharmony_ci# define UI_FLAG_DUPL_DATA 0x0002 /* user_data was duplicated */ 103e1051a39Sopenharmony_ci# define UI_FLAG_PRINT_ERRORS 0x0100 104e1051a39Sopenharmony_ci int flags; 105e1051a39Sopenharmony_ci 106e1051a39Sopenharmony_ci CRYPTO_RWLOCK *lock; 107e1051a39Sopenharmony_ci}; 108e1051a39Sopenharmony_ci 109e1051a39Sopenharmony_ci#endif 110