Skip to content

Push scraps to yard via CLI #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
surprisetalk opened this issue May 14, 2025 · 2 comments
Open

Push scraps to yard via CLI #253

surprisetalk opened this issue May 14, 2025 · 2 comments

Comments

@surprisetalk
Copy link
Contributor

The following serves a directory of scraps over the network:

echo "123" > /var/scrap/yard/example.scrap
scrap yard serve /var/scrap/yard

But we also want to enable folks to remotely (and securely) push scraps to a yard:

cat fib.scrap \
  | scrap yard push sarah/fib \
      --yard yard.scrap.land \
      --key ~/.ssh/id_scrap

We could implement the CLI command like so:

def yard_push(): 
    input = sys.stdin.read()
    flat = to_flat(input)
    with open(args.key, encoding="utf-8") as f:
        key = f.read()
    requests.post(
        f"https://yard.scrap.land/{args.dir}", 
        data=to_flat({
            "sig": sign(flat, key),
            "data": input,
        })
    )

On the server side, we can start out by storing a directory of public keys like so:

mkdir -p /var/scrap/keys
cp ~/.ssh/id_scrap.pub /var/scrap/keys/sarah
scrap yard serve /var/scrap/yard --keys /var/scrap/keys --port 8080 &
scrap yard push sarah/fib --yard :8080 --key ~/.ssh/id_scrap < fib.scrap
@tekknolagi
Copy link
Owner

It seems interesting. I feel wary of rolling our own crypto. What existing (extremely widely deployed) software can we lean on here? Last time we went for this I was thinking about Git

@surprisetalk
Copy link
Contributor Author

surprisetalk commented May 15, 2025

The auth handler could be as simple as this:

@app.route('/<path>', methods=['POST'])
def push_scrap(path):
    top, scrap_path = scrap_path.split('/', 1)
    scrap = Deserialize(request.data)
    with open(os.path.join(KEYS_PATH, top), "rb") as key_file:
        pub_key = load_ssh_public_key(key_file.read())
    public_key.verify(
        base64.b64decode(scrap.sig),
        scrap.data,
        padding.PSS(mgf=padding.MGF1(hashes.SHA256()), salt_length=padding.PSS.MAX_LENGTH),
        hashes.SHA256()
    )
    with open(os.path.join(top, f"{scrap_path}.scrap"), "w") as f:
        f.write(scrap)
    return nil, 204

We're just verifying that the sig matches the key 🤠 We can keep things real spartan for now haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants