mirror of
https://github.com/openssl/openssl.git
synced 2025-01-18 13:44:20 +08:00
cms demos: print signingTime attributes
Add a makefile for the cms demos, and add a routine to cms_ver.c to print any signingTime attributes from the CMS_ContentInfo object. This provides an example that could be extended if an application wants to examine the purported signing times. Part of #8026 Testing: $ cd demos/cms $ make test Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22618)
This commit is contained in:
parent
8286e63271
commit
9257a89b6f
35
demos/cms/Makefile
Normal file
35
demos/cms/Makefile
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#
|
||||||
|
# To run the demos when linked with a shared library (default) ensure that
|
||||||
|
# libcrypto is on the library path. For example, to run the
|
||||||
|
# cms_enc demo:
|
||||||
|
#
|
||||||
|
# LD_LIBRARY_PATH=../.. ./cms_enc
|
||||||
|
|
||||||
|
TESTS = cms_comp \
|
||||||
|
cms_ddec \
|
||||||
|
cms_dec \
|
||||||
|
cms_denc \
|
||||||
|
cms_enc \
|
||||||
|
cms_sign \
|
||||||
|
cms_sign2 \
|
||||||
|
cms_uncomp \
|
||||||
|
cms_ver
|
||||||
|
|
||||||
|
CFLAGS = -I../../include -g
|
||||||
|
LDFLAGS = -L../..
|
||||||
|
LDLIBS = -lcrypto
|
||||||
|
|
||||||
|
all: $(TESTS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(TESTS) *.o
|
||||||
|
|
||||||
|
cms_%: cms_%.c
|
||||||
|
$(CC) $(CFLAGS) $(LDFLAGS) -o "$@" "$<" $(LDLIBS)
|
||||||
|
|
||||||
|
test: all
|
||||||
|
@echo "\nCMS tests:"
|
||||||
|
LD_LIBRARY_PATH=../.. ./cms_enc
|
||||||
|
LD_LIBRARY_PATH=../.. ./cms_dec
|
||||||
|
LD_LIBRARY_PATH=../.. ./cms_sign2
|
||||||
|
LD_LIBRARY_PATH=../.. ./cms_ver
|
@ -59,6 +59,8 @@ int main(int argc, char **argv)
|
|||||||
if (!CMS_decrypt(cms, rkey, rcert, NULL, out, 0))
|
if (!CMS_decrypt(cms, rkey, rcert, NULL, out, 0))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
printf("Decryption Successful\n");
|
||||||
|
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
@ -73,6 +73,8 @@ int main(int argc, char **argv)
|
|||||||
if (!SMIME_write_CMS(out, cms, in, flags))
|
if (!SMIME_write_CMS(out, cms, in, flags))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
printf("Encryption Successful\n");
|
||||||
|
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
err:
|
err:
|
||||||
if (ret != EXIT_SUCCESS) {
|
if (ret != EXIT_SUCCESS) {
|
||||||
|
@ -77,6 +77,8 @@ int main(int argc, char **argv)
|
|||||||
if (!SMIME_write_CMS(out, cms, in, CMS_STREAM))
|
if (!SMIME_write_CMS(out, cms, in, CMS_STREAM))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
printf("Signing Successful\n");
|
||||||
|
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
err:
|
err:
|
||||||
if (ret != EXIT_SUCCESS) {
|
if (ret != EXIT_SUCCESS) {
|
||||||
|
@ -12,6 +12,49 @@
|
|||||||
#include <openssl/cms.h>
|
#include <openssl/cms.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* print any signingTime attributes.
|
||||||
|
* signingTime is when each party purportedly signed the message.
|
||||||
|
*/
|
||||||
|
static void print_signingTime(CMS_ContentInfo *cms)
|
||||||
|
{
|
||||||
|
STACK_OF(CMS_SignerInfo) *sis;
|
||||||
|
CMS_SignerInfo *si;
|
||||||
|
X509_ATTRIBUTE *attr;
|
||||||
|
ASN1_TYPE *t;
|
||||||
|
ASN1_UTCTIME *utctime;
|
||||||
|
ASN1_GENERALIZEDTIME *gtime;
|
||||||
|
BIO *b;
|
||||||
|
int i, loc;
|
||||||
|
|
||||||
|
b = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);
|
||||||
|
sis = CMS_get0_SignerInfos(cms);
|
||||||
|
for (i = 0; i < sk_CMS_SignerInfo_num(sis); i++) {
|
||||||
|
si = sk_CMS_SignerInfo_value(sis, i);
|
||||||
|
loc = CMS_signed_get_attr_by_NID(si, NID_pkcs9_signingTime, -1);
|
||||||
|
attr = CMS_signed_get_attr(si, loc);
|
||||||
|
t = X509_ATTRIBUTE_get0_type(attr, 0);
|
||||||
|
if (t == NULL)
|
||||||
|
continue;
|
||||||
|
switch (t->type) {
|
||||||
|
case V_ASN1_UTCTIME:
|
||||||
|
utctime = t->value.utctime;
|
||||||
|
ASN1_UTCTIME_print(b, utctime);
|
||||||
|
break;
|
||||||
|
case V_ASN1_GENERALIZEDTIME:
|
||||||
|
gtime = t->value.generalizedtime;
|
||||||
|
ASN1_GENERALIZEDTIME_print(b, gtime);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "unrecognized signingTime type\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
BIO_printf(b, ": signingTime from SignerInfo %i\n", i);
|
||||||
|
}
|
||||||
|
BIO_free(b);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
BIO *in = NULL, *out = NULL, *tbio = NULL, *cont = NULL;
|
BIO *in = NULL, *out = NULL, *tbio = NULL, *cont = NULL;
|
||||||
@ -56,6 +99,8 @@ int main(int argc, char **argv)
|
|||||||
if (cms == NULL)
|
if (cms == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
print_signingTime(cms);
|
||||||
|
|
||||||
/* File to output verified content to */
|
/* File to output verified content to */
|
||||||
out = BIO_new_file("smver.txt", "w");
|
out = BIO_new_file("smver.txt", "w");
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
@ -66,9 +111,10 @@ int main(int argc, char **argv)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Verification Successful\n");
|
printf("Verification Successful\n");
|
||||||
|
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (ret != EXIT_SUCCESS) {
|
if (ret != EXIT_SUCCESS) {
|
||||||
fprintf(stderr, "Error Verifying Data\n");
|
fprintf(stderr, "Error Verifying Data\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user