Setting HWCryptoHook_InitInfo structure for HWCRHK/CHIL library

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting HWCryptoHook_InitInfo structure for HWCRHK/CHIL library

Bartek Palak
Hi *,

I have defined HWCryptoHook_InitInfo structure (in order to use my own getphystoken and getpassphrase functions)
and set it using HWCRyptoHook_Init function (see listing below)
.
Unfortunately  function ENGINE_by_id("chil") calls internally HWCRHK get_context function that sets default structure;

How to force HWCRHK library to use "my" getphystoken and getpassphrase functions?

regards
Bartek


 /*======================================================================================================*/
#include <openssl/ui.h>
#include <openssl/evp.h>
#include <openssl/engine.h>
#include <openssl/rsa.h>

#include <string.h>
#include <iostream>
#include <cstdlib>

#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>

extern "C"
{
#include "../crypto/engine/vendor_defns/hwcryptohook.h"

int my_hwcrhk_get_pass(const char *prompt_info,
                     int *len_io, char *buf,
                     HWCryptoHook_PassphraseContext *ppctx,
                     HWCryptoHook_CallerContext *cactx)
{
   return 0;
}

 int my_hwcrhk_insert_card(const char *prompt_info,
                         const char *wrong_info,
                         HWCryptoHook_PassphraseContext *ppctx,
                         HWCryptoHook_CallerContext *cactx)
{
   return 0;
}

 void my_hwcrhk_log_message(void *logstr, const char *message)
{
}


static HWCryptoHook_InitInfo my_hwcrhk_globals = {
   HWCryptoHook_InitFlags_SimpleForkCheck,   /* Flags */
   NULL, // &logstream,    /* logstream */
   sizeof(BN_ULONG), /* limbsize */
   0,       /* mslimb first: false for BNs */
   -1,         /* msbyte first: use native */
   0,       /* Max mutexes, 0 = no small limit */
   0,       /* Max simultaneous, 0 = default */

   /* The next few are mutex stuff: we write wrapper functions
   around the OS mutex functions.  We initialise them to 0
   here, and change that to actual function pointers in hwcrhk_init()
   if dynamic locks are supported (that is, if the application
   programmer has made sure of setting up callbacks bafore starting
   this engine) *and* if disable_mutex_callbacks hasn't been set by
   a call to ENGINE_ctrl(ENGINE_CTRL_CHIL_NO_LOCKING). */
   1024, //sizeof(HWCryptoHook_Mutex),
   0,
   0,
   0,
   0,

   /* The next few are condvar stuff: we write wrapper functions
   round the OS functions.  Currently not implemented and not
   and absolute necessity even in threaded programs, therefore
   0'ed.  Will hopefully be implemented some day, since it
   enhances the efficiency of HWCryptoHook.  */
   0, /* sizeof(HWCryptoHook_CondVar), */
   0, /* hwcrhk_cv_init, */
   0, /* hwcrhk_cv_wait, */
   0, /* hwcrhk_cv_signal, */
   0, /* hwcrhk_cv_broadcast, */
   0, /* hwcrhk_cv_destroy, */

   my_hwcrhk_get_pass,  /* pass phrase */
   my_hwcrhk_insert_card,  /* insert a card */
   my_hwcrhk_log_message   /* Log message */
};
}
void
      app_init2()
{
   OpenSSL_add_all_algorithms();
   ERR_load_crypto_strings();
   ENGINE_load_builtin_engines();

}

/* hwcryptohook.h has some typedefs that turn
   struct HWCryptoHook_CallerContextValue
   into HWCryptoHook_CallerContext */

typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);

struct HWCryptoHook_CallerContextValue
{
   pem_password_cb *password_callback; /* Deprecated!  Only present for
   backward compatibility! */
   UI_METHOD *ui_method;
   void *callback_data;
};



static HWCryptoHook_CallerContext password_context = { NULL, NULL, NULL };

int main(int argc, char *argv[])
{
   char tempbuf[1024];
   HWCryptoHook_ErrMsgBuf rmsg;
   HWCryptoHook_CallerContext *cac;

   rmsg.buf = tempbuf;
   rmsg.size = sizeof(tempbuf);

   app_init2();

   HWCryptoHook_ContextHandle hac = HWCryptoHook_Init(&my_hwcrhk_globals, sizeof(my_hwcrhk_globals), &rmsg,
         &password_context);


   ENGINE* e = ENGINE_by_id("chil");
  return 0;
}

/*======================================================================================================*/
Reply | Threaded
Open this post in threaded view
|

Re: Setting HWCryptoHook_InitInfo structure for HWCRHK/CHIL library

Richard Levitte - VMS Whacker
In message <[hidden email]> on Mon, 11 Jul 2005 10:35:32 +0200, Bartek Palak <[hidden email]> said:

bartek> How to force HWCRHK library to use "my" getphystoken and
bartek> getpassphrase functions?

Sounds like you're about to write your own engine...

Cheers,
Richard

-----
Please consider sponsoring my work on free software.
See http://www.free.lp.se/sponsoring.html for details.

--
Richard Levitte                         [hidden email]
                                        http://richard.levitte.org/

"When I became a man I put away childish things, including
 the fear of childishness and the desire to be very grown up."
                                                -- C.S. Lewis
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]