hexpm / hex

Package manager for the Erlang ecosystem.
https://hex.pm
969 stars 184 forks source link

How to generate a fingerprint for public_key? #986

Closed mplatts closed 1 year ago

mplatts commented 1 year ago

This might be a stupid question, but I've followed the guide here: https://hex.pm/docs/self_hosting and want to use the --fetch-public-key feature. The problem is, I don't know how to generate the fingerprint. I have a private and public key, but no fingerprint.

ericmj commented 1 year ago

You can use https://www.erlang.org/doc/man/ssh.html#hostkey_fingerprint-1.

mplatts commented 1 year ago

I can't seem to get it to work. Not sure what I''m doing wrong.

iex(24)> file_path = Path.join([:code.priv_dir(:petal_pro), "static/repo", "public_key"])
iex(25)> public_key = File.read! file_path
iex(26)> :ssh.hostkey_fingerprint(public_key)                                            
** (FunctionClauseError) no function clause matching in :ssh_message.ssh2_pubkey_encode/1    

    The following arguments were given to :ssh_message.ssh2_pubkey_encode/1:

        # 1
        "-----BEGIN RSA PUBLIC KEY-----truncated-----END RSA PUBLIC KEY-----\n\n"

    ssh_message.erl:572: :ssh_message.ssh2_pubkey_encode/1
    ssh.erl:799: :ssh.hostkey_fingerprint/1
mplatts commented 1 year ago

Same happens for :ssh.hostkey_fingerprint(:sha256, public_key)

ericmj commented 1 year ago

You need to decode the key first:

[pem_entry] = :public_key.pem_decode(public_key)
public_key = :public_key.pem_entry_decode(pem_entry)
mplatts commented 1 year ago

That worked - thanks!