Skip to content

Commit 5d620b6

Browse files
romanmichalvasko
authored andcommitted
session server REFACTOR move nc_base64der_to_cert
Moved this function from session_server_tls file, because it shall be used by more different files in the future.
1 parent 26b474c commit 5d620b6

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

src/session.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,24 @@ nc_poll(struct pollfd *pfd, uint16_t pfd_count, int timeout_ms)
138138

139139
#ifdef NC_ENABLED_SSH_TLS
140140

141+
void *
142+
nc_base64der_to_cert(const char *data)
143+
{
144+
char *buf = NULL;
145+
void *cert;
146+
147+
NC_CHECK_ARG_RET(NULL, data, NULL);
148+
149+
if (asprintf(&buf, "%s%s%s", "-----BEGIN CERTIFICATE-----\n", data, "\n-----END CERTIFICATE-----") == -1) {
150+
ERRMEM;
151+
return NULL;
152+
}
153+
154+
cert = nc_tls_pem_to_cert_wrap(buf);
155+
free(buf);
156+
return cert;
157+
}
158+
141159
const char *
142160
nc_privkey_format_to_str(NC_PRIVKEY_FORMAT format)
143161
{

src/session_p.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,14 @@ const char *nc_privkey_format_to_str(NC_PRIVKEY_FORMAT format);
756756
*/
757757
int nc_is_pk_subject_public_key_info(const char *b64);
758758

759+
/**
760+
* @brief Import a Base64 DER encoded certificate data.
761+
*
762+
* @param[in] data Base64 DER encoded certificate data.
763+
* @return Imported certificate on success, NULL on error.
764+
*/
765+
void * nc_base64der_to_cert(const char *data);
766+
759767
#endif /* NC_ENABLED_SSH_TLS */
760768

761769
void *nc_realloc(void *ptr, size_t size);

src/session_server_tls.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,6 @@ nc_server_tls_ts_ref_get_certs(const char *referenced_name, struct nc_certificat
9999
return 0;
100100
}
101101

102-
static void *
103-
nc_base64der_to_cert(const char *in)
104-
{
105-
char *buf = NULL;
106-
void *cert;
107-
108-
NC_CHECK_ARG_RET(NULL, in, NULL);
109-
110-
if (asprintf(&buf, "%s%s%s", "-----BEGIN CERTIFICATE-----\n", in, "\n-----END CERTIFICATE-----") == -1) {
111-
ERRMEM;
112-
return NULL;
113-
}
114-
115-
cert = nc_tls_pem_to_cert_wrap(buf);
116-
free(buf);
117-
return cert;
118-
}
119-
120102
static void *
121103
nc_base64der_to_privkey(const char *in, const char *key_str)
122104
{

0 commit comments

Comments
 (0)