aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/security/KeyStoreException.java
diff options
context:
space:
mode:
authorRichard Henderson <rth@gcc.gnu.org>2003-01-28 14:08:24 -0800
committerRichard Henderson <rth@gcc.gnu.org>2003-01-28 14:08:24 -0800
commit1e1bd14eb2e457e969b82e4e14e7d4efdc4f3fc8 (patch)
treef2589fe0432d26e56b8bf94d6226660983e179ba /libjava/java/security/KeyStoreException.java
parent4ce1921a71d41e4cd8b59ed7bbdad831c4918537 (diff)
downloadgcc-1e1bd14eb2e457e969b82e4e14e7d4efdc4f3fc8.zip
gcc-1e1bd14eb2e457e969b82e4e14e7d4efdc4f3fc8.tar.gz
gcc-1e1bd14eb2e457e969b82e4e14e7d4efdc4f3fc8.tar.bz2
ia64.c (ia64_rwreloc_section_type_flags): New.
* config/ia64/ia64.c (ia64_rwreloc_section_type_flags): New. * config/ia64/hpux.h (TARGET_SECTION_TYPE_FLAGS): New. From-SVN: r62028
Diffstat (limited to 'libjava/java/security/KeyStoreException.java')
0 files changed, 0 insertions, 0 deletions
id='n100' href='#n100'>100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
/*
 * Copyright (C) 2021 Michael Brown <mbrown@fensystems.co.uk>.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 * You can also choose to distribute this program under the terms of
 * the Unmodified Binary Distribution Licence (as given in the file
 * COPYING.UBDL), provided that you have satisfied its requirements.
 */

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <byteswap.h>
#include <ipxe/netdevice.h>
#include <ipxe/md5.h>
#include <ipxe/chap.h>
#include <ipxe/eap.h>

/** @file
 *
 * Extensible Authentication Protocol
 *
 */

/**
 * Transmit EAP response
 *
 * @v supplicant	EAP supplicant
 * @v rsp		Response type data
 * @v rsp_len		Length of response type data
 * @ret rc		Return status code
 */
static int eap_tx_response ( struct eap_supplicant *supplicant,
			     const void *rsp, size_t rsp_len ) {
	struct net_device *netdev = supplicant->netdev;
	struct eap_message *msg;
	size_t len;
	int rc;

	/* Allocate and populate response */
	len = ( sizeof ( *msg ) + rsp_len );
	msg = malloc ( len );
	if ( ! msg ) {
		rc = -ENOMEM;
		goto err_alloc;
	}
	msg->hdr.code = EAP_CODE_RESPONSE;
	msg->hdr.id = supplicant->id;
	msg->hdr.len = htons ( len );
	msg->type = supplicant->type;
	memcpy ( msg->data, rsp, rsp_len );
	DBGC ( netdev, "EAP %s Response id %#02x type %d\n",
	       netdev->name, msg->hdr.id, msg->type );

	/* Transmit response */
	if ( ( rc = supplicant->tx ( supplicant, msg, len ) ) != 0 ) {
		DBGC ( netdev, "EAP %s could not transmit: %s\n",
		       netdev->name, strerror ( rc ) );
		goto err_tx;
	}

 err_tx:
	free ( msg );
 err_alloc:
	return rc;
}

/**
 * Transmit EAP NAK
 *
 * @v supplicant	EAP supplicant
 * @ret rc		Return status code
 */
static int eap_tx_nak ( struct eap_supplicant *supplicant ) {
	struct net_device *netdev = supplicant->netdev;
	unsigned int max = table_num_entries ( EAP_METHODS );
	uint8_t methods[ max + 1 /* potential EAP_TYPE_NONE */ ];
	unsigned int count = 0;
	struct eap_method *method;

	/* Populate methods list */
	DBGC ( netdev, "EAP %s Nak offering types {", netdev->name );
	for_each_table_entry ( method, EAP_METHODS ) {
		if ( method->type > EAP_TYPE_NAK ) {
			DBGC ( netdev, "%s%d",
			       ( count ? ", " : "" ), method->type );
			methods[count++] = method->type;
		}
	}
	if ( ! count )
		methods[count++] = EAP_TYPE_NONE;
	DBGC ( netdev, "}\n" );
	assert ( count <= max );

	/* Transmit response */
	supplicant->type = EAP_TYPE_NAK;
	return eap_tx_response ( supplicant, methods, count );
}

