diff --git a/include/freerdp/utils/certstore.h b/include/freerdp/utils/certstore.h index 2aa63be1a..c6ae4a4a2 100644 --- a/include/freerdp/utils/certstore.h +++ b/include/freerdp/utils/certstore.h @@ -21,6 +21,7 @@ struct rdp_certstore char* path; char* file; char* home; + int match; struct rdp_certdata* certdata; }; void certstore_create(rdpCertstore* certstore); diff --git a/libfreerdp-utils/cerstore.c b/libfreerdp-utils/cerstore.c index 46463c55b..0e9e23495 100644 --- a/libfreerdp-utils/cerstore.c +++ b/libfreerdp-utils/cerstore.c @@ -75,7 +75,8 @@ void certstore_init(rdpCertstore* certstore) int length; char* home_path; struct stat stat_info; - + + certstore->match=1; home_path = getenv("HOME"); if (home_path == NULL) @@ -134,3 +135,51 @@ void cerstore_free(rdpCertsore* certstore) xfree(certstore); } } + +int match_certdata(rdpCertdata* certdata) +{ + char *host; + char *p; + char *thumb_print; + int length; + unsigned char c; + FILE* cfp; + rdpCertstore* certstore=certstore_new(certdata); + cfp=certstore->fp; + length=strlen(certdata->thumbprint); + for(;;) + { + if((int)fread(host,sizeof(char),strlen(certdata->hostname),cfp) < strlen(certdata->hostname)) + break; + if((!strcmp(host,certdata->hostname)) && ((c=fgetc(cfp))==' ' || c=='\t') ) + { + ungetc(c,cfp); + while((c=fgetc(cfp))==' ' || c=='\t'); + if(c==EOF) + break; + ungetc(c,cfp); + thumb_print=xzalloc(length+1); + p=thumb_print; + while((p-thumb_print < length) && (*p=fgetc(cfp))!=EOF && *p!='\n' && *p==certdata->thumbprint+p-thumb_print) + p++; + if(p-thumb_print==length) + certdata->match=0; + else + certdata->match=-1; + break; + } + else + while(c!='\n'||c!=EOF) + c=fgetc(cfp); + if(c==EOF) + break; + else + ungetc(c,cfp); + } + return certdata->match; +} +void print_certdata(rdpCertstore* certstore) +{ + lseek(certstore->fp,0,SEEK_END); + fprintf(certstore->fp,"%s %s\n",certstore->certdata->hostname,certstore->certdata->thumbprint); +}