<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hello,</p>
<p>thanks a lot. Works nice. Just it is interesting that I get X509_ATTRIBUTEs what should be a SEQUENCE but need to parse as SET.</p>
<p>And to free the memory:</p>
<p>X509_ATTRIBUTE *attr;<br /> while ((attr = sk_X509_ATTRIBUTE_pop(attrs)) != NULL) {<br />    X509_ATTRIBUTE_free(attr);<br /> }<br />sk_X509_ATTRIBUTE_free(attrs);</p>
<p>Looks working.</p>
<p>Regards,<br />Libor</p>
<p> </p>
<p>On 2017-11-15 15:31, Dave Coombs wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->Hello,
<div> </div>
<div>You can do something like the following.</div>
<div> </div>
<div>First make a type corresponding to a stack of x509 attributes:</div>
<div> </div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>typedef STACK_OF(X509_ATTRIBUTE) SEQ_X509_ATTRIBUTE;</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>DECLARE_ASN1_FUNCTIONS(SEQ_X509_ATTRIBUTE);</div>
<div> </div>
<div>Then make an asn1 template that specifies how the stack should be encoded.  (You can use ASN1_TFLG_SET_OF instead of ..SEQUENCE_OF here, depending on the DER you're trying to interpret, I don't know.)</div>
<div> </div>
<div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>ASN1_ITEM_TEMPLATE(SEQ_X509_ATTRIBUTE) =</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, x509attribute, X509_ATTRIBUTE)</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>ASN1_ITEM_TEMPLATE_END(SEQ_X509_ATTRIBUTE)</div>
</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>IMPLEMENT_ASN1_FUNCTIONS(SEQ_X509_ATTRIBUTE)</div>
<div> </div>
<div>Now your type has its own d2i and i2d functions, and you can use them:</div>
<div> </div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>STACK_OF(X509_ATTRIBUTE) *attrs = d2i_SEQ_X509_ATTRIBUTE(NULL, &data, length);</div>
<div> </div>
<div>Cheers,</div>
<div>  -Dave</div>
<div> </div>
<div><br />
<div>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<div>On Nov 15, 2017, at 07:26, Libor Chocholaty <<a href="mailto:ossl@mts.cz">ossl@mts.cz</a>> wrote:</div>
<div>
<div style="font-size: 10pt; font-family: Verdana,Geneva,sans-serif;">
<p>Hello,</p>
<p>I would like to parse DER encoded x509 attributes and have no clue how to use d2i_ASN1_SET_OF_X509_ATTRIBUTE. There are params that cannot find what to pass like free_func.</p>
<p>I am trying to uderstand by collecting pieces of known code, looking into openssl sources but...</p>
<p>PKCS7_SIGNER_INFO *p7si = PKCS7_SIGNER_INFO_new();<br />d2i_ASN1_SET_OF_X509_ATTRIBUTE(&p7si->auth_attr, &der_data, der_data_length, d2i_X509_ATTRIBUTE, free_func, V_ASN1_SET, V_ASN1_UNIVERSAL);</p>
<p>Could somebody help how to do it or give a link to some useful documentation?<br />Search internet looks completely not useful in this topic... or do not know how to ask...</p>
<p>Regards,<br />Libor</p>
<div> </div>
</div>
-- <br />openssl-users mailing list<br />To unsubscribe: <a href="https://mta.openssl.org/mailman/listinfo/openssl-users">https://mta.openssl.org/mailman/listinfo/openssl-users</a></div>
</blockquote>
</div>
</div>
<!-- html ignored --><br />
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
</blockquote>
<p> </p>
<div> </div>
</body></html>