2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
21 // CSSM_SAMPLE POD routines
24 #define _CPP_UTILITIES
27 #include <cdsa_utilities/cssmlist.h>
28 #include <cdsa_utilities/SampleGroup.h>
32 CssmSample::CssmSample()
35 TypedSample
.ListType
= CSSM_LIST_TYPE_UNKNOWN
;
36 TypedSample
.Head
= NULL
;
37 TypedSample
.Tail
= NULL
;
40 CssmSample::CssmSample( CSSM_LIST
&list
, CSSM_SUBSERVICE_UID
*verifier
)
43 TypedSample
.ListType
= list
.ListType
;
44 TypedSample
.Head
= list
.Head
;
45 TypedSample
.Tail
= list
.Tail
;
48 CssmSample::~CssmSample()
53 CssmSample
* CssmSample::operator = (CssmSample
& sample
)
58 this->Verifier
= sample
.Verifier
;
60 this->TypedSample
= sample
.TypedSample
;
65 CSSM_RETURN
CssmSample::AddPasswordImmediate( char* password
, CSSM_SUBSERVICE_UID
*optionalVerifier
)
67 CSSM_RETURN result
= CSSM_OK
;
69 CSSM_LIST_ELEMENT
* passwordTypeElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_PASSWORD
); // declares the type to be password
70 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(passwordTypeElement
) );
72 char* permanentPasswordData
= (char*)malloc( strlen(password
) + 1 ); // need error handling. Going to assume these succeed for now
73 strcpy( permanentPasswordData
, password
);
74 CSSM_LIST_ELEMENT
* passwordElement
= MakeDatumElement( (void*)permanentPasswordData
, strlen(password
) ); // has the password CSSM_DATA in it
75 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(passwordElement
) );
77 Verifier
= optionalVerifier
;
83 CSSM_RETURN
CssmSample::AddPasswordCallback( )
85 CSSM_RETURN result
= CSSM_OK
;
87 CSSM_LIST_ELEMENT
* passwordCallbackElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_PASSWORD
); // declares the type to be password
88 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(passwordCallbackElement
) );
96 CSSM_RETURN
CssmSample::AddHashedPassword( char* password
, CSSM_SUBSERVICE_UID
*optionalVerifier
)
98 CSSM_RETURN result
= CSSM_OK
;
100 CSSM_LIST_ELEMENT
* passwordTypeElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_HASHED_PASSWORD
); // declares the type to be password
101 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(passwordTypeElement
) );
103 char* permanentPasswordData
= (char*)malloc( strlen(password
) + 1 ); // need error handling. Going to assume these succeed for now
104 strcpy( permanentPasswordData
, password
);
105 CSSM_LIST_ELEMENT
* passwordElement
= MakeDatumElement( (void*)permanentPasswordData
, strlen(password
) ); // has the password CSSM_DATA in it
106 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(passwordElement
) );
108 Verifier
= optionalVerifier
;
116 CSSM_RETURN
CssmSample::AddProtectedPasword(CSSM_SUBSERVICE_UID
*optionalVerifier
)
118 CSSM_RETURN result
= CSSM_OK
;
120 CSSM_LIST_ELEMENT
* passwordCallbackElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_PROTECTED_PASSWORD
); // declares the type to be password
121 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(passwordCallbackElement
) );
123 Verifier
= optionalVerifier
;
129 CSSM_RETURN
CssmSample::AddPromptedPassword( char* promptedPassword
, CSSM_SUBSERVICE_UID
*optionalVerifier
)
131 CSSM_RETURN result
= CSSM_OK
;
133 CSSM_LIST_ELEMENT
* passwordTypeElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_PROMPTED_PASSWORD
); // declares the type to be password
134 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(passwordTypeElement
) );
136 char* permanentPasswordData
= (char*)malloc( strlen(promptedPassword
) + 1 ); // need error handling. Going to assume these succeed for now
137 strcpy( permanentPasswordData
, promptedPassword
);
138 CSSM_LIST_ELEMENT
* passwordPromptElement
= MakeDatumElement( (void*)permanentPasswordData
, strlen(promptedPassword
) ); // has the password CSSM_DATA in it
139 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(passwordPromptElement
) );
141 Verifier
= optionalVerifier
;
147 CSSM_RETURN
CssmSample::AddSignedNonceForCallback( CSSM_SUBSERVICE_UID
*requiredVerifier
)
149 CSSM_RETURN result
= CSSM_OK
;
151 CSSM_LIST_ELEMENT
* signedNonceCallbackElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_SIGNED_NONCE
);
152 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(signedNonceCallbackElement
) );
154 Verifier
= requiredVerifier
;
159 CSSM_RETURN
CssmSample::AddSignedNonceReply( CSSM_DATA_PTR signedNonce
, CSSM_SUBSERVICE_UID
*requiredVerifier
)
161 CSSM_RETURN result
= CSSM_OK
;
163 CSSM_LIST_ELEMENT
* signedNonceTypeElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_SIGNED_NONCE
);
164 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(signedNonceTypeElement
) );
166 CSSM_LIST_ELEMENT
* signedNonceDataElement
= MakeDatumElement( (void*)signedNonce
->Data
, signedNonce
->Length
);
167 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(signedNonceDataElement
) );
169 Verifier
= requiredVerifier
;
174 CSSM_RETURN
CssmSample::AddSignedSecretForCallback( CSSM_SUBSERVICE_UID
*requiredVerifier
)
176 CSSM_RETURN result
= CSSM_OK
;
177 CSSM_LIST_ELEMENT
* signedSecretCallbackElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_SIGNED_SECRET
);
178 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(signedSecretCallbackElement
) );
180 Verifier
= requiredVerifier
;
185 CSSM_RETURN
CssmSample::AddSignedSecretImmediate( CSSM_DATA_PTR signedSecret
, CSSM_SUBSERVICE_UID
*requiredVerifier
)
187 CSSM_RETURN result
= CSSM_OK
;
189 CSSM_LIST_ELEMENT
* signedSecretTypeElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_SIGNED_SECRET
);
190 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(signedSecretTypeElement
) );
192 CSSM_LIST_ELEMENT
* signedSecretElement
= MakeDatumElement( (void*)signedSecret
->Data
, signedSecret
->Length
);
193 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(signedSecretElement
) );
195 Verifier
= requiredVerifier
;
200 CSSM_RETURN
CssmSample::AddBiometricCallback( CSSM_SUBSERVICE_UID
*requiredVerifier
)
202 CSSM_RETURN result
= CSSM_OK
;
204 CSSM_LIST_ELEMENT
* callbackElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_BIOMETRIC
);
205 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(callbackElement
) );
207 Verifier
= requiredVerifier
;
213 CSSM_RETURN
CssmSample::AddBiometricImmediate( CSSM_DATA_PTR biometricData
, CSSM_SUBSERVICE_UID
*requiredVerifier
)
215 CSSM_RETURN result
= CSSM_OK
;
217 CSSM_LIST_ELEMENT
* typeElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_BIOMETRIC
);
218 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(typeElement
) );
220 CSSM_LIST_ELEMENT
* dataElement
= MakeDatumElement( (void*)biometricData
->Data
, biometricData
->Length
);
221 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(dataElement
) );
223 Verifier
= requiredVerifier
;
229 CSSM_RETURN
CssmSample::AddProtectedBiometric( CSSM_SUBSERVICE_UID
*requiredVerifier
)
231 CSSM_RETURN result
= CSSM_OK
;
233 CSSM_LIST_ELEMENT
* callbackElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_PROTECTED_BIOMETRIC
);
234 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(callbackElement
) );
236 Verifier
= requiredVerifier
;
240 CSSM_RETURN
CssmSample::AddPromptedBiometric( CSSM_DATA_PTR biometricData
, CSSM_SUBSERVICE_UID
*requiredVerifier
)
242 CSSM_RETURN result
= CSSM_OK
;
244 CSSM_LIST_ELEMENT
* callbackElement
= MakeWordIDElement( CSSM_SAMPLE_TYPE_PROMPTED_BIOMETRIC
);
245 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(callbackElement
) );
248 CSSM_LIST_ELEMENT
* dataElement
= MakeDatumElement( (void*)biometricData
->Data
, biometricData
->Length
);
249 (CssmList::overlay(TypedSample
)).append( ListElement::overlay(dataElement
) );
251 Verifier
= requiredVerifier
;
257 CssmSampleGroup::CssmSampleGroup()
258 { // creates the nothing sample group
263 CSSM_RETURN
CssmSampleGroup::AddSample(CSSM_SAMPLE
* sample
)
265 CSSM_RETURN result
= CSSM_OK
;
266 CSSM_SAMPLE
* sampleBase
;
267 if( NumberOfSamples
== 0 )
268 { // malloc to create the first item
269 sampleBase
= (CSSM_SAMPLE
*)malloc( sizeof(CSSM_SAMPLE
) );
270 Samples
= sampleBase
;
273 { // realloc to add the next item
274 sampleBase
= (CSSM_SAMPLE
*)realloc( (void*)Samples
, sizeof(CSSM_SAMPLE
) * (NumberOfSamples
+ 1) );
275 Samples
= sampleBase
;
278 sampleBase
[NumberOfSamples
].TypedSample
.ListType
= sample
->TypedSample
.ListType
;
279 sampleBase
[NumberOfSamples
].TypedSample
.Head
= sample
->TypedSample
.Head
;
280 sampleBase
[NumberOfSamples
].TypedSample
.Tail
= sample
->TypedSample
.Tail
;
281 sampleBase
[NumberOfSamples
].Verifier
= sample
->Verifier
;
288 CSSM_SAMPLE
* CssmSampleGroup::GetIthSample(uint32 sampleIndex
)
290 if( (0 != NumberOfSamples
) && (sampleIndex
< NumberOfSamples
-1) )
291 return (CSSM_SAMPLE
*)&Samples
[sampleIndex
];