1
0
mirror of https://github.com/osmarks/ngircd.git synced 2024-10-28 04:46:17 +00:00
Commit Graph

2327 Commits

Author SHA1 Message Date
Alexander Barton
c8589e9890 S2S-TLS: MAX_CERT_CHAIN_LENGTH is only used by OpenSSL 2024-03-23 20:19:01 +01:00
Alexander Barton
02bb99b024 S2S-TLS/OpenSSL: Streamline logging
This includes simplifying cb_connserver_login_ssl() a bit, we do not
have to code for invalid state which was ruled out by an assert() and
therefore can get rid of the goto altogether (and don't log the same
error twice with different messages).
2024-03-23 20:19:01 +01:00
Alexander Barton
3db3b47fc7 S2S-TLS/OpenSSL: Postpone verification of TLS session right before server handshake
The verify callback in OpenSSL is called pretty early, and at that time
it is not possible yet to check which connection it belongs to, and some
connections may have relaxed requirements.

So always return success in the Verify_openssl() callback, and postpone
validation of the TLS session until starting the server handshake in
cb_connserver_login_ssl(), when we know which server this connection
belongs to and which options (like "SSLVerify") are in effect.

The code doing this was already present in cb_connserver_login_ssl(),
but this patch adds a more prominent comment to the function.
2024-03-23 20:19:01 +01:00
Alexander Barton
679505aab9 S2S-TLS/OpenSSL: Fix handling of certificate information for incoming connections
Show proper certificate information for incoming connections, too, and
not "peer did not present a certificate", regardless if the client sent
a certificate or not.

And free the client certificate structure "peer_cert" on incoming
connections as well!
2024-03-23 20:19:01 +01:00
Alexander Barton
08647ab1e7 S2S-TLS/OpenSSL: Set the verification flags only once
Set the verification flags in the ConnSSL_SetVerifyProperties_openssl
function only, don't override them in ConnSSL_InitLibrary() afterwards.

No functional changes, now ConnSSL_SetVerifyProperties_openssl() sets
exactly the parameters which ConnSSL_InitLibrary() always overwrote ...
2024-03-23 20:19:01 +01:00
Alexander Barton
84b019b11f S2S-TLS/OpenSSL: Always setup host name verification
Setup host name verification even when the "SSLVerify" option is
disabled, because even then the peer can present a valid certificate and
validation would always(!) fail because of the missing host name
verification setup.
2024-03-23 20:19:01 +01:00
Alexander Barton
8f8bef9fae S2S-TLS: Remove leftover debug messages 2024-03-23 20:19:01 +01:00
Alexander Barton
5ca567a18c S2S-TLS: Add missing CAFile and CRLFile options to "configtest" output 2024-03-23 20:19:01 +01:00
Christoph Biedl
817937b218 Support for server certificate validation on server links [S2S-TLS]
This patch provides code to validate the server certificate in
server links, defeating nasty man-in-the-middle attacks on server
links.

Features:

- Check whether the certificate is signed by a trusted certificate
  authority (CA).
- Check the host name, including wildcard certificates and Subject
  Alternative Names.
- Optionally check against a certificate revocation list (CRL).
- Implementation for both OpenSSL and GnuTLS linkage.

Left for another day:

- Parameterize the TLS parameter of an outbound connection. Currently,
  it's hardcoded to disable all versions before TLSv1.1.
- Using certificate as CA-certificate. They work for GnuTLS only but
  perhaps this should rather raise an error there, too.
- Optional OCSP checking.
- Checking client certificates. Code is there but this first needs some
  consideration about the use cases. This could replace all other
  authentication methods, for both client-server and server-server
  connections.

This patch is based on a patch by Florian Westphal from 2009, which
implemented this for OpenSSL only:

  From: Florian Westphal <fw@strlen.de>
  Date: Mon, 18 May 2009 00:29:02 +0200
  Subject: SSL/TLS: Add initial certificate support to OpenSSL backend

Commit message modified by Alex Barton.

