Skip to content

Commit 78ea2df

Browse files
authored
Merge pull request #60 from StirNetwork/feat/change_default_algo_from_ed25519_to_rsa4096
update configure gen-keys
2 parents 43037f2 + 40b5a64 commit 78ea2df

File tree

6 files changed

+54
-20
lines changed

6 files changed

+54
-20
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
hooks:
2525
- id: update-__init__.py
2626
name: Sync __init__.py with pyproject.toml
27-
entry: python ./scripts/sync_init_with_pyproject.py
27+
entry: poetry run python ./scripts/sync_init_with_pyproject.py
2828
language: python
2929
files: pyproject.toml
3030
- repo: local

fireblocks_cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# Author: Shohei KAMON <[email protected]>
66

77

8-
__version__ = "0.1.9"
8+
__version__ = "0.1.10"

fireblocks_cli/commands/configure.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,36 @@ def init():
6565

6666

6767
@configure_app.command("gen-keys")
68-
def gen_keys():
69-
"""秘密鍵とCSRを api_key_dir に生成します"""
70-
org = typer.prompt("🔐 組織名を入力してください(例: MyCompany)").strip()
68+
def gen_keys(
69+
org_name: str = typer.Option(None, help="Organization Name (CN/O)"),
70+
key_type: str = typer.Option(
71+
None, "--key-type", help="Key type: rsa:2048, rsa:4096, ed25519"
72+
),
73+
):
74+
"""Generate a pair of secret key and the CSR key"""
75+
org = typer.prompt("🔐 Organization Name:").strip()
7176
if not org:
72-
typer.secho("❌ 組織名は必須です。処理を中止します。", fg=typer.colors.RED)
77+
typer.secho("❌ Organisztion Name is required.", fg=typer.colors.RED)
7378
raise typer.Exit(code=1)
79+
if not key_type:
80+
typer.echo("Select Key Type:")
81+
typer.echo("[1] rsa:2048")
82+
typer.echo("[2] rsa:4096 (default)")
83+
typer.echo("[3] ed25519")
84+
choice = typer.prompt("Enter number (or 'y' for default)").strip().lower()
85+
if choice in ("", "y", "2"):
86+
key_type = "rsa:4096"
87+
elif choice == "1":
88+
key_type = "rsa:2048"
89+
elif choice == "3":
90+
key_type = "ed25519"
91+
else:
92+
typer.secho("❌ Invalid choice.", fg=typer.colors.RED)
93+
raise typer.Exit(code=1)
7494

75-
key_path, csr_path = generate_key_and_csr(org)
76-
typer.secho(f"✅ 秘密鍵: {key_path}", fg=typer.colors.GREEN)
77-
typer.secho(f"✅ CSR : {csr_path}", fg=typer.colors.GREEN)
95+
key_path, csr_path = generate_key_and_csr(org_name, key_type)
96+
typer.secho(f"✅ Private Key: {key_path}", fg=typer.colors.GREEN)
97+
typer.secho(f"✅ CSR Key: {csr_path}", fg=typer.colors.GREEN)
7898

7999

80100
@configure_app.command("validate")

fireblocks_cli/crypto.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,33 @@ def generate_unique_basename(base_dir: Path) -> tuple[str, Path, Path]:
2323
return basename, key_path, csr_path
2424

2525

26-
def generate_key_and_csr(org_name: str) -> tuple[Path, Path]:
26+
def generate_key_and_csr(
27+
org_name: str, key_type: str = "rsa:4096"
28+
) -> tuple[Path, Path]:
2729
api_key_dir = get_api_key_dir()
2830
api_key_dir.mkdir(parents=True, exist_ok=True)
2931

3032
basename, key_path, csr_path = generate_unique_basename(api_key_dir)
3133
subj = f"/O={org_name}"
3234

35+
# key_type: "rsa:2048", "rsa:4096", "ed25519"
36+
if key_type.startswith("rsa:"):
37+
bits = key_type.split(":")[1]
38+
key_alg = "rsa"
39+
key_args = ["-newkey", f"rsa:{bits}"]
40+
elif key_type == "ed25519":
41+
key_alg = "ed25519"
42+
key_args = ["-newkey", "ed25519"]
43+
else:
44+
typer.secho(f"❌ Unsupported key type: {key_type}", fg=typer.colors.RED)
45+
raise typer.Exit(code=1)
46+
3347
result = subprocess.run(
3448
[
3549
"openssl",
3650
"req",
3751
"-new",
38-
"-newkey",
39-
"ed25519",
52+
*key_args,
4053
"-nodes",
4154
"-keyout",
4255
str(key_path),
@@ -51,10 +64,10 @@ def generate_key_and_csr(org_name: str) -> tuple[Path, Path]:
5164
)
5265

5366
if result.returncode != 0:
54-
typer.secho("❌ OpenSSLエラー:", fg=typer.colors.RED)
67+
typer.secho("❌ OpenSSL error:", fg=typer.colors.RED)
5568
typer.echo(result.stderr)
5669
raise typer.Exit(code=1)
70+
5771
key_path.chmod(0o600)
5872
csr_path.chmod(0o600)
59-
6073
return key_path, csr_path

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[project]
88
name = "fireblocks-cli"
9-
version = "0.1.9"
9+
version = "0.1.10"
1010
description = "An unofficial CLI for managing Fireblocks services."
1111
authors = [{ name = "Kamon Shohei", email = "[email protected]" }]
1212
readme = "README.md"

scripts/sync_init_with_pyproject.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
# SPDX-License-Identifier: MPL-2.0
66
# Author: Shohei KAMON <[email protected]>
77

8-
import toml
98
import re
9+
import sys
10+
import tomllib as toml
1011

1112

1213
def update_version(
@@ -16,7 +17,7 @@ def update_version(
1617
"""pyproject.tomlのversionと__init__.pyのversionを同期する"""
1718

1819
# 1. pyproject.toml を読み込む
19-
with open(pyproject_path, "r") as f:
20+
with open(pyproject_path, "rb") as f:
2021
pyproject = toml.load(f)
2122
pyproject_version = pyproject["project"]["version"]
2223

@@ -37,7 +38,7 @@ def update_version(
3738
print(
3839
f"No update needed: {init_path} version {current_version} matches pyproject.toml version {pyproject_version}"
3940
)
40-
return
41+
return False
4142

4243
# 5. SPDXヘッダーのみ残して、後続を書き直す
4344
header = []
@@ -50,11 +51,11 @@ def update_version(
5051
# 6. ファイルを書き直す
5152
with open(init_path, "w") as f:
5253
f.writelines(header)
53-
f.write("\n")
5454
f.write(f'__version__ = "{pyproject_version}"\n')
5555

5656
print(f"Updated {init_path}: {current_version}{pyproject_version}")
5757

5858

5959
if __name__ == "__main__":
60-
update_version()
60+
changed = update_version()
61+
sys.exit(1 if changed else 0)

0 commit comments

Comments
 (0)