From 0f08b48fe5d8bff810a8d36e3746494b0a394996 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Sun, 6 Jul 2025 14:55:56 -0400 Subject: [PATCH] dig_getchallange procure ready --- lib/unidig.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/unidig.h | 6 +++++ 2 files changed, 79 insertions(+) diff --git a/lib/unidig.c b/lib/unidig.c index e4316c3..e93f51b 100644 --- a/lib/unidig.c +++ b/lib/unidig.c @@ -14,6 +14,9 @@ #include "subcnv.h" #include "unidig.h" +#define ALGO "md5-sess" +#define MAXBUF 2000 +#define CHARSET "utf-8" /* */ @@ -278,6 +281,76 @@ while (proceed==true) { } return hashmd5; +#undef OPEP +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to generate a unique DIGEST-M5 */ +/* challenge as an B64 string. */ +/* */ +/********************************************************/ +PUBLIC char *dig_getchallenge() + +{ +#define OPEP "unidig.c:dig_getchallenge," + +static char *comp[]={ + "realm=\"%s\"", //the LOCAL realm + ",nonce=\"%s\"", + ",maxbuf=%d", + ",qop=%s", + ",algorithm=%s", + ",charset=%s", + (char*)0 + }; + +char *challenge; + +challenge=(char *)calloc(MAXBUF,sizeof(char)); +for (int num=0;comp[num]!=(char *)0;num++) { + char loc[MAXBUF/2]; + + (void) memset(loc,'\000',sizeof(loc)); + switch (num) { + case 0 : //realm + (void) snprintf(loc,sizeof(loc),comp[num],REALM); + break; + case 1 : { //nonce + char *nonce; + char *b64; + + nonce=cnv_getrndstr(20); + b64=cnv_setb64(nonce); + (void) snprintf(loc,sizeof(loc),comp[num],b64); + b64=rou_freestr(b64); + nonce=rou_freestr(nonce); + } + break; + case 2 : //maxbuf + (void) snprintf(loc,sizeof(loc),comp[num],MAXBUF); + break; + case 3 : //qop + (void) snprintf(loc,sizeof(loc),comp[num],"auth"); + break; + case 4 : //algorithm + (void) snprintf(loc,sizeof(loc),comp[num],ALGO); + break; + case 5 : //charset + (void) snprintf(loc,sizeof(loc),comp[num],CHARSET); + break; + default : //none expect field BUG! + (void) rou_alert(0,"%s field[%d]=%s not treated (BUG!)",OPEP,num,comp[num]); + challenge=rou_freestr(challenge); + break; + } + if (strlen(loc)>0) + (void) strcat(challenge,loc); + } +return challenge; + #undef OPEP } /* diff --git a/lib/unidig.h b/lib/unidig.h index fa856c4..cecc3c1 100644 --- a/lib/unidig.h +++ b/lib/unidig.h @@ -8,6 +8,8 @@ #ifndef UNIDIG #define UNIDIG +#define REALM APPNAME"-email" + typedef struct { //DIGEST-MD5 challange response structure char *username; //username requesting authentication char *realm; //Challenge realm @@ -37,6 +39,10 @@ extern MD5TYP *dig_hashmd5(unsigned char *seq); //Procedure to crypt a string with MD5 hash function extern char *dig_cryptmd5(const void *key,unsigned char *seq); +//Procedure to generate a DISGEST-MD5 challaneg as a +//b64 string. +extern char *dig_getchallenge(); + //Procedure to compute local response to challenge and //check if the remote session is the same extern _Bool dig_checkresp(RSPTYP *resp,char *secret); -- 2.47.3