Compare commits

..

2 Commits

Author SHA1 Message Date
Mithras
9022a21f2c 0.1.0 2020-04-06 16:38:30 +02:00
Mithras
01b0e56804 0.1.0 2020-04-06 16:37:01 +02:00
6 changed files with 127 additions and 67 deletions

View File

@ -524,23 +524,28 @@ static int connect( int argc, char *argv[] )
fflush( stdout ); fflush( stdout );
FILE* f; FILE* f;
f = fopen( opt.serial, "w+" ); f = fopen( opt.serial, "r" );
if(f){
//Nacitavanie serioveho cisla do premennej typu mpi zo suboru mbedtls_mpi_read_file(&serial,10,f);
if( ( ret = mbedtls_mpi_read_file(&serial,10,f) ) != 0 ) }else
{//ak subor neexistuje tak sa nacita seriove cislo zo stringu "1" {
mbedtls_mpi_read_string( &serial, 10, "1"); fclose(f);
// mbedtls_strerror( ret, buf, 1024 ); fopen(opt.serial,"w");
// mbedtls_printf( " failed\n ! mbedtls_mpi_read_string " mbedtls_mpi_read_string( &serial, 10, "0");
// "returned -0x%04x - %s\n\n", -ret, buf );
//goto exit;
} }
fclose(f);
/*Zvysenie serioveho cisla o +1*/ /*Zvysenie serioveho cisla o +1*/
mbedtls_mpi_add_int(&serial,&serial,1); mbedtls_mpi_add_int(&serial,&serial,1);
/*Zapis serioveho cisla do suboru*/ /*Zapis serioveho cisla do suboru*/
mbedtls_mpi_write_file(NULL,&serial,10,f);
fclose( f );
f = fopen( opt.serial, "w" );
mbedtls_mpi_write_file(NULL,&serial,10,f);
fclose( f );
mbedtls_printf( " ok\n" ); mbedtls_printf( " ok\n" );

View File

@ -0,0 +1,15 @@
-----BEGIN CERTIFICATE-----
MIICKDCCAYigAwIBAgIBAjAMBggqhkjOPQQDAgUAMC8xETAPBgNVBAMMCEVTUDMy
X0NBMQ0wCwYDVQQKDARUVUtFMQswCQYDVQQGEwJTSzAeFw0wMTAxMDEwMDAwMDBa
Fw0zMDEyMzEyMzU5NTlaMC8xETAPBgNVBAMMCEVTUDMyX0NBMQ0wCwYDVQQKDARU
VUtFMQswCQYDVQQGEwJTSzCBmzAQBgc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urfOcDq4EGEaxRKAU0814VEmU87btIDx80+z5Dbf+GGHCPrY7odIkxGNn0DJY AD2BS1xluszT1wE9FZahLqlQIpy7viII8W6RyLcjHsj/EOK73+jcyKzhyqOX0E/g
W1WcF+DOcbiWoUN6DTkAML0SMnp8aGj9ffx3x+qoggT+vGdWVVA4pgwqZT7Ybntx lhHB6GOGv9B9BELrlVP4MlG47kDiXZpa3hhCUL4IuQhUejOLttLtpbvf3qzV6OLv
bkzcNFW0sqmCv4IN1t4w6L0A87ZwsNwVpre/j6uyBw7s8YoJHDLRFT6g7qgn0tcN UhGSkpstIAqUxb85GZdjGJpLxMIFxDV6ZIj1mm+R+z2UcYTO5sBtEgsEMgraj/x8
ZufhNISvgWCVJQy/SZjNBHSpnIdCUSJAeTY2mkM4sGxY0Widk8LnjydxZUSxC3Nl bShp3AuclQvva7TvvZKIxa53v5SGs41Bmbz/B7XI2I5fzoFC7k/3zLEsReeQ9qg3
hb6pnMh3jRq4h0+5CZielA4/a+TdrNPv/qok67ot/XJdY3qHCCd8O2b14OVq9jo= 0V6UUMlSv+6xcAYwUF2joEMFE8RYSs6tVRh3yHoGlngu08tbf3vLZ/XHj2tkXTnD
Na9raei70fQGtUU3atIkhkY=
-----END CERTIFICATE----- -----END CERTIFICATE-----

View File

