PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::security::audit_log_cipher Class Reference

Encrypts and decrypts single audit log records. More...

#include <audit_log_cipher.h>

Collaboration diagram for kcenon::pacs::security::audit_log_cipher:
Collaboration graph

Public Member Functions

 audit_log_cipher (audit_key_manager &keys)
 Construct a cipher backed by the given key manager.
 
Result< std::string > encrypt_record (const std::string &plaintext) const
 Encrypt a plaintext audit record.
 
Result< std::string > decrypt_record (const std::string &encoded) const
 Decrypt a previously encoded record.
 
VoidResult verify_record (const std::string &encoded) const
 Verify a record's authenticity without returning plaintext.
 

Static Public Member Functions

static bool looks_encrypted (const std::string &line) noexcept
 Check whether a line appears to be an encrypted audit record.
 

Private Attributes

audit_key_manager & keys_
 

Detailed Description

Encrypts and decrypts single audit log records.

Instances are stateless with respect to plaintext content; they hold a reference to a key manager and generate a fresh random IV per record.

Thread-safety: all public methods are safe to call from multiple threads provided the referenced audit_key_manager outlives the cipher.

Definition at line 196 of file audit_log_cipher.h.

Constructor & Destructor Documentation

◆ audit_log_cipher()

kcenon::pacs::security::audit_log_cipher::audit_log_cipher ( audit_key_manager & keys)
explicit

Construct a cipher backed by the given key manager.

Parameters
keyskey store (must outlive this cipher)

Definition at line 349 of file audit_log_cipher.cpp.

349: keys_(keys) {}

Member Function Documentation

◆ decrypt_record()

Result< std::string > kcenon::pacs::security::audit_log_cipher::decrypt_record ( const std::string & encoded) const
nodiscard

Decrypt a previously encoded record.

Looks up the key by the embedded key_id. If the key is unknown, returns an error. If either the HMAC or the GCM tag fails to verify, returns a distinct integrity error (never a partial plaintext).

Parameters
encodedsingle-line record produced by encrypt_record (trailing '
' is tolerated)
Returns
plaintext on success

Definition at line 658 of file audit_log_cipher.cpp.

659 {
661 kcenon::common::error::codes::common_errors::internal_error,
662 "audit log decryption requires OpenSSL "
663 "(build with PACS_WITH_OPENSSL=ON)");
664}
Result< T > pacs_error(int code, const std::string &message, const std::string &details="")
Create a PACS error result with module context.
Definition result.h:234

References kcenon::pacs::pacs_error().

Here is the call graph for this function:

◆ encrypt_record()

Result< std::string > kcenon::pacs::security::audit_log_cipher::encrypt_record ( const std::string & plaintext) const
nodiscard

Encrypt a plaintext audit record.

Uses the currently-active key. A fresh 96-bit IV is drawn for every call from the OS CSPRNG. The returned string is the single-line serialised record (without trailing newline).

Parameters
plaintextarbitrary byte string (typically an RFC 3881 XML audit message)
Returns
encoded record or an error if no active key is configured or the underlying crypto provider fails

Definition at line 650 of file audit_log_cipher.cpp.

651 {
653 kcenon::common::error::codes::common_errors::internal_error,
654 "audit log encryption requires OpenSSL "
655 "(build with PACS_WITH_OPENSSL=ON)");
656}

References kcenon::pacs::pacs_error().

Here is the call graph for this function:

◆ looks_encrypted()

bool kcenon::pacs::security::audit_log_cipher::looks_encrypted ( const std::string & line)
staticnodiscardnoexcept

Check whether a line appears to be an encrypted audit record.

Definition at line 351 of file audit_log_cipher.cpp.

351 {
352 const std::string prefix = std::string(audit_cipher_format_tag) + "|" +
354 return line.size() >= prefix.size() &&
355 std::equal(prefix.begin(), prefix.end(), line.begin());
356}
constexpr const char * audit_cipher_format_version
constexpr const char * audit_cipher_format_tag
Format version string embedded in every encrypted record.

References kcenon::pacs::security::audit_cipher_format_tag, and kcenon::pacs::security::audit_cipher_format_version.

◆ verify_record()

VoidResult kcenon::pacs::security::audit_log_cipher::verify_record ( const std::string & encoded) const
nodiscard

Verify a record's authenticity without returning plaintext.

Returns
VoidResult::ok if both HMAC and GCM tag verify, error otherwise

Definition at line 666 of file audit_log_cipher.cpp.

667 {
668 return pacs_void_error(
669 kcenon::common::error::codes::common_errors::internal_error,
670 "audit log verification requires OpenSSL "
671 "(build with PACS_WITH_OPENSSL=ON)");
672}
VoidResult pacs_void_error(int code, const std::string &message, const std::string &details="")
Create a PACS void error result.
Definition result.h:249

References kcenon::pacs::pacs_void_error().

Here is the call graph for this function:

Member Data Documentation

◆ keys_

audit_key_manager& kcenon::pacs::security::audit_log_cipher::keys_
private

Definition at line 243 of file audit_log_cipher.h.


The documentation for this class was generated from the following files: