rxrpc-type.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* RxRPC key type
  3. *
  4. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #ifndef _KEYS_RXRPC_TYPE_H
  8. #define _KEYS_RXRPC_TYPE_H
  9. #include <linux/key.h>
  10. /*
  11. * key type for AF_RXRPC keys
  12. */
  13. extern struct key_type key_type_rxrpc;
  14. extern struct key *rxrpc_get_null_key(const char *);
  15. /*
  16. * RxRPC key for Kerberos IV (type-2 security)
  17. */
  18. struct rxkad_key {
  19. u32 vice_id;
  20. u32 start; /* time at which ticket starts */
  21. u32 expiry; /* time at which ticket expires */
  22. u32 kvno; /* key version number */
  23. u8 primary_flag; /* T if key for primary cell for this user */
  24. u16 ticket_len; /* length of ticket[] */
  25. u8 session_key[8]; /* DES session key */
  26. u8 ticket[]; /* the encrypted ticket */
  27. };
  28. /*
  29. * Kerberos 5 principal
  30. * name/name/name@realm
  31. */
  32. struct krb5_principal {
  33. u8 n_name_parts; /* N of parts of the name part of the principal */
  34. char **name_parts; /* parts of the name part of the principal */
  35. char *realm; /* parts of the realm part of the principal */
  36. };
  37. /*
  38. * Kerberos 5 tagged data
  39. */
  40. struct krb5_tagged_data {
  41. /* for tag value, see /usr/include/krb5/krb5.h
  42. * - KRB5_AUTHDATA_* for auth data
  43. * -
  44. */
  45. s32 tag;
  46. u32 data_len;
  47. u8 *data;
  48. };
  49. /*
  50. * RxRPC key for Kerberos V (type-5 security)
  51. */
  52. struct rxk5_key {
  53. u64 authtime; /* time at which auth token generated */
  54. u64 starttime; /* time at which auth token starts */
  55. u64 endtime; /* time at which auth token expired */
  56. u64 renew_till; /* time to which auth token can be renewed */
  57. s32 is_skey; /* T if ticket is encrypted in another ticket's
  58. * skey */
  59. s32 flags; /* mask of TKT_FLG_* bits (krb5/krb5.h) */
  60. struct krb5_principal client; /* client principal name */
  61. struct krb5_principal server; /* server principal name */
  62. u16 ticket_len; /* length of ticket */
  63. u16 ticket2_len; /* length of second ticket */
  64. u8 n_authdata; /* number of authorisation data elements */
  65. u8 n_addresses; /* number of addresses */
  66. struct krb5_tagged_data session; /* session data; tag is enctype */
  67. struct krb5_tagged_data *addresses; /* addresses */
  68. u8 *ticket; /* krb5 ticket */
  69. u8 *ticket2; /* second krb5 ticket, if related to ticket (via
  70. * DUPLICATE-SKEY or ENC-TKT-IN-SKEY) */
  71. struct krb5_tagged_data *authdata; /* authorisation data */
  72. };
  73. /*
  74. * list of tokens attached to an rxrpc key
  75. */
  76. struct rxrpc_key_token {
  77. u16 security_index; /* RxRPC header security index */
  78. struct rxrpc_key_token *next; /* the next token in the list */
  79. union {
  80. struct rxkad_key *kad;
  81. struct rxk5_key *k5;
  82. };
  83. };
  84. /*
  85. * structure of raw payloads passed to add_key() or instantiate key
  86. */
  87. struct rxrpc_key_data_v1 {
  88. u16 security_index;
  89. u16 ticket_length;
  90. u32 expiry; /* time_t */
  91. u32 kvno;
  92. u8 session_key[8];
  93. u8 ticket[];
  94. };
  95. /*
  96. * AF_RXRPC key payload derived from XDR format
  97. * - based on openafs-1.4.10/src/auth/afs_token.xg
  98. */
  99. #define AFSTOKEN_LENGTH_MAX 16384 /* max payload size */
  100. #define AFSTOKEN_STRING_MAX 256 /* max small string length */
  101. #define AFSTOKEN_DATA_MAX 64 /* max small data length */
  102. #define AFSTOKEN_CELL_MAX 64 /* max cellname length */
  103. #define AFSTOKEN_MAX 8 /* max tokens per payload */
  104. #define AFSTOKEN_BDATALN_MAX 16384 /* max big data length */
  105. #define AFSTOKEN_RK_TIX_MAX 12000 /* max RxKAD ticket size */
  106. #define AFSTOKEN_GK_KEY_MAX 64 /* max GSSAPI key size */
  107. #define AFSTOKEN_GK_TOKEN_MAX 16384 /* max GSSAPI token size */
  108. #define AFSTOKEN_K5_COMPONENTS_MAX 16 /* max K5 components */
  109. #define AFSTOKEN_K5_NAME_MAX 128 /* max K5 name length */
  110. #define AFSTOKEN_K5_REALM_MAX 64 /* max K5 realm name length */
  111. #define AFSTOKEN_K5_TIX_MAX 16384 /* max K5 ticket size */
  112. #define AFSTOKEN_K5_ADDRESSES_MAX 16 /* max K5 addresses */
  113. #define AFSTOKEN_K5_AUTHDATA_MAX 16 /* max K5 pieces of auth data */
  114. /*
  115. * Truncate a time64_t to the range from 1970 to 2106 as in the network
  116. * protocol.
  117. */
  118. static inline u32 rxrpc_time64_to_u32(time64_t time)
  119. {
  120. if (time < 0)
  121. return 0;
  122. if (time > UINT_MAX)
  123. return UINT_MAX;
  124. return (u32)time;
  125. }
  126. /*
  127. * Extend u32 back to time64_t using the same 1970-2106 range.
  128. */
  129. static inline time64_t rxrpc_u32_to_time64(u32 time)
  130. {
  131. return (time64_t)time;
  132. }
  133. #endif /* _KEYS_RXRPC_TYPE_H */