2 * Copyright (c) 2012,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 * tsaDERUtilities.c - ASN1 templates Time Stamping Authority requests and responses.
24 * see rfc3161.asn1 for ASN.1 and other comments
27 #include <libDER/asn1Types.h>
28 #include <libDER/DER_Decode.h>
29 #include <AssertMacros.h>
30 #include <Security/cssmtype.h>
32 #include "tsaDERUtilities.h"
34 #ifndef DER_MULTIBYTE_TAGS
35 #error We expect DER_MULTIBYTE_TAGS
40 DERItem status
; // INTEGER
41 DERItem statusString
; // UTF8_STRING | SEC_ASN1_OPTIONAL
42 DERItem failInfo
; // BIT_STRING | SEC_ASN1_OPTIONAL
47 DERItem statusString
; // UTF8_STRING | SEC_ASN1_OPTIONAL
48 } DERPKIStatusStringInner
;
53 DERItem status
; /* PKIStatusInfo */
54 DERItem timeStampToken
; /* TimeStampToken */
58 const DERItemSpec DERTimeStampRespItemSpecs
[] =
60 { DER_OFFSET(DERTimeStampResp
, status
),
61 ASN1_CONSTR_SEQUENCE
, DER_DEC_NO_OPTS
},
62 { DER_OFFSET(DERTimeStampResp
, timeStampToken
),
63 ASN1_CONSTR_SEQUENCE
, DER_DEC_NO_OPTS
| DER_DEC_OPTIONAL
| DER_DEC_SAVE_DER
}
65 const DERSize DERNumTimeStampRespItemSpecs
= sizeof(DERTimeStampRespItemSpecs
) / sizeof(DERItemSpec
);
68 This code is here rather than in libsecurity_smime because
69 libsecurity_smime doesn't know about libDER
72 int DERDecodeTimeStampResponse(
73 const CSSM_DATA
*contents
,
75 CSSM_DATA
*derTimeStampToken
,
76 size_t *numUsedBytes
) /* RETURNED */
78 DERReturn drtn
= DR_ParamErr
;
79 DERDecodedInfo decodedPackage
;
83 DERItem derContents
= {.data
= contents
->Data
, .length
= contents
->Length
};
84 DERTimeStampResp derResponse
= {{0,},{0,}};
86 require_noerr(DERDecodeItem(&derContents
, &decodedPackage
), badResponse
);
88 rx
= DERParseSequenceContent(&decodedPackage
.content
,
89 DERNumTimeStampRespItemSpecs
, DERTimeStampRespItemSpecs
,
94 require_noerr(DERParseSequenceContent(&decodedPackage.content,
95 DERNumTimeStampRespItemSpecs, DERTimeStampRespItemSpecs,
96 &derResponse, 0), badResponse);
98 if (derStatus
&& derResponse
.status
.data
)
100 derStatus
->Data
= malloc(derResponse
.status
.length
);
101 derStatus
->Length
= derResponse
.status
.length
;
102 memcpy(derStatus
->Data
, derResponse
.status
.data
, derStatus
->Length
);
104 if (derTimeStampToken
&& derResponse
.timeStampToken
.data
)
106 derTimeStampToken
->Data
= malloc(derResponse
.timeStampToken
.length
);
107 derTimeStampToken
->Length
= derResponse
.timeStampToken
.length
;
108 memcpy(derTimeStampToken
->Data
, derResponse
.timeStampToken
.data
, derTimeStampToken
->Length
);
116 *numUsedBytes
= decodedPackage
.content
.length
+
117 decodedPackage
.content
.data
- contents
->Data
;