POSSIBLE FIX! Re: Windows and hidden service...

Hideki Saito hsaito at comcast.net
Thu Sep 2 10:00:22 UTC 2004


Well, I didn't really like to just complain, and do nothing about it.
Especially I think Tor is cool program. I really wanted to help out.

Well, I've came up with a bit of workaround in crypto.c that may work
out.

It seems like working fine, and there's no crash on me anymore!
(I know this may be quite messy code...well, this is what happens
slapping together code at 2:00AM -- feel free to clean up) :-)

(Just pasting a code...)

--- begin code ---

/** Read a PEM-encoded private key from <b>src</b> into <b>env</b>.
 */
static int crypto_pk_read_private_key_from_file(crypto_pk_env_t *env,
                                                FILE *src)
{
#ifdef MS_WINDOWS
/*	Workaround for Windows (By Hideki Saito)
	There's library related problem that the program crashes when attempted
	calling PEM_read_RSAPrivateKey.

	This is quite bitter workaround, basically implementing loading part on my own
	and using BIO instead of FP.

	This is something I slapped together, and is still crude.
	Something may be leaking...
*/
	
	BUF_MEM *buf;
  BIO *b;
  char *line;

  tor_assert(env && src);

  b = BIO_new(BIO_s_mem()); /* Create a memory BIO */

  buf = malloc(sizeof(BUF_MEM));
  buf->data = malloc(1024);
  
  line = malloc(100);

  fgets(line,100,src);
  strcpy(buf->data,line);

  while(fgets(line,100,src))
  {
	  strcat(buf->data,line);
  }
  free(line);

  buf->length = strlen(buf->data);
	buf->max = strlen(buf->data);

	BIO_puts(b,buf->data);

  if (env->key)
    RSA_free(env->key);

  env->key = PEM_read_bio_RSAPrivateKey(b,NULL,NULL,NULL);
 
#else
    tor_assert(env && src);

  if (env->key)
    RSA_free(env->key);
  env->key = PEM_read_RSAPrivateKey(src, NULL, NULL, NULL);
#endif

  if (!env->key) {
    crypto_log_errors(LOG_WARN, "reading private key from file");
    return -1;
  }
  return 0;
}

-- end code ---

I'll try to run this for while to see if there are any apparant problems.


-- 
Hideki Saito mailto:hsaito at comcast.net



More information about the tor-dev mailing list