🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
5 messages
5 total messages Started by Andreas Barth Fri, 04 Apr 2003 12:07
nnrp: patch to restrict cancels
#64752
Author: Andreas Barth
Date: Fri, 04 Apr 2003 12:07
409 lines
15286 bytes
We had a recent discussion in de.admin.net-abuse.news about forged
cancels, starting with <dann.1047730329.fsf@debian.jens.unfaehig.de> ;
in a subthread (starting at <slrnb7effe.2ak.aba@postings.so.argh.org> )
a proposal was discussed to restrict the ability of posting cancels.
I've now implemented a patch for INN 2.3.5 (see below). The features
are:

- A user can only post cancels for articles that are local posted or
  were originally generated and canceled by a cancel-lock enabled
  newsreader. The administrator may however allow users in
  readers.conf to post cancels for every article.
- The patch adds just a very small burden on accepting articles and
  cancels with post and almost no burden at all for transfering
  articels.
- Any news system could detect whether a cancel for an article
  originating at your site is fraud.
  
The patch works as follows (just regarding the post-command in nnrpd):
- if a article is posted, - unless existing - a user cancel lock
  is added, and always an admin cancel lock is added.
- if a cancel (oder supersedes) is posted, a user cancel key is always
  added. Now it is checked, whether one of the keys[1] matches one of
  the locks. If yes, the cancel is accepted. The cancel is also
  accepted, if
  - the original article is (no longer) available,
  - the original article has no lock and was posted before a given
    time (to allow for the transition periode).
  Otherwise, the cancel is rejected.

[1] The article could also have a key created by the user agent.

  
This means that a user with an cancel lock enabled user agent can post
a cancel of one of his own postings on any newsserver. A Cancel for an
article that was posted by an user agent that doesn't use cancel locks
could only be posted on the same newsserver as the originating
article, but from every user there (that's not worse than today, where
it can be cancelled on every server). Furthermore, a patched server
doesn't accept a cancel for an article posted at any other site after
the named time, unless the secrets are shared.

However, the processing of (spam) cancels is not modified at all. This
patch only modifies the _posting_ of cancels (and supersedes) over nnrpd.

