Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print out signed attribute #478

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 62 additions & 21 deletions pkcs7/smime-verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,37 @@ static int Verify(byte* smime, int smimeSz, byte* ca, int caSz, byte* contentIn,
printf("\n");
}

/* print out the signing time attribute if found */
if (ret == 0) {
word32 outSz;
byte* out;
int err;
const byte signingTimeOid[] = {
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x05
};

err = wc_PKCS7_GetAttributeValue(&pkcs7Compat->pkcs7, signingTimeOid,
sizeof(signingTimeOid), NULL, &outSz);
if (err == LENGTH_ONLY_E) {
out = (byte*)XMALLOC(outSz + 1, NULL, DYNAMIC_TYPE_PKCS7);
if (out != NULL) {
err = wc_PKCS7_GetAttributeValue(&pkcs7Compat->pkcs7,
signingTimeOid, sizeof(signingTimeOid), out, &outSz);
if (err > 0) {
word32 i;
printf("Signing time attribute is :\n\t");
for (i = 0; i < outSz; i++)
printf("%02X", out[i]);
printf("\n");
}
}
XFREE(out, NULL, DYNAMIC_TYPE_PKCS7);
}
else {
printf("No signing time attribute found\n");
}
}

wolfSSL_BIO_free(in);
wolfSSL_BIO_free(content);
wolfSSL_BIO_free(multi);
Expand All @@ -145,6 +176,7 @@ static int ReadSmimeAndCert(char* smimeFile, char* certFile, char* contentFile,
{
int ret;
XFILE f;
*contentSz = 0;

f = XFOPEN(smimeFile, "rb");
if (f == NULL) {
Expand Down Expand Up @@ -188,23 +220,25 @@ static int ReadSmimeAndCert(char* smimeFile, char* certFile, char* contentFile,
}
}

f = XFOPEN(contentFile, "rb");
if (f == NULL) {
printf("Error opening file %s\n", contentFile);
return -1;
}
else {
ret = XFREAD(content, 1, *contentSz, f);
if (ret >= 0) {
if (ret == *contentSz) {
printf("Cert read in was larger than buffer\n");
XFCLOSE(f);
return -1;
}
else {
*contentSz = ret;
ret = 0;
XFCLOSE(f);
if (contentFile != NULL) {
f = XFOPEN(contentFile, "rb");
if (f == NULL) {
printf("Error opening file %s\n", contentFile);
return -1;
}
else {
ret = XFREAD(content, 1, *contentSz, f);
if (ret >= 0) {
if (ret == *contentSz) {
printf("Cert read in was larger than buffer\n");
XFCLOSE(f);
return -1;
}
else {
*contentSz = ret;
ret = 0;
XFCLOSE(f);
}
}
}
}
Expand All @@ -225,8 +259,9 @@ int main(int argc, char** argv)

int ret;

if (argc != 4) {
printf("Use ./smime-verify <smime file> <der cert file> <content file>\n");
if (argc < 3) {
printf("Use ./smime-verify <smime file> <der cert file> "
"<optional content file>\n");
return -1;
}

Expand All @@ -239,8 +274,14 @@ int main(int argc, char** argv)
return -1;
}

ret = ReadSmimeAndCert(argv[1], argv[2], argv[3], smime, &smimeSz, cert,
&certSz, content, &contentSz);
if (argc > 3) {
ret = ReadSmimeAndCert(argv[1], argv[2], argv[3], smime, &smimeSz, cert,
&certSz, content, &contentSz);
}
else {
ret = ReadSmimeAndCert(argv[1], argv[2], NULL, smime, &smimeSz, cert,
&certSz, content, &contentSz);
}
if (ret == 0) {
ret = Verify(smime, smimeSz, cert, certSz, content, contentSz, 0);
if (ret == 0) {
Expand Down