Source
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
static void pem_replace_spaces(char *s)
{
while ('\0' != *s && '-' != *s)
{
if (' ' == *s)
*s = '\n';
s++;
}
}
/******************************************************************************
* *
* Purpose: Receives PEM container with arbitrary newlines, validate if *
* contains necessary newlines after header and before footer, *
* insert them if they are absent. *
* *
* Parameters: key - [IN/OUT] key in PEM container *
* key_len - [IN/OUT] key length *
* *
******************************************************************************/
void zbx_normalize_pem(char **key, size_t *key_len)
{
char *ptr;
size_t offset;
if (0 == strncmp(*key, PEM_BEGIN, ZBX_CONST_STRLEN(PEM_BEGIN)))
{
if (NULL == (ptr = strstr(*key + ZBX_CONST_STRLEN(PEM_BEGIN), PEM_BEGIN_HEADER_END)))