xref: /illumos-gate/usr/src/head/arpa/telnet.h (revision d1aea6f139360e9e7f1504facb24f8521047b15c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  * Copyright (c) 2016 by Delphix. All rights reserved.
26  */
27 
28 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
29 /*	  All Rights Reserved  	*/
30 
31 /*
32  * Portions of this source code were derived from Berkeley 4.3 BSD
33  * under license from the Regents of the University of California.
34  */
35 
36 #ifndef	_ARPA_TELNET_H
37 #define	_ARPA_TELNET_H
38 
39 #pragma ident	"%Z%%M%	%I%	%E% SMI"
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * Definitions for the TELNET protocol.
47  */
48 #define	IAC	255		/* interpret as command: */
49 #define	DONT	254		/* you are not to use option */
50 #define	DO	253		/* please, you use option */
51 #define	WONT	252		/* I won't use option */
52 #define	WILL	251		/* I will use option */
53 #define	SB	250		/* interpret as subnegotiation */
54 #define	GA	249		/* you may reverse the line */
55 #define	EL	248		/* erase the current line */
56 #define	EC	247		/* erase the current character */
57 #define	AYT	246		/* are you there */
58 #define	AO	245		/* abort output--but let prog finish */
59 #define	IP	244		/* interrupt process--permanently */
60 #define	BREAK	243		/* break */
61 #define	DM	242		/* data mark--for connect. cleaning */
62 #define	NOP	241		/* nop */
63 #define	SE	240		/* end sub negotiation */
64 #define	EOR	239		/* end of record (transparent mode) */
65 #define	ABORT	238		/* Abort process */
66 #define	SUSP	237		/* Suspend process */
67 #define	xEOF	236		/* End of file: EOF is already used... */
68 
69 #define	SYNCH	242		/* for telfunc calls */
70 
71 #ifdef TELCMDS
72 char *telcmds[] = {
73 	"EOF", "SUSP", "ABORT", "EOR",
74 	"SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
75 	"EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0
76 };
77 #endif
78 
79 #define	TELCMD_FIRST	xEOF
80 #define	TELCMD_LAST	IAC
81 #define	TELCMD_OK(x)	((unsigned int)(x) <= TELCMD_LAST && \
82 			    (unsigned int)(x) >= TELCMD_FIRST)
83 #define	TELCMD(x)	telcmds[(x)-TELCMD_FIRST]
84 
85 /* telnet options */
86 #define	TELOPT_BINARY	0	/* 8-bit data path */
87 #define	TELOPT_ECHO	1	/* echo */
88 #define	TELOPT_RCP	2	/* prepare to reconnect */
89 #define	TELOPT_SGA	3	/* suppress go ahead */
90 #define	TELOPT_NAMS	4	/* approximate message size */
91 #define	TELOPT_STATUS	5	/* give status */
92 #define	TELOPT_TM	6	/* timing mark */
93 #define	TELOPT_RCTE	7	/* remote controlled transmission and echo */
94 #define	TELOPT_NAOL 	8	/* negotiate about output line width */
95 #define	TELOPT_NAOP 	9	/* negotiate about output page size */
96 #define	TELOPT_NAOCRD	10	/* negotiate about CR disposition */
97 #define	TELOPT_NAOHTS	11	/* negotiate about horizontal tabstops */
98 #define	TELOPT_NAOHTD	12	/* negotiate about horizontal tab disposition */
99 #define	TELOPT_NAOFFD	13	/* negotiate about formfeed disposition */
100 #define	TELOPT_NAOVTS	14	/* negotiate about vertical tab stops */
101 #define	TELOPT_NAOVTD	15	/* negotiate about vertical tab disposition */
102 #define	TELOPT_NAOLFD	16	/* negotiate about output LF disposition */
103 #define	TELOPT_XASCII	17	/* extended ascic character set */
104 #define	TELOPT_LOGOUT	18	/* force logout */
105 #define	TELOPT_BM	19	/* byte macro */
106 #define	TELOPT_DET	20	/* data entry terminal */
107 #define	TELOPT_SUPDUP	21	/* supdup protocol */
108 #define	TELOPT_SUPDUPOUTPUT 22	/* supdup output */
109 #define	TELOPT_SNDLOC	23	/* send location */
110 #define	TELOPT_TTYPE	24	/* terminal type */
111 #define	TELOPT_EOR	25	/* end or record */
112 #define	TELOPT_TUID	26	/* TACACS user identification */
113 #define	TELOPT_OUTMRK	27	/* output marking */
114 #define	TELOPT_TTYLOC	28	/* terminal location number */
115 #define	TELOPT_3270REGIME 29	/* 3270 regime */
116 #define	TELOPT_X3PAD	30	/* X.3 PAD */
117 #define	TELOPT_NAWS	31	/* window size */
118 #define	TELOPT_TSPEED	32	/* terminal speed */
119 #define	TELOPT_LFLOW	33	/* remote flow control */
120 #define	TELOPT_LINEMODE	34	/* Linemode option */
121 #define	TELOPT_XDISPLOC	35	/* X Display Location */
122 #define	TELOPT_OLD_ENVIRON 36	/* Old - Environment variables */
123 #define	TELOPT_AUTHENTICATION 37 /* Authenticate */
124 #define	TELOPT_ENCRYPT	38	/* Encryption option */
125 #define	TELOPT_NEW_ENVIRON 39	/* New - Environment variables */
126 #define	TELOPT_EXOPL	255	/* extended-options-list */
127 
128 #ifdef TELOPTS
129 #define	NTELOPTS	(1+TELOPT_NEW_ENVIRON)
130 char *telopts[NTELOPTS+1] = {
131 	"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
132 	"STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
133 	"NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
134 	"NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
135 	"DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
136 	"SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
137 	"TACACS UID", "OUTPUT MARKING", "TTYLOC",
138 	"3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
139 	"LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
140 	"ENCRYPT", "NEW-ENVIRON",
141 	0,
142 };
143 #endif /* TELOPTS */
144 #define	TELOPT_FIRST	TELOPT_BINARY
145 #define	TELOPT_LAST	TELOPT_NEW_ENVIRON
146 #define	TELOPT_OK(x)	((unsigned int)(x) <= TELOPT_LAST)
147 #define	TELOPT(x)	telopts[(x)-TELOPT_FIRST]
148 
149 /* sub-option qualifiers */
150 #define	TELQUAL_IS	0	/* option is... */
151 #define	TELQUAL_SEND	1	/* send option */
152 #define	TELQUAL_INFO	2	/* ENVIRON: informational version of IS */
153 #define	TELQUAL_REPLY	2	/* AUTHENTICATION: client version of IS */
154 #define	TELQUAL_NAME	3	/* AUTHENTICATION: client version of IS */
155 
156 #define	LFLOW_OFF		0	/* Disable remote flow control */
157 #define	LFLOW_ON		1	/* Enable remote flow control */
158 #define	LFLOW_RESTART_ANY	2	/* Restart output on any char */
159 #define	LFLOW_RESTART_XON	3	/* Restart output only on XON */
160 
161 /*
162  * LINEMODE suboptions
163  */
164 
165 #define	LM_MODE		1
166 #define	LM_FORWARDMASK	2
167 #define	LM_SLC		3
168 
169 #define	MODE_EDIT	0x01
170 #define	MODE_TRAPSIG	0x02
171 #define	MODE_ACK	0x04
172 #define	MODE_SOFT_TAB	0x08
173 #define	MODE_LIT_ECHO	0x10
174 
175 #define	MODE_MASK	0x1f
176 
177 /* Not part of protocol, but needed to simplify things... */
178 #define	MODE_FLOW		0x0100
179 #define	MODE_ECHO		0x0200
180 #define	MODE_INBIN		0x0400
181 #define	MODE_OUTBIN		0x0800
182 #define	MODE_FORCE		0x1000
183 
184 #define	SLC_SYNCH	1
185 #define	SLC_BRK		2
186 #define	SLC_IP		3
187 #define	SLC_AO		4
188 #define	SLC_AYT		5
189 #define	SLC_EOR		6
190 #define	SLC_ABORT	7
191 #define	SLC_EOF		8
192 #define	SLC_SUSP	9
193 #define	SLC_EC		10
194 #define	SLC_EL		11
195 #define	SLC_EW		12
196 #define	SLC_RP		13
197 #define	SLC_LNEXT	14
198 #define	SLC_XON		15
199 #define	SLC_XOFF	16
200 #define	SLC_FORW1	17
201 #define	SLC_FORW2	18
202 
203 #define	NSLC		18
204 
205 /*
206  * For backwards compatability, we define SLC_NAMES to be the
207  * list of names if SLC_NAMES is not defined.
208  */
209 #define	SLC_NAMELIST	"0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \
210 			"ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \
211 			"LNEXT", "XON", "XOFF", "FORW1", "FORW2", 0,
212 #ifdef	SLC_NAMES
213 char *slc_names[] = {
214 	SLC_NAMELIST
215 };
216 #else
217 extern char *slc_names[];
218 #define	SLC_NAMES SLC_NAMELIST
219 #endif
220 
221 #define	SLC_NAME_OK(x)	((unsigned int)(x) <= NSLC)
222 #define	SLC_NAME(x)	slc_names[x]
223 
224 #define	SLC_NOSUPPORT	0
225 #define	SLC_CANTCHANGE	1
226 #define	SLC_VARIABLE	2
227 #define	SLC_DEFAULT	3
228 #define	SLC_LEVELBITS	0x03
229 
230 #define	SLC_FUNC	0
231 #define	SLC_FLAGS	1
232 #define	SLC_VALUE	2
233 
234 #define	SLC_ACK		0x80
235 #define	SLC_FLUSHIN	0x40
236 #define	SLC_FLUSHOUT	0x20
237 
238 #define	OLD_ENV_VAR	1
239 #define	OLD_ENV_VALUE	0
240 #define	NEW_ENV_VAR	0
241 #define	NEW_ENV_VALUE	1
242 #define	ENV_ESC		2
243 #define	ENV_USERVAR	3
244 
245 /*
246  * AUTHENTICATION suboptions
247  */
248 #define	AUTH_REJECT	0	/* Rejected */
249 #define	AUTH_UNKNOWN	1	/* We don't know who it is, but it's okay */
250 #define	AUTH_OTHER	2	/* We know it, but not it's name */
251 #define	AUTH_USER	3	/* We know it's name */
252 #define	AUTH_VALID	4	/* We know it, and it needs no password */
253 
254 /*
255  * Who is authenticating who ...
256  */
257 #define	AUTH_WHO_CLIENT		0	/* Client authenticating server */
258 #define	AUTH_WHO_SERVER		1	/* Server authenticating client */
259 #define	AUTH_WHO_MASK		1
260 
261 #ifdef	AUTHWHO_STR
262 char *authwho_str[] = {
263 	"CLIENT", "SERVER" };
264 #define	AUTHWHO_NAME(x)	authwho_str[x]
265 #endif /* AUTHWHO_STR */
266 
267 /*
268  * amount of authentication done
269  */
270 #define	AUTH_HOW_ONE_WAY	0
271 #define	AUTH_HOW_MUTUAL		2
272 #define	AUTH_HOW_MASK		2
273 
274 /*
275  * should we be encrypting? (not yet formally standardized)
276  */
277 #define	AUTH_ENCRYPT_OFF	0
278 #define	AUTH_ENCRYPT_ON		4
279 #define	AUTH_ENCRYPT_MASK	4
280 
281 #define	AUTHTYPE_NULL		0
282 #define	AUTHTYPE_KERBEROS_V4	1	/* not supported */
283 #define	AUTHTYPE_KERBEROS_V5	2
284 #define	AUTHTYPE_CNT		3
285 
286 #define	OPTS_FORWARD_CREDS		0x00000002
287 #define	OPTS_FORWARDABLE_CREDS		0x00000001
288 
289 #ifdef AUTHTYPE_NAMES
290 char *authtype_names[] = {
291 	"NULL", "KERBEROS_V4", "KERBEROS_V5", 0,
292 };
293 #else
294 extern char *authtype_names[];
295 #endif /* AUTHTYPE_NAMES */
296 
297 #define	AUTHTYPE_NAME(x)	authtype_names[x]
298 #define	AUTHTYPE_NAME_OK(x)	((unsigned int)(x) < AUTHTYPE_CNT)
299 
300 #ifdef AUTHHOW_NAMES
301 char *authhow_names[] = {
302 	"ONE-WAY", "[undefined]", "MUTUAL" };
303 #endif /* AUTHHOW_NAMES */
304 
305 #define	AUTHHOW_NAME(x)		authhow_names[x]
306 
307 #define	KRB_AUTH		0	/* Authentication data follows */
308 #define	KRB_REJECT		1	/* Rejected (reason might follow) */
309 #define	KRB_ACCEPT		2	/* Accepted */
310 #define	KRB_RESPONSE		3	/* Response for mutual auth. */
311 #define	KRB_FORWARD		4	/* Forwarded credentials follow */
312 #define	KRB_FORWARD_ACCEPT	5	/* Forwarded credentials accepted */
313 #define	KRB_FORWARD_REJECT	6	/* Forwarded credentials rejected */
314 
315 #ifdef AUTHRSP_NAMES
316 char *authrsp_names[] = {
317 	"AUTH", "REJECT", "ACCEPT", "RESPONSE", "FORWARD",
318 	"FORWARD_ACCEPT", "FORWARD_REJECT" };
319 #define	AUTHRSP_NAME(x)		authrsp_names[x]
320 #endif /* AUTHRSP_NAMES */
321 
322 #define	AUTH_MODE_REQUIRE	0
323 #define	AUTH_MODE_PROMPT	1
324 #define	AUTH_MODE_WARN		2
325 #define	AUTH_MODE_REJECT	3
326 
327 
328 /*
329  * Encryption suboptions. See RFC 2946.
330  */
331 #define	ENCRYPT_IS		0	/* I pick encryption type ... */
332 #define	ENCRYPT_SUPPORT		1	/* I support encryption types ... */
333 #define	ENCRYPT_REPLY		2	/* Initial setup response */
334 #define	ENCRYPT_START		3	/* Starting encrypting output */
335 #define	ENCRYPT_END		4	/* End encrypting output */
336 #define	ENCRYPT_REQSTART	5	/* Request to start encrypting output */
337 #define	ENCRYPT_REQEND		6	/* Request to stop encrypting output */
338 #define	ENCRYPT_ENC_KEYID	7	/* Negotiate encryption key */
339 #define	ENCRYPT_DEC_KEYID	8	/* Negotiate decryption key */
340 #define	ENCRYPT_CNT		9	/* marks the maximum ENCRYPT value */
341 
342 #define	TELOPT_ENCTYPE_NULL		0
343 #define	TELOPT_ENCTYPE_DES_CFB64	1 /* 64-bit Cipher Feedback Mode */
344 #define	TELOPT_ENCTYPE_CNT		2
345 
346 #define	CFB64_IV	1
347 #define	CFB64_IV_OK	2
348 #define	CFB64_IV_BAD	3
349 
350 #define	FB64_IV		CFB64_IV
351 #define	FB64_IV_OK	CFB64_IV_OK
352 #define	FB64_IV_BAD	CFB64_IV_BAD
353 
354 #ifdef ENCRYPT_NAMES
355 char *encrypt_names[] = {
356 	"IS", "SUPPORT", "REPLY", "START", "END",
357 	"REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID",
358 	0,
359 };
360 
361 char *enctype_names[] = {
362 	"ANY", "DES_CFB64", 0,
363 };
364 #else
365 extern char *encrypt_names[];
366 extern char *enctype_names[];
367 #endif /* ENCRYPT_NAMES */
368 
369 #define	ENCRYPT_NAME(x)		encrypt_names[x]
370 #define	ENCTYPE_NAME(x)		enctype_names[x]
371 
372 #define	ENCRYPT_NAME_OK(x)	((unsigned int)(x) < ENCRYPT_CNT)
373 #define	ENCTYPE_NAME_OK(x)	((unsigned int)(x) < TELOPT_ENCTYPE_CNT)
374 
375 #define	SK_DES	1 /* Matched Kerberos v5 ENCTYPE_DES */
376 
377 #ifndef	DES_BLOCKSIZE
378 #define	DES_BLOCKSIZE  8
379 #endif	/* DES_BLOCKSIZE */
380 
381 #define	TELNET_MAXNUMKEYS	64
382 #define	TELNET_MAXKEYIDLEN	16
383 
384 #define	CFB 0
385 
386 #define	ENCR_STATE_FAILED	-1
387 #define	ENCR_STATE_OK		0x00
388 #define	ENCR_STATE_NO_SEND_IV	0x01
389 #define	ENCR_STATE_NO_RECV_IV	0x02
390 #define	ENCR_STATE_NO_KEYID	0x04
391 #define	ENCR_STATE_NOT_READY	0x08
392 #define	ENCR_STATE_IN_PROGRESS \
393 	(ENCR_STATE_NO_SEND_IV|ENCR_STATE_NO_RECV_IV|ENCR_STATE_NO_KEYID)
394 #define	TELNET_DIR_ENCRYPT	0
395 #define	TELNET_DIR_DECRYPT	1
396 
397 typedef unsigned char Block[DES_BLOCKSIZE];
398 typedef unsigned char *BlockT;
399 typedef struct { Block _; } Schedule[16];
400 
401 typedef struct {
402 	short		type;
403 	int		length;
404 	unsigned char	*data;
405 } Session_Key;
406 
407 typedef struct {
408 	unsigned char	need_start;
409 	unsigned char	autoflag;	/* automatically start operation */
410 	unsigned char	setup;
411 	unsigned char	type;
412 	unsigned int	state;
413 	unsigned char	keyid[TELNET_MAXNUMKEYS];
414 	int		keyidlen;
415 	Block		ivec;
416 	Block		krbdes_key;
417 } cipher_info_t;
418 
419 typedef struct {
420 	cipher_info_t encrypt;
421 	cipher_info_t decrypt;
422 } telnet_enc_data_t;
423 
424 /* A valid key has no "0" bytes */
425 #define	VALIDKEY(key)	(key[0] | key[1] | key[2] | key[3] | \
426 		key[4] | key[5] | key[6] | key[7])
427 
428 
429 #ifdef	__cplusplus
430 }
431 #endif
432 
433 #endif	/* _ARPA_TELNET_H */
434