@ -1,28 +1,27 @@
-----BEGIN PRIVATE KEY----- -----BEGIN RSA PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCwYp7epz++0QkH MIIEpAIBAAKCAQEAn4LXgTvdUVOCPODVhF0F2rB6vDWHk+YgxhR31fZFnOcxNw+9
JioMD7U7BitLgpcYPi8Cid1l7snt6Kp546iQsDBJ3l8xnRtPU7ANEsjT8KxIHmyw DIpda+3LSukp/QBn7xrd+cZBTTK9tfDIVDF4e2nnedk0HkHyuKcnyOKUzyFdtE04
h/NGp94FlOKRw3ahh3yUGtowS9vdHv+S+TAfuj07NjSnKIyv5KnGZJ+fDFl4Q1tT B8f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QglM19ZtQeW3LKkY4BsIxjDf45ymH407IQKBgE/g aj9OoZ22B/74MygHJVlW9A8CgYEAmK8p/FQ8JrG93J2Uz1wISAabNM76BVIghryd
Ul6cPfOxQRlNLH4VMVgInSyyxWx1mODFy7DRrgCuh5kTVh+QUVBM8x9lcwAn8V9/ 6MJgLjsKYTnE94ao4NHJZdB71exeRRpD382Ts0BOf1xc/nyzk8QB3y0FpHETuvsH
nQT55wR8E603pznqY/jX0xvAqZE6YVPcw4kpZcwNwL1RhEl8GliikBlRzUL3SsW3 ejwi31wpOl5AXed7DZOgctax5pEjp1vLrSPFnHx4+XN9CEfiLQJR7idG1SpTvBv1
q30AfqEViHPE3XpE66PPo6Hb1ymJCVr77iUuC3wtAoGBAIBrOGunv1qZMfqmwAY2 kqib8CUCgYBTu9CNS5WfQC/YbKYeU1F6lYRNw79mVmQfAJyL/aUrSGJuUcZo+kZv
lxlzRgxgSiaev0lTNxDzZkmU/u3dgdTwJ5DDANqPwJc6b8SGYTp9rQ0mbgVHnhIB Rq6QfB7mJDLwniwgVALAGhiDJPagstyajUCSkrV9lDleAPOfb4ep0HQK1GA2Jrs6
jcJQBQkTfq6Z0H6OoTVi7dPs3ibQJFrtkoyvYAbyk36quBmNRjVh6rc8468bhXYr ldn8NTn7z9pToWbgMyl25vaoSMzIjVJ7uic3LN+iruXpxDpBAFqrfA==
v/t+MeGJP/0Zw8v/X2CFll96 -----END RSA PRIVATE KEY-----
-----END PRIVATE KEY-----

View File

@ -194,15 +194,51 @@ static httpd_handle_t start_webserver(void)
httpd_ssl_config_t conf = HTTPD_SSL_CONFIG_DEFAULT(); httpd_ssl_config_t conf = HTTPD_SSL_CONFIG_DEFAULT();
conf.httpd.stack_size = 12000; conf.httpd.stack_size = 12000;
//pridanie certifikatu do konfiguracie //pridanie certifikatu do konfiguracie
extern const unsigned char cacert_pem_start[] asm("_binary_cacert_pem_start"); unsigned char *cacert_pem_start = calloc(1200,sizeof(unsigned char));//[1025];
extern const unsigned char cacert_pem_end[] asm("_binary_cacert_pem_end"); //memset(cacert_pem_start,'\0',1025);
conf.cacert_pem = cacert_pem_start; //char line_buffer[66];
conf.cacert_len = cacert_pem_end - cacert_pem_start; FILE* fd = fopen("/spiffs/server.crt", "r");
fseek(fd, 0, SEEK_END);
long int size = ftell(fd);
fseek(fd, 0, SEEK_SET);
int bytes_read = fread(cacert_pem_start, sizeof(unsigned char), size, fd);
/*
if(fd!=NULL){
while(fgets(line_buffer, sizeof(line_buffer)-1, fd)){
strcat(cacert_pem_start,line_buffer);
}
}
*/
fclose(fd);
conf.cacert_pem = (const unsigned char*)cacert_pem_start;
printf("%s", conf.cacert_pem);
conf.cacert_len = size+1;
//pridanie sukromneho kluca do konfiguracie //pridanie sukromneho kluca do konfiguracie
extern const unsigned char prvtkey_pem_start[] asm("_binary_prvtkey_pem_start"); unsigned char *prvtkey_pem_start =calloc(1800,sizeof(unsigned char));
extern const unsigned char prvtkey_pem_end[] asm("_binary_prvtkey_pem_end");
//memset(prvtkey_pem_start,'\0',2050);
// memset(line_buffer,'\0',66);
fd = fopen("/spiffs/server_key.key", "rb");
/*
if(fd!=NULL){
while(fgets(line_buffer, sizeof(line_buffer)-1, fd)){
strcat((char*)prvtkey_pem_start,line_buffer);
}
}
*/
fseek(fd, 0, SEEK_END);
size = ftell(fd);
fseek(fd, 0, SEEK_SET);
bytes_read = fread(prvtkey_pem_start, sizeof(unsigned char), size, fd);
fclose(fd);
conf.prvtkey_pem = prvtkey_pem_start; conf.prvtkey_pem = prvtkey_pem_start;
conf.prvtkey_len = prvtkey_pem_end - prvtkey_pem_start; conf.prvtkey_len = size+1;
//vytvorenie HTTP + SSL servera //vytvorenie HTTP + SSL servera
esp_err_t ret = httpd_ssl_start(&server, &conf); esp_err_t ret = httpd_ssl_start(&server, &conf);
if (ESP_OK != ret) { if (ESP_OK != ret) {

View File

@ -177,9 +177,13 @@ void app_main(void)
read_file("/spiffs/keyfile.key"); //read_file("/spiffs/keyfile.key");
read_file("/spiffs/ca.crt"); read_file("/spiffs/ca.crt");
read_file("/spiffs/user.crt"); read_file("/spiffs/server.crt");
read_file("/spiffs/server_key.key");
read_file("/spiffs/serial.txt");
/* Prompt to be printed before each line. /* Prompt to be printed before each line.
* This can be customized, made dynamic, etc. * This can be customized, made dynamic, etc.
*/ */