xref: /linux/include/keys/rxrpc-type.h (revision d2ae4e91)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
217926a79SDavid Howells /* RxRPC key type
317926a79SDavid Howells  *
417926a79SDavid Howells  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
517926a79SDavid Howells  * Written by David Howells (dhowells@redhat.com)
617926a79SDavid Howells  */
717926a79SDavid Howells 
817926a79SDavid Howells #ifndef _KEYS_RXRPC_TYPE_H
917926a79SDavid Howells #define _KEYS_RXRPC_TYPE_H
1017926a79SDavid Howells 
1117926a79SDavid Howells #include <linux/key.h>
1217926a79SDavid Howells 
1317926a79SDavid Howells /*
1417926a79SDavid Howells  * key type for AF_RXRPC keys
1517926a79SDavid Howells  */
1617926a79SDavid Howells extern struct key_type key_type_rxrpc;
1717926a79SDavid Howells 
1876181c13SDavid Howells extern struct key *rxrpc_get_null_key(const char *);
1976181c13SDavid Howells 
2033941284SDavid Howells /*
2133941284SDavid Howells  * RxRPC key for Kerberos IV (type-2 security)
2233941284SDavid Howells  */
2333941284SDavid Howells struct rxkad_key {
2433941284SDavid Howells 	u32	vice_id;
2533941284SDavid Howells 	u32	start;			/* time at which ticket starts */
2633941284SDavid Howells 	u32	expiry;			/* time at which ticket expires */
2733941284SDavid Howells 	u32	kvno;			/* key version number */
2833941284SDavid Howells 	u8	primary_flag;		/* T if key for primary cell for this user */
2933941284SDavid Howells 	u16	ticket_len;		/* length of ticket[] */
3033941284SDavid Howells 	u8	session_key[8];		/* DES session key */
3118bdc20bSGustavo A. R. Silva 	u8	ticket[];		/* the encrypted ticket */
3233941284SDavid Howells };
3333941284SDavid Howells 
3433941284SDavid Howells /*
3533941284SDavid Howells  * list of tokens attached to an rxrpc key
3633941284SDavid Howells  */
3733941284SDavid Howells struct rxrpc_key_token {
3833941284SDavid Howells 	u16	security_index;		/* RxRPC header security index */
39*d2ae4e91SDavid Howells 	bool	no_leak_key;		/* Don't copy the key to userspace */
4033941284SDavid Howells 	struct rxrpc_key_token *next;	/* the next token in the list */
4133941284SDavid Howells 	union {
4233941284SDavid Howells 		struct rxkad_key *kad;
4333941284SDavid Howells 	};
4433941284SDavid Howells };
4533941284SDavid Howells 
4633941284SDavid Howells /*
4733941284SDavid Howells  * structure of raw payloads passed to add_key() or instantiate key
4833941284SDavid Howells  */
4933941284SDavid Howells struct rxrpc_key_data_v1 {
5033941284SDavid Howells 	u16		security_index;
5133941284SDavid Howells 	u16		ticket_length;
5233941284SDavid Howells 	u32		expiry;			/* time_t */
5333941284SDavid Howells 	u32		kvno;
5433941284SDavid Howells 	u8		session_key[8];
5518bdc20bSGustavo A. R. Silva 	u8		ticket[];
5633941284SDavid Howells };
5733941284SDavid Howells 
5833941284SDavid Howells /*
5933941284SDavid Howells  * AF_RXRPC key payload derived from XDR format
6033941284SDavid Howells  * - based on openafs-1.4.10/src/auth/afs_token.xg
6133941284SDavid Howells  */
6233941284SDavid Howells #define AFSTOKEN_LENGTH_MAX		16384	/* max payload size */
6399455153SDavid Howells #define AFSTOKEN_STRING_MAX		256	/* max small string length */
6499455153SDavid Howells #define AFSTOKEN_DATA_MAX		64	/* max small data length */
6533941284SDavid Howells #define AFSTOKEN_CELL_MAX		64	/* max cellname length */
6633941284SDavid Howells #define AFSTOKEN_MAX			8	/* max tokens per payload */
6799455153SDavid Howells #define AFSTOKEN_BDATALN_MAX		16384	/* max big data length */
6833941284SDavid Howells #define AFSTOKEN_RK_TIX_MAX		12000	/* max RxKAD ticket size */
6933941284SDavid Howells #define AFSTOKEN_GK_KEY_MAX		64	/* max GSSAPI key size */
7033941284SDavid Howells #define AFSTOKEN_GK_TOKEN_MAX		16384	/* max GSSAPI token size */
7133941284SDavid Howells 
7210674a03SBaolin Wang /*
7310674a03SBaolin Wang  * Truncate a time64_t to the range from 1970 to 2106 as in the network
7410674a03SBaolin Wang  * protocol.
7510674a03SBaolin Wang  */
rxrpc_time64_to_u32(time64_t time)7610674a03SBaolin Wang static inline u32 rxrpc_time64_to_u32(time64_t time)
7710674a03SBaolin Wang {
7810674a03SBaolin Wang 	if (time < 0)
7910674a03SBaolin Wang 		return 0;
8010674a03SBaolin Wang 
8110674a03SBaolin Wang 	if (time > UINT_MAX)
8210674a03SBaolin Wang 		return UINT_MAX;
8310674a03SBaolin Wang 
8410674a03SBaolin Wang 	return (u32)time;
8510674a03SBaolin Wang }
8610674a03SBaolin Wang 
8710674a03SBaolin Wang /*
8810674a03SBaolin Wang  * Extend u32 back to time64_t using the same 1970-2106 range.
8910674a03SBaolin Wang  */
rxrpc_u32_to_time64(u32 time)9010674a03SBaolin Wang static inline time64_t rxrpc_u32_to_time64(u32 time)
9110674a03SBaolin Wang {
9210674a03SBaolin Wang 	return (time64_t)time;
9310674a03SBaolin Wang }
9410674a03SBaolin Wang 
95dd89db1dSRobert P. J. Day #endif /* _KEYS_RXRPC_TYPE_H */
96