/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 2009, Sun Microsystems, Inc.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are met:8* - Redistributions of source code must retain the above copyright notice,9* this list of conditions and the following disclaimer.10* - Redistributions in binary form must reproduce the above copyright notice,11* this list of conditions and the following disclaimer in the documentation12* and/or other materials provided with the distribution.13* - Neither the name of Sun Microsystems, Inc. nor the names of its14* contributors may be used to endorse or promote products derived15* from this software without specific prior written permission.16*17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"18* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE21* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS24* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN25* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)26* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE27* POSSIBILITY OF SUCH DAMAGE.28*/2930#include <sys/cdefs.h>31/*32* auth_none.c33* Creates a client authentication handle for passing "null"34* credentials and verifiers to remote systems.35*36* Copyright (C) 1984, Sun Microsystems, Inc.37*/3839/*40* Modified from auth_none.c to expect a reply verifier of "STARTTLS"41* for the RPC-over-TLS STARTTLS command.42*/4344#include <sys/param.h>45#include <sys/systm.h>46#include <sys/kernel.h>47#include <sys/lock.h>48#include <sys/malloc.h>49#include <sys/mutex.h>5051#include <rpc/types.h>52#include <rpc/xdr.h>53#include <rpc/auth.h>54#include <rpc/clnt.h>55#include <rpc/rpcsec_tls.h>5657#define MAX_MARSHAL_SIZE 205859/*60* Authenticator operations routines61*/6263static bool_t authtls_marshal (AUTH *, uint32_t, XDR *, struct mbuf *);64static void authtls_verf (AUTH *);65static bool_t authtls_validate (AUTH *, uint32_t, struct opaque_auth *,66struct mbuf **);67static bool_t authtls_refresh (AUTH *, void *);68static void authtls_destroy (AUTH *);6970static const struct auth_ops authtls_ops = {71.ah_nextverf = authtls_verf,72.ah_marshal = authtls_marshal,73.ah_validate = authtls_validate,74.ah_refresh = authtls_refresh,75.ah_destroy = authtls_destroy,76};7778struct authtls_private {79AUTH no_client;80char mclient[MAX_MARSHAL_SIZE];81u_int mcnt;82};8384static struct authtls_private authtls_private;85static struct opaque_auth _tls_null_auth;8687static void88authtls_init(void *dummy)89{90struct authtls_private *ap = &authtls_private;91XDR xdrs;9293_tls_null_auth.oa_flavor = AUTH_TLS;94_tls_null_auth.oa_base = NULL;95_tls_null_auth.oa_length = 0;96ap->no_client.ah_cred = _tls_null_auth;97ap->no_client.ah_verf = _null_auth;98ap->no_client.ah_ops = &authtls_ops;99xdrmem_create(&xdrs, ap->mclient, MAX_MARSHAL_SIZE, XDR_ENCODE);100xdr_opaque_auth(&xdrs, &ap->no_client.ah_cred);101xdr_opaque_auth(&xdrs, &ap->no_client.ah_verf);102ap->mcnt = XDR_GETPOS(&xdrs);103XDR_DESTROY(&xdrs);104}105SYSINIT(authtls_init, SI_SUB_KMEM, SI_ORDER_ANY, authtls_init, NULL);106107AUTH *108authtls_create(void)109{110struct authtls_private *ap = &authtls_private;111112return (&ap->no_client);113}114115/*ARGSUSED*/116static bool_t117authtls_marshal(AUTH *client, uint32_t xid, XDR *xdrs, struct mbuf *args)118{119struct authtls_private *ap = &authtls_private;120121KASSERT(xdrs != NULL, ("authtls_marshal: xdrs is null"));122123if (!XDR_PUTBYTES(xdrs, ap->mclient, ap->mcnt))124return (FALSE);125126return (xdr_putmbuf(xdrs, args));127}128129/* All these unused parameters are required to keep ANSI-C from grumbling */130/*ARGSUSED*/131static void132authtls_verf(AUTH *client)133{134}135136/*ARGSUSED*/137static bool_t138authtls_validate(AUTH *client, uint32_t xid, struct opaque_auth *opaque,139struct mbuf **mrepp)140{141size_t strsiz;142143strsiz = strlen(RPCTLS_START_STRING);144/* The verifier must be the string RPCTLS_START_STRING. */145if (opaque != NULL &&146(opaque->oa_length != strsiz || memcmp(opaque->oa_base,147RPCTLS_START_STRING, strsiz) != 0))148return (FALSE);149return (TRUE);150}151152/*ARGSUSED*/153static bool_t154authtls_refresh(AUTH *client, void *dummy)155{156157return (FALSE);158}159160/*ARGSUSED*/161static void162authtls_destroy(AUTH *client)163{164}165166167