Hi Aravind:
Ok - to do verification, you need two things:
1: The certificate that you are trying to verify.
and
2: The trust anchor (CA Certificate) that you are trying to build a path back to.
If you don't have the second, then your security model is fatally flawed, as you have no point of trust to start the process from.
In Pathfinder, what you want to do is to call the callback - you are right to use pathfinder_dbus_verify as follows (in your own validation callback, whatever that is):
I'm going to assume that you have the certificate in the unsigned char * buffer 'cert' in DER format, and the size of that buffer in an size_t variable cert_size:
const char* hex = "0123456789ABCDEF";
unsigned char *iend;
iend = cert + cert_size;
char *certdata_str = new char[(cert_size * 2 + 1)];
unsigned char *cp = cert;
char *certdata_str_i = certdata_str;
while (cp < iend)
{
unsigned char ch = *cp++;
*certdata_str_i++ = hex[(ch >> 4) & 0xf];
*certdata_str_i++ = hex[ch & 0xf];
}
*certdata_str_i = 0;
const char *policy = "2.5.29.32.0"; // anyPolicy
char *errmsg;
int validated = pathfinder_dbus_verify(certdata_str, policy, 0, 0,
&errmsg);
And that's it. The first part of this code just converts the DER encoded certificate to a character based "hexified" buffer. After that, take that buffer, and run it against the pathfinder_dbus_verify() function. Validated will return 0 if it fails, and errmsg will be set accordingly, validated will be non-zero on success.
The validation (including checking CRLs, chasing AIA extensions, and other Path Discovery and Validation checks as defined by RFC3280) is all done in the pathfinder daemon, which you can set up with your trust anchors in the directory pointed to by:
[Trusted directories]
Extra certs = /tmp/trusted
(in this example, your trust anchors (CA Root Certificates) will be in /tmp/trusted)
You shouldn't have to implement any code to do verification and validation at all. Just supply the "peer" certificate in the callback, and give the Pathfinder daemon your trust anchor, and you should be good to go.
Hope this helps.
Patrick.
--
Personal Mail from Patrick Patterson
No company affiliation