Closes #120, "Server links using TLS/SSL need certificate validation".
Supersedes PR #8, "Options for verifying and requiring SSL client
certificates", which had (incomplete?) code for OpenSSL, no GnuTLS.
2024-03-23 20:19:01 +01:00
Alexander Barton
1118b0e77c METATADA: Fix unsetting "cloakhost"
Correctly re-generate the "cloaked hostname" when removing the
"cloakhost" using an empty string by passing down NULL instead of the
empty string, which results in protocol violations (for example on
WHOIS).
2024-03-17 22:42:19 +01:00
Alexander Barton
ea7f4e07b7 Remove outdated, unsupported and broken support for splint(1) 2024-02-10 00:22:33 +01:00
Sebastian Andrzej Siewior
bdb55fb4b3 testsuite: Pass -nameopt to openssl s_client.
The default value for the -nameopt option changed in OpenSSL 3.2 from
`oneline' to `utf8'. The `oneline' option also included a space around
the fields which is not the case for `utf8'. This means that
	CN = my.first.domain.tld

changed to

	CN=my.first.domain.tld

and is now longer recognized, leading to test failure.
This can be fixed by either going back to `oneline' or keeping `utf8'
and adding additionally `space_eq'. Anoter way would be to teach the
expect that the space is optional.

Add explicit -nameopt option with `utf8,space_eq' which is understood by
by OpenSSL 3.2 and earlier to make explicit. Remove the wildcard.

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
2024-02-05 13:39:15 +01:00
Alexander Barton
a1c2ac5d5b 2nd attempt to always show the correct config file name ...
But we are getting there!
2024-01-23 22:21:33 +01:00
Alexander Barton
951c8b84ab Testsuite: Test for the openssl command before using it
And skip the tests calling it instead of failing!
2024-01-23 14:43:06 +01:00
Alexander Barton
14838a249f Correctly show the configuration file used 2024-01-23 14:43:06 +01:00
Alexander Barton
47d3872c60 Don't show the default config file name on config errors
The configuration can be set in drop-in files in the include directory,
too, so it is not clear in which file it is actually missing.
2024-01-21 20:15:47 +01:00
Alexander Barton
b4c8e74ccb Use a default "IncludeDir" only when no config file was specified
No longer use a default built-in value for the "IncludeDir" directive
when a configuration file was explicitly specified on the command line
using "--config"/"-f": This way no default include directory is scanned
when a possibly non-default configuration file is used which
(intentionally) did not specify an "IncludeDir" directive.

With this patch you now can use "-f /dev/null" for checking all built-in
defaults, regardless of any local configuration files in the default
drop-in directory (which would have been read in until this change).
2024-01-21 20:15:47 +01:00
Alexander Barton
aa92837b02 Do not log channel keys ("passwords") for predefined channels 2024-01-21 14:14:59 +01:00
Alexander Barton
3c39094b52 Deduce a server name when not set in the configuration
The server "Name" in the "[Global]" section of the configuration file is
optional now: When not set (or empty), ngIRCd now tries to deduce a
valid IRC server name from the local host name ("node name"), possibly
adding a ".host" extension when the host name does not contain a dot
(".") which is required in an IRC server name ("ID").

This new behaviour, with all configuration parameters now being
optional, allows running ngIRCd without any configuration file at all.
2024-01-21 01:20:46 +01:00
Alexander Barton
669d71f3fe Explicitly test for the empty string in Channel_UserHasMode()
Basically this is unnecessary, as Channel_UserModes() always returns a
valid pointer and strchr() can deal with an empty (NULL-terminated)
string perfectly fine, bit it makes the code a bit more obvious and
silences the following warning:

  In function ‘Channel_UserHasMode’,
      inlined from ‘Channel_Kick’ at channel.c:384:7:
  channel.c:784:16: warning: ‘strchr’ reading 1 or more bytes from a region
                    of size 0 [-Wstringop-overread]
    784 |         return strchr(Channel_UserModes(Chan, Client), Mode) != NULL;
        |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This was seen with "gcc (Debian 12.2.0-14) 12.2.0" at least.
2024-01-20 16:43:54 +01:00
Alexander Barton
c83d55f758 Annotate "fall through" cases to silence warnings
Add a "/* fall through */" annotation to "case" statements which
actually should "fall through" to silences GCC warning like this:

  hash.c: In function ‘jenkins_hash’:
  hash.c:110:27: warning: this statement may fall through
                 [-Wimplicit-fallthrough=]
    110 |                 case 12: c+=((UINT32)k[11])<<24;
        |                          ~^~~~~~~~~~~~~~~~~~~~~
2024-01-18 22:49:48 +01:00
Alexander Barton
d702ebab0a Spelling fixes, mostly in file comments 2024-01-16 22:32:33 +01:00
Alexander Barton
00dc9d2845 Do IDENT requests even when DNS lookups are disabled
Without this patch, disabling DNS in the configuration disabled IDENT
lookups as well (for no good reason).

