Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

I have connect to a https server successfully, and in the callback function of ISSL_Negotiate,I want to get some info of the server's certification, such as subject and so on, but I failed to get it, I write like this:

void NegotiateCb(void * user)
{
int n = 0;
int ok = 0;
PSSLCtx pCtx = (PSSLCtx)user;
SSLInfo * pinfo = pCtx->pInfo;

X509PartRequest Req;
X509CertPart Res;

// get server certification info here
Req.nCertWebOpt = WEBOPT_X509_CHAIN_CERT;
Req.nCertIndex = 0;
Req.nInstance = 0;
Req.pcRawOID = NULL;
Req.uASNOID = ASNOID_X500_O;
Req.uCertPart = X509CHAIN_FIELD_SUBJECT;

pChain = pCtx->pGetChain;
ok = IX509CHAIN_GetFieldPart(pChain, &Req, &Res);

Req.nCertWebOpt = WEBOPT_X509_LEAF_CERT;
ok = IX509CHAIN_GetFieldPart(pChain, &Req, &Res);

Req.nCertWebOpt = WEBOPT_X509_ROOT_CERTS;
ok = IX509CHAIN_GetFieldPart(pChain, &Req, &Res);

I have tried 3-times use 3 type cert parameter

when I used WEBOPT_X509_CHAIN_CERT: ok is AEE_X509_NO_CHAIN_YET
when I used WEBOPT_X509_LEAF_CERT or WEBOPT_X509_ROOT_CERTS: ok is EFAILED

and I call negotiate like:

ISSL * pSsl = NULL;
IWebOpts * pOpts = NULL;
IX509Chain * pChain = NULL;

SSLInfo * pinfo = MALLOC(sizeof(SSLInfo));
WebOpt opt;

PSSLCtx pCtx = (PSSLCtx)user;

AEECallback *pcb = MALLOC(sizeof(AEECallback));

int ok = ISHELL_CreateInstance(pCtx->pShell, AEECLSID_SSL, &pSsl);

ok = ISHELL_CreateInstance(pCtx->pShell, AEECLSID_X509CHAIN, &pChain);

ok = ISHELL_CreateInstance(pCtx->pShell, AEECLSID_WEBOPTS, &pOpts);

MEMSET(pinfo, 0x00, sizeof(SSLInfo));

opt.nId = WEBOPT_SSL_TRUST_MODE;
opt.pVal = (void *)SSL_TRUST_MODE_CHECK;
IWEBOPTS_AddOpt(pOpts, &opt);

opt.nId = WEBOPT_SSL_NEGOTIATE_HANDLER;
opt.pVal = SSLHandler;
IWEBOPTS_AddOpt(pOpts, &opt);

opt.nId = WEBOPT_SSL_NEGOTIATE_HANDLER_DATA;
opt.pVal = user;
IWEBOPTS_AddOpt(pOpts, &opt);

g_pRootCertData = ReadRootCertData(pCtx->pShell);
opt.nId = WEBOPT_X509_ROOT_CERTS;
opt.pVal = g_pRootCertData;
IWEBOPTS_AddOpt(pOpts, &opt);

opt.nId = WEBOPT_X509_HOST;
opt.pVal = "iacj002918.inc.iac";
IWEBOPTS_AddOpt(pOpts, &opt);

opt.nId = WEBOPT_SSL_WANT_X509_CHAIN;
opt.pVal = (void*)TRUE;
IWEBOPTS_AddOpt(pOpts, &opt);

ISSL_SetSocket(pSsl, pCtx->pSimSock);

pCtx->pGetChain = pChain;
pCtx->pInfo = pinfo;
pCtx->pSsl = pSsl;

MEMSET(pcb, 0x00, sizeof(AEECallback));
pcb->pfnNotify = NegotiateCb;
pcb->pNotifyData = pCtx;

ISSL_Negotiate(pSsl, (pSsl, pinfo, &pChain, pcb, WEBOPT_DEFAULTS, pOpts, WEBOPT_END));

I have no idea how to get info I want, thanks