1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  *	nis_dhext.h: NIS+ extended Diffie-Hellman interface.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #ifndef _NIS_DHEXT_H
32*7c478bd9Sstevel@tonic-gate #define	_NIS_DHEXT_H
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
35*7c478bd9Sstevel@tonic-gate extern "C" {
36*7c478bd9Sstevel@tonic-gate #endif
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
39*7c478bd9Sstevel@tonic-gate #include <rpc/key_prot.h>
40*7c478bd9Sstevel@tonic-gate #include <rpcsvc/nis.h>   /* to get nis_server */
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #define	AUTH_DES_KEYLEN  192
44*7c478bd9Sstevel@tonic-gate #define	AUTH_DES_ALGTYPE 0
45*7c478bd9Sstevel@tonic-gate #define	AUTH_DES_AUTH_TYPE "DES"
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate #define	AUTH_DES_KEY(k, a) (((k) == AUTH_DES_KEYLEN) && \
48*7c478bd9Sstevel@tonic-gate 			    ((a) == AUTH_DES_ALGTYPE))
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #define	BITS2NIBBLES(b)	((b)/4)
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate #define	NIS_SVCNAME_NISD	"nisd"
53*7c478bd9Sstevel@tonic-gate #define	NIS_SVCNAME_NISPASSWD	"nispasswd"
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate typedef struct extdhkey {
56*7c478bd9Sstevel@tonic-gate 	ushort_t	keylen;
57*7c478bd9Sstevel@tonic-gate 	ushort_t	algtype;
58*7c478bd9Sstevel@tonic-gate 	uchar_t		key[1];
59*7c478bd9Sstevel@tonic-gate } extdhkey_t;
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate char *__nis_dhext_extract_pkey(netobj *, keylen_t, algtype_t);
62*7c478bd9Sstevel@tonic-gate int __nis_dhext_extract_keyinfo(nis_server *, extdhkey_t **);
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate /*
66*7c478bd9Sstevel@tonic-gate  * NIS+ Security conf file
67*7c478bd9Sstevel@tonic-gate  */
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate #define	NIS_SEC_CF_PATHNAME		"/etc/rpcsec/nisplussec.conf"
70*7c478bd9Sstevel@tonic-gate #define	NIS_SEC_CF_MAX_FLDLEN		MAX_GSS_NAME
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate typedef struct {
74*7c478bd9Sstevel@tonic-gate 		char			*mechname;
75*7c478bd9Sstevel@tonic-gate 		char			*alias;
76*7c478bd9Sstevel@tonic-gate 		keylen_t		keylen;
77*7c478bd9Sstevel@tonic-gate 		algtype_t		algtype;
78*7c478bd9Sstevel@tonic-gate 		char			*qop;
79*7c478bd9Sstevel@tonic-gate 		rpc_gss_service_t	secserv;
80*7c478bd9Sstevel@tonic-gate } mechanism_t;
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate /* The string that indicates AUTH_DES compat in the nis sec conf file. */
83*7c478bd9Sstevel@tonic-gate #define	NIS_SEC_CF_DES_ALIAS		"des"
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate /*
86*7c478bd9Sstevel@tonic-gate  * The value a keylen or algtype mechanism_t element will be set
87*7c478bd9Sstevel@tonic-gate  * to if the conf file indicates "not applicable" for that field.
88*7c478bd9Sstevel@tonic-gate  * Except if the alias is equal to NIS_SEC_CF_DES_ALIAS,
89*7c478bd9Sstevel@tonic-gate  * then the keylen is set to 192 and the algtype to 0.
90*7c478bd9Sstevel@tonic-gate  */
91*7c478bd9Sstevel@tonic-gate #define	NIS_SEC_CF_NA_KA		-1
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate /* Is the NIS+ security conf file mech entry a real live GSS mech? */
94*7c478bd9Sstevel@tonic-gate #define	NIS_SEC_CF_GSS_MECH(mp)	((mp)->mechname != NULL)
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate #define	AUTH_DES_COMPAT_CHK(mp)	((mp)->alias && \
97*7c478bd9Sstevel@tonic-gate 					(strncasecmp(NIS_SEC_CF_DES_ALIAS, \
98*7c478bd9Sstevel@tonic-gate 					(mp)->alias,\
99*7c478bd9Sstevel@tonic-gate 					sizeof (NIS_SEC_CF_DES_ALIAS) + 1) \
100*7c478bd9Sstevel@tonic-gate 					== 0))
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate #define	VALID_GSS_MECH(m)	((m) != NULL)
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate /* valid keylen and algtype check */
105*7c478bd9Sstevel@tonic-gate #define	VALID_KEYALG(k, a)	((k) != NIS_SEC_CF_NA_KA && \
106*7c478bd9Sstevel@tonic-gate 					(a) != NIS_SEC_CF_NA_KA)
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate #define	VALID_ALIAS(a)	((a) != NULL)
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate #define	VALID_MECH_ENTRY(mp) (VALID_GSS_MECH((mp)->mechname) && \
111*7c478bd9Sstevel@tonic-gate 				VALID_KEYALG((mp)->keylen, (mp)->algtype) &&\
112*7c478bd9Sstevel@tonic-gate 				VALID_ALIAS((mp)->alias))
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate /* Is the mech entry of the public key crypto variety? */
115*7c478bd9Sstevel@tonic-gate #define	MECH_PK_TECH(mp)  (((mp)->alias)[0] == 'd' && ((mp)->alias)[1] == 'h')
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate #define	MECH_MAXATNAME 32	/* Mechanism max size of auth_type name */
118*7c478bd9Sstevel@tonic-gate #define	MECH_MAXALIASNAME 32	/* Mechanism max size of mech alias name */
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate mechanism_t ** __nis_get_mechanisms(bool_t);
121*7c478bd9Sstevel@tonic-gate int __nis_translate_mechanism(const char *, int *, int *);
122*7c478bd9Sstevel@tonic-gate void __nis_release_mechanisms(mechanism_t **);
123*7c478bd9Sstevel@tonic-gate char *__nis_mechname2alias(const char *, char *, size_t);
124*7c478bd9Sstevel@tonic-gate char *__nis_authtype2mechalias(const char *, char *, size_t);
125*7c478bd9Sstevel@tonic-gate char *__nis_mechalias2authtype(const char *, char *, size_t);
126*7c478bd9Sstevel@tonic-gate char *__nis_keyalg2mechalias(keylen_t, algtype_t, char *, size_t);
127*7c478bd9Sstevel@tonic-gate char *__nis_keyalg2authtype(keylen_t, algtype_t, char *, size_t);
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate /*
131*7c478bd9Sstevel@tonic-gate  * NIS+ GSS Mech Dynamic Library Loading
132*7c478bd9Sstevel@tonic-gate  */
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate #define	MAXDHNAME	64
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate char *__nis_get_mechanism_library(keylen_t keylen, algtype_t algtype,
137*7c478bd9Sstevel@tonic-gate 					char *buffer, size_t buflen);
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate void *__nis_get_mechanism_symbol(keylen_t keylen, algtype_t algtype,
140*7c478bd9Sstevel@tonic-gate 					const char *);
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate /*
144*7c478bd9Sstevel@tonic-gate  * misc prototypes
145*7c478bd9Sstevel@tonic-gate  */
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate CLIENT *nis_make_rpchandle_gss_svc(nis_server *, int, rpcprog_t, rpcvers_t,
148*7c478bd9Sstevel@tonic-gate 					uint_t, int, int, char *, char *);
149*7c478bd9Sstevel@tonic-gate CLIENT *nis_make_rpchandle_gss_svc_ruid(nis_server *, int, rpcprog_t, rpcvers_t,
150*7c478bd9Sstevel@tonic-gate 					uint_t, int, int, char *, char *);
151*7c478bd9Sstevel@tonic-gate nis_server *__nis_host2nis_server_g(const char *, bool_t, bool_t, int *);
152*7c478bd9Sstevel@tonic-gate int __nis_gssprin2netname(rpc_gss_principal_t, char []);
153*7c478bd9Sstevel@tonic-gate void __nis_auth2princ_rpcgss(char *, struct svc_req *, bool_t, int);
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate void des_setparity_g(des_block *);
156*7c478bd9Sstevel@tonic-gate int passwd2des_g(const char *, const char *, int, des_block *, bool_t);
157*7c478bd9Sstevel@tonic-gate int getpublickey_g(const char [], keylen_t, algtype_t, char *, size_t);
158*7c478bd9Sstevel@tonic-gate int getsecretkey_g(const char *, keylen_t, algtype_t, char *, size_t,
159*7c478bd9Sstevel@tonic-gate 			const char *);
160*7c478bd9Sstevel@tonic-gate int __getpublickey_cached_g(const char [], keylen_t, algtype_t, char *, size_t,
161*7c478bd9Sstevel@tonic-gate 					int *);
162*7c478bd9Sstevel@tonic-gate void __getpublickey_flush_g(const char *, keylen_t, algtype_t);
163*7c478bd9Sstevel@tonic-gate int __gen_dhkeys_g(char *, char *, keylen_t, algtype_t, char *);
164*7c478bd9Sstevel@tonic-gate int __gen_common_dhkeys_g(char *, char *, keylen_t, algtype_t, des_block [],
165*7c478bd9Sstevel@tonic-gate 	keynum_t);
166*7c478bd9Sstevel@tonic-gate int __cbc_triple_crypt(des_block [], char *, uint_t, uint_t, char *);
167*7c478bd9Sstevel@tonic-gate int key_get_conv_g(const char *, keylen_t, algtype_t, des_block [], keynum_t);
168*7c478bd9Sstevel@tonic-gate int key_secretkey_is_set_g(keylen_t, algtype_t);
169*7c478bd9Sstevel@tonic-gate int key_removesecret_g(void);
170*7c478bd9Sstevel@tonic-gate int key_setnet_g(const char *, const char *, keylen_t, const char *,
171*7c478bd9Sstevel@tonic-gate 			keylen_t, algtype_t);
172*7c478bd9Sstevel@tonic-gate int xencrypt_g(char *, keylen_t, algtype_t, const char *, const char [],
173*7c478bd9Sstevel@tonic-gate 		char **, bool_t);
174*7c478bd9Sstevel@tonic-gate int xdecrypt_g(char *, keylen_t, algtype_t, const char *, const char [],
175*7c478bd9Sstevel@tonic-gate 		bool_t);
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
178*7c478bd9Sstevel@tonic-gate }
179*7c478bd9Sstevel@tonic-gate #endif
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate #endif /* !_NIS_DHEXT_H */
182