2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
28 // database - database session management
31 #include "agentquery.h"
35 #include <security_agent_client/agentclient.h>
36 #include <security_cdsa_utilities/acl_any.h> // for default owner ACLs
37 #include <security_cdsa_client/wrapkey.h>
38 #include <security_utilities/endian.h>
44 DbCommon::DbCommon(Session
&session
)
49 Session
&DbCommon::session() const
51 return referent
<Session
>();
58 Database::Database(Process
&proc
)
59 : SecurityServerAcl(dbAcl
, Allocator::standard())
65 Process
& Database::process() const
67 return referent
<Process
>();
74 void DbCommon::sleepProcessing()
80 void Database::releaseKey(Key
&key
)
87 // Implementation of a "system keychain unlock key store"
89 SystemKeychainKey::SystemKeychainKey(const char *path
)
92 // explicitly set up a key header for a raw 3DES key
93 CssmKey::Header
&hdr
= mKey
.header();
94 hdr
.blobType(CSSM_KEYBLOB_RAW
);
95 hdr
.blobFormat(CSSM_KEYBLOB_RAW_FORMAT_OCTET_STRING
);
96 hdr
.keyClass(CSSM_KEYCLASS_SESSION_KEY
);
97 hdr
.algorithm(CSSM_ALGID_3DES_3KEY_EDE
);
99 hdr
.KeyUsage
= CSSM_KEYUSE_ANY
;
100 mKey
= CssmData::wrap(mBlob
.masterKey
);
103 SystemKeychainKey::~SystemKeychainKey()
107 bool SystemKeychainKey::matches(const DbBlob::Signature
&signature
)
109 return update() && signature
== mBlob
.signature
;
112 bool SystemKeychainKey::update()
114 // if we checked recently, just assume it's okay
115 if (mUpdateThreshold
> Time::now())
120 if (::stat(mPath
.c_str(), &st
)) {
121 // something wrong with the file; can't use it
122 mUpdateThreshold
= Time::now() + Time::Interval(checkDelay
);
123 return mValid
= false;
125 if (mValid
&& Time::Absolute(st
.st_mtimespec
) == mCachedDate
)
127 mUpdateThreshold
= Time::now() + Time::Interval(checkDelay
);
130 secdebug("syskc", "reading system unlock record from %s", mPath
.c_str());
131 AutoFileDesc
fd(mPath
, O_RDONLY
);
132 if (fd
.read(mBlob
) != sizeof(mBlob
))
134 if (mBlob
.isValid()) {
135 mCachedDate
= st
.st_mtimespec
;
136 return mValid
= true;
138 return mValid
= false;
140 secdebug("syskc", "system unlock record not available");