codeimprint 0.5.0a36__tar.gz → 0.5.0a37__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/CHANGELOG.md +18 -0
  2. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/PKG-INFO +2 -2
  3. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/README.pypi.md +1 -1
  4. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/pyproject.toml +1 -1
  5. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/__init__.py +1 -1
  6. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/cli.py +45 -32
  7. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/config.py +34 -3
  8. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/.gitignore +0 -0
  9. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/LICENSE +0 -0
  10. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/NOTICE +0 -0
  11. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint/__init__.py +0 -0
  12. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint/__main__.py +0 -0
  13. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/__main__.py +0 -0
  14. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/api.py +0 -0
  15. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/chainseal.py +0 -0
  16. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/filelist.py +0 -0
  17. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/gitrepo.py +0 -0
  18. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/imprint_file.py +0 -0
  19. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/linecount.py +0 -0
  20. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/ownership.py +0 -0
  21. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/project.py +0 -0
  22. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/receipt.py +0 -0
  23. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/records.py +0 -0
  24. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/timestamp.py +0 -0
  25. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/transparency.py +0 -0
  26. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/trust.py +0 -0
  27. {codeimprint-0.5.0a36 → codeimprint-0.5.0a37}/src/codeimprint_cli/tsa_roots.py +0 -0
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0a37 — The default server, safe URLs, and the invite-only beta [CIM-BE-60-v1]
4
+
5
+ Client only.
6
+
7
+ - **`imprint login` signs in to https://api.codeimprint.ai** when no server is saved and none
8
+ is given, without asking for a URL. `--server` (new, an alias of `--url`, on every command)
9
+ and `CODEIMPRINT_URL` override it, as does a saved server.
10
+ - **Safe URLs.** A server typed without a scheme (`api.codeimprint.ai`) gets `https://`.
11
+ Plain `http://` is refused everywhere (login, `--url`/`--server`, `CODEIMPRINT_URL`, the saved
12
+ server) except for a server on this machine: `localhost`, `127.0.0.1`, `::1`, `*.localhost`,
13
+ and `host.docker.internal` (the Docker host, seen from a container). The old "this URL is not
14
+ HTTPS" warning is gone: such a URL is no longer accepted.
15
+ - **Invite-only beta.** A sign-in the server refuses as `invite_only` now says: "CodeImprint is
16
+ invite-only during the beta. Request early access at https://app.codeimprint.ai/signup."
17
+ and never "Sent a sign-in link". Today's engine refuses once the link is used (at the
18
+ terminal's poll); when it refuses before sending the link, the client says the same at once.
19
+ - Tests: `test_default_server.py`.
20
+
3
21
  ## 0.5.0a36 — No false differences from Git's line-ending conversions [CIM-BE-59-v1]
4
22
 
5
23
  Client only; engine unchanged (0.7.0a44).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codeimprint
3
- Version: 0.5.0a36
3
+ Version: 0.5.0a37
4
4
  Summary: CodeImprint: seal your code with a CodeImprint server (tamper-evident, logged and timestamped) and verify seals offline.
5
5
  Project-URL: Homepage, https://codeimprint.ai
6
6
  Project-URL: Hub, https://app.codeimprint.ai
@@ -67,7 +67,7 @@ Windows `py -m codeimprint` works too.
67
67
  ## Get started
68
68
 
69
69
  ```bash
70
- imprint login --url https://api.codeimprint.ai # sign in (browser or e-mail link)
70
+ imprint login # sign in to https://api.codeimprint.ai (browser or e-mail link)
71
71
  imprint init # your developer key, the project and its first seal
72
72
  imprint seal . # seal the current commit
73
73
  imprint verify # check the seal offline
@@ -33,7 +33,7 @@ Windows `py -m codeimprint` works too.
33
33
  ## Get started
34
34
 
35
35
  ```bash
36
- imprint login --url https://api.codeimprint.ai # sign in (browser or e-mail link)
36
+ imprint login # sign in to https://api.codeimprint.ai (browser or e-mail link)
37
37
  imprint init # your developer key, the project and its first seal
38
38
  imprint seal . # seal the current commit
39
39
  imprint verify # check the seal offline
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
  # Published on PyPI as `codeimprint`. The import package stays `codeimprint_cli` and the
7
7
  # command `imprint`.
8
8
  name = "codeimprint"
