That question was migrated from security.stachexchange.com to serverfault.com and I very strongly disagree with that.
The CMS / PKCS7 was generated with my own custom code. Not OpenSSL and not any third party library but my own custom written code. So given that it seems likely that the issue is structural. ie. having to do with ASN1 / DER and what is anyone at serverfault.com going to know about ASN1 / DER? That's a format used almost exclusively with cryptography. I'm split between security.stackexchange.com or crypto.stackexchange.com being the best place for ASN1 / DER questions but serverfault.com? That's not even remotely the appropriate place.
Heck - even stackoverflow.com would be more appropriate than serverfault.com.
I mean, seriously, so long as it's over there, people are going to ask how I generated it. With proprietary code that I'm not willing to share. That's how I generated it. I'm not asking for help how to generate them using existant tools. What I'm looking for is someone to look at the ASN1 / DER structure and, utilizing their knowledge of the PKCS7 / CMS RFC's to say why it's not finding the cert. serverfault.com is not the place to find answers like that.
Asking for how the signed message was generated is about as relevant as asking about how a CSV was generated when Microsoft Excel isn't able to load the CSV. In that scenario a more appropriate response would be to look at the CSV and, utilizing your knowledge of the CSV format (if you're attempting to answer the question) say what is wrong about it. Same thing with this. If you know anything about PKCS7 / CMS / ASN1 / DER then you can utilize that knowledge to maybe answer the question if you're so inclined.