Add a converter from private ssh keys to age

This commit is contained in:
Janne Heß 2021-08-28 16:24:05 +02:00
parent 4568162629
commit 6c916c1f57
No known key found for this signature in database
GPG key ID: 69165158F05265DF
6 changed files with 62 additions and 8 deletions

View file

@ -0,0 +1,19 @@
{ stdenv, lib, buildGoModule, path, pkgs, vendorSha256, go }:
buildGoModule {
pname = "ssh-privkey-to-age";
version = "0.0.1";
src = ../..;
subPackages = [ "pkgs/ssh-privkey-to-age" ];
inherit vendorSha256;
meta = with lib; {
description = "Converter that converts SSH private keys into age keys";
homepage = "https://github.com/Mic92/sops-nix";
license = licenses.mit;
maintainers = with maintainers; [ mic92 ];
platforms = platforms.linux;
};
}

View file

@ -0,0 +1,28 @@
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/Mic92/sops-nix/pkgs/sops-install-secrets/agessh"
)
func main() {
if len(os.Args) != 2 {
println("Usage: " + os.Args[0] + " [path to ssh private key]")
os.Exit(1)
}
sshKey, err := ioutil.ReadFile(os.Args[1])
if err != nil {
panic(fmt.Errorf("Cannot read ssh key '%s': %w", os.Args[1], err))
}
// Convert the key to bech32
bech32, err := agessh.SSHPrivateKeyToBech32(sshKey)
if err != nil {
panic(fmt.Errorf("Cannot convert ssh key '%s': %w", os.Args[1], err))
}
fmt.Println(bech32)
}

View file

@ -1,11 +1,11 @@
{ stdenv, lib, buildGoModule, path, pkgs, vendorSha256, go }:
buildGoModule {
pname = "sops-ssh-to-age";
pname = "ssh-pubkey-to-age";
version = "0.0.1";
src = ../..;
subPackages = [ "pkgs/sops-ssh-to-age" ];
subPackages = [ "pkgs/ssh-pubkey-to-age" ];
inherit vendorSha256;