mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Add output fields to 'keyring add' command
This commit is contained in:
parent
735d9a42cc
commit
d2898ee22c
@ -1322,31 +1322,22 @@ int app_keyring_list(int argc, const char *const *argv, struct command_line_opti
|
|||||||
keyring_file *k = keyring_open_with_pins(pin);
|
keyring_file *k = keyring_open_with_pins(pin);
|
||||||
if (!k)
|
if (!k)
|
||||||
return -1;
|
return -1;
|
||||||
|
int cn, in;
|
||||||
int cn=0;
|
for (cn = 0; cn < k->context_count; ++cn)
|
||||||
int in=0;
|
for (in = 0; in < k->contexts[cn]->identity_count; ++in) {
|
||||||
|
const unsigned char *sid = NULL;
|
||||||
for(cn=0;cn<k->context_count;cn++)
|
const char *did = NULL;
|
||||||
for(in=0;in<k->contexts[cn]->identity_count;in++)
|
const char *name = NULL;
|
||||||
{
|
keyring_identity_extract(k->contexts[cn]->identities[in], &sid, &did, &name);
|
||||||
int kpn;
|
if (sid || did) {
|
||||||
keypair *kp;
|
if (sid) cli_printf("%s", alloca_tohex_sid(sid));
|
||||||
unsigned char *sid=NULL,*did=NULL,*name=NULL;
|
cli_delim(":");
|
||||||
for(kpn=0;kpn<k->contexts[cn]->identities[in]->keypair_count;kpn++)
|
if (did) cli_puts(did);
|
||||||
{
|
cli_delim(":");
|
||||||
kp=k->contexts[cn]->identities[in]->keypairs[kpn];
|
if (name) cli_puts(name);
|
||||||
if (kp->type==KEYTYPE_CRYPTOBOX) sid=kp->public_key;
|
cli_delim("\n");
|
||||||
if (kp->type==KEYTYPE_DID) { did=kp->private_key; name=kp->public_key; }
|
|
||||||
}
|
|
||||||
if (sid||did) {
|
|
||||||
if (sid) cli_printf("%s", alloca_tohex_sid(sid));
|
|
||||||
cli_delim(":");
|
|
||||||
if (did) cli_puts((char*)did);
|
|
||||||
cli_delim(":");
|
|
||||||
if (name) cli_puts((char*)name);
|
|
||||||
cli_delim("\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1357,10 +1348,39 @@ int app_keyring_add(int argc, const char *const *argv, struct command_line_optio
|
|||||||
keyring_file *k = keyring_open_with_pins("");
|
keyring_file *k = keyring_open_with_pins("");
|
||||||
if (!k)
|
if (!k)
|
||||||
return -1;
|
return -1;
|
||||||
if (keyring_create_identity(k,k->contexts[0],(char *)pin)==NULL)
|
const keyring_identity *id = keyring_create_identity(k, k->contexts[0], pin);
|
||||||
return WHY("Could not create new identity (keyring_create_identity() failed)");
|
if (id == NULL) {
|
||||||
if (keyring_commit(k))
|
keyring_free(k);
|
||||||
return WHY("Could not write new identity (keyring_commit() failed)");
|
return WHY("Could not create new identity");
|
||||||
|
}
|
||||||
|
const unsigned char *sid = NULL;
|
||||||
|
const char *did = "";
|
||||||
|
const char *name = "";
|
||||||
|
keyring_identity_extract(id, &sid, &did, &name);
|
||||||
|
if (!sid) {
|
||||||
|
keyring_free(k);
|
||||||
|
return WHY("New identity has no SID");
|
||||||
|
}
|
||||||
|
if (keyring_commit(k) == -1) {
|
||||||
|
keyring_free(k);
|
||||||
|
return WHY("Could not write new identity");
|
||||||
|
}
|
||||||
|
cli_puts("sid");
|
||||||
|
cli_delim(":");
|
||||||
|
cli_printf("%s", alloca_tohex_sid(sid));
|
||||||
|
cli_delim("\n");
|
||||||
|
if (did) {
|
||||||
|
cli_puts("did");
|
||||||
|
cli_delim(":");
|
||||||
|
cli_puts(did);
|
||||||
|
cli_delim("\n");
|
||||||
|
}
|
||||||
|
if (name) {
|
||||||
|
cli_puts("name");
|
||||||
|
cli_delim(":");
|
||||||
|
cli_puts(name);
|
||||||
|
cli_delim("\n");
|
||||||
|
}
|
||||||
keyring_free(k);
|
keyring_free(k);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
50
keyring.c
50
keyring.c
@ -787,8 +787,7 @@ int keyring_enter_pin(keyring_file *k, const char *pin)
|
|||||||
The crypto_box and crypto_sign key pairs are automatically created, and the PKR
|
The crypto_box and crypto_sign key pairs are automatically created, and the PKR
|
||||||
is packed and written to a hithero unallocated slot which is then marked full.
|
is packed and written to a hithero unallocated slot which is then marked full.
|
||||||
*/
|
*/
|
||||||
keyring_identity *keyring_create_identity(keyring_file *k,keyring_context *c,
|
keyring_identity *keyring_create_identity(keyring_file *k,keyring_context *c, const char *pin)
|
||||||
char *pin)
|
|
||||||
{
|
{
|
||||||
/* Check obvious abort conditions early */
|
/* Check obvious abort conditions early */
|
||||||
if (!k) { WHY("keyring is NULL"); return NULL; }
|
if (!k) { WHY("keyring is NULL"); return NULL; }
|
||||||
@ -1340,30 +1339,37 @@ unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid)
|
|||||||
RETURN(NULL);
|
RETURN(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int keyring_find_sid(const keyring_file *k,int *cn,int *in,int *kp, const unsigned char *sid)
|
int keyring_find_sid(const keyring_file *k, int *cn, int *in, int *kp, const unsigned char *sid)
|
||||||
{
|
{
|
||||||
if (keyring_sanitise_position(k,cn,in,kp)) return 0;
|
for (; !keyring_sanitise_position(k, cn, in, kp); ++*kp)
|
||||||
|
if (k->contexts[*cn]->identities[*in]->keypairs[*kp]->type == KEYTYPE_CRYPTOBOX
|
||||||
while (1) {
|
&& memcmp(sid, k->contexts[*cn]->identities[*in]->keypairs[*kp]->public_key, SID_SIZE) == 0)
|
||||||
/* we know we have a sane position, so see if it is interesting */
|
return 1;
|
||||||
|
|
||||||
if (k->contexts[*cn]->identities[*in]->keypairs[*kp]->type==KEYTYPE_CRYPTOBOX)
|
|
||||||
{
|
|
||||||
/* Compare SIDs */
|
|
||||||
if (!memcmp(sid,(char *)k->contexts[*cn]->identities[*in]
|
|
||||||
->keypairs[*kp]->public_key,SID_SIZE))
|
|
||||||
{
|
|
||||||
/* match */
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(*kp)++;
|
|
||||||
if (keyring_sanitise_position(k,cn,in,kp)) return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void keyring_identity_extract(const keyring_identity *id, const unsigned char **sidp, const char **didp, const char **namep)
|
||||||
|
{
|
||||||
|
int todo = (sidp ? 1 : 0) | (didp ? 2 : 0) || (namep ? 4 : 0);
|
||||||
|
int kpn;
|
||||||
|
for (kpn = 0; todo && kpn < id->keypair_count; ++kpn) {
|
||||||
|
keypair *kp = id->keypairs[kpn];
|
||||||
|
switch (kp->type) {
|
||||||
|
case KEYTYPE_CRYPTOBOX:
|
||||||
|
if (sidp)
|
||||||
|
*sidp = kp->public_key;
|
||||||
|
todo &= ~1;
|
||||||
|
break;
|
||||||
|
case KEYTYPE_DID:
|
||||||
|
if (didp)
|
||||||
|
*didp = (const char *) kp->private_key;
|
||||||
|
if (namep)
|
||||||
|
*namep = (const char *) kp->public_key;
|
||||||
|
todo &= ~6;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int keyring_enter_pins(keyring_file *k, const char *pinlist)
|
int keyring_enter_pins(keyring_file *k, const char *pinlist)
|
||||||
{
|
{
|
||||||
|
4
serval.h
4
serval.h
@ -263,9 +263,9 @@ unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
|
|||||||
unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid);
|
unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid);
|
||||||
|
|
||||||
int keyring_commit(keyring_file *k);
|
int keyring_commit(keyring_file *k);
|
||||||
keyring_identity *keyring_create_identity(keyring_file *k,keyring_context *c,
|
keyring_identity *keyring_create_identity(keyring_file *k,keyring_context *c, const char *pin);
|
||||||
char *pin);
|
|
||||||
int keyring_seed(keyring_file *k);
|
int keyring_seed(keyring_file *k);
|
||||||
|
void keyring_identity_extract(const keyring_identity *id, const unsigned char **sidp, const char **didp, const char **namep);
|
||||||
|
|
||||||
/* Packet format:
|
/* Packet format:
|
||||||
|
|
||||||
|
3
server.c
3
server.c
@ -490,8 +490,7 @@ int processRequest(unsigned char *packet,int len,
|
|||||||
if (debug&DEBUG_HLR) DEBUG("Verified that create request supplies DID but not SID");
|
if (debug&DEBUG_HLR) DEBUG("Verified that create request supplies DID but not SID");
|
||||||
|
|
||||||
/* Creating an identity is nice and easy now with the new keyring */
|
/* Creating an identity is nice and easy now with the new keyring */
|
||||||
keyring_identity *id=keyring_create_identity(keyring,keyring->contexts[0],
|
keyring_identity *id=keyring_create_identity(keyring,keyring->contexts[0], "");
|
||||||
"");
|
|
||||||
if (id) keyring_set_did(id,did,"Mr. Smith");
|
if (id) keyring_set_did(id,did,"Mr. Smith");
|
||||||
if (id==NULL||keyring_commit(keyring))
|
if (id==NULL||keyring_commit(keyring))
|
||||||
return respondSimple(NULL,ACTION_DECLINED,NULL,0,transaction_id,recvttl,
|
return respondSimple(NULL,ACTION_DECLINED,NULL,0,transaction_id,recvttl,
|
||||||
|
Loading…
Reference in New Issue
Block a user