🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #64752

nnrp: patch to restrict cancels

#64752
From: 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
Technical Details
Message-ID: <slrnb8qtbh.le1.aba@postings.so.argh.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!uucp.muenster.de!news.uni-x.net!not.so.argh.org!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <slrnb8qtbh.le1.aba@postings.so.argh.org>
Subject: nnrp: patch to restrict cancels
Date: Fri, 04 Apr 2003 12:07:14 +0000
From: Andreas Barth <aba@not.so.argh.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!uucp.muenster.de!news.uni-x.net!not.so.argh.org!not-for-mail
Newsgroups: news.software.nntp
Organization: A not so poorly-installed InterNetNews site
Lines: 408
X-Trace: yrkBfWte7lbYGoihMV+zDJPpIgQ
Cancel-Lock: sha1:ntQ9RkiOVMnCKVi3yURupoKwKBA= sha1:JItvv7esg7koP3ymLUb5J1ju/a4=
User-Agent: slrn/0.9.7.4-canlock (Linux)