/**
 * Handle EAP Request-Identity
 *
 * @v supplicant	EAP supplicant
 * @v req		Request type data
 * @v req_len		Length of request type data
 * @ret rc		Return status code
 */
static int eap_rx_identity ( struct eap_supplicant *supplicant,
			     const void *req, size_t req_len ) {
	struct net_device *netdev = supplicant->netdev;
	void *rsp;
	int rsp_len;
	int rc;

	/* Treat Request-Identity as blocking the link */
	DBGC ( netdev, "EAP %s Request-Identity blocking link\n",
	       netdev->name );
	DBGC_HDA ( netdev, 0, req, req_len );
	netdev_link_block ( netdev, EAP_BLOCK_TIMEOUT );

	/* Mark EAP as in progress */
	supplicant->flags |= EAP_FL_ONGOING;

	/* Construct response, if applicable */
	rsp_len = fetch_raw_setting_copy ( netdev_settings ( netdev ),
					   &username_setting, &rsp );
	if ( rsp_len < 0 ) {
		/* We have no identity to offer, so wait until the
		 * switch times out and switches to MAC Authentication
		 * Bypass (MAB).
		 */
		DBGC2 ( netdev, "EAP %s has no identity\n", netdev->name );
		supplicant->flags |= EAP_FL_PASSIVE;
		rc = 0;
		goto no_response;
	}

	/* Transmit response */
	if ( ( rc = eap_tx_response ( supplicant, rsp, rsp_len ) ) != 0 )
		goto err_tx;

 err_tx:
	free ( rsp );
 no_response:
	return rc;
}

/** EAP Request-Identity method */
struct eap_method eap_identity_method __eap_method = {
	.type = EAP_TYPE_IDENTITY,
	.rx = eap_rx_identity,
};

/**
 * Handle EAP MD5-Challenge
 *
 * @v req		Request type data
 * @v req_len		Length of request type data
 * @ret rc		Return status code
 */
static int eap_rx_md5 ( struct eap_supplicant *supplicant,
			const void *req, size_t req_len ) {
	struct net_device *netdev = supplicant->netdev;
	const struct eap_md5 *md5req = req;
	struct {
		uint8_t len;
		uint8_t value[MD5_DIGEST_SIZE];
	} __attribute__ (( packed )) md5rsp;
	struct chap_response chap;
	void *secret;
	int secret_len;
	int rc;

	/* Sanity checks */
	if ( req_len < sizeof ( *md5req ) ) {
		DBGC ( netdev, "EAP %s underlength MD5-Challenge:\n",
		       netdev->name );
		DBGC_HDA ( netdev, 0, req, req_len );
		rc = -EINVAL;
		goto err_sanity;
	}
	if ( ( req_len - sizeof ( *md5req ) ) < md5req->len ) {
		DBGC ( netdev, "EAP %s truncated MD5-Challenge:\n",
		       netdev->name );
		DBGC_HDA ( netdev, 0, req, req_len );
		rc = -EINVAL;
		goto err_sanity;
	}

	/* Construct response */
	if ( ( rc = chap_init ( &chap, &md5_algorithm ) ) != 0 ) {
		DBGC ( netdev, "EAP %s could not initialise CHAP: %s\n",
		       netdev->name, strerror ( rc ) );
		goto err_chap;
	}
	chap_set_identifier ( &chap, supplicant->id );
	secret_len = fetch_raw_setting_copy ( netdev_settings ( netdev ),
					      &password_setting, &secret );
	if ( secret_len < 0 ) {
		rc = secret_len;
		DBGC ( netdev, "EAP %s has no secret: %s\n",
		       netdev->name, strerror ( rc ) );
		goto err_secret;
	}
	chap_update ( &chap, secret, secret_len );
	chap_update ( &chap, md5req->value, md5req->len );
	chap_respond ( &chap );
	assert ( chap.response_len == sizeof ( md5rsp.value ) );
	md5rsp.len = sizeof ( md5rsp.value );
	memcpy ( md5rsp.value, chap.response, sizeof ( md5rsp.value ) );

	/* Transmit response */
	if ( ( rc = eap_tx_response ( supplicant, &md5rsp,
				      sizeof ( md5rsp ) ) ) != 0 )
		goto err_tx;

 err_tx:
	free ( secret );
 err_secret:
	chap_finish ( &chap );
 err_chap:
 err_sanity:
	return rc;
}

