Debian Codegraph @

testcases/login/login_test.sh

raw
1 #!/bin/sh
2 #
3 # COPYRIGHT (c) International Business Machines Corp. 2005-2017
4 #
5 # This program is provided under the terms of the Common Public License,
6 # version 1.0 (CPL-1.0). Any use, reproduction or distribution for this software
7 # constitutes recipient's acceptance of CPL-1.0 terms which can be found
8 # in the file LICENSE file or at https://opensource.org/licenses/cpl1.0.php
9 #
10 # login_test.sh
11 #
12 # Kent Yoder <[email protected]>
13 #
14 # usage: login_test.sh -slot [n]
15 #
16 # By default, slot 0 is used. This script will run through several
17 # scenarios WRT login's to the PKCS#11 API. It expects a completely
18 # uninitialized token, such as right after installation. It is
19 # expected that the token will be reinitialized after running this test.
20 #
21 set -x
22
23
24 DEFAULT_SO_PIN=${P11_SO_PWD:=87654321}
25 DEFAULT_USER_PIN=${P11_USER_PWD:=12345678}
26
27 NEW_USER_PIN1=${NEW_P11_USER_PWD:=userPW1}
28 NEW_USER_PIN2=${NEW_P11_USER_PWD2:=userPW2}
29 NEW_SO_PIN1=${NEW_P11_SO_PWD:=so_PW1}
30 NEW_SO_PIN2=${NEW_P11_SO_PWD2:=so_PW2}
31 BAD_PIN=bad
32
33 CKR_PIN_EXPIRED=163
34 CKR_PIN_INVALID=161
35 CKR_PIN_INCORRECT=160
36 CKR_USER_PIN_NOT_INITIALIZED=2
37 CKR_OK=0
38
39 #init the token
40 ./init_tok $* -pass $DEFAULT_SO_PIN
41 if test $? -ne $CKR_OK; then
42 echo "TEST FAIL"
43 exit
44 fi
45
46 # Try to login as SO with a bad pass
47 ./login $* -so -pass bad
48 if test $? -ne $CKR_PIN_INCORRECT; then
49 echo "TEST FAIL"
50 exit
51 fi
52
53 # Try to login as USER before init
54 ./login $* -user -pass $DEFAULT_USER_PIN
55 if test $? -ne $CKR_USER_PIN_NOT_INITIALIZED; then
56 echo "TEST FAIL"
57 exit
58 fi
59
60 # Try a correct SO login, should SUCCEED
61 ./login $* -so -pass $DEFAULT_SO_PIN
62 if test $? -ne $CKR_OK; then
63 echo "TEST FAIL"
64 exit
65 fi
66
67 # Try to do something after logging in before PIN is set
68 ./digest_init $* -so -pass $DEFAULT_SO_PIN
69 if test $? -ne $CKR_PIN_EXPIRED; then
70 echo "TEST FAIL"
71 exit
72 fi
73
74 # Try to set pin to the default value
75 ./set_pin $* -so -old $DEFAULT_SO_PIN -new $DEFAULT_SO_PIN
76 if test $? -ne $CKR_PIN_INVALID; then
77 echo "TEST FAIL"
78 exit
79 fi
80
81 # Do a legitimate pin set for the SO
82 ./set_pin $* -so -old $DEFAULT_SO_PIN -new $NEW_SO_PIN1
83 if test $? -ne $CKR_OK; then
84 echo "TEST FAIL"
85 exit
86 fi
87
88 # Init the USER PIN
89 ./init_pin $* -sopass $NEW_SO_PIN1 -userpass $DEFAULT_USER_PIN
90 if test $? -ne $CKR_OK; then
91 echo "TEST_FAIL"
92 exit
93 fi
94
95 # Try to set pin to the default value
96 ./set_pin $* -user -old $DEFAULT_USER_PIN -new $DEFAULT_USER_PIN
97 if test $? -ne $CKR_PIN_INVALID; then
98 echo "TEST FAIL"
99 exit
100 fi
101
102 # Do a legitimate pin set for the USER
103 ./set_pin $* -user -old $DEFAULT_USER_PIN -new $NEW_USER_PIN1
104 if test $? -ne $CKR_OK; then
105 echo "TEST FAIL"
106 exit
107 fi
108
109 # login with the good pins
110 ./login $* -so -pass $NEW_SO_PIN1
111 if test $? -ne $CKR_OK; then
112 echo "TEST FAIL"
113 exit
114 fi
115
116 ./login $* -user -pass $NEW_USER_PIN1
117 if test $? -ne $CKR_OK; then
118 echo "TEST FAIL"
119 exit
120 fi
121
122 # Try login with bad pins
123 ./login $* -so -pass $BAD_PIN
124 if test $? -ne $CKR_PIN_INCORRECT; then
125 echo "TEST FAIL"
126 exit
127 fi
128
129 ./login $* -user -pass $BAD_PIN
130 if test $? -ne $CKR_PIN_INCORRECT; then
131 echo "TEST FAIL"
132 exit
133 fi
134
135 # try to change both pins back to defaults (should fail)
136 ./set_pin $* -so -old $NEW_SO_PIN1 -new $DEFAULT_SO_PIN
137 if test $? -ne $CKR_PIN_INVALID; then
138 echo "TEST FAIL"
139 exit
140 fi
141
142 ./set_pin $* -user -old $NEW_USER_PIN1 -new $DEFAULT_USER_PIN
143 if test $? -ne $CKR_PIN_INVALID; then
144 echo "TEST FAIL"
145 exit
146 fi
147
148 # change both pins legitimately
149 ./set_pin $* -so -old $NEW_SO_PIN1 -new $NEW_SO_PIN2
150 if test $? -ne $CKR_OK; then
151 echo "TEST FAIL"
152 exit
153 fi
154
155 ./set_pin $* -user -old $NEW_USER_PIN1 -new $NEW_USER_PIN2
156 if test $? -ne $CKR_OK; then
157 echo "TEST FAIL"
158 exit
159 fi
160
161 # login with new passes
162 ./login $* -so -pass $NEW_SO_PIN2
163 if test $? -ne $CKR_OK; then
164 echo "TEST FAIL"
165 exit
166 fi
167
168 ./login $* -user -pass $NEW_USER_PIN2
169 if test $? -ne $CKR_OK; then
170 echo "TEST FAIL"
171 exit
172 fi
173
174 echo "TEST SUCCEEDED"
175
176 echo "Currently the SO Pin is set to \"$NEW_SO_PIN2\""
177 echo "Currently the USER Pin is set to \"$NEW_USER_PIN2\""
178
179 exit 0