Added /etc/telegram/server.pub as default server public key place

This commit is contained in:
Vysheng 2014-02-04 20:35:16 +04:00
parent 57cff060a3
commit 12e8e5c7b7
3 changed files with 23 additions and 10 deletions

6
main.c
View File

@ -47,6 +47,7 @@
#include <libconfig.h> #include <libconfig.h>
#endif #endif
#include "telegram.h"
#include "loop.h" #include "loop.h"
#include "mtproto-client.h" #include "mtproto-client.h"
#include "interface.h" #include "interface.h"
@ -59,7 +60,7 @@
#define PROGNAME "telegram-client" #define PROGNAME "telegram-client"
#define VERSION "0.01" #define VERSION "0.01"
#define CONFIG_DIRECTORY ".telegram" #define CONFIG_DIRECTORY "." PROG_NAME
#define CONFIG_FILE "config" #define CONFIG_FILE "config"
#define AUTH_KEY_FILE "auth" #define AUTH_KEY_FILE "auth"
#define STATE_FILE "state" #define STATE_FILE "state"
@ -208,7 +209,6 @@ void running_for_first_time (void) {
tasprintf (&config_filename, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, CONFIG_FILE); tasprintf (&config_filename, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, CONFIG_FILE);
config_filename = make_full_path (config_filename); config_filename = make_full_path (config_filename);
static struct stat config_file_stat;
int config_file_fd; int config_file_fd;
char *config_directory = get_config_directory (); char *config_directory = get_config_directory ();
//char *downloads_directory = get_downloads_directory (); //char *downloads_directory = get_downloads_directory ();
@ -220,7 +220,7 @@ void running_for_first_time (void) {
tfree_str (config_directory); tfree_str (config_directory);
config_directory = NULL; config_directory = NULL;
// see if config file is there // see if config file is there
if (stat (config_filename, &config_file_stat) != 0) { if (access (config_filename, R_OK) != 0) {
// config file missing, so touch it // config file missing, so touch it
config_file_fd = open (config_filename, O_CREAT | O_RDWR, 0600); config_file_fd = open (config_filename, O_CREAT | O_RDWR, 0600);
if (config_file_fd == -1) { if (config_file_fd == -1) {

View File

@ -45,6 +45,7 @@
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <poll.h> #include <poll.h>
#include "telegram.h"
#include "net.h" #include "net.h"
#include "include.h" #include "include.h"
#include "queries.h" #include "queries.h"
@ -126,7 +127,7 @@ int Response_len;
* *
*/ */
char *rsa_public_key_name = "tg.pub"; char *rsa_public_key_name; // = "tg.pub";
RSA *pubKey; RSA *pubKey;
long long pk_fingerprint; long long pk_fingerprint;
@ -144,6 +145,10 @@ static int rsa_load_public_key (const char *public_key_name) {
return -1; return -1;
} }
if (verbosity) {
logprintf ( "public key '%s' loaded successfully\n", rsa_public_key_name);
}
return 0; return 0;
} }
@ -1807,12 +1812,16 @@ int auth_is_success (void) {
void on_start (void) { void on_start (void) {
prng_seed (0, 0); prng_seed (0, 0);
if (rsa_load_public_key (rsa_public_key_name) < 0) { if (rsa_public_key_name) {
perror ("rsa_load_public_key"); if (rsa_load_public_key (rsa_public_key_name) < 0) {
exit (1); perror ("rsa_load_public_key");
} exit (1);
if (verbosity) { }
logprintf ( "public key '%s' loaded successfully\n", rsa_public_key_name); } else {
if (rsa_load_public_key ("tg.pub") < 0 && rsa_load_public_key ("/etc/" PROG_NAME "/server.pub") < 0) {
perror ("rsa_load_public_key");
exit (1);
}
} }
pk_fingerprint = compute_rsa_key_fingerprint (pubKey); pk_fingerprint = compute_rsa_key_fingerprint (pubKey);
} }

View File

@ -18,3 +18,7 @@
*/ */
#define MAX_DC_NUM 9 #define MAX_DC_NUM 9
#define MAX_PEER_NUM 100000 #define MAX_PEER_NUM 100000
#ifndef PROG_NAME
#define PROG_NAME "telegram"
#endif