Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions moscow.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# nasm, ussr, C toolchain the runtime and its native xHCI driver
# clang, ld.lld /lib/ctest.so, gui.so and tls.so (BearSSL,
# fetched once); CLANG= and LLD= override
# Linux, gcc, flex, bison, /bin/ussr, /bin/ural and /bin/moscow_native:
# Linux, gcc, flex, bison, /bin/ussr, /bin/ural, /bin/moscow_native and /bin/kal-ssh:
# perl, curl static PIE against musl, with zlib, OpenSSL,
# curl and SQLite, all fetched once
# clang, lld-link BOOTX64.EFI, the UEFI loader (efi/loader.c),
Expand Down Expand Up @@ -88,6 +88,8 @@ ZLIB := zlib-1.3.2
ZLIB_SHA256 := bb329a0a2cd0274d05519d61c667c062e06990d72e125ee2dfa8de64f0119d16
OPENSSL := openssl-3.5.9
OPENSSL_SHA256 := 603f5602e2eef00d77fbd429d34dcd5822bb301757a1bc9cdb24c670f1eb859a
LIBSSH2 := libssh2-1.11.1
LIBSSH2_SHA256 := d9ec76cbe34db98eec3539fe2c899d26b0c837cb3eb466a56b0f109cabf658f7
CURL := curl-8.23.0
CURL_SHA256 := e3de77cfa6367083c776a26647fc9f633b538c06c3baa73d931a252ac8f72b49
SQLITE := sqlite-autoconf-3540100
Expand Down Expand Up @@ -123,6 +125,9 @@ $(DL)/$(ZLIB).tar.gz:
$(call fetch,https://zlib.net/fossils/$(ZLIB).tar.gz https://github.com/madler/zlib/releases/download/v$(ZLIB:zlib-%=%)/$(ZLIB).tar.gz,$(ZLIB_SHA256))
$(DL)/$(OPENSSL).tar.gz:
$(call fetch,https://github.com/openssl/openssl/releases/download/$(OPENSSL)/$(OPENSSL).tar.gz https://www.openssl.org/source/$(OPENSSL).tar.gz,$(OPENSSL_SHA256))
$(DL)/$(LIBSSH2).tar.gz:
$(call fetch,https://libssh2.org/download/$(LIBSSH2).tar.gz,$(LIBSSH2_SHA256))

$(DL)/$(CURL).tar.gz:
$(call fetch,https://curl.se/download/$(CURL).tar.gz https://github.com/curl/curl/releases/download/curl-$(subst .,_,$(CURL:curl-%=%))/$(CURL).tar.gz,$(CURL_SHA256))
$(DL)/$(SQLITE).tar.gz:
Expand All @@ -148,7 +153,7 @@ $(OUT)/xhci.bin: $(OUT)/xhci.o $(ARCH)/xhci.ld
CHINA := $(ROOT)/src/china
SU_SRC := $(filter-out $(CHINA)/%,$(wildcard $(ROOT)/src/*.su $(ROOT)/src/*/*.su $(ROOT)/src/*/*/*.su))
BOOT_FILES := ussr_rt.bin moscow.ru russia.ru rush.ru
NATIVE_RU := install stalin belarus
NATIVE_RU := install stalin belarus kal
RUSSIA_RU := Mbl Mbltishi kremlin
CHINA_RU := china $(basename $(notdir $(wildcard $(CHINA)/*/*.su)))
BIN_RU := $(NATIVE_RU) $(RUSSIA_RU) $(CHINA_RU)
Expand All @@ -168,6 +173,10 @@ $(OUT)/russia.ru $(OUT)/stalin.ru $(OUT)/belarus.ru: $(OUT)/%.ru: $(SU_SRC) $(US
mkdir -p $(OUT)
cd $(ROOT)/src/$* && $(RUN_USSR) -c $*.su $@

$(OUT)/kal.ru: $(ROOT)/src/kaliningrad/kal.su $(USSR)
mkdir -p $(OUT)
cd $(ROOT)/src/kaliningrad && $(RUN_USSR) -c kal.su $@

$(OUT)/rush.ru: $(SU_SRC) $(USSR)
mkdir -p $(OUT)
cd $(ROOT)/src/russia && $(RUN_USSR) -c rush.su $@
Expand Down Expand Up @@ -271,7 +280,7 @@ NATIVE_TOOLS := gcc make flex bison perl curl
NATIVE_OK := $(if $(filter Linux,$(shell uname -s)),$(if $(strip $(foreach t,$(NATIVE_TOOLS),$(if $(call have,$(t)),,$(t)))),,yes))

ifeq ($(NATIVE_OK),yes)
PROGS := $(NATIVE)/ussr $(NATIVE)/ural $(NATIVE)/moscow_native
PROGS := $(NATIVE)/ussr $(NATIVE)/ural $(NATIVE)/moscow_native $(NATIVE)/kal-ssh
PREFIX := $(NATIVE)/musl
MUSL_GCC := $(PREFIX)/bin/musl-gcc
MLIB := $(PREFIX)/lib
Expand Down Expand Up @@ -318,6 +327,20 @@ $(DEPS)/lib/libcurl.a: $(DL)/$(CURL).tar.gz $(DEPS)/lib/libssl.a $(DEPS)/lib/lib
$(MAKE) -j$(JOBS) -C lib >/dev/null 2>&1 && $(MAKE) -C lib install >/dev/null 2>&1 && \
$(MAKE) -C include install >/dev/null 2>&1

$(DEPS)/lib/libssh2.a: $(DL)/$(LIBSSH2).tar.gz $(DEPS)/lib/libssl.a
tar -xzf $< -C $(NATIVE)
cd $(NATIVE)/$(LIBSSH2) && CC=$(MUSL_GCC) CFLAGS="$(PICFLAGS)" \
CPPFLAGS="-I$(DEPS)/include" LDFLAGS="-L$(DEPS)/lib -static" LIBS= \
./configure --prefix=$(DEPS) --with-crypto=openssl --with-libssl-prefix=$(DEPS) \
--disable-shared --enable-static --without-libz >/dev/null && \
$(MAKE) -C src -j$(JOBS) >/dev/null && $(MAKE) -C src install >/dev/null && \
cp include/libssh2.h $(DEPS)/include/

$(NATIVE)/kal-ssh: $(ROOT)/src/kaliningrad/kal_ssh.c $(DEPS)/lib/libssh2.a
$(MUSL_GCC) -fPIE -O2 -Wall -Wextra -I$(DEPS)/include $(PIE) -o $@ $< \
-L$(DEPS)/lib -lssh2 -lcrypto $(MLIB)/crtn.o
strip $@ 2>/dev/null || true

$(NATIVE)/$(SQLITE)/sqlite3.c: $(DL)/$(SQLITE).tar.gz
mkdir -p $(NATIVE)
tar -xzf $< -C $(NATIVE)
Expand Down Expand Up @@ -351,7 +374,7 @@ $(NATIVE)/ussr: $(USSR_SRC) $(DEPS)/lib/libssl.a | $(MUSL_GCC)
$(NATIVE)/moscow_native: $(ROOT)/tests/moscow_native.c | $(MUSL_GCC)
$(MUSL_GCC) -fPIE -O1 -w $(PIE) -o $@ $< $(MLIB)/crtn.o
else
$(call missing,Linux programs need Linux and $(NATIVE_TOOLS): no new /bin/ussr /bin/ural /bin/moscow_native)
$(call missing,Linux programs need Linux and $(NATIVE_TOOLS): no new /bin/ussr /bin/ural /bin/moscow_native /bin/kal-ssh)
PROGS :=
endif

Expand Down Expand Up @@ -416,7 +439,7 @@ $(IMG): $(OUT)/moscow.img $(addprefix $(OUT)/,$(addsuffix .ru,$(BIN_RU))) $(LIBS
[ -f "$$so" ] || { echo "moscow.mk: no /lib/*.so" >&2; break; }; \
$(BELARUS) put $@ $$so /lib/$$(basename $$so); \
done
for f in ussr ural moscow_native; do \
for f in ussr ural moscow_native kal-ssh; do \
if [ -f $(NATIVE)/$$f ]; then $(BELARUS) put $@ $(NATIVE)/$$f /bin/$$f; \
else echo "moscow.mk: no /bin/$$f" >&2; fi; \
done
Expand Down Expand Up @@ -446,7 +469,7 @@ $(ISO): $(IMG) $(ISO_EFI) FORCE
mkdir -p $(STAGE)/boot $(STAGE)/bin $(STAGE)/etc/ssl $(STAGE)/src/ussr
for f in $(BOOT_FILES); do cp $(OUT)/$$f $(STAGE)/boot/$$f; done
for f in $(BIN_RU); do cp $(OUT)/$$f.ru $(STAGE)/bin/$$f.ru; done
for f in ussr ural moscow_native; do \
for f in ussr ural moscow_native kal-ssh; do \
if [ -f $(NATIVE)/$$f ]; then cp $(NATIVE)/$$f $(STAGE)/bin/$$f; fi; \
done
printf '%s' "moscow-install" >$(STAGE)/etc/hostname
Expand Down Expand Up @@ -481,7 +504,7 @@ endif
clean:
rm -rf $(OUT)/*.bin $(OUT)/*.ru $(OUT)/*.img $(OUT)/*.iso $(OUT)/iso $(OUT)/lib \
$(OUT)/files.txt $(OUT)/murmansk.rules \
$(NATIVE)/ussr $(NATIVE)/ural $(NATIVE)/moscow_native $(NATIVE)/src
$(NATIVE)/ussr $(NATIVE)/ural $(NATIVE)/moscow_native $(NATIVE)/kal-ssh $(NATIVE)/src

FORCE:
.PHONY: all boot img iso clean certs FORCE
39 changes: 39 additions & 0 deletions src/kaliningrad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Kaliningrad

Kaliningrad opens a remote SSH shell from the current console.

## Linux and Windows

Install OpenSSH Client and make sure `ssh` is on `PATH`. From the
repository root:

ussr src/kaliningrad/kal.su server.example alice
ussr src/kaliningrad/kal.su server.example alice 2222

Kaliningrad passes the arguments directly to OpenSSH and returns its exit
status. OpenSSH handles host verification, authentication, configuration,
and terminal I/O.

## Moscow

A Linux build of the Moscow ISO includes `/bin/kal.ru` and the static
libssh2 backend. At the Rush prompt in a master-admin session:

kal(): "192.0.2.10" "alice" 22 "HOST_KEY_SHA256_HEX"

Use the server's IPv4 address and replace the final argument with the
64-character SHA-256 hex digest of its SSH host public key. Obtain it
from the server's trusted console or administrator. On a Linux server,
for an Ed25519 host key:

awk '{print $2}' /etc/ssh/ssh_host_ed25519_key.pub | base64 -d | sha256sum

Use the digest of the host key the server and client negotiate. A mismatch
ends the connection before password entry. Moscow supports password
authentication and an interactive remote terminal. Press Ctrl-] to
disconnect locally. Its backend requires a CPU with working RDRAND.

With Paramiko installed for Python, run the SSH integration test after
building the ISO:

python src/moscow/tools/kal_test.py --qemu qemu-system-x86_64 --uefi
1 change: 1 addition & 0 deletions src/kaliningrad/box.uno
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'Package{name=`kaliningrad`,version=`0.1.0`,description=`Console SSH client for Linux, Windows, and Moscow`,entry=`kal.su`,dependencies=[],files=[`kal.su`,`kal_ssh.c`,`README.md`],license=`UNSPECIFIED`,minimum_ussr=`0.5.0`,source=``}'
29 changes: 29 additions & 0 deletions src/kaliningrad/kal.su
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Hosted systems use their installed OpenSSH. Moscow ships kal-ssh.
init(r): argc argv [
getenv(os): "OS"
if(_): {argc < 2 || argc > 4} [
print(_): "Usage: kal HOST USER [PORT] (Moscow also requires a host key fingerprint)"
return(r): 2
]
at(host): argv 0
at(user): argv 1
set(port): "22"
if(_): {argc >= 3} [ at(port): argv 2 ]
typeof(port_type): port
if(_): {port_type = "integer"} [ encode(port): port ]
elif(_): {port_type != "string"} [ return(r): 2 ]
if(_): {os = "Moscow"} [
if(_): {argc != 4} [
print(_): "Usage: kal HOST USER PORT SHA256_HEX"
return(r): 2
]
at(fingerprint): argv 3
run(r): "/bin/kal-ssh" host user port fingerprint
return(r): r
]
if(_): {argc > 3} [
print(_): "Usage: kal HOST USER [PORT]"
return(r): 2
]
ssh(r): "-l" user "-p" port "--" host
]
Loading
Loading