diff --git a/examples/client/common.c b/examples/client/common.c index 3fd5305e..9e8e9d22 100644 --- a/examples/client/common.c +++ b/examples/client/common.c @@ -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); diff --git a/keys/gretel-key-ed25519.der b/keys/gretel-key-ed25519.der new file mode 100644 index 00000000..4ee73f8b Binary files /dev/null and b/keys/gretel-key-ed25519.der differ diff --git a/keys/gretel-key-ed25519.pem b/keys/gretel-key-ed25519.pem new file mode 100644 index 00000000..b322e776 --- /dev/null +++ b/keys/gretel-key-ed25519.pem @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEIEHo0C0B8ZM9j3mX6D3LLQLp+wHhvXG6eriviX8uBDhc +-----END PRIVATE KEY----- diff --git a/keys/gretel-key-ed25519.pub b/keys/gretel-key-ed25519.pub new file mode 100644 index 00000000..b172de69 --- /dev/null +++ b/keys/gretel-key-ed25519.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFD8Bwir++gzNJmif9ooAZdaRisFZjlp9XU2seaec7/m gretel diff --git a/keys/hansel-key-ed25519.der b/keys/hansel-key-ed25519.der new file mode 100644 index 00000000..ee8603af Binary files /dev/null and b/keys/hansel-key-ed25519.der differ diff --git a/keys/hansel-key-ed25519.pem b/keys/hansel-key-ed25519.pem new file mode 100644 index 00000000..2d2a8432 --- /dev/null +++ b/keys/hansel-key-ed25519.pem @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEICjG6dg3TQxSfl+zTIHoaO7JfK0AraDj4hMGVfEX8Qrw +-----END PRIVATE KEY----- diff --git a/keys/hansel-key-ed25519.pub b/keys/hansel-key-ed25519.pub new file mode 100644 index 00000000..82581826 --- /dev/null +++ b/keys/hansel-key-ed25519.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHTSoBZIJBO2V0Jb2OWyMWNbkDd6ReDfKxnrAPlbPuCe hansel diff --git a/keys/include.am b/keys/include.am index e465ee7e..db10dd30 100644 --- a/keys/include.am +++ b/keys/include.am @@ -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 \