title: Unable to create the correct signature for SAML response
body: <p>I am using <a href="https://github.com/RobotsAndPencils/go-saml/#creating-a-saml-response-if-acting-as-an-idp" rel="nofollow noreferrer">go-saml</a> library in our project to enable SSO in which the service provider will be Salesforce and Identity Provider will be the Golang code. Golang code will first verify the user then it will create a SAML response to allow the user to login to Salesforce.
  I am new to Golang and following <strong>Creating a SAML Response (if acting as an IdP)</strong> of this library. So, far I am able to create a SAML response using it but facing some challenges in customizing it as per the requirement.</p>
  
  <ol>
  <li>The first challenge I was facing is to add <em><strong>AudienceRestriction</strong></em> in the <em><strong>Conditions</strong></em> block as below:-</li>
  </ol>
  
  <p><code>&lt;saml:Conditions NotBefore="2020-03-15T16:33:16.23103491Z" NotOnOrAfter="2020-03-15T16:43:16.23104017Z"&gt;
           &lt;saml:AudienceRestriction&gt;
                  &lt;saml:Audience&gt;https://saml.salesforce.com&lt;/saml:Audience&gt;
           &lt;/saml:AudienceRestriction&gt;
   &lt;/saml:Conditions&gt;</code></p>
  
  <p>I have tried to add it like below in the code, but it seems <strong>AudienceRestrictions</strong> is not defined in <strong>Conditions</strong> object.</p>
  
  <p><code>authnResponse := saml.NewSignedResponse()
   authnResponse.Conditions.AudienceRestrictions = "https://saml.salesforce.com"</code></p>
  
  <p>I don't find any way to add the above block in the Conditions block which is mandatory for Salesforce. Please suggest me some way to do so.</p>
  
  <ol start="2">
  <li>I also have to add <strong>AuthnStatement</strong> below the conditions block as below:-</li>
  </ol>
  
  <p><code>&lt;saml:AuthnStatement AuthnInstant="2020-03-01T11:28:31.396Z"&gt;
     &lt;saml:AuthnContext&gt;    &lt;saml:AuthnContextClassRef&gt;urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified&lt;/saml:AuthnContextClassRef&gt; 
     &lt;/saml:AuthnContext&gt; 
  &lt;/saml:AuthnStatement&gt;</code></p>
  
  <ol start="3">
  <li>Even after manually adding the above blocks in the SAML response, I am getting the below error while validating the SAML response using the Salesforce SAML validator</li>
  </ol>
  
  <blockquote>
    <p>Validating the Signature... 
    Is the response signed? true<br>
    Is the assertion signed? false<br>
    The reference in the response signature is valid<br>
    Is the correct certificate supplied in the keyinfo? true</p>
    
    <p>Signature or certificate problems<br>
    The signature in the response is not valid</p>
  </blockquote>
  
  <p>I have generated a Public key(self-signed .pem certificate) and a Private key. After that, I have uploaded the public key to the Salesforce and using private and public keys to inside the code for generating SAML response. I have no idea why I am getting <strong>Signature Invalid</strong> error. Please let me know if you have any suggestions for me.</p>
  
  <p>In case you want to check my Golang code - <a href="https://play.golang.org/p/U9dXZblTHG1" rel="nofollow noreferrer">https://play.golang.org/p/U9dXZblTHG1</a> </p>