This patch allows enabling/disabling DNS lookups and IDENT requests
completely separately and enhances the messages sent to the client when
"NoticeBeforeRegistration" is enabled, too.

Thanks for reporting this, Miniontoby!

Closes #291.
2024-01-16 22:32:33 +01:00
Alexander Barton
a06f33d4e5 Channel Admins are not allowed to set Channel Owner status!
This was reported back in April 2021, thanks Sarah!

    Subject: NGIRCD bug report
    Date: April 28 2021, 14:30:08 MESZ
    To: alex@barton.de

    Hello,

    I am writing to you to report a bug in ngircd.
    In any give channel, if an user is with mode +a (admin), he/she can
    sets mode +/-q(owner) to any other user. This is not inline with the
    documentation.

    I've looked into the code irc-mode.c, apparently an if block is
    missing. Below are the code snippets that I believe fixes the bug.

This patch is what Sarah sent in. Thanks a lot!
2024-01-11 15:12:54 +01:00
Alexander Barton
2877706660 Test suite: Update for OpenSSL 3.x 2024-01-11 15:12:54 +01:00
Alexander Barton
2448d047f9 Allow SSL client-only configurations without keys/certificates
You don't need to configure certificates/keys as long as you don't
configure SSL-enabled listening ports.

This can make sense when you want to only link your local daemon to an
uplink server using SSL and only have clients on your local host or in
you fully trusted network, where SSL is not required.
2024-01-11 15:12:54 +01:00
Alexander Barton
0061394d7f 2024 =:) 2024-01-11 15:11:56 +01:00
Alexander Barton
bc7148f4ac Fix showing the "Ident" option in --configtest output
We tested for the wrong #define ... ooops!
2024-01-06 16:21:01 +01:00
Alexander Barton
f96966a62f Change GnuTLS "slot handling" messages to debug level
Those messages are about an internal implementation detail, not relevant
for an administrator of ngIRCd.
2024-01-06 16:21:01 +01:00
Alexander Barton
7c90264f1f Enlarge buffer for log messages
For example, SSL/TLS certificate information can easily get longer than
256 characters. So enlarge the log buffer to 1 KB.
2024-01-06 16:21:01 +01:00
Alexander Barton
21c1751b04 Respect "SSLConnect" option for incoming connections
Don't accept incoming plain-text ("non SSL") server connections for
servers configured with "SSLConnect" enabled.

If "SSLConnect" is not set for an incoming connection the server still
accepts both plain-text and encrypted connections.

This change prevents an authenticated client-server being able to force
the server-server to send its password on a plain-text connection when
SSL/TLS was intended.
2024-01-06 16:21:01 +01:00
Alexander Barton
843cbfc0f3 Always initiate closing a connection on errors.
Always try to close a connection with errors immediately, but try hard
to avoid too much recursion.

Without this patch, an outgoing server connection could get stuck in an
"endless" state trying to write out data over and over again.

This tries to fix 04de1423eb.
2024-01-06 16:21:01 +01:00
Valentin Lorentz
0714466af8 Return ERR_NOTEXTTOSEND on empty PRIVMSG content
They are dropped further down the line anyway; and sending ERR_NOTEXTTOSEND
early matches other servers' behavior.
2023-09-17 22:25:40 +02:00
Alexander Barton
8fdb8f90b1 Merge branch 'katp32/master'
Thanks Katherine Peeters for the patch and pull request!

Closes #294.

* katp32/master:
  Improve documentation for --syslog
  Added command line flag to enable syslog
  Split NoSyslog from behaviour of NoDaemon
2023-09-17 21:37:45 +02:00
Alexander Barton
a106d18d7d Conf_Test(): Use yesno_to_str() instead of individual tests and output 2023-09-17 20:28:52 +02:00
Alexander Barton
a7f448e713 Channel autojoin: Add missing variable in --configtest output 2023-09-17 20:27:14 +02:00
Alexander Barton
232c7382de Silence compiler warning in Init_New_Client()
Use strdup() instead of pointless strndup() to fix the following
compiler warning:

client.c: In function ‘Init_New_Client’:
client.c:216:32: warning: ‘strndup’ specified bound 127 exceeds source size 5 [-Wstringop-overread]
  216 |                 client->away = strndup(DEFAULT_AWAY_MSG, CLIENT_AWAY_LEN - 1);
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2023-09-17 20:16:35 +02:00
Alexander Barton
30ba325dde Various fixes and enhancements for the "Autojoin" patch
- Bring sample-ngircd.conf and ngircd.conf.5 description in line.
- Fix configuration parsing, it always showed the 'Unknown variable
  "Autojoin"' error message, even when everything was perfectly fine.
