examples, keys: add an Ed25519 user credential

The sample clients load hansel's Ed25519 key when neither RSA nor ECDSA
is compiled in, so public key auth reaches the echoserver's matching
sample keys instead of sending a request carrying no key.

- commit keys/{hansel,gretel}-key-ed25519.{der,pem,pub}, the pair to the
  echoserver's sample authorized keys
- ClientUserAuth() fails a publickey request with no key loaded, so the
  library can offer another method
pull/1257/head
John Safranek 2026-09-15 19:56:50 -07:00
parent 53814839bb
commit 49f07314d6
8 changed files with 58 additions and 2 deletions

View File

@ -275,6 +275,23 @@ static const unsigned int hanselPrivateEccSz = 223;
#endif
#endif
/* The pair in keys/hansel-key-ed25519.*, the only built-in user key left
* when both RSA and ECDSA are compiled out. */
#if defined(WOLFSSH_NO_RSA) && defined(WOLFSSH_NO_ECDSA) && \
!defined(WOLFSSH_NO_ED25519)
static const char* hanselPublicEd25519 =
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHTSoBZIJBO2V0Jb2OWyMWNbkD"
"d6ReDfKxnrAPlbPuCe hansel";
static const byte hanselPrivateEd25519[] = {
0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70,
0x04, 0x22, 0x04, 0x20, 0x28, 0xc6, 0xe9, 0xd8, 0x37, 0x4d, 0x0c, 0x52,
0x7e, 0x5f, 0xb3, 0x4c, 0x81, 0xe8, 0x68, 0xee, 0xc9, 0x7c, 0xad, 0x00,
0xad, 0xa0, 0xe3, 0xe2, 0x13, 0x06, 0x55, 0xf1, 0x17, 0xf1, 0x0a, 0xf0
};
static const unsigned int hanselPrivateEd25519Sz =
(unsigned int)sizeof(hanselPrivateEd25519);
#endif
#if defined(WOLFSSH_CERTS)
@ -476,6 +493,13 @@ int ClientUserAuth(byte authType,
if (authType == WOLFSSH_USERAUTH_PUBLICKEY) {
WS_UserAuthData_PublicKey* pk = &authData->sf.publicKey;
if (userPublicKeyType == NULL || userPublicKeySz == 0) {
/* Nothing to sign with. SendUserAuthRequest() turns this
* into WS_FATAL_ERROR rather than putting an untyped
* publickey request on the wire. */
return WOLFSSH_USERAUTH_FAILURE;
}
pk->publicKeyType = userPublicKeyType;
pk->publicKeyTypeSz = userPublicKeyTypeSz;
pk->publicKey = userPublicKey;
@ -1009,12 +1033,21 @@ int ClientSetPrivateKey(const char* privKeyName, int userEcc,
if (privKeyName == NULL) {
#if defined(WOLFSSH_NO_RSA) && defined(WOLFSSH_NO_ECDSA)
(void)userEcc;
#ifndef WOLFSSH_NO_ED25519
userPrivateKeySz = sizeof(userPrivateKeyBuf);
ret = wolfSSH_ReadKey_buffer(hanselPrivateEd25519,
hanselPrivateEd25519Sz, WOLFSSH_FORMAT_ASN1,
&userPrivateKey, &userPrivateKeySz,
&userPrivateKeyType, &userPrivateKeyTypeSz, heap);
isPrivate = 1;
#else
/* No built-in key to load. Leave the client to authenticate
* some other way rather than failing here. */
userPrivateKeySz = 0;
userPrivateKeyType = NULL;
(void)userEcc;
(void)heap;
#endif
#else
if (userEcc) {
#ifndef WOLFSSH_NO_ECDSA
@ -1081,12 +1114,25 @@ int ClientUsePubKey(const char* pubKeyName, int userEcc, void* heap)
if (pubKeyName == NULL) {
#if defined(WOLFSSH_NO_RSA) && defined(WOLFSSH_NO_ECDSA)
(void)userEcc;
#ifndef WOLFSSH_NO_ED25519
{
byte* p = userPublicKey;
userPublicKeySz = sizeof(userPublicKeyBuf);
ret = wolfSSH_ReadKey_buffer((const byte*)hanselPublicEd25519,
(word32)strlen(hanselPublicEd25519), WOLFSSH_FORMAT_SSH,
&p, &userPublicKeySz,
&userPublicKeyType, &userPublicKeyTypeSz, heap);
isPrivate = 1;
}
#else
/* No built-in key to load. Leave the client to authenticate
* some other way rather than failing here. */
userPublicKeySz = 0;
userPublicKeyType = NULL;
(void)userEcc;
(void)heap;
#endif
#else
byte* p = userPublicKey;
userPublicKeySz = sizeof(userPublicKeyBuf);

Binary file not shown.

View File

@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIEHo0C0B8ZM9j3mX6D3LLQLp+wHhvXG6eriviX8uBDhc
-----END PRIVATE KEY-----

View File

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFD8Bwir++gzNJmif9ooAZdaRisFZjlp9XU2seaec7/m gretel

Binary file not shown.

View File

@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEICjG6dg3TQxSfl+zTIHoaO7JfK0AraDj4hMGVfEX8Qrw
-----END PRIVATE KEY-----

View File

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHTSoBZIJBO2V0Jb2OWyMWNbkDd6ReDfKxnrAPlbPuCe hansel

View File

@ -16,6 +16,8 @@ EXTRA_DIST+= \
keys/gretel-key-ecc-384.der keys/gretel-key-ecc-384.pem keys/gretel-key-ecc-384.pub \
keys/gretel-key-ecc-521.der keys/gretel-key-ecc-521.pem keys/gretel-key-ecc-521.pub \
keys/gretel-key-rsa.der keys/gretel-key-rsa.pem keys/gretel-key-rsa.pub \
keys/hansel-key-ed25519.der keys/hansel-key-ed25519.pem keys/hansel-key-ed25519.pub \
keys/gretel-key-ed25519.der keys/gretel-key-ed25519.pem keys/gretel-key-ed25519.pub \
keys/pubkeys-ecc.txt keys/pubkeys-ecc-384.txt keys/pubkeys-ecc-521.txt \
keys/pubkeys-rsa.txt keys/passwd.txt keys/ca-cert-ecc.der \
keys/ca-cert-ecc.pem keys/ca-key-ecc.der keys/ca-key-ecc.pem \