/*
 * Giacob: ldap ocsp cert status check 
 */
#include <lber.h>
#include <ldap.h>
#include "ocsp.h"
#define OCSP_RESPONSE_STATUS_NOTUSED 4
#define READ_ONLY "r"
#define WRITE_ONLY "w"
#define APPEND "a"
#define SERVER_CERT_PATH "/m/home/giacob/src/work_ocsp/apache/conf/ssl.crt/server.crt"
#define SERVER_KEY_PATH "/m/home/giacob/src/work_ocsp/apache/conf/ssl.key/server.key"
#define CA_CERT_PATH "/m/home/giacob/src/work_ocsp/apache/conf/ssl.crt/giacobca.crt"
#define OCSP_FILE_PATH "/tmp/ocsp.log"
/* 
 * Giacob: structures for ldap ocsp cert status check
 */
typedef struct cert_file_st
        {
        char *name;
        int   status;
        int   reason;
        char *time;
        char *this;
        char *next;
        } CERT_FILE;

typedef struct response_st
        {
        CERT_FILE *cert_file;
        int rsp_status;
        } RESPONSE_FILE;

typedef struct ldap_st
        {
        char *servers;
        char *base_dn;
        char *user;
        char *pwd;
        } LDAP_FILE;

typedef struct strtbl_st { int t; char *m; } STRTBL;

/*
 * Giacob: ldap cert status check messages
 */ 
STRTBL crlReasons[8]= {
        { OCSP_REVOKED_STATUS_UNSPECIFIED, "unspecified" }, 
        { OCSP_REVOKED_STATUS_KEYCOMPROMISE, "keyCompromise" },
        { OCSP_REVOKED_STATUS_CACOMPROMISE, "cACompromise" },
        { OCSP_REVOKED_STATUS_AFFILIATIONCHANGED, "affiliationChanged" },
        { OCSP_REVOKED_STATUS_SUPERSEDED, "superseded" },
        { OCSP_REVOKED_STATUS_CESSATIONOFOPERATION, "cessationOfOperation" },  
        { OCSP_REVOKED_STATUS_CERTIFICATEHOLD, "certificateHold" },
        { OCSP_REVOKED_STATUS_REMOVEFROMCRL, "removeFromCRL" } };
    
STRTBL respStatus[7] = {
        { OCSP_RESPONSE_STATUS_SUCCESSFULL, "successfull" },
        { OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, "malformedRequest" },
        { OCSP_RESPONSE_STATUS_INTERNALERROR, "internalError" },
        { OCSP_RESPONSE_STATUS_TRYLATER, "tryLater" },
        { OCSP_RESPONSE_STATUS_NOTUSED, "notUsed" },
        { OCSP_RESPONSE_STATUS_SIGREQUIRED, "sigRequired" },
        { OCSP_RESPONSE_STATUS_UNAUTHORIZED, "unauthorized" } };
            
STRTBL certStatus[3] = {
        { V_OCSP_CERTSTATUS_GOOD, "good" },
        { V_OCSP_CERTSTATUS_REVOKED, "revoked" },
        { V_OCSP_CERTSTATUS_UNKNOWN, "unknown" } };
            
STRTBL respIds[2] = {
        { V_OCSP_RESPID_NAME, "name" },
        { V_OCSP_RESPID_KEY, "key" } };

/*
 * Giacob: ldap cert status check hooks
 */
void ldap_check_hook(request_rec *r, X509 *xs, SSLSrvConfigRec *sc, conn_rec *conn);
OCSP_RESPONSE *ocsp_response_hook(request_rec *r, int id, int rsp_status, X509* xs, OCSP_CERTID *certid,
                                  OCSP_CERTSTATUS *ocsp_status, char *this, char *next);
OCSP_REQUEST *ocsp_request_hook(request_rec *r, X509* xs, OCSP_CERTID *certid);
RESPONSE_FILE *ocsp_ldap_hook(request_rec *r, X509 *xs, LDAP_FILE *ldap, char *mail, char *time);
void get_entry_hook(request_rec *r, LDAP *ld, LDAPMessage *entry, RESPONSE_FILE **response, char *cert, int len);
RESPONSE_FILE *ocsp_responder_hook(request_rec *r, X509 *xs, LDAP_FILE *ldap);
   

