diff options
Diffstat (limited to 'demos/smime')
-rw-r--r-- | demos/smime/Makefile | 37 | ||||
-rw-r--r-- | demos/smime/smdec.c | 7 | ||||
-rw-r--r-- | demos/smime/smenc.c | 5 | ||||
-rw-r--r-- | demos/smime/smsign.c | 15 | ||||
-rw-r--r-- | demos/smime/smsign2.c | 11 | ||||
-rw-r--r-- | demos/smime/smver.c | 3 |
6 files changed, 60 insertions, 18 deletions
diff --git a/demos/smime/Makefile b/demos/smime/Makefile new file mode 100644 index 0000000000..449efd627b --- /dev/null +++ b/demos/smime/Makefile @@ -0,0 +1,37 @@ +# +# To run the demos when linked with a shared library (default) ensure that +# libcrypto is on the library path. For example, to run the +# sm_enc demo: +# +# LD_LIBRARY_PATH=../.. ./sms_enc + +TESTS = smenc \ + smdec \ + smsign \ + smsign2 \ + smver + +CFLAGS = -I../../include -g -Wall +LDFLAGS = -L../.. +LDLIBS = -lcrypto + +all: $(TESTS) + +smenc: smenc.o +smdec: smdec.o +smsign: smsign.o +smsign2: smsign2.o +smver: smver.o + +$(TESTS): + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS) + +clean: + $(RM) $(TESTS) *.o + +test: all + @echo "\nS/MIME tests:" + LD_LIBRARY_PATH=../.. ./smenc + LD_LIBRARY_PATH=../.. ./smdec + LD_LIBRARY_PATH=../.. ./smsign2 + LD_LIBRARY_PATH=../.. ./smver diff --git a/demos/smime/smdec.c b/demos/smime/smdec.c index 7cf66f1dcd..f27c353f40 100644 --- a/demos/smime/smdec.c +++ b/demos/smime/smdec.c @@ -31,7 +31,8 @@ int main(int argc, char **argv) rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - BIO_reset(tbio); + if (BIO_reset(tbio) < 0) + goto err; rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); @@ -59,8 +60,9 @@ int main(int argc, char **argv) if (!PKCS7_decrypt(p7, rkey, rcert, out, 0)) goto err; - ret = EXIT_SUCCESS; + printf("Success\n"); + ret = EXIT_SUCCESS; err: if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Signing Data\n"); @@ -74,5 +76,4 @@ int main(int argc, char **argv) BIO_free(tbio); return ret; - } diff --git a/demos/smime/smenc.c b/demos/smime/smenc.c index 3e3f34d1cf..2113e12d1c 100644 --- a/demos/smime/smenc.c +++ b/demos/smime/smenc.c @@ -21,7 +21,6 @@ int main(int argc, char **argv) int ret = EXIT_FAILURE; /* - * On OpenSSL 0.9.9 only: * for streaming set PKCS7_STREAM */ int flags = PKCS7_STREAM; @@ -73,8 +72,9 @@ int main(int argc, char **argv) if (!SMIME_write_PKCS7(out, p7, in, flags)) goto err; - ret = EXIT_SUCCESS; + printf("Success\n"); + ret = EXIT_SUCCESS; err: if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Encrypting Data\n"); @@ -87,5 +87,4 @@ int main(int argc, char **argv) BIO_free(out); BIO_free(tbio); return ret; - } diff --git a/demos/smime/smsign.c b/demos/smime/smsign.c index 4ce671d05c..3e27c931f6 100644 --- a/demos/smime/smsign.c +++ b/demos/smime/smsign.c @@ -21,7 +21,7 @@ int main(int argc, char **argv) int ret = EXIT_FAILURE; /* - * For simple S/MIME signing use PKCS7_DETACHED. On OpenSSL 0.9.9 only: + * For simple S/MIME signing use PKCS7_DETACHED. * for streaming detached set PKCS7_DETACHED|PKCS7_STREAM for streaming * non-detached set PKCS7_STREAM */ @@ -38,7 +38,8 @@ int main(int argc, char **argv) scert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - BIO_reset(tbio); + if (BIO_reset(tbio) < 0) + goto err; skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); @@ -62,15 +63,18 @@ int main(int argc, char **argv) if (!out) goto err; - if (!(flags & PKCS7_STREAM)) - BIO_reset(in); + if (!(flags & PKCS7_STREAM)) { + if (BIO_reset(in) < 0) + goto err; + } /* Write out S/MIME message */ if (!SMIME_write_PKCS7(out, p7, in, flags)) goto err; - ret = EXIT_SUCCESS; + printf("Success\n"); + ret = EXIT_SUCCESS; err: if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Signing Data\n"); @@ -84,5 +88,4 @@ int main(int argc, char **argv) BIO_free(tbio); return ret; - } diff --git a/demos/smime/smsign2.c b/demos/smime/smsign2.c index 4e62c6b82c..5ad86f15f8 100644 --- a/demos/smime/smsign2.c +++ b/demos/smime/smsign2.c @@ -7,7 +7,7 @@ * https://www.openssl.org/source/license.html */ -/* S/MIME signing example: 2 signers. OpenSSL 0.9.9 only */ +/* S/MIME signing example: 2 signers */ #include <openssl/pem.h> #include <openssl/pkcs7.h> #include <openssl/err.h> @@ -30,7 +30,8 @@ int main(int argc, char **argv) scert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - BIO_reset(tbio); + if (BIO_reset(tbio) < 0) + goto err; skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); @@ -43,7 +44,8 @@ int main(int argc, char **argv) scert2 = PEM_read_bio_X509(tbio, NULL, 0, NULL); - BIO_reset(tbio); + if (BIO_reset(tbio) < 0) + goto err; skey2 = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); @@ -77,8 +79,9 @@ int main(int argc, char **argv) if (!SMIME_write_PKCS7(out, p7, in, PKCS7_STREAM)) goto err; - ret = EXIT_SUCCESS; + printf("Success\n"); + ret = EXIT_SUCCESS; err: if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Signing Data\n"); diff --git a/demos/smime/smver.c b/demos/smime/smver.c index 2e55c72584..caa9ed304f 100644 --- a/demos/smime/smver.c +++ b/demos/smime/smver.c @@ -66,10 +66,9 @@ int main(int argc, char **argv) goto err; } - fprintf(stderr, "Verification Successful\n"); + printf("Verification Successful\n"); ret = EXIT_SUCCESS; - err: if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Verifying Data\n"); |