Thank you for your help, but it doesn't work at all.
I need to sign a "char * msg" to obtain a "char * (or similar)"
for sending a signed mail. 
I'm using for it Dr Stephen N Henson (you're great) sign program, which I call
in "sign(x509,pkey,data,p7);".
Afterwards I write the p7 object with "PEM_write_PKCS7(stdout,p7);" and it 
works ok. But just when I try to cast it to unsigned char * I'm getting a
Segmentation Fault.

Thanks Patrik and Dr. Henson, in advance.



void sign_pkcs7(char *msg,unsigned char *der){
  X509 *x509;
  EVP_PKEY *pkey;
  PKCS7 *p7;

  BIO *in;
  BIO *data;
  int i;
  unsigned char *msg_aux,*buf;

  if (inf) printf("Funcion que construye la firma PKCS7\n");
  data=BIO_new(BIO_s_bio());

  if ((in=BIO_new_file("server.pem","r")) == NULL) goto err;
  if ((x509=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL) goto err;
  BIO_reset(in);
  if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL)) == NULL) goto err;
  BIO_free(in);
  BIO_set_ex_data(data,sizeof(msg),msg); 
  p7=PKCS7_new(); 

  sign(x509,pkey,data,p7);
    
  printf("Now I will print the p7 object\n");
  PEM_write_PKCS7(stdout,p7);
  
  /*Here I've got the problem*/
 
  /*printf("mark1\n");*/  /*I know if there is a segmentation fault, it won't 
  show the marks... but...*/
  i=i2d_PKCS7(p7,NULL);
  /*printf("mark2\n");*/
  buf=malloc(i);
  /*printf("mark3\n");*/
  msg_aux=buf;
  /*printf("mark4\n");*/
  i=i2d_PKCS7(p7,&msg_aux);
  
  printf("Printting PKCS7\n%s\n",msg_aux);
  strcpy(der,msg_aux);
  
  PKCS7_free(p7); 
      
  goto ok;
  
 err: 
  ERR_load_crypto_strings();
  ERR_print_errors_fp(stderr);
  exit(-1);
 ok:
}

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to