4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/types.h>
26 #include <sys/random.h>
29 #include <sys/sunddi.h>
31 #include <sys/socket.h>
35 #include <sys/stmf_ioctl.h>
36 #include <sys/portif.h>
37 #include <sys/idm/idm.h>
38 #include <sys/iscsit/chap.h>
41 #include "radius_auth.h"
44 client_set_numeric_data(auth_key_block_t
*keyBlock
,
50 ASSERT(key_type
< AUTH_KEY_TYPE_MAX
);
52 p
= &keyBlock
->key
[key_type
];
53 p
->value
.numeric
= numeric
;
58 client_set_string_data(auth_key_block_t
*keyBlock
,
64 ASSERT(key_type
< AUTH_KEY_TYPE_MAX
);
66 p
= &keyBlock
->key
[key_type
];
67 p
->value
.string
= string
;
72 client_set_binary_data(auth_key_block_t
*keyBlock
,
74 unsigned char *binary
, unsigned int len
)
78 ASSERT(key_type
< AUTH_KEY_TYPE_MAX
);
80 p
= &keyBlock
->key
[key_type
];
81 p
->value
.binary
= binary
;
87 client_get_numeric_data(auth_key_block_t
*keyBlock
,
93 ASSERT(key_type
< AUTH_KEY_TYPE_MAX
);
95 p
= &keyBlock
->key
[key_type
];
96 *numeric
= p
->value
.numeric
;
100 client_get_string_data(auth_key_block_t
*keyBlock
,
106 ASSERT(key_type
< AUTH_KEY_TYPE_MAX
);
108 p
= &keyBlock
->key
[key_type
];
109 *string
= p
->value
.string
;
113 client_get_binary_data(auth_key_block_t
*keyBlock
,
115 unsigned char **binary
, unsigned int *len
)
119 ASSERT(key_type
< AUTH_KEY_TYPE_MAX
);
121 p
= &keyBlock
->key
[key_type
];
122 *binary
= p
->value
.binary
;
127 client_auth_key_present(auth_key_block_t
*keyBlock
,
132 ASSERT(key_type
< AUTH_KEY_TYPE_MAX
);
134 p
= &keyBlock
->key
[key_type
];
136 return (p
->present
!= 0 ? 1 : 0);
141 client_compute_chap_resp(uchar_t
*resp
,
143 uint8_t *password
, int password_len
,
144 uchar_t
*chap_c
, unsigned int challenge_len
)
153 resp
[0] = (uchar_t
)chap_i
;
154 MD5Update(&context
, resp
, 1);
159 MD5Update(&context
, (uchar_t
*)password
, password_len
);
164 MD5Update(&context
, chap_c
, challenge_len
);
166 MD5Final(resp
, &context
);
170 iscsit_verify_chap_resp(iscsit_conn_login_t
*lsm
,
172 uchar_t
*chap_c
, unsigned int challenge_len
,
173 uchar_t
*chap_r
, unsigned int resp_len
)
175 uchar_t verifyData
[iscsitAuthChapResponseLength
];
176 conn_auth_t
*auth
= &lsm
->icl_auth
;
178 /* Check if RADIUS access is enabled */
179 if (auth
->ca_use_radius
== B_TRUE
) {
180 chap_validation_status_type chap_valid_status
;
181 RADIUS_CONFIG radius_cfg
;
182 struct sockaddr_storage
*sa
= &auth
->ca_radius_server
;
183 struct sockaddr_in
*sin
;
184 struct sockaddr_in6
*sin6
;
186 /* Use RADIUS server to authentication target */
187 sin
= (struct sockaddr_in
*)sa
;
188 radius_cfg
.rad_svr_port
= ntohs(sin
->sin_port
);
189 if (sa
->ss_family
== AF_INET
) {
191 radius_cfg
.rad_svr_addr
.i_addr
.in4
.s_addr
=
192 sin
->sin_addr
.s_addr
;
193 radius_cfg
.rad_svr_addr
.i_insize
= sizeof (in_addr_t
);
194 } else if (sa
->ss_family
== AF_INET6
) {
196 sin6
= (struct sockaddr_in6
*)sa
;
197 bcopy(sin6
->sin6_addr
.s6_addr
,
198 radius_cfg
.rad_svr_addr
.i_addr
.in6
.s6_addr
,
199 sizeof (struct in6_addr
));
200 radius_cfg
.rad_svr_addr
.i_insize
= sizeof (in6_addr_t
);
202 return (ISCSI_AUTH_FAILED
);
205 bcopy(auth
->ca_radius_secret
,
206 radius_cfg
.rad_svr_shared_secret
,
207 MAX_RAD_SHARED_SECRET_LEN
);
208 radius_cfg
.rad_svr_shared_secret_len
=
209 auth
->ca_radius_secretlen
;
211 chap_valid_status
= iscsit_radius_chap_validate(
212 auth
->ca_ini_chapuser
,
213 auth
->ca_tgt_chapuser
,
219 radius_cfg
.rad_svr_addr
,
220 radius_cfg
.rad_svr_port
,
221 radius_cfg
.rad_svr_shared_secret
,
222 radius_cfg
.rad_svr_shared_secret_len
);
224 if (chap_valid_status
== CHAP_VALIDATION_PASSED
) {
225 return (ISCSI_AUTH_PASSED
);
227 return (ISCSI_AUTH_FAILED
);
230 /* Empty chap secret is not allowed */
231 if (auth
->ca_ini_chapsecretlen
== 0) {
232 return (ISCSI_AUTH_FAILED
);
235 /* only MD5 is supported */
236 if (resp_len
!= sizeof (verifyData
)) {
237 return (ISCSI_AUTH_FAILED
);
240 client_compute_chap_resp(
243 auth
->ca_ini_chapsecret
, auth
->ca_ini_chapsecretlen
,
244 chap_c
, challenge_len
);
246 if (bcmp(chap_r
, verifyData
,
247 sizeof (verifyData
)) != 0) {
248 return (ISCSI_AUTH_FAILED
);
251 /* chap response OK */
252 return (ISCSI_AUTH_PASSED
);
256 auth_random_set_data(uchar_t
*data
, unsigned int length
)
258 (void) random_get_pseudo_bytes(data
, length
);