For compilation of a patched inn, the cancel lock library is needed
(it used to be at http://cssri.meowing.net/, but I get "ressource
locked" right now; so I put the .tar.gz at
http://home.arcor.de/andreas-barth/libcanlock-0.0.19980924.tar.gz ).
You must also create the files /etc/news/canlock.def and
/etc/news/canlock.adm and fill them with any characters (but please
use printable characters, that makes the live of fgets easier). The
patch needs some polishing before inclusion, especially review and
removing of the fixed path for the secret files.

I could forward-port the patch to inn-CURRENT, if wanted.


Andi
--------------------------
diff -Nur inn-2.3.5.orig/doc/man/readers.conf.5 inn-2.3.5/doc/man/readers.conf.5
--- inn-2.3.5.orig/doc/man/readers.conf.5	Sun Mar  9 03:00:44 2003
+++ inn-2.3.5/doc/man/readers.conf.5	Thu Apr  3 10:16:28 2003
@@ -407,6 +407,12 @@
 The client may post articles with Approved: headers (in other words, may
 approve articles for moderated newsgroups).  By default, this is not
 allowed.
+.IP "C" 3
+.IX Item "C"
+The client may post cancels for articles not originating from him nor
+this site (in other words, may forge cancels; this is needed by spam
+cancellers, but can do harm if used unsound).  By default, this is not
+allowed.
 .IP "N" 3
 .IX Item "N"
 The client may use the \s-1NEWNEWS\s0 command, overriding the global setting.
diff -Nur inn-2.3.5.orig/nnrpd/Makefile inn-2.3.5/nnrpd/Makefile
--- inn-2.3.5.orig/nnrpd/Makefile	Sun Mar  9 03:00:44 2003
+++ inn-2.3.5/nnrpd/Makefile	Wed Apr  2 21:42:19 2003
@@ -6,9 +6,11 @@
 
 ALL		= nnrpd
 
+CANLOCKLIB = -lcanlock
+
 SOURCES		= article.c group.c commands.c loadave.c misc.c newnews.c \
 		  nnrpd.c perl.c perm.c post.c python.c sasl_config.c \
-		  tls.c track.c
+		  tls.c track.c canlock.c
 
 INCLUDES	= nnrpd.h post.h sasl_config.h tls.h
 
@@ -32,7 +34,7 @@
 ##  Compilation rules.
 
 NNRPDLIBS	= $(LIBSTORAGE) $(LIBINN) $(EXTSTORAGELIBS) $(PERLLIB) \
-		  $(PYTHONLIB) $(SSLLIB) $(LIBS)
+		  $(PYTHONLIB) $(SSLLIB) $(LIBS) $(CANLOCKLIB)
 
 perl.o:		perl.c		; $(CC) $(CFLAGS) $(PERLINC) -c perl.c
 python.o:	python.c	; $(CC) $(CFLAGS) $(PYTHONINC) -c python.c
diff -Nur inn-2.3.5.orig/nnrpd/article.c inn-2.3.5/nnrpd/article.c
--- inn-2.3.5.orig/nnrpd/article.c	Sun Mar  9 03:00:44 2003
+++ inn-2.3.5/nnrpd/article.c	Thu Apr  3 09:13:41 2003
@@ -353,7 +353,7 @@
 /*
 **  Open the article for a given Message-ID.
 */
-STATIC BOOL ARTopenbyid(char *msg_id, ARTNUM *ap)
+BOOL ARTopenbyid(char *msg_id, ARTNUM *ap)
 {
     char		*p;
     HASH		hash = HashMessageID(msg_id);
Binary files inn-2.3.5.orig/nnrpd/article.o and inn-2.3.5/nnrpd/article.o differ
diff -Nur inn-2.3.5.orig/nnrpd/canlock.c inn-2.3.5/nnrpd/canlock.c
--- inn-2.3.5.orig/nnrpd/canlock.c	Thu Jan  1 01:00:00 1970
+++ inn-2.3.5/nnrpd/canlock.c	Thu Apr  3 10:47:28 2003
@@ -0,0 +1,162 @@
+/*
+ * $Revision: 1.2 $
+ */
+
+#if ! defined (lint)
+static const char *rcsid = "$Id: $";
+static void use_rcsid (const char *rid) {   /* Never called */
+                  use_rcsid (rcsid) ; use_rcsid (rid) ;
+}
+#endif
+
+
+#include <stdio.h>
+#include <sys/types.h>
+#include "configdata.h"
+#include "clibrary.h"
+#include "nnrpd.h"
+#include <canlock.h>
+
+BOOL checker(const char *key, const char *lock);
+BOOL ARTopenbyid(char *msg_id, ARTNUM *ap);
+
+char* canlock (char *msgid, char *name, int mode)
+{
+        FILE *secret;
+        unsigned char *p;
+        long filelen;
+        char csec[1024];
+        
+        if (!(secret=fopen(name, "r"))) {
+                syslog(L_ERROR, "Cant open input file %s (%m)", name);
+                return NULL;
+        }
+        if (!fgets(csec, 1024, secret)) {
+                syslog(L_ERROR, "Cant read input file %s (%m)", name);
+                return NULL;
+        }
+        fclose(secret);
+                
+        if (mode == CL_KEY) {
+                return sha_key(csec, strlen(csec), msgid, strlen(msgid));
+        }
+
+        return sha_lock(csec, strlen(csec), msgid, strlen(msgid));
+                
+}
+
+/*
+** Get the Cancel-Lock-Header and test
+** Partly cloned from CMDxpat by Andreas Barth
+**
+** some administrative decisions are compiled in here (what to do if the
+** articel doesn't exist, ...)
+*/
+#define ACCEPTOLD 1
+BOOL testcanlock(const char *Keys, const char *MessageID)
+{
+    char                *lock,*date;
+	ARTNUM              artnum;
+    time_t      t;
+
+    if (!ARTopenbyid(MessageID, &artnum)) return TRUE;
+    lock = GetHeader("Cancel-Lock", FALSE);
+#if ACCEPTOLD
+    date = GetHeader("Date", FALSE);
+#endif
+    ARTclose();
+    if (lock == NULL)
+#if ACCEPTOLD
+    {
+        if ((t = parsedate(date, NULL)) == -1)
+        //  Can't parse Date header, so we accept
+            return TRUE;
+        if (t < 1054425600)
+        // posted before 1st of June 2003, 0:00 UTC
+            return TRUE;
+        return FALSE;
+    // XXX isn't it needed to get rid of date? But CMDxpat doesn't do this.
+    }
+#else
+        return FALSE;
+#endif
+    // XXX isn't it needed to get rid of lock? But CMDxpat doesn't do this.
+    return checker(Keys, lock);
+}
+
+BOOL allowedhashchar(const char c) {
+    if ('\0' == c) return FALSE;
+    switch (c) {
+	case ':':
+	case '=':
+	case '-':
+	case '+':
+	case '/':
+	    // XXX are base64 chars missing here?
+	    return TRUE;
+    }
+    return isalnum(c);
+}
+
+char * tokencpy(const char *src, char *dest, int max) {
+    int i=0;
+    if (src[i]!='\0')
+	while((src[i]!='\0') && !allowedhashchar(src[i]))
+	    i++;
+
+    while(allowedhashchar(src[i]) && (i < max)) {
+	dest[i]=src[i];
+	i++;
+    }
+
+    dest[i]='\0';
+    if (src[i]!='\0')
+	while((src[i]!='\0') && !allowedhashchar(src[i]))
+	    i++;
+    return src+i;
+}
+
+#define BUFFSIZE 512
+BOOL checker(const char *key, const char *lock)
+{
+    char *k, *l;
+    char lockbuff[BUFFSIZE], keybuff[BUFFSIZE];
+    int i=0;
+
+    k=key;
+    l=lock;
+    while (*k != '\0') {
+	k=tokencpy(k, keybuff, BUFFSIZE);
+	while (*l != '\0') {
+	    l=tokencpy(l, lockbuff, BUFFSIZE);
+	    i++;
+	    if (realchecker(keybuff, lockbuff)) return TRUE;
+	}
+    }
+    return FALSE;
+}
+
+
+/* 
+ * cloned by Andreas Barth from
+ * canlocktest.c written by buffy
+ */
+
+BOOL realchecker(char *key, char *lock)
+{
+    char *rawkey, *rawlock;
+    char keytype[BUFFSIZE], locktype[BUFFSIZE];
+
+    rawkey = lock_strip_alpha(key, keytype);
+    rawlock = lock_strip_alpha(lock, locktype);
+
+    if (!strcmp(keytype, locktype)) {
+        if (!strcmp(keytype, "md5")) {
+            if (!md5_verify(rawkey, rawlock)) return TRUE;
+            else return FALSE;
+        } else if (!strcmp(keytype, "sha1")) {
+            if (!sha_verify(rawkey, rawlock)) return TRUE;
+            else return FALSE;
+        } else return FALSE;
+    } else return FALSE;
+}
diff -Nur inn-2.3.5.orig/nnrpd/commands.c inn-2.3.5/nnrpd/commands.c
--- inn-2.3.5.orig/nnrpd/commands.c	Sun Mar  9 03:00:44 2003
+++ inn-2.3.5/nnrpd/commands.c	Thu Apr  3 10:16:36 2003
@@ -91,6 +91,7 @@
     PERMcanpost = FALSE;
     PERMaccessconf->locpost = FALSE;
     PERMaccessconf->allowapproved = FALSE;
+    PERMaccessconf->allowforgecancel = FALSE;
 
     if (!*av) {
 	Reply("%d no authenticator\r\n", NNTP_SYNTAX_VAL);
@@ -196,6 +197,7 @@
     PERMaccessconf->locpost = strchr(fields[1], 'L') != NULL;
     if (strchr(fields[1], 'N') != NULL) PERMaccessconf->allownewnews = TRUE;
     PERMaccessconf->allowapproved = strchr(fields[1], 'A') != NULL;
+    PERMaccessconf->allowapproved = strchr(fields[1], 'C') != NULL;
     sprintf(PERMuser, "%s@%s", fields[2], fields[0]);
     (void)strcpy(PERMpass, fields[3]);
     (void)strcpy(accesslist, fields[4]);
diff -Nur inn-2.3.5.orig/nnrpd/nnrpd.h inn-2.3.5/nnrpd/nnrpd.h
--- inn-2.3.5.orig/nnrpd/nnrpd.h	Sun Mar  9 03:00:44 2003
+++ inn-2.3.5/nnrpd/nnrpd.h	Thu Apr  3 10:13:24 2003
@@ -66,6 +66,7 @@
     int allownewnews;
     int locpost;
     int allowapproved;
+    int allowforgecancel;
     int used;
     int localtime;
     int strippath;               
@@ -231,3 +232,7 @@
 int PY_authenticate(char *ClientHost, char *ClientIP, char *ServerHost, char *Username, char *Password, char *accesslist);
 int PY_authorize(char *ClientHost, char *ClientIP, char *ServerHost, char *Username, char *NewsGroup, int PostFlag, char **reply_message);
 #endif	/* DO_PYTHON */
+
+#define CL_LOCK 1
+#define CL_KEY 2
+char* canlock (char *msgid, char *name, int mode);
diff -Nur inn-2.3.5.orig/nnrpd/perm.c inn-2.3.5/nnrpd/perm.c
--- inn-2.3.5.orig/nnrpd/perm.c	Sun Mar  9 03:00:44 2003
+++ inn-2.3.5/nnrpd/perm.c	Thu Apr  3 10:17:08 2003
@@ -407,6 +407,7 @@
     curaccess->allownewnews = innconf->allownewnews;
     curaccess->locpost = FALSE;
     curaccess->allowapproved = FALSE;
+    curaccess->allowforgecancel = FALSE;
     curaccess->localtime = FALSE;
     curaccess->strippath = FALSE;
     curaccess->nnrpdperlfilter = TRUE;
@@ -752,6 +753,7 @@
 	    CLEAR_CONFIG(PERMpost);
 	}
 	curaccess->allowapproved = (strchr(tok->name, 'A') != NULL);
+	curaccess->allowforgecancel = (strchr(tok->name, 'C') != NULL);
 	curaccess->allownewnews = (strchr(tok->name, 'N') != NULL);
 	curaccess->locpost = (strchr(tok->name, 'L') != NULL);
 	SET_CONFIG(oldtype);
diff -Nur inn-2.3.5.orig/nnrpd/post.c inn-2.3.5/nnrpd/post.c
--- inn-2.3.5.orig/nnrpd/post.c	Sun Mar  9 03:00:44 2003
+++ inn-2.3.5/nnrpd/post.c	Thu Apr  3 10:26:40 2003
@@ -77,6 +77,10 @@
 #define _xcomplaintsto	22
     {   "NNTP-Posting-Date",	FALSE, HTstd },
 #define _nntppostdate	23
+    {   "Cancel-Lock",	TRUE, HTstd },
+#define _canlock	24
+    {   "Cancel-Key",	TRUE, HTstd },
+#define _cankey	25
     {   "Injector-Info",        FALSE,  HTstd },
     {	"Xref",			FALSE,	HTstd },
     {	"Summary",		TRUE,	HTstd },
@@ -318,6 +322,8 @@
     static char	datebuff[40];
     static char	localdatebuff[40];
     static char	orgbuff[SMBUF];
+    static char	canlockbuff[SMBUF];
+    static char	cankeybuff[SMBUF];
     static char	linebuff[40];
     static char	tracebuff[SMBUF];
     static char	complaintsbuff[SMBUF];
@@ -521,6 +527,45 @@
 	sprintf (complaintsbuff, "%s", NEWSMASTER);
     }
     HDR_SET(_xcomplaintsto ,complaintsbuff);
+
+
+	/* Set Cancel-Lock */
+    {
+        char *admlock, *userlock;
+        userlock=HDR(_canlock);
+        if (!(userlock))
+            userlock=canlock(HDR(_messageid), "/etc/news/canlock.def", CL_LOCK);
+
+        admlock=canlock(HDR(_messageid), "/etc/news/canlock.adm", CL_LOCK);
+        snprintf(canlockbuff, SMBUF, "%s %s", userlock, admlock);
+        HDR_SET(_canlock, canlockbuff);
+    }
+
+    /* Set Cancel-Key */
+    {
+        char *messageid=NULL;
+        if ((HDR(_control) && !(strncasecmp(HDR(_control), "cancel <", 7))))
+            messageid=HDR(_control)+7;
+
+        if (HDR(_supersedes)) messageid=HDR(_supersedes);
+
+        if (messageid) {
+            char *userkey;
+            userkey=canlock(messageid, "/etc/news/canlock.def", CL_KEY);
+            if (HDR(_cankey))
+                snprintf(cankeybuff, SMBUF, "%s %s", HDR(_cankey), userkey);
+            else snprintf(cankeybuff, SMBUF, "%s", userkey);
+
+            HDR_SET(_cankey, cankeybuff);
+
+            /* Verify the Cancel-Lock with the Key of the original article */
+            if (!PERMaccessconf->allowforgecancel &&
+                (!(testcanlock(cankeybuff, messageid)))) return Error;
+			/* This may be a place to verify that spam cancels follow
+			 * the cybercancel-Conventions
+			 */
+        }
+    }
 
     /* Clear out some headers that should not be here */
     if (PERMaccessconf->strippostcc) {
-- 
  My users get their dirty pics on the web, and use Usenet for what it was
  originally intended.                 Brian Edmonds in news.software.nntp
Re: nnrp: patch to restrict cancels
#64751
Author: Russ Allbery
Date: Fri, 04 Apr 2003 23:56
19 lines
1815 bytes
Andreas Barth <aba@not.so.argh.org> writes:

> We had a recent discussion in de.admin.net-abuse.news about forged
> cancels, starting with <dann.1047730329.fsf@debian.jens.unfaehig.de> ;
> in a subthread (starting at <slrnb7effe.2ak.aba@postings.so.argh.org> )
> a proposal was discussed to restrict the ability of posting cancels.
> I've now implemented a patch for INN 2.3.5 (see below). The features
> are:

I can take a look at this for INN 2.4.  Are you okay with your work being
included in the INN distribution under INN's regular license?  (Just
asking because I don't like to assume.)

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Re: nnrp: patch to restrict cancels
#64763
Author: Andreas Barth
Date: Sat, 05 Apr 2003 07:52
29 lines
2113 bytes
Russ Allbery wrote:
> Andreas Barth <aba@not.so.argh.org> writes:

>> We had a recent discussion in de.admin.net-abuse.news about forged
>> cancels, starting with <dann.1047730329.fsf@debian.jens.unfaehig.de> ;
>> in a subthread (starting at <slrnb7effe.2ak.aba@postings.so.argh.org> )
>> a proposal was discussed to restrict the ability of posting cancels.
>> I've now implemented a patch for INN 2.3.5 (see below). The features
>> are:
 
> I can take a look at this for INN 2.4.  Are you okay with your work being
> included in the INN distribution under INN's regular license?

Yes, certainly.
But:
- the function realchecker is derived from code written by Fluffy
  that was placed in the public domain.
- the function testcanlock is partly derived from code in
  nnrpd/article.c (function CMDxpat).
- the libcanlock functions are - except base64.c - placed in the
  public domain. base64.c is copyright by the ISC, but has not the
  standard INN licence.


Andi
-- 
  My users get their dirty pics on the web, and use Usenet for what it was
  originally intended.                 Brian Edmonds in news.software.nntp
Re: nnrp: patch to restrict cancels
#64765
Author: greg andruk
Date: Sat, 05 Apr 2003 13:23
21 lines
2399 bytes
Andreas Barth <aba@not.so.argh.org> writes:

> But:
> - the function realchecker is derived from code written by Fluffy
>   that was placed in the public domain.
> - the function testcanlock is partly derived from code in
>   nnrpd/article.c (function CMDxpat).
> - the libcanlock functions are - except base64.c - placed in the
>   public domain. base64.c is copyright by the ISC, but has not the
>   standard INN licence.

Just to reaffirm: yes, any project is free do do whatever it wants
with the base code.  Please advise if an explicit do-whatever-you-like
license is needed to cover locations that don't recognize public
domain work.

On the base64 function: it contains a weird disclaimer from IBM that
can probably be safely ignored (if that function was covered by any
IBM patents, any equivalent function would most likely be in trouble
too).
Re: nnrp: patch to restrict cancels
#64766
Author: Russ Allbery
Date: Sat, 05 Apr 2003 18:01
15 lines
1729 bytes
greg andruk <gja@meowing.net> writes:

> On the base64 function: it contains a weird disclaimer from IBM that can
> probably be safely ignored (if that function was covered by any IBM
> patents, any equivalent function would most likely be in trouble too).

I'll take a look at it; if there's a problem, I've written my own base64
functions a long time back that I'm happy to put in the public domain.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads