2 * Copyright (c) 2012 The FreeBSD Foundation
5 * This software was developed by Edward Tomasz Napierala under sponsorship
6 * from the FreeBSD Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/types.h>
38 #include <netinet/in.h>
39 #include <openssl/err.h>
40 #include <openssl/md5.h>
41 #include <openssl/rand.h>
44 #include "iscsi_proto.h"
47 login_nsg(const struct pdu *response)
49 struct iscsi_bhs_login_response *bhslr;
51 bhslr = (struct iscsi_bhs_login_response *)response->pdu_bhs;
53 return (bhslr->bhslr_flags & 0x03);
57 login_set_nsg(struct pdu *request, int nsg)
59 struct iscsi_bhs_login_request *bhslr;
61 assert(nsg == BHSLR_STAGE_SECURITY_NEGOTIATION ||
62 nsg == BHSLR_STAGE_OPERATIONAL_NEGOTIATION ||
63 nsg == BHSLR_STAGE_FULL_FEATURE_PHASE);
65 bhslr = (struct iscsi_bhs_login_request *)request->pdu_bhs;
67 bhslr->bhslr_flags &= 0xFC;
68 bhslr->bhslr_flags |= nsg;
72 login_set_csg(struct pdu *request, int csg)
74 struct iscsi_bhs_login_request *bhslr;
76 assert(csg == BHSLR_STAGE_SECURITY_NEGOTIATION ||
77 csg == BHSLR_STAGE_OPERATIONAL_NEGOTIATION ||
78 csg == BHSLR_STAGE_FULL_FEATURE_PHASE);
80 bhslr = (struct iscsi_bhs_login_request *)request->pdu_bhs;
82 bhslr->bhslr_flags &= 0xF3;
83 bhslr->bhslr_flags |= csg << 2;
87 login_target_error_str(int class, int detail)
92 * RFC 3270, 10.13.5. Status-Class and Status-Detail
98 return ("Target moved temporarily");
100 return ("Target moved permanently");
102 snprintf(msg, sizeof(msg), "unknown redirection; "
103 "Status-Class 0x%x, Status-Detail 0x%x",
110 return ("Initiator error");
112 return ("Authentication failure");
114 return ("Authorization failure");
116 return ("Not found");
118 return ("Target removed");
120 return ("Unsupported version");
122 return ("Too many connections");
124 return ("Missing parameter");
126 return ("Can't include in session");
128 return ("Session type not supported");
130 return ("Session does not exist");
132 return ("Invalid during login");
134 snprintf(msg, sizeof(msg), "unknown initiator error; "
135 "Status-Class 0x%x, Status-Detail 0x%x",
142 return ("Target error");
144 return ("Service unavailable");
146 return ("Out of resources");
148 snprintf(msg, sizeof(msg), "unknown target error; "
149 "Status-Class 0x%x, Status-Detail 0x%x",
154 snprintf(msg, sizeof(msg), "unknown error; "
155 "Status-Class 0x%x, Status-Detail 0x%x",
162 login_receive(struct connection *conn, bool initial)
164 struct pdu *response;
165 struct iscsi_bhs_login_response *bhslr;
166 const char *errorstr;
168 response = pdu_new(conn);
169 pdu_receive(response);
170 if (response->pdu_bhs->bhs_opcode != ISCSI_BHS_OPCODE_LOGIN_RESPONSE) {
171 log_errx(1, "protocol error: received invalid opcode 0x%x",
172 response->pdu_bhs->bhs_opcode);
174 bhslr = (struct iscsi_bhs_login_response *)response->pdu_bhs;
176 * XXX: Implement the C flag some day.
178 if ((bhslr->bhslr_flags & BHSLR_FLAGS_CONTINUE) != 0)
179 log_errx(1, "received Login PDU with unsupported \"C\" flag");
180 if (bhslr->bhslr_version_max != 0x00)
181 log_errx(1, "received Login PDU with unsupported "
182 "Version-max 0x%x", bhslr->bhslr_version_max);
183 if (bhslr->bhslr_version_active != 0x00)
184 log_errx(1, "received Login PDU with unsupported "
185 "Version-active 0x%x", bhslr->bhslr_version_active);
186 if (bhslr->bhslr_status_class != 0) {
187 errorstr = login_target_error_str(bhslr->bhslr_status_class,
188 bhslr->bhslr_status_detail);
189 fail(conn, errorstr);
190 log_errx(1, "target returned error: %s", errorstr);
193 if (response->pdu_data_len == 0)
194 log_errx(1, "received Login PDU with empty data segment");
196 if (initial == false &&
197 ntohl(bhslr->bhslr_statsn) != conn->conn_statsn + 1) {
199 * It's a warning, not an error, to work around what seems
200 * to be bug in NetBSD iSCSI target.
202 log_warnx("received Login PDU with wrong StatSN: "
203 "is %d, should be %d", ntohl(bhslr->bhslr_statsn),
204 conn->conn_statsn + 1);
206 conn->conn_statsn = ntohl(bhslr->bhslr_statsn);
212 login_new_request(struct connection *conn)
215 struct iscsi_bhs_login_request *bhslr;
217 request = pdu_new(conn);
218 bhslr = (struct iscsi_bhs_login_request *)request->pdu_bhs;
219 bhslr->bhslr_opcode = ISCSI_BHS_OPCODE_LOGIN_REQUEST |
220 ISCSI_BHS_OPCODE_IMMEDIATE;
221 bhslr->bhslr_flags = BHSLR_FLAGS_TRANSIT;
222 login_set_csg(request, BHSLR_STAGE_SECURITY_NEGOTIATION);
223 login_set_nsg(request, BHSLR_STAGE_OPERATIONAL_NEGOTIATION);
224 memcpy(bhslr->bhslr_isid, &conn->conn_isid, sizeof(bhslr->bhslr_isid));
225 bhslr->bhslr_initiator_task_tag = 0;
226 bhslr->bhslr_cmdsn = 0;
227 bhslr->bhslr_expstatsn = htonl(conn->conn_statsn + 1);
233 login_list_prefers(const char *list,
234 const char *choice1, const char *choice2)
236 char *tofree, *str, *token;
238 tofree = str = checked_strdup(list);
240 while ((token = strsep(&str, ",")) != NULL) {
241 if (strcmp(token, choice1) == 0) {
245 if (strcmp(token, choice2) == 0) {
255 login_hex2int(const char hex)
302 * XXX: Review this _carefully_.
305 login_hex2bin(const char *hex, char **binp, size_t *bin_lenp)
307 int i, hex_len, nibble;
308 bool lo = true; /* As opposed to 'hi'. */
310 size_t bin_off, bin_len;
312 if (strncasecmp(hex, "0x", strlen("0x")) != 0) {
313 log_warnx("malformed variable, should start with \"0x\"");
318 hex_len = strlen(hex);
320 log_warnx("malformed variable; doesn't contain anything "
325 bin_len = hex_len / 2 + hex_len % 2;
326 bin = calloc(bin_len, 1);
328 log_err(1, "calloc");
330 bin_off = bin_len - 1;
331 for (i = hex_len - 1; i >= 0; i--) {
332 nibble = login_hex2int(hex[i]);
334 log_warnx("malformed variable, invalid char \"%c\"",
339 assert(bin_off < bin_len);
341 bin[bin_off] = nibble;
344 bin[bin_off] |= nibble << 4;
356 login_bin2hex(const char *bin, size_t bin_len)
358 unsigned char *hex, *tmp, ch;
362 hex_len = bin_len * 2 + 3; /* +2 for "0x", +1 for '\0'. */
363 hex = malloc(hex_len);
365 log_err(1, "malloc");
368 tmp += sprintf(tmp, "0x");
369 for (i = 0; i < bin_len; i++) {
371 tmp += sprintf(tmp, "%02x", ch);
378 login_compute_md5(const char id, const char *secret,
379 const void *challenge, size_t challenge_len, void *response,
385 assert(response_len == MD5_DIGEST_LENGTH);
388 MD5_Update(&ctx, &id, sizeof(id));
389 MD5_Update(&ctx, secret, strlen(secret));
390 MD5_Update(&ctx, challenge, challenge_len);
391 rv = MD5_Final(response, &ctx);
393 log_errx(1, "MD5_Final");
397 login_negotiate_key(struct connection *conn, const char *name,
402 if (strcmp(name, "TargetAlias") == 0) {
403 strlcpy(conn->conn_target_alias, value,
404 sizeof(conn->conn_target_alias));
405 } else if (strcmp(value, "Irrelevant") == 0) {
407 } else if (strcmp(name, "HeaderDigest") == 0) {
408 which = login_list_prefers(value, "CRC32C", "None");
411 log_debugx("target prefers CRC32C "
412 "for header digest; we'll use it");
413 conn->conn_header_digest = CONN_DIGEST_CRC32C;
416 log_debugx("target prefers not to do "
417 "header digest; we'll comply");
420 log_warnx("target sent unrecognized "
421 "HeaderDigest value \"%s\"; will use None", value);
424 } else if (strcmp(name, "DataDigest") == 0) {
425 which = login_list_prefers(value, "CRC32C", "None");
428 log_debugx("target prefers CRC32C "
429 "for data digest; we'll use it");
430 conn->conn_data_digest = CONN_DIGEST_CRC32C;
433 log_debugx("target prefers not to do "
434 "data digest; we'll comply");
437 log_warnx("target sent unrecognized "
438 "DataDigest value \"%s\"; will use None", value);
441 } else if (strcmp(name, "MaxConnections") == 0) {
443 } else if (strcmp(name, "InitialR2T") == 0) {
444 if (strcmp(value, "Yes") == 0)
445 conn->conn_initial_r2t = true;
447 conn->conn_initial_r2t = false;
448 } else if (strcmp(name, "ImmediateData") == 0) {
449 if (strcmp(value, "Yes") == 0)
450 conn->conn_immediate_data = true;
452 conn->conn_immediate_data = false;
453 } else if (strcmp(name, "MaxRecvDataSegmentLength") == 0) {
454 tmp = strtoul(value, NULL, 10);
456 log_errx(1, "received invalid "
457 "MaxRecvDataSegmentLength");
458 conn->conn_max_data_segment_length = tmp;
459 } else if (strcmp(name, "MaxBurstLength") == 0) {
460 if (conn->conn_immediate_data) {
461 tmp = strtoul(value, NULL, 10);
463 log_errx(1, "received invalid MaxBurstLength");
464 conn->conn_max_burst_length = tmp;
466 } else if (strcmp(name, "FirstBurstLength") == 0) {
467 tmp = strtoul(value, NULL, 10);
469 log_errx(1, "received invalid FirstBurstLength");
470 conn->conn_first_burst_length = tmp;
471 } else if (strcmp(name, "DefaultTime2Wait") == 0) {
473 } else if (strcmp(name, "DefaultTime2Retain") == 0) {
475 } else if (strcmp(name, "MaxOutstandingR2T") == 0) {
477 } else if (strcmp(name, "DataPDUInOrder") == 0) {
479 } else if (strcmp(name, "DataSequenceInOrder") == 0) {
481 } else if (strcmp(name, "ErrorRecoveryLevel") == 0) {
483 } else if (strcmp(name, "OFMarker") == 0) {
485 } else if (strcmp(name, "IFMarker") == 0) {
487 } else if (strcmp(name, "TargetPortalGroupTag") == 0) {
490 log_debugx("unknown key \"%s\"; ignoring", name);
495 login_negotiate(struct connection *conn)
497 struct pdu *request, *response;
498 struct keys *request_keys, *response_keys;
499 struct iscsi_bhs_login_response *bhslr;
502 log_debugx("beginning parameter negotiation");
503 request = login_new_request(conn);
504 login_set_csg(request, BHSLR_STAGE_OPERATIONAL_NEGOTIATION);
505 login_set_nsg(request, BHSLR_STAGE_FULL_FEATURE_PHASE);
506 request_keys = keys_new();
509 * The following keys are irrelevant for discovery sessions.
511 if (conn->conn_conf.isc_discovery == 0) {
512 if (conn->conn_conf.isc_header_digest != 0)
513 keys_add(request_keys, "HeaderDigest", "CRC32C");
515 keys_add(request_keys, "HeaderDigest", "None");
516 if (conn->conn_conf.isc_data_digest != 0)
517 keys_add(request_keys, "DataDigest", "CRC32C");
519 keys_add(request_keys, "DataDigest", "None");
521 keys_add(request_keys, "ImmediateData", "Yes");
522 keys_add_int(request_keys, "MaxBurstLength",
523 ISCSI_MAX_DATA_SEGMENT_LENGTH);
524 keys_add_int(request_keys, "FirstBurstLength",
525 ISCSI_MAX_DATA_SEGMENT_LENGTH);
526 keys_add(request_keys, "InitialR2T", "Yes");
528 keys_add(request_keys, "HeaderDigest", "None");
529 keys_add(request_keys, "DataDigest", "None");
532 keys_add_int(request_keys, "MaxRecvDataSegmentLength",
533 ISCSI_MAX_DATA_SEGMENT_LENGTH);
534 keys_add(request_keys, "DefaultTime2Wait", "0");
535 keys_add(request_keys, "DefaultTime2Retain", "0");
536 keys_add(request_keys, "ErrorRecoveryLevel", "0");
537 keys_add(request_keys, "MaxOutstandingR2T", "1");
538 keys_save(request_keys, request);
539 keys_delete(request_keys);
545 response = login_receive(conn, false);
546 response_keys = keys_new();
547 keys_load(response_keys, response);
548 for (i = 0; i < KEYS_MAX; i++) {
549 if (response_keys->keys_names[i] == NULL)
552 login_negotiate_key(conn,
553 response_keys->keys_names[i], response_keys->keys_values[i]);
556 bhslr = (struct iscsi_bhs_login_response *)response->pdu_bhs;
557 if ((bhslr->bhslr_flags & BHSLR_FLAGS_TRANSIT) == 0)
558 log_warnx("received final login response "
559 "without the \"T\" flag");
560 else if (login_nsg(response) != BHSLR_STAGE_FULL_FEATURE_PHASE)
561 log_warnx("received final login response with wrong NSG 0x%x",
562 login_nsg(response));
564 log_debugx("parameter negotiation done; "
565 "transitioning to Full Feature phase");
567 keys_delete(response_keys);
568 pdu_delete(response);
572 login_send_chap_a(struct connection *conn)
575 struct keys *request_keys;
577 request = login_new_request(conn);
578 request_keys = keys_new();
579 keys_add(request_keys, "CHAP_A", "5");
580 keys_save(request_keys, request);
581 keys_delete(request_keys);
587 login_send_chap_r(struct pdu *response)
589 struct connection *conn;
591 struct keys *request_keys, *response_keys;
592 const char *chap_a, *chap_c, *chap_i;
593 char *chap_r, *challenge, response_bin[MD5_DIGEST_LENGTH];
594 size_t challenge_len;
597 char *mutual_chap_c, mutual_chap_i[4];
600 * As in the rest of the initiator, 'request' means
601 * 'initiator -> target', and 'response' means 'target -> initiator',
603 * So, here the 'response' from the target is the packet that contains
604 * CHAP challenge; our CHAP response goes into 'request'.
607 conn = response->pdu_connection;
609 response_keys = keys_new();
610 keys_load(response_keys, response);
613 * First, compute the response.
615 chap_a = keys_find(response_keys, "CHAP_A");
617 log_errx(1, "received CHAP packet without CHAP_A");
618 chap_c = keys_find(response_keys, "CHAP_C");
620 log_errx(1, "received CHAP packet without CHAP_C");
621 chap_i = keys_find(response_keys, "CHAP_I");
623 log_errx(1, "received CHAP packet without CHAP_I");
625 if (strcmp(chap_a, "5") != 0)
626 log_errx(1, "received CHAP packet "
627 "with unsupported CHAP_A \"%s\"", chap_a);
628 id = strtoul(chap_i, NULL, 10);
629 error = login_hex2bin(chap_c, &challenge, &challenge_len);
631 log_errx(1, "received CHAP packet with malformed CHAP_C");
632 login_compute_md5(id, conn->conn_conf.isc_secret,
633 challenge, challenge_len, response_bin, sizeof(response_bin));
635 chap_r = login_bin2hex(response_bin, sizeof(response_bin));
637 keys_delete(response_keys);
639 request = login_new_request(conn);
640 request_keys = keys_new();
641 keys_add(request_keys, "CHAP_N", conn->conn_conf.isc_user);
642 keys_add(request_keys, "CHAP_R", chap_r);
646 * If we want mutual authentication, we're expected to send
647 * our CHAP_I/CHAP_C now.
649 if (conn->conn_conf.isc_mutual_user[0] != '\0') {
650 log_debugx("requesting mutual authentication; "
651 "binary challenge size is %zd bytes",
652 sizeof(conn->conn_mutual_challenge));
654 rv = RAND_bytes(conn->conn_mutual_challenge,
655 sizeof(conn->conn_mutual_challenge));
657 log_errx(1, "RAND_bytes failed: %s",
658 ERR_error_string(ERR_get_error(), NULL));
660 rv = RAND_bytes(&conn->conn_mutual_id,
661 sizeof(conn->conn_mutual_id));
663 log_errx(1, "RAND_bytes failed: %s",
664 ERR_error_string(ERR_get_error(), NULL));
666 mutual_chap_c = login_bin2hex(conn->conn_mutual_challenge,
667 sizeof(conn->conn_mutual_challenge));
668 snprintf(mutual_chap_i, sizeof(mutual_chap_i),
669 "%d", conn->conn_mutual_id);
670 keys_add(request_keys, "CHAP_I", mutual_chap_i);
671 keys_add(request_keys, "CHAP_C", mutual_chap_c);
675 keys_save(request_keys, request);
676 keys_delete(request_keys);
682 login_verify_mutual(const struct pdu *response)
684 struct connection *conn;
685 struct keys *response_keys;
686 const char *chap_n, *chap_r;
687 char *response_bin, expected_response_bin[MD5_DIGEST_LENGTH];
688 size_t response_bin_len;
691 conn = response->pdu_connection;
693 response_keys = keys_new();
694 keys_load(response_keys, response);
696 chap_n = keys_find(response_keys, "CHAP_N");
698 log_errx(1, "received CHAP Response PDU without CHAP_N");
699 chap_r = keys_find(response_keys, "CHAP_R");
701 log_errx(1, "received CHAP Response PDU without CHAP_R");
702 error = login_hex2bin(chap_r, &response_bin, &response_bin_len);
704 log_errx(1, "received CHAP Response PDU with malformed CHAP_R");
706 if (strcmp(chap_n, conn->conn_conf.isc_mutual_user) != 0) {
707 fail(conn, "Mutual CHAP failed");
708 log_errx(1, "mutual CHAP authentication failed: wrong user");
711 login_compute_md5(conn->conn_mutual_id,
712 conn->conn_conf.isc_mutual_secret, conn->conn_mutual_challenge,
713 sizeof(conn->conn_mutual_challenge), expected_response_bin,
714 sizeof(expected_response_bin));
716 if (memcmp(response_bin, expected_response_bin,
717 sizeof(expected_response_bin)) != 0) {
718 fail(conn, "Mutual CHAP failed");
719 log_errx(1, "mutual CHAP authentication failed: wrong secret");
722 keys_delete(response_keys);
725 log_debugx("mutual CHAP authentication succeeded");
729 login_chap(struct connection *conn)
731 struct pdu *response;
733 log_debugx("beginning CHAP authentication; sending CHAP_A");
734 login_send_chap_a(conn);
736 log_debugx("waiting for CHAP_A/CHAP_C/CHAP_I");
737 response = login_receive(conn, false);
739 log_debugx("sending CHAP_N/CHAP_R");
740 login_send_chap_r(response);
741 pdu_delete(response);
744 * XXX: Make sure this is not susceptible to MITM.
747 log_debugx("waiting for CHAP result");
748 response = login_receive(conn, false);
749 if (conn->conn_conf.isc_mutual_user[0] != '\0')
750 login_verify_mutual(response);
751 pdu_delete(response);
753 log_debugx("CHAP authentication done");
757 login_create_isid(struct connection *conn)
762 * RFC 3720, 10.12.5: 10b, "Random" ISID.
765 conn->conn_isid[0] = 0x80;
767 rv = RAND_bytes(&conn->conn_isid[1], 3);
769 log_errx(1, "RAND_bytes failed: %s",
770 ERR_error_string(ERR_get_error(), NULL));
775 login(struct connection *conn)
777 struct pdu *request, *response;
778 struct keys *request_keys, *response_keys;
779 struct iscsi_bhs_login_request *bhslr;
780 struct iscsi_bhs_login_response *bhslr2;
781 const char *auth_method;
784 login_create_isid(conn);
786 log_debugx("beginning Login phase; sending Login PDU");
787 request = login_new_request(conn);
789 bhslr = (struct iscsi_bhs_login_request *)request->pdu_bhs;
790 bhslr->bhslr_flags |= BHSLR_FLAGS_TRANSIT;
792 request_keys = keys_new();
793 if (conn->conn_conf.isc_mutual_user[0] != '\0') {
794 keys_add(request_keys, "AuthMethod", "CHAP");
795 } else if (conn->conn_conf.isc_user[0] != '\0') {
797 * Give target a chance to skip authentication if it
798 * doesn't feel like it.
800 * None is first, CHAP second; this is to work around
801 * what seems to be LIO (Linux target) bug: otherwise,
802 * if target is configured with no authentication,
803 * and we are configured to authenticate, the target
804 * will erroneously respond with AuthMethod=CHAP
805 * instead of AuthMethod=None, and will subsequently
806 * fail the connection. This usually happens with
807 * Discovery sessions, which default to no authentication.
809 keys_add(request_keys, "AuthMethod", "None,CHAP");
811 keys_add(request_keys, "AuthMethod", "None");
813 keys_add(request_keys, "InitiatorName",
814 conn->conn_conf.isc_initiator);
815 if (conn->conn_conf.isc_initiator_alias[0] != '\0') {
816 keys_add(request_keys, "InitiatorAlias",
817 conn->conn_conf.isc_initiator_alias);
819 if (conn->conn_conf.isc_discovery == 0) {
820 keys_add(request_keys, "SessionType", "Normal");
821 keys_add(request_keys,
822 "TargetName", conn->conn_conf.isc_target);
824 keys_add(request_keys, "SessionType", "Discovery");
826 keys_save(request_keys, request);
827 keys_delete(request_keys);
831 response = login_receive(conn, true);
833 response_keys = keys_new();
834 keys_load(response_keys, response);
836 for (i = 0; i < KEYS_MAX; i++) {
837 if (response_keys->keys_names[i] == NULL)
841 * Not interested in AuthMethod at this point; we only need
842 * to parse things such as TargetAlias.
844 * XXX: This is somewhat ugly. We should have a way to apply
845 * all the keys to the session and use that by default
846 * instead of discarding them.
848 if (strcmp(response_keys->keys_names[i], "AuthMethod") == 0)
851 login_negotiate_key(conn,
852 response_keys->keys_names[i], response_keys->keys_values[i]);
855 bhslr2 = (struct iscsi_bhs_login_response *)response->pdu_bhs;
856 if ((bhslr2->bhslr_flags & BHSLR_FLAGS_TRANSIT) != 0 &&
857 login_nsg(response) == BHSLR_STAGE_OPERATIONAL_NEGOTIATION) {
858 if (conn->conn_conf.isc_mutual_user[0] != '\0') {
859 log_errx(1, "target requested transition "
860 "to operational negotiation, but we require "
864 log_debugx("target requested transition "
865 "to operational negotiation");
866 keys_delete(response_keys);
867 pdu_delete(response);
868 login_negotiate(conn);
872 auth_method = keys_find(response_keys, "AuthMethod");
873 if (auth_method == NULL)
874 log_errx(1, "received response without AuthMethod");
875 if (strcmp(auth_method, "None") == 0) {
876 if (conn->conn_conf.isc_mutual_user[0] != '\0') {
877 log_errx(1, "target does not require authantication, "
878 "but we require mutual CHAP");
881 log_debugx("target does not require authentication");
882 keys_delete(response_keys);
883 pdu_delete(response);
884 login_negotiate(conn);
888 if (strcmp(auth_method, "CHAP") != 0) {
889 fail(conn, "Unsupported AuthMethod");
890 log_errx(1, "received response "
891 "with unsupported AuthMethod \"%s\"", auth_method);
894 if (conn->conn_conf.isc_user[0] == '\0' ||
895 conn->conn_conf.isc_secret[0] == '\0') {
896 fail(conn, "Authentication required");
897 log_errx(1, "target requests CHAP authentication, but we don't "
898 "have user and secret");
901 keys_delete(response_keys);
902 response_keys = NULL;
903 pdu_delete(response);
907 login_negotiate(conn);