ComIntCmd_Certs/Certs.c

72 lines
3.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Created by cfif on 04.06.2024.
//
#include "Certs.h"
#include "string.h"
#include "AtGsmSimComA7600_SSL_LOAD_CA.h"
const char file_ca[] = "ca.pem";
const char file_crt[] = "crt.pem";
const char file_key[] = "key.pem";
void XfcProtMethodsInit_Certs(tCerts *certs) {
tIsFind check;
memset(&check, 0, sizeof(check));
if (osMutexAcquire(certs->gsmAt->access, 15000) == osOK) {
check = AtGsmSimComA7600_SSL_CHECK_CA(certs->gsmAt,
file_ca, strlen(file_ca),
file_crt, strlen(file_crt),
file_key, strlen(file_key), 2000);
osMutexRelease(certs->gsmAt->access);
}
if ((!check.isFind1) || (!check.isFind2) || (!check.isFind3)) {
if (!check.isFind1) {
String64Copy(&certs->cacert, "Не загружен", sizeof("Не загружен") - 1);
} else {
String64Copy(&certs->cacert, "Загружен", sizeof("Загружен") - 1);
}
if (!check.isFind2) {
String64Copy(&certs->clientcert, "Не загружен", sizeof("Не загружен") - 1);
} else {
String64Copy(&certs->clientcert, "Загружен", sizeof("Загружен") - 1);
}
if (!check.isFind3) {
String64Copy(&certs->clientkey, "Не загружен", sizeof("Не загружен") - 1);
} else {
String64Copy(&certs->clientkey, "Загружен", sizeof("Загружен") - 1);
}
} else {
String64Copy(&certs->cacert, "Загружен", sizeof("Загружен") - 1);
String64Copy(&certs->clientcert, "Загружен", sizeof("Загружен") - 1);
String64Copy(&certs->clientkey, "Загружен", sizeof("Загружен") - 1);
}
}
void XfcProtMethodsAdd_Certs(tXfcProtTable *protTab, tCerts *certs, tAtCmd *gsmAt) {
certs->gsmAt = gsmAt;
if (gsmAt == NULL) {
String64Copy(&certs->cacert, "Интерфейс не инициализирован", sizeof("Интерфейс не инициализирован") - 1);
String64Copy(&certs->clientcert, "Интерфейс не инициализирован", sizeof("Интерфейс не инициализирован") - 1);
String64Copy(&certs->clientkey, "Интерфейс не инициализирован", sizeof("Интерфейс не инициализирован") - 1);
} else {
String64Copy(&certs->cacert, "Инициализация", sizeof("Инициализация") - 1);
String64Copy(&certs->clientcert, "Инициализация", sizeof("Инициализация") - 1);
String64Copy(&certs->clientkey, "Инициализация", sizeof("Инициализация") - 1);
}
XfcProtTable_AddStatic(protTab, "GET_CERTS", XfcProtMethod_CertsGet, certs);
XfcProtTable_AddStatic(protTab, "SET_CERTS", XfcProtMethod_CertsSet, certs);
XfcProtTable_AddStatic(protTab, "DEL_CERTS", XfcProtMethod_CertsDel, certs);
}