Merge pull request #478 from JacobBarthelmeh/smime

print out signed attribute
pull/479/head
David Garske 2025-01-20 16:48:14 -08:00 committed by GitHub
commit ae1097d6ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 62 additions and 21 deletions

View File

@ -128,6 +128,37 @@ static int Verify(byte* smime, int smimeSz, byte* ca, int caSz, byte* contentIn,
printf("\n"); 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(in);
wolfSSL_BIO_free(content); wolfSSL_BIO_free(content);
wolfSSL_BIO_free(multi); wolfSSL_BIO_free(multi);
@ -145,6 +176,7 @@ static int ReadSmimeAndCert(char* smimeFile, char* certFile, char* contentFile,
{ {
int ret; int ret;
XFILE f; XFILE f;
*contentSz = 0;
f = XFOPEN(smimeFile, "rb"); f = XFOPEN(smimeFile, "rb");
if (f == NULL) { if (f == NULL) {
@ -188,23 +220,25 @@ static int ReadSmimeAndCert(char* smimeFile, char* certFile, char* contentFile,
} }
} }
f = XFOPEN(contentFile, "rb"); if (contentFile != NULL) {
if (f == NULL) { f = XFOPEN(contentFile, "rb");
printf("Error opening file %s\n", contentFile); if (f == NULL) {
return -1; printf("Error opening file %s\n", contentFile);
} return -1;
else { }
ret = XFREAD(content, 1, *contentSz, f); else {
if (ret >= 0) { ret = XFREAD(content, 1, *contentSz, f);
if (ret == *contentSz) { if (ret >= 0) {
printf("Cert read in was larger than buffer\n"); if (ret == *contentSz) {
XFCLOSE(f); printf("Cert read in was larger than buffer\n");
return -1; XFCLOSE(f);
} return -1;
else { }
*contentSz = ret; else {
ret = 0; *contentSz = ret;
XFCLOSE(f); ret = 0;
XFCLOSE(f);
}
} }
} }
} }
@ -225,8 +259,9 @@ int main(int argc, char** argv)
int ret; int ret;
if (argc != 4) { if (argc < 3) {
printf("Use ./smime-verify <smime file> <der cert file> <content file>\n"); printf("Use ./smime-verify <smime file> <der cert file> "
"<optional content file>\n");
return -1; return -1;
} }
@ -239,8 +274,14 @@ int main(int argc, char** argv)
return -1; return -1;
} }
ret = ReadSmimeAndCert(argv[1], argv[2], argv[3], smime, &smimeSz, cert, if (argc > 3) {
&certSz, content, &contentSz); 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) { if (ret == 0) {
ret = Verify(smime, smimeSz, cert, certSz, content, contentSz, 0); ret = Verify(smime, smimeSz, cert, certSz, content, contentSz, 0);
if (ret == 0) { if (ret == 0) {