1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/crmf/respcli.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,137 @@ 1.4 +/* -*- Mode: C; tab-width: 8 -*-*/ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/* 1.11 + * This file will contain all routines needed by a client that has 1.12 + * to parse a CMMFCertRepContent structure and retirieve the appropriate 1.13 + * data. 1.14 + */ 1.15 + 1.16 +#include "cmmf.h" 1.17 +#include "cmmfi.h" 1.18 +#include "crmf.h" 1.19 +#include "crmfi.h" 1.20 +#include "secitem.h" 1.21 +#include "secder.h" 1.22 +#include "secasn1.h" 1.23 + 1.24 +CMMFCertRepContent* 1.25 +CMMF_CreateCertRepContentFromDER(CERTCertDBHandle *db, const char *buf, 1.26 + long len) 1.27 +{ 1.28 + PLArenaPool *poolp; 1.29 + CMMFCertRepContent *certRepContent; 1.30 + SECStatus rv; 1.31 + int i; 1.32 + 1.33 + poolp = PORT_NewArena(CRMF_DEFAULT_ARENA_SIZE); 1.34 + if (poolp == NULL) { 1.35 + return NULL; 1.36 + } 1.37 + certRepContent = PORT_ArenaZNew(poolp, CMMFCertRepContent); 1.38 + if (certRepContent == NULL) { 1.39 + goto loser; 1.40 + } 1.41 + certRepContent->poolp = poolp; 1.42 + rv = SEC_ASN1Decode(poolp, certRepContent, CMMFCertRepContentTemplate, 1.43 + buf, len); 1.44 + if (rv != SECSuccess) { 1.45 + goto loser; 1.46 + } 1.47 + if (certRepContent->response != NULL) { 1.48 + for (i=0; certRepContent->response[i] != NULL; i++) { 1.49 + rv = cmmf_decode_process_cert_response(poolp, db, 1.50 + certRepContent->response[i]); 1.51 + if (rv != SECSuccess) { 1.52 + goto loser; 1.53 + } 1.54 + } 1.55 + } 1.56 + certRepContent->isDecoded = PR_TRUE; 1.57 + return certRepContent; 1.58 + loser: 1.59 + PORT_FreeArena(poolp, PR_FALSE); 1.60 + return NULL; 1.61 +} 1.62 + 1.63 +long 1.64 +CMMF_CertResponseGetCertReqId(CMMFCertResponse *inCertResp) 1.65 +{ 1.66 + PORT_Assert(inCertResp != NULL); 1.67 + if (inCertResp == NULL) { 1.68 + return -1; 1.69 + } 1.70 + return DER_GetInteger(&inCertResp->certReqId); 1.71 +} 1.72 + 1.73 +PRBool 1.74 +cmmf_CertRepContentIsIndexValid(CMMFCertRepContent *inCertRepContent, 1.75 + int inIndex) 1.76 +{ 1.77 + int numResponses; 1.78 + 1.79 + PORT_Assert(inCertRepContent != NULL); 1.80 + numResponses = CMMF_CertRepContentGetNumResponses(inCertRepContent); 1.81 + return (PRBool)(inIndex >= 0 && inIndex < numResponses); 1.82 +} 1.83 + 1.84 +CMMFCertResponse* 1.85 +CMMF_CertRepContentGetResponseAtIndex(CMMFCertRepContent *inCertRepContent, 1.86 + int inIndex) 1.87 +{ 1.88 + CMMFCertResponse *certResponse; 1.89 + SECStatus rv; 1.90 + 1.91 + PORT_Assert(inCertRepContent != NULL && 1.92 + cmmf_CertRepContentIsIndexValid(inCertRepContent, inIndex)); 1.93 + if (inCertRepContent == NULL || 1.94 + !cmmf_CertRepContentIsIndexValid(inCertRepContent, inIndex)) { 1.95 + return NULL; 1.96 + } 1.97 + certResponse = PORT_ZNew(CMMFCertResponse); 1.98 + rv = cmmf_CopyCertResponse(NULL, certResponse, 1.99 + inCertRepContent->response[inIndex]); 1.100 + if (rv != SECSuccess) { 1.101 + CMMF_DestroyCertResponse(certResponse); 1.102 + certResponse = NULL; 1.103 + } 1.104 + return certResponse; 1.105 +} 1.106 + 1.107 +CMMFPKIStatus 1.108 +CMMF_CertResponseGetPKIStatusInfoStatus(CMMFCertResponse *inCertResp) 1.109 +{ 1.110 + PORT_Assert(inCertResp != NULL); 1.111 + if (inCertResp == NULL) { 1.112 + return cmmfNoPKIStatus; 1.113 + } 1.114 + return cmmf_PKIStatusInfoGetStatus(&inCertResp->status); 1.115 +} 1.116 + 1.117 +CERTCertificate* 1.118 +CMMF_CertResponseGetCertificate(CMMFCertResponse *inCertResp, 1.119 + CERTCertDBHandle *inCertdb) 1.120 +{ 1.121 + PORT_Assert(inCertResp != NULL); 1.122 + if (inCertResp == NULL || inCertResp->certifiedKeyPair == NULL) { 1.123 + return NULL; 1.124 + } 1.125 + 1.126 + return cmmf_CertOrEncCertGetCertificate( 1.127 + &inCertResp->certifiedKeyPair->certOrEncCert, inCertdb); 1.128 + 1.129 +} 1.130 + 1.131 +CERTCertList* 1.132 +CMMF_CertRepContentGetCAPubs (CMMFCertRepContent *inCertRepContent) 1.133 +{ 1.134 + PORT_Assert (inCertRepContent != NULL); 1.135 + if (inCertRepContent == NULL || inCertRepContent->caPubs == NULL) { 1.136 + return NULL; 1.137 + } 1.138 + return cmmf_MakeCertList(inCertRepContent->caPubs); 1.139 +} 1.140 +