-1

im trying to create a peer to peer network that is controlled by a peer with the master private key, part of that is approving peers to connect

the following code is suppose to take a public key, sign that and send it to the peer so that it can check if its valid and in its approved peer list

gcry_sexp_t signature, keydata;
char *blob = malloc(size + 64);

sprintf(blob, "(data\n (flags pkcs1)\n (hash sha1 #%.*s#))\n", (int)size, buf);
printf("%s\n", blob);
free(buf);

gcry_sexp_sscan(&keydata, &size, blob, strlen(blob));
printf("offset %d\n", (int)size);

size = gcry_sexp_sprint(keydata, GCRYSEXP_FMT_ADVANCED, NULL, 0);
printf("size %d\n", (int)size);

buf = gcry_xmalloc(size);
gcry_sexp_sprint(keydata, GCRYSEXP_FMT_ADVANCED, buf, size);
printf("keydata: %.*s\n", size, buf);
free(buf);

gcry_pk_sign(&signature, keydata, skey);
size = gcry_sexp_sprint(signature, GCRYSEXP_FMT_ADVANCED, NULL, 0);
buf = gcry_xmalloc(size);
gcry_sexp_sprint(signature, GCRYSEXP_FMT_ADVANCED, buf, size);
//add signature buf to msg and send to peer

But it crashes. Any ideas why?

1 Answers1

0

The printf arguments are around the wrong way. Should be:

printf("keydata: %.*s\n", size, buf);
kaylum
  • 13,833
  • 2
  • 22
  • 31
  • stupid mistake, odd no compiler warning altho the signature is empty – Gabriel Lambert Nov 08 '15 at 22:33
  • Strange. My compiler (gcc 4.8.4) does give a warning: `field precision specifier ‘.*’ expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat=]` – kaylum Nov 08 '15 at 22:38
  • Oh, you've changed the question and made this answer irrelevant (and will confuse future readers). I'm not fussed about the rep points but the correct way to do this is to accept this answer (or not if it didn't help with the original question) and ask a new question. – kaylum Nov 08 '15 at 22:45