2 * Copyright (c) 2000-2006,2011,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@
26 // acl_password - password-based ACL subject types
28 #include <security_cdsa_utilities/acl_password.h>
29 #include <security_utilities/debugging.h>
30 #include <security_utilities/endian.h>
35 // PasswordAclSubject always pre-loads its secret, and thus never has to
36 // "get" its secret. If we ever try, it's a bug.
38 bool PasswordAclSubject::getSecret(const AclValidationContext
&context
,
39 const TypedList
&sample
, CssmOwnedData
&secret
) const
41 switch (sample
.length()) {
43 return false; // no password in sample
48 CssmError::throwMe(CSSM_ERRCODE_INVALID_SAMPLE_VALUE
);
54 // Make a copy of this subject in CSSM_LIST form
56 CssmList
PasswordAclSubject::toList(Allocator
&alloc
) const
58 // the password itself is private and not exported to CSSM
59 return TypedList(alloc
, CSSM_ACL_SUBJECT_TYPE_PASSWORD
);
64 // Create a PasswordAclSubject
66 PasswordAclSubject
*PasswordAclSubject::Maker::make(const TypedList
&list
) const
68 Allocator
&alloc
= Allocator::standard(Allocator::sensitive
);
69 switch (list
.length()) {
71 return new PasswordAclSubject(alloc
, true);
74 ListElement
*password
;
75 crack(list
, 1, &password
, CSSM_LIST_ELEMENT_DATUM
);
76 return new PasswordAclSubject(alloc
, password
->data());
79 CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_SUBJECT_VALUE
);
83 PasswordAclSubject
*PasswordAclSubject::Maker::make(Version
, Reader
&pub
, Reader
&priv
) const
85 Allocator
&alloc
= Allocator::standard(Allocator::sensitive
);
86 const void *data
; size_t length
; priv
.countedData(data
, length
);
87 CssmAutoData
passwordData(alloc
, data
, length
);
88 return new PasswordAclSubject(alloc
, passwordData
);
93 // Export the subject to a memory blob
95 void PasswordAclSubject::exportBlob(Writer::Counter
&pub
, Writer::Counter
&priv
)
97 priv
.countedData(secret());
100 void PasswordAclSubject::exportBlob(Writer
&pub
, Writer
&priv
)
102 priv
.countedData(secret());
108 void PasswordAclSubject::debugDump() const
110 Debug::dump("Password");
111 SecretAclSubject::debugDump();