Skip to content

Commit f986805

Browse files
authored
Merge pull request #296 from Castaglia/proxy-chachapoly-issue295
Issue #295: Implement support for the OpenSSH-specific ChaChaPoly SSH…
2 parents 215ab9e + de6bb2e commit f986805

File tree

15 files changed

+1022
-212
lines changed

15 files changed

+1022
-212
lines changed

Makefile.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ MODULE_OBJS=mod_proxy.o \
5454
lib/proxy/ssh/misc.o \
5555
lib/proxy/ssh/msg.o \
5656
lib/proxy/ssh/packet.o \
57+
lib/proxy/ssh/poly1305.o \
5758
lib/proxy/ssh/service.o \
5859
lib/proxy/ssh/session.o \
5960
lib/proxy/ssh/umac.o \
@@ -102,6 +103,7 @@ SHARED_MODULE_OBJS=mod_proxy.lo \
102103
lib/proxy/ssh/misc.lo \
103104
lib/proxy/ssh/msg.lo \
104105
lib/proxy/ssh/packet.lo \
106+
lib/proxy/ssh/poly1305.lo \
105107
lib/proxy/ssh/service.lo \
106108
lib/proxy/ssh/session.lo \
107109
lib/proxy/ssh/umac.lo \

configure

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4300,6 +4300,46 @@ $as_echo "no" >&6; }
43004300
LIBS="$saved_libs"
43014301
43024302
4303+
fi
4304+
rm -f core conftest.err conftest.$ac_objext \
4305+
conftest$ac_exeext conftest.$ac_ext
4306+
4307+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether OpenSSL supports EVP_chacha20" >&5
4308+
$as_echo_n "checking whether OpenSSL supports EVP_chacha20... " >&6; }
4309+
LIBS="-lcrypto $LIBS"
4310+
4311+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
4312+
/* end confdefs.h. */
4313+
4314+
#include <openssl/evp.h>
4315+
4316+
int
4317+
main ()
4318+
{
4319+
4320+
EVP_CIPHER *cipher;
4321+
cipher = EVP_chacha20();
4322+
4323+
;
4324+
return 0;
4325+
}
4326+
_ACEOF
4327+
if ac_fn_c_try_link "$LINENO"; then :
4328+
4329+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
4330+
$as_echo "yes" >&6; }
4331+
4332+
$as_echo "#define HAVE_EVP_CHACHA20_OPENSSL 1" >>confdefs.h
4333+
4334+
LIBS="$saved_libs"
4335+
4336+
else
4337+
4338+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
4339+
$as_echo "no" >&6; }
4340+
LIBS="$saved_libs"
4341+
4342+
43034343
fi
43044344
rm -f core conftest.err conftest.$ac_objext \
43054345
conftest$ac_exeext conftest.$ac_ext

configure.in

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl ProFTPD - mod_proxy
2-
dnl Copyright (c) 2012-2022 TJ Saunders <[email protected]>
2+
dnl Copyright (c) 2012-2025 TJ Saunders <[email protected]>
33
dnl
44
dnl This program is free software; you can redistribute it and/or modify
55
dnl it under the terms of the GNU General Public License as published by
@@ -364,6 +364,28 @@ AC_TRY_LINK(
364364
]
365365
)
366366

367+
AC_MSG_CHECKING([whether OpenSSL supports EVP_chacha20])
368+
LIBS="-lcrypto $LIBS"
369+
370+
AC_TRY_LINK(
371+
[
372+
#include <openssl/evp.h>
373+
],
374+
[
375+
EVP_CIPHER *cipher;
376+
cipher = EVP_chacha20();
377+
],
378+
[
379+
AC_MSG_RESULT(yes)
380+
AC_DEFINE(HAVE_EVP_CHACHA20_OPENSSL, 1, [OpenSSL supports EVP_chacha20])
381+
LIBS="$saved_libs"
382+
],
383+
[
384+
AC_MSG_RESULT(no)
385+
LIBS="$saved_libs"
386+
]
387+
)
388+
367389
AC_MSG_CHECKING([whether OpenSSL supports X448 algorithm])
368390
LIBS="-lcrypto $LIBS"
369391

include/proxy/ssh/cipher.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ProFTPD - mod_proxy SSH cipher API
3-
* Copyright (c) 2021-2022 TJ Saunders
3+
* Copyright (c) 2021-2025 TJ Saunders
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -41,6 +41,8 @@ size_t proxy_ssh_cipher_get_write_block_size(void);
4141
void proxy_ssh_cipher_set_read_block_size(size_t);
4242
void proxy_ssh_cipher_set_write_block_size(size_t);
4343

44+
int proxy_ssh_cipher_is_read_chachapoly(void);
45+
4446
/* Returns the cipher authenticated data size, or zero. */
4547
size_t proxy_ssh_cipher_get_read_auth_size(void);
4648
size_t proxy_ssh_cipher_get_read_auth_size2(void);
@@ -55,6 +57,9 @@ int proxy_ssh_cipher_set_read_key(pool *p, const EVP_MD *md,
5557
int proxy_ssh_cipher_read_data(struct proxy_ssh_packet *pkt,
5658
unsigned char *data, uint32_t data_len, unsigned char **buf,
5759
uint32_t *buflen);
60+
int proxy_ssh_cipher_read_packet_len(struct proxy_ssh_packet *pkt,
61+
unsigned char *data, uint32_t data_len, unsigned char **buf,
62+
uint32_t *buflen, uint32_t *packet_len);
5863

5964
const char *proxy_ssh_cipher_get_write_algo(void);
6065
int proxy_ssh_cipher_set_write_algo(pool *p, const char *algo);

include/proxy/ssh/poly1305.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Public Domain poly1305 from Andrew Moon
3+
* poly1305-donna-unrolled.c from https://github.com/floodyberry/poly1305-donna
4+
*/
5+
6+
#ifndef POLY1305_H
7+
#define POLY1305_H
8+
9+
#include "mod_proxy.h"
10+
11+
#if defined(HAVE_EVP_CHACHA20_OPENSSL) && \
12+
!defined(HAVE_BROKEN_CHACHA20)
13+
#include <sys/types.h>
14+
15+
#define POLY1305_KEYLEN 32
16+
#define POLY1305_TAGLEN 16
17+
18+
void poly1305_auth(u_char out[POLY1305_TAGLEN], const u_char *m, size_t inlen,
19+
const u_char key[POLY1305_KEYLEN])
20+
__attribute__((__bounded__(__minbytes__, 1, POLY1305_TAGLEN)))
21+
__attribute__((__bounded__(__buffer__, 2, 3)))
22+
__attribute__((__bounded__(__minbytes__, 4, POLY1305_KEYLEN)));
23+
24+
#endif /* HAVE_EVP_CHACHA20_OPENSSL and !HAVE_BROKEN_CHACHA20 */
25+
#endif /* POLY1305_H */

lib/proxy/ssh/auth.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ProFTPD - mod_proxy SSH user authentication
3-
* Copyright (c) 2021-2022 TJ Saunders
3+
* Copyright (c) 2021-2025 TJ Saunders
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -1209,6 +1209,8 @@ int proxy_ssh_auth_handle(struct proxy_ssh_packet *pkt,
12091209
return -1;
12101210
}
12111211

1212+
(void) len;
1213+
12121214
} else if (msg_type == PROXY_SSH_MSG_USER_AUTH_INFO_RESP) {
12131215
pr_trace_msg(trace_channel, 17,
12141216
"handling USER_AUTH_INFO_RESPONSE");

0 commit comments

Comments
 (0)