9
- version = "0.5.0a36"
9
+ version = "0.5.0a37"
10
10
  description = "CodeImprint: seal your code with a CodeImprint server (tamper-evident, logged and timestamped) and verify seals offline."
11
11
  readme = "README.pypi.md"
12
12
  license = "Apache-2.0"
@@ -5,4 +5,4 @@ A thin client for a CodeImprint server: it zips a project, asks the server to se
5
5
  it, and verifies Imprint files offline. All analysis happens on the server.
6
6
  """
7
7
 
8
- __version__ = "0.5.0a36"
8
+ __version__ = "0.5.0a37"
@@ -557,7 +557,11 @@ def _signin(args, url: str) -> int:
557
557
  email = input("E-mail address: ").strip()
558
558
  try:
559
559
  start = client.login_start(provider, email)
560
- except (ApiError, NetworkError) as exc:
560
+ except ApiError as exc:
561
+ if exc.code == "invite_only": # refused before any link is sent
562
+ raise Abort(INVITE_ONLY) from exc
563
+ raise Abort(f"sign-in failed: {exc}") from exc
564
+ except NetworkError as exc:
561
565
  raise Abort(f"sign-in failed: {exc}") from exc
562
566
  _say(f"Code {start['user_code']} (the browser must show the same code)")
563
567
  if provider == "email":
@@ -572,6 +576,8 @@ def _signin(args, url: str) -> int:
572
576
  try:
573
577
  done = client.login_poll(start["login_id"], start["device_secret"])
574
578
  except ApiError as exc:
579
+ if exc.code == "invite_only": # a new account while the beta is invite-only
580
+ raise Abort(INVITE_ONLY) from exc
575
581
  raise Abort(f"sign-in failed: {exc.message}") from exc
576
582
  except NetworkError as exc:
577
583
  raise Abort(str(exc)) from exc
@@ -591,12 +597,18 @@ def _signin(args, url: str) -> int:
591
597
  raise Abort("the sign-in expired: run `imprint login` again")
592
598
 
593
599
 
600
+ INVITE_ONLY = ("CodeImprint is invite-only during the beta. Request early access at "
601
+ "https://app.codeimprint.ai/signup.")
602
+
603
+
594
604
  def cmd_login(args) -> int:
605
+ # 0.5.0a37: no saved server, no flag, no CODEIMPRINT_URL: CodeImprint's own, without asking.
595
606
  url = (args.url or os.environ.get("CODEIMPRINT_URL") or config.load_user_config().get("url")
596
- or (input("CodeImprint server URL: ") if not args.token_stdin else ""))
597
- url = url.strip().rstrip("/")
598
- if not url.startswith(("https://", "http://")):
599
- raise Abort("the URL must start with https:// (or http:// for a local server)")
607
+ or config.DEFAULT_URL)
608
+ try:
609
+ url = config.check_url(url)
610
+ except ValueError as exc:
611
+ raise Abort(str(exc)) from exc
600
612
  if args.cf_access:
601
613
  client_id = input("Cloudflare Access service token, Client ID: ").strip()
602
614
  client_secret = getpass.getpass("Client Secret (not shown): ").strip()
@@ -623,8 +635,6 @@ def cmd_login(args) -> int:
623
635
  _say(f"Saved {url} to {path}",
624
636
  f"Server {health.get('version', '?')}, {health.get('key_mode', '?')} key, "
625
637
  f"auth: {health.get('auth_mode', 'unknown')}")
626
- if url.startswith("http://") and "localhost" not in url and "127.0.0.1" not in url:
627
- _warn("this URL is not HTTPS: your code and token would travel unencrypted")
628
638
  return 0
629
639
 
630
640
 
@@ -3612,7 +3622,10 @@ def build_parser() -> argparse.ArgumentParser:
3612
3622
  sub = p.add_subparsers(dest="command", required=True)
3613
3623
 
3614
3624
  lg = sub.add_parser("login", help="sign in (browser or e-mail link), or save an API token")
3615
- lg.add_argument("--url", help="server URL, for example https://imprint.example.com")
3625
+ lg.add_argument("--url", "--server",
3626
+ help=f"server URL (default: the saved one, CODEIMPRINT_URL, else "
3627
+ f"{config.DEFAULT_URL}); https:// is added when no scheme is given, "
3628
+ "and plain http:// is only for a server on this machine")
3616
3629
  lg.add_argument("--provider", choices=["github", "gitlab", "google", "microsoft", "email"],
3617
3630
  help="sign in with this provider (default: the first one the server offers)")
3618
3631
  lg.add_argument("--email", help="your address, for --provider email")
@@ -3638,7 +3651,7 @@ def build_parser() -> argparse.ArgumentParser:
3638
3651
  "seals this repository")
3639
3652
  n.add_argument("--no-key", action="store_true", help="do not create a developer key")
3640
3653
  n.add_argument("--force", action="store_true", help="overwrite files that already exist")
3641
- n.add_argument("--url", help="server URL for creating the project (else login or "
3654
+ n.add_argument("--url", "--server", help="server URL for creating the project (else login or "
3642
3655
  "CODEIMPRINT_URL)")
3643
3656
  n.add_argument("--no-project", action="store_true",
3644
3657
  help="do not create the project and its genesis seal now")
@@ -3666,14 +3679,14 @@ def build_parser() -> argparse.ArgumentParser:
3666
3679
  ky.add_argument("--label", help="request: a name for this device, shown to whoever "
3667
3680
  "approves (default: the computer's name)")
3668
3681
  ky.add_argument("--yes", action="store_true", help="approve, retire: do not ask")
3669
- ky.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3682
+ ky.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3670
3683
  ky.set_defaults(func=cmd_key)
3671
3684
 
3672
3685
  pl = sub.add_parser("plan", help="your plan, its status and usage (read-only; buy or "
3673
3686
  "change it on the hub's billing page)")
3674
3687
  pl.add_argument("--org", help="an organisation you administer, by its ID")
3675
3688
  pl.add_argument("--json", action="store_true", help="the server's answer as JSON")
3676
- pl.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3689
+ pl.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3677
3690
  pl.set_defaults(func=cmd_plan)
3678
3691
 
3679
3692
  tk = sub.add_parser("token", help="CI tokens for automated builds (CODEIMPRINT_TOKEN): "
@@ -3686,7 +3699,7 @@ def build_parser() -> argparse.ArgumentParser:
3686
3699
  help="create: how long the token lasts, 1 to 365 (default 90)")
3687
3700
  tk.add_argument("--label", help="create: a name for you, for example where it is kept")
3688
3701
  tk.add_argument("--json", action="store_true", help="list: as JSON")
3689
- tk.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3702
+ tk.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3690
3703
  tk.set_defaults(func=cmd_token)
3691
3704
 
3692
3705
  pj = sub.add_parser("project", help="the project: rename it, record that its "
@@ -3707,7 +3720,7 @@ def build_parser() -> argparse.ArgumentParser:
3707
3720
  "and GitHub App connection move there")
3708
3721
  pj.add_argument("--reason", help="archive: a note for you (at most 200 characters)")
3709
3722
  pj.add_argument("--yes", action="store_true", help="archive: do not ask")
3710
- pj.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3723
+ pj.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3711
3724
  pj.set_defaults(func=cmd_project)
3712
3725
 
3713
3726
  en = sub.add_parser("engagement", help="work with a vendor or a client: create, list, show, "
@@ -3726,7 +3739,7 @@ def build_parser() -> argparse.ArgumentParser:
3726
3739
  help="end: the seal marked as handed over (default: the vendor's latest)")
3727
3740
  en.add_argument("--no-handover", action="store_true", help="end: no handover marker")
3728
3741
  en.add_argument("--json", action="store_true")
3729
- en.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3742
+ en.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3730
3743
  en.set_defaults(func=cmd_engagement)
3731
3744
 
3732
3745
  dl = sub.add_parser("deliver", help="deliver a seal: to the project's owner (engagement "
@@ -3736,12 +3749,12 @@ def build_parser() -> argparse.ArgumentParser:
3736
3749
  dl.add_argument("--to-client", action="store_true",
3737
3750
  help="vendor-led: e-mail your client a link to accept it")
3738
3751
  dl.add_argument("--engagement", help="--to-client: which engagement, when there are several")
3739
- dl.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3752
+ dl.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3740
3753
  dl.set_defaults(func=cmd_deliver)
3741
3754
 
3742
3755
  ac = sub.add_parser("accept", help="accept a seal your vendor delivered (project owner)")
3743
3756
  ac.add_argument("seal", metavar="IMP1_ID")
3744
- ac.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3757
+ ac.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3745
3758
  ac.set_defaults(func=cmd_accept)
3746
3759
 
3747
3760
  gh = sub.add_parser("github", help="the GitHub App: link this repository's project to your "
@@ -3752,7 +3765,7 @@ def build_parser() -> argparse.ArgumentParser:
3752
3765
  gh.add_argument("--project", help="your existing project to attach (default: "
3753
3766
  ".imprint/config.json, else the App's project)")
3754
3767
  gh.add_argument("--yes", action="store_true", help="sign without asking")
3755
- gh.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3768
+ gh.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3756
3769
  gh.set_defaults(func=cmd_github)
3757
3770
 
3758
3771
  s = sub.add_parser("seal", help="seal a project on the server; saves .imprint/baseline.imprint "
@@ -3762,7 +3775,7 @@ def build_parser() -> argparse.ArgumentParser:
3762
3775
  s.add_argument("--hub-url", help="hub for the verify link and badge (default: "
3763
3776
  "CODEIMPRINT_HUB_URL, else the hub the server names)")
3764
3777
  s.add_argument("-o", "--output", help="where to save the Imprint")
3765
- s.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3778
+ s.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3766
3779
  s.add_argument("--yes", action="store_true", help="do not ask before uploading (CI)")
3767
3780
  s.add_argument("--tsa-certs", metavar="FILE",
3768
3781
  help="also trust the time-stamping authorities in this PEM bundle")
@@ -3787,7 +3800,7 @@ def build_parser() -> argparse.ArgumentParser:
3787
3800
  ch = sub.add_parser("chain", help="show the project's chain (server, plus this clone's commits)")
3788
3801
  ch.add_argument("path", nargs="?", default=".")
3789
3802
  ch.add_argument("--project", help="project ID (default: .imprint/config.json)")
3790
- ch.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3803
+ ch.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3791
3804
  ch.set_defaults(func=cmd_chain)
3792
3805
 
3793
3806
  idn = sub.add_parser("identity", help="your developer key's verified identity: show, bind, "
@@ -3803,7 +3816,7 @@ def build_parser() -> argparse.ArgumentParser:
3803
3816
  idn.add_argument("--compromised-since", metavar="TIME",
3804
3817
  help="revoke --reason key-compromised: UTC time, e.g. 2026-11-01T12:00:00Z")
3805
3818
  idn.add_argument("--key", help="show: another key's fingerprint")
3806
- idn.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3819
+ idn.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3807
3820
  idn.set_defaults(func=cmd_identity)
3808
3821
 
3809
3822
  cl = sub.add_parser("claim", help="ownership claims: create, show, withdraw, add-key, "
@@ -3829,7 +3842,7 @@ def build_parser() -> argparse.ArgumentParser:
3829
3842
  cl.add_argument("--key", help="retire-key: the key's fingerprint")
3830
3843
  cl.add_argument("--project", help="project ID (default: .imprint/config.json)")
3831
3844
  cl.add_argument("--path", default=".", help="the project folder (default: .)")
3832
- cl.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3845
+ cl.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3833
3846
  cl.add_argument("--yes", action="store_true", help="do not ask before signing")
3834
3847
  cl.set_defaults(func=cmd_claim)
3835
3848
 
@@ -3845,7 +3858,7 @@ def build_parser() -> argparse.ArgumentParser:
3845
3858
  asg.add_argument("--complete", metavar="FILE", help="add your signature to a file the "
3846
3859
  "other side wrote, and submit it")
3847
3860
  asg.add_argument("-o", "--output", help="where to write a half-signed assignment")
3848
- asg.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3861
+ asg.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3849
3862
  asg.add_argument("--yes", action="store_true", help="do not ask before submitting")
3850
3863
  asg.set_defaults(func=cmd_assign)
3851
3864
 
@@ -3855,7 +3868,7 @@ def build_parser() -> argparse.ArgumentParser:
3855
3868
  own.add_argument("path", nargs="?", default=".")
3856
3869
  own.add_argument("--project", help="project ID (default: .imprint/config.json)")
3857
3870
  own.add_argument("--json", action="store_true")
3858
- own.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3871
+ own.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3859
3872
  own.set_defaults(func=cmd_ownership)
3860
3873
 
3861
3874
  og = sub.add_parser("org", help="organisations: create, show, domain, verify, disclose, join, "
@@ -3872,7 +3885,7 @@ def build_parser() -> argparse.ArgumentParser:
3872
3885
  og.add_argument("--also-sign", action="append", metavar="KEYFILE",
3873
3886
  help="join: the admin key (PEM), if you hold it")
3874
3887
  og.add_argument("-o", "--output", help="join: where to write the membership for the admin")
3875
- og.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3888
+ og.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3876
3889
  og.add_argument("--yes", action="store_true", help="do not ask before signing")
3877
3890
  og.set_defaults(func=cmd_org)
3878
3891
 
@@ -3898,7 +3911,7 @@ def build_parser() -> argparse.ArgumentParser:
3898
3911
  ct.add_argument("-o", "--output", help="where to write a half-signed record")
3899
3912
  ct.add_argument("--project", help="project ID (default: .imprint/config.json)")
3900
3913
  ct.add_argument("--path", default=".", help="the project folder (default: .)")
3901
- ct.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3914
+ ct.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3902
3915
  ct.add_argument("--yes", action="store_true", help="do not ask before submitting")
3903
3916
  ct.set_defaults(func=cmd_contributor)
3904
3917
 
@@ -3906,7 +3919,7 @@ def build_parser() -> argparse.ArgumentParser:
3906
3919
  ex.add_argument("imprint_id")
3907
3920
  ex.add_argument("path", nargs="?", default=".")
3908
3921
  ex.add_argument("-o", "--output", help="where to save it (default <ID>.full.imprint)")
3909
- ex.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3922
+ ex.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3910
3923
  ex.set_defaults(func=cmd_export)
3911
3924
 
3912
3925
 
@@ -3917,7 +3930,7 @@ def build_parser() -> argparse.ArgumentParser:
3917
3930
  help=f"exit 1 when the score reaches this value (default {DEFAULT_FAIL_ABOVE})")
3918
3931
  c.add_argument("--format", choices=["text", "json"], default="text")
3919
3932
  c.add_argument("-o", "--output", help="also write the JSON result to this file")
3920
- c.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3933
+ c.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3921
3934
  c.add_argument("--yes", action="store_true", help="do not ask before uploading (CI)")
3922
3935
  c.add_argument("--files", action="store_true",
3923
3936
  help="compare every file with a seal's file list, hashed here; nothing is "
@@ -3943,7 +3956,7 @@ def build_parser() -> argparse.ArgumentParser:
3943
3956
  pv.add_argument("--seal", help="the seal (default: this folder's baseline)")
3944
3957
  pv.add_argument("--root", default=".", help="the sealed folder (default: here)")
3945
3958
  pv.add_argument("-o", "--output", help="where to write it (default <name>.proof.json)")
3946
- pv.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3959
+ pv.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
3947
3960
  pv.add_argument("--export", metavar="PATH",
3948
3961
  help="also write the exact sealed bytes of the file (from Git, at the "
3949
3962
  "sealed commit) to PATH, for the other party to verify")
@@ -3961,7 +3974,7 @@ def build_parser() -> argparse.ArgumentParser:
3961
3974
  vf.add_argument("--proof", required=True, help="the proof (from `imprint prove`)")
3962
3975
  vf.add_argument("--keys", metavar="FILE",
3963
3976
  help="trust only these server keys (a codeimprint-keys.json)")
3964
- vf.add_argument("--url", help="the server (default: the one the proof names)")
3977
+ vf.add_argument("--url", "--server", help="the server (default: the one the proof names)")
3965
3978
  vf.add_argument("--tsa-certs", metavar="FILE",
3966
3979
  help="also trust the time-stamping authorities in this PEM bundle")
3967
3980
  vf.add_argument("--json", action="store_true")
@@ -3986,7 +3999,7 @@ def build_parser() -> argparse.ArgumentParser:
3986
3999
  v.add_argument("--online", action="store_true",
3987
4000
  help="also check the server's live log (consistency, order, registry)")
3988
4001
  v.add_argument("--project", help="where to look for receipts when given an ID")
3989
- v.add_argument("--url", help="server URL for --online")
4002
+ v.add_argument("--url", "--server", help="server URL for --online")
3990
4003
  v.add_argument("--tsa-certs", metavar="FILE",
3991
4004
  help="also trust the time-stamping authorities in this PEM bundle")
3992
4005
  v.add_argument("--opening", metavar="FILE",
@@ -4004,7 +4017,7 @@ def build_parser() -> argparse.ArgumentParser:
4004
4017
  help="save the record (and its opening, when shown to you) to verify "
4005
4018
  "offline with `imprint verify FILE`")
4006
4019
  ln.add_argument("--json", action="store_true")
4007
- ln.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
4020
+ ln.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
4008
4021
  ln.set_defaults(func=cmd_lineage)
4009
4022
 
4010
4023
  ce = sub.add_parser("certificate", help="download a seal's certificate (PDF): for the "
@@ -4012,7 +4025,7 @@ def build_parser() -> argparse.ArgumentParser:
4012
4025
  ce.add_argument("seal", metavar="FINGERPRINT_ID", help="the seal's ID (IMP1-…)")
4013
4026
  ce.add_argument("-o", "--out", metavar="FILE",
4014
4027
  help="where to save it (default: certificate-<ID>.pdf in this folder)")
4015
- ce.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
4028
+ ce.add_argument("--url", "--server", help="server URL (overrides login and CODEIMPRINT_URL)")
4016
4029
  ce.set_defaults(func=cmd_certificate)
4017
4030
  return p
4018
4031
 
@@ -1,8 +1,13 @@
1
1
  # SPDX-License-Identifier: Apache-2.0
2
2
  """Where the client keeps the server URL and token, and how settings are resolved.
