<div dir="ltr">Hiya Chip,<div><br></div><div>I don't have an answer off the top of my head. But let's see if we can unpack that ASN.1 a bit.</div><div><br></div><div>First, with the type, notice that crypt32_private.h defines a few useful types that Microsoft omitted for some reason from their public header, including:</div>



<div><div>#define ASN_SETOF           (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x11)</div></div><div>Okay, so that's what we're dealing with.<br></div><div><br></div><div>Next, to help sort it out: write each of the blobs to a binary, and interpret it with "openssl asn1parse -dump -i -inform DER". Here's the output from PKCSSignerWithUnknownItem31:</div>




<div><br></div><div><div>    0:d=0  hl=4 l= 146 cons: SEQUENCE          </div><div>    4:d=1  hl=2 l=   1 prim:  INTEGER           :00</div><div>    7:d=1  hl=2 l=  25 cons:  SEQUENCE          </div><div>    9:d=2  hl=2 l=  20 cons:   SEQUENCE          </div>




<div>   11:d=3  hl=2 l=  18 cons:    SET               </div><div>   13:d=4  hl=2 l=  16 cons:     SEQUENCE          </div><div>   15:d=5  hl=2 l=   3 prim:      OBJECT            :commonName</div><div>   20:d=5  hl=2 l=   9 prim:      PRINTABLESTRING   :Juan Lang</div>




<div>   31:d=2  hl=2 l=   1 prim:   INTEGER           :01</div><div>   34:d=1  hl=2 l=   6 cons:  SEQUENCE          </div><div>   36:d=2  hl=2 l=   2 prim:   OBJECT            :1.2.3</div><div>   40:d=2  hl=2 l=   0 prim:   NULL              </div>




<div>   42:d=1  hl=2 l=  96 cons:  SET               </div><div>   44:d=2  hl=2 l=   0 prim:   EOC               </div></div><div>(a bunch of these omitted)</div><div><div>  140:d=1  hl=2 l=   6 cons:  SEQUENCE          </div>




<div>  142:d=2  hl=2 l=   2 prim:   OBJECT            :1.5.6</div><div>  146:d=2  hl=2 l=   0 prim:   NULL              </div><div>  148:d=1  hl=2 l=   0 prim:  OCTET STRING      </div></div><div><br></div><div>And here's the output from PKCSSignerWithAuthAttrAndUnknownItem31:</div>




<div><div>    0:d=0  hl=4 l= 196 cons: SEQUENCE          </div><div>    4:d=1  hl=2 l=   1 prim:  INTEGER           :00</div><div>    7:d=1  hl=2 l=  25 cons:  SEQUENCE          </div><div>    9:d=2  hl=2 l=  20 cons:   SEQUENCE          </div>




<div>   11:d=3  hl=2 l=  18 cons:    SET               </div><div>   13:d=4  hl=2 l=  16 cons:     SEQUENCE          </div><div>   15:d=5  hl=2 l=   3 prim:      OBJECT            :commonName</div><div>   20:d=5  hl=2 l=   9 prim:      PRINTABLESTRING   :Juan Lang</div>




<div>   31:d=2  hl=2 l=   1 prim:   INTEGER           :01</div><div>   34:d=1  hl=2 l=   6 cons:  SEQUENCE          </div><div>   36:d=2  hl=2 l=   2 prim:   OBJECT            :1.2.3</div><div>   40:d=2  hl=2 l=   0 prim:   NULL              </div>




<div>   42:d=1  hl=2 l=  32 cons:  cont [ 0 ]        </div><div>   44:d=2  hl=2 l=  30 cons:   SEQUENCE          </div><div>   46:d=3  hl=2 l=   3 prim:    OBJECT            :commonName</div><div>   51:d=3  hl=2 l=  23 cons:    SET               </div>




<div>   53:d=4  hl=2 l=  21 cons:     SEQUENCE          </div><div>   55:d=5  hl=2 l=  19 cons:      SET               </div><div>   57:d=6  hl=2 l=  17 cons:       SEQUENCE          </div><div>   59:d=7  hl=2 l=   3 prim:        OBJECT            :commonName</div>




<div>   64:d=7  hl=2 l=  10 prim:        PRINTABLESTRING   :Juan Lang</div><div>   76:d=1  hl=2 l=  96 cons:  SET               </div><div>   78:d=2  hl=2 l=   0 prim:   EOC               </div></div><div>(again, a bunch of these omitted)</div>




<div><div>  174:d=1  hl=2 l=   6 cons:  SEQUENCE          </div><div>  176:d=2  hl=2 l=   2 prim:   OBJECT            :1.5.6</div><div>  180:d=2  hl=2 l=   0 prim:   NULL              </div><div>  182:d=1  hl=2 l=  16 prim:  OCTET STRING      </div>




<div>      0000 - 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f   ................</div></div><div><br></div><div>You can see that in the latter case, you've got a context-specific tag of 0 wrapping a sequence containing a non-empty set. That context-specific [0] looks an awful lot like "<span style="font-size:1em">signedAttrs [0] IMPLICIT SignedAttributes OPTIONAL," no? And SignedAttributes is defined as "</span><span style="font-size:1em">SignedAttributes ::= SET SIZE (1..MAX) OF Attribute".</span></div>

<div><span style="font-size:1em"><br></span></div><div><span style="font-size:1em">Anyway, in the latter case, the signed attributes precede the set, and in the former case they're missing.</span></div>
<div><br></div><div>In addition to that, it's not entirely clear from your test results that it's expected to succeed in Windows in either case:</div>

<div><br></div><div><div>+    ret = pCryptDecodeObjectEx(dwEncoding, PKCS7_SIGNER_INFO,</div>
<div>+     PKCSSignerWithAuthAttrAndUnknownItem31,</div><div>+     sizeof(PKCSSignerWithAuthAttrAndUnknownItem31),</div><div>+     CRYPT_DECODE_ALLOC_FLAG, NULL, &buf, &size);</div><div>+    if (ret)</div></div><div>




<br></div><div>You don't have an ok(ret) here. I can't blame you too much for that, though: it looks like I omitted a bunch of ok(ret)s in my tests too. Sigh. Sorry about that. Could you add that and see what that turns up?</div>
<div>--Juan</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Sep 5, 2013 at 11:57 PM, Charles Davis <span dir="ltr"><<a href="mailto:cdavis5x@gmail.com" target="_blank">cdavis5x@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Juan,<br>
<br>
I need some advice.<br>
<br>
Attached is a patch to fix bug 34388, where an app that tries to verify its code signature fails because Wine, while parsing the certificates embedded within the signature, encounters an item in the CMS signer info (tag 0x31, i.e. ASN_UNIVERSAL | ASN_CONSTRUCTOR | 0x11), right before the HashEncryptionAlgorithm sequence item, that it doesn't yet know how to decode. This patch (which just skips the item in question) allows that app to successfully verify its code signature and run, but...<br>

<br>
My testing on Windows (cf. job 2037 on newtestbot) shows some interesting behavior. Windows will indeed accept this item, but only if the AuthAttrs item is also present and immediately precedes it in the sequence. (The other test bails out with CRYPT_E_ASN_BADTAG.) I don't quite know what to make of this. The odd thing is that the certificate in question doesn't have this optional AuthAttrs item, and yet (in most cases, at least) most people who run this particular app on Windows do not have this problem. I can't seem to find anything about this from reading the relevant RFCs. Is there something I'm missing?<br>

<br>
Thanks.<br>
<br>
Chip<br>
</blockquote></div><br></div>