]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/codesigning.h
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.
20 // codesigning - support for signing and verifying "bags o' bits" on disk.
22 // This file defines CodeSigner objects that sign, SignableCode objects
23 // that can be signed, and CodeSignature objects that represent signatures.
24 // Anything that can be "enumerated" into a stream of bits is fair game as
25 // a SignableCode, though the primary intent is to sign files or directories
31 #include <Security/utilities.h>
34 #ifdef _CPP_CODESIGNING
45 // Type codes for signatures. Each represents a particular type of signature.
48 standardOSXSignature
= 1 // standard MacOS X signature (SHA1)
53 // A CodeSignature is an abstract object representing a complete signature.
54 // You may think of this as a cryptographic hash of some kind together with
55 // type information and enough abstraction to make changing the algorithms
60 virtual ~Signature() { }
62 virtual bool operator == (const Signature
&other
) const = 0;
63 bool operator != (const Signature
&other
) const { return !(*this == other
); }
65 virtual uint32
type() const = 0; // yield type code
66 virtual const void *data() const = 0; // yield data pointer
67 virtual size_t length() const = 0; // yield length of data
72 // A Signer is the engine that can sign and verify. It may have configuration,
73 // but it should have NO state that carries over between signing/verifying
74 // operations. In other words, once a signing/verifyng operation is complete,
75 // the signer should forget about what it did.
78 friend class Signable
;
85 virtual void enumerateContents(const void *data
, size_t length
) = 0;
90 State(Signer
&sgn
) : signer(sgn
) { }
94 virtual Signature
*sign(const Signable
&target
) = 0;
95 virtual bool verify(const Signable
&target
, const Signature
*signature
) = 0;
97 virtual Signature
*restore(uint32 type
, const void *data
, size_t length
) = 0;
98 Signature
*restore(uint32 type
, const CssmData
&data
)
99 { return restore(type
, data
.data(), data
.length()); }
102 void scanContents(State
&state
, const Signable
&target
);
107 // A Signable object represents something that can be signed
112 virtual ~Signable() { }
114 Signature
*sign(Signer
&signer
) const
115 { return signer
.sign(*this); }
116 bool verify(const Signature
*signature
, Signer
&signer
) const
117 { return signer
.verify(*this, signature
); }
120 virtual void scanContents(Signer::State
&state
) const = 0;
125 // Close mutually recursive calls
127 inline void Signer::scanContents(State
&state
, const Signable
&target
)
129 target
.scanContents(state
);
132 } // end namespace CodeSigning
134 } // end namespace Security
136 #ifdef _CPP_CODESIGNING
141 #endif //_CODESIGNING