<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Sep 6, 2013, at 1:10 PM, Juan Lang wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><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></blockquote>I guess that makes sense... even though the tag in question is an ASN_CONSTRUCTOR instead of an ASN_PRIMITIVE. I must've overlooked that because it didn't have the ASN_CONSTRUCTOR bit set.<br><blockquote type="cite"><div dir="ltr"><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></blockquote>Yep, I remember reading that in the specs, but I was thrown off by Wine expecting some custom tag (ASN_CONTEXT | ASN_CONSTRUCTOR | 0) for that.<br><blockquote type="cite"><div dir="ltr">

<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></blockquote>I did what you said, and it turns out that my initial analysis (if you can call it that) was wrong. Windows Crypto doesn't accept the SET either way (cf. job 2056 on newtestbot).</div><div><br></div><div>In the "AuthAttrsAndUnknownItem" case, it might be because it already encountered the AuthAttrs set and didn't expect to find another one. But I suspect that in the other case (just with the "UnknownItem"), it's because Crypto was expecting to find something in the set, but didn't. (I did, after all, fill the set with zeroes.)</div><div><br></div><div>Maybe then the real fix is to make Wine accept either a constructor SET or the custom tag (ASN_CONTEXT | ASN_CONSTRUCTOR) it currently accepts, for either attribute set. I should come up with a test case first, though, to see if that's what Windows does. I'll get back to you on that.</div><div><br></div><div>Chip</div><div><br><blockquote type="cite"><div dir="ltr">
<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>
</blockquote></div><br></body></html>