2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2020 Rick Macklem
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #ifndef _RPC_RPCSEC_TLS_H_
31 #define _RPC_RPCSEC_TLS_H_
33 /* Operation values for rpctls syscall. */
34 #define RPCTLS_SYSC_CLSETPATH 1
35 #define RPCTLS_SYSC_CLSOCKET 2
36 #define RPCTLS_SYSC_CLSHUTDOWN 3
37 #define RPCTLS_SYSC_SRVSETPATH 4
38 #define RPCTLS_SYSC_SRVSOCKET 5
39 #define RPCTLS_SYSC_SRVSHUTDOWN 6
40 #define RPCTLS_SYSC_SRVSTARTUP 7
42 /* Max nprocs for SRV startup */
43 #define RPCTLS_SRV_MAXNPROCS 16
45 /* System call used by the rpctlscd, rpctlssd daemons. */
46 int rpctls_syscall(int, const char *);
48 /* Flag bits to indicate certificate results. */
49 #define RPCTLS_FLAGS_HANDSHAKE 0x01
50 #define RPCTLS_FLAGS_GOTCERT 0x02
51 #define RPCTLS_FLAGS_SELFSIGNED 0x04
52 #define RPCTLS_FLAGS_VERIFIED 0x08
53 #define RPCTLS_FLAGS_DISABLED 0x10
54 #define RPCTLS_FLAGS_CERTUSER 0x20
55 #define RPCTLS_FLAGS_HANDSHFAIL 0x40
57 /* Error return values for upcall rpcs. */
58 #define RPCTLSERR_OK 0
59 #define RPCTLSERR_NOCLOSE 1
60 #define RPCTLSERR_NOSSL 2
61 #define RPCTLSERR_NOSOCKET 3
64 /* Functions that perform upcalls to the rpctlsd daemon. */
65 enum clnt_stat rpctls_connect(CLIENT *newclient, char *certname,
66 struct socket *so, uint64_t *sslp, uint32_t *reterr);
67 enum clnt_stat rpctls_cl_handlerecord(uint64_t sec, uint64_t usec,
68 uint64_t ssl, uint32_t *reterr);
69 enum clnt_stat rpctls_srv_handlerecord(uint64_t sec, uint64_t usec,
70 uint64_t ssl, int procpos, uint32_t *reterr);
71 enum clnt_stat rpctls_cl_disconnect(uint64_t sec, uint64_t usec,
72 uint64_t ssl, uint32_t *reterr);
73 enum clnt_stat rpctls_srv_disconnect(uint64_t sec, uint64_t usec,
74 uint64_t ssl, int procpos, uint32_t *reterr);
76 /* Initialization function for rpcsec_tls. */
77 int rpctls_init(void);
79 /* Get TLS information function. */
80 bool rpctls_getinfo(u_int *maxlen, bool rpctlscd_run,
83 /* String for AUTH_TLS reply verifier. */
84 #define RPCTLS_START_STRING "STARTTLS"
86 /* ssl refno value to indicate TLS handshake being done. */
87 #define RPCTLS_REFNO_HANDSHAKE 0xFFFFFFFFFFFFFFFFULL
89 /* Macros for VIMAGE. */
90 /* Just define the KRPC_VNETxxx() macros as VNETxxx() macros. */
91 #define KRPC_VNET_DEFINE(t, n) VNET_DEFINE(t, n)
92 #define KRPC_VNET_DEFINE_STATIC(t, n) VNET_DEFINE_STATIC(t, n)
93 #define KRPC_VNET(n) VNET(n)
95 #define KRPC_CURVNET_SET(n) CURVNET_SET(n)
96 #define KRPC_CURVNET_SET_QUIET(n) CURVNET_SET_QUIET(n)
97 #define KRPC_CURVNET_RESTORE() CURVNET_RESTORE()
98 #define KRPC_TD_TO_VNET(n) TD_TO_VNET(n)
102 #endif /* _RPC_RPCSEC_TLS_H_ */