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);
192 if (initial == false &&
193 ntohl(bhslr->bhslr_statsn) != conn->conn_statsn + 1) {
195 * It's a warning, not an error, to work around what seems
196 * to be bug in NetBSD iSCSI target.
198 log_warnx("received Login PDU with wrong StatSN: "
199 "is %d, should be %d", ntohl(bhslr->bhslr_statsn),
200 conn->conn_statsn + 1);
202 conn->conn_statsn = ntohl(bhslr->bhslr_statsn);
208 login_new_request(struct connection *conn)
211 struct iscsi_bhs_login_request *bhslr;
213 request = pdu_new(conn);
214 bhslr = (struct iscsi_bhs_login_request *)request->pdu_bhs;
215 bhslr->bhslr_opcode = ISCSI_BHS_OPCODE_LOGIN_REQUEST |
216 ISCSI_BHS_OPCODE_IMMEDIATE;
217 bhslr->bhslr_flags = BHSLR_FLAGS_TRANSIT;
218 login_set_csg(request, BHSLR_STAGE_SECURITY_NEGOTIATION);
219 login_set_nsg(request, BHSLR_STAGE_OPERATIONAL_NEGOTIATION);
220 memcpy(bhslr->bhslr_isid, &conn->conn_isid, sizeof(bhslr->bhslr_isid));
221 bhslr->bhslr_initiator_task_tag = 0;
222 bhslr->bhslr_cmdsn = 0;
223 bhslr->bhslr_expstatsn = htonl(conn->conn_statsn + 1);
229 login_list_prefers(const char *list,
230 const char *choice1, const char *choice2)
232 char *tofree, *str, *token;
234 tofree = str = checked_strdup(list);
236 while ((token = strsep(&str, ",")) != NULL) {
237 if (strcmp(token, choice1) == 0) {
241 if (strcmp(token, choice2) == 0) {
251 login_hex2int(const char hex)
298 * XXX: Review this _carefully_.
301 login_hex2bin(const char *hex, char **binp, size_t *bin_lenp)
303 int i, hex_len, nibble;
304 bool lo = true; /* As opposed to 'hi'. */
306 size_t bin_off, bin_len;
308 if (strncasecmp(hex, "0x", strlen("0x")) != 0) {
309 log_warnx("malformed variable, should start with \"0x\"");
314 hex_len = strlen(hex);
316 log_warnx("malformed variable; doesn't contain anything "
321 bin_len = hex_len / 2 + hex_len % 2;
322 bin = calloc(bin_len, 1);
324 log_err(1, "calloc");
326 bin_off = bin_len - 1;
327 for (i = hex_len - 1; i >= 0; i--) {
328 nibble = login_hex2int(hex[i]);
330 log_warnx("malformed variable, invalid char \"%c\"",
335 assert(bin_off < bin_len);
337 bin[bin_off] = nibble;
340 bin[bin_off] |= nibble << 4;
352 login_bin2hex(const char *bin, size_t bin_len)
354 unsigned char *hex, *tmp, ch;
358 hex_len = bin_len * 2 + 3; /* +2 for "0x", +1 for '\0'. */
359 hex = malloc(hex_len);
361 log_err(1, "malloc");
364 tmp += sprintf(tmp, "0x");
365 for (i = 0; i < bin_len; i++) {
367 tmp += sprintf(tmp, "%02x", ch);
374 login_compute_md5(const char id, const char *secret,
375 const void *challenge, size_t challenge_len, void *response,
381 assert(response_len == MD5_DIGEST_LENGTH);
384 MD5_Update(&ctx, &id, sizeof(id));
385 MD5_Update(&ctx, secret, strlen(secret));
386 MD5_Update(&ctx, challenge, challenge_len);
387 rv = MD5_Final(response, &ctx);
389 log_errx(1, "MD5_Final");
393 login_negotiate_key(struct connection *conn, const char *name,
398 if (strcmp(name, "TargetAlias") == 0) {
399 strlcpy(conn->conn_target_alias, value,
400 sizeof(conn->conn_target_alias));
401 } else if (strcmp(value, "Irrelevant") == 0) {
403 } else if (strcmp(name, "HeaderDigest") == 0) {
404 which = login_list_prefers(value, "CRC32C", "None");
407 log_debugx("target prefers CRC32C "
408 "for header digest; we'll use it");
409 conn->conn_header_digest = CONN_DIGEST_CRC32C;
412 log_debugx("target prefers not to do "
413 "header digest; we'll comply");
416 log_warnx("target sent unrecognized "
417 "HeaderDigest value \"%s\"; will use None", value);
420 } else if (strcmp(name, "DataDigest") == 0) {
421 which = login_list_prefers(value, "CRC32C", "None");
424 log_debugx("target prefers CRC32C "
425 "for data digest; we'll use it");
426 conn->conn_data_digest = CONN_DIGEST_CRC32C;
429 log_debugx("target prefers not to do "
430 "data digest; we'll comply");
433 log_warnx("target sent unrecognized "
434 "DataDigest value \"%s\"; will use None", value);
437 } else if (strcmp(name, "MaxConnections") == 0) {
439 } else if (strcmp(name, "InitialR2T") == 0) {
440 if (strcmp(value, "Yes") == 0)
441 conn->conn_initial_r2t = true;
443 conn->conn_initial_r2t = false;
444 } else if (strcmp(name, "ImmediateData") == 0) {
445 if (strcmp(value, "Yes") == 0)
446 conn->conn_immediate_data = true;
448 conn->conn_immediate_data = false;
449 } else if (strcmp(name, "MaxRecvDataSegmentLength") == 0) {
450 tmp = strtoul(value, NULL, 10);
452 log_errx(1, "received invalid "
453 "MaxRecvDataSegmentLength");
454 conn->conn_max_data_segment_length = tmp;
455 } else if (strcmp(name, "MaxBurstLength") == 0) {
456 if (conn->conn_immediate_data) {
457 tmp = strtoul(value, NULL, 10);
459 log_errx(1, "received invalid MaxBurstLength");
460 conn->conn_max_burst_length = tmp;
462 } else if (strcmp(name, "FirstBurstLength") == 0) {
463 tmp = strtoul(value, NULL, 10);
465 log_errx(1, "received invalid FirstBurstLength");
466 conn->conn_first_burst_length = tmp;
467 } else if (strcmp(name, "DefaultTime2Wait") == 0) {
469 } else if (strcmp(name, "DefaultTime2Retain") == 0) {
471 } else if (strcmp(name, "MaxOutstandingR2T") == 0) {
473 } else if (strcmp(name, "DataPDUInOrder") == 0) {
475 } else if (strcmp(name, "DataSequenceInOrder") == 0) {
477 } else if (strcmp(name, "ErrorRecoveryLevel") == 0) {
479 } else if (strcmp(name, "OFMarker") == 0) {
481 } else if (strcmp(name, "IFMarker") == 0) {
483 } else if (strcmp(name, "TargetPortalGroupTag") == 0) {
486 log_debugx("unknown key \"%s\"; ignoring", name);
491 login_negotiate(struct connection *conn)
493 struct pdu *request, *response;
494 struct keys *request_keys, *response_keys;
495 struct iscsi_bhs_login_response *bhslr;
498 log_debugx("beginning parameter negotiation");
499 request = login_new_request(conn);
500 login_set_csg(request, BHSLR_STAGE_OPERATIONAL_NEGOTIATION);
501 login_set_nsg(request, BHSLR_STAGE_FULL_FEATURE_PHASE);
502 request_keys = keys_new();
505 * The following keys are irrelevant for discovery sessions.
507 if (conn->conn_conf.isc_discovery == 0) {
508 if (conn->conn_conf.isc_header_digest != 0)
509 keys_add(request_keys, "HeaderDigest", "CRC32C");
511 keys_add(request_keys, "HeaderDigest", "None");
512 if (conn->conn_conf.isc_data_digest != 0)
513 keys_add(request_keys, "DataDigest", "CRC32C");
515 keys_add(request_keys, "DataDigest", "None");
517 keys_add(request_keys, "ImmediateData", "Yes");
518 keys_add_int(request_keys, "MaxBurstLength",
519 ISCSI_MAX_DATA_SEGMENT_LENGTH);
520 keys_add_int(request_keys, "FirstBurstLength",
521 ISCSI_MAX_DATA_SEGMENT_LENGTH);
522 keys_add(request_keys, "InitialR2T", "Yes");
524 keys_add(request_keys, "HeaderDigest", "None");
525 keys_add(request_keys, "DataDigest", "None");
528 keys_add_int(request_keys, "MaxRecvDataSegmentLength",
529 ISCSI_MAX_DATA_SEGMENT_LENGTH);
530 keys_add(request_keys, "DefaultTime2Wait", "0");
531 keys_add(request_keys, "DefaultTime2Retain", "0");
532 keys_add(request_keys, "ErrorRecoveryLevel", "0");
533 keys_add(request_keys, "MaxOutstandingR2T", "1");
534 keys_save(request_keys, request);
535 keys_delete(request_keys);
541 response = login_receive(conn, false);
542 response_keys = keys_new();
543 keys_load(response_keys, response);
544 for (i = 0; i < KEYS_MAX; i++) {
545 if (response_keys->keys_names[i] == NULL)
548 login_negotiate_key(conn,
549 response_keys->keys_names[i], response_keys->keys_values[i]);
552 bhslr = (struct iscsi_bhs_login_response *)response->pdu_bhs;
553 if ((bhslr->bhslr_flags & BHSLR_FLAGS_TRANSIT) == 0)
554 log_warnx("received final login response "
555 "without the \"T\" flag");
556 else if (login_nsg(response) != BHSLR_STAGE_FULL_FEATURE_PHASE)
557 log_warnx("received final login response with wrong NSG 0x%x",
558 login_nsg(response));
560 log_debugx("parameter negotiation done; "
561 "transitioning to Full Feature phase");
563 keys_delete(response_keys);
564 pdu_delete(response);
568 login_send_chap_a(struct connection *conn)
571 struct keys *request_keys;
573 request = login_new_request(conn);
574 request_keys = keys_new();
575 keys_add(request_keys, "CHAP_A", "5");
576 keys_save(request_keys, request);
577 keys_delete(request_keys);
583 login_send_chap_r(struct pdu *response)
585 struct connection *conn;
587 struct keys *request_keys, *response_keys;
588 const char *chap_a, *chap_c, *chap_i;
589 char *chap_r, *challenge, response_bin[MD5_DIGEST_LENGTH];
590 size_t challenge_len;
593 char *mutual_chap_c, mutual_chap_i[4];
596 * As in the rest of the initiator, 'request' means
597 * 'initiator -> target', and 'response' means 'target -> initiator',
599 * So, here the 'response' from the target is the packet that contains
600 * CHAP challenge; our CHAP response goes into 'request'.
603 conn = response->pdu_connection;
605 response_keys = keys_new();
606 keys_load(response_keys, response);
609 * First, compute the response.
611 chap_a = keys_find(response_keys, "CHAP_A");
613 log_errx(1, "received CHAP packet without CHAP_A");
614 chap_c = keys_find(response_keys, "CHAP_C");
616 log_errx(1, "received CHAP packet without CHAP_C");
617 chap_i = keys_find(response_keys, "CHAP_I");
619 log_errx(1, "received CHAP packet without CHAP_I");
621 if (strcmp(chap_a, "5") != 0)
622 log_errx(1, "received CHAP packet "
623 "with unsupported CHAP_A \"%s\"", chap_a);
624 id = strtoul(chap_i, NULL, 10);
625 error = login_hex2bin(chap_c, &challenge, &challenge_len);
627 log_errx(1, "received CHAP packet with malformed CHAP_C");
628 login_compute_md5(id, conn->conn_conf.isc_secret,
629 challenge, challenge_len, response_bin, sizeof(response_bin));
631 chap_r = login_bin2hex(response_bin, sizeof(response_bin));
633 keys_delete(response_keys);
635 request = login_new_request(conn);
636 request_keys = keys_new();
637 keys_add(request_keys, "CHAP_N", conn->conn_conf.isc_user);
638 keys_add(request_keys, "CHAP_R", chap_r);
642 * If we want mutual authentication, we're expected to send
643 * our CHAP_I/CHAP_C now.
645 if (conn->conn_conf.isc_mutual_user[0] != '\0') {
646 log_debugx("requesting mutual authentication; "
647 "binary challenge size is %zd bytes",
648 sizeof(conn->conn_mutual_challenge));
650 rv = RAND_bytes(conn->conn_mutual_challenge,
651 sizeof(conn->conn_mutual_challenge));
653 log_errx(1, "RAND_bytes failed: %s",
654 ERR_error_string(ERR_get_error(), NULL));
656 rv = RAND_bytes(&conn->conn_mutual_id,
657 sizeof(conn->conn_mutual_id));
659 log_errx(1, "RAND_bytes failed: %s",
660 ERR_error_string(ERR_get_error(), NULL));
662 mutual_chap_c = login_bin2hex(conn->conn_mutual_challenge,
663 sizeof(conn->conn_mutual_challenge));
664 snprintf(mutual_chap_i, sizeof(mutual_chap_i),
665 "%d", conn->conn_mutual_id);
666 keys_add(request_keys, "CHAP_I", mutual_chap_i);
667 keys_add(request_keys, "CHAP_C", mutual_chap_c);
671 keys_save(request_keys, request);
672 keys_delete(request_keys);
678 login_verify_mutual(const struct pdu *response)
680 struct connection *conn;
681 struct keys *response_keys;
682 const char *chap_n, *chap_r;
683 char *response_bin, expected_response_bin[MD5_DIGEST_LENGTH];
684 size_t response_bin_len;
687 conn = response->pdu_connection;
689 response_keys = keys_new();
690 keys_load(response_keys, response);
692 chap_n = keys_find(response_keys, "CHAP_N");
694 log_errx(1, "received CHAP Response PDU without CHAP_N");
695 chap_r = keys_find(response_keys, "CHAP_R");
697 log_errx(1, "received CHAP Response PDU without CHAP_R");
698 error = login_hex2bin(chap_r, &response_bin, &response_bin_len);
700 log_errx(1, "received CHAP Response PDU with malformed CHAP_R");
702 if (strcmp(chap_n, conn->conn_conf.isc_mutual_user) != 0) {
703 fail(conn, "Mutual CHAP failed");
704 log_errx(1, "mutual CHAP authentication failed: wrong user");
707 login_compute_md5(conn->conn_mutual_id,
708 conn->conn_conf.isc_mutual_secret, conn->conn_mutual_challenge,
709 sizeof(conn->conn_mutual_challenge), expected_response_bin,
710 sizeof(expected_response_bin));
712 if (memcmp(response_bin, expected_response_bin,
713 sizeof(expected_response_bin)) != 0) {
714 fail(conn, "Mutual CHAP failed");
715 log_errx(1, "mutual CHAP authentication failed: wrong secret");
718 keys_delete(response_keys);
721 log_debugx("mutual CHAP authentication succeeded");
725 login_chap(struct connection *conn)
727 struct pdu *response;
729 log_debugx("beginning CHAP authentication; sending CHAP_A");
730 login_send_chap_a(conn);
732 log_debugx("waiting for CHAP_A/CHAP_C/CHAP_I");
733 response = login_receive(conn, false);
735 log_debugx("sending CHAP_N/CHAP_R");
736 login_send_chap_r(response);
737 pdu_delete(response);
740 * XXX: Make sure this is not susceptible to MITM.
743 log_debugx("waiting for CHAP result");
744 response = login_receive(conn, false);
745 if (conn->conn_conf.isc_mutual_user[0] != '\0')
746 login_verify_mutual(response);
747 pdu_delete(response);
749 log_debugx("CHAP authentication done");
753 login_create_isid(struct connection *conn)
758 * RFC 3720, 10.12.5: 10b, "Random" ISID.
761 conn->conn_isid[0] = 0x80;
763 rv = RAND_bytes(&conn->conn_isid[1], 3);
765 log_errx(1, "RAND_bytes failed: %s",
766 ERR_error_string(ERR_get_error(), NULL));
771 login(struct connection *conn)
773 struct pdu *request, *response;
774 struct keys *request_keys, *response_keys;
775 struct iscsi_bhs_login_request *bhslr;
776 struct iscsi_bhs_login_response *bhslr2;
777 const char *auth_method;
780 login_create_isid(conn);
782 log_debugx("beginning Login phase; sending Login PDU");
783 request = login_new_request(conn);
785 bhslr = (struct iscsi_bhs_login_request *)request->pdu_bhs;
786 bhslr->bhslr_flags |= BHSLR_FLAGS_TRANSIT;
788 request_keys = keys_new();
789 if (conn->conn_conf.isc_mutual_user[0] != '\0') {
790 keys_add(request_keys, "AuthMethod", "CHAP");
791 } else if (conn->conn_conf.isc_user[0] != '\0') {
793 * Give target a chance to skip authentication if it
794 * doesn't feel like it.
796 * None is first, CHAP second; this is to work around
797 * what seems to be LIO (Linux target) bug: otherwise,
798 * if target is configured with no authentication,
799 * and we are configured to authenticate, the target
800 * will erroneously respond with AuthMethod=CHAP
801 * instead of AuthMethod=None, and will subsequently
802 * fail the connection. This usually happens with
803 * Discovery sessions, which default to no authentication.
805 keys_add(request_keys, "AuthMethod", "None,CHAP");
807 keys_add(request_keys, "AuthMethod", "None");
809 keys_add(request_keys, "InitiatorName",
810 conn->conn_conf.isc_initiator);
811 if (conn->conn_conf.isc_initiator_alias[0] != '\0') {
812 keys_add(request_keys, "InitiatorAlias",
813 conn->conn_conf.isc_initiator_alias);
815 if (conn->conn_conf.isc_discovery == 0) {
816 keys_add(request_keys, "SessionType", "Normal");
817 keys_add(request_keys,
818 "TargetName", conn->conn_conf.isc_target);
820 keys_add(request_keys, "SessionType", "Discovery");
822 keys_save(request_keys, request);
823 keys_delete(request_keys);
827 response = login_receive(conn, true);
829 response_keys = keys_new();
830 keys_load(response_keys, response);
832 for (i = 0; i < KEYS_MAX; i++) {
833 if (response_keys->keys_names[i] == NULL)
837 * Not interested in AuthMethod at this point; we only need
838 * to parse things such as TargetAlias.
840 * XXX: This is somewhat ugly. We should have a way to apply
841 * all the keys to the session and use that by default
842 * instead of discarding them.
844 if (strcmp(response_keys->keys_names[i], "AuthMethod") == 0)
847 login_negotiate_key(conn,
848 response_keys->keys_names[i], response_keys->keys_values[i]);
851 bhslr2 = (struct iscsi_bhs_login_response *)response->pdu_bhs;
852 if ((bhslr2->bhslr_flags & BHSLR_FLAGS_TRANSIT) != 0 &&
853 login_nsg(response) == BHSLR_STAGE_OPERATIONAL_NEGOTIATION) {
854 if (conn->conn_conf.isc_mutual_user[0] != '\0') {
855 log_errx(1, "target requested transition "
856 "to operational negotiation, but we require "
860 log_debugx("target requested transition "
861 "to operational negotiation");
862 keys_delete(response_keys);
863 pdu_delete(response);
864 login_negotiate(conn);
868 auth_method = keys_find(response_keys, "AuthMethod");
869 if (auth_method == NULL)
870 log_errx(1, "received response without AuthMethod");
871 if (strcmp(auth_method, "None") == 0) {
872 if (conn->conn_conf.isc_mutual_user[0] != '\0') {
873 log_errx(1, "target does not require authantication, "
874 "but we require mutual CHAP");
877 log_debugx("target does not require authentication");
878 keys_delete(response_keys);
879 pdu_delete(response);
880 login_negotiate(conn);
884 if (strcmp(auth_method, "CHAP") != 0) {
885 fail(conn, "Unsupported AuthMethod");
886 log_errx(1, "received response "
887 "with unsupported AuthMethod \"%s\"", auth_method);
890 if (conn->conn_conf.isc_user[0] == '\0' ||
891 conn->conn_conf.isc_secret[0] == '\0') {
892 fail(conn, "Authentication required");
893 log_errx(1, "target requests CHAP authentication, but we don't "
894 "have user and secret");
897 keys_delete(response_keys);
898 response_keys = NULL;
899 pdu_delete(response);
903 login_negotiate(conn);