#include "subcnv.h"
#include "unidig.h"
+#define ALGO "md5-sess"
+#define MAXBUF 2000
+#define CHARSET "utf-8"
/*
\f
*/
}
return hashmd5;
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* 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
}
/*
#ifndef UNIDIG
#define UNIDIG
+#define REALM APPNAME"-email"
+
typedef struct { //DIGEST-MD5 challange response structure
char *username; //username requesting authentication
char *realm; //Challenge realm
//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);