Skip to content

Commit

Permalink
provide notice that new public key has been created and stored
Browse files Browse the repository at this point in the history
  • Loading branch information
fduncanh committed Dec 7, 2023
1 parent 40da5d2 commit b1c52a6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
7 changes: 5 additions & 2 deletions lib/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,19 @@ struct ed25519_key_s {
EVP_PKEY *pkey;
};

ed25519_key_t *ed25519_key_generate(const char *keyfile) {
ed25519_key_t *ed25519_key_generate(const char *keyfile, int *result) {
ed25519_key_t *key;
EVP_PKEY_CTX *pctx;
BIO *bp;
FILE *file;
bool new_pk = false;
bool use_keyfile = strlen(keyfile);

*result = 0;

key = calloc(1, sizeof(ed25519_key_t));
assert(key);

if (use_keyfile) {
file = fopen(keyfile, "r");
if (file) {
Expand Down Expand Up @@ -399,6 +401,7 @@ ed25519_key_t *ed25519_key_generate(const char *keyfile) {
PEM_write_bio_PrivateKey(bp, key->pkey, NULL, NULL, 0, NULL, NULL);
BIO_free(bp);
fclose(file);
*result = 1;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int gcm_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *pl

typedef struct ed25519_key_s ed25519_key_t;

ed25519_key_t *ed25519_key_generate(const char * keyfile);
ed25519_key_t *ed25519_key_generate(const char * keyfile, int * result);
ed25519_key_t *ed25519_key_from_raw(const unsigned char data[ED25519_KEY_SIZE]);
void ed25519_key_get_raw(unsigned char data[ED25519_KEY_SIZE], const ed25519_key_t *key);
/*
Expand Down
6 changes: 3 additions & 3 deletions lib/pairing.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ derive_key_internal(pairing_session_t *session, const unsigned char *salt, unsig
}

pairing_t *
pairing_init_generate(const char * keyfile)
pairing_init_generate(const char * keyfile, int *result)
{
pairing_t *pairing;

*result = 0;
pairing = calloc(1, sizeof(pairing_t));
if (!pairing) {
return NULL;
}

pairing->ed = ed25519_key_generate(keyfile);
pairing->ed = ed25519_key_generate(keyfile, result);

return pairing;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/pairing.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
typedef struct pairing_s pairing_t;
typedef struct pairing_session_s pairing_session_t;

pairing_t *pairing_init_generate(const char * keyfile);
pairing_t *pairing_init_generate(const char * keyfile, int *result);
void pairing_get_public_key(pairing_t *pairing, unsigned char public_key[ED25519_KEY_SIZE]);

pairing_session_t *pairing_session_init(pairing_t *pairing);
Expand Down
10 changes: 6 additions & 4 deletions lib/raop.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,12 @@ raop_init(int max_clients, raop_callbacks_t *callbacks, const char* keyfile) {
raop->logger = logger_init();

/* create a new public key for pairing */
pairing = pairing_init_generate(keyfile);
int new_key;
pairing = pairing_init_generate(keyfile, &new_key);
if (!pairing) {
free(raop);
return NULL;
}

/* store PK as a string in raop->pk_str */
memset(raop->pk_str, 0, sizeof(raop->pk_str));
#ifdef PK
Expand All @@ -459,7 +459,10 @@ raop_init(int max_clients, raop_callbacks_t *callbacks, const char* keyfile) {
strncpy(raop->pk_str, (const char *) pk_str, 2*ED25519_KEY_SIZE);
free(pk_str);
#endif

if (new_key) {
printf("*** A new Public Key has been created and stored in %s\n", keyfile);
}

/* Set HTTP callbacks to our handlers */
memset(&httpd_cbs, 0, sizeof(httpd_cbs));
httpd_cbs.opaque = raop;
Expand Down Expand Up @@ -626,7 +629,6 @@ int
raop_start(raop_t *raop, unsigned short *port) {
assert(raop);
assert(port);
logger_log(raop->logger, LOGGER_DEBUG, "using Public Key:\n%s", raop->pk_str);
return httpd_start(raop->httpd, port);
}

Expand Down
4 changes: 2 additions & 2 deletions uxplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,9 +1224,9 @@ static int register_dnssd() {
LOGE("No DNS-SD Server found (DNSServiceRegister call returned kDNSServiceErr_Unknown)");
} else if (dnssd_error == -65548) {
LOGE("DNSServiceRegister call returned kDNSServiceErr_NameConflict");
LOGE("Is another instance of %s running with the same DeviceID (MAC address) or using same network ports?",
LOGI("Is another instance of %s running with the same DeviceID (MAC address) or using same network ports?",
DEFAULT_NAME);
LOGI("\nUse options -m ... and -p ... to allow multiple instances of %s to run concurrently", DEFAULT_NAME);
LOGI("Use options -m ... and -p ... to allow multiple instances of %s to run concurrently", DEFAULT_NAME);
} else {
LOGE("dnssd_register_raop failed with error code %d\n"
"mDNS Error codes are in range FFFE FF00 (-65792) to FFFE FFFF (-65537) "
Expand Down

0 comments on commit b1c52a6

Please sign in to comment.