Revision 733538a4

b/src/charon/encoding/message.c
161 161
static payload_order_t ike_sa_init_i_payload_order[] = {
162 162
/*	payload type					notify type */
163 163
	{NOTIFY,						COOKIE},
164
	{SECURITY_ASSOCIATION, 			0},
165
	{KEY_EXCHANGE, 					0},
166
	{NONCE, 						0},
164
	{SECURITY_ASSOCIATION,			0},
165
	{KEY_EXCHANGE,					0},
166
	{NONCE,							0},
167 167
	{NOTIFY,						NAT_DETECTION_SOURCE_IP},
168 168
	{NOTIFY,						NAT_DETECTION_DESTINATION_IP},
169 169
	{NOTIFY,						0},
......
187 187
 */
188 188
static payload_order_t ike_sa_init_r_payload_order[] = {
189 189
/*	payload type					notify type */
190
	{SECURITY_ASSOCIATION, 			0},
191
	{KEY_EXCHANGE, 					0},
192
	{NONCE, 						0},
190
	{SECURITY_ASSOCIATION,			0},
191
	{KEY_EXCHANGE,					0},
192
	{NONCE,							0},
193 193
	{NOTIFY,						NAT_DETECTION_SOURCE_IP},
194 194
	{NOTIFY,						NAT_DETECTION_DESTINATION_IP},
195 195
	{NOTIFY,						HTTP_CERT_LOOKUP_SUPPORTED},
......
241 241
	{NOTIFY,						USE_TRANSPORT_MODE},
242 242
	{NOTIFY,						ESP_TFC_PADDING_NOT_SUPPORTED},
243 243
	{NOTIFY,						NON_FIRST_FRAGMENTS_ALSO},
244
	{SECURITY_ASSOCIATION, 			0},
244
	{SECURITY_ASSOCIATION,			0},
245 245
	{TRAFFIC_SELECTOR_INITIATOR,	0},
246 246
	{TRAFFIC_SELECTOR_RESPONDER,	0},
247 247
	{NOTIFY,						MOBIKE_SUPPORTED},
......
283 283
	{NOTIFY,						USE_TRANSPORT_MODE},
284 284
	{NOTIFY,						ESP_TFC_PADDING_NOT_SUPPORTED},
285 285
	{NOTIFY,						NON_FIRST_FRAGMENTS_ALSO},
286
	{SECURITY_ASSOCIATION, 			0},
286
	{SECURITY_ASSOCIATION,			0},
287 287
	{TRAFFIC_SELECTOR_INITIATOR,	0},
288 288
	{TRAFFIC_SELECTOR_RESPONDER,	0},
289 289
	{NOTIFY,						AUTH_LIFETIME},
......
370 370
	{NOTIFY,						USE_TRANSPORT_MODE},
371 371
	{NOTIFY,						ESP_TFC_PADDING_NOT_SUPPORTED},
372 372
	{NOTIFY,						NON_FIRST_FRAGMENTS_ALSO},
373
	{SECURITY_ASSOCIATION, 			0},
373
	{SECURITY_ASSOCIATION,			0},
374 374
	{NONCE,							0},
375
	{KEY_EXCHANGE, 					0},
375
	{KEY_EXCHANGE,					0},
376 376
	{TRAFFIC_SELECTOR_INITIATOR,	0},
377 377
	{TRAFFIC_SELECTOR_RESPONDER,	0},
378 378
	{NOTIFY,						0},
......
402 402
	{NOTIFY,						USE_TRANSPORT_MODE},
403 403
	{NOTIFY,						ESP_TFC_PADDING_NOT_SUPPORTED},
404 404
	{NOTIFY,						NON_FIRST_FRAGMENTS_ALSO},
405
	{SECURITY_ASSOCIATION, 			0},
405
	{SECURITY_ASSOCIATION,			0},
406 406
	{NONCE,							0},
407
	{KEY_EXCHANGE, 					0},
407
	{KEY_EXCHANGE,					0},
408 408
	{TRAFFIC_SELECTOR_INITIATOR,	0},
409 409
	{TRAFFIC_SELECTOR_RESPONDER,	0},
410 410
	{NOTIFY,						ADDITIONAL_TS_POSSIBLE},
......
612 612
/**
613 613
 * Implementation of private_message_t.get_payload_rule.
614 614
 */
615
static status_t get_payload_rule(private_message_t *this, payload_type_t payload_type, payload_rule_t **payload_rule)
615
static status_t get_payload_rule(private_message_t *this,
616
					payload_type_t payload_type, payload_rule_t **payload_rule)
616 617
{
617 618
	int i;
618 619

  
......
632 633
/**
633 634
 * Implementation of message_t.set_ike_sa_id.
634 635
 */
635
static void set_ike_sa_id (private_message_t *this,ike_sa_id_t *ike_sa_id)
636
static void set_ike_sa_id(private_message_t *this,ike_sa_id_t *ike_sa_id)
636 637
{
637 638
	DESTROY_IF(this->ike_sa_id);
638 639
	this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
......
641 642
/**
642 643
 * Implementation of message_t.get_ike_sa_id.
643 644
 */
644
static ike_sa_id_t* get_ike_sa_id (private_message_t *this)
645
static ike_sa_id_t* get_ike_sa_id(private_message_t *this)
645 646
{
646 647
	return this->ike_sa_id;
647 648
}
......
649 650
/**
650 651
 * Implementation of message_t.set_message_id.
651 652
 */
652
static void set_message_id (private_message_t *this,u_int32_t message_id)
653
static void set_message_id(private_message_t *this,u_int32_t message_id)
653 654
{
654 655
	this->message_id = message_id;
655 656
}
......
657 658
/**
658 659
 * Implementation of message_t.get_message_id.
659 660
 */
660
static u_int32_t get_message_id (private_message_t *this)
661
static u_int32_t get_message_id(private_message_t *this)
661 662
{
662 663
	return this->message_id;
663 664
}
......
665 666
/**
666 667
 * Implementation of message_t.get_initiator_spi.
667 668
 */
668
static u_int64_t get_initiator_spi (private_message_t *this)
669
static u_int64_t get_initiator_spi(private_message_t *this)
669 670
{
670 671
	return (this->ike_sa_id->get_initiator_spi(this->ike_sa_id));
671 672
}
......
673 674
/**
674 675
 * Implementation of message_t.get_responder_spi.
675 676
 */
676
static u_int64_t get_responder_spi (private_message_t *this)
677
static u_int64_t get_responder_spi(private_message_t *this)
677 678
{
678 679
	return (this->ike_sa_id->get_responder_spi(this->ike_sa_id));
679 680
}
......
681 682
/**
682 683
 * Implementation of message_t.set_major_version.
683 684
 */
684
static void set_major_version (private_message_t *this,u_int8_t major_version)
685
static void set_major_version(private_message_t *this,u_int8_t major_version)
685 686
{
686 687
	this->major_version = major_version;
687 688
}
688 689

  
689

  
690 690
/**
691 691
 * Implementation of message_t.set_major_version.
692 692
 */
693
static u_int8_t get_major_version (private_message_t *this)
693
static u_int8_t get_major_version(private_message_t *this)
694 694
{
695 695
	return this->major_version;
696 696
}
......
698 698
/**
699 699
 * Implementation of message_t.set_minor_version.
700 700
 */
701
static void set_minor_version (private_message_t *this,u_int8_t minor_version)
701
static void set_minor_version(private_message_t *this,u_int8_t minor_version)
702 702
{
703 703
	this->minor_version = minor_version;
704 704
}
......
706 706
/**
707 707
 * Implementation of message_t.get_minor_version.
708 708
 */
709
static u_int8_t get_minor_version (private_message_t *this)
709
static u_int8_t get_minor_version(private_message_t *this)
710 710
{
711 711
	return this->minor_version;
712 712
}
......
714 714
/**
715 715
 * Implementation of message_t.set_exchange_type.
716 716
 */
717
static void set_exchange_type (private_message_t *this,exchange_type_t exchange_type)
717
static void set_exchange_type(private_message_t *this,
718
							  exchange_type_t exchange_type)
718 719
{
719 720
	this->exchange_type = exchange_type;
720 721
}
......
722 723
/**
723 724
 * Implementation of message_t.get_exchange_type.
724 725
 */
725
static exchange_type_t get_exchange_type (private_message_t *this)
726
static exchange_type_t get_exchange_type(private_message_t *this)
726 727
{
727 728
	return this->exchange_type;
728 729
}
......
730 731
/**
731 732
 * Implementation of message_t.get_first_payload_type.
732 733
 */
733
static payload_type_t get_first_payload_type (private_message_t *this)
734
static payload_type_t get_first_payload_type(private_message_t *this)
734 735
{
735 736
	return this->first_payload;
736 737
}
......
738 739
/**
739 740
 * Implementation of message_t.set_request.
740 741
 */
741
static void set_request (private_message_t *this,bool request)
742
static void set_request(private_message_t *this, bool request)
742 743
{
743 744
	this->is_request = request;
744 745
}
......
746 747
/**
747 748
 * Implementation of message_t.get_request.
748 749
 */
749
static exchange_type_t get_request (private_message_t *this)
750
static exchange_type_t get_request(private_message_t *this)
750 751
{
751 752
	return this->is_request;
752 753
}
......
1152 1153
	ike_header->set_exchange_type(ike_header, this->exchange_type);
1153 1154
	ike_header->set_message_id(ike_header, this->message_id);
1154 1155
	ike_header->set_response_flag(ike_header, !this->is_request);
1155
	ike_header->set_initiator_flag(ike_header, this->ike_sa_id->is_initiator(this->ike_sa_id));
1156
	ike_header->set_initiator_spi(ike_header, this->ike_sa_id->get_initiator_spi(this->ike_sa_id));
1157
	ike_header->set_responder_spi(ike_header, this->ike_sa_id->get_responder_spi(this->ike_sa_id));
1156
	ike_header->set_initiator_flag(ike_header,
1157
						this->ike_sa_id->is_initiator(this->ike_sa_id));
1158
	ike_header->set_initiator_spi(ike_header,
1159
						this->ike_sa_id->get_initiator_spi(this->ike_sa_id));
1160
	ike_header->set_responder_spi(ike_header,
1161
						this->ike_sa_id->get_responder_spi(this->ike_sa_id));
1158 1162

  
1159 1163
	generator = generator_create();
1160 1164

  
......
1205 1209
/**
1206 1210
 * Implementation of message_t.get_packet.
1207 1211
 */
1208
static packet_t *get_packet (private_message_t *this)
1212
static packet_t *get_packet(private_message_t *this)
1209 1213
{
1210 1214
	if (this->packet == NULL)
1211 1215
	{
......
1217 1221
/**
1218 1222
 * Implementation of message_t.get_packet_data.
1219 1223
 */
1220
static chunk_t get_packet_data (private_message_t *this)
1224
static chunk_t get_packet_data(private_message_t *this)
1221 1225
{
1222 1226
	if (this->packet == NULL)
1223 1227
	{
......
1237 1241
	DBG2(DBG_ENC, "parsing header of message");
1238 1242

  
1239 1243
	this->parser->reset_context(this->parser);
1240
	status = this->parser->parse_payload(this->parser,HEADER,(payload_t **) &ike_header);
1244
	status = this->parser->parse_payload(this->parser, HEADER,
1245
										 (payload_t**)&ike_header);
1241 1246
	if (status != SUCCESS)
1242 1247
	{
1243 1248
		DBG1(DBG_ENC, "header could not be parsed");
......
1246 1251
	}
1247 1252

  
1248 1253
	/* verify payload */
1249
	status = ike_header->payload_interface.verify(&(ike_header->payload_interface));
1254
	status = ike_header->payload_interface.verify(
1255
										&ike_header->payload_interface);
1250 1256
	if (status != SUCCESS)
1251 1257
	{
1252 1258
		DBG1(DBG_ENC, "header verification failed");
......
1260 1266
	}
1261 1267

  
1262 1268
	this->ike_sa_id = ike_sa_id_create(ike_header->get_initiator_spi(ike_header),
1263
									   ike_header->get_responder_spi(ike_header),
1264
									   ike_header->get_initiator_flag(ike_header));
1269
									ike_header->get_responder_spi(ike_header),
1270
									ike_header->get_initiator_flag(ike_header));
1265 1271

  
1266 1272
	this->exchange_type = ike_header->get_exchange_type(ike_header);
1267 1273
	this->message_id = ike_header->get_message_id(ike_header);
1268 1274
	this->is_request = (!(ike_header->get_response_flag(ike_header)));
1269 1275
	this->major_version = ike_header->get_maj_version(ike_header);
1270 1276
	this->minor_version = ike_header->get_min_version(ike_header);
1271
	this->first_payload = ike_header->payload_interface.get_next_type(&(ike_header->payload_interface));
1277
	this->first_payload = ike_header->payload_interface.get_next_type(
1278
												&ike_header->payload_interface);
1272 1279

  
1273 1280
	DBG2(DBG_ENC, "parsed a %N %s", exchange_type_names, this->exchange_type,
1274 1281
		 this->is_request ? "request" : "response");
......
1290 1297
/**
1291 1298
 * Implementation of private_message_t.decrypt_and_verify_payloads.
1292 1299
 */
1293
static status_t decrypt_payloads(private_message_t *this,crypter_t *crypter, signer_t* signer)
1300
static status_t decrypt_payloads(private_message_t *this, crypter_t *crypter,
1301
								 signer_t* signer)
1294 1302
{
1295 1303
	bool current_payload_was_encrypted = FALSE;
1296 1304
	payload_t *previous_payload = NULL;
......
1330 1338
				return VERIFY_ERROR;
1331 1339
			}
1332 1340
			/* decrypt */
1333
			encryption_payload->set_transforms(encryption_payload, crypter, signer);
1341
			encryption_payload->set_transforms(encryption_payload,
1342
											   crypter, signer);
1334 1343
			DBG2(DBG_ENC, "verify signature of encryption payload");
1335 1344
			status = encryption_payload->verify_signature(encryption_payload,
1336 1345
										this->packet->get_data(this->packet));
......
1363 1372
			}
1364 1373
			else
1365 1374
			{
1366
				/* encryption_payload is replaced with first payload contained in encryption_payload */
1367
				encryption_payload->remove_first_payload(encryption_payload, &current_encrypted_payload);
1368
				iterator->replace(iterator,NULL,(void *) current_encrypted_payload);
1369
				current_payload_type = current_encrypted_payload->get_type(current_encrypted_payload);
1375
				/* encryption_payload is replaced with first payload contained
1376
				 * in encryption_payload */
1377
				encryption_payload->remove_first_payload(encryption_payload,
1378
													&current_encrypted_payload);
1379
				iterator->replace(iterator, NULL,
1380
								  (void *)current_encrypted_payload);
1381
				current_payload_type = current_encrypted_payload->get_type(
1382
													current_encrypted_payload);
1370 1383
			}
1371 1384

  
1372 1385
			/* is the current paylad the first in the message? */
1373 1386
			if (previous_payload == NULL)
1374 1387
			{
1375
				/* yes, set the first payload type of the message to the current type */
1388
				/* yes, set the first payload type of the message to the
1389
				 * current type */
1376 1390
				this->first_payload = current_payload_type;
1377 1391
			}
1378 1392
			else
1379 1393
			{
1380
				/* no, set the next_type of the previous payload to the current type */
1381
				previous_payload->set_next_type(previous_payload, current_payload_type);
1394
				/* no, set the next_type of the previous payload to the
1395
				 * current type */
1396
				previous_payload->set_next_type(previous_payload,
1397
												current_payload_type);
1382 1398
			}
1383 1399

  
1384 1400
			/* all encrypted payloads are added to the payload list */
1385 1401
			while (encryption_payload->get_payload_count(encryption_payload) > 0)
1386 1402
			{
1387
				encryption_payload->remove_first_payload(encryption_payload, &current_encrypted_payload);
1388
				DBG2(DBG_ENC, "insert unencrypted payload of type %N at end of list",
1389
					 payload_type_names, current_encrypted_payload->get_type(current_encrypted_payload));
1390
				this->payloads->insert_last(this->payloads,current_encrypted_payload);
1403
				encryption_payload->remove_first_payload(encryption_payload,
1404
													&current_encrypted_payload);
1405
				DBG2(DBG_ENC, "insert unencrypted payload of type "
1406
					 "%N at end of list", payload_type_names,
1407
					 current_encrypted_payload->get_type(
1408
											current_encrypted_payload));
1409
				this->payloads->insert_last(this->payloads,
1410
											current_encrypted_payload);
1391 1411
			}
1392 1412

  
1393 1413
			/* encryption payload is processed, payloads are moved. Destroy it. */
1394 1414
			encryption_payload->destroy(encryption_payload);
1395 1415
		}
1396 1416

  
1397
		/* we allow unknown payloads of any type and don't bother if it was encrypted. Not our problem. */
1398
		if (current_payload_type != UNKNOWN_PAYLOAD && current_payload_type != NO_PAYLOAD)
1417
		/* we allow unknown payloads of any type and don't bother if it was
1418
		 * encrypted. Not our problem. */
1419
		if (current_payload_type != UNKNOWN_PAYLOAD &&
1420
			current_payload_type != NO_PAYLOAD)
1399 1421
		{
1400 1422
			/* get the ruleset for found payload */
1401 1423
			status = get_payload_rule(this, current_payload_type, &payload_rule);
......
1408 1430
				return VERIFY_ERROR;
1409 1431
			}
1410 1432

  
1411
			/* check if the payload was encrypted, and if it should been have encrypted */
1433
			/* check if the payload was encrypted, and if it should been have
1434
			 * encrypted */
1412 1435
			if (payload_rule->encrypted != current_payload_was_encrypted)
1413 1436
			{
1414
				/* payload was not encrypted, but should have been. or vice-versa */
1437
				/* payload was not encrypted, but should have been.
1438
				 * or vice-versa */
1415 1439
				DBG1(DBG_ENC, "payload type %N should be %s!",
1416 1440
					 payload_type_names, current_payload_type,
1417 1441
					 (payload_rule->encrypted) ? "encrypted" : "not encrypted");
......
1512 1536
/**
1513 1537
 * Implementation of message_t.parse_body.
1514 1538
 */
1515
static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t *signer)
1539
static status_t parse_body(private_message_t *this, crypter_t *crypter,
1540
						   signer_t *signer)
1516 1541
{
1517 1542
	status_t status = SUCCESS;
1518 1543
	payload_type_t current_payload_type;
......
1532 1557
			 payload_type_names, current_payload_type);
1533 1558

  
1534 1559
		/* parse current payload */
1535
		status = this->parser->parse_payload(this->parser,current_payload_type,(payload_t **) &current_payload);
1536

  
1560
		status = this->parser->parse_payload(this->parser, current_payload_type,
1561
											 (payload_t**)&current_payload);
1537 1562
		if (status != SUCCESS)
1538 1563
		{
1539 1564
			DBG1(DBG_ENC, "payload type %N could not be parsed",
......
1558 1583
			 payload_type_names, current_payload_type);
1559 1584
		this->payloads->insert_last(this->payloads,current_payload);
1560 1585

  
1561
		/* an encryption payload is the last one, so STOP here. decryption is done later */
1586
		/* an encryption payload is the last one, so STOP here. decryption is
1587
		 * done later */
1562 1588
		if (current_payload_type == ENCRYPTED)
1563 1589
		{
1564 1590
			DBG2(DBG_ENC, "%N payload found. Stop parsing",

Also available in: Unified diff