<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Menlo;
        panose-1:2 11 6 9 3 8 4 2 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="en-DE" link="blue" vlink="purple" style="word-wrap:break-word;-webkit-nbsp-mode: space;line-break:after-white-space">
<div class="WordSection1">
<p class="MsoNormal"><span lang="DE" style="mso-fareast-language:EN-US">Hi Russ,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="DE" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">I have the 126 bytes, but as described I omitted them, because they are in my opinion not helpful<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">for my problem, and would only clutter the email. I should probably have written some ellipses<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">to indicate it better.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">best regards<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Max Larsson<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Russ Housley <housley@vigilsec.com><br>
<b>Date: </b>Thursday, 4. November 2021 at 17:29<br>
<b>To: </b>Max Larsson <max.larsson@facilityboss.biz><br>
<b>Cc: </b>openssl-users@openssl.org <openssl-users@openssl.org><br>
<b>Subject: </b>Re: ASN1 <-> DER encoding with application tag<o:p></o:p></span></p>
</div>
<p class="MsoNormal">The data is not correct if it supposed to match RFC 2743.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The first byte is [APPLICATION 0].  That seems fine.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The second byte provides a length for the full SEQUENCE.  It says there are 126 bytes, but you do not have that many.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Russ<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Nov 4, 2021, at 10:18 AM, Max Larsson <<a href="mailto:max.larsson@facilityboss.biz">max.larsson@facilityboss.biz</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><span lang="DE">Hi Russ,</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="DE"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US">do you mean that the DER data</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x60 </span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x7e </span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x06 </span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x06 </span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x</span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">2</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">b </span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x06 </span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x01 </span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x05 </span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x05 </span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x02 </span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">xa0 </span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x74</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US">is wrong?</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US">If so, that DER data have I captured with wireshark from an smb2 session setup request.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US">and that’s even I try to decode with help of openssl. If the case is that that data is wrongly,</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US">is there a way to get decode with openssl anyway?</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US">Max</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt">From:<span class="apple-converted-space"> </span></span></b><span style="font-size:12.0pt">Russ Housley <</span><a href="mailto:housley@vigilsec.com"><span style="font-size:12.0pt">housley@vigilsec.com</span></a><span style="font-size:12.0pt">><br>
<b>Date:<span class="apple-converted-space"> </span></b>Thursday, 4. November 2021 at 15:08<br>
<b>To:<span class="apple-converted-space"> </span></b>Max Larsson <</span><a href="mailto:max.larsson@facilityboss.biz"><span style="font-size:12.0pt">max.larsson@facilityboss.biz</span></a><span style="font-size:12.0pt">><br>
<b>Cc:<span class="apple-converted-space"> </span></b></span><a href="mailto:openssl-users@openssl.org"><span style="font-size:12.0pt">openssl-users@openssl.org</span></a><span class="apple-converted-space"><span style="font-size:12.0pt"> </span></span><span style="font-size:12.0pt"><</span><a href="mailto:openssl-users@openssl.org"><span style="font-size:12.0pt">openssl-users@openssl.org</span></a><span style="font-size:12.0pt">><br>
<b>Subject:<span class="apple-converted-space"> </span></b>Re: ASN1 <-> DER encoding with application tag</span></p>
</div>
<div>
<p class="MsoNormal">RFC 2743 shows this structure:<o:p></o:p></p>
</div>
<div>
<pre>      MechType ::= OBJECT IDENTIFIER</pre>
<pre>      -- data structure definitions</pre>
<pre>      -- callers must be able to distinguish among</pre>
<pre>      -- InitialContextToken, SubsequentContextToken,</pre>
<pre>      -- PerMsgToken, and SealedMessage data elements</pre>
<pre>      -- based on the usage in which they occur</pre>
<pre> </pre>
<pre>      InitialContextToken ::=</pre>
<pre>      -- option indication (delegation, etc.) indicated within</pre>
<pre>      -- mechanism-specific token</pre>
<pre>      [APPLICATION 0] IMPLICIT SEQUENCE {</pre>
<pre>              thisMech MechType,</pre>
<pre>              innerContextToken ANY DEFINED BY thisMech</pre>
<pre>                 -- contents mechanism-specific</pre>
<pre>                 -- ASN.1 structure not required</pre>
<pre>              }</pre>
<div>
<div>
<p class="MsoNormal">The encoded data that you provided dies begin with the [APPLICATION 0] tag, then it if followed by by the { 1 3 6 1 5 5 2 } object identifier.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Russ<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><br>
<br>
<br>
<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal">On Nov 4, 2021, at 9:58 AM, Max Larsson <<a href="mailto:max.larsson@facilityboss.biz">max.larsson@facilityboss.biz</a>> wrote:<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span lang="DE">Hi everyone,</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="DE"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US">I’m trying to decode and encode Der structure. In my case that are DER encoded GSSAPI structure.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US">My DER encoded data looks like this (stripped the pending bytes):</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x60<span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x7e<span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x06<span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x06<span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x</span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">2</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">b<span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x06<span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x01<span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x05<span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x05<span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x02<span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">xa0<span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x74</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US">My ANS1 definition in my source look like this:</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:blue">typedef</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">struct</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">ContextToken_st
 {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">    ASN1_OBJECT *mech;</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">    ASN1_OCTET_STRING *innerContextToken;</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">} GSSAPI_CONTEXTTOKEN;</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">DECLARE_ASN1_FUNCTIONS( GSSAPI_CONTEXTTOKEN )</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">ASN1_SEQUENCE( GSSAPI_CONTEXTTOKEN ) = {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">    ASN1_SIMPLE( GSSAPI_CONTEXTTOKEN, mech, ASN1_OBJECT ),</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">    ASN1_SIMPLE( GSSAPI_CONTEXTTOKEN, innerContextToken, ASN1_OCTET_STRING  )</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">} ASN1_SEQUENCE_END( GSSAPI_CONTEXTTOKEN )  </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">IMPLEMENT_ASN1_FUNCTIONS( GSSAPI_CONTEXTTOKEN )</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US">Parsing the above DER data fails, so I decided to encode a own Der structure, to see where the difference is with my setup:</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black">   <span class="apple-converted-space"> </span></span><span lang="DE" style="font-size:9.0pt;font-family:Menlo;color:black">.
 . .</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black">    </span><span style="font-size:9.0pt;font-family:Menlo;color:black">negToken = GSSAPI_CONTEXTTOKEN_new();</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">   <span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">if</span><span style="font-size:9.0pt;font-family:Menlo;color:black">(
 negToken !=<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">NULL</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">)
 {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">        negToken->mech = OBJ_txt2obj(<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">"1.3.6.1.5.5.2"</span><span style="font-size:9.0pt;font-family:Menlo;color:black">,</span><span style="font-size:9.0pt;font-family:Menlo;color:#098658">0</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">        negToken->innerContextToken = ASN1_OCTET_STRING_new();</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">       <span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">const</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">unsigned</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">char</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">mechToken</span><span style="font-size:9.0pt;font-family:Menlo;color:blue">[]</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">=<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">"\xa0\x74\x30<span class="apple-converted-space"> </span></span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">//
 … stripped for readability</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">       <span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">const</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">size_t</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">mechTokenSize
 =<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">sizeof</span><span style="font-size:9.0pt;font-family:Menlo;color:black">( mechToken ) -<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#098658">1</span><span style="font-size:9.0pt;font-family:Menlo;color:black">;</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">        printf(<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">"Size
 of inner token: %zu\n"</span><span style="font-size:9.0pt;font-family:Menlo;color:black">,mechTokenSize );</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">        ASN1_OCTET_STRING_set( negToken->innerContextToken,mechToken,mechTokenSize );</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">        buffer =<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">NULL</span><span style="font-size:9.0pt;font-family:Menlo;color:black">;</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">       <span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">size_t</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">bufferSize
 = i2d_GSSAPI_CONTEXTTOKEN( negToken,</span><span style="font-size:9.0pt;font-family:Menlo;color:blue">NULL</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">        printf(<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">"Required
 buffer size for DER encoding of ASN1 structure: %zu\n"</span><span style="font-size:9.0pt;font-family:Menlo;color:black">,bufferSize );</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">       <span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">unsigned</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">char</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">*buffer
 = malloc( bufferSize );</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">       <span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">unsigned</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">char</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">*p
 = buffer;</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">        i2d_GSSAPI_CONTEXTTOKEN( negToken,&p );</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">   <span class="apple-converted-space"> </span>    </span><span style="font-size:9.0pt;font-family:Menlo;color:blue">for</span><span style="font-size:9.0pt;font-family:Menlo;color:black">(<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">int</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">len
 =<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#098658">0</span><span style="font-size:9.0pt;font-family:Menlo;color:black">;len < bufferSize;len++ ) {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">           <span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">if</span><span style="font-size:9.0pt;font-family:Menlo;color:black">(
 ( len %<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#098658">8</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">)
 ==<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#098658">0</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">)</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">                printf(<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">" 
 "</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">           <span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:blue">if</span><span style="font-size:9.0pt;font-family:Menlo;color:black">(
 ( len %<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#098658">16</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">)
 ==<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#098658">0</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">)</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">                printf(<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">"\n\t\t"</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">            printf(<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">"
 0x%02x"</span><span style="font-size:9.0pt;font-family:Menlo;color:black">,(</span><span style="font-size:9.0pt;font-family:Menlo;color:blue">short</span><span style="font-size:9.0pt;font-family:Menlo;color:black">)buffer[ len ] );</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">        }</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black">        printf(<span class="apple-converted-space"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">"\n"</span><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span></span><span style="font-size:9.0pt;font-family:Menlo;color:black">);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:black">    . . .</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><span style="font-size:9.0pt;font-family:Menlo;color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US">The code above output the following DER encoded structure (the difference marled in bold):</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:13.5pt;background:white"><b><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span></b><b><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x</span></b><b><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">3</span></b><b><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">0<span class="apple-converted-space"> </span></span></b><b><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span></b><b><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x</span></b><b><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">81
 0x80</span></b><span class="apple-converted-space"><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515"> </span></span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x06<span class="apple-converted-space"> </span></span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x06<span class="apple-converted-space"> </span></span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x</span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">2</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">b<span class="apple-converted-space"> </span></span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x06<span class="apple-converted-space"> </span></span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x01<span class="apple-converted-space"> </span></span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x05<span class="apple-converted-space"> </span></span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x05<span class="apple-converted-space"> </span></span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x02<span class="apple-converted-space"> </span></span><b><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0x04
 0x76</span></b><span class="apple-converted-space"><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515"> </span></span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">xa0<span class="apple-converted-space"> </span></span><span lang="EN-US" style="font-size:9.0pt;font-family:Menlo;color:#A31515">0</span><span style="font-size:9.0pt;font-family:Menlo;color:#A31515">x74</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US">The google result, which I found seems to point into the direction to use application tags to encode.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US">But I haven’t found any example or how to how to achieve this with openssl, can anyone give me sone hints?</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US">Best regards</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US">Max Larsson</span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt">Mit freundlichen Grüßen<br>
Best regards</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt">Dipl.-Inform. Max Larsson<br>
Geschäftsleitung</span><o:p></o:p></p>
</div>
<div>
<div>
<div class="MsoNormal">
<hr size="0" width="100%" align="left">
</div>
</div>
</div>
<table class="MsoNormalTable" border="0" cellpadding="0" width="600" style="width:450.0pt;caret-color: rgb(0, 0, 0);-webkit-text-stroke-width: 0px;word-spacing:0px">
<tbody>
<tr>
<td width="236" valign="top" style="width:176.7pt;padding:.75pt .75pt .75pt .75pt">
<div>
<p class="MsoNormal"><span style="font-size:8.5pt">phone: +49(0)6151/62908-75<br>
fax:<span class="apple-converted-space"> </span><br>
email:<span class="apple-converted-space"> </span></span><a href="mailto:max.larsson@facilityboss.biz" target="_new" title="Send an email to"><span style="font-size:8.5pt">max.larsson@facilityboss.biz</span></a><span style="font-size:8.5pt"><br>
web:<span class="apple-converted-space"> </span></span><a href="http://facilityboss.biz/" target="_new" title="Visit facilityboss.biz"><span style="font-size:8.5pt">http://facilityboss.biz</span></a><o:p></o:p></p>
</div>
</td>
<td style="padding:.75pt .75pt .75pt .75pt">
<div>
<p class="MsoNormal"><a href="http://facilityboss.biz/" title=""Visit facilityboss.biz" t "><b><span style="font-size:10.0pt;text-decoration:none"><img border="0" width="280" height="73" style="width:2.9166in;height:.7604in" id="_x0000_i1026" src="http://facilityboss.biz/sites/default/files/facilityboss_logo.png" alt="facilityboss"></span></b></a><span style="font-size:10.0pt"><br>
Bad Nauheimer Str. 4<br>
64289 Darmstadt<br>
Germany</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:7.0pt">Sitz der Gesellschaft: Darmstadt<br>
Registergericht: Amtsgericht Darmstadt, HRB 86193<br>
Geschäftsführer: Dipl.-Inform Max Lars Robert Larsson</span><o:p></o:p></p>
</div>
</td>
</tr>
</tbody>
</table>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Helvetica;color:white"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<div class="MsoNormal">
<hr size="0" width="100%" noshade="" style="color:#73706E" align="left">
</div>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:6.0pt;color:#73706E">Diese E-Mail enthält unter Umständen vertrauliche und/oder rechtlich geschützte Informationen, die allein für den Adressaten bestimmt sind. Wenn Sie nicht der zutreffende Adressat sind oder diese
 E-Mail irrtümlich erhalten haben, ist jede Verwendung, Verbreitung, Kopie oder Bezugnahme auf den Inhalt dieser E-Mail verboten. Bitte informieren Sie uns über einen eventuellen Irrtum per Telefon, per Telefax oder E-Mail.<br>
<br>
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient, any disclosure, copying, distribution or reference on the contents of this e-mail is strictly prohibited. If you have received this e-mail in error please
 notify us by e-mail, facsimile or phone call.</span><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>