1*cfb92d14SAndroid Build Coastguard Worker /*
2*cfb92d14SAndroid Build Coastguard Worker * Copyright (c) 2017, The OpenThread Authors.
3*cfb92d14SAndroid Build Coastguard Worker * All rights reserved.
4*cfb92d14SAndroid Build Coastguard Worker *
5*cfb92d14SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without
6*cfb92d14SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are met:
7*cfb92d14SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright
8*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer.
9*cfb92d14SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright
10*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the
11*cfb92d14SAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution.
12*cfb92d14SAndroid Build Coastguard Worker * 3. Neither the name of the copyright holder nor the
13*cfb92d14SAndroid Build Coastguard Worker * names of its contributors may be used to endorse or promote products
14*cfb92d14SAndroid Build Coastguard Worker * derived from this software without specific prior written permission.
15*cfb92d14SAndroid Build Coastguard Worker *
16*cfb92d14SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17*cfb92d14SAndroid Build Coastguard Worker * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*cfb92d14SAndroid Build Coastguard Worker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*cfb92d14SAndroid Build Coastguard Worker * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20*cfb92d14SAndroid Build Coastguard Worker * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*cfb92d14SAndroid Build Coastguard Worker * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*cfb92d14SAndroid Build Coastguard Worker * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*cfb92d14SAndroid Build Coastguard Worker * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*cfb92d14SAndroid Build Coastguard Worker * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*cfb92d14SAndroid Build Coastguard Worker * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*cfb92d14SAndroid Build Coastguard Worker * POSSIBILITY OF SUCH DAMAGE.
27*cfb92d14SAndroid Build Coastguard Worker */
28*cfb92d14SAndroid Build Coastguard Worker #include <openthread/config.h>
29*cfb92d14SAndroid Build Coastguard Worker
30*cfb92d14SAndroid Build Coastguard Worker #include "meshcop/commissioner.hpp"
31*cfb92d14SAndroid Build Coastguard Worker #include "meshcop/meshcop.hpp"
32*cfb92d14SAndroid Build Coastguard Worker
33*cfb92d14SAndroid Build Coastguard Worker #include "test_platform.h"
34*cfb92d14SAndroid Build Coastguard Worker #include "test_util.h"
35*cfb92d14SAndroid Build Coastguard Worker
36*cfb92d14SAndroid Build Coastguard Worker namespace ot {
37*cfb92d14SAndroid Build Coastguard Worker namespace MeshCoP {
38*cfb92d14SAndroid Build Coastguard Worker
39*cfb92d14SAndroid Build Coastguard Worker #if OPENTHREAD_FTD
40*cfb92d14SAndroid Build Coastguard Worker
TestMinimumPassphrase(void)41*cfb92d14SAndroid Build Coastguard Worker void TestMinimumPassphrase(void)
42*cfb92d14SAndroid Build Coastguard Worker {
43*cfb92d14SAndroid Build Coastguard Worker static const otExtendedPanId kExtPanId = {{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}};
44*cfb92d14SAndroid Build Coastguard Worker static const otNetworkName kNetworkName = {{'O', 'p', 'e', 'n', 'T', 'h', 'r', 'e', 'a', 'd', '\0'}};
45*cfb92d14SAndroid Build Coastguard Worker static const char kPassphrase[] = "123456";
46*cfb92d14SAndroid Build Coastguard Worker
47*cfb92d14SAndroid Build Coastguard Worker static const otPskc kExpectedPskc = {
48*cfb92d14SAndroid Build Coastguard Worker {0x44, 0x98, 0x8e, 0x22, 0xcf, 0x65, 0x2e, 0xee, 0xcc, 0xd1, 0xe4, 0xc0, 0x1d, 0x01, 0x54, 0xf8}};
49*cfb92d14SAndroid Build Coastguard Worker
50*cfb92d14SAndroid Build Coastguard Worker Instance *instance = testInitInstance();
51*cfb92d14SAndroid Build Coastguard Worker Pskc pskc;
52*cfb92d14SAndroid Build Coastguard Worker
53*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(GeneratePskc(kPassphrase, AsCoreType(&kNetworkName), AsCoreType(&kExtPanId), pskc));
54*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(pskc == AsCoreType(&kExpectedPskc));
55*cfb92d14SAndroid Build Coastguard Worker
56*cfb92d14SAndroid Build Coastguard Worker testFreeInstance(instance);
57*cfb92d14SAndroid Build Coastguard Worker }
58*cfb92d14SAndroid Build Coastguard Worker
TestMaximumPassphrase(void)59*cfb92d14SAndroid Build Coastguard Worker void TestMaximumPassphrase(void)
60*cfb92d14SAndroid Build Coastguard Worker {
61*cfb92d14SAndroid Build Coastguard Worker static const otExtendedPanId kExtPanId = {{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}};
62*cfb92d14SAndroid Build Coastguard Worker static const otNetworkName kNetworkName = {{'O', 'p', 'e', 'n', 'T', 'h', 'r', 'e', 'a', 'd', '\0'}};
63*cfb92d14SAndroid Build Coastguard Worker
64*cfb92d14SAndroid Build Coastguard Worker static const char kPassphrase[] = "1234567812345678"
65*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
66*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
67*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
68*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
69*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
70*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
71*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
72*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
73*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
74*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
75*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
76*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
77*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
78*cfb92d14SAndroid Build Coastguard Worker "1234567812345678"
79*cfb92d14SAndroid Build Coastguard Worker "123456781234567";
80*cfb92d14SAndroid Build Coastguard Worker
81*cfb92d14SAndroid Build Coastguard Worker static const otPskc kExpectedPskc = {
82*cfb92d14SAndroid Build Coastguard Worker {0x9e, 0x81, 0xbd, 0x35, 0xa2, 0x53, 0x76, 0x2f, 0x80, 0xee, 0x04, 0xff, 0x2f, 0xa2, 0x85, 0xe9}};
83*cfb92d14SAndroid Build Coastguard Worker
84*cfb92d14SAndroid Build Coastguard Worker Instance *instance = testInitInstance();
85*cfb92d14SAndroid Build Coastguard Worker Pskc pskc;
86*cfb92d14SAndroid Build Coastguard Worker
87*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(GeneratePskc(kPassphrase, AsCoreType(&kNetworkName), AsCoreType(&kExtPanId), pskc));
88*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(pskc == AsCoreType(&kExpectedPskc));
89*cfb92d14SAndroid Build Coastguard Worker
90*cfb92d14SAndroid Build Coastguard Worker testFreeInstance(instance);
91*cfb92d14SAndroid Build Coastguard Worker }
92*cfb92d14SAndroid Build Coastguard Worker
TestExampleInSpec(void)93*cfb92d14SAndroid Build Coastguard Worker void TestExampleInSpec(void)
94*cfb92d14SAndroid Build Coastguard Worker {
95*cfb92d14SAndroid Build Coastguard Worker static const otExtendedPanId kExtPanId = {{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}};
96*cfb92d14SAndroid Build Coastguard Worker static const otNetworkName kNetworkName = {{'T', 'e', 's', 't', ' ', 'N', 'e', 't', 'w', 'o', 'r', 'k', '\0'}};
97*cfb92d14SAndroid Build Coastguard Worker static const char kPassphrase[] = "12SECRETPASSWORD34";
98*cfb92d14SAndroid Build Coastguard Worker
99*cfb92d14SAndroid Build Coastguard Worker static const otPskc kExpectedPskc = {
100*cfb92d14SAndroid Build Coastguard Worker {0xc3, 0xf5, 0x93, 0x68, 0x44, 0x5a, 0x1b, 0x61, 0x06, 0xbe, 0x42, 0x0a, 0x70, 0x6d, 0x4c, 0xc9}};
101*cfb92d14SAndroid Build Coastguard Worker
102*cfb92d14SAndroid Build Coastguard Worker Instance *instance = testInitInstance();
103*cfb92d14SAndroid Build Coastguard Worker Pskc pskc;
104*cfb92d14SAndroid Build Coastguard Worker
105*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(GeneratePskc(kPassphrase, AsCoreType(&kNetworkName), AsCoreType(&kExtPanId), pskc));
106*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(pskc == AsCoreType(&kExpectedPskc));
107*cfb92d14SAndroid Build Coastguard Worker
108*cfb92d14SAndroid Build Coastguard Worker testFreeInstance(instance);
109*cfb92d14SAndroid Build Coastguard Worker }
110*cfb92d14SAndroid Build Coastguard Worker
111*cfb92d14SAndroid Build Coastguard Worker } // namespace MeshCoP
112*cfb92d14SAndroid Build Coastguard Worker } // namespace ot
113*cfb92d14SAndroid Build Coastguard Worker
114*cfb92d14SAndroid Build Coastguard Worker #endif // OPENTHREAD_FTD
115*cfb92d14SAndroid Build Coastguard Worker
main(void)116*cfb92d14SAndroid Build Coastguard Worker int main(void)
117*cfb92d14SAndroid Build Coastguard Worker {
118*cfb92d14SAndroid Build Coastguard Worker #if OPENTHREAD_FTD
119*cfb92d14SAndroid Build Coastguard Worker ot::MeshCoP::TestMinimumPassphrase();
120*cfb92d14SAndroid Build Coastguard Worker ot::MeshCoP::TestMaximumPassphrase();
121*cfb92d14SAndroid Build Coastguard Worker ot::MeshCoP::TestExampleInSpec();
122*cfb92d14SAndroid Build Coastguard Worker printf("All tests passed\n");
123*cfb92d14SAndroid Build Coastguard Worker #else
124*cfb92d14SAndroid Build Coastguard Worker printf("PSKc generation is not supported on non-ftd build\n");
125*cfb92d14SAndroid Build Coastguard Worker #endif
126*cfb92d14SAndroid Build Coastguard Worker return 0;
127*cfb92d14SAndroid Build Coastguard Worker }
128