certauth_plugin.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
  2. /* include/krb5/certauth_plugin.h - certauth plugin header. */
  3. /*
  4. * Copyright (C) 2017 by Red Hat, Inc.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * * Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  28. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  30. * OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /*
  33. * Declarations for certauth plugin module implementors.
  34. *
  35. * The certauth pluggable interface currently has only one supported major
  36. * version, which is 1. Major version 1 has a current minor version number of
  37. * 1.
  38. *
  39. * certauth plugin modules should define a function named
  40. * certauth_<modulename>_initvt, matching the signature:
  41. *
  42. * krb5_error_code
  43. * certauth_modname_initvt(krb5_context context, int maj_ver, int min_ver,
  44. * krb5_plugin_vtable vtable);
  45. *
  46. * The initvt function should:
  47. *
  48. * - Check that the supplied maj_ver number is supported by the module, or
  49. * return KRB5_PLUGIN_VER_NOTSUPP if it is not.
  50. *
  51. * - Cast the vtable pointer as appropriate for maj_ver:
  52. * maj_ver == 1: Cast to krb5_certauth_vtable
  53. *
  54. * - Initialize the methods of the vtable, stopping as appropriate for the
  55. * supplied min_ver. Optional methods may be left uninitialized.
  56. *
  57. * Memory for the vtable is allocated by the caller, not by the module.
  58. */
  59. #ifndef KRB5_CERTAUTH_PLUGIN_H
  60. #define KRB5_CERTAUTH_PLUGIN_H
  61. #include <krb5/krb5.h>
  62. #include <krb5/plugin.h>
  63. /* Abstract module data type. */
  64. typedef struct krb5_certauth_moddata_st *krb5_certauth_moddata;
  65. /* A module can optionally include <kdb.h> to inspect the client principal
  66. * entry when authorizing a request. */
  67. struct _krb5_db_entry_new;
  68. /*
  69. * Optional: Initialize module data.
  70. */
  71. typedef krb5_error_code
  72. (*krb5_certauth_init_fn)(krb5_context context,
  73. krb5_certauth_moddata *moddata_out);
  74. /*
  75. * Optional: Clean up the module data.
  76. */
  77. typedef void
  78. (*krb5_certauth_fini_fn)(krb5_context context, krb5_certauth_moddata moddata);
  79. /*
  80. * Mandatory: decode cert as an X.509 certificate and determine whether it is
  81. * authorized to authenticate as the requested client principal princ using
  82. * PKINIT. Return 0 or KRB5_CERTAUTH_HWAUTH if the certificate is authorized.
  83. * Otherwise return one of the following error codes:
  84. *
  85. * - KRB5KDC_ERR_CLIENT_NAME_MISMATCH - incorrect SAN value
  86. * - KRB5KDC_ERR_INCONSISTENT_KEY_PURPOSE - incorrect EKU
  87. * - KRB5KDC_ERR_CERTIFICATE_MISMATCH - other extension error
  88. * - KRB5_PLUGIN_NO_HANDLE or KRB5_CERTAUTH_HWAUTH_PASS - the module has no
  89. * opinion about whether cert is authorized
  90. *
  91. * Returning KRB5_CERTAUTH_HWAUTH will authorize the PKINIT authentication and
  92. * cause the hw-authent flag to be set in the issued ticket (new in release
  93. * 1.19). Returning KRB5_CERTAUTH_HWAUTH_PASS does not authorize the PKINIT
  94. * authentication, but causes the hw-authent flag to be set if another module
  95. * authorizes it (new in release 1.20)
  96. *
  97. * - opts is used by built-in modules to receive internal data, and must be
  98. * ignored by other modules.
  99. * - db_entry receives the client principal database entry, and can be ignored
  100. * by modules that do not link with libkdb5.
  101. * - *authinds_out optionally returns a null-terminated list of authentication
  102. * indicator strings upon KRB5_PLUGIN_NO_HANDLE or accepted authorization.
  103. */
  104. typedef krb5_error_code
  105. (*krb5_certauth_authorize_fn)(krb5_context context,
  106. krb5_certauth_moddata moddata,
  107. const uint8_t *cert, size_t cert_len,
  108. krb5_const_principal princ, const void *opts,
  109. const struct _krb5_db_entry_new *db_entry,
  110. char ***authinds_out);
  111. /*
  112. * Free indicators allocated by a module. Mandatory if authorize returns
  113. * authentication indicators.
  114. */
  115. typedef void
  116. (*krb5_certauth_free_indicator_fn)(krb5_context context,
  117. krb5_certauth_moddata moddata,
  118. char **authinds);
  119. typedef struct krb5_certauth_vtable_st {
  120. const char *name;
  121. krb5_certauth_init_fn init;
  122. krb5_certauth_fini_fn fini;
  123. krb5_certauth_authorize_fn authorize;
  124. krb5_certauth_free_indicator_fn free_ind;
  125. } *krb5_certauth_vtable;
  126. #endif /* KRB5_CERTAUTH_PLUGIN_H */