1ab0c29afSRick Macklem /*-
2ab0c29afSRick Macklem * SPDX-License-Identifier: BSD-3-Clause
3ab0c29afSRick Macklem *
4ab0c29afSRick Macklem * Copyright (c) 2009, Sun Microsystems, Inc.
5ab0c29afSRick Macklem * All rights reserved.
6ab0c29afSRick Macklem *
7ab0c29afSRick Macklem * Redistribution and use in source and binary forms, with or without
8ab0c29afSRick Macklem * modification, are permitted provided that the following conditions are met:
9ab0c29afSRick Macklem * - Redistributions of source code must retain the above copyright notice,
10ab0c29afSRick Macklem * this list of conditions and the following disclaimer.
11ab0c29afSRick Macklem * - Redistributions in binary form must reproduce the above copyright notice,
12ab0c29afSRick Macklem * this list of conditions and the following disclaimer in the documentation
13ab0c29afSRick Macklem * and/or other materials provided with the distribution.
14ab0c29afSRick Macklem * - Neither the name of Sun Microsystems, Inc. nor the names of its
15ab0c29afSRick Macklem * contributors may be used to endorse or promote products derived
16ab0c29afSRick Macklem * from this software without specific prior written permission.
17ab0c29afSRick Macklem *
18ab0c29afSRick Macklem * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19ab0c29afSRick Macklem * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20ab0c29afSRick Macklem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ab0c29afSRick Macklem * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22ab0c29afSRick Macklem * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23ab0c29afSRick Macklem * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24ab0c29afSRick Macklem * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25ab0c29afSRick Macklem * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26ab0c29afSRick Macklem * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ab0c29afSRick Macklem * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28ab0c29afSRick Macklem * POSSIBILITY OF SUCH DAMAGE.
29ab0c29afSRick Macklem */
30ab0c29afSRick Macklem
31ab0c29afSRick Macklem #include <sys/cdefs.h>
32ab0c29afSRick Macklem /*
33ab0c29afSRick Macklem * auth_none.c
34ab0c29afSRick Macklem * Creates a client authentication handle for passing "null"
35ab0c29afSRick Macklem * credentials and verifiers to remote systems.
36ab0c29afSRick Macklem *
37ab0c29afSRick Macklem * Copyright (C) 1984, Sun Microsystems, Inc.
38ab0c29afSRick Macklem */
39ab0c29afSRick Macklem
40ab0c29afSRick Macklem /*
41ab0c29afSRick Macklem * Modified from auth_none.c to expect a reply verifier of "STARTTLS"
42ab0c29afSRick Macklem * for the RPC-over-TLS STARTTLS command.
43ab0c29afSRick Macklem */
44ab0c29afSRick Macklem
45ab0c29afSRick Macklem #include <sys/param.h>
46ab0c29afSRick Macklem #include <sys/systm.h>
47ab0c29afSRick Macklem #include <sys/kernel.h>
48ab0c29afSRick Macklem #include <sys/lock.h>
49ab0c29afSRick Macklem #include <sys/malloc.h>
50ab0c29afSRick Macklem #include <sys/mutex.h>
51ab0c29afSRick Macklem
52ab0c29afSRick Macklem #include <rpc/types.h>
53ab0c29afSRick Macklem #include <rpc/xdr.h>
54ab0c29afSRick Macklem #include <rpc/auth.h>
55ab0c29afSRick Macklem #include <rpc/clnt.h>
56ab0c29afSRick Macklem #include <rpc/rpcsec_tls.h>
57ab0c29afSRick Macklem
58ab0c29afSRick Macklem #define MAX_MARSHAL_SIZE 20
59ab0c29afSRick Macklem
60ab0c29afSRick Macklem /*
61ab0c29afSRick Macklem * Authenticator operations routines
62ab0c29afSRick Macklem */
63ab0c29afSRick Macklem
64ab0c29afSRick Macklem static bool_t authtls_marshal (AUTH *, uint32_t, XDR *, struct mbuf *);
65ab0c29afSRick Macklem static void authtls_verf (AUTH *);
66ab0c29afSRick Macklem static bool_t authtls_validate (AUTH *, uint32_t, struct opaque_auth *,
67ab0c29afSRick Macklem struct mbuf **);
68ab0c29afSRick Macklem static bool_t authtls_refresh (AUTH *, void *);
69ab0c29afSRick Macklem static void authtls_destroy (AUTH *);
70ab0c29afSRick Macklem
71*20d728b5SMark Johnston static const struct auth_ops authtls_ops = {
72ab0c29afSRick Macklem .ah_nextverf = authtls_verf,
73ab0c29afSRick Macklem .ah_marshal = authtls_marshal,
74ab0c29afSRick Macklem .ah_validate = authtls_validate,
75ab0c29afSRick Macklem .ah_refresh = authtls_refresh,
76ab0c29afSRick Macklem .ah_destroy = authtls_destroy,
77ab0c29afSRick Macklem };
78ab0c29afSRick Macklem
79ab0c29afSRick Macklem struct authtls_private {
80ab0c29afSRick Macklem AUTH no_client;
81ab0c29afSRick Macklem char mclient[MAX_MARSHAL_SIZE];
82ab0c29afSRick Macklem u_int mcnt;
83ab0c29afSRick Macklem };
84ab0c29afSRick Macklem
85ab0c29afSRick Macklem static struct authtls_private authtls_private;
86ab0c29afSRick Macklem static struct opaque_auth _tls_null_auth;
87ab0c29afSRick Macklem
88ab0c29afSRick Macklem static void
authtls_init(void * dummy)89ab0c29afSRick Macklem authtls_init(void *dummy)
90ab0c29afSRick Macklem {
91ab0c29afSRick Macklem struct authtls_private *ap = &authtls_private;
92ab0c29afSRick Macklem XDR xdrs;
93ab0c29afSRick Macklem
94ab0c29afSRick Macklem _tls_null_auth.oa_flavor = AUTH_TLS;
95ab0c29afSRick Macklem _tls_null_auth.oa_base = NULL;
96ab0c29afSRick Macklem _tls_null_auth.oa_length = 0;
97ab0c29afSRick Macklem ap->no_client.ah_cred = _tls_null_auth;
98ab0c29afSRick Macklem ap->no_client.ah_verf = _null_auth;
99ab0c29afSRick Macklem ap->no_client.ah_ops = &authtls_ops;
100ab0c29afSRick Macklem xdrmem_create(&xdrs, ap->mclient, MAX_MARSHAL_SIZE, XDR_ENCODE);
101ab0c29afSRick Macklem xdr_opaque_auth(&xdrs, &ap->no_client.ah_cred);
102ab0c29afSRick Macklem xdr_opaque_auth(&xdrs, &ap->no_client.ah_verf);
103ab0c29afSRick Macklem ap->mcnt = XDR_GETPOS(&xdrs);
104ab0c29afSRick Macklem XDR_DESTROY(&xdrs);
105ab0c29afSRick Macklem }
106ab0c29afSRick Macklem SYSINIT(authtls_init, SI_SUB_KMEM, SI_ORDER_ANY, authtls_init, NULL);
107ab0c29afSRick Macklem
108ab0c29afSRick Macklem AUTH *
authtls_create(void)109ab0c29afSRick Macklem authtls_create(void)
110ab0c29afSRick Macklem {
111ab0c29afSRick Macklem struct authtls_private *ap = &authtls_private;
112ab0c29afSRick Macklem
113ab0c29afSRick Macklem return (&ap->no_client);
114ab0c29afSRick Macklem }
115ab0c29afSRick Macklem
116ab0c29afSRick Macklem /*ARGSUSED*/
117ab0c29afSRick Macklem static bool_t
authtls_marshal(AUTH * client,uint32_t xid,XDR * xdrs,struct mbuf * args)118ab0c29afSRick Macklem authtls_marshal(AUTH *client, uint32_t xid, XDR *xdrs, struct mbuf *args)
119ab0c29afSRick Macklem {
120ab0c29afSRick Macklem struct authtls_private *ap = &authtls_private;
121ab0c29afSRick Macklem
122ab0c29afSRick Macklem KASSERT(xdrs != NULL, ("authtls_marshal: xdrs is null"));
123ab0c29afSRick Macklem
124ab0c29afSRick Macklem if (!XDR_PUTBYTES(xdrs, ap->mclient, ap->mcnt))
125ab0c29afSRick Macklem return (FALSE);
126ab0c29afSRick Macklem
127ab0c29afSRick Macklem xdrmbuf_append(xdrs, args);
128ab0c29afSRick Macklem
129ab0c29afSRick Macklem return (TRUE);
130ab0c29afSRick Macklem }
131ab0c29afSRick Macklem
132ab0c29afSRick Macklem /* All these unused parameters are required to keep ANSI-C from grumbling */
133ab0c29afSRick Macklem /*ARGSUSED*/
134ab0c29afSRick Macklem static void
authtls_verf(AUTH * client)135ab0c29afSRick Macklem authtls_verf(AUTH *client)
136ab0c29afSRick Macklem {
137ab0c29afSRick Macklem }
138ab0c29afSRick Macklem
139ab0c29afSRick Macklem /*ARGSUSED*/
140ab0c29afSRick Macklem static bool_t
authtls_validate(AUTH * client,uint32_t xid,struct opaque_auth * opaque,struct mbuf ** mrepp)141ab0c29afSRick Macklem authtls_validate(AUTH *client, uint32_t xid, struct opaque_auth *opaque,
142ab0c29afSRick Macklem struct mbuf **mrepp)
143ab0c29afSRick Macklem {
144ab0c29afSRick Macklem size_t strsiz;
145ab0c29afSRick Macklem
146ab0c29afSRick Macklem strsiz = strlen(RPCTLS_START_STRING);
147ab0c29afSRick Macklem /* The verifier must be the string RPCTLS_START_STRING. */
148ab0c29afSRick Macklem if (opaque != NULL &&
149ab0c29afSRick Macklem (opaque->oa_length != strsiz || memcmp(opaque->oa_base,
150ab0c29afSRick Macklem RPCTLS_START_STRING, strsiz) != 0))
151ab0c29afSRick Macklem return (FALSE);
152ab0c29afSRick Macklem return (TRUE);
153ab0c29afSRick Macklem }
154ab0c29afSRick Macklem
155ab0c29afSRick Macklem /*ARGSUSED*/
156ab0c29afSRick Macklem static bool_t
authtls_refresh(AUTH * client,void * dummy)157ab0c29afSRick Macklem authtls_refresh(AUTH *client, void *dummy)
158ab0c29afSRick Macklem {
159ab0c29afSRick Macklem
160ab0c29afSRick Macklem return (FALSE);
161ab0c29afSRick Macklem }
162ab0c29afSRick Macklem
163ab0c29afSRick Macklem /*ARGSUSED*/
164ab0c29afSRick Macklem static void
authtls_destroy(AUTH * client)165ab0c29afSRick Macklem authtls_destroy(AUTH *client)
166ab0c29afSRick Macklem {
167ab0c29afSRick Macklem }
168