/** EAP MD5-Challenge method */
struct eap_method eap_md5_method __eap_method = {
	.type = EAP_TYPE_MD5,
	.rx = eap_rx_md5,
};

/**
 * Handle EAP Request
 *
 * @v supplicant	EAP supplicant
 * @v msg		EAP request
 * @v len		Length of EAP request
 * @ret rc		Return status code
 */
static int eap_rx_request ( struct eap_supplicant *supplicant,
			    const struct eap_message *msg, size_t len ) {
	struct net_device *netdev = supplicant->netdev;
	struct eap_method *method;
	const void *req;
	size_t req_len;

	/* Sanity checks */
	if ( len < sizeof ( *msg ) ) {
		DBGC ( netdev, "EAP %s underlength request:\n", netdev->name );
		DBGC_HDA ( netdev, 0, msg, len );
		return -EINVAL;
	}
	if ( len < ntohs ( msg->hdr.len ) ) {
		DBGC ( netdev, "EAP %s truncated request:\n", netdev->name );
		DBGC_HDA ( netdev, 0, msg, len );
		return -EINVAL;
	}
	req = msg->data;
	req_len = ( ntohs ( msg->hdr.len ) - sizeof ( *msg ) );

	/* Record request details */
	supplicant->id = msg->hdr.id;
	supplicant->type = msg->type;
	DBGC ( netdev, "EAP %s Request id %#02x type %d\n",
	       netdev->name, msg->hdr.id, msg->type );

	/* Handle according to type */
	for_each_table_entry ( method, EAP_METHODS ) {
		if ( msg->type == method->type )
			return method->rx ( supplicant, req, req_len );
	}
	DBGC ( netdev, "EAP %s requested type %d unknown:\n",
	       netdev->name, msg->type );
	DBGC_HDA ( netdev, 0, msg, len );

	/* Send NAK if applicable */
	if ( msg->type > EAP_TYPE_NAK )
		return eap_tx_nak ( supplicant );

	return -ENOTSUP;
}

/**
 * Handle EAP Success
 *
 * @v supplicant	EAP supplicant
 * @ret rc		Return status code
 */
static int eap_rx_success ( struct eap_supplicant *supplicant ) {
	struct net_device *netdev = supplicant->netdev;

	/* Mark authentication as complete */
	supplicant->flags = EAP_FL_PASSIVE;

	/* Mark link as unblocked */
	DBGC ( netdev, "EAP %s Success\n", netdev->name );
	netdev_link_unblock ( netdev );

	return 0;
}

/**
 * Handle EAP Failure
 *
 * @v supplicant	EAP supplicant
 * @ret rc		Return status code
 */
static int eap_rx_failure ( struct eap_supplicant *supplicant ) {
	struct net_device *netdev = supplicant->netdev;

	/* Mark authentication as complete */
	supplicant->flags = EAP_FL_PASSIVE;

	/* Record error */
	DBGC ( netdev, "EAP %s Failure\n", netdev->name );
	return -EPERM;
}

/**
 * Handle EAP packet
 *
 * @v supplicant	EAP supplicant
 * @v data		EAP packet
 * @v len		Length of EAP packet
 * @ret rc		Return status code
 */
int eap_rx ( struct eap_supplicant *supplicant, const void *data,
	     size_t len ) {
	struct net_device *netdev = supplicant->netdev;
	const union eap_packet *eap = data;

	/* Sanity check */
	if ( len < sizeof ( eap->hdr ) ) {
		DBGC ( netdev, "EAP %s underlength header:\n", netdev->name );
		DBGC_HDA ( netdev, 0, eap, len );
		return -EINVAL;
	}

	/* Handle according to code */
	switch ( eap->hdr.code ) {
	case EAP_CODE_REQUEST:
		return eap_rx_request ( supplicant, &eap->msg, len );
	case EAP_CODE_RESPONSE:
		DBGC2 ( netdev, "EAP %s ignoring response\n", netdev->name );
		return 0;
	case EAP_CODE_SUCCESS:
		return eap_rx_success ( supplicant );
	case EAP_CODE_FAILURE:
		return eap_rx_failure ( supplicant );
	default:
		DBGC ( netdev, "EAP %s unsupported code %d\n",
		       netdev->name, eap->hdr.code );
		DBGC_HDA ( netdev, 0, eap, len );
		return -ENOTSUP;
	}
}