<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div><span style="font-size: 10pt;">Hi,</span><br></div><div class="yahoo_quoted" style="display: block;"><div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 10pt;"><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt;"><div class="y_msg_container"><div id="yiv6406954911"><div><div style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 10pt;"><div class="yiv6406954911" style=""><br class="yiv6406954911" style=""></div><div class="yiv6406954911" style="">Sorry if this is a re-post but I didnot see this one on the list.</div><div class="yiv6406954911" style=""><br></div><div style="color:
 rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;" class="yiv6406954911">I am writing client side of an authentication service, where I get encrypted and signed SAML response from the server process.</div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;" class="yiv6406954911">I am confused about the right way to decrypt an encrypted response (precisely, a signed response with encrypted assertion in it). I am writing the pseudo-code which I have (mainly from
 the saml-2.5.3-src/samltest/encryption/EncryptedAssertionTest.h) :&nbsp;</div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;" class="yiv6406954911"><br class="yiv6406954911" style=""></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;" class="yiv6406954911">========================================</div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;" class="yiv6406954911"><br class="yiv6406954911" style=""></div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911"
 style="white-space:pre;">        </span>/* get the credential resolver */</div><div style="
background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">        </span>credentialresolver* c_resolver = null;</div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">        </span>std::string config = keystore_path + "filesystemcredentialresolver.xml";<span class="yiv6406954911" style="white-space:pre;">        </span>// has client&nbsp;<span style="background-color:transparent;font-size:10pt;" class="yiv6406954911">private/public key</span></div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">        </span>std::ifstream in(config.c_str());</div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">        </span>domdocument* doc = xmltoolingconfig::getconfig().getparser().parse(in);</div><div style="background-color:transparent;"
 class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">        </span>xercesjanitor&lt;domdocument&gt; janitor(doc);</div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">        </span>c_resolver = xmltoolingconfig::getconfig().credentialresolvermanager.</div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">                                        </span>newplugin(filesystem_credential_resolver,doc-&gt;getdocumentelement());</div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">        </span>in.close();</div><div style="background-color:transparent;" class="yiv6406954911"><br class="yiv6406954911" style=""></div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">        </span>/* get the meta-data provider details
 */</div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; std::string m_config = keystore_path + "metadataproviderconfig.xml";<span class="yiv6406954911" style="white-space:pre;">                <span class="yiv6406954911" style="white-space:pre;">                        </span>       </span>// tells the path of&nbsp;<span style="background-color:transparent;font-size:10pt;" class="yiv6406954911">actual metadata file</span></div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; std::ifstream m_in(m_config.c_str());</div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; domdocument* m_doc = xmltoolingconfig::getconfig().getparser().parse(m_in);</div><div style="background-color:transparent;" class="yiv6406954911"><span style="white-space:pre;" class="yiv6406954911">&nbsp;   </span>xercesjanitor&lt;domdocument&gt; m_janitor(m_doc);</div><div style="background-color:transparent;"
 class="yiv6406954911">&nbsp; &nbsp; auto_ptr_xmlch md_path("path");</div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; std::string s = keystore_path + "metadata.xml";<span class="yiv6406954911" style="white-space:pre;">                                                                </span>// same file as&nbsp;<span style="background-color:transparent;font-size:10pt;" class="yiv6406954911">example-metadata.xml in samltest/data</span></div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp;
 auto_ptr_xmlch file(s.c_str());</div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; (m_doc-&gt;getdocumentelement())-&gt;setattributens(null, md_path.get(), file.get());</div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; opensaml::saml2md::metadataprovider *m_metadata =&nbsp;<span style="background-color:transparent;font-size:10pt;" class="yiv6406954911">&nbsp;</span><span class="yiv6406954911" style="background-color:transparent;font-size:10pt;white-space:pre;">                </span><span style="background-color:transparent;font-size:10pt;" class="yiv6406954911">opensaml::samlconfig::getconfig().metadataprovidermanager.newplugin(</span></div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; &nbsp; &nbsp; xml_metadata_provider,m_doc-&gt;getdocumentelement());</div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; m_metadata-&gt;init();</div><div
 style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; locker
 mlocker(m_metadata);</div><div style="background-color:transparent;" class="yiv6406954911"><br class="yiv6406954911" style=""></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;" class="yiv6406954911">&nbsp; &nbsp; /* create metadata provider */</div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; opensaml::saml2md::metadataprovider::criteria mc("https://sp.example.org/", &amp;opensaml::saml2md::<span style="background-color:transparent;font-size:10pt;" class="yiv6406954911">spssodescriptor::element_qname, samlconstants::saml20p_ns);</span></div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; std::pair&lt;const opensaml::saml2md::entitydescriptor*,const opensaml::saml2md::roledescriptor*&gt; sp =&nbsp;</div><div
 style="background-color:transparent;" class="yiv6406954911">m_metadata-&gt;getentitydescriptor(mc);</div><div style="background-color:transparent;" class="yiv6406954911"><br class="yiv6406954911" style=""></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;" class="yiv6406954911">&nbsp; &nbsp; /* get encrypted assertion from response (available to this function) */</div><div style="background-color:transparent;" class="yiv6406954911">&nbsp; &nbsp; encryptedassertion *ea = null;</div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">        </span>if ((response-&gt;getencryptedassertions()).size() &gt; 0) {</div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">                            
 </span>/* get the first encrypted assertion */</div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">                       <span class="yiv6406954911" style="white-space:pre;">                                        </span>      </span>ea =
 dynamic_cast&lt;encryptedassertion*&gt;((response-&gt;getencryptedassertions()).at(0));</div><div style="background-color:transparent;" class="yiv6406954911"><span style="white-space:pre;" class="yiv6406954911">&nbsp;       </span>}</div><div style="background-color:transparent;" class="yiv6406954911"><span class="yiv6406954911" style="white-space:pre;">        </span>std::auto_ptr&lt;opensaml::saml2::assertion&gt; assertion2(dynamic_cast&lt;opensaml::saml2::assertion*&gt;(ea-&gt;</div><div style="background-color:transparent;" class="yiv6406954911">decrypt(*c_resolver, sp.first-&gt;getentityid())));</div><div style="background-color:transparent;" class="yiv6406954911"><br class="yiv6406954911" style=""></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;"
 class="yiv6406954911">=================================</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;" class="yiv6406954911"><br class="yiv6406954911" style=""></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;" class="yiv6406954911">I have posted the same code in pastebin (http://pastebin.com/VvLnDxGv).</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;" class="yiv6406954911">Is it the right way to do it or this code is too convoluted for what it is supposed to do (extracting decrypted assertion from encrypted
 assertion, which is in a SAML response). This code dumps core on the last decrypt step&nbsp;</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;" class="yiv6406954911"><span style="background-color:transparent;font-size:10pt;" class="yiv6406954911"><span class="yiv6406954911Apple-tab-span" style="white-space:pre;">        </span>ea-&gt;</span><span style="background-color:transparent;font-size:10pt;">decrypt(*c_resolver, sp.first-&gt;getentityid())</span></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;" class="yiv6406954911"><br class="yiv6406954911" style=""></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family:
 HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;" class="yiv6406954911">Please advise.</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;" class="yiv6406954911"><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;" class="yiv6406954911">Thanks,</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;" class="yiv6406954911">Akshay</div></div></div></div></div>  </div> </div>  </div> </div></body></html>