CSslClientSocket

作者在 2006-12-03 00:51:00 发布以下内容
int   CSslClientSocket::Rand(const   char   *file,int   dont_warn,char   *   outMsg)  
  {  
  int   consider_randfile   =   (file   ==   NULL);  
  char   buffer[200];  
   
  #ifdef   WINDOWS  
  // BIO_flush(bio_e);  
  RAND_screen();  
  #endif  
   
  if   (file   ==   NULL)  
  file   =   RAND_file_name(buffer,   sizeof   buffer);  
  else   if   (RAND_egd(file)   >   0)  
  {  
  /*   we   try   if   the   given   filename   is   an   EGD   socket.  
  if   it   is,   we   don't   write   anything   back   to   the   file.   */  
  return   1;  
  }  
  if   (file   ==   NULL   ||   !RAND_load_file(file,   -1))  
  {  
  if   (RAND_status()   ==   0   &&   !dont_warn)  
  {  
  sprintf(outMsg,"unable   to   load   'random   state'\n");  
  sprintf(outMsg,"This   means   that   the   random   number   generator   has   not   been   seeded\n");  
  if   (consider_randfile)   /*   explanation   does   not   apply   when   a   file   is   explicitly   named   */  
  {  
  sprintf(outMsg,"Consider   setting   the   RANDFILE   environment   variable   to   point   at   a   file   that\n");  
  sprintf(outMsg,"'random'   data   can   be   kept   in   (the   file   will   be   overwritten).\n");  
  }  
  }  
  return   0;  
  }  
  return   1;  
  }  
   
  void   CSslClientSocket::GetPeerInfo(SSL   *   ssl,stuSERVERINFO   *   stu)  
  {  
   
  X509   *peer=NULL;  
  char   *p;  
  static   char   *space="                                 ";  
  char   buf[BUFSIZ];//512  
  STACK_OF(X509)   *sk;  
  STACK_OF(X509_NAME)   *sk2;  
  SSL_CIPHER   *c;  
  X509_NAME   *xn;  
  int   j,i;  
  BIO   *bio=BIO_new(BIO_s_mem());  
  char   bufout[1024]={0};  
   
  int   got_a_chain   =   0;  
   
  sk=SSL_get_peer_cert_chain(ssl);//returns   a   pointer   to   STACKOF(X509)   certificates  
  if   (sk   !=   NULL)  
  {  
  got_a_chain   =   1;   /*   we   don't   have   it   for   SSL2   (yet)   */  
   
  for   (i=0;   i<sk_X509_num(sk);   i++)  
  {  
  X509_NAME_oneline(X509_get_subject_name(sk_X509_value(sk,i)),  
  stu->peerChain.sub,BUFSIZ);  
  X509_NAME_oneline(X509_get_issuer_name(sk_X509_value(sk,i)),  
  stu->peerChain.iss,BUFSIZ);  
  // PEM_write_bio_X509(bio,sk_X509_value(sk,i));  
  // BIO_read(bio,bufout,4*BUFSIZ);  
  }  
 
(编程)Work | 阅读 2166 次
文章评论,共0条
游客请输入验证码
浏览317434次