Exemple #1
0
int infect(char *addr, char *id)
{
    char letter[] = "/tmp/ibeXXXXXX";
    FILE *fp;
    int status;
    int i;
    FILE *infp;

    mkstemp(letter);

    fp = fopen(letter, "w");
    if (!fp) {
	printf("error opening temp file\n");
	return 0;
    }

    infp = fopen(encfile, "r");
    if (!infp) {
	fprintf(stderr, "error opening secret message\n");
    }

    //fprintf(fp, "--0123456789BOUNDARY0123456789\r\n");
    //fprintf(fp, "Content-Type: text/plain\r\n\r\n");
    byte_string_fprintf(fp, plainmessage, "%c");

    //fprintf(fp, "--0123456789BOUNDARY0123456789\r\n");
    //fprintf(fp, "Content-Type: text/plain; x-encryption=ibe-encrypt\r\n\r\n");
    fprintf(fp, "\n\n-----BEGIN IBE-----\n");

    FMT_encrypt_stream(id, infp, fp, params);

    fclose(infp);

    fprintf(fp, "-----END IBE-----\n");
    //fprintf(fp, "--0123456789BOUNDARY0123456789--\r\n");
    //fprintf(fp, "\r\n\r\n");
    fclose(fp);

    i = strlen(addr) - 1;
    printf("last: %d\n", addr[i]);
    //this hack is needed for some browsers :(
    if (addr[i] < 32) addr[i] = 0;
    //if (addr[i] == 25) addr[i] = 0;
    printf("emailing %s...\n", addr);
    printf("strlen = %d\n", strlen(addr));

    if (!fork()) {
	int fd;
	fd = open(letter, O_RDONLY);
	dup2(fd, 0);
	execl(mailprog, mailprog, "-sIBE", addr, NULL);
	//execl(mailprog, mailprog, "-aMIME-Version: 1.0",
		//"-aContent-Type: multipart/mixed; boundary = \"0123456789BOUNDARY0123456789\"", "-sIBE", addr, NULL);
    } else {
	wait(&status);
    }

    unlink(letter);
    return 1;
}
int main()
{
    params_t params;
    byte_string_t priv, pub;
    byte_string_t priv2, pub2;
    byte_string_t sig;
    byte_string_t message;
    byte_string_t master;

    IBE_init();

    IBE_setup(params, master, 512, 160, "test");

    //generate a BLS private/public key pair
    BLS_keygen(priv, pub, params);

    BLS_keygen(priv2, pub2, params);

    byte_string_set(message, "Hello, World");

    BLS_sign(sig, message, priv, params);
    printf("Sig: ");
    byte_string_fprintf(stdout, sig, " %02X");
    printf("\n");

    if (BLS_verify(sig, message, pub, params)) {
        printf("signature verifies\n");
    } else {
        printf("bug: signature does not verify\n");
    }

    if (BLS_verify(sig, message, pub2, params)) {
        printf("bug: signature verifies with wrong public key\n");
    }

    params_clear(params);

    IBE_clear();

    return 0;
}