2 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 #pragma ident "%Z%%M% %I% %E% SMI"
9 * usr/src/cmd/cmd-inet/usr.bin/telnet/encrypt.c
13 * Copyright (c) 1991, 1993
14 * The Regents of the University of California. All rights reserved.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 /* based on @(#)encrypt.c 8.1 (Berkeley) 6/4/93 */
48 * Copyright (C) 1990 by the Massachusetts Institute of Technology
50 * Export of this software from the United States of America may
51 * require a specific license from the United States Government.
52 * It is the responsibility of any person or organization contemplating
53 * export to obtain such a license before exporting.
55 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
56 * distribute this software and its documentation for any purpose and
57 * without fee is hereby granted, provided that the above copyright
58 * notice appear in all copies and that both that copyright notice and
59 * this permission notice appear in supporting documentation, and that
60 * the name of M.I.T. not be used in advertising or publicity pertaining
61 * to distribution of the software without specific, written prior
62 * permission. Furthermore if you modify this software you must label
63 * your software as modified software and not distribute it in such a
64 * fashion that it might be confused with the original M.I.T. software.
65 * M.I.T. makes no representations about the suitability of
66 * this software for any purpose. It is provided "as is" without express
67 * or implied warranty.
71 static char *encrypt_names
[] = {0};
72 static char *enctype_names
[] = {0};
76 #include <arpa/telnet.h>
85 * These functions pointers point to the current routines
86 * for encrypting and decrypting data.
88 void (*encrypt_output
)(uchar_t
*, int);
89 int (*decrypt_input
)(int);
90 static void encrypt_start_output(int);
91 static void encrypt_send_end(void);
92 static void encrypt_send_request_start(void);
93 static void encrypt_send_request_end(void);
95 boolean_t encrypt_debug_mode
= B_FALSE
;
97 static int decrypt_mode
= 0;
98 static int encrypt_mode
= 0;
99 static boolean_t encrypt_verbose
= B_FALSE
;
100 static boolean_t autoencrypt
= B_FALSE
;
101 static boolean_t autodecrypt
= B_FALSE
;
102 static char *Name
= "Noname";
104 #define typemask(x) ((x) > 0 ? 1 << ((x)-1) : 0)
106 #define UNKNOWN gettext("(unknown)")
108 static int i_support_encrypt
= typemask(TELOPT_ENCTYPE_DES_CFB64
);
109 static int i_support_decrypt
= typemask(TELOPT_ENCTYPE_DES_CFB64
);
110 static int i_wont_support_encrypt
= 0;
111 static int i_wont_support_decrypt
= 0;
112 #define I_SUPPORT_ENCRYPT (i_support_encrypt & ~i_wont_support_encrypt)
113 #define I_SUPPORT_DECRYPT (i_support_decrypt & ~i_wont_support_decrypt)
115 static int remote_supports_encrypt
= 0;
116 static int remote_supports_decrypt
= 0;
118 static Encryptions encryptions
[] = {
119 { "DES_CFB64", TELOPT_ENCTYPE_DES_CFB64
,
132 static uchar_t str_send
[64] = { IAC
, SB
, TELOPT_ENCRYPT
,
134 static uchar_t str_suplen
= 0;
135 static uchar_t str_start
[72] = { IAC
, SB
, TELOPT_ENCRYPT
};
136 static uchar_t str_end
[] = { IAC
, SB
, TELOPT_ENCRYPT
, 0, IAC
, SE
};
139 findencryption(int type
)
141 Encryptions
*ep
= encryptions
;
143 if (!(I_SUPPORT_ENCRYPT
& remote_supports_decrypt
& typemask(type
)))
145 for (; (ep
->type
!= NULL
) && (ep
->type
!= type
); ep
++);
146 return (ep
->type
? ep
: NULL
);
150 finddecryption(int type
)
152 Encryptions
*ep
= encryptions
;
154 if (!(I_SUPPORT_DECRYPT
& remote_supports_encrypt
& typemask(type
)))
156 while (ep
->type
&& ep
->type
!= type
)
158 return (ep
->type
? ep
: NULL
);
163 static struct key_info
{
164 uchar_t keyid
[MAXKEYLEN
];
168 Encryptions
*(*getcrypt
)();
170 { { 0 }, 0, TELNET_DIR_ENCRYPT
, &encrypt_mode
, findencryption
},
171 { { 0 }, 0, TELNET_DIR_DECRYPT
, &decrypt_mode
, finddecryption
},
177 encrypt_init(char *name
)
179 Encryptions
*ep
= encryptions
;
182 i_support_encrypt
= i_support_decrypt
= 0;
183 remote_supports_encrypt
= remote_supports_decrypt
= 0;
189 encrypt_verbose
= !server
;
195 if (encrypt_debug_mode
)
196 (void) printf(gettext(
197 ">>>%s: I will support %s\r\n"),
198 Name
, ENCTYPE_NAME(ep
->type
));
199 i_support_encrypt
|= typemask(ep
->type
);
200 i_support_decrypt
|= typemask(ep
->type
);
201 if ((i_wont_support_decrypt
& typemask(ep
->type
)) == 0)
202 if ((str_send
[str_suplen
++] = ep
->type
) == IAC
)
203 str_send
[str_suplen
++] = IAC
;
208 str_send
[str_suplen
++] = IAC
;
209 str_send
[str_suplen
++] = SE
;
213 encrypt_list_types(void)
215 Encryptions
*ep
= encryptions
;
217 (void) printf(gettext("Valid encryption types:\n"));
219 (void) printf("\t%s (%d)\r\n",
220 ENCTYPE_NAME(ep
->type
), ep
->type
);
226 EncryptEnable(char *type
, char *mode
)
228 if (isprefix(type
, "help") || isprefix(type
, "?")) {
229 (void) printf(gettext(
230 "Usage: encrypt enable <type> [input|output]\n"));
231 encrypt_list_types();
235 if (EncryptType(type
, mode
))
236 return (EncryptStart(mode
));
242 EncryptDisable(char *type
, char *mode
)
244 register Encryptions
*ep
;
247 if (isprefix(type
, "help") || isprefix(type
, "?")) {
248 (void) printf(gettext(
249 "Usage: encrypt disable <type> [input|output]\n"));
250 encrypt_list_types();
251 } else if ((ep
= (Encryptions
*)genget(type
, (char **)encryptions
,
252 sizeof (Encryptions
))) == 0) {
253 (void) printf(gettext("%s: invalid encryption type\n"), type
);
254 } else if (Ambiguous(ep
)) {
255 (void) printf(gettext("Ambiguous type '%s'\n"), type
);
257 if ((mode
== 0) || (isprefix(mode
, "input") ? 1 : 0)) {
258 if (decrypt_mode
== ep
->type
)
259 (void) EncryptStopInput();
260 i_wont_support_decrypt
|= typemask(ep
->type
);
263 if ((mode
== 0) || (isprefix(mode
, "output"))) {
264 if (encrypt_mode
== ep
->type
)
265 (void) EncryptStopOutput();
266 i_wont_support_encrypt
|= typemask(ep
->type
);
270 (void) printf(gettext(
271 "%s: invalid encryption mode\n"), mode
);
277 EncryptType(char *type
, char *mode
)
279 register Encryptions
*ep
;
282 if (isprefix(type
, "help") || isprefix(type
, "?")) {
283 (void) printf(gettext(
284 "Usage: encrypt type <type> [input|output]\n"));
285 encrypt_list_types();
286 } else if ((ep
= (Encryptions
*)genget(type
, (char **)encryptions
,
287 sizeof (Encryptions
))) == 0) {
288 (void) printf(gettext("%s: invalid encryption type\n"), type
);
289 } else if (Ambiguous(ep
)) {
290 (void) printf(gettext("Ambiguous type '%s'\n"), type
);
292 if ((mode
== 0) || isprefix(mode
, "input")) {
293 decrypt_mode
= ep
->type
;
294 i_wont_support_decrypt
&= ~typemask(ep
->type
);
297 if ((mode
== 0) || isprefix(mode
, "output")) {
298 encrypt_mode
= ep
->type
;
299 i_wont_support_encrypt
&= ~typemask(ep
->type
);
303 (void) printf(gettext(
304 "%s: invalid encryption mode\n"), mode
);
310 EncryptStart(char *mode
)
312 register int ret
= 0;
314 if (isprefix(mode
, "input"))
315 return (EncryptStartInput());
316 if (isprefix(mode
, "output"))
317 return (EncryptStartOutput());
318 if (isprefix(mode
, "help") || isprefix(mode
, "?")) {
319 (void) printf(gettext(
320 "Usage: encrypt start [input|output]\n"));
323 (void) printf(gettext(
324 "%s: invalid encryption mode 'encrypt start ?' "
325 "for help\n"), mode
);
328 ret
+= EncryptStartInput();
329 ret
+= EncryptStartOutput();
334 EncryptStartInput(void)
337 encrypt_send_request_start();
340 (void) printf(gettext("No previous decryption mode, "
341 "decryption not enabled\r\n"));
346 EncryptStartOutput(void)
349 encrypt_start_output(encrypt_mode
);
352 (void) printf(gettext("No previous encryption mode, "
353 "encryption not enabled\r\n"));
358 EncryptStop(char *mode
)
362 if (isprefix(mode
, "input"))
363 return (EncryptStopInput());
364 if (isprefix(mode
, "output"))
365 return (EncryptStopOutput());
366 if (isprefix(mode
, "help") || isprefix(mode
, "?")) {
367 (void) printf(gettext(
368 "Usage: encrypt stop [input|output]\n"));
371 (void) printf(gettext(
372 "%s: invalid encryption mode 'encrypt stop ?' "
373 "for help\n"), mode
);
376 ret
+= EncryptStopInput();
377 ret
+= EncryptStopOutput();
382 EncryptStopInput(void)
384 encrypt_send_request_end();
389 EncryptStopOutput(void)
396 encrypt_display(void)
399 (void) printf(gettext(
400 "Currently encrypting output with %s\r\n"),
401 ENCTYPE_NAME(encrypt_mode
));
403 (void) printf(gettext(
404 "Currently decrypting input with %s\r\n"),
405 ENCTYPE_NAME(decrypt_mode
));
412 (void) printf(gettext(
413 "Currently encrypting output with %s\r\n"),
414 ENCTYPE_NAME(encrypt_mode
));
415 else if (encrypt_mode
) {
416 (void) printf(gettext("Currently output is clear text.\r\n"));
417 (void) printf(gettext("Last encryption mode was %s\r\n"),
418 ENCTYPE_NAME(encrypt_mode
));
421 (void) printf(gettext(
422 "Currently decrypting input with %s\r\n"),
423 ENCTYPE_NAME(decrypt_mode
));
424 } else if (decrypt_mode
) {
425 (void) printf(gettext("Currently input is clear text.\r\n"));
426 (void) printf(gettext("Last decryption mode was %s\r\n"),
427 ENCTYPE_NAME(decrypt_mode
));
433 encrypt_send_support(void)
437 * If the user has requested that decryption start
438 * immediatly, then send a "REQUEST START" before
439 * we negotiate the type.
442 encrypt_send_request_start();
443 (void) net_write(str_send
, str_suplen
);
444 printsub('>', &str_send
[2], str_suplen
- 2);
452 encrypt_debug_mode
= (on
< 0) ? !encrypt_debug_mode
:
453 (on
> 0) ? B_TRUE
: B_FALSE
;
454 (void) printf(encrypt_debug_mode
?
455 gettext("Encryption debugging enabled\r\n") :
456 gettext("Encryption debugging disabled\r\n"));
461 EncryptVerbose(int on
)
463 encrypt_verbose
= (on
< 0) ? !encrypt_verbose
:
464 (on
> 0) ? B_TRUE
: B_FALSE
;
465 (void) printf(encrypt_verbose
?
466 gettext("Encryption is verbose\r\n") :
467 gettext("Encryption is not verbose\r\n"));
472 EncryptAutoEnc(int on
)
475 (void) printf(autoencrypt
?
476 gettext("Automatic encryption of output is enabled\r\n") :
477 gettext("Automatic encryption of output is disabled\r\n"));
482 EncryptAutoDec(int on
)
485 (void) printf(autodecrypt
?
486 gettext("Automatic decryption of input is enabled\r\n") :
487 gettext("Automatic decryption of input is disabled\r\n"));
492 * Called when ENCRYPT SUPPORT is received.
495 encrypt_support(uchar_t
*typelist
, int cnt
)
497 register int type
, use_type
= 0;
501 * Forget anything the other side has previously told us.
503 remote_supports_decrypt
= 0;
507 if (encrypt_debug_mode
)
508 (void) printf(gettext(
509 ">>>%s: Remote host supports %s (%d)\r\n"),
510 Name
, ENCTYPE_NAME(type
), type
);
511 if ((type
< TELOPT_ENCTYPE_CNT
) &&
512 (I_SUPPORT_ENCRYPT
& typemask(type
))) {
513 remote_supports_decrypt
|= typemask(type
);
519 ep
= findencryption(use_type
);
522 type
= ep
->start
? (*ep
->start
)(TELNET_DIR_ENCRYPT
) : 0;
523 if (encrypt_debug_mode
)
524 (void) printf(gettext(
525 ">>>%s: (*ep->start)() returned %d\r\n"),
529 encrypt_mode
= use_type
;
531 encrypt_start_output(use_type
);
536 encrypt_is(uchar_t
*data
, int cnt
)
539 register int type
, ret
;
544 if (type
< TELOPT_ENCTYPE_CNT
)
545 remote_supports_encrypt
|= typemask(type
);
546 if (!(ep
= finddecryption(type
))) {
547 if (encrypt_debug_mode
)
548 (void) printf(gettext(
549 ">>>%s: Can't find type %s (%d) for "
550 "initial negotiation\r\n"), Name
,
551 ENCTYPE_NAME_OK(type
) ?
552 ENCTYPE_NAME(type
) : UNKNOWN
, type
);
556 if (encrypt_debug_mode
)
557 (void) printf(gettext(
558 ">>>%s: No initial negotiation needed "
559 "for type %s (%d)\r\n"), Name
,
560 ENCTYPE_NAME_OK(type
) ?
561 ENCTYPE_NAME(type
) : UNKNOWN
, type
);
564 ret
= (*ep
->is
)(data
, cnt
);
565 if (encrypt_debug_mode
)
566 (void) printf(gettext(
567 "(*ep->is)(%x, %d) returned %s(%d)\n"),
568 data
, cnt
, (ret
< 0) ? "FAIL " :
569 (ret
== 0) ? "SUCCESS " : "MORE_TO_DO ", ret
);
572 autodecrypt
= B_FALSE
;
575 if (ret
== 0 && autodecrypt
)
576 encrypt_send_request_start();
581 encrypt_reply(uchar_t
*data
, int cnt
)
584 register int ret
, type
;
589 if (!(ep
= findencryption(type
))) {
590 if (encrypt_debug_mode
)
591 (void) printf(gettext(
592 ">>>%s: Can't find type %s (%d) "
593 "for initial negotiation\r\n"), Name
,
594 ENCTYPE_NAME_OK(type
) ?
595 ENCTYPE_NAME(type
) : UNKNOWN
, type
);
599 if (encrypt_debug_mode
)
600 (void) printf(gettext(
601 ">>>%s: No initial negotiation needed "
602 "for type %s (%d)\r\n"), Name
,
603 ENCTYPE_NAME_OK(type
) ?
604 ENCTYPE_NAME(type
) : UNKNOWN
, type
);
607 ret
= (*ep
->reply
)(data
, cnt
);
608 if (encrypt_debug_mode
)
609 (void) printf(gettext(
610 "(*ep->reply)(%x, %d) returned %s(%d)\n"),
611 data
, cnt
, (ret
< 0) ? "FAIL " :
612 (ret
== 0) ? "SUCCESS " : "MORE_TO_DO ", ret
);
614 if (encrypt_debug_mode
)
615 (void) printf(gettext(
616 ">>>%s: encrypt_reply returned %d\n"), Name
, ret
);
618 autoencrypt
= B_FALSE
;
621 if (ret
== 0 && autoencrypt
)
622 encrypt_start_output(type
);
627 * Called when a ENCRYPT START command is received.
631 encrypt_start(uchar_t
*data
, int cnt
)
637 * Something is wrong. We should not get a START
638 * command without having already picked our
639 * decryption scheme. Send a REQUEST-END to
640 * attempt to clear the channel...
642 (void) printf(gettext("%s: Warning, cannot decrypt "
643 "input stream!!!\r\n"), Name
);
644 encrypt_send_request_end();
648 if (ep
= finddecryption(decrypt_mode
)) {
649 decrypt_input
= ep
->input
;
651 (void) printf(gettext(
652 "[ Input is now decrypted with type %s ]\r\n"),
653 ENCTYPE_NAME(decrypt_mode
));
654 if (encrypt_debug_mode
)
655 (void) printf(gettext(
656 ">>>%s: Start to decrypt input with type %s\r\n"),
657 Name
, ENCTYPE_NAME(decrypt_mode
));
659 (void) printf(gettext(
660 "%s: Warning, cannot decrypt type %s (%d)!!!\r\n"),
661 Name
, ENCTYPE_NAME_OK(decrypt_mode
) ?
662 ENCTYPE_NAME(decrypt_mode
) : UNKNOWN
,
664 encrypt_send_request_end();
669 encrypt_session_key(Session_Key
*key
)
671 Encryptions
*ep
= encryptions
;
677 if (!encrypt_output
&& autoencrypt
)
678 encrypt_start_output(ep
->type
);
679 if (!decrypt_input
&& autodecrypt
)
680 encrypt_send_request_start();
687 * Called when ENCRYPT END is received.
693 if (encrypt_debug_mode
)
694 (void) printf(gettext(
695 ">>>%s: Input is back to clear text\r\n"), Name
);
697 (void) printf(gettext("[ Input is now clear text ]\r\n"));
701 * Called when ENCRYPT REQUEST-END is received.
704 encrypt_request_end(void)
710 * Called when ENCRYPT REQUEST-START is received. If we receive
711 * this before a type is picked, then that indicates that the
712 * other side wants us to start encrypting data as soon as we
717 encrypt_request_start(uchar_t
*data
, int cnt
)
719 if (encrypt_mode
== 0)
721 encrypt_start_output(encrypt_mode
);
724 static uchar_t str_keyid
[(MAXKEYLEN
*2)+5] = { IAC
, SB
, TELOPT_ENCRYPT
};
725 static void encrypt_keyid(struct key_info
*, uchar_t
*, int);
728 encrypt_enc_keyid(uchar_t
*keyid
, int len
)
730 encrypt_keyid(&ki
[KI_DECRYPT
], keyid
, len
);
734 encrypt_dec_keyid(uchar_t
*keyid
, int len
)
736 encrypt_keyid(&ki
[KI_ENCRYPT
], keyid
, len
);
740 encrypt_keyid(struct key_info
*kp
, uchar_t
*keyid
, int len
)
744 register int ret
= 0;
746 if (!(ep
= (*kp
->getcrypt
)(*kp
->modep
))) {
750 } else if (len
== 0) {
752 * Empty option, indicates a failure.
758 (void) (*ep
->keyid
)(dir
, kp
->keyid
, &kp
->keylen
);
760 } else if ((len
!= kp
->keylen
) ||
761 (memcmp(keyid
, kp
->keyid
, len
) != 0)) {
763 * Length or contents are different
766 (void) memcpy(kp
->keyid
, keyid
, len
);
768 (void) (*ep
->keyid
)(dir
, kp
->keyid
, &kp
->keylen
);
771 ret
= (*ep
->keyid
)(dir
, kp
->keyid
, &kp
->keylen
);
772 if ((ret
== 0) && (dir
== TELNET_DIR_ENCRYPT
) && autoencrypt
)
773 encrypt_start_output(*kp
->modep
);
777 encrypt_send_keyid(dir
, kp
->keyid
, kp
->keylen
, 0);
781 encrypt_send_keyid(int dir
, uchar_t
*keyid
, int keylen
, int saveit
)
785 str_keyid
[3] = (dir
== TELNET_DIR_ENCRYPT
)
786 ? ENCRYPT_ENC_KEYID
: ENCRYPT_DEC_KEYID
;
788 struct key_info
*kp
= &ki
[(dir
== TELNET_DIR_ENCRYPT
) ? 0 : 1];
789 (void) memcpy(kp
->keyid
, keyid
, keylen
);
793 for (strp
= &str_keyid
[4]; keylen
> 0; --keylen
) {
794 if ((*strp
++ = *keyid
++) == IAC
)
799 (void) net_write(str_keyid
, strp
- str_keyid
);
800 printsub('>', &str_keyid
[2], strp
- str_keyid
- 2);
806 autoencrypt
= (on
< 0) ? !autoencrypt
:
807 (on
> 0) ? B_TRUE
: B_FALSE
;
813 autodecrypt
= (on
< 0) ? !autodecrypt
:
814 (on
> 0) ? B_TRUE
: B_FALSE
;
818 encrypt_start_output(int type
)
824 if (!(ep
= findencryption(type
))) {
825 if (encrypt_debug_mode
) {
826 (void) printf(gettext(
827 ">>>%s: Can't encrypt with type %s (%d)\r\n"),
828 Name
, ENCTYPE_NAME_OK(type
) ?
829 ENCTYPE_NAME(type
) : UNKNOWN
, type
);
834 i
= (*ep
->start
)(TELNET_DIR_ENCRYPT
);
835 if (encrypt_debug_mode
) {
836 (void) printf(gettext(
837 ">>>%s: Encrypt start: %s (%d) %s\r\n"),
840 gettext("initial negotiation in progress"),
841 i
, ENCTYPE_NAME(type
));
847 *p
++ = ENCRYPT_START
;
848 for (i
= 0; i
< ki
[KI_ENCRYPT
].keylen
; ++i
) {
849 if ((*p
++ = ki
[KI_ENCRYPT
].keyid
[i
]) == IAC
)
854 (void) net_write(str_start
, p
- str_start
);
856 printsub('>', &str_start
[2], p
- &str_start
[2]);
858 * If we are already encrypting in some mode, then
859 * encrypt the ring (which includes our request) in
860 * the old mode, mark it all as "clear text" and then
861 * switch to the new mode.
863 encrypt_output
= ep
->output
;
865 if (encrypt_debug_mode
)
866 (void) printf(gettext(
867 ">>>%s: Started to encrypt output with type %s\r\n"),
868 Name
, ENCTYPE_NAME(type
));
870 (void) printf(gettext(
871 "[ Output is now encrypted with type %s ]\r\n"),
876 encrypt_send_end(void)
881 str_end
[3] = ENCRYPT_END
;
882 (void) net_write(str_end
, sizeof (str_end
));
884 printsub('>', &str_end
[2], sizeof (str_end
) - 2);
886 * Encrypt the output buffer now because it will not be done by
890 if (encrypt_debug_mode
)
891 (void) printf(gettext(
892 ">>>%s: Output is back to clear text\r\n"), Name
);
894 (void) printf(gettext("[ Output is now clear text ]\r\n"));
898 encrypt_send_request_start(void)
904 *p
++ = ENCRYPT_REQSTART
;
905 for (i
= 0; i
< ki
[KI_DECRYPT
].keylen
; ++i
) {
906 if ((*p
++ = ki
[KI_DECRYPT
].keyid
[i
]) == IAC
)
911 (void) net_write(str_start
, p
- str_start
);
912 printsub('>', &str_start
[2], p
- &str_start
[2]);
913 if (encrypt_debug_mode
)
914 (void) printf(gettext(
915 ">>>%s: Request input to be encrypted\r\n"), Name
);
919 encrypt_send_request_end(void)
921 str_end
[3] = ENCRYPT_REQEND
;
922 (void) net_write(str_end
, sizeof (str_end
));
923 printsub('>', &str_end
[2], sizeof (str_end
) - 2);
925 if (encrypt_debug_mode
)
926 (void) printf(gettext(
927 ">>>%s: Request input to be clear text\r\n"), Name
);
931 encrypt_is_encrypting(void)
933 return (encrypt_output
&& decrypt_input
? B_TRUE
: B_FALSE
);
937 encrypt_gen_printsub(uchar_t
*data
, int cnt
, uchar_t
*buf
, int buflen
)
939 char lbuf
[ENCR_LBUF_BUFSIZ
], *cp
;
941 if (cnt
< 2 || buflen
< 2)
945 buf
[buflen
-1] = '\0';
948 for (; cnt
> 0; cnt
--, data
++) {
949 (void) snprintf(lbuf
, ENCR_LBUF_BUFSIZ
, " %d", *data
);
950 for (cp
= lbuf
; *cp
&& buflen
> 0; --buflen
)
959 encrypt_printsub(uchar_t
*data
, int cnt
, uchar_t
*buf
, int buflen
)
962 register int type
= data
[1];
964 for (ep
= encryptions
; ep
->type
&& ep
->type
!= type
; ep
++)
968 (*ep
->printsub
)(data
, cnt
, buf
, buflen
);
970 encrypt_gen_printsub(data
, cnt
, buf
, buflen
);