@@ -1559,26 +1559,38 @@ int main(int argc, char **argv)
1559
1559
1560
1560
/* Build our SSL context */
1561
1561
if (SSL_ENABLED () && do_ssl ) {
1562
+ char * cert = nvram_safe_get ("https_cert" );
1563
+ char * key = nvram_safe_get ("https_key" );
1564
+ char * certfile = NULL ;
1565
+ char * keyfile = NULL ;
1566
+ if (* cert ) {
1567
+ certfile = "/tmp/https_cert" ;
1568
+ writenvram ("https_cert" , certfile );
1569
+ }
1570
+ if (* key ) {
1571
+ keyfile = "/tmp/https_key" ;
1572
+ writenvram ("https_key" , keyfile );
1573
+ }
1574
+ if (!certfile )
1575
+ certfile = nvram_safe_get ("https_cert_file" );
1576
+ if (!* certfile )
1577
+ certfile = CERT_FILE ;
1578
+ if (!keyfile )
1579
+ keyfile = nvram_safe_get ("https_key_file" );
1580
+ if (!* keyfile )
1581
+ keyfile = KEY_FILE ;
1562
1582
#ifdef HAVE_OPENSSL
1563
1583
SSLeay_add_ssl_algorithms ();
1564
1584
SSL_load_error_strings ();
1565
1585
ctx = SSL_CTX_new (SSLv23_server_method ());
1566
- #ifdef HAVE_CUSTOMSSLCERT
1567
- if (SSL_CTX_use_certificate_file (ctx , nvram_safe_get ("https_cert_file" ), SSL_FILETYPE_PEM )
1568
- #else
1569
- if (SSL_CTX_use_certificate_file (ctx , CERT_FILE , SSL_FILETYPE_PEM )
1570
- #endif
1586
+ if (SSL_CTX_use_certificate_file (ctx , certfile , SSL_FILETYPE_PEM )
1571
1587
== 0 ) {
1572
1588
cprintf ("Can't read %s\n" , CERT_FILE );
1573
1589
ERR_print_errors_fp (stderr );
1574
1590
exit (1 );
1575
1591
1576
1592
}
1577
- #ifdef HAVE_CUSTOMSSLCERT
1578
- if (SSL_CTX_use_PrivateKey_file (ctx , nvram_safe_get ("https_key_file" ), SSL_FILETYPE_PEM )
1579
- #else
1580
- if (SSL_CTX_use_PrivateKey_file (ctx , KEY_FILE , SSL_FILETYPE_PEM )
1581
- #endif
1593
+ if (SSL_CTX_use_PrivateKey_file (ctx , keyfile , SSL_FILETYPE_PEM )
1582
1594
== 0 ) {
1583
1595
cprintf ("Can't read %s\n" , KEY_FILE );
1584
1596
ERR_print_errors_fp (stderr );
@@ -1599,12 +1611,12 @@ int main(int argc, char **argv)
1599
1611
bzero (& ssl , sizeof (ssl ));
1600
1612
bzero (& srvcert , sizeof (x509_crt ));
1601
1613
x509_crt_init (& srvcert );
1602
- ret = x509_crt_parse_file (& srvcert , CERT_FILE );
1614
+ ret = x509_crt_parse_file (& srvcert , certfile );
1603
1615
if (ret != 0 ) {
1604
1616
printf ("x509_read_crtfile failed\n" );
1605
1617
exit (0 );
1606
1618
}
1607
- ret = pk_parse_keyfile (& rsa , KEY_FILE , NULL );
1619
+ ret = pk_parse_keyfile (& rsa , keyfile , NULL );
1608
1620
if (ret != 0 ) {
1609
1621
printf ("x509_read_keyfile failed\n" );
1610
1622
exit (0 );
@@ -1613,18 +1625,9 @@ int main(int argc, char **argv)
1613
1625
1614
1626
#ifdef HAVE_MATRIXSSL
1615
1627
matrixssl_init ();
1616
- #ifdef HAVE_CUSTOMSSLCERT
1617
- if (f_exists (nvram_safe_get ("https_cert_file" )) && f_exists (nvram_safe_get ("https_key_file" ))) {
1618
- if (0 != matrixSslReadKeys (& keys , nvram_safe_get ("https_cert_file" ), nvram_safe_get ("https_key_file" ), NULL , NULL )) {
1619
- fprintf (stderr , "Error reading or parsing %s / %s.\n" , nvram_safe_get ("https_cert_file" ), nvram_safe_get ("https_key_file" ));
1620
- }
1621
- } else
1622
- #endif
1623
- {
1624
- if (0 != matrixSslReadKeys (& keys , CERT_FILE , KEY_FILE , NULL , NULL )) {
1625
- fprintf (stderr , "Error reading or parsing %s.\n" , KEY_FILE );
1626
- exit (0 );
1627
- }
1628
+ if (0 != matrixSslReadKeys (& keys , certfile , keyfile , NULL , NULL )) {
1629
+ fprintf (stderr , "Error reading or parsing %s.\n" , KEY_FILE );
1630
+ exit (0 );
1628
1631
}
1629
1632
#endif
1630
1633
}
0 commit comments