OSSL_CMP_log_open.pod 4.7 KB

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