Files
bongo/include/bongotlsrpt.h
T
2026-07-21 10:32:45 +02:00

185 lines
7.0 KiB
C

/****************************************************************************
* <Novell-copyright>
* Copyright (c) 2001 Novell, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, contact Novell, Inc.
* </Novell-copyright>
****************************************************************************/
#ifndef BONGO_TLSRPT_H
#define BONGO_TLSRPT_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define BONGO_TLSRPT_MAX_ENDPOINTS 16
#define BONGO_TLSRPT_URI_SIZE 2048
#define BONGO_TLSRPT_DOMAIN_SIZE 256
#define BONGO_TLSRPT_REPORTING_POLICY_SIZE 16384
#define BONGO_TLSRPT_POLICY_SIZE 8192
#define BONGO_TLSRPT_MX_SIZE 2048
#define BONGO_TLSRPT_HELO_SIZE 4096
#define BONGO_TLSRPT_REASON_SIZE 1024
#define BONGO_TLSRPT_ADDRESS_SIZE 64
typedef enum BongoTlsRptEndpointType {
BONGO_TLSRPT_ENDPOINT_MAILTO = 1,
BONGO_TLSRPT_ENDPOINT_HTTPS = 2
} BongoTlsRptEndpointType;
typedef struct BongoTlsRptEndpoint {
BongoTlsRptEndpointType type;
char uri[BONGO_TLSRPT_URI_SIZE];
} BongoTlsRptEndpoint;
typedef struct BongoTlsRptDnsPolicy {
BongoTlsRptEndpoint endpoints[BONGO_TLSRPT_MAX_ENDPOINTS];
size_t endpoint_count;
} BongoTlsRptDnsPolicy;
typedef enum BongoTlsRptPolicyType {
BONGO_TLSRPT_POLICY_TLSA = 1,
BONGO_TLSRPT_POLICY_STS = 2,
BONGO_TLSRPT_POLICY_NONE = 3
} BongoTlsRptPolicyType;
typedef enum BongoTlsRptResultType {
BONGO_TLSRPT_RESULT_SUCCESS = 0,
BONGO_TLSRPT_RESULT_STARTTLS_NOT_SUPPORTED,
BONGO_TLSRPT_RESULT_CERTIFICATE_HOST_MISMATCH,
BONGO_TLSRPT_RESULT_CERTIFICATE_EXPIRED,
BONGO_TLSRPT_RESULT_CERTIFICATE_NOT_TRUSTED,
BONGO_TLSRPT_RESULT_VALIDATION_FAILURE,
BONGO_TLSRPT_RESULT_TLSA_INVALID,
BONGO_TLSRPT_RESULT_DNSSEC_INVALID,
BONGO_TLSRPT_RESULT_DANE_REQUIRED,
BONGO_TLSRPT_RESULT_STS_POLICY_FETCH_ERROR,
BONGO_TLSRPT_RESULT_STS_POLICY_INVALID,
BONGO_TLSRPT_RESULT_STS_WEBPKI_INVALID
} BongoTlsRptResultType;
typedef struct BongoTlsRptEvent {
int64_t day_start;
/* Destination domain that published the _smtp._tls reporting policy. */
const char *report_domain;
/* Domain to which the applied STS/TLSA policy belongs. */
const char *policy_domain;
/* The exact _smtp._tls TXT value in force for this SMTP connection. */
const char *reporting_policy;
BongoTlsRptPolicyType policy_type;
/* Newline-separated RFC presentation strings. */
const char *policy_strings;
/* Newline-separated MX host names for an MTA-STS policy. */
const char *mx_hosts;
BongoTlsRptResultType result_type;
const char *sending_mta_ip;
const char *receiving_mx_hostname;
const char *receiving_mx_helo;
const char *receiving_ip;
const char *additional_information;
const char *failure_reason;
} BongoTlsRptEvent;
typedef struct BongoTlsRptStore BongoTlsRptStore;
typedef struct BongoTlsRptDelivery {
int64_t id;
int endpoint_type;
int attempts;
int64_t day_start;
int64_t created_at;
int64_t expires_at;
char report_domain[BONGO_TLSRPT_DOMAIN_SIZE];
char report_id[BONGO_TLSRPT_DOMAIN_SIZE * 2];
char endpoint_uri[BONGO_TLSRPT_URI_SIZE];
char *json;
} BongoTlsRptDelivery;
typedef enum BongoTlsRptDeliveryResult {
BONGO_TLSRPT_DELIVERY_RETRY = 0,
BONGO_TLSRPT_DELIVERY_SUCCESS = 1,
BONGO_TLSRPT_DELIVERY_PERMANENT_FAILURE = 2
} BongoTlsRptDeliveryResult;
/* Parse one complete TXT value after DNS character-string concatenation. */
int BongoTlsRptParseRecord(const char *record, BongoTlsRptDnsPolicy *policy);
/* RFC 8460 selection: exactly one candidate TLSRPTv1 record is usable. */
int BongoTlsRptSelectRecord(const char *const *records, size_t record_count,
BongoTlsRptDnsPolicy *policy);
int BongoTlsRptSelectRecordValue(const char *const *records,
size_t record_count,
BongoTlsRptDnsPolicy *policy,
const char **selected_record);
int BongoTlsRptStoreOpen(BongoTlsRptStore **store, const char *database_path);
void BongoTlsRptStoreClose(BongoTlsRptStore **store);
int BongoTlsRptStoreRecord(BongoTlsRptStore *store,
const BongoTlsRptEvent *event);
/* Caller owns the returned JSON string and releases it with MemFree(). */
int BongoTlsRptStoreBuildReport(BongoTlsRptStore *store,
const char *report_domain,
int64_t day_start,
const char *reporting_policy,
const char *organization_name,
const char *contact_info,
const char *report_id,
char **json);
int BongoTlsRptStoreDeleteReport(BongoTlsRptStore *store,
const char *report_domain,
int64_t day_start,
const char *reporting_policy);
/*
* Atomically turn the oldest completed reporting-policy group into one
* durable delivery per RUA endpoint. The corresponding event rows are
* removed in the same SQLite write transaction, so events recorded after
* the snapshot cannot be lost. Returns 1 when a batch was prepared, 0 when
* no complete day is available, and -1 on error.
*/
int BongoTlsRptStorePrepareNext(BongoTlsRptStore *store,
int64_t before_day_start,
const char *organization_name,
const char *contact_info,
const char *submitter,
int64_t now,
int64_t initial_not_before);
/* Returns 1 for a due delivery, 0 when none is due, and -1 on error. */
int BongoTlsRptStoreNextDelivery(BongoTlsRptStore *store, int64_t now,
BongoTlsRptDelivery *delivery,
int64_t *next_not_before);
void BongoTlsRptDeliveryFree(BongoTlsRptDelivery *delivery);
int BongoTlsRptStoreFinishDelivery(BongoTlsRptStore *store,
int64_t delivery_id,
BongoTlsRptDeliveryResult result,
int64_t next_attempt,
const char *error);
int BongoTlsRptStoreCleanupExpired(BongoTlsRptStore *store, int64_t now);
const char *BongoTlsRptPolicyTypeName(BongoTlsRptPolicyType type);
const char *BongoTlsRptResultTypeName(BongoTlsRptResultType type);
#ifdef __cplusplus
}
#endif
#endif