OSSL_CMP_log_open.pod 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. =pod
  2. =head1 NAME
  3. OSSL_CMP_log_open,
  4. OSSL_CMP_log_close,
  5. OSSL_CMP_severity,
  6. OSSL_CMP_LOG_EMERG,
  7. OSSL_CMP_LOG_ALERT,
  8. OSSL_CMP_LOG_CRIT,
  9. OSSL_CMP_LOG_ERR,
  10. OSSL_CMP_LOG_WARNING,
  11. OSSL_CMP_LOG_NOTICE,
  12. OSSL_CMP_LOG_INFO,
  13. OSSL_CMP_LOG_DEBUG,
  14. OSSL_CMP_log_cb_t,
  15. OSSL_CMP_print_to_bio,
  16. OSSL_CMP_print_errors_cb
  17. - functions for logging and error reporting
  18. =head1 SYNOPSIS
  19. #include <openssl/cmp_util.h>
  20. int OSSL_CMP_log_open(void);
  21. void OSSL_CMP_log_close(void);
  22. /* severity level declarations resemble those from syslog.h */
  23. typedef int OSSL_CMP_severity;
  24. #define OSSL_CMP_LOG_EMERG 0
  25. #define OSSL_CMP_LOG_ALERT 1
  26. #define OSSL_CMP_LOG_CRIT 2
  27. #define OSSL_CMP_LOG_ERR 3
  28. #define OSSL_CMP_LOG_WARNING 4
  29. #define OSSL_CMP_LOG_NOTICE 5
  30. #define OSSL_CMP_LOG_INFO 6
  31. #define OSSL_CMP_LOG_DEBUG 7
  32. typedef int (*OSSL_CMP_log_cb_t)(const char *component,
  33. const char *file, int line,
  34. OSSL_CMP_severity level, const char *msg);
  35. int OSSL_CMP_print_to_bio(BIO *bio, const char *component, const char *file,
  36. int line, OSSL_CMP_severity level, const char *msg);
  37. void OSSL_CMP_print_errors_cb(OSSL_CMP_log_cb_t log_fn);
  38. =head1 DESCRIPTION
  39. The logging and error reporting facility described here contains
  40. convenience functions for CMP-specific logging,
  41. including a string prefix mirroring the severity levels of syslog.h,
  42. and enhancements of the error queue mechanism needed for large diagnostic
  43. messages produced by the CMP library in case of certificate validation failures.
  44. When an interesting activity is performed or an error occurs, some detail
  45. should be provided for user information, debugging, and auditing purposes.
  46. A CMP application can obtain this information by providing a callback function
  47. with the following type:
  48. typedef int (*OSSL_CMP_log_cb_t)(const char *component,
  49. const char *file, int line,
  50. OSSL_CMP_severity level, const char *msg);
  51. The parameters may provide
  52. some component info (which may be a module name and/or function name) or NULL,
  53. a file pathname or NULL,
  54. a line number or 0 indicating the source code location,
  55. a severity level, and
  56. a message string describing the nature of the event, terminated by '\n'.
  57. Even when an activity is successful some warnings may be useful and some degree
  58. of auditing may be required. Therefore, the logging facility supports a severity
  59. level and the callback function has a B<level> parameter indicating such a
  60. level, such that error, warning, info, debug, etc. can be treated differently.
  61. The callback is activated only when the severity level is sufficient according
  62. to the current level of verbosity, which by default is OSSL_CMP_LOG_INFO.
  63. The callback function may itself do non-trivial tasks like writing to
  64. a log file or remote stream, which in turn may fail.
  65. Therefore, the function should return 1 on success and 0 on failure.
  66. OSSL_CMP_log_open() initializes the CMP-specific logging facility to output
  67. everything to STDOUT. It fails if the integrated tracing is disabled or STDIO
  68. is not available. It may be called during application startup.
  69. Alternatively, L<OSSL_CMP_CTX_set_log_cb(3)> can be used for more flexibility.
  70. As long as neither if the two is used any logging output is ignored.
  71. OSSL_CMP_log_close() may be called when all activities are finished to flush
  72. any pending CMP-specific log output and deallocate related resources.
  73. It may be called multiple times. It does get called at OpenSSL stutdown.
  74. OSSL_CMP_print_to_bio() prints the given component info, filename, line number,
  75. severity level, and log message or error queue message to the given B<bio>.
  76. B<component> usually is a function or module name.
  77. If it is NULL, empty, or "(unknown function)" then "CMP" is used as fallback.
  78. OSSL_CMP_print_errors_cb() outputs any entries in the OpenSSL error queue.
  79. It is similar to B<ERR_print_errors_cb()> but uses the CMP log callback function
  80. C<log_fn> for uniformity with CMP logging if not B<NULL>. Otherwise it prints to
  81. STDERR using B<OSSL_CMP_print_to_bio(3)> (unless OPENSSL_NO_STDIO is defined).
  82. =head1 RETURN VALUES
  83. OSSL_CMP_log_close() and OSSL_CMP_print_errors_cb() do not return anything.
  84. All other functions return 1 on success, 0 on error.
  85. =head1 HISTORY
  86. The OpenSSL CMP support was added in OpenSSL 3.0.
  87. =head1 COPYRIGHT
  88. Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
  89. Licensed under the Apache License 2.0 (the "License"). You may not use
  90. this file except in compliance with the License. You can obtain a copy
  91. in the file LICENSE in the source distribution or at
  92. L<https://www.openssl.org/source/license.html>.
  93. =cut