2 * Copyright (c) 2006-2008,2011-2012 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@
24 #include <architecture/byte_order.h>
25 #include <string.h> /* bzero() */
26 #include <stdlib.h> /* exit() */
27 #include <assert.h> /* assert() */
28 #include <stdio.h> /* XXX/gh because utilities/debugging.h doesn't */
29 #include <security_utilities/debugging.h>
33 // All functions with the "writes" comment write to memory without regard for size only operation. This is okay as long as they aren't used "naked", ie. as toplevel encoders. For our purposes they're always in a struct or array, or with a pointer pointing at them.
36 bool_t
sec_xdr_clip_long(XDR
*xdrs
, long *objp
)
40 if (objp
&& xdrs
->x_op
== XDR_ENCODE
)
41 clip
= *objp
& UINT32_MAX
;
42 if (!xdr_uint32(xdrs
, &clip
))
44 if (objp
&& xdrs
->x_op
== XDR_DECODE
)
50 bool_t
xdr_voidptr(XDR
*xdrs
, void **objp
)
55 ptr
= (intptr_t)*objp
;
56 if (!sec_xdr_clip_long(xdrs
, &ptr
))
63 bool_t
xdr_CSSM_DATA(XDR
*xdrs
, CSSM_DATA
*objp
)
65 u_int valueLength
; // objp->Length is a size_t
66 if (xdrs
->x_op
== XDR_ENCODE
) {
67 if (objp
->Length
> (u_int
)~0)
69 valueLength
= (u_int
)objp
->Length
;
71 if (!sec_xdr_bytes(xdrs
, &objp
->Data
, &valueLength
, ~0))
73 if (xdrs
->x_op
== XDR_DECODE
)
74 objp
->Length
= valueLength
;
78 bool_t
xdr_CSSM_GUID(XDR
*xdrs
, CSSM_GUID
*objp
)
80 return xdr_opaque(xdrs
, (char *)objp
, sizeof(CSSM_GUID
));
83 bool_t
xdr_CSSM_VERSION(XDR
*xdrs
, CSSM_VERSION
*objp
)
85 if (!xdr_uint32(xdrs
, &objp
->Major
))
87 if (!xdr_uint32(xdrs
, &objp
->Minor
))
92 bool_t
xdr_CSSM_SUBSERVICE_UID(XDR
*xdrs
, CSSM_SUBSERVICE_UID
*objp
)
94 if (!xdr_CSSM_GUID(xdrs
, &objp
->Guid
))
96 if (!xdr_CSSM_VERSION(xdrs
, &objp
->Version
))
98 if (!xdr_uint32(xdrs
, &objp
->SubserviceId
))
100 if (!xdr_CSSM_SERVICE_TYPE(xdrs
, &objp
->SubserviceType
))
105 bool_t
xdr_CSSM_NET_ADDRESS(XDR
*xdrs
, CSSM_NET_ADDRESS
*objp
)
107 if (!xdr_CSSM_NET_ADDRESS_TYPE(xdrs
, &objp
->AddressType
))
109 if (!xdr_CSSM_DATA(xdrs
, &objp
->Address
))
114 // XXX/cs crypto_data will automagically send callback data when necessary, on the pass out it will reappear in Param, which is also the alternative data sent. So Callback!=NULL means Param is crypto callback data, otherwise it is param data.
115 bool_t
xdr_CSSM_CRYPTO_DATA(XDR
*xdrs
, CSSM_CRYPTO_DATA
*objp
)
117 void *cb
= (void *)objp
->Callback
;
118 if (!xdr_voidptr(xdrs
, &cb
))
120 if (!xdr_voidptr(xdrs
, &objp
->CallerCtx
))
123 // Encode callback result if existing, otherwise just param
124 // Result comes back in Param
125 if (xdrs
->x_op
== XDR_ENCODE
&& objp
->Callback
)
127 CSSM_CALLBACK func
= objp
->Callback
;
130 if ((err
= func(&data
, objp
->CallerCtx
)))
131 return (FALSE
); // XXX/cs meaningfully return err
132 if (!xdr_CSSM_DATA(xdrs
, &data
))
137 if (!xdr_CSSM_DATA(xdrs
, &objp
->Param
))
143 bool_t
inline xdr_CSSM_LIST_ELEMENT(XDR
*xdrs
, CSSM_LIST_ELEMENT
*objp
)
145 if (!xdr_CSSM_WORDID_TYPE(xdrs
, &objp
->WordID
))
147 if (!xdr_CSSM_LIST_ELEMENT_TYPE(xdrs
, &objp
->ElementType
))
149 switch(objp
->ElementType
) {
150 case CSSM_LIST_ELEMENT_DATUM
:
151 if (!xdr_CSSM_DATA(xdrs
, &objp
->Element
.Word
)) return (FALSE
); break;
152 case CSSM_LIST_ELEMENT_SUBLIST
:
153 if (!xdr_CSSM_LIST(xdrs
, &objp
->Element
.Sublist
)) return (FALSE
); break;
154 case CSSM_LIST_ELEMENT_WORDID
:
157 secinfo("secxdr", "Illegal CSSM_LIST_ELEMENT type: %u", objp
->ElementType
); return (FALSE
);
160 if (!sec_xdr_pointer(xdrs
, (uint8_t**)&objp
->NextElement
, sizeof(CSSM_LIST_ELEMENT
), (xdrproc_t
)xdr_CSSM_LIST_ELEMENT
))
166 bool_t
xdr_CSSM_LIST(XDR
*xdrs
, CSSM_LIST
*objp
)
168 if (!xdr_CSSM_LIST_TYPE(xdrs
, &objp
->ListType
))
170 if (!sec_xdr_pointer(xdrs
, (uint8_t**)&objp
->Head
, sizeof(CSSM_LIST_ELEMENT
), (xdrproc_t
)xdr_CSSM_LIST_ELEMENT
))
172 // if we're restoring things, make sure to fix up Tail to point
173 // to the right place
174 if (xdrs
->x_op
== XDR_DECODE
)
176 bool_t size_alloc
= sec_xdr_arena_size_allocator(xdrs
);
178 for (objp
->Tail
= objp
->Head
; objp
->Tail
&& objp
->Tail
->NextElement
; objp
->Tail
= objp
->Tail
->NextElement
);
183 bool_t
xdr_CSSM_SAMPLE(XDR
*xdrs
, CSSM_SAMPLE
*objp
)
185 if (!xdr_CSSM_LIST(xdrs
, &objp
->TypedSample
))
187 if (!sec_xdr_pointer(xdrs
, (uint8_t**)&objp
->Verifier
, sizeof(CSSM_SUBSERVICE_UID
), (xdrproc_t
)xdr_CSSM_SUBSERVICE_UID
))
192 bool_t
xdr_CSSM_SAMPLEGROUP(XDR
*xdrs
, CSSM_SAMPLEGROUP
*objp
)
194 assert(sizeof(objp
->NumberOfSamples
) == sizeof(int));
195 if (!sec_xdr_array(xdrs
, (uint8_t**)&objp
->Samples
, (u_int
*)&objp
->NumberOfSamples
, ~0, sizeof(CSSM_SAMPLE
), (xdrproc_t
)xdr_CSSM_SAMPLE
))
200 bool_t
xdr_CSSM_ENCODED_CERT(XDR
*xdrs
, CSSM_ENCODED_CERT
*objp
)
203 if (!xdr_CSSM_CERT_TYPE(xdrs
, &objp
->CertType
))
205 if (!xdr_CSSM_CERT_ENCODING(xdrs
, &objp
->CertEncoding
))
207 if (!xdr_CSSM_DATA(xdrs
, &objp
->CertBlob
))
212 bool_t
xdr_CSSM_CERTGROUP(XDR
*xdrs
, CSSM_CERTGROUP
*objp
)
214 if (!xdr_CSSM_CERT_TYPE(xdrs
, &objp
->CertType
))
216 if (!xdr_CSSM_CERT_ENCODING(xdrs
, &objp
->CertEncoding
))
219 // NumCerts encoded as part of sec_xdr_array below (we need it
220 // before the switch on decode)
221 if (!xdr_CSSM_CERTGROUP_TYPE(xdrs
, &objp
->CertGroupType
))
224 switch (objp
->CertGroupType
) {
225 case CSSM_CERTGROUP_DATA
:
226 if (!sec_xdr_array(xdrs
, (uint8_t**)&objp
->GroupList
.CertList
, &objp
->NumCerts
, ~0, sizeof(CSSM_DATA
), (xdrproc_t
)xdr_CSSM_DATA
))
229 case CSSM_CERTGROUP_ENCODED_CERT
:
230 if (!sec_xdr_array(xdrs
, (uint8_t**)&objp
->GroupList
.EncodedCertList
,
232 sizeof(CSSM_ENCODED_CERT
), (xdrproc_t
)xdr_CSSM_ENCODED_CERT
))
235 case CSSM_CERTGROUP_PARSED_CERT
: // unimplemented -> there are no walkers for it
236 case CSSM_CERTGROUP_CERT_PAIR
: // unimplemented -> there are no walkers for it
242 if (!xdr_voidptr(xdrs
, &objp
->Reserved
))
247 bool_t
xdr_CSSM_BASE_CERTS(XDR
*xdrs
, CSSM_BASE_CERTS
*objp
)
249 if (!xdr_CSSM_TP_HANDLE(xdrs
, &objp
->TPHandle
))
251 if (!xdr_CSSM_CL_HANDLE(xdrs
, &objp
->CLHandle
))
253 if (!xdr_CSSM_CERTGROUP(xdrs
, &objp
->Certs
))
258 bool_t
xdr_CSSM_ACCESS_CREDENTIALS(XDR
*xdrs
, CSSM_ACCESS_CREDENTIALS
*objp
)
260 // XXX/cs this was for executing the callback but we're not doing that apparently void *cb = (void *)objp->Callback;
262 if (!xdr_CSSM_STRING(xdrs
, objp
->EntryTag
))
264 if (!xdr_CSSM_BASE_CERTS(xdrs
, &objp
->BaseCerts
))
266 if (!xdr_CSSM_SAMPLEGROUP(xdrs
, &objp
->Samples
))
268 // @@@ treating both Callback and CallerCtx like intptr_t
269 // in case it ever turns into a magic cookie
270 if (!xdr_voidptr(xdrs
, (void *)&objp
->Callback
))
272 if (!xdr_voidptr(xdrs
, &objp
->CallerCtx
))
278 bool_t
xdr_CSSM_ACCESS_CREDENTIALS_PTR(XDR
*xdrs
, CSSM_ACCESS_CREDENTIALS_PTR
*objp
)
280 return sec_xdr_reference(xdrs
, (uint8_t **)objp
, sizeof(CSSM_ACCESS_CREDENTIALS
), (xdrproc_t
)xdr_CSSM_ACCESS_CREDENTIALS
);
283 bool_t
xdr_CSSM_AUTHORIZATIONGROUP(XDR
*xdrs
, CSSM_AUTHORIZATIONGROUP
*objp
)
285 assert(sizeof(objp
->NumberOfAuthTags
) == sizeof(int));
286 if (!sec_xdr_array(xdrs
, (uint8_t **)&objp
->AuthTags
, (u_int
*)&objp
->NumberOfAuthTags
, ~0, sizeof(CSSM_ACL_AUTHORIZATION_TAG
), (xdrproc_t
)xdr_CSSM_ACL_AUTHORIZATION_TAG
))
291 bool_t
xdr_CSSM_ACL_VALIDITY_PERIOD(XDR
*xdrs
, CSSM_ACL_VALIDITY_PERIOD
*objp
)
293 if (!xdr_CSSM_DATA(xdrs
, &objp
->StartDate
))
295 if (!xdr_CSSM_DATA(xdrs
, &objp
->EndDate
))
300 bool_t
xdr_CSSM_ACL_ENTRY_PROTOTYPE(XDR
*xdrs
, CSSM_ACL_ENTRY_PROTOTYPE
*objp
)
302 if (!xdr_CSSM_LIST(xdrs
, &objp
->TypedSubject
))
304 // if (!xdr_CSSM_BOOL(xdrs, &objp->Delegate))
306 if (!xdr_CSSM_AUTHORIZATIONGROUP(xdrs
, &objp
->Authorization
))
308 // XXX/cs enable once securityd stops leaving garbage in here
309 // if (!xdr_CSSM_ACL_VALIDITY_PERIOD(xdrs, &objp->TimeRange))
311 if (!xdr_CSSM_STRING(xdrs
, objp
->EntryTag
))
316 bool_t
xdr_CSSM_ACL_ENTRY_PROTOTYPE_PTR(XDR
*xdrs
, CSSM_ACL_ENTRY_PROTOTYPE_PTR
*objp
)
318 return sec_xdr_reference(xdrs
, (uint8_t **)objp
, sizeof(CSSM_ACL_ENTRY_PROTOTYPE
), (xdrproc_t
)xdr_CSSM_ACL_ENTRY_PROTOTYPE
);
321 bool_t
xdr_CSSM_ACL_OWNER_PROTOTYPE(XDR
*xdrs
, CSSM_ACL_OWNER_PROTOTYPE
*objp
)
323 if (!xdr_CSSM_LIST(xdrs
, &objp
->TypedSubject
))
325 if (!xdr_CSSM_BOOL(xdrs
, &objp
->Delegate
))
330 bool_t
xdr_CSSM_ACL_OWNER_PROTOTYPE_PTR(XDR
*xdrs
, CSSM_ACL_OWNER_PROTOTYPE_PTR
*objp
)
332 return sec_xdr_reference(xdrs
, (uint8_t **)objp
,sizeof(CSSM_ACL_OWNER_PROTOTYPE
), (xdrproc_t
)xdr_CSSM_ACL_OWNER_PROTOTYPE
);
335 bool_t
xdr_CSSM_ACL_ENTRY_INPUT(XDR
*xdrs
, CSSM_ACL_ENTRY_INPUT
*objp
)
337 if (!xdr_CSSM_ACL_ENTRY_PROTOTYPE(xdrs
, &objp
->Prototype
))
339 // XXX/cs not currently using this
340 // @@@ treating both Callback and CallerCtx like intptr_t
341 // in case it ever turns into a magic cookie
342 // if (!xdr_voidptr(xdrs, &cb))
344 // if (!xdr_voidptr(xdrs, &objp->CallerContext))
349 bool_t
xdr_CSSM_ACL_ENTRY_INPUT_PTR(XDR
*xdrs
, CSSM_ACL_ENTRY_INPUT_PTR
*objp
)
351 return sec_xdr_reference(xdrs
, (uint8_t **)objp
,sizeof(CSSM_ACL_ENTRY_INPUT
), (xdrproc_t
)xdr_CSSM_ACL_ENTRY_INPUT
);
354 bool_t
xdr_CSSM_ACL_ENTRY_INFO(XDR
*xdrs
, CSSM_ACL_ENTRY_INFO
*objp
)
357 if (!xdr_CSSM_ACL_ENTRY_PROTOTYPE(xdrs
, &objp
->EntryPublicInfo
))
359 if (!xdr_CSSM_ACL_HANDLE(xdrs
, &objp
->EntryHandle
))
364 bool_t
xdr_CSSM_ACL_ENTRY_INFO_ARRAY(XDR
*xdrs
, CSSM_ACL_ENTRY_INFO_ARRAY
*objp
)
366 return sec_xdr_array(xdrs
, (uint8_t **)&objp
->acls
, (u_int
*)&objp
->count
, ~0, sizeof(CSSM_ACL_ENTRY_INFO
), (xdrproc_t
)xdr_CSSM_ACL_ENTRY_INFO
);
369 bool_t
xdr_CSSM_ACL_ENTRY_INFO_ARRAY_PTR(XDR
*xdrs
, CSSM_ACL_ENTRY_INFO_ARRAY_PTR
*objp
)
371 return sec_xdr_reference(xdrs
, (uint8_t **)objp
, sizeof(CSSM_ACL_ENTRY_INFO_ARRAY
), (xdrproc_t
)xdr_CSSM_ACL_ENTRY_INFO_ARRAY
);
375 bool_t
xdr_CSSM_DATE(XDR
*xdrs
, CSSM_DATE
*objp
)
377 return xdr_opaque(xdrs
, (char *)objp
, sizeof(CSSM_DATE
));
380 bool_t
xdr_CSSM_RANGE(XDR
*xdrs
, CSSM_RANGE
*objp
)
383 if (!xdr_uint32(xdrs
, &objp
->Min
))
385 if (!xdr_uint32(xdrs
, &objp
->Max
))
390 bool_t
xdr_CSSM_KEYHEADER(XDR
*xdrs
, CSSM_KEYHEADER
*objp
)
393 if (!xdr_CSSM_HEADERVERSION(xdrs
, &objp
->HeaderVersion
))
395 if (!xdr_CSSM_GUID(xdrs
, &objp
->CspId
))
397 if (!xdr_CSSM_KEYBLOB_TYPE(xdrs
, &objp
->BlobType
))
399 if (!xdr_CSSM_KEYBLOB_FORMAT(xdrs
, &objp
->Format
))
401 if (!xdr_CSSM_ALGORITHMS(xdrs
, &objp
->AlgorithmId
))
403 if (!xdr_CSSM_KEYCLASS(xdrs
, &objp
->KeyClass
))
405 if (!xdr_uint32(xdrs
, &objp
->LogicalKeySizeInBits
))
407 if (!xdr_CSSM_KEYATTR_FLAGS(xdrs
, &objp
->KeyAttr
))
409 if (!xdr_CSSM_KEYUSE(xdrs
, &objp
->KeyUsage
))
411 if (!xdr_CSSM_DATE(xdrs
, &objp
->StartDate
))
413 if (!xdr_CSSM_DATE(xdrs
, &objp
->EndDate
))
415 if (!xdr_CSSM_ALGORITHMS(xdrs
, &objp
->WrapAlgorithmId
))
417 if (!xdr_CSSM_ENCRYPT_MODE(xdrs
, &objp
->WrapMode
))
419 if (!xdr_uint32(xdrs
, &objp
->Reserved
))
424 bool_t
xdr_CSSM_KEYHEADER_PTR(XDR
*xdrs
, CSSM_KEYHEADER_PTR
*objp
)
426 return sec_xdr_reference(xdrs
, (uint8_t **)objp
, sizeof(CSSM_KEYHEADER
), (xdrproc_t
)xdr_CSSM_KEYHEADER
);
429 bool_t
xdr_CSSM_KEY(XDR
*xdrs
, CSSM_KEY
*objp
)
431 if (!xdr_CSSM_KEYHEADER(xdrs
, &objp
->KeyHeader
))
433 if (!xdr_CSSM_DATA(xdrs
, &objp
->KeyData
))
438 bool_t
xdr_CSSM_KEY_PTR(XDR
*xdrs
, CSSM_KEY_PTR
*objp
)
440 if (!sec_xdr_reference(xdrs
, (uint8_t **)objp
, sizeof(CSSM_KEY
), (xdrproc_t
)xdr_CSSM_KEY
))
445 // CSSM_DATA passed through in the following calls: findFirst, findNext and
446 // findRecordHandle actually contains a CSSM_KEY if the item is a key.
447 // Since a key has byte order sensitive bits it needs to be encoded.
448 // At this level we can only guess based on the length of the CSSM_DATA passed in
449 // during encode, whether it's a CSSM_KEY, so we're currently letting securityd
450 // call xdr_CSSM_KEY_IN_DATA or xdr_CSSM_NO_KEY_IN_DATA to let us know.
451 bool_t
xdr_CSSM_POSSIBLY_KEY_IN_DATA_WITH_BOOL(XDR
*xdrs
, CSSM_DATA
*objp
, bool_t in_iskey
)
453 bool_t size_alloc
= sec_xdr_arena_size_allocator(xdrs
);
454 bool_t is_key
= FALSE
; /* shut compiler up */
455 if (xdrs
->x_op
== XDR_ENCODE
)
456 is_key
= (in_iskey
&& objp
->Length
== sizeof(CSSM_KEY
));
457 if (!xdr_CSSM_BOOL(xdrs
, &is_key
))
460 if (!xdr_CSSM_KEY_PTR(xdrs
, (CSSM_KEY_PTR
*)&objp
->Data
))
462 if (!size_alloc
&& (xdrs
->x_op
== XDR_DECODE
))
463 objp
->Length
= sizeof(CSSM_KEY
);
465 if (!xdr_CSSM_DATA(xdrs
, objp
))
471 bool_t
xdr_CSSM_POSSIBLY_KEY_IN_DATA(XDR
*xdrs
, CSSM_DATA
*objp
)
473 return xdr_CSSM_POSSIBLY_KEY_IN_DATA_WITH_BOOL(xdrs
, objp
, FALSE
);
476 bool_t
xdr_CSSM_POSSIBLY_KEY_IN_DATA_PTR(XDR
*xdrs
, CSSM_DATA_PTR
*objp
)
478 if (!sec_xdr_reference(xdrs
, (uint8_t **)objp
, sizeof(CSSM_DATA
), (xdrproc_t
)xdr_CSSM_POSSIBLY_KEY_IN_DATA
))
483 bool_t
xdr_CSSM_KEY_IN_DATA(XDR
*xdrs
, CSSM_DATA
*objp
)
485 return xdr_CSSM_POSSIBLY_KEY_IN_DATA_WITH_BOOL(xdrs
, objp
, TRUE
);
488 bool_t
xdr_CSSM_NO_KEY_IN_DATA(XDR
*xdrs
, CSSM_DATA
*objp
)
490 return xdr_CSSM_POSSIBLY_KEY_IN_DATA_WITH_BOOL(xdrs
, objp
, FALSE
);
493 bool_t
xdr_CSSM_DB_ATTRIBUTE_INFO(XDR
*xdrs
, CSSM_DB_ATTRIBUTE_INFO
*objp
)
495 if (!xdr_CSSM_DB_ATTRIBUTE_NAME_FORMAT(xdrs
, &objp
->AttributeNameFormat
))
497 switch (objp
->AttributeNameFormat
)
499 case CSSM_DB_ATTRIBUTE_NAME_AS_STRING
:
500 if (!sec_xdr_charp(xdrs
, &objp
->Label
.AttributeName
, ~0))
503 case CSSM_DB_ATTRIBUTE_NAME_AS_OID
:
504 if (!xdr_CSSM_OID(xdrs
, &objp
->Label
.AttributeOID
))
507 case CSSM_DB_ATTRIBUTE_NAME_AS_INTEGER
: // @@@ apparently unused
508 if (!xdr_uint32(xdrs
, &objp
->Label
.AttributeID
))
514 if (!xdr_CSSM_DB_ATTRIBUTE_FORMAT(xdrs
, &objp
->AttributeFormat
))
520 bool_t
xdr_CSSM_DATA_FLIPPED(XDR
*xdrs
, CSSM_DATA
*objp
)
522 bool_t size_alloc
= sec_xdr_arena_size_allocator(xdrs
);
523 if ((xdrs
->x_op
== XDR_ENCODE
) && !size_alloc
) {
524 switch (objp
->Length
) {
525 case sizeof(uint32_t): *(uint32_t*)objp
->Data
= htonl(*(uint32_t*)objp
->Data
); break;
526 case sizeof(uint64_t): *(uint64_t*)objp
->Data
= OSSwapHostToBigInt64(*(uint64_t*)objp
->Data
); break;
527 case sizeof(uint8_t): break;
528 default: assert(FALSE
); break;
531 if (!xdr_CSSM_DATA(xdrs
, objp
))
533 if ((xdrs
->x_op
== XDR_DECODE
) && !size_alloc
) {
534 switch (objp
->Length
) {
535 case sizeof(uint32_t): *(uint32_t*)objp
->Data
= ntohl(*(uint32_t*)objp
->Data
); break;
536 case sizeof(uint64_t): *(uint64_t*)objp
->Data
= OSSwapBigToHostInt64(*(uint64_t*)objp
->Data
); break;
537 case sizeof(uint8_t): break;
538 default: assert(FALSE
); break;
544 bool_t
xdr_CSSM_DB_ATTRIBUTE_DATA(XDR
*xdrs
, CSSM_DB_ATTRIBUTE_DATA
*objp
)
546 if (!xdr_CSSM_DB_ATTRIBUTE_INFO(xdrs
, &objp
->Info
))
548 assert(sizeof(objp
->NumberOfValues
) == sizeof(int));
549 CSSM_DB_ATTRIBUTE_FORMAT format
= objp
->Info
.AttributeFormat
;
550 xdrproc_t proc
= (xdrproc_t
)xdr_CSSM_DATA
; // fallback
552 case CSSM_DB_ATTRIBUTE_FORMAT_STRING
:
553 case CSSM_DB_ATTRIBUTE_FORMAT_BLOB
:
554 case CSSM_DB_ATTRIBUTE_FORMAT_TIME_DATE
: // all byte strings
556 case CSSM_DB_ATTRIBUTE_FORMAT_UINT32
:
557 case CSSM_DB_ATTRIBUTE_FORMAT_SINT32
:
558 case CSSM_DB_ATTRIBUTE_FORMAT_REAL
:
559 proc
= (xdrproc_t
)xdr_CSSM_DATA_FLIPPED
;
562 Note that in case of values being passed from CopyIn, it will be normal
563 for the format to be set to CSSM_DB_ATTRIBUTE_FORMAT_COMPLEX, as that
564 is the "not-yet-filled-in" value in the CssmDbAttributeInfo constructor
565 (see Record::addAttributes for where this is called).
567 case CSSM_DB_ATTRIBUTE_FORMAT_BIG_NUM
:
568 case CSSM_DB_ATTRIBUTE_FORMAT_MULTI_UINT32
:
569 case CSSM_DB_ATTRIBUTE_FORMAT_COMPLEX
:
570 assert(objp
->NumberOfValues
== 0);
575 if (!sec_xdr_array(xdrs
, (uint8_t **)&objp
->Value
, (u_int
*)&objp
->NumberOfValues
, ~0, sizeof(CSSM_DATA
), proc
))
580 bool_t
xdr_CSSM_DB_RECORD_ATTRIBUTE_DATA(XDR
*xdrs
, CSSM_DB_RECORD_ATTRIBUTE_DATA
*objp
)
582 if (!xdr_CSSM_DB_RECORDTYPE(xdrs
, &objp
->DataRecordType
))
584 if (!xdr_uint32(xdrs
, &objp
->SemanticInformation
))
586 assert(sizeof(objp
->NumberOfAttributes
) == sizeof(int));
587 if (!sec_xdr_array(xdrs
, (uint8_t **)&objp
->AttributeData
, (u_int
*)&objp
->NumberOfAttributes
, ~0, sizeof(CSSM_DB_ATTRIBUTE_DATA
), (xdrproc_t
)xdr_CSSM_DB_ATTRIBUTE_DATA
))
592 bool_t
xdr_CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR(XDR
*xdrs
, CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR
*objp
)
594 return sec_xdr_reference(xdrs
, (uint8_t **)objp
, sizeof(CSSM_DB_RECORD_ATTRIBUTE_DATA
), (xdrproc_t
)xdr_CSSM_DB_RECORD_ATTRIBUTE_DATA
);
597 bool_t
xdr_CSSM_SELECTION_PREDICATE(XDR
*xdrs
, CSSM_SELECTION_PREDICATE
*objp
)
600 if (!xdr_CSSM_DB_OPERATOR(xdrs
, &objp
->DbOperator
))
602 if (!xdr_CSSM_DB_ATTRIBUTE_DATA(xdrs
, &objp
->Attribute
))
607 bool_t
xdr_CSSM_QUERY_LIMITS(XDR
*xdrs
, CSSM_QUERY_LIMITS
*objp
)
610 if (!xdr_uint32(xdrs
, &objp
->TimeLimit
))
612 if (!xdr_uint32(xdrs
, &objp
->SizeLimit
))
617 bool_t
xdr_CSSM_QUERY(XDR
*xdrs
, CSSM_QUERY
*objp
)
620 if (!xdr_CSSM_DB_RECORDTYPE(xdrs
, &objp
->RecordType
))
622 if (!xdr_CSSM_DB_CONJUNCTIVE(xdrs
, &objp
->Conjunctive
))
624 assert(sizeof(objp
->NumSelectionPredicates
) == sizeof(int));
625 if (!sec_xdr_array(xdrs
, (uint8_t **)&objp
->SelectionPredicate
, (u_int
*)&objp
->NumSelectionPredicates
, ~0, sizeof(CSSM_SELECTION_PREDICATE
), (xdrproc_t
)xdr_CSSM_SELECTION_PREDICATE
))
627 if (!xdr_CSSM_QUERY_LIMITS(xdrs
, &objp
->QueryLimits
))
629 if (!xdr_CSSM_QUERY_FLAGS(xdrs
, &objp
->QueryFlags
))
634 bool_t
xdr_CSSM_QUERY_PTR(XDR
*xdrs
, CSSM_QUERY_PTR
*objp
)
636 return sec_xdr_reference(xdrs
, (uint8_t **)objp
, sizeof(CSSM_QUERY
), (xdrproc_t
)xdr_CSSM_QUERY
);
639 bool_t
xdr_CSSM_CONTEXT_ATTRIBUTE(XDR
*xdrs
, CSSM_CONTEXT_ATTRIBUTE
*objp
)
641 if (!xdr_CSSM_ATTRIBUTE_TYPE(xdrs
, &objp
->AttributeType
))
643 // @@@ original walkers skirt the issue: set to 0 on copyin, set to sizeof(attr) on copyout - all attrs do have internal size or null termination.
644 if (!xdr_uint32(xdrs
, &objp
->AttributeLength
))
646 switch(objp
->AttributeType
& CSSM_ATTRIBUTE_TYPE_MASK
)
648 case CSSM_ATTRIBUTE_DATA_CSSM_DATA
:
649 if (!sec_xdr_reference(xdrs
, (uint8_t **)&objp
->Attribute
.Data
, sizeof(CSSM_DATA
), (xdrproc_t
)xdr_CSSM_DATA
)) return (FALSE
); break;
650 case CSSM_ATTRIBUTE_DATA_CRYPTO_DATA
:
651 if (!sec_xdr_reference(xdrs
, (uint8_t **)&objp
->Attribute
.CryptoData
, sizeof(CSSM_CRYPTO_DATA
), (xdrproc_t
)xdr_CSSM_CRYPTO_DATA
)) return (FALSE
); break;
652 case CSSM_ATTRIBUTE_DATA_KEY
:
653 if (!sec_xdr_reference(xdrs
, (uint8_t **)&objp
->Attribute
.Key
, sizeof(CSSM_KEY
), (xdrproc_t
)xdr_CSSM_KEY
)) return (FALSE
); break;
654 case CSSM_ATTRIBUTE_DATA_STRING
:
655 if (!sec_xdr_charp(xdrs
, &objp
->Attribute
.String
, ~0)) return (FALSE
); break;
656 case CSSM_ATTRIBUTE_DATA_DATE
:
657 if (!sec_xdr_reference(xdrs
, (uint8_t **)&objp
->Attribute
.Date
, sizeof(CSSM_DATE
), (xdrproc_t
)xdr_CSSM_DATE
)) return (FALSE
); break;
658 case CSSM_ATTRIBUTE_DATA_RANGE
:
659 if (!sec_xdr_reference(xdrs
, (uint8_t **)&objp
->Attribute
.Range
, sizeof(CSSM_RANGE
), (xdrproc_t
)xdr_CSSM_RANGE
)) return (FALSE
); break;
660 case CSSM_ATTRIBUTE_DATA_ACCESS_CREDENTIALS
:
661 if (!sec_xdr_reference(xdrs
, (uint8_t **)&objp
->Attribute
.AccessCredentials
, sizeof(CSSM_ACCESS_CREDENTIALS
), (xdrproc_t
)xdr_CSSM_ACCESS_CREDENTIALS
)) return (FALSE
); break;
662 case CSSM_ATTRIBUTE_DATA_VERSION
:
663 if (!sec_xdr_reference(xdrs
, (uint8_t **)&objp
->Attribute
.Version
, sizeof(CSSM_VERSION
), (xdrproc_t
)xdr_CSSM_VERSION
)) return (FALSE
); break;
664 case CSSM_ATTRIBUTE_DATA_DL_DB_HANDLE
:
665 if (!sec_xdr_reference(xdrs
, (uint8_t **)&objp
->Attribute
.DLDBHandle
, sizeof(CSSM_DL_DB_HANDLE
), (xdrproc_t
)xdr_CSSM_DL_DB_HANDLE
)) return (FALSE
); break;
666 case CSSM_ATTRIBUTE_NONE
:
668 case CSSM_ATTRIBUTE_DATA_UINT32
:
669 if (!xdr_uint32(xdrs
, &objp
->Attribute
.Uint32
))
679 bool_t
xdr_CSSM_CONTEXT(XDR
*xdrs
, CSSM_CONTEXT
*objp
)
681 if (!xdr_CSSM_CONTEXT_TYPE(xdrs
, &objp
->ContextType
))
683 if (!xdr_CSSM_ALGORITHMS(xdrs
, &objp
->AlgorithmType
))
685 if (!sec_xdr_array(xdrs
, (uint8_t **)&objp
->ContextAttributes
, (u_int
*)&objp
->NumberOfAttributes
, ~0, sizeof(CSSM_CONTEXT_ATTRIBUTE
), (xdrproc_t
)xdr_CSSM_CONTEXT_ATTRIBUTE
))
687 if (!xdr_CSSM_CSP_HANDLE(xdrs
, &objp
->CSPHandle
))
689 if (!xdr_CSSM_BOOL(xdrs
, &objp
->Privileged
))
691 if (!xdr_uint32(xdrs
, &objp
->EncryptionProhibited
))
693 if (!xdr_uint32(xdrs
, &objp
->WorkFactor
))
695 if (!xdr_uint32(xdrs
, &objp
->Reserved
))
700 bool_t
xdr_CSSM_CONTEXT_PTR(XDR
*xdrs
, CSSM_CONTEXT_PTR
*objp
)
702 return sec_xdr_reference(xdrs
, (uint8_t **)objp
, sizeof(CSSM_CONTEXT
), (xdrproc_t
)xdr_CSSM_CONTEXT
);
705 // this is possibly not actually used in favor of the flatidentifier
706 bool_t
xdr_CSSM_DL_DB_HANDLE(XDR
*xdrs
, CSSM_DL_DB_HANDLE
*objp
)
708 if (!xdr_CSSM_DL_HANDLE(xdrs
, &objp
->DLHandle
))
710 if (!xdr_CSSM_DB_HANDLE(xdrs
, &objp
->DBHandle
))
715 bool_t
xdr_CSSM_PKCS5_PBKDF2_PARAMS(XDR
*xdrs
, CSSM_PKCS5_PBKDF2_PARAMS
*objp
)
717 if (!xdr_CSSM_DATA(xdrs
, &objp
->Passphrase
))
719 if (!xdr_CSSM_PKCS5_PBKDF2_PRF(xdrs
, &objp
->PseudoRandomFunction
))
724 bool_t
xdr_CSSM_DERIVE_DATA(XDR
*xdrs
, CSSM_DERIVE_DATA
*objp
)
726 if (!xdr_CSSM_ALGORITHMS(xdrs
,&objp
->algorithm
))
728 switch (objp
->algorithm
) {
729 case CSSM_ALGID_PKCS5_PBKDF2
:
730 if ((xdrs
->x_op
== XDR_ENCODE
) &&
731 (!objp
->baseData
.Data
) &&
732 (objp
->baseData
.Length
!= sizeof(CSSM_PKCS5_PBKDF2_PARAMS
)))
733 return (FALSE
); //CssmError::throwMe(CSSMERR_CSP_INVALID_ATTR_ALG_PARAMS);
734 if (!sec_xdr_reference(xdrs
, &(objp
->baseData
.Data
), sizeof(CSSM_PKCS5_PBKDF2_PARAMS
), (xdrproc_t
)xdr_CSSM_PKCS5_PBKDF2_PARAMS
))
736 objp
->baseData
.Length
= sizeof(CSSM_PKCS5_PBKDF2_PARAMS
);
739 if (!xdr_CSSM_DATA(xdrs
, &objp
->baseData
))
746 bool_t
xdr_CSSM_DERIVE_DATA_PTR(XDR
*xdrs
, CSSM_DERIVE_DATA
**objp
)
748 return sec_xdr_reference(xdrs
, (uint8_t **)objp
, sizeof(CSSM_DERIVE_DATA
), (xdrproc_t
)xdr_CSSM_DERIVE_DATA
);
751 bool_t
xdr_CSSM_ACL_OWNER_PROTOTYPE_ARRAY(XDR
*xdrs
, CSSM_ACL_OWNER_PROTOTYPE_ARRAY
*objp
)
753 if (!sec_xdr_array(xdrs
, (uint8_t **)&objp
->acls
, (u_int
*)&objp
->count
, ~0, sizeof(CSSM_ACL_OWNER_PROTOTYPE
), (xdrproc_t
)xdr_CSSM_ACL_OWNER_PROTOTYPE
))
759 #if 0 /* unimplemented in current stack */
761 bool_t
xdr_CSSM_FIELD(XDR
*xdrs
, CSSM_FIELD
*objp
)
764 if (!xdr_CSSM_OID(xdrs
, &objp
->FieldOid
))
766 if (!xdr_CSSM_DATA(xdrs
, &objp
->FieldValue
))
771 bool_t
xdr_CSSM_FIELDGROUP(XDR
*xdrs
, CSSM_FIELDGROUP
*objp
)
773 assert(sizeof(objp
->NumberOfFields
) == sizeof(int));
774 if (!sec_xdr_array(xdrs
, (uint8_t**)&objp
->Fields
, (u_int
*)&objp
->NumberOfFields
, ~0, sizeof(CSSM_FIELD
), (xdrproc_t
)xdr_CSSM_FIELD
))
779 bool_t
xdr_CSSM_TUPLE(XDR
*xdrs
, CSSM_TUPLE
*objp
)
781 if (!xdr_CSSM_LIST(xdrs
, &objp
->Issuer
))
783 if (!xdr_CSSM_LIST(xdrs
, &objp
->Subject
))
785 if (!xdr_CSSM_BOOL(xdrs
, &objp
->Delegate
))
787 if (!xdr_CSSM_LIST(xdrs
, &objp
->AuthorizationTag
))
789 if (!xdr_CSSM_LIST(xdrs
, &objp
->ValidityPeriod
))
794 bool_t
xdr_CSSM_PARSED_CERT(XDR
*xdrs
, CSSM_PARSED_CERT
*objp
)
796 if (!xdr_CSSM_CERT_TYPE(xdrs
, &objp
->CertType
))
798 switch (objp
->ParsedCertFormat
)
800 case CSSM_CERT_PARSE_FORMAT_NONE
:
801 case CSSM_CERT_PARSE_FORMAT_CUSTOM
: /* void* */
804 case CSSM_CERT_PARSE_FORMAT_SEXPR
:
805 if (!xdr_CSSM_LIST(xdrs
, (CSSM_LIST
*)objp
->ParsedCert
))
808 case CSSM_CERT_PARSE_FORMAT_COMPLEX
: /* void* */
811 case CSSM_CERT_PARSE_FORMAT_OID_NAMED
:
812 if (!xdr_CSSM_FIELDGROUP(xdrs
, (CSSM_FIELDGROUP
*)objp
->ParsedCert
))
815 case CSSM_CERT_PARSE_FORMAT_TUPLE
:
816 if (!xdr_CSSM_TUPLE(xdrs
, (CSSM_TUPLE
*)objp
->ParsedCert
))
819 case CSSM_CERT_PARSE_FORMAT_MULTIPLE
:
820 /* multiple forms; each cert carries a parse format indicator */
823 case CSSM_CERT_PARSE_FORMAT_LAST
:
826 case CSSM_CL_CUSTOM_CERT_PARSE_FORMAT
:
835 bool_t
xdr_CSSM_CERT_PAIR(XDR
*xdrs
, CSSM_CERT_PAIR
*objp
)
838 if (!xdr_CSSM_ENCODED_CERT(xdrs
, &objp
->EncodedCert
))
840 if (!xdr_CSSM_PARSED_CERT(xdrs
, &objp
->ParsedCert
))
845 #endif /* unimplemented in current stack */