1226031Sstas<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2226031Sstas<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3226031Sstas<title>Heimdalntlmlibrary: test_ntlm.c</title>
4226031Sstas<link href="doxygen.css" rel="stylesheet" type="text/css">
5226031Sstas<link href="tabs.css" rel="stylesheet" type="text/css">
6226031Sstas</head><body>
7226031Sstas<p>
8226031Sstas<a href="http://www.h5l.org/"><img src="http://www.h5l.org/keyhole-heimdal.png" alt="keyhole logo"/></a>
9226031Sstas</p>
10226031Sstas<!-- end of header marker -->
11226031Sstas<!-- Generated by Doxygen 1.5.6 -->
12226031Sstas<div class="navigation" id="top">
13226031Sstas  <div class="tabs">
14226031Sstas    <ul>
15226031Sstas      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
16226031Sstas      <li><a href="modules.html"><span>Modules</span></a></li>
17226031Sstas      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
18226031Sstas      <li><a href="examples.html"><span>Examples</span></a></li>
19226031Sstas    </ul>
20226031Sstas  </div>
21226031Sstas</div>
22226031Sstas<div class="contents">
23226031Sstas<h1>test_ntlm.c</h1>Example how to use the NTLM primitives.<p>
24226031Sstas<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
25226031Sstas<span class="comment"> * Copyright (c) 2006 - 2007 Kungliga Tekniska H��gskolan</span>
26226031Sstas<span class="comment"> * (Royal Institute of Technology, Stockholm, Sweden).</span>
27226031Sstas<span class="comment"> * All rights reserved.</span>
28226031Sstas<span class="comment"> *</span>
29226031Sstas<span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
30226031Sstas<span class="comment"> * modification, are permitted provided that the following conditions</span>
31226031Sstas<span class="comment"> * are met:</span>
32226031Sstas<span class="comment"> *</span>
33226031Sstas<span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
34226031Sstas<span class="comment"> *    notice, this list of conditions and the following disclaimer.</span>
35226031Sstas<span class="comment"> *</span>
36226031Sstas<span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
37226031Sstas<span class="comment"> *    notice, this list of conditions and the following disclaimer in the</span>
38226031Sstas<span class="comment"> *    documentation and/or other materials provided with the distribution.</span>
39226031Sstas<span class="comment"> *</span>
40226031Sstas<span class="comment"> * 3. Neither the name of KTH nor the names of its contributors may be</span>
41226031Sstas<span class="comment"> *    used to endorse or promote products derived from this software without</span>
42226031Sstas<span class="comment"> *    specific prior written permission.</span>
43226031Sstas<span class="comment"> *</span>
44226031Sstas<span class="comment"> * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY</span>
45226031Sstas<span class="comment"> * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
46226031Sstas<span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR</span>
47226031Sstas<span class="comment"> * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE</span>
48226031Sstas<span class="comment"> * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</span>
49226031Sstas<span class="comment"> * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</span>
50226031Sstas<span class="comment"> * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR</span>
51226031Sstas<span class="comment"> * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span>
52226031Sstas<span class="comment"> * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR</span>
53226031Sstas<span class="comment"> * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF</span>
54226031Sstas<span class="comment"> * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
55226031Sstas<span class="comment"> */</span>
56226031Sstas
57226031Sstas<span class="preprocessor">#include "config.h"</span>
58226031Sstas
59226031Sstas<span class="preprocessor">#include &lt;stdio.h&gt;</span>
60226031Sstas<span class="preprocessor">#include &lt;err.h&gt;</span>
61226031Sstas<span class="preprocessor">#include &lt;roken.h&gt;</span>
62226031Sstas<span class="preprocessor">#include &lt;getarg.h&gt;</span>
63226031Sstas
64226031Sstas<span class="preprocessor">#include &lt;krb5-types.h&gt;</span> <span class="comment">/* or &lt;inttypes.h&gt; */</span>
65226031Sstas<span class="preprocessor">#include &lt;heimntlm.h&gt;</span>
66226031Sstas
67226031Sstas<span class="keyword">static</span> <span class="keywordtype">int</span>
68226031Sstastest_parse(<span class="keywordtype">void</span>)
69226031Sstas{
70226031Sstas    <span class="keyword">const</span> <span class="keywordtype">char</span> *user = <span class="stringliteral">"foo"</span>,
71226031Sstas        *domain = <span class="stringliteral">"mydomain"</span>,
72226031Sstas        *password = <span class="stringliteral">"digestpassword"</span>,
73226031Sstas        *target = <span class="stringliteral">"DOMAIN"</span>;
74226031Sstas    <span class="keyword">struct </span><a name="_a0"></a><a class="code" href="structntlm__type1.html">ntlm_type1</a> type1;
75226031Sstas    <span class="keyword">struct </span><a name="_a1"></a><a class="code" href="structntlm__type2.html">ntlm_type2</a> type2;
76226031Sstas    <span class="keyword">struct </span><a name="_a2"></a><a class="code" href="structntlm__type3.html">ntlm_type3</a> type3;
77226031Sstas    <span class="keyword">struct </span><a name="_a3"></a><a class="code" href="structntlm__buf.html">ntlm_buf</a> data;
78226031Sstas    <span class="keywordtype">int</span> ret, flags;
79226031Sstas
80226031Sstas    memset(&amp;type1, 0, <span class="keyword">sizeof</span>(type1));
81226031Sstas
82226031Sstas    type1.<a name="a4"></a><a class="code" href="structntlm__type1.html#e2f4bbf968f7dde8f1cd2a71396a06fb">flags</a> = NTLM_NEG_UNICODE|NTLM_NEG_TARGET|NTLM_NEG_NTLM;
83226031Sstas    type1.<a name="a5"></a><a class="code" href="structntlm__type1.html#7d99f4da91742cd5bd94f1af1713c075">domain</a> = rk_UNCONST(domain);
84226031Sstas    type1.<a name="a6"></a><a class="code" href="structntlm__type1.html#63e2c0e1d31b93802670e677b89ae7e8">hostname</a> = NULL;
85226031Sstas    type1.<a name="a7"></a><a class="code" href="structntlm__type1.html#3f0a2c98b021a211c030b09b37d35fa3">os</a>[0] = 0;
86226031Sstas    type1.<a class="code" href="structntlm__type1.html#3f0a2c98b021a211c030b09b37d35fa3">os</a>[1] = 0;
87226031Sstas
88226031Sstas    ret = <a name="a8"></a><a class="code" href="group__ntlm__core.html#g0107727234287ac61a8801b0faff9dff">heim_ntlm_encode_type1</a>(&amp;type1, &amp;data);
89226031Sstas    <span class="keywordflow">if</span> (ret)
90226031Sstas        errx(1, <span class="stringliteral">"heim_ntlm_encode_type1"</span>);
91226031Sstas
92226031Sstas    memset(&amp;type1, 0, <span class="keyword">sizeof</span>(type1));
93226031Sstas
94226031Sstas    ret = heim_ntlm_decode_type1(&amp;data, &amp;type1);
95226031Sstas    free(data.<a name="a9"></a><a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
96226031Sstas    <span class="keywordflow">if</span> (ret)
97226031Sstas        errx(1, <span class="stringliteral">"heim_ntlm_encode_type1"</span>);
98226031Sstas
99226031Sstas    <a name="a10"></a><a class="code" href="group__ntlm__core.html#g76fa6caf3f539e24008e31613f5eb663">heim_ntlm_free_type1</a>(&amp;type1);
100226031Sstas
101226031Sstas    <span class="comment">/*</span>
102226031Sstas<span class="comment">     *</span>
103226031Sstas<span class="comment">     */</span>
104226031Sstas
105226031Sstas    memset(&amp;type2, 0, <span class="keyword">sizeof</span>(type2));
106226031Sstas
107226031Sstas    flags = NTLM_NEG_UNICODE | NTLM_NEG_NTLM | NTLM_TARGET_DOMAIN;
108226031Sstas    type2.<a name="a11"></a><a class="code" href="structntlm__type2.html#7f52e5d5e1e31e369d88d1cfb738a9ff">flags</a> = flags;
109226031Sstas
110226031Sstas    memset(type2.<a name="a12"></a><a class="code" href="structntlm__type2.html#12c5c7a960c60bbd54dbf49527856bab">challenge</a>, 0x7f, <span class="keyword">sizeof</span>(type2.<a class="code" href="structntlm__type2.html#12c5c7a960c60bbd54dbf49527856bab">challenge</a>));
111226031Sstas    type2.<a name="a13"></a><a class="code" href="structntlm__type2.html#7ed7a5246d77d4358e6fa459c6263a10">targetname</a> = rk_UNCONST(target);
112226031Sstas    type2.<a name="a14"></a><a class="code" href="structntlm__type2.html#d468bf3c5f042a893f3d118a9cb50a34">targetinfo</a>.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a> = NULL;
113226031Sstas    type2.<a class="code" href="structntlm__type2.html#d468bf3c5f042a893f3d118a9cb50a34">targetinfo</a>.<a name="a15"></a><a class="code" href="structntlm__buf.html#1ca1856fd5b4ac0197320d7723c73bd0">length</a> = 0;
114226031Sstas
115226031Sstas    ret = <a name="a16"></a><a class="code" href="group__ntlm__core.html#g2860c6f6d497255eb433adc8cacc49dd">heim_ntlm_encode_type2</a>(&amp;type2, &amp;data);
116226031Sstas    <span class="keywordflow">if</span> (ret)
117226031Sstas        errx(1, <span class="stringliteral">"heim_ntlm_encode_type2"</span>);
118226031Sstas
119226031Sstas    memset(&amp;type2, 0, <span class="keyword">sizeof</span>(type2));
120226031Sstas
121226031Sstas    ret = heim_ntlm_decode_type2(&amp;data, &amp;type2);
122226031Sstas    free(data.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
123226031Sstas    <span class="keywordflow">if</span> (ret)
124226031Sstas        errx(1, <span class="stringliteral">"heim_ntlm_decode_type2"</span>);
125226031Sstas
126226031Sstas    <a name="a17"></a><a class="code" href="group__ntlm__core.html#g8fde84c86f1c7c9f730f7fb4acedcb43">heim_ntlm_free_type2</a>(&amp;type2);
127226031Sstas
128226031Sstas    <span class="comment">/*</span>
129226031Sstas<span class="comment">     *</span>
130226031Sstas<span class="comment">     */</span>
131226031Sstas
132226031Sstas    memset(&amp;type3, 0, <span class="keyword">sizeof</span>(type3));
133226031Sstas
134226031Sstas    type3.<a name="a18"></a><a class="code" href="structntlm__type3.html#65347e68a22b66fc65c299f2cda2cf2d">flags</a> = flags;
135226031Sstas    type3.<a name="a19"></a><a class="code" href="structntlm__type3.html#c6e99229102b238c4aad9b93fabe95b7">username</a> = rk_UNCONST(user);
136226031Sstas    type3.<a name="a20"></a><a class="code" href="structntlm__type3.html#89d7688f04cb1362ffa5a81759d28716">targetname</a> = rk_UNCONST(target);
137226031Sstas    type3.<a name="a21"></a><a class="code" href="structntlm__type3.html#ffbe974b5c93e47e2c8bf6f5a767c82d">ws</a> = rk_UNCONST(<span class="stringliteral">"workstation"</span>);
138226031Sstas
139226031Sstas    {
140226031Sstas        <span class="keyword">struct </span><a class="code" href="structntlm__buf.html">ntlm_buf</a> key;
141226031Sstas        <a name="a22"></a><a class="code" href="group__ntlm__core.html#g254ee0a4d5a2594833e36697ad575d7e">heim_ntlm_nt_key</a>(password, &amp;key);
142226031Sstas
143226031Sstas        <a name="a23"></a><a class="code" href="group__ntlm__core.html#ge3b634802ef94233a175291abd2ea14d">heim_ntlm_calculate_ntlm1</a>(key.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>, key.<a class="code" href="structntlm__buf.html#1ca1856fd5b4ac0197320d7723c73bd0">length</a>,
144226031Sstas                                  type2.<a class="code" href="structntlm__type2.html#12c5c7a960c60bbd54dbf49527856bab">challenge</a>,
145226031Sstas                                  &amp;type3.<a name="a24"></a><a class="code" href="structntlm__type3.html#7b496ad8682fbd4a5fe06c32da7621c7">ntlm</a>);
146226031Sstas        free(key.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
147226031Sstas    }
148226031Sstas
149226031Sstas    ret = <a name="a25"></a><a class="code" href="group__ntlm__core.html#g9cf026be6e602c22d62aa9e47e85c7c2">heim_ntlm_encode_type3</a>(&amp;type3, &amp;data);
150226031Sstas    <span class="keywordflow">if</span> (ret)
151226031Sstas        errx(1, <span class="stringliteral">"heim_ntlm_encode_type3"</span>);
152226031Sstas
153226031Sstas    free(type3.<a class="code" href="structntlm__type3.html#7b496ad8682fbd4a5fe06c32da7621c7">ntlm</a>.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
154226031Sstas
155226031Sstas    memset(&amp;type3, 0, <span class="keyword">sizeof</span>(type3));
156226031Sstas
157226031Sstas    ret = heim_ntlm_decode_type3(&amp;data, 1, &amp;type3);
158226031Sstas    free(data.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
159226031Sstas    <span class="keywordflow">if</span> (ret)
160226031Sstas        errx(1, <span class="stringliteral">"heim_ntlm_decode_type3"</span>);
161226031Sstas
162226031Sstas    <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"workstation"</span>, type3.<a class="code" href="structntlm__type3.html#ffbe974b5c93e47e2c8bf6f5a767c82d">ws</a>) != 0)
163226031Sstas        errx(1, <span class="stringliteral">"type3 ws wrong"</span>);
164226031Sstas
165226031Sstas    <span class="keywordflow">if</span> (strcmp(target, type3.<a class="code" href="structntlm__type3.html#89d7688f04cb1362ffa5a81759d28716">targetname</a>) != 0)
166226031Sstas        errx(1, <span class="stringliteral">"type3 targetname wrong"</span>);
167226031Sstas
168226031Sstas    <span class="keywordflow">if</span> (strcmp(user, type3.<a class="code" href="structntlm__type3.html#c6e99229102b238c4aad9b93fabe95b7">username</a>) != 0)
169226031Sstas        errx(1, <span class="stringliteral">"type3 username wrong"</span>);
170226031Sstas
171226031Sstas
172226031Sstas    <a name="a26"></a><a class="code" href="group__ntlm__core.html#gc4e6d01e5247b8540d41ccbbf1031319">heim_ntlm_free_type3</a>(&amp;type3);
173226031Sstas
174226031Sstas    <span class="comment">/*</span>
175226031Sstas<span class="comment">     * NTLMv2</span>
176226031Sstas<span class="comment">     */</span>
177226031Sstas
178226031Sstas    memset(&amp;type2, 0, <span class="keyword">sizeof</span>(type2));
179226031Sstas
180226031Sstas    flags = NTLM_NEG_UNICODE | NTLM_NEG_NTLM | NTLM_TARGET_DOMAIN;
181226031Sstas    type2.<a class="code" href="structntlm__type2.html#7f52e5d5e1e31e369d88d1cfb738a9ff">flags</a> = flags;
182226031Sstas
183226031Sstas    memset(type2.<a class="code" href="structntlm__type2.html#12c5c7a960c60bbd54dbf49527856bab">challenge</a>, 0x7f, <span class="keyword">sizeof</span>(type2.<a class="code" href="structntlm__type2.html#12c5c7a960c60bbd54dbf49527856bab">challenge</a>));
184226031Sstas    type2.<a class="code" href="structntlm__type2.html#7ed7a5246d77d4358e6fa459c6263a10">targetname</a> = rk_UNCONST(target);
185226031Sstas    type2.<a class="code" href="structntlm__type2.html#d468bf3c5f042a893f3d118a9cb50a34">targetinfo</a>.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a> = <span class="stringliteral">"\x00\x00"</span>;
186226031Sstas    type2.<a class="code" href="structntlm__type2.html#d468bf3c5f042a893f3d118a9cb50a34">targetinfo</a>.<a class="code" href="structntlm__buf.html#1ca1856fd5b4ac0197320d7723c73bd0">length</a> = 2;
187226031Sstas
188226031Sstas    ret = <a class="code" href="group__ntlm__core.html#g2860c6f6d497255eb433adc8cacc49dd">heim_ntlm_encode_type2</a>(&amp;type2, &amp;data);
189226031Sstas    <span class="keywordflow">if</span> (ret)
190226031Sstas        errx(1, <span class="stringliteral">"heim_ntlm_encode_type2"</span>);
191226031Sstas
192226031Sstas    memset(&amp;type2, 0, <span class="keyword">sizeof</span>(type2));
193226031Sstas
194226031Sstas    ret = heim_ntlm_decode_type2(&amp;data, &amp;type2);
195226031Sstas    free(data.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
196226031Sstas    <span class="keywordflow">if</span> (ret)
197226031Sstas        errx(1, <span class="stringliteral">"heim_ntlm_decode_type2"</span>);
198226031Sstas
199226031Sstas    <a class="code" href="group__ntlm__core.html#g8fde84c86f1c7c9f730f7fb4acedcb43">heim_ntlm_free_type2</a>(&amp;type2);
200226031Sstas
201226031Sstas    <span class="keywordflow">return</span> 0;
202226031Sstas}
203226031Sstas
204226031Sstas<span class="keyword">static</span> <span class="keywordtype">int</span>
205226031Sstastest_keys(<span class="keywordtype">void</span>)
206226031Sstas{
207226031Sstas    <span class="keyword">const</span> <span class="keywordtype">char</span>
208226031Sstas        *username = <span class="stringliteral">"test"</span>,
209226031Sstas        *password = <span class="stringliteral">"test1234"</span>,
210226031Sstas        *target = <span class="stringliteral">"TESTNT"</span>;
211226031Sstas    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>
212226031Sstas        serverchallenge[8] = <span class="stringliteral">"\x67\x7f\x1c\x55\x7a\x5e\xe9\x6c"</span>;
213226031Sstas    <span class="keyword">struct </span><a class="code" href="structntlm__buf.html">ntlm_buf</a> infotarget, infotarget2, answer, key;
214226031Sstas    <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ntlmv2[16], ntlmv2_1[16];
215226031Sstas    <span class="keywordtype">int</span> ret;
216226031Sstas
217226031Sstas    infotarget.length = 70;
218226031Sstas    infotarget.data =
219226031Sstas        <span class="stringliteral">"\x02\x00\x0c\x00\x54\x00\x45\x00\x53\x00\x54\x00\x4e\x00\x54\x00"</span>
220226031Sstas        <span class="stringliteral">"\x01\x00\x0c\x00\x4d\x00\x45\x00\x4d\x00\x42\x00\x45\x00\x52\x00"</span>
221226031Sstas        <span class="stringliteral">"\x03\x00\x1e\x00\x6d\x00\x65\x00\x6d\x00\x62\x00\x65\x00\x72\x00"</span>
222226031Sstas            <span class="stringliteral">"\x2e\x00\x74\x00\x65\x00\x73\x00\x74\x00\x2e\x00\x63\x00\x6f"</span>
223226031Sstas            <span class="stringliteral">"\x00\x6d\x00"</span>
224226031Sstas        <span class="stringliteral">"\x00\x00\x00\x00"</span>;
225226031Sstas
226226031Sstas    answer.length = 0;
227226031Sstas    answer.data = NULL;
228226031Sstas
229226031Sstas    <a class="code" href="group__ntlm__core.html#g254ee0a4d5a2594833e36697ad575d7e">heim_ntlm_nt_key</a>(password, &amp;key);
230226031Sstas
231226031Sstas    ret = <a name="a27"></a><a class="code" href="group__ntlm__core.html#ga8f07fb71a0d5f095cde3fb9fb40d10c">heim_ntlm_calculate_ntlm2</a>(key.data,
232226031Sstas                                    key.length,
233226031Sstas                                    username,
234226031Sstas                                    target,
235226031Sstas                                    serverchallenge,
236226031Sstas                                    &amp;infotarget,
237226031Sstas                                    ntlmv2,
238226031Sstas                                    &amp;answer);
239226031Sstas    <span class="keywordflow">if</span> (ret)
240226031Sstas        errx(1, <span class="stringliteral">"heim_ntlm_calculate_ntlm2"</span>);
241226031Sstas
242226031Sstas    ret = <a name="a28"></a><a class="code" href="group__ntlm__core.html#g3b3d6a5187cab6bfe656afa7a8273ca6">heim_ntlm_verify_ntlm2</a>(key.data,
243226031Sstas                                 key.length,
244226031Sstas                                 username,
245226031Sstas                                 target,
246226031Sstas                                 0,
247226031Sstas                                 serverchallenge,
248226031Sstas                                 &amp;answer,
249226031Sstas                                 &amp;infotarget2,
250226031Sstas                                 ntlmv2_1);
251226031Sstas    <span class="keywordflow">if</span> (ret)
252226031Sstas        errx(1, <span class="stringliteral">"heim_ntlm_verify_ntlm2"</span>);
253226031Sstas
254226031Sstas    <span class="keywordflow">if</span> (memcmp(ntlmv2, ntlmv2_1, <span class="keyword">sizeof</span>(ntlmv2)) != 0)
255226031Sstas        errx(1, <span class="stringliteral">"ntlm master key not same"</span>);
256226031Sstas
257226031Sstas    <span class="keywordflow">if</span> (infotarget.length &gt; infotarget2.length)
258226031Sstas        errx(1, <span class="stringliteral">"infotarget length"</span>);
259226031Sstas
260226031Sstas    <span class="keywordflow">if</span> (memcmp(infotarget.data, infotarget2.data, infotarget.length) != 0)
261226031Sstas        errx(1, <span class="stringliteral">"infotarget not the same"</span>);
262226031Sstas
263226031Sstas    free(key.data);
264226031Sstas    free(answer.data);
265226031Sstas    free(infotarget2.data);
266226031Sstas
267226031Sstas    <span class="keywordflow">return</span> 0;
268226031Sstas}
269226031Sstas
270226031Sstas<span class="keyword">static</span> <span class="keywordtype">int</span>
271226031Sstastest_ntlm2_session_resp(<span class="keywordtype">void</span>)
272226031Sstas{
273226031Sstas    <span class="keywordtype">int</span> ret;
274226031Sstas    <span class="keyword">struct </span><a class="code" href="structntlm__buf.html">ntlm_buf</a> lm, ntlm;
275226031Sstas
276226031Sstas    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> lm_resp[24] =
277226031Sstas        <span class="stringliteral">"\xff\xff\xff\x00\x11\x22\x33\x44"</span>
278226031Sstas        <span class="stringliteral">"\x00\x00\x00\x00\x00\x00\x00\x00"</span>
279226031Sstas        <span class="stringliteral">"\x00\x00\x00\x00\x00\x00\x00\x00"</span>;
280226031Sstas    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ntlm2_sess_resp[24] =
281226031Sstas        <span class="stringliteral">"\x10\xd5\x50\x83\x2d\x12\xb2\xcc"</span>
282226031Sstas        <span class="stringliteral">"\xb7\x9d\x5a\xd1\xf4\xee\xd3\xdf"</span>
283226031Sstas        <span class="stringliteral">"\x82\xac\xa4\xc3\x68\x1d\xd4\x55"</span>;
284226031Sstas
285226031Sstas    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> client_nonce[8] =
286226031Sstas        <span class="stringliteral">"\xff\xff\xff\x00\x11\x22\x33\x44"</span>;
287226031Sstas    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> server_challenge[8] =
288226031Sstas        <span class="stringliteral">"\x01\x23\x45\x67\x89\xab\xcd\xef"</span>;
289226031Sstas
290226031Sstas    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ntlm_hash[16] =
291226031Sstas        <span class="stringliteral">"\xcd\x06\xca\x7c\x7e\x10\xc9\x9b"</span>
292226031Sstas        <span class="stringliteral">"\x1d\x33\xb7\x48\x5a\x2e\xd8\x08"</span>;
293226031Sstas
294226031Sstas    ret = heim_ntlm_calculate_ntlm2_sess(client_nonce,
295226031Sstas                                         server_challenge,
296226031Sstas                                         ntlm_hash,
297226031Sstas                                         &amp;lm,
298226031Sstas                                         &amp;ntlm);
299226031Sstas    <span class="keywordflow">if</span> (ret)
300226031Sstas        errx(1, <span class="stringliteral">"heim_ntlm_calculate_ntlm2_sess_resp"</span>);
301226031Sstas
302226031Sstas    <span class="keywordflow">if</span> (lm.length != 24 || memcmp(lm.data, lm_resp, 24) != 0)
303226031Sstas        errx(1, <span class="stringliteral">"lm_resp wrong"</span>);
304226031Sstas    <span class="keywordflow">if</span> (ntlm.length != 24 || memcmp(ntlm.data, ntlm2_sess_resp, 24) != 0)
305226031Sstas        errx(1, <span class="stringliteral">"ntlm2_sess_resp wrong"</span>);
306226031Sstas
307226031Sstas    free(lm.data);
308226031Sstas    free(ntlm.data);
309226031Sstas
310226031Sstas
311226031Sstas    <span class="keywordflow">return</span> 0;
312226031Sstas}
313226031Sstas
314226031Sstas<span class="keyword">static</span> <span class="keywordtype">int</span>
315226031Sstastest_targetinfo(<span class="keywordtype">void</span>)
316226031Sstas{
317226031Sstas    <span class="keyword">struct </span>ntlm_targetinfo ti;
318226031Sstas    <span class="keyword">struct </span><a class="code" href="structntlm__buf.html">ntlm_buf</a> buf;
319226031Sstas    <span class="keyword">const</span> <span class="keywordtype">char</span> *dnsservername = <span class="stringliteral">"dnsservername"</span>;
320226031Sstas    <span class="keywordtype">int</span> ret;
321226031Sstas
322226031Sstas    memset(&amp;ti, 0, <span class="keyword">sizeof</span>(ti));
323226031Sstas
324226031Sstas    ti.dnsservername = rk_UNCONST(dnsservername);
325226031Sstas    ti.avflags = 1;
326226031Sstas    ret = <a name="a29"></a><a class="code" href="group__ntlm__core.html#g2881747fad2ac2979a28d3bd050b0fa8">heim_ntlm_encode_targetinfo</a>(&amp;ti, 1, &amp;buf);
327226031Sstas    <span class="keywordflow">if</span> (ret)
328226031Sstas        <span class="keywordflow">return</span> ret;
329226031Sstas
330226031Sstas    memset(&amp;ti, 0, <span class="keyword">sizeof</span>(ti));
331226031Sstas
332226031Sstas    ret = <a name="a30"></a><a class="code" href="group__ntlm__core.html#gf1d4de2faec8b1c1070a55fd2e6e630f">heim_ntlm_decode_targetinfo</a>(&amp;buf, 1, &amp;ti);
333226031Sstas    <span class="keywordflow">if</span> (ret)
334226031Sstas        <span class="keywordflow">return</span> ret;
335226031Sstas
336226031Sstas    <span class="keywordflow">if</span> (ti.dnsservername == NULL ||
337226031Sstas        strcmp(ti.dnsservername, dnsservername) != 0)
338226031Sstas        errx(1, <span class="stringliteral">"ti.dnshostname != %s"</span>, dnsservername);
339226031Sstas    <span class="keywordflow">if</span> (ti.avflags != 1)
340226031Sstas        errx(1, <span class="stringliteral">"ti.avflags != 1"</span>);
341226031Sstas
342226031Sstas    <a name="a31"></a><a class="code" href="group__ntlm__core.html#g704ec8c5dba05ef57186d242ff165565">heim_ntlm_free_targetinfo</a>(&amp;ti);
343226031Sstas
344226031Sstas    <span class="keywordflow">return</span> 0;
345226031Sstas}
346226031Sstas
347226031Sstas<span class="keyword">static</span> <span class="keywordtype">int</span> verbose_flag = 0;
348226031Sstas<span class="keyword">static</span> <span class="keywordtype">int</span> version_flag = 0;
349226031Sstas<span class="keyword">static</span> <span class="keywordtype">int</span> help_flag    = 0;
350226031Sstas
351226031Sstas<span class="keyword">static</span> <span class="keyword">struct </span>getargs args[] = {
352226031Sstas    {<span class="stringliteral">"verbose"</span>, 0,      arg_flag,       &amp;verbose_flag, <span class="stringliteral">"verbose printing"</span>, NULL },
353226031Sstas    {<span class="stringliteral">"version"</span>, 0,      arg_flag,       &amp;version_flag, <span class="stringliteral">"print version"</span>, NULL },
354226031Sstas    {<span class="stringliteral">"help"</span>,    0,      arg_flag,       &amp;help_flag,  NULL, NULL }
355226031Sstas};
356226031Sstas
357226031Sstas<span class="keyword">static</span> <span class="keywordtype">void</span>
358226031Sstasusage (<span class="keywordtype">int</span> ret)
359226031Sstas{
360226031Sstas    arg_printusage (args, <span class="keyword">sizeof</span>(args)/<span class="keyword">sizeof</span>(*args),
361226031Sstas                    NULL, <span class="stringliteral">""</span>);
362226031Sstas    exit (ret);
363226031Sstas}
364226031Sstas
365226031Sstas<span class="keywordtype">int</span>
366226031Sstasmain(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
367226031Sstas{
368226031Sstas    <span class="keywordtype">int</span> ret = 0, optind = 0;
369226031Sstas
370226031Sstas    setprogname(argv[0]);
371226031Sstas
372226031Sstas    <span class="keywordflow">if</span>(getarg(args, <span class="keyword">sizeof</span>(args) / <span class="keyword">sizeof</span>(args[0]), argc, argv, &amp;optind))
373226031Sstas        usage(1);
374226031Sstas
375226031Sstas    <span class="keywordflow">if</span> (help_flag)
376226031Sstas        usage (0);
377226031Sstas
378226031Sstas    <span class="keywordflow">if</span>(version_flag){
379226031Sstas        print_version(NULL);
380226031Sstas        exit(0);
381226031Sstas    }
382226031Sstas
383226031Sstas    argc -= optind;
384226031Sstas    argv += optind;
385226031Sstas
386226031Sstas    <span class="keywordflow">if</span> (verbose_flag)
387226031Sstas        printf(<span class="stringliteral">"test_parse\n"</span>);
388226031Sstas
389226031Sstas    ret += test_parse();
390226031Sstas    <span class="keywordflow">if</span> (verbose_flag)
391226031Sstas        printf(<span class="stringliteral">"test_keys\n"</span>);
392226031Sstas
393226031Sstas    ret += test_keys();
394226031Sstas    <span class="keywordflow">if</span> (verbose_flag)
395226031Sstas        printf(<span class="stringliteral">"test_ntlm2_session_resp\n"</span>);
396226031Sstas    ret += test_ntlm2_session_resp();
397226031Sstas
398226031Sstas    <span class="keywordflow">if</span> (verbose_flag)
399226031Sstas        printf(<span class="stringliteral">"test_targetinfo\n"</span>);
400226031Sstas    ret += test_targetinfo();
401226031Sstas
402226031Sstas    <span class="keywordflow">return</span> ret;
403226031Sstas}
404226031Sstas</pre></div> </div>
405226031Sstas<hr size="1"><address style="text-align: right;"><small>
406234027SstasGenerated on Wed Jan 11 14:07:50 2012 for Heimdalntlmlibrary by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6</small></address>
407226031Sstas</body>
408226031Sstas</html>
409