mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-26 17:03:43 +02:00
Identity commands: new
This commit is contained in:
parent
68fe57decd
commit
445a246506
4 changed files with 89 additions and 3 deletions
|
@ -20,12 +20,18 @@ use num_traits::{FromPrimitive, ToPrimitive};
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use crate::capi as ztcore;
|
use crate::capi as ztcore;
|
||||||
|
|
||||||
#[derive(FromPrimitive, ToPrimitive, PartialEq, Eq)]
|
#[derive(FromPrimitive, ToPrimitive, PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum IdentityType {
|
pub enum IdentityType {
|
||||||
Curve25519 = ztcore::ZT_IdentityType_ZT_IDENTITY_TYPE_C25519 as isize,
|
Curve25519 = ztcore::ZT_IdentityType_ZT_IDENTITY_TYPE_C25519 as isize,
|
||||||
NistP384 = ztcore::ZT_IdentityType_ZT_IDENTITY_TYPE_P384 as isize,
|
NistP384 = ztcore::ZT_IdentityType_ZT_IDENTITY_TYPE_P384 as isize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToString for IdentityType {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
String::from(if *self == IdentityType::Curve25519 { "c25519" } else { "p384" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Identity {
|
pub struct Identity {
|
||||||
pub type_: IdentityType,
|
pub type_: IdentityType,
|
||||||
pub address: Address,
|
pub address: Address,
|
||||||
|
|
|
@ -199,7 +199,7 @@ pub(crate) fn parse_cli_args() -> ArgMatches<'static> {
|
||||||
.arg(Arg::with_name("member").index(1).required(true))))
|
.arg(Arg::with_name("member").index(1).required(true))))
|
||||||
.subcommand(App::new("identity")
|
.subcommand(App::new("identity")
|
||||||
.subcommand(App::new("new")
|
.subcommand(App::new("new")
|
||||||
.arg(Arg::with_name("type").possible_value("p384").possible_value("c25519").index(1)))
|
.arg(Arg::with_name("type").possible_value("p384").possible_value("c25519").default_value("c25519").index(1)))
|
||||||
.subcommand(App::new("getpublic")
|
.subcommand(App::new("getpublic")
|
||||||
.arg(Arg::with_name("identity").index(1).required(true)))
|
.arg(Arg::with_name("identity").index(1).required(true)))
|
||||||
.subcommand(App::new("fingerprint")
|
.subcommand(App::new("fingerprint")
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c)2013-2021 ZeroTier, Inc.
|
||||||
|
*
|
||||||
|
* Use of this software is governed by the Business Source License included
|
||||||
|
* in the LICENSE.TXT file in the project's root directory.
|
||||||
|
*
|
||||||
|
* Change Date: 2026-01-01
|
||||||
|
*
|
||||||
|
* On the date above, in accordance with the Business Source License, use
|
||||||
|
* of this software will be governed by version 2.0 of the Apache License.
|
||||||
|
*/
|
||||||
|
/****/
|
||||||
|
|
||||||
|
use clap::ArgMatches;
|
||||||
|
use crate::store::Store;
|
||||||
|
use zerotier_core::{IdentityType, Identity};
|
||||||
|
|
||||||
|
/*
|
||||||
|
identity <command> [args]
|
||||||
|
new [c25519 | p384] Create identity (default: c25519)
|
||||||
|
getpublic <identity> Extract public part of identity
|
||||||
|
fingerprint <identity> Get an identity's fingerprint
|
||||||
|
validate <identity> Locally validate an identity
|
||||||
|
sign <identity> <file> Sign a file with an identity's key
|
||||||
|
verify <identity> <file> <sig> Verify a signature
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
fn new_<'a>(store: &Store, cli_args: &ArgMatches<'a>) -> i32 {
|
||||||
|
let id_type = cli_args.value_of("type").map_or(IdentityType::Curve25519, |idt| {
|
||||||
|
match idt {
|
||||||
|
"p384" => IdentityType::NistP384,
|
||||||
|
_ => IdentityType::Curve25519,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let id = Identity::new_generate(id_type);
|
||||||
|
if id.is_err() {
|
||||||
|
println!("ERROR: identity generation failed: {}", id.err().unwrap().to_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
println!("{}", id.ok().unwrap().to_secret_string());
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn getpublic<'a>(store: &Store, cli_args: &ArgMatches<'a>) -> i32 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fingerprint<'a>(store: &Store, cli_args: &ArgMatches<'a>) -> i32 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate<'a>(store: &Store, cli_args: &ArgMatches<'a>) -> i32 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sign<'a>(store: &Store, cli_args: &ArgMatches<'a>) -> i32 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn verify<'a>(store: &Store, cli_args: &ArgMatches<'a>) -> i32 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn run<'a>(store: &Store, cli_args: &ArgMatches<'a>, _: &Option<String>) -> i32 {
|
||||||
|
match cli_args.subcommand() {
|
||||||
|
("new", Some(sub_cli_args)) => new_(store, sub_cli_args),
|
||||||
|
("getpublic", Some(sub_cli_args)) => getpublic(store, sub_cli_args),
|
||||||
|
("fingerprint", Some(sub_cli_args)) => fingerprint(store, sub_cli_args),
|
||||||
|
("validate", Some(sub_cli_args)) => validate(store, sub_cli_args),
|
||||||
|
("sign", Some(sub_cli_args)) => sign(store, sub_cli_args),
|
||||||
|
("verify", Some(sub_cli_args)) => verify(store, sub_cli_args),
|
||||||
|
_ => {
|
||||||
|
crate::cli::print_help();
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -101,7 +101,9 @@ fn main() {
|
||||||
process_exit_value = service::run(&store, auth_token);
|
process_exit_value = service::run(&store, auth_token);
|
||||||
}
|
}
|
||||||
("controller", Some(sub_cli_args)) => {}
|
("controller", Some(sub_cli_args)) => {}
|
||||||
("identity", Some(sub_cli_args)) => {}
|
("identity", Some(sub_cli_args)) => {
|
||||||
|
process_exit_value = crate::commands::identity::run(&store, sub_cli_args, &auth_token);
|
||||||
|
}
|
||||||
("locator", Some(sub_cli_args)) => {
|
("locator", Some(sub_cli_args)) => {
|
||||||
process_exit_value = crate::commands::locator::run(&store, sub_cli_args, &auth_token);
|
process_exit_value = crate::commands::locator::run(&store, sub_cli_args, &auth_token);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue