commit: | 6de360bac2929e44bd7fa14f6ada2e7f0ec0f163 |
author: | mrmekon |
committer: | mrmekon |
date: | Mon Nov 14 18:07:27 2011 -0500 |
parents: | 147293bc581373797ab2082b7aff0b49d126d488 |
diff --git a/Makefile.am b/Makefile.am line changes: +5/-4 index 4de7341..9d19c95 --- a/Makefile.am +++ b/Makefile.am
@@ -12,10 +12,11 @@ libsimplepgp_la_SOURCES = \ src/mpi.c installcheck-local: - make -C examples/01_decrypt - pushd "`pwd`/examples/01_decrypt" ;\ - ./decrypt ;\ - popd + @make -C examples/01_decrypt + @make -C examples/02_decrypt_rsa + @pushd "`pwd`/examples/01_decrypt";./decrypt;popd + @read -p "Press return to run next test..." + @pushd "`pwd`/examples/02_decrypt_rsa";./decrypt_rsa;popd clean-local: -rm -rf build
diff --git a/examples/01_decrypt/decrypt.c b/examples/01_decrypt/decrypt.c line changes: +6/-0 index 407622c..afd4e69 --- a/examples/01_decrypt/decrypt.c +++ b/examples/01_decrypt/decrypt.c
@@ -2,6 +2,7 @@ #include <fcntl.h> #include <string.h> #include <stdint.h> +#include <unistd.h> #include <simplepgp.h>
@@ -67,6 +68,11 @@ int main(int argc, char **argv) { } printf("Filename length: %u\n", filenamelen); printf("Data length: %u\n", datalen); + write(STDOUT_FILENO, filename, filenamelen); + printf(": "); + fflush(stdout); + write(STDOUT_FILENO, data, datalen); + printf("\n"); spgp_close();
diff --git a/examples/02_decrypt_rsa/Makefile b/examples/02_decrypt_rsa/Makefile line changes: +9/-0 index 0000000..7f3f35e --- /dev/null +++ b/examples/02_decrypt_rsa/Makefile
@@ -0,0 +1,9 @@ +LDFLAGS=`pkg-config --libs simplepgp` +CFLAGS=`pkg-config --cflags simplepgp` + +EXEC=decrypt_rsa +OBJS=decrypt_rsa.c + +default: $(EXEC) + +all: default \ No newline at end of file
diff --git a/examples/02_decrypt_rsa/ciphertext.pgp b/examples/02_decrypt_rsa/ciphertext.pgp line changes: +0/-0 index 0000000..3ae0d19 --- /dev/null +++ b/examples/02_decrypt_rsa/ciphertext.pgp
diff --git a/examples/02_decrypt_rsa/decrypt_rsa.c b/examples/02_decrypt_rsa/decrypt_rsa.c line changes: +81/-0 index 0000000..0a2d7c4 --- /dev/null +++ b/examples/02_decrypt_rsa/decrypt_rsa.c
@@ -0,0 +1,81 @@ +#include <stdio.h> +#include <fcntl.h> +#include <string.h> +#include <stdint.h> +#include <unistd.h> + +#include <simplepgp.h> + +#define SECKEY_BUF 4096 +#define CTEXT_BUF 1024 + +#define KEY_PASS "test" + +int main(int argc, char **argv) { + char seckey[SECKEY_BUF]; + char ctext[CTEXT_BUF]; + int fd; + int seckey_len, ctext_len; + spgp_packet_t *pkt; + char *data, *filename; + uint32_t datalen, filenamelen; + uint32_t i; + + printf("simplepgp decrypt example.\n"); + + fd = open("test2_sec.pgp", O_RDONLY); + if (fd < 0) { perror("seckey open"); return 1; } + if ((seckey_len = read(fd, seckey, SECKEY_BUF)) < 0) { + perror("seckey read"); return 1; + } + close(fd); + + fd = open("ciphertext.pgp", O_RDONLY); + if (fd < 0) { perror("cipher open"); return 1; } + if ((ctext_len = read(fd, ctext, CTEXT_BUF)) < 0) { + perror("cipher read"); return 1; + } + close(fd); + + if (spgp_init() != 0) { + fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err())); + return 1; + } + + spgp_debug_log_set(1); + + pkt = spgp_decode_message(seckey, seckey_len); + if (NULL == pkt) { + fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err())); + return 1; + } + + if (spgp_decrypt_all_secret_keys(pkt, KEY_PASS, strlen(KEY_PASS)) != 0) { + fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err())); + return 1; + } + + pkt = spgp_decode_message(ctext, ctext_len); + if (NULL == pkt) { + fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err())); + return 1; + } + + data = spgp_get_literal_data(pkt, &datalen, + &filename, &filenamelen); + if (NULL == data) { + fprintf(stderr, "error: %s\n", spgp_err_str(spgp_err())); + return 1; + } + printf("Filename length: %u\n", filenamelen); + printf("Data length: %u\n", datalen); + write(STDOUT_FILENO, filename, filenamelen); + printf(": "); + fflush(stdout); + write(STDOUT_FILENO, data, datalen); + printf("\n"); + + spgp_close(); + + return 0; +}
diff --git a/examples/02_decrypt_rsa/test2_sec.pgp b/examples/02_decrypt_rsa/test2_sec.pgp line changes: +0/-0 index 0000000..a9ce3cf --- /dev/null +++ b/examples/02_decrypt_rsa/test2_sec.pgp