- And fix a build error (at least on macOS with Apple Clang 14):
    login.c:234:3: error: call to undeclared function 'IRC_JOIN'; ISO
    C99 and later do not support implicit function declarations
    [-Wimplicit-function-declaration]
       IRC_JOIN(Client, &Req);
       ^
  The #include for the "irc.channel.h" header was missing!
- Remove a unused variable that caused a compiler warning:
    login.c:222:12: warning: unused variable 'n' [-Wunused-variable]
       size_t i, n, channel_count = array_length(&Conf_Channels, sizeof(*conf_chan));
                 ^
- Add a explicit cast to fix a compiler warning:
    login.c:235:15: warning: assigning to 'char *' from 'const char[51]'
    discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
       Req.argv[0] = conf_chan->name;
                   ^ ~~~~~~~~~~~~~~~
2023-09-17 19:56:07 +02:00
Ivan Agarkov
cfd7d4288e Channel autojoin functionality 2023-09-16 12:40:33 +02:00
Alexander Barton
3b70f4ba0c 2023! 2023-08-03 14:22:53 +02:00
Alexander Barton
335ae4f0d0 Hide +i users on "WHOIS <pattern>"
Let's behave like most(?) other IRC daemons (at least ircd2.11) and hide
all +i users when WHOIS is used with a pattern. Otherwise privacy of
this users is not guaranteed and the +i mode a bit useless ...

Reported by Cahata on #ngircd, thanks!
2023-08-03 10:57:27 +02:00
Alexander Barton
63ad3b9acd Update the final "closing connection" message
Add some more information (nick name, user name, host name) and bring it
in line with some other implementations (at least ircd2.11 and Hybrid).
2023-07-18 11:45:01 +02:00
Alexander Barton
0035e0d778 Fix RPL_INVITING message: It must originate from the server
All numeric replies must originate from an IRC server, never from a
client. So fix the RPL_INVITING message!

Thanks tommyrot for reporting this!

Closes #307.
2023-07-18 11:42:07 +02:00
Alexander Barton
0f90a059b6 Enhance log messages for refused connections 2023-07-05 11:03:02 +02:00
Alexander Barton
50114cd017 Add "+DEBUG" to the version string only when configured with --enable-debug
The debug log messages are always available and a runtime option (since
commit c7de505c), but the assert()'s are only active when ngIRCd was
configured with the "--enable-debug" option.

So only add "+DEBUG" to the version string when the latter is the case.
2023-01-02 23:51:15 +01:00
michi
c7de505c91 Make the debug loglevel always available
This basically means to unifdef DEBUG in (almost) all places.
We keep it in src/portab/portab.h so DEBUG stays available to
enable assert(). Also add a comment about this.
2023-01-02 22:39:16 +01:00
Alexander Barton
8e9c789ae1 Better validate MODE +k & +l parameters and return errors
Implement new numeric ERR_INVALIDMODEPARAM_MSG(696) and:

- Reject channel keys with spaces and return ERR_INVALIDMODEPARAM_MSG;
  This was possible until now and resulted in garbled IRC commands later.
- Reject empty channel keys and return ERR_INVALIDMODEPARAM_MSG;
  This was possible until now and resulted in garbled IRC commands later.
- Return ERR_INVALIDMODEPARAM_MSG when user limit is out of bounds;
  This was silently ignored until now.

Closes #290. Thanks Val Lorentz for reporting it!
2023-01-02 22:32:16 +01:00
Alexander Barton
3c9c54989e Channel modes +k & +l: Always report an error when a parameter is missing
This relates to #290 and considerations which errors to show when: and I
think it is the better approach to give feedback instead of silently
failing.

Note that this code path is also used when handling modes of channels
defined in "[Channel]" blocks in configuration files: in this case the
client is the local server and we can't send messages to it, because it
has no socket connection! Therefore we need those "is_machine" checks
and log an error im this case.
2023-01-02 21:48:42 +01:00
Alexander Barton
0ea1715d00 Refactor Channel_Mode(), get rid of some nesting
No functional changes.
2023-01-02 21:25:28 +01:00
michi
24f956abf7 Allow ircops to use WHO on any channel. 2023-01-02 21:17:29 +01:00