4

GitHub - hauleth/ssh_signature

 2 years ago
source link: https://github.com/hauleth/ssh_signature
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

SSH signatures for Erlang

Implementation of SSH signatures in Erlang. It uses only stuff distributed with OTP, so no external dependencies needed.

Currently supported algorithms:

  • Ed25519
  • Ed448 - not tested, as my implementation of OpenSSH do not support Ed448 keys

Usage

There are just 3 exported functions:

  • sign/{3,4} which allows signing data
  • verify/2 that verifies the signature for given data and outputs details about signature
% First we need the private key that we will use for signing.
% For the purpose of this example just use RSA-4096
SecretKey = public_key:generate_key({rsa, 4096, 3}),

Data = <<"Foo">>,

% Sign data using our key. 3rd argument there is a namespace, that must be
% non-empty string.
Signature = ssh_signature:sign(Data, SecretKey, "text"),

% The created signature is already in armoured (ASCII-only) format.

% Now we can check if the signature is correct
{ok, #{public_key := PubKey, ns := <<"test">>, signature := Sig}} =
    ssh_signature:verify(Data, Signature).
% Notice that we do not pass public key to verify/2, it is left to the user to
% check whether the returned public key is trusted.

License

See LICENSE


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK