navid/veins / commit
a01b6805cc14
Navid M <navidmomtahen@gmail.com> · 2026-11-26
parents: fbccfbdb04ba
Browse files at this commit · Download source
--- /dev/null+++ b/veins/src/auth/credentials.sx@@ -0,0 +1,375 @@+/// Per-user native-protocol credentials.+///+/// Key names are stored as one small file per target under `.../veins/auth/`.+/// The directory never contains private key material. `default` is the global+/// fallback; other entries are host or host:port names.+///+/// Resolution order in commands is: explicit `-key:`, repository remote key,+/// then this directory (host, host without port, default).++val str = use("std/string")+val bytes = use("../core/bytes.sx")+val lists = use("../core/lists.sx")+val files = use("../io/files.sx")+val keys = use("keys.sx")++fn trim(b: bytes.Bytes) bytes.Bytes = trust {+ val start: mut usize = 0+ val end: mut usize = b.len+ for start < end {+ val c: u8 = bytes.Bytes.at(b, start)+ if c != 32 && c != 9 && c != 13 && c != 10 {+ break+ }+ start+++ }+ for end > start {+ val c2: u8 = bytes.Bytes.at(b, end - 1)+ if c2 != 32 && c2 != 9 && c2 != 13 && c2 != 10 {+ break+ }+ end--+ }+ return bytes.Bytes.slice(b, start, end)+}++fn lower(b: bytes.Bytes) bytes.Bytes = trust {+ val out: ref u8 = @alloc(b.len) as ref u8+ val i: mut usize = 0+ for i < b.len {+ val c: u8 = bytes.Bytes.at(b, i)+ if c >= 65 && c <= 90 {+ @store8(@ptradd(out, i as i64), (c + 32) as u8)+ } else {+ @store8(@ptradd(out, i as i64), c)+ }+ i+++ }+ return bytes.bytes(out, b.len)+}++fn find_from(hay: bytes.Bytes, needle: bytes.Bytes, from: usize) i64 = trust {+ if needle.len == 0 || needle.len > hay.len {+ return -1+ }+ val i: mut usize = from+ for i <= hay.len - needle.len {+ if bytes.Bytes.eql(bytes.Bytes.slice(hay, i, i + needle.len), needle) {+ return i as i64+ }+ i+++ }+ return -1+}++fn auth_dir() bytes.Bytes = trust {+ val dir: bytes.Bytes = keys.key_dir()+ val last: mut i64 = -1+ val i: mut usize = 0+ for i < dir.len {+ if bytes.Bytes.at(dir, i) == 47 {+ last = i as i64+ }+ i+++ }+ if last <= 0 {+ bytes.free_owned(dir)+ return bytes.Bytes.dup(bytes.bytes(c".veins-auth", 11))+ }+ val base: bytes.Bytes = bytes.Bytes.slice(dir, 0, last as usize)+ val joined: str.StringView = files.join(files.to_view(base), str.from_cstr(c"auth"))+ val out: bytes.Bytes = bytes.Bytes.dup(bytes.bytes(joined.ptr, joined.len))+ files.free_path(joined)+ bytes.free_owned(dir)+ return out+}++fn hex_char(v: u8) u8 = {+ if v < 10 {+ return (48 + v) as u8+ }+ return (87 + v) as u8+}++fn hex_encode(b: bytes.Bytes) bytes.Bytes = trust {+ val out: ref u8 = @alloc(b.len * 2) as ref u8+ val i: mut usize = 0+ for i < b.len {+ val c: u8 = bytes.Bytes.at(b, i)+ @store8(@ptradd(out, (i * 2) as i64), hex_char(c >> 4))+ @store8(@ptradd(out, (i * 2 + 1) as i64), hex_char(c & 15))+ i+++ }+ return bytes.bytes(out, b.len * 2)+}++fn hex_value(c: u8) i32 = {+ if c >= 48 && c <= 57 {+ return (c - 48) as i32+ }+ if c >= 97 && c <= 102 {+ return (c - 87) as i32+ }+ return -1+}++fn hex_decode(b: bytes.Bytes) option[bytes.Bytes] = trust {+ if b.len == 0 || b.len % 2 != 0 {+ return none+ }+ val out: ref u8 = @alloc(b.len / 2) as ref u8+ val i: mut usize = 0+ for i < b.len / 2 {+ val hi: i32 = hex_value(bytes.Bytes.at(b, i * 2))+ val lo: i32 = hex_value(bytes.Bytes.at(b, i * 2 + 1))+ if hi < 0 || lo < 0 {+ @free(out as ref void)+ return none+ }+ @store8(@ptradd(out, i as i64), ((hi << 4) | lo) as u8)+ i+++ }+ return some bytes.bytes(out, b.len / 2)+}++fn target_path(dir: bytes.Bytes, target: bytes.Bytes) bytes.Bytes = trust {+ val encoded: bytes.Bytes = hex_encode(target)+ val joined: str.StringView = files.join(files.to_view(dir), files.to_view(encoded))+ val out: bytes.Bytes = bytes.Bytes.dup(bytes.bytes(joined.ptr, joined.len))+ files.free_path(joined)+ bytes.free_owned(encoded)+ return out+}++fn read_key(path: bytes.Bytes) option[bytes.Bytes] = trust {+ val data_opt = files.read_all(files.to_view(path))+ val data: mut bytes.Bytes = bytes.empty()+ match data_opt {+ some d => {+ data = d+ }+ none => {+ return none+ }+ }+ val value: bytes.Bytes = trim(data)+ if value.len == 0 {+ files.free_buffer(data)+ return none+ }+ val out: bytes.Bytes = bytes.Bytes.dup(value)+ files.free_buffer(data)+ return some out+}++fn lookup(dir: bytes.Bytes, target: bytes.Bytes) option[bytes.Bytes] = trust {+ val path: bytes.Bytes = target_path(dir, target)+ val out = read_key(path)+ bytes.free_owned(path)+ return out+}++fn strip_authority_user(authority: bytes.Bytes) bytes.Bytes = trust {+ val last: mut i64 = -1+ val i: mut usize = 0+ for i < authority.len {+ if bytes.Bytes.at(authority, i) == 64 {+ last = i as i64+ }+ i+++ }+ if last >= 0 {+ return bytes.Bytes.slice(authority, (last as usize) + 1, authority.len)+ }+ return authority+}++fn authority_of(input: bytes.Bytes) option[bytes.Bytes] = trust {+ val scheme: i64 = find_from(input, bytes.bytes(c"://", 3), 0)+ val start: mut usize = 0+ if scheme >= 0 {+ start = (scheme as usize) + 3+ }+ if start >= input.len {+ return none+ }+ val slash: i64 = find_from(input, bytes.bytes(c"/", 1), start)+ val end: mut usize = input.len+ if slash >= 0 {+ end = slash as usize+ }+ if end <= start {+ return none+ }+ val raw: bytes.Bytes = bytes.Bytes.slice(input, start, end)+ val host: bytes.Bytes = strip_authority_user(raw)+ if host.len == 0 {+ return none+ }+ return some lower(host)+}++/// Normalize an auth target. `default` is the global fallback; otherwise the+/// target is a host or host:port extracted from a URL when necessary.+pub fn normalize_target(input: bytes.Bytes) bytes.Bytes = trust {+ val t: bytes.Bytes = trim(input)+ if t.len == 0 || bytes.Bytes.eql(t, bytes.bytes(c"default", 7)) {+ return bytes.Bytes.dup(bytes.bytes(c"default", 7))+ }+ val auth = authority_of(t)+ if auth is some a {+ val out: bytes.Bytes = bytes.Bytes.dup(a)+ bytes.free_owned(a)+ return out+ }+ val slash: i64 = find_from(t, bytes.bytes(c"/", 1), 0)+ val end: mut usize = t.len+ if slash >= 0 {+ end = slash as usize+ }+ val raw: bytes.Bytes = bytes.Bytes.slice(t, 0, end)+ val host: bytes.Bytes = strip_authority_user(raw)+ if host.len == 0 {+ return bytes.Bytes.dup(bytes.bytes(c"default", 7))+ }+ return lower(host)+}++/// Store or replace a key mapping.+pub fn set_key(target: bytes.Bytes, name: bytes.Bytes) bool = trust {+ if target.len == 0 || name.len == 0 {+ return false+ }+ val dir: bytes.Bytes = auth_dir()+ if !files.exists_dir(files.to_view(dir)) {+ if !files.mkdir_all(files.to_view(dir)) {+ bytes.free_owned(dir)+ return false+ }+ }+ val path: bytes.Bytes = target_path(dir, target)+ val passed: bool = files.write_all(files.to_view(path), name)+ bytes.free_owned(path)+ bytes.free_owned(dir)+ return passed+}++pub fn remove_key(target: bytes.Bytes) bool = trust {+ val dir: bytes.Bytes = auth_dir()+ val path: bytes.Bytes = target_path(dir, target)+ val removed: bool = files.delete(files.to_view(path))+ bytes.free_owned(path)+ bytes.free_owned(dir)+ return removed+}++pub fn list_lines() list[bytes.Bytes] = trust {+ val out: mut list[bytes.Bytes] = lists.new[bytes.Bytes]()+ val dir: bytes.Bytes = auth_dir()+ if !files.exists_dir(files.to_view(dir)) {+ bytes.free_owned(dir)+ return out+ }+ val names: list[ref u8] = files.list_dir(files.to_view(dir))+ for n in names {+ val encoded: bytes.Bytes = bytes.from_cstr(n)+ val decoded = hex_decode(encoded)+ if decoded is some target {+ val path: bytes.Bytes = target_path(dir, target)+ val key_opt = read_key(path)+ bytes.free_owned(path)+ if key_opt is some key {+ val line: ref u8 = @fmtalloc("{s}: {s}\n", {+ str.view(target.ptr, target.len as i64),+ str.view(key.ptr, key.len as i64)+ })+ @append(out, bytes.Bytes.dup(bytes.from_cstr(line)))+ @free(line as ref void)+ bytes.free_owned(key)+ }+ bytes.free_owned(target)+ }+ }+ files.free_names(names)+ bytes.free_owned(dir)+ return out+}++fn host_without_port(host: bytes.Bytes) option[bytes.Bytes] = trust {+ if host.len == 0 || bytes.Bytes.at(host, 0) == 91 {+ return none+ }+ val last: mut i64 = -1+ val i: mut usize = 0+ for i < host.len {+ if bytes.Bytes.at(host, i) == 58 {+ last = i as i64+ }+ i+++ }+ if last <= 0 {+ return none+ }+ return some bytes.Bytes.slice(host, 0, last as usize)+}++/// Resolve the key for a native URL: host:port, then host, then default.+pub fn key_for_url(url: bytes.Bytes) option[bytes.Bytes] = trust {+ val dir: bytes.Bytes = auth_dir()+ val host_opt = authority_of(url)+ if host_opt is some host {+ val exact = lookup(dir, host)+ if exact is some k {+ bytes.free_owned(host)+ bytes.free_owned(dir)+ return some k+ }+ val no_port = host_without_port(host)+ if no_port is some h {+ val base = lookup(dir, h)+ if base is some k {+ bytes.free_owned(host)+ bytes.free_owned(dir)+ return some k+ }+ }+ bytes.free_owned(host)+ }+ val fallback = lookup(dir, bytes.bytes(c"default", 7))+ bytes.free_owned(dir)+ if fallback is some k {+ return some k+ }+ return none+}++test "auth targets normalize hosts and URLs" {+ trust {+ val a: bytes.Bytes = normalize_target(bytes.bytes(+ c"veins://User@Forge.Example.com:7419/alice/repo",+ 46+ ))+ assert bytes.Bytes.eql(a, bytes.bytes(c"forge.example.com:7419", 22))+ bytes.free_owned(a)+ val b: bytes.Bytes = normalize_target(bytes.bytes(c"ssh://git@Example.com:22/x", 26))+ assert bytes.Bytes.eql(b, bytes.bytes(c"example.com:22", 14))+ bytes.free_owned(b)+ val c: bytes.Bytes = normalize_target(bytes.bytes(c"default", 7))+ assert bytes.Bytes.eql(c, bytes.bytes(c"default", 7))+ bytes.free_owned(c)+ }+}++test "auth target hex round trip" {+ trust {+ val a: bytes.Bytes = hex_encode(bytes.bytes(c"forge.example.com:7419", 22))+ val b = hex_decode(a)+ if b is some raw {+ assert bytes.Bytes.eql(raw, bytes.bytes(c"forge.example.com:7419", 22))+ bytes.free_owned(raw)+ } else {+ assert false+ }+ bytes.free_owned(a)+ }+}--- /dev/null+++ b/veins/src/cli/auth_cmd.sx@@ -0,0 +1,114 @@+/// `vn auth`: remember which Ed25519 key to use for a host or by default.++val stdio = use("std/stdio")+val str = use("std/string")+val bytes = use("../core/bytes.sx")+val keys = use("../auth/keys.sx")+val credentials = use("../auth/credentials.sx")+val cmsg = use("../core/msg.sx")++fn usage() void = trust {+ stdio.eprint("usage: vn auth <use|list|remove> ...\n", {})+ stdio.eprint(" vn auth use <key> [<host|url>] set the default or host key\n", {})+ stdio.eprint(" vn auth list show stored key mappings\n", {})+ stdio.eprint(" vn auth remove [<host|url>] remove a mapping (default if omitted)\n", {})+}++fn arg(args: list[ref u8], i: usize) bytes.Bytes = trust {+ val o = @get(args, i)+ if o is some v {+ return bytes.from_cstr(v)+ }+ return bytes.empty()+}++pub fn run(args: list[ref u8], start: usize) i32 = trust {+ val sub_opt = @get(args, start)+ if sub_opt is none {+ usage()+ return 1+ }+ val sub: mut ref u8 = none+ match sub_opt {+ some s => {+ sub = s+ }+ none => {+ return 1+ }+ }+ if @strcmp(sub, c"use") == 0 {+ val name: bytes.Bytes = arg(args, start + 1)+ if name.len == 0 {+ usage()+ return 1+ }+ val key_opt = keys.load(name)+ if key_opt is none {+ cmsg.error_prefix()+ stdio.eprint("key not found or has unsafe permissions: {s}\n", {+ str.view(name.ptr, name.len as i64)+ })+ return 1+ }+ match key_opt {+ some k => {+ keys.free_key(k)+ }+ none => {+ return 1+ }+ }+ val target: bytes.Bytes = credentials.normalize_target(arg(args, start + 2))+ val passed: bool = credentials.set_key(target, name)+ if passed {+ if bytes.Bytes.eql(target, bytes.bytes(c"default", 7)) {+ stdio.print("default key set to {s}\n", {str.view(name.ptr, name.len as i64)})+ } else {+ stdio.print("key for {s} set to {s}\n", {+ str.view(target.ptr, target.len as i64),+ str.view(name.ptr, name.len as i64)+ })+ }+ } else {+ cmsg.error_prefix()+ stdio.eprint("cannot write auth configuration\n", {})+ }+ bytes.free_owned(target)+ if passed {+ return 0+ }+ return 1+ }+ if @strcmp(sub, c"list") == 0 {+ val lines: list[bytes.Bytes] = credentials.list_lines()+ if @len(lines) == 0 {+ stdio.print("no stored credentials\n", {})+ }+ for line in lines {+ stdio.print("{s}", {str.view(line.ptr, line.len as i64)})+ bytes.free_owned(line)+ }+ @listfree(lines)+ return 0+ }+ if @strcmp(sub, c"remove") == 0 {+ val target: bytes.Bytes = credentials.normalize_target(arg(args, start + 1))+ val removed: bool = credentials.remove_key(target)+ if removed {+ stdio.print("removed {s}\n", {str.view(target.ptr, target.len as i64)})+ } else {+ cmsg.error_prefix()+ stdio.eprint("no credential for {s}\n", {str.view(target.ptr, target.len as i64)})+ }+ bytes.free_owned(target)+ if removed {+ return 0+ }+ return 1+ }+ cmsg.error_prefix()+ stdio.eprint("unknown auth subcommand: {s}\n", {str.from_cstr(sub)})+ usage()+ return 1+}--- a/veins/src/cli/clone_cmd.sx+++ b/veins/src/cli/clone_cmd.sx@@ -10,6 +10,7 @@ val files = use("../io/files.sx") val config = use("../core/repoconfig.sx") val remote_config = use("../git/remote.sx")+val credentials = use("../auth/credentials.sx") val client = use("../protocol/client.sx") val msg_refs = use("../protocol/messages.sx") val transfer = use("../protocol/transfer.sx")@@ -91,9 +92,9 @@ cmsg.error_prefix() if detail.len > 0 { stdio.eprint("{s}: {s}\n", {- str.view(context.ptr, context.len as i64),- str.view(detail.ptr, detail.len as i64)- })+ str.view(context.ptr, context.len as i64),+ str.view(detail.ptr, detail.len as i64)+ }) } else { stdio.eprint("{s}\n", {str.view(context.ptr, context.len as i64)}) }@@ -105,6 +106,7 @@ val path: mut bytes.Bytes = bytes.empty() val policy: mut bytes.Bytes = bytes.bytes(c"head", 4) val key_name: mut bytes.Bytes = bytes.empty()+ val key_explicit: mut bool = false val tls_pin: mut bytes.Bytes = bytes.empty() val i: mut usize = start for i < @len(args) {@@ -115,6 +117,7 @@ policy = bytes.Bytes.dup(bytes.Bytes.slice(av, 7, av.len)) } elif bytes.Bytes.starts_with(av, bytes.bytes(c"-key:", 5)) { key_name = bytes.Bytes.dup(bytes.Bytes.slice(av, 5, av.len))+ key_explicit = true } elif bytes.Bytes.starts_with(av, bytes.bytes(c"-pin:", 5)) { tls_pin = bytes.Bytes.dup(bytes.Bytes.slice(av, 5, av.len)) } elif av.len > 0 && bytes.Bytes.at(av, 0) == 45 {@@ -154,6 +157,12 @@ cmsg.error_prefix() stdio.eprint("cannot create repository ({d})\n", {e}) return 1+ }+ }+ if key_name.ptr == none {+ val fallback = credentials.key_for_url(url)+ if fallback is some ck {+ key_name = ck } } val remote_name: bytes.Bytes = bytes.Bytes.dup(bytes.bytes(c"origin", 6))@@ -160,7 +169,7 @@ val url_key: bytes.Bytes = remote_config.key_for(remote_name, bytes.bytes(c"url", 3)) config.set(repo, url_key, url) bytes.free_owned(url_key)- if key_name.ptr != none {+ if key_explicit && key_name.ptr != none { val remote_key: bytes.Bytes = remote_config.key_for(remote_name, bytes.bytes(c"key", 3)) config.set(repo, remote_key, key_name) bytes.free_owned(remote_key)--- a/veins/src/cli/fetch_cmd.sx+++ b/veins/src/cli/fetch_cmd.sx@@ -9,6 +9,7 @@ val state = use("../store/state.sx") val layout = use("../store/layout.sx") val remote_config = use("../git/remote.sx")+val credentials = use("../auth/credentials.sx") val client = use("../protocol/client.sx") val transfer = use("../protocol/transfer.sx") val msg_refs = use("../protocol/messages.sx")@@ -58,9 +59,9 @@ cmsg.error_prefix() if detail.len > 0 { stdio.eprint("{s}: {s}\n", {- str.view(context.ptr, context.len as i64),- str.view(detail.ptr, detail.len as i64)- })+ str.view(context.ptr, context.len as i64),+ str.view(detail.ptr, detail.len as i64)+ }) } else { stdio.eprint("{s}\n", {str.view(context.ptr, context.len as i64)}) }@@ -70,6 +71,7 @@ pub fn run(args: list[ref u8], start: usize) i32 = trust { val remote_name: mut bytes.Bytes = bytes.Bytes.dup(bytes.bytes(c"origin", 6)) val path: mut str.StringView = str.from_cstr(c".")+ val explicit_key: mut bytes.Bytes = bytes.empty() val have_remote: mut bool = false val i: mut usize = start for i < @len(args) {@@ -76,7 +78,9 @@ val o = @get(args, i) if o is some a { val av: bytes.Bytes = bytes.from_cstr(a)- if av.len > 0 && bytes.Bytes.at(av, 0) == 45 {+ if bytes.Bytes.starts_with(av, bytes.bytes(c"-key:", 5)) {+ explicit_key = bytes.Bytes.dup(bytes.Bytes.slice(av, 5, av.len))+ } elif av.len > 0 && bytes.Bytes.at(av, 0) == 45 { cmsg.error_prefix() stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)}) return 1@@ -119,8 +123,20 @@ } val key_name = remote_config.key_name_of(repo, remote_name) val key: mut bytes.Bytes = bytes.empty()- if key_name is some k {- key = k+ if explicit_key.ptr != none {+ key = explicit_key+ } else {+ match key_name {+ some k => {+ key = k+ }+ none => {+ val fallback = credentials.key_for_url(url)+ if fallback is some ck {+ key = ck+ }+ }+ } } val pin_opt = remote_config.tls_pin_of(repo, remote_name) val pin: mut bytes.Bytes = bytes.empty()--- a/veins/src/cli/help_cmd.sx+++ b/veins/src/cli/help_cmd.sx@@ -19,6 +19,7 @@ stdio.puts(" push push a bookmark to a native remote") stdio.puts(" serve run the native server over stdio or TLS") stdio.puts(" key manage local Ed25519 keys")+ stdio.puts(" auth remember keys for hosts and set a default") stdio.puts(" access manage a served repository's access file") stdio.puts(" whoami report the role granted by a server") stdio.puts(" co write a revision into the working directory; alias: checkout")@@ -351,18 +352,24 @@ stdio.puts("usage: vn clone <url> [-blobs:<head|none|all>] [-key:<name>] [-pin:<sha256>] [path]") stdio.puts("") stdio.puts("clone a repository over file://, ssh://, or veins://")+ stdio.puts("")+ stdio.puts("without -key, the key stored by 'vn auth use' is used when available") } fn show_fetch() void = trust {- stdio.puts("usage: vn fetch [<remote>] [path]")+ stdio.puts("usage: vn fetch [-key:<name>] [<remote>] [path]") stdio.puts("") stdio.puts("fetch new history and chunks from a configured native remote")+ stdio.puts("")+ stdio.puts("auth falls back to remote.<name>.key, then 'vn auth use'") } fn show_push() void = trust {- stdio.puts("usage: vn push [<remote>] <bookmark> [path]")+ stdio.puts("usage: vn push [-key:<name>] [<remote>] <bookmark> [path]") stdio.puts("") stdio.puts("push a bookmark to a configured native remote")+ stdio.puts("")+ stdio.puts("auth falls back to remote.<name>.key, then 'vn auth use'") } fn show_serve() void = trust {@@ -376,6 +383,16 @@ stdio.puts("usage: vn key <generate|list|show> [name]") stdio.puts("") stdio.puts("manage local Ed25519 keys in the user key directory")+}++fn show_auth() void = trust {+ stdio.puts("usage: vn auth <use|list|remove> ...")+ stdio.puts("")+ stdio.puts("remember which key clone/fetch/push should use")+ stdio.puts("")+ stdio.puts(" vn auth use <key> [<host|url>] set the default or host key")+ stdio.puts(" vn auth list show stored key mappings")+ stdio.puts(" vn auth remove [<host|url>] remove a mapping") } fn show_access() void = trust {@@ -513,6 +530,10 @@ } if cmd_is(cmd, c"key", 3) { show_key()+ return 0+ }+ if cmd_is(cmd, c"auth", 4) {+ show_auth() return 0 } if cmd_is(cmd, c"access", 6) {--- a/veins/src/cli/push_cmd.sx+++ b/veins/src/cli/push_cmd.sx@@ -11,6 +11,7 @@ val state = use("../store/state.sx") val layout = use("../store/layout.sx") val remote_config = use("../git/remote.sx")+val credentials = use("../auth/credentials.sx") val client = use("../protocol/client.sx") val transfer = use("../protocol/transfer.sx") val msg_refs = use("../protocol/messages.sx")@@ -21,9 +22,9 @@ cmsg.error_prefix() if detail.len > 0 { stdio.eprint("{s}: {s}\n", {- str.view(context.ptr, context.len as i64),- str.view(detail.ptr, detail.len as i64)- })+ str.view(context.ptr, context.len as i64),+ str.view(detail.ptr, detail.len as i64)+ }) } else { stdio.eprint("{s}\n", {str.view(context.ptr, context.len as i64)}) }@@ -42,6 +43,7 @@ pub fn run(args: list[ref u8], start: usize) i32 = trust { val remote_name: mut bytes.Bytes = bytes.Bytes.dup(bytes.bytes(c"origin", 6)) val bookmark: mut bytes.Bytes = bytes.empty()+ val explicit_key: mut bytes.Bytes = bytes.empty() val path: mut str.StringView = str.from_cstr(c".") val have_remote: mut bool = false val i: mut usize = start@@ -49,7 +51,9 @@ val o = @get(args, i) if o is some a { val av: bytes.Bytes = bytes.from_cstr(a)- if av.len > 0 && bytes.Bytes.at(av, 0) == 45 {+ if bytes.Bytes.starts_with(av, bytes.bytes(c"-key:", 5)) {+ explicit_key = bytes.Bytes.dup(bytes.Bytes.slice(av, 5, av.len))+ } elif av.len > 0 && bytes.Bytes.at(av, 0) == 45 { cmsg.error_prefix() stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)}) return 1@@ -99,8 +103,20 @@ } val key_name = remote_config.key_name_of(repo, remote_name) val key: mut bytes.Bytes = bytes.empty()- if key_name is some k {- key = k+ if explicit_key.ptr != none {+ key = explicit_key+ } else {+ match key_name {+ some k => {+ key = k+ }+ none => {+ val fallback = credentials.key_for_url(url)+ if fallback is some ck {+ key = ck+ }+ }+ } } val pin_opt = remote_config.tls_pin_of(repo, remote_name) val pin: mut bytes.Bytes = bytes.empty()--- a/veins/src/cli/whoami_cmd.sx+++ b/veins/src/cli/whoami_cmd.sx@@ -5,6 +5,7 @@ val bytes = use("../core/bytes.sx") val layout = use("../store/layout.sx") val remote_config = use("../git/remote.sx")+val credentials = use("../auth/credentials.sx") val ed = use("../crypto/ed25519.sx") val client = use("../protocol/client.sx") val cmsg = use("../core/msg.sx")@@ -73,6 +74,12 @@ } repo_name = client.url_repo_name(url) layout.free_repo(repo)+ }+ if key.ptr == none {+ val fallback = credentials.key_for_url(url)+ if fallback is some ck {+ key = ck+ } } val w = client.whoami_pinned(url, key, repo_name, pin) if url.ptr != none {--- a/veins/src/main.sx+++ b/veins/src/main.sx@@ -15,6 +15,7 @@ val push_cmd = use("cli/push_cmd.sx") val serve_cmd = use("cli/serve_cmd.sx") val key_cmd = use("cli/key_cmd.sx")+val auth_cmd = use("cli/auth_cmd.sx") val access_cmd = use("cli/access_cmd.sx") val whoami_cmd = use("cli/whoami_cmd.sx") val checkout_cmd = use("cli/checkout_cmd.sx")@@ -908,6 +909,9 @@ } if cmd_is(cmd, c"key", 3) { return key_cmd.run(args, 2)+ }+ if cmd_is(cmd, c"auth", 4) {+ return auth_cmd.run(args, 2) } if cmd_is(cmd, c"access", 6) { return access_cmd.run(args, 2)--- a/veins/src/protocol/client.sx+++ b/veins/src/protocol/client.sx@@ -631,7 +631,11 @@ return none } -pub fn negotiate(c: mut ref Client, wants: list[bytes.Bytes], haves: list[bytes.Bytes]) bool = trust {+pub fn negotiate(+ c: mut ref Client,+ wants: list[bytes.Bytes],+ haves: list[bytes.Bytes]+) bool = trust { val body: bytes.Bytes = msg.encode_negotiate(wants, haves) val f_opt = request(c, wire.NEGOTIATE, body) if f_opt is some f {