Skip to content

Commit

Permalink
finalize handling key role conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffgrunewald committed Jun 17, 2023
1 parent 3733fd7 commit 002dabb
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 24 deletions.
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
version: "2.4"
services:

mobile-config:
image: mobile-config:latest
build:
context: .
dockerfile: mobile_config.Dockerfile
depends_on:
- postgres
ports:
- 8090:8090
environment:
CFG__DATABASE__URL: postgres://postgres:postgres@postgres:5432/mobile_config_db
CFG__DATABASE__MAX_CONNECTIONS: 50
CFG__METADATA__URL: postgres://postgres:postgres@postgres:5432/mobile_metadata_db
CFG__METADATA__MAX_CONNECTIONS: 50
CFG__LISTEN: 0.0.0.0:8090
CFG__METRICS__ENDPOINT: 0.0.0.0:19010
CFG__ADMIN_PUBKEY: ${CONFIG_ADMIN_PUBKEY}
CFG__SIGNING_KEYPAIR: /config-signing-key.bin
CFG__LOG: debug
volumes:
- ${CONFIG_SIGNING_KEY}:/config-signing-key.bin:ro

iot-config:
image: iot-config:latest
build:
Expand Down
2 changes: 1 addition & 1 deletion iot_config.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.68 AS builder
FROM rust:1.70 AS builder

RUN apt-get update && apt-get install -y protobuf-compiler

Expand Down
35 changes: 35 additions & 0 deletions mobile_config.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM rust:1.70 as builder

RUN apt-get update && apt-get install -y protobuf-compiler

# Copy cargo file and workspace dependency crates to cache build
COPY Cargo.toml Cargo.lock ./
COPY db_store ./db_store/
COPY file_store ./file_store/
COPY metrics ./metrics/
COPY mobile_config/Cargo.toml ./mobile_config/Cargo.toml

# Enable sparse registry to avoid crates indexing infinite loop
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse

RUN mkdir ./mobile_config/src \
# Create a dummy project file to build deps around
&& echo "fn main() {}" > ./mobile_config/src/main.rs \
&& sed -i -e '/ingest/d' -e '/iot_config/d' -e '/mobile_verifier/d' \
-e '/poc_entropy/d' -e '/iot_verifier/d' -e '/price/d' \
-e '/reward_index/d' -e '/reward_scheduler/d' -e '/denylist/d' \
-e '/iot_packet_verifier/d' -e '/solana/d' -e '/mobile_packet_verifier/d' \
-e '/mobile_config_cli/d' \
Cargo.toml \
&& cargo build --package mobile-config --release

COPY mobile_config ./mobile_config/
RUN cargo build --package mobile-config --release

FROM debian:bullseye-slim

COPY --from=builder ./target/release/mobile-config /opt/mobile_config/bin/mobile-config

EXPOSE 8090

CMD ["/opt/mobile_config/bin/mobile-config", "server"]
12 changes: 8 additions & 4 deletions mobile_config_cli/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{cmds::gateway::GatewayInfo, current_timestamp, KeyRole, Result};
use crate::{cmds::gateway::GatewayInfo, current_timestamp, KeyRole, NetworkKeyRole, Result};
use base64::Engine;
use helium_crypto::{Keypair, PublicKey, Sign, Verify};
use helium_proto::{
Expand Down Expand Up @@ -94,12 +94,12 @@ impl AuthClient {
pub async fn verify(
&mut self,
pubkey: &PublicKey,
role: KeyRole,
role: NetworkKeyRole,
keypair: &Keypair,
) -> Result<bool> {
let mut request = AuthorizationVerifyReqV1 {
pubkey: pubkey.into(),
role: role.try_into()?,
role: role as i32,
signer: keypair.public_key().into(),
signature: vec![],
};
Expand All @@ -115,7 +115,11 @@ impl AuthClient {
}
}

pub async fn list(&mut self, role: KeyRole, keypair: &Keypair) -> Result<Vec<PublicKey>> {
pub async fn list(
&mut self,
role: NetworkKeyRole,
keypair: &Keypair,
) -> Result<Vec<PublicKey>> {
let mut request = AuthorizationListReqV1 {
role: role.try_into()?,
signer: keypair.public_key().into(),
Expand Down
14 changes: 8 additions & 6 deletions mobile_config_cli/src/cmds/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{cmds::env::NetworkArg, KeyRole, Result};
use crate::{cmds::env::NetworkArg, KeyRole, NetworkKeyRole, Result};
use anyhow::Context;
use clap::{Args, Parser, Subcommand};
use helium_crypto::PublicKey;
Expand Down Expand Up @@ -88,8 +88,9 @@ pub enum AuthCommands {

#[derive(Debug, Args)]
pub struct VerifyNetKey {
#[arg(value_enum)]
pub key_role: KeyRole,
#[arg(long, value_enum)]
pub key_role: NetworkKeyRole,
#[arg(long)]
pub pubkey: PublicKey,
#[arg(from_global)]
pub keypair: PathBuf,
Expand All @@ -101,8 +102,8 @@ pub struct VerifyNetKey {

#[derive(Debug, Args)]
pub struct ListNetKeys {
#[arg(value_enum)]
pub key_role: KeyRole,
#[arg(long, value_enum)]
pub key_role: NetworkKeyRole,
#[arg(from_global)]
pub keypair: PathBuf,
#[arg(from_global)]
Expand Down Expand Up @@ -189,8 +190,9 @@ pub enum AdminCommands {

#[derive(Debug, Args)]
pub struct AdminKeyArgs {
#[arg(value_enum)]
#[arg(long, value_enum)]
pub key_role: KeyRole,
#[arg(long)]
pub pubkey: PublicKey,
#[arg(from_global)]
pub keypair: PathBuf,
Expand Down
45 changes: 32 additions & 13 deletions mobile_config_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,6 @@ impl From<KeyRole> for i32 {
}
}

impl TryFrom<KeyRole> for proto::NetworkKeyRole {
type Error = &'static str;

fn try_from(value: KeyRole) -> Result<Self, Self::Error> {
let role = match value {
KeyRole::Carrier => proto::NetworkKeyRole::MobileCarrier,
KeyRole::Router => proto::NetworkKeyRole::MobileRouter,
_ => Err("invalid mobile network authorizing key role")?,
};
Ok(role)
}
}

impl Display for KeyRole {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand All @@ -121,3 +108,35 @@ impl Display for KeyRole {
}
}
}

#[derive(Debug, clap::ValueEnum, Clone, Copy, Serialize)]
pub enum NetworkKeyRole {
#[value(alias("carrier"))]
MobileCarrier,
#[value(alias("router"))]
MobileRouter,
}

impl From<NetworkKeyRole> for proto::NetworkKeyRole {
fn from(value: NetworkKeyRole) -> Self {
match value {
NetworkKeyRole::MobileRouter => Self::MobileRouter,
NetworkKeyRole::MobileCarrier => Self::MobileCarrier,
}
}
}

impl From<NetworkKeyRole> for i32 {
fn from(value: NetworkKeyRole) -> Self {
proto::NetworkKeyRole::from(value) as i32
}
}

impl Display for NetworkKeyRole {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
NetworkKeyRole::MobileCarrier => write!(f, "Carrier"),
NetworkKeyRole::MobileRouter => write!(f, "Router"),
}
}
}

0 comments on commit 002dabb

Please sign in to comment.