3
3
 
4
- Order: command-line flag, then environment (CODEIMPRINT_URL, CODEIMPRINT_TOKEN), then the
5
- user config file written by `imprint login`.
4
+ Order: command-line flag (`--url`, or its alias `--server`), then environment
5
+ (CODEIMPRINT_URL, CODEIMPRINT_TOKEN), then the user config file written by `imprint login`.
6
+ `imprint login` with none of them signs in to CodeImprint's own server, DEFAULT_URL.
7
+
8
+ A URL without a scheme gets ``https://``. Plain ``http://`` is refused except for a server on
9
+ this machine (``localhost``, ``127.0.0.1``, ``::1``, ``*.localhost``, or the Docker host from a
10
+ container, ``host.docker.internal``): a token must never travel unencrypted.
6
11
 
7
12
  A server behind **Cloudflare Access** (a development lock) also needs a service token: the
8
13
  ``CF-Access-Client-Id`` and ``CF-Access-Client-Secret`` headers. They come from
@@ -99,6 +104,32 @@ def session_expired(url: str) -> bool:
99
104
 
100
105
 
101
106
  LOOPBACK = {"localhost", "127.0.0.1", "::1"}
107
+ DEFAULT_URL = "https://api.codeimprint.ai"
108
+ LOCAL_HTTP = LOOPBACK | {"host.docker.internal"}
109
+
110
+
111
+ def local_host(host: str | None) -> bool:
112
+ """A server on this machine, where plain HTTP is allowed."""
113
+ host = (host or "").lower()
114
+ return host in LOCAL_HTTP or host.endswith(".localhost")
115
+
116
+
117
+ def check_url(text: str) -> str:
118
+ """A server URL as typed, made safe: ``https://`` added when there is no scheme, the
119
+ trailing slash removed; plain HTTP only for a server on this machine (ValueError)."""
120
+ url = (text or "").strip()
121
+ if not url:
122
+ raise ValueError("no server URL")
123
+ if "://" not in url:
124
+ url = "https://" + url
125
+ url = url.rstrip("/")
126
+ parts = urlparse(url)
127
+ if parts.scheme not in ("https", "http") or not parts.hostname:
128
+ raise ValueError(f"not a server URL: {text.strip()}")
129
+ if parts.scheme == "http" and not local_host(parts.hostname):
130
+ raise ValueError(f"plain http:// is allowed only for a server on this machine "
131
+ f"(localhost): use https://{url.split('://', 1)[1]}")
132
+ return url
102
133
 
103
134
 
104
135
  def _host(url: str | None) -> str | None:
@@ -185,4 +216,4 @@ def resolve(url_flag: str | None = None) -> Settings:
185
216
  stored = load_user_config()
186
217
  url = url_flag or os.environ.get("CODEIMPRINT_URL") or stored.get("url")
187
218
  token = os.environ.get("CODEIMPRINT_TOKEN") or stored.get("token")
188
- return Settings(url=url.rstrip("/") if url else None, token=token or None)
219
+ return Settings(url=check_url(url) if url else None, token=token or None)
File without changes
File without changes