<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="29112" data-post-id="29112">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cgraham" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cgraham
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yeah - that is my plan!  Once I get the functionality working I’ll then have to figure out how to separate it out into a library (Haven’t never done that yet but I am assuming there is good documentation and it is not that hard).</p>
<p>Part of me is wondering if there is a big need for an elixir library that basically has all of the erlang records preloaded so that Elixir members can use Erlang records without needing to find the files and extract them etc…</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="29112" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/x-509-request-cert-chain-validation-plug-for-alexa-skills/4463/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-29112" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="29112"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #21"></div>
  </section>
</div>
    <div class="postbit" id="29113" data-post-id="29113">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="cgraham" data-post="22" data-topic="4463">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/c/e19adc/48.png" class="avatar"> cgraham:</div>
<blockquote>
<p>(Haven’t never done that yet but I am assuming there is good documentation and it is not that hard)</p>
</blockquote>
</aside>
<p>Yeah it is <em>very</em> simple.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="cgraham" data-post="22" data-topic="4463">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/c/e19adc/48.png" class="avatar"> cgraham:</div>
<blockquote>
<p>Part of me is wondering if there is a big need for an elixir library that basically has all of the erlang records preloaded so that Elixir members can use Erlang records without needing to find the files and extract them etc…</p>
</blockquote>
</aside>
<p>Always useful too!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="29113" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/x-509-request-cert-chain-validation-plug-for-alexa-skills/4463/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-29113" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="29113"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="29121" data-post-id="29121">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cgraham" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cgraham
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Woo hoo!  I got it to verify!  Some notes for those of you who may later read this:  I did need to base64 decode the message and we did not need to further decode the RSA since the :otp decode did it recursively.</p>
<p>I am attaching a modified version of the PublicKey test that xlphs posted on github that now works with verify.  I have a few more easy validations an to add and some cleanup and will then extract this whole thing into a library so that people can just use mix to import it.  Thanks again to everyone who helped!  I really appreciate it!</p>
<pre><code>defmodule PublicKey do
	

	def verify_fun(_, {:extension, _}, state) do
		IO.puts "verify_fun -- extension"
	  {:unknown, state}
	end
	def verify_fun(_, {:revoked, _}, state) do
		IO.puts "verify_fun -- revoked"
	  {:fail, state}
	end
	def verify_fun(cert, event, state) do
		IO.puts "verify_fun --"
	  IO.inspect event
	  {:unknown, state}
	end

	def verify do
		Application.ensure_all_started :inets
		Application.ensure_all_started :ssl
		Application.ensure_all_started :public_key

		{:ok, resp} = :httpc.request(:get, {'https://s3.amazonaws.com/echo.api/echo-api-cert-4.pem', []}, [], [body_format: :binary])
		{_, _headers, certificate_chain_bin} = resp
		# alternatively, read from local file
		# {:ok, certificate_chain_bin} = :file.read_file("echo-api-cert.pem")
		cert_chain = :public_key.pem_decode(certificate_chain_bin)
		cert_chain_decoded = Enum.map(cert_chain,
			fn {_, bin, _} -&gt; bin
		end) |&gt; Enum.reverse

		{:ok, resp} = :httpc.request(:get, {'https://www.symantec.com/content/dam/symantec/docs/other-resources/verisign-class-3-public-primary-certification-authority-g5-en.pem', []}, [], [body_format: :binary])
		{_, _headers, root_cert_bin} = resp
		# {:ok, root_cert_bin} = :file.read_file("auth_root.pem")
		[{_, root_cer, _}] = :public_key.pem_decode(root_cert_bin)

		case :public_key.pkix_path_validation(root_cer, cert_chain_decoded,
					[{:verify_fun, {&amp;PublicKey.verify_fun/3, {}}}]) do
			{:ok, {public_key_info, _policy_tree}} -&gt;
				IO.inspect public_key_info
			{:error, {:bad_cert, reason}} -&gt;
				IO.puts "validation failed with bad cert"
				IO.inspect reason
		end


		[{_,first,_}|_tail] = cert_chain
		decoded = :public_key.pkix_decode_cert(first,:otp)
		public_key_der = decoded |&gt; elem(1) |&gt; elem(7) |&gt; elem(2)


		message = "&lt;raw body of alexa request&gt;"
        signature = "cHV0IHNpZ25hdHVyZSB2YWx1ZSBpbiByZXF1ZXN0IGhlYWRlciBoZXJl" #signature request header parameter
		{:ok, signature} = Base.decode64(signature)
		 IO.puts ("verified? #{:public_key.verify(message, :sha, signature, public_key_der)}"); 

	end	
end

PublicKey.verify()
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="29121" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/x-509-request-cert-chain-validation-plug-for-alexa-skills/4463/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-29121" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="29121"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #23"></div>
  </section>
</div>
    <div class="postbit" id="29626" data-post-id="29626">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cgraham" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cgraham
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi all,</p>
<p>Just a quick note that I believe I finished all the validation and published it to hex and github as a library.  You can see it on github here <a href="https://github.com/grahac/alexa_request_verifier" class="inline-onebox" rel="noopener nofollow ugc">GitHub - grahac/alexa_request_verifier · GitHub</a>. and on Hex here <a href="https://hexdocs.pm/alexa_request_verifier/api-reference.html" class="inline-onebox" rel="noopener nofollow ugc">API Reference – alexa_request_verifier v0.1.6</a></p>
<p>Thank you all once again for your help! Also, this is my very first Elixir library submission so if I did something wrong or if you have any suggestions on how to make it better, please let me know!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="29626" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/x-509-request-cert-chain-validation-plug-for-alexa-skills/4463/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-29626" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="29626"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>