2 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * usr/src/cmd/cmd-inet/usr.bin/telnet/encrypt.c
11 * Copyright (c) 1991, 1993
12 * The Regents of the University of California. All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the University of
25 * California, Berkeley and its contributors.
26 * 4. Neither the name of the University nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 /* based on @(#)encrypt.c 8.1 (Berkeley) 6/4/93 */
46 * Copyright (C) 1990 by the Massachusetts Institute of Technology
48 * Export of this software from the United States of America may
49 * require a specific license from the United States Government.
50 * It is the responsibility of any person or organization contemplating
51 * export to obtain such a license before exporting.
53 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
54 * distribute this software and its documentation for any purpose and
55 * without fee is hereby granted, provided that the above copyright
56 * notice appear in all copies and that both that copyright notice and
57 * this permission notice appear in supporting documentation, and that
58 * the name of M.I.T. not be used in advertising or publicity pertaining
59 * to distribution of the software without specific, written prior
60 * permission. Furthermore if you modify this software you must label
61 * your software as modified software and not distribute it in such a
62 * fashion that it might be confused with the original M.I.T. software.
63 * M.I.T. makes no representations about the suitability of
64 * this software for any purpose. It is provided "as is" without express
65 * or implied warranty.
69 #include <arpa/telnet.h>
78 * These functions pointers point to the current routines
79 * for encrypting and decrypting data.
81 void (*encrypt_output
)(uchar_t
*, int);
82 int (*decrypt_input
)(int);
83 static void encrypt_start_output(int);
84 static void encrypt_send_end(void);
85 static void encrypt_send_request_start(void);
86 static void encrypt_send_request_end(void);
88 boolean_t encrypt_debug_mode
= B_FALSE
;
90 static int decrypt_mode
= 0;
91 static int encrypt_mode
= 0;
92 static boolean_t encrypt_verbose
= B_FALSE
;
93 static boolean_t autoencrypt
= B_FALSE
;
94 static boolean_t autodecrypt
= B_FALSE
;
95 static char *Name
= "Noname";
97 #define typemask(x) ((x) > 0 ? 1 << ((x)-1) : 0)
99 #define UNKNOWN gettext("(unknown)")
101 static int i_support_encrypt
= typemask(TELOPT_ENCTYPE_DES_CFB64
);
102 static int i_support_decrypt
= typemask(TELOPT_ENCTYPE_DES_CFB64
);
103 static int i_wont_support_encrypt
= 0;
104 static int i_wont_support_decrypt
= 0;
105 #define I_SUPPORT_ENCRYPT (i_support_encrypt & ~i_wont_support_encrypt)
106 #define I_SUPPORT_DECRYPT (i_support_decrypt & ~i_wont_support_decrypt)
108 static int remote_supports_encrypt
= 0;
109 static int remote_supports_decrypt
= 0;
111 static Encryptions encryptions
[] = {
112 { "DES_CFB64", TELOPT_ENCTYPE_DES_CFB64
,
125 static uchar_t str_send
[64] = { IAC
, SB
, TELOPT_ENCRYPT
,
127 static uchar_t str_suplen
= 0;
128 static uchar_t str_start
[72] = { IAC
, SB
, TELOPT_ENCRYPT
};
129 static uchar_t str_end
[] = { IAC
, SB
, TELOPT_ENCRYPT
, 0, IAC
, SE
};
132 findencryption(int type
)
134 Encryptions
*ep
= encryptions
;
136 if (!(I_SUPPORT_ENCRYPT
& remote_supports_decrypt
& typemask(type
)))
138 for (; (ep
->type
!= 0) && (ep
->type
!= type
); ep
++);
139 return (ep
->type
? ep
: NULL
);
143 finddecryption(int type
)
145 Encryptions
*ep
= encryptions
;
147 if (!(I_SUPPORT_DECRYPT
& remote_supports_encrypt
& typemask(type
)))
149 while (ep
->type
&& ep
->type
!= type
)
151 return (ep
->type
? ep
: NULL
);
156 static struct key_info
{
157 uchar_t keyid
[MAXKEYLEN
];
161 Encryptions
*(*getcrypt
)();
163 { { 0 }, 0, TELNET_DIR_ENCRYPT
, &encrypt_mode
, findencryption
},
164 { { 0 }, 0, TELNET_DIR_DECRYPT
, &decrypt_mode
, finddecryption
},
170 encrypt_init(char *name
)
172 Encryptions
*ep
= encryptions
;
175 i_support_encrypt
= i_support_decrypt
= 0;
176 remote_supports_encrypt
= remote_supports_decrypt
= 0;
182 encrypt_verbose
= !server
;
188 if (encrypt_debug_mode
)
189 (void) printf(gettext(
190 ">>>%s: I will support %s\r\n"),
191 Name
, ENCTYPE_NAME(ep
->type
));
192 i_support_encrypt
|= typemask(ep
->type
);
193 i_support_decrypt
|= typemask(ep
->type
);
194 if ((i_wont_support_decrypt
& typemask(ep
->type
)) == 0)
195 if ((str_send
[str_suplen
++] = ep
->type
) == IAC
)
196 str_send
[str_suplen
++] = IAC
;
201 str_send
[str_suplen
++] = IAC
;
202 str_send
[str_suplen
++] = SE
;
206 encrypt_list_types(void)
208 Encryptions
*ep
= encryptions
;
210 (void) printf(gettext("Valid encryption types:\n"));
212 (void) printf("\t%s (%d)\r\n",
213 ENCTYPE_NAME(ep
->type
), ep
->type
);
219 EncryptEnable(char *type
, char *mode
)
221 if (isprefix(type
, "help") || isprefix(type
, "?")) {
222 (void) printf(gettext(
223 "Usage: encrypt enable <type> [input|output]\n"));
224 encrypt_list_types();
228 if (EncryptType(type
, mode
))
229 return (EncryptStart(mode
));
235 EncryptDisable(char *type
, char *mode
)
237 register Encryptions
*ep
;
240 if (isprefix(type
, "help") || isprefix(type
, "?")) {
241 (void) printf(gettext(
242 "Usage: encrypt disable <type> [input|output]\n"));
243 encrypt_list_types();
244 } else if ((ep
= (Encryptions
*)genget(type
, (char **)encryptions
,
245 sizeof (Encryptions
))) == 0) {
246 (void) printf(gettext("%s: invalid encryption type\n"), type
);
247 } else if (Ambiguous(ep
)) {
248 (void) printf(gettext("Ambiguous type '%s'\n"), type
);
250 if ((mode
== 0) || (isprefix(mode
, "input") ? 1 : 0)) {
251 if (decrypt_mode
== ep
->type
)
252 (void) EncryptStopInput();
253 i_wont_support_decrypt
|= typemask(ep
->type
);
256 if ((mode
== 0) || (isprefix(mode
, "output"))) {
257 if (encrypt_mode
== ep
->type
)
258 (void) EncryptStopOutput();
259 i_wont_support_encrypt
|= typemask(ep
->type
);
263 (void) printf(gettext(
264 "%s: invalid encryption mode\n"), mode
);
270 EncryptType(char *type
, char *mode
)
272 register Encryptions
*ep
;
275 if (isprefix(type
, "help") || isprefix(type
, "?")) {
276 (void) printf(gettext(
277 "Usage: encrypt type <type> [input|output]\n"));
278 encrypt_list_types();
279 } else if ((ep
= (Encryptions
*)genget(type
, (char **)encryptions
,
280 sizeof (Encryptions
))) == 0) {
281 (void) printf(gettext("%s: invalid encryption type\n"), type
);
282 } else if (Ambiguous(ep
)) {
283 (void) printf(gettext("Ambiguous type '%s'\n"), type
);
285 if ((mode
== 0) || isprefix(mode
, "input")) {
286 decrypt_mode
= ep
->type
;
287 i_wont_support_decrypt
&= ~typemask(ep
->type
);
290 if ((mode
== 0) || isprefix(mode
, "output")) {
291 encrypt_mode
= ep
->type
;
292 i_wont_support_encrypt
&= ~typemask(ep
->type
);
296 (void) printf(gettext(
297 "%s: invalid encryption mode\n"), mode
);
303 EncryptStart(char *mode
)
305 register int ret
= 0;
307 if (isprefix(mode
, "input"))
308 return (EncryptStartInput());
309 if (isprefix(mode
, "output"))
310 return (EncryptStartOutput());
311 if (isprefix(mode
, "help") || isprefix(mode
, "?")) {
312 (void) printf(gettext(
313 "Usage: encrypt start [input|output]\n"));
316 (void) printf(gettext(
317 "%s: invalid encryption mode 'encrypt start ?' "
318 "for help\n"), mode
);
321 ret
+= EncryptStartInput();
322 ret
+= EncryptStartOutput();
327 EncryptStartInput(void)
330 encrypt_send_request_start();
333 (void) printf(gettext("No previous decryption mode, "
334 "decryption not enabled\r\n"));
339 EncryptStartOutput(void)
342 encrypt_start_output(encrypt_mode
);
345 (void) printf(gettext("No previous encryption mode, "
346 "encryption not enabled\r\n"));
351 EncryptStop(char *mode
)
355 if (isprefix(mode
, "input"))
356 return (EncryptStopInput());
357 if (isprefix(mode
, "output"))
358 return (EncryptStopOutput());
359 if (isprefix(mode
, "help") || isprefix(mode
, "?")) {
360 (void) printf(gettext(
361 "Usage: encrypt stop [input|output]\n"));
364 (void) printf(gettext(
365 "%s: invalid encryption mode 'encrypt stop ?' "
366 "for help\n"), mode
);
369 ret
+= EncryptStopInput();
370 ret
+= EncryptStopOutput();
375 EncryptStopInput(void)
377 encrypt_send_request_end();
382 EncryptStopOutput(void)
389 encrypt_display(void)
392 (void) printf(gettext(
393 "Currently encrypting output with %s\r\n"),
394 ENCTYPE_NAME(encrypt_mode
));
396 (void) printf(gettext(
397 "Currently decrypting input with %s\r\n"),
398 ENCTYPE_NAME(decrypt_mode
));
405 (void) printf(gettext(
406 "Currently encrypting output with %s\r\n"),
407 ENCTYPE_NAME(encrypt_mode
));
408 else if (encrypt_mode
) {
409 (void) printf(gettext("Currently output is clear text.\r\n"));
410 (void) printf(gettext("Last encryption mode was %s\r\n"),
411 ENCTYPE_NAME(encrypt_mode
));
414 (void) printf(gettext(
415 "Currently decrypting input with %s\r\n"),
416 ENCTYPE_NAME(decrypt_mode
));
417 } else if (decrypt_mode
) {
418 (void) printf(gettext("Currently input is clear text.\r\n"));
419 (void) printf(gettext("Last decryption mode was %s\r\n"),
420 ENCTYPE_NAME(decrypt_mode
));
426 encrypt_send_support(void)
430 * If the user has requested that decryption start
431 * immediatly, then send a "REQUEST START" before
432 * we negotiate the type.
435 encrypt_send_request_start();
436 (void) net_write(str_send
, str_suplen
);
437 printsub('>', &str_send
[2], str_suplen
- 2);
445 encrypt_debug_mode
= (on
< 0) ? !encrypt_debug_mode
:
446 (on
> 0) ? B_TRUE
: B_FALSE
;
447 (void) printf(encrypt_debug_mode
?
448 gettext("Encryption debugging enabled\r\n") :
449 gettext("Encryption debugging disabled\r\n"));
454 EncryptVerbose(int on
)
456 encrypt_verbose
= (on
< 0) ? !encrypt_verbose
:
457 (on
> 0) ? B_TRUE
: B_FALSE
;
458 (void) printf(encrypt_verbose
?
459 gettext("Encryption is verbose\r\n") :
460 gettext("Encryption is not verbose\r\n"));
465 EncryptAutoEnc(int on
)
468 (void) printf(autoencrypt
?
469 gettext("Automatic encryption of output is enabled\r\n") :
470 gettext("Automatic encryption of output is disabled\r\n"));
475 EncryptAutoDec(int on
)
478 (void) printf(autodecrypt
?
479 gettext("Automatic decryption of input is enabled\r\n") :
480 gettext("Automatic decryption of input is disabled\r\n"));
485 * Called when ENCRYPT SUPPORT is received.
488 encrypt_support(uchar_t
*typelist
, int cnt
)
490 register int type
, use_type
= 0;
494 * Forget anything the other side has previously told us.
496 remote_supports_decrypt
= 0;
500 if (encrypt_debug_mode
)
501 (void) printf(gettext(
502 ">>>%s: Remote host supports %s (%d)\r\n"),
503 Name
, ENCTYPE_NAME(type
), type
);
504 if ((type
< TELOPT_ENCTYPE_CNT
) &&
505 (I_SUPPORT_ENCRYPT
& typemask(type
))) {
506 remote_supports_decrypt
|= typemask(type
);
512 ep
= findencryption(use_type
);
515 type
= ep
->start
? (*ep
->start
)(TELNET_DIR_ENCRYPT
) : 0;
516 if (encrypt_debug_mode
)
517 (void) printf(gettext(
518 ">>>%s: (*ep->start)() returned %d\r\n"),
522 encrypt_mode
= use_type
;
524 encrypt_start_output(use_type
);
529 encrypt_is(uchar_t
*data
, int cnt
)
532 register int type
, ret
;
537 if (type
< TELOPT_ENCTYPE_CNT
)
538 remote_supports_encrypt
|= typemask(type
);
539 if (!(ep
= finddecryption(type
))) {
540 if (encrypt_debug_mode
)
541 (void) printf(gettext(
542 ">>>%s: Can't find type %s (%d) for "
543 "initial negotiation\r\n"), Name
,
544 ENCTYPE_NAME_OK(type
) ?
545 ENCTYPE_NAME(type
) : UNKNOWN
, type
);
549 if (encrypt_debug_mode
)
550 (void) printf(gettext(
551 ">>>%s: No initial negotiation needed "
552 "for type %s (%d)\r\n"), Name
,
553 ENCTYPE_NAME_OK(type
) ?
554 ENCTYPE_NAME(type
) : UNKNOWN
, type
);
557 ret
= (*ep
->is
)(data
, cnt
);
558 if (encrypt_debug_mode
)
559 (void) printf(gettext(
560 "(*ep->is)(%x, %d) returned %s(%d)\n"),
561 data
, cnt
, (ret
< 0) ? "FAIL " :
562 (ret
== 0) ? "SUCCESS " : "MORE_TO_DO ", ret
);
565 autodecrypt
= B_FALSE
;
568 if (ret
== 0 && autodecrypt
)
569 encrypt_send_request_start();
574 encrypt_reply(uchar_t
*data
, int cnt
)
577 register int ret
, type
;
582 if (!(ep
= findencryption(type
))) {
583 if (encrypt_debug_mode
)
584 (void) printf(gettext(
585 ">>>%s: Can't find type %s (%d) "
586 "for initial negotiation\r\n"), Name
,
587 ENCTYPE_NAME_OK(type
) ?
588 ENCTYPE_NAME(type
) : UNKNOWN
, type
);
592 if (encrypt_debug_mode
)
593 (void) printf(gettext(
594 ">>>%s: No initial negotiation needed "
595 "for type %s (%d)\r\n"), Name
,
596 ENCTYPE_NAME_OK(type
) ?
597 ENCTYPE_NAME(type
) : UNKNOWN
, type
);
600 ret
= (*ep
->reply
)(data
, cnt
);
601 if (encrypt_debug_mode
)
602 (void) printf(gettext(
603 "(*ep->reply)(%x, %d) returned %s(%d)\n"),
604 data
, cnt
, (ret
< 0) ? "FAIL " :
605 (ret
== 0) ? "SUCCESS " : "MORE_TO_DO ", ret
);
607 if (encrypt_debug_mode
)
608 (void) printf(gettext(
609 ">>>%s: encrypt_reply returned %d\n"), Name
, ret
);
611 autoencrypt
= B_FALSE
;
614 if (ret
== 0 && autoencrypt
)
615 encrypt_start_output(type
);
620 * Called when a ENCRYPT START command is received.
624 encrypt_start(uchar_t
*data
, int cnt
)
630 * Something is wrong. We should not get a START
631 * command without having already picked our
632 * decryption scheme. Send a REQUEST-END to
633 * attempt to clear the channel...
635 (void) printf(gettext("%s: Warning, cannot decrypt "
636 "input stream!!!\r\n"), Name
);
637 encrypt_send_request_end();
641 if (ep
= finddecryption(decrypt_mode
)) {
642 decrypt_input
= ep
->input
;
644 (void) printf(gettext(
645 "[ Input is now decrypted with type %s ]\r\n"),
646 ENCTYPE_NAME(decrypt_mode
));
647 if (encrypt_debug_mode
)
648 (void) printf(gettext(
649 ">>>%s: Start to decrypt input with type %s\r\n"),
650 Name
, ENCTYPE_NAME(decrypt_mode
));
652 (void) printf(gettext(
653 "%s: Warning, cannot decrypt type %s (%d)!!!\r\n"),
654 Name
, ENCTYPE_NAME_OK(decrypt_mode
) ?
655 ENCTYPE_NAME(decrypt_mode
) : UNKNOWN
,
657 encrypt_send_request_end();
662 encrypt_session_key(Session_Key
*key
)
664 Encryptions
*ep
= encryptions
;
670 if (!encrypt_output
&& autoencrypt
)
671 encrypt_start_output(ep
->type
);
672 if (!decrypt_input
&& autodecrypt
)
673 encrypt_send_request_start();
680 * Called when ENCRYPT END is received.
686 if (encrypt_debug_mode
)
687 (void) printf(gettext(
688 ">>>%s: Input is back to clear text\r\n"), Name
);
690 (void) printf(gettext("[ Input is now clear text ]\r\n"));
694 * Called when ENCRYPT REQUEST-END is received.
697 encrypt_request_end(void)
703 * Called when ENCRYPT REQUEST-START is received. If we receive
704 * this before a type is picked, then that indicates that the
705 * other side wants us to start encrypting data as soon as we
710 encrypt_request_start(uchar_t
*data
, int cnt
)
712 if (encrypt_mode
== 0)
714 encrypt_start_output(encrypt_mode
);
717 static uchar_t str_keyid
[(MAXKEYLEN
*2)+5] = { IAC
, SB
, TELOPT_ENCRYPT
};
718 static void encrypt_keyid(struct key_info
*, uchar_t
*, int);
721 encrypt_enc_keyid(uchar_t
*keyid
, int len
)
723 encrypt_keyid(&ki
[KI_DECRYPT
], keyid
, len
);
727 encrypt_dec_keyid(uchar_t
*keyid
, int len
)
729 encrypt_keyid(&ki
[KI_ENCRYPT
], keyid
, len
);
733 encrypt_keyid(struct key_info
*kp
, uchar_t
*keyid
, int len
)
737 register int ret
= 0;
739 if (!(ep
= (*kp
->getcrypt
)(*kp
->modep
))) {
743 } else if (len
== 0) {
745 * Empty option, indicates a failure.
751 (void) (*ep
->keyid
)(dir
, kp
->keyid
, &kp
->keylen
);
753 } else if ((len
!= kp
->keylen
) ||
754 (memcmp(keyid
, kp
->keyid
, len
) != 0)) {
756 * Length or contents are different
759 (void) memcpy(kp
->keyid
, keyid
, len
);
761 (void) (*ep
->keyid
)(dir
, kp
->keyid
, &kp
->keylen
);
764 ret
= (*ep
->keyid
)(dir
, kp
->keyid
, &kp
->keylen
);
765 if ((ret
== 0) && (dir
== TELNET_DIR_ENCRYPT
) && autoencrypt
)
766 encrypt_start_output(*kp
->modep
);
770 encrypt_send_keyid(dir
, kp
->keyid
, kp
->keylen
, 0);
774 encrypt_send_keyid(int dir
, uchar_t
*keyid
, int keylen
, int saveit
)
778 str_keyid
[3] = (dir
== TELNET_DIR_ENCRYPT
)
779 ? ENCRYPT_ENC_KEYID
: ENCRYPT_DEC_KEYID
;
781 struct key_info
*kp
= &ki
[(dir
== TELNET_DIR_ENCRYPT
) ? 0 : 1];
782 (void) memcpy(kp
->keyid
, keyid
, keylen
);
786 for (strp
= &str_keyid
[4]; keylen
> 0; --keylen
) {
787 if ((*strp
++ = *keyid
++) == IAC
)
792 (void) net_write(str_keyid
, strp
- str_keyid
);
793 printsub('>', &str_keyid
[2], strp
- str_keyid
- 2);
799 autoencrypt
= (on
< 0) ? !autoencrypt
:
800 (on
> 0) ? B_TRUE
: B_FALSE
;
806 autodecrypt
= (on
< 0) ? !autodecrypt
:
807 (on
> 0) ? B_TRUE
: B_FALSE
;
811 encrypt_start_output(int type
)
817 if (!(ep
= findencryption(type
))) {
818 if (encrypt_debug_mode
) {
819 (void) printf(gettext(
820 ">>>%s: Can't encrypt with type %s (%d)\r\n"),
821 Name
, ENCTYPE_NAME_OK(type
) ?
822 ENCTYPE_NAME(type
) : UNKNOWN
, type
);
827 i
= (*ep
->start
)(TELNET_DIR_ENCRYPT
);
828 if (encrypt_debug_mode
) {
829 (void) printf(gettext(
830 ">>>%s: Encrypt start: %s (%d) %s\r\n"),
833 gettext("initial negotiation in progress"),
834 i
, ENCTYPE_NAME(type
));
840 *p
++ = ENCRYPT_START
;
841 for (i
= 0; i
< ki
[KI_ENCRYPT
].keylen
; ++i
) {
842 if ((*p
++ = ki
[KI_ENCRYPT
].keyid
[i
]) == IAC
)
847 (void) net_write(str_start
, p
- str_start
);
849 printsub('>', &str_start
[2], p
- &str_start
[2]);
851 * If we are already encrypting in some mode, then
852 * encrypt the ring (which includes our request) in
853 * the old mode, mark it all as "clear text" and then
854 * switch to the new mode.
856 encrypt_output
= ep
->output
;
858 if (encrypt_debug_mode
)
859 (void) printf(gettext(
860 ">>>%s: Started to encrypt output with type %s\r\n"),
861 Name
, ENCTYPE_NAME(type
));
863 (void) printf(gettext(
864 "[ Output is now encrypted with type %s ]\r\n"),
869 encrypt_send_end(void)
874 str_end
[3] = ENCRYPT_END
;
875 (void) net_write(str_end
, sizeof (str_end
));
877 printsub('>', &str_end
[2], sizeof (str_end
) - 2);
879 * Encrypt the output buffer now because it will not be done by
883 if (encrypt_debug_mode
)
884 (void) printf(gettext(
885 ">>>%s: Output is back to clear text\r\n"), Name
);
887 (void) printf(gettext("[ Output is now clear text ]\r\n"));
891 encrypt_send_request_start(void)
897 *p
++ = ENCRYPT_REQSTART
;
898 for (i
= 0; i
< ki
[KI_DECRYPT
].keylen
; ++i
) {
899 if ((*p
++ = ki
[KI_DECRYPT
].keyid
[i
]) == IAC
)
904 (void) net_write(str_start
, p
- str_start
);
905 printsub('>', &str_start
[2], p
- &str_start
[2]);
906 if (encrypt_debug_mode
)
907 (void) printf(gettext(
908 ">>>%s: Request input to be encrypted\r\n"), Name
);
912 encrypt_send_request_end(void)
914 str_end
[3] = ENCRYPT_REQEND
;
915 (void) net_write(str_end
, sizeof (str_end
));
916 printsub('>', &str_end
[2], sizeof (str_end
) - 2);
918 if (encrypt_debug_mode
)
919 (void) printf(gettext(
920 ">>>%s: Request input to be clear text\r\n"), Name
);
924 encrypt_is_encrypting(void)
926 return (encrypt_output
&& decrypt_input
? B_TRUE
: B_FALSE
);
930 encrypt_gen_printsub(uchar_t
*data
, int cnt
, uchar_t
*buf
, int buflen
)
932 char lbuf
[ENCR_LBUF_BUFSIZ
], *cp
;
934 if (cnt
< 2 || buflen
< 2)
938 buf
[buflen
-1] = '\0';
941 for (; cnt
> 0; cnt
--, data
++) {
942 (void) snprintf(lbuf
, ENCR_LBUF_BUFSIZ
, " %d", *data
);
943 for (cp
= lbuf
; *cp
&& buflen
> 0; --buflen
)
952 encrypt_printsub(uchar_t
*data
, int cnt
, uchar_t
*buf
, int buflen
)
955 register int type
= data
[1];
957 for (ep
= encryptions
; ep
->type
&& ep
->type
!= type
; ep
++)
961 (*ep
->printsub
)(data
, cnt
, buf
, buflen
);
963 encrypt_gen_printsub(data
, cnt
, buf
, buflen
);