From: Jean-Marc Pigeon (Delson) Date: Sat, 5 Jul 2025 19:33:57 +0000 (-0400) Subject: Adding module unidig.c to agg all digest-md5 function X-Git-Tag: tag-0.12~26 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=4d215af142e92d2a7ac648b277ee695c733a40e1;p=jmp%2Fmailleur Adding module unidig.c to agg all digest-md5 function --- diff --git a/lib/Makefile b/lib/Makefile index 5ed5c29..45a07b2 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -23,7 +23,7 @@ OBJS= \ lvleml.o \ gesspf.o gestcp.o geseml.o \ devlog.o devsoc.o devsql.o \ - unidns.o unieml.o unipar.o \ + unidig.o unidns.o unieml.o unipar.o \ uniprc.o unisig.o unisql.o unitls.o \ subafn.o subcnv.o subrou.o @@ -45,7 +45,7 @@ modrec.o: \ lvleml.o: \ subcnv.h subrou.h \ - unieml.h unidns.h \ + unidig.h unidns.h unieml.h \ lvleml.h lvleml.c gesspf.o: \ @@ -80,6 +80,10 @@ devsql.o: \ unimar.h \ devsql.h devsql.c +unidig.o: \ + subrou.h subcnv.h \ + unidig.h unidig.c + unidns.o: \ subafn.h subrou.h \ unidns.h unidns.c diff --git a/lib/lvleml.c b/lib/lvleml.c index 4734cb0..931a7ce 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -20,6 +20,7 @@ #include "subrou.h" #include "subcnv.h" +#include "unidig.h" #include "unieml.h" #include "devlog.h" #include "gestcp.h" @@ -436,7 +437,7 @@ while (proceed==true) { char *local; char *hexa; - local=cnv_cryptmd5(passwd,(unsigned char *)challenge); + local=dig_cryptmd5(passwd,(unsigned char *)challenge); hexa=cnv_tohexa(local); //(void) rou_alert(0,"%s anwr=<%s>",OPEP,answer); //(void) rou_alert(0,"%s hexa=<%s>",OPEP,hexa); @@ -518,6 +519,10 @@ while (proceed==true) { res=cnv_getb64(line); (void) snprintf(answer,sizeof(answer),"%s",res); (void) rou_alert(0,"JMPDBG Got <%s>",answer); + { + unsigned char *seq=(unsigned char *)"webmaster@example.com:devel5.safe.ca:xxx"; + (void) dig_hashmd5(seq); + } res=rou_freestr(res); line=rou_freestr(line); } @@ -625,7 +630,7 @@ while (proceed==true) { //local=cnv_cryptmd5(usr->passwd,(unsigned char *)seq); (void) rou_asprintf(&decoded,"%s%s%s%s",IOBNULL,name,IOBNULL,(char *)0); - local=cnv_cryptmd5("mailleur",(unsigned char *)seq); + local=dig_cryptmd5("mailleur",(unsigned char *)seq); hexa=cnv_tohexa(local); (void) rou_alert(0,"%s code=<%s>",OPEP,code); (void) rou_alert(0,"%s hexa=<%s>",OPEP,hexa); diff --git a/lib/subcnv.c b/lib/subcnv.c index 505edca..c4e167f 100644 --- a/lib/subcnv.c +++ b/lib/subcnv.c @@ -8,13 +8,9 @@ #include #include #include - -#define OPENSSL_NO_KRB5 #include +#include #include -#include -#include -#include #include "subcnv.h" @@ -167,63 +163,6 @@ coded=(char *)calloc(bptr->length+1,sizeof(char)); (void) BIO_free_all(b64); return coded; -#undef OPEP -} -/* - -*/ -/********************************************************/ -/* */ -/* Procedure to crypt a string with MD5 hash */ -/* function. */ -/* */ -/********************************************************/ -PUBLIC char *cnv_cryptmd5(const void *key,unsigned char *seq) - -{ -#define OPEP "subcnv.c:cnv_hashmd5," - -char *hashmd5; //function result -unsigned char *d5; //md5 hash result -u_int reslen; -int phase; -int proceed; - -hashmd5=(char *)0; -d5=(unsigned char *)0; -reslen=-1; -phase=1; -proceed=true; -while (proceed==true) { - switch (phase) { - case 0 : //do ve have good parameters - if ((key==(const void *)0)||(seq==(unsigned char *)0)) { - (void) fprintf(stderr,"%s key or seq undefined (Bug?)",OPEP); - phase=999; - } - break; - case 1 : //computing sequence - d5=HMAC(EVP_md5(),key,strlen(key),seq,strlen((const char *)seq),d5,&reslen); - if (d5==(unsigned char *)0) { - (void) fprintf(stderr,"%s No MD5 for key=<%s> and seq=<%s> (Bug?)", - OPEP,(char *)key,seq); - phase=999; - } - break; - case 2 : //duplicate md5 result - if (reslen>0) { - hashmd5=(char *)calloc(reslen+1,sizeof(char)); - (void) memmove((void *)hashmd5,(void *)d5,reslen); - } - break; - default : //SAFE Guard - proceed=false; - break; - } - phase++; - } -return hashmd5; - #undef OPEP } /* diff --git a/lib/subcnv.h b/lib/subcnv.h index dfb54ff..d3d728e 100644 --- a/lib/subcnv.h +++ b/lib/subcnv.h @@ -11,6 +11,9 @@ //base64 char 0 coding #define IOBNULL "\\0" +//MD5 hashing result +typedef unsigned char MD5TYP[17]; + //Procedure to convert a plain ASCII B64 sequence //to a plain ASCII sequence extern char *cnv_getb64(char *b64); @@ -19,13 +22,6 @@ extern char *cnv_getb64(char *b64); //to an ASCII B64 sequence extern char *cnv_setb64(const char *str); -//procedure to convert a string to a 128 Bit sequence -//as a string -extern char *cnv_hashmd5(char *seq); - -//Procedure to crypt a string with MD5 hash function -extern char *cnv_cryptmd5(const void *key,unsigned char *seq); - //Procedure to convert a string of character as an HEXA string extern char *cnv_tohexa(const char *str); diff --git a/lib/unidig.c b/lib/unidig.c new file mode 100644 index 0000000..ffb1866 --- /dev/null +++ b/lib/unidig.c @@ -0,0 +1,128 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* Implement all procedure to use digest-md5 */ +/* authentication exchange. */ +/* */ +/********************************************************/ +#include +#include +#include + +#include "subrou.h" +#include "subcnv.h" +#include "unidig.h" + +/* + * +*/ +/********************************************************/ +/* */ +/* Procedure to hash a string with MD5 hash */ +/* an return a 16+1 Bytes. */ +/* */ +/********************************************************/ +PUBLIC MD5TYP *dig_hashmd5(unsigned char *seq) + +{ +#define OPEP "subdig.c:dig_hashmd5," + +MD5TYP *md5; +EVP_MD_CTX *mdctx; +unsigned int digestlength; +int phase; +_Bool proceed; + +md5=(MD5TYP *)0; +mdctx=(EVP_MD_CTX *)0; +digestlength=sizeof(MD5TYP)-1; +phase=1; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //do we hae a sequence? + if ((seq==(unsigned char *)0)&&(strlen((const char *)seq)==0)) + phase=999; //no need to go further + break; + case 1 : //getting md5 context + if ((mdctx=EVP_MD_CTX_new())==(EVP_MD_CTX *)0) { + (void) fprintf(stdout,"%s Unable to open MD5 context (System?)",OPEP); + phase=999; //no need to go further + } + break; + case 2 : //doing hashing + (void) EVP_DigestInit_ex(mdctx,EVP_md5(),(ENGINE *)0); + (void) EVP_DigestUpdate(mdctx,seq,strlen((const char *)seq)); + break; + case 3 : //assign memory + md5=calloc(1,sizeof(MD5TYP)); + (void) EVP_DigestFinal_ex(mdctx,(unsigned char *)md5,&digestlength); + EVP_MD_CTX_free(mdctx); + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +return md5; + +#undef OPEP +} +/* + * +*/ +/********************************************************/ +/* */ +/* Procedure to crypt a string with MD5 hash */ +/* function. */ +/* */ +/********************************************************/ +PUBLIC char *dig_cryptmd5(const void *key,unsigned char *seq) + +{ +#define OPEP "subdig.c:dig_hashmd5," + +char *hashmd5; //function result +unsigned char *d5; //md5 hash result +u_int reslen; +int phase; +int proceed; + +hashmd5=(char *)0; +d5=(unsigned char *)0; +reslen=-1; +phase=1; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //do ve have good parameters + if ((key==(const void *)0)||(seq==(unsigned char *)0)) { + (void) fprintf(stderr,"%s key or seq undefined (Bug?)",OPEP); + phase=999; + } + break; + case 1 : //computing sequence + d5=HMAC(EVP_md5(),key,strlen(key),seq,strlen((const char *)seq),d5,&reslen); + if (d5==(unsigned char *)0) { + (void) fprintf(stderr,"%s No MD5 for key=<%s> and seq=<%s> (Bug?)", + OPEP,(char *)key,seq); + phase=999; + } + break; + case 2 : //duplicate md5 result + if (reslen>0) { + hashmd5=(char *)calloc(reslen+1,sizeof(char)); + (void) memmove((void *)hashmd5,(void *)d5,reslen); + } + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +return hashmd5; + +#undef OPEP +} diff --git a/lib/unidig.h b/lib/unidig.h new file mode 100644 index 0000000..31e73c6 --- /dev/null +++ b/lib/unidig.h @@ -0,0 +1,18 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* Define all procedure to use digest-md5 */ +/* authentication exchanges. */ +/* */ +/********************************************************/ +#ifndef UNIDIG +#define UNIDIG + +//procedure to convert a string to a 128 Bit sequence +//as a string +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); + +#endif