security/nss/lib/crmf/cmmfasn1.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C; tab-width: 8 -*-*/
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "cmmf.h"
michael@0 7 #include "cmmfi.h"
michael@0 8 #include "secasn1.h"
michael@0 9 #include "secitem.h"
michael@0 10
michael@0 11 SEC_ASN1_MKSUB(SEC_SignedCertificateTemplate)
michael@0 12
michael@0 13 static const SEC_ASN1Template CMMFSequenceOfCertifiedKeyPairsTemplate[] = {
michael@0 14 { SEC_ASN1_SEQUENCE_OF, 0, CMMFCertifiedKeyPairTemplate}
michael@0 15 };
michael@0 16
michael@0 17 static const SEC_ASN1Template CMMFKeyRecRepContentTemplate[] = {
michael@0 18 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CMMFKeyRecRepContent)},
michael@0 19 { SEC_ASN1_INLINE, offsetof(CMMFKeyRecRepContent, status),
michael@0 20 CMMFPKIStatusInfoTemplate},
michael@0 21 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER |
michael@0 22 SEC_ASN1_XTRN | 0,
michael@0 23 offsetof(CMMFKeyRecRepContent, newSigCert),
michael@0 24 SEC_ASN1_SUB(SEC_SignedCertificateTemplate)},
michael@0 25 { SEC_ASN1_CONSTRUCTED | SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | 1,
michael@0 26 offsetof(CMMFKeyRecRepContent, caCerts),
michael@0 27 CMMFSequenceOfCertsTemplate},
michael@0 28 { SEC_ASN1_CONSTRUCTED | SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | 2,
michael@0 29 offsetof(CMMFKeyRecRepContent, keyPairHist),
michael@0 30 CMMFSequenceOfCertifiedKeyPairsTemplate},
michael@0 31 { 0 }
michael@0 32 };
michael@0 33
michael@0 34 SECStatus
michael@0 35 CMMF_EncodeCertRepContent (CMMFCertRepContent *inCertRepContent,
michael@0 36 CRMFEncoderOutputCallback inCallback,
michael@0 37 void *inArg)
michael@0 38 {
michael@0 39 return cmmf_user_encode(inCertRepContent, inCallback, inArg,
michael@0 40 CMMFCertRepContentTemplate);
michael@0 41 }
michael@0 42
michael@0 43 SECStatus
michael@0 44 CMMF_EncodePOPODecKeyChallContent(CMMFPOPODecKeyChallContent *inDecKeyChall,
michael@0 45 CRMFEncoderOutputCallback inCallback,
michael@0 46 void *inArg)
michael@0 47 {
michael@0 48 return cmmf_user_encode(inDecKeyChall, inCallback, inArg,
michael@0 49 CMMFPOPODecKeyChallContentTemplate);
michael@0 50 }
michael@0 51
michael@0 52 CMMFPOPODecKeyRespContent*
michael@0 53 CMMF_CreatePOPODecKeyRespContentFromDER(const char *buf, long len)
michael@0 54 {
michael@0 55 PLArenaPool *poolp;
michael@0 56 CMMFPOPODecKeyRespContent *decKeyResp;
michael@0 57 SECStatus rv;
michael@0 58
michael@0 59 poolp = PORT_NewArena(CRMF_DEFAULT_ARENA_SIZE);
michael@0 60 if (poolp == NULL) {
michael@0 61 return NULL;
michael@0 62 }
michael@0 63 decKeyResp = PORT_ArenaZNew(poolp, CMMFPOPODecKeyRespContent);
michael@0 64 if (decKeyResp == NULL) {
michael@0 65 goto loser;
michael@0 66 }
michael@0 67 decKeyResp->poolp = poolp;
michael@0 68 rv = SEC_ASN1Decode(poolp, decKeyResp, CMMFPOPODecKeyRespContentTemplate,
michael@0 69 buf, len);
michael@0 70 if (rv != SECSuccess) {
michael@0 71 goto loser;
michael@0 72 }
michael@0 73 return decKeyResp;
michael@0 74
michael@0 75 loser:
michael@0 76 if (poolp != NULL) {
michael@0 77 PORT_FreeArena(poolp, PR_FALSE);
michael@0 78 }
michael@0 79 return NULL;
michael@0 80 }
michael@0 81
michael@0 82 SECStatus
michael@0 83 CMMF_EncodeKeyRecRepContent(CMMFKeyRecRepContent *inKeyRecRep,
michael@0 84 CRMFEncoderOutputCallback inCallback,
michael@0 85 void *inArg)
michael@0 86 {
michael@0 87 return cmmf_user_encode(inKeyRecRep, inCallback, inArg,
michael@0 88 CMMFKeyRecRepContentTemplate);
michael@0 89 }
michael@0 90
michael@0 91 CMMFKeyRecRepContent*
michael@0 92 CMMF_CreateKeyRecRepContentFromDER(CERTCertDBHandle *db, const char *buf,
michael@0 93 long len)
michael@0 94 {
michael@0 95 PLArenaPool *poolp;
michael@0 96 CMMFKeyRecRepContent *keyRecContent;
michael@0 97 SECStatus rv;
michael@0 98
michael@0 99 poolp = PORT_NewArena(CRMF_DEFAULT_ARENA_SIZE);
michael@0 100 if (poolp == NULL) {
michael@0 101 return NULL;
michael@0 102 }
michael@0 103 keyRecContent = PORT_ArenaZNew(poolp, CMMFKeyRecRepContent);
michael@0 104 if (keyRecContent == NULL) {
michael@0 105 goto loser;
michael@0 106 }
michael@0 107 keyRecContent->poolp = poolp;
michael@0 108 rv = SEC_ASN1Decode(poolp, keyRecContent, CMMFKeyRecRepContentTemplate,
michael@0 109 buf, len);
michael@0 110 if (rv != SECSuccess) {
michael@0 111 goto loser;
michael@0 112 }
michael@0 113 if (keyRecContent->keyPairHist != NULL) {
michael@0 114 while(keyRecContent->keyPairHist[keyRecContent->numKeyPairs] != NULL) {
michael@0 115 rv = cmmf_decode_process_certified_key_pair(poolp, db,
michael@0 116 keyRecContent->keyPairHist[keyRecContent->numKeyPairs]);
michael@0 117 if (rv != SECSuccess) {
michael@0 118 goto loser;
michael@0 119 }
michael@0 120 keyRecContent->numKeyPairs++;
michael@0 121 }
michael@0 122 keyRecContent->allocKeyPairs = keyRecContent->numKeyPairs;
michael@0 123 }
michael@0 124 keyRecContent->isDecoded = PR_TRUE;
michael@0 125 return keyRecContent;
michael@0 126 loser:
michael@0 127 if (poolp != NULL) {
michael@0 128 PORT_FreeArena(poolp, PR_FALSE);
michael@0 129 }
michael@0 130 return NULL;
michael@0 131 }
michael@0 132

mercurial