Skip to content

Commit 43b6834

Browse files
committed
remove some unused code
1 parent d837b94 commit 43b6834

11 files changed

Lines changed: 127 additions & 462 deletions

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ sigtest: sign-efi-siglist
2525

2626
clean:
2727
@rm -f mkefivardata cert-to-efi-sig-list sign-efi-siglist
28+
@rm -f *.esl *.vardata
2829

2930
install: cert-to-efi-sig-list sign-efi-siglist
3031
install -m 755 $^ $(DESTDIR)/usr/local/bin

cert-to-efi-sig-list.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <guid.h>
1212
#include <efiauthenticated.h>
13-
#include <version.h>
1413

1514
static void usage(const char *progname)
1615
{
@@ -38,14 +37,14 @@ int main(int argc, char *argv[])
3837
memset(&owner, 0, sizeof(EFI_GUID));
3938

4039
while (argc > 1) {
41-
if (strcmp("--version", argv[1]) == 0) {
42-
version(progname);
43-
exit(0);
44-
} else if (strcmp("--help", argv[1]) == 0) {
40+
if (strcmp("--help", argv[1]) == 0) {
4541
help(progname);
4642
exit(0);
4743
} else if (strcmp("-g", argv[1]) == 0) {
48-
str_to_guid(argv[2], &owner);
44+
if (str_to_guid(argv[2], &owner)) {
45+
printf("invalid guid\n");
46+
exit(1);
47+
}
4948
argv += 2;
5049
argc -= 2;
5150
} else {

include/efiauthenticated.h

Lines changed: 69 additions & 269 deletions
Original file line numberDiff line numberDiff line change
@@ -1,289 +1,89 @@
1-
#ifndef _INC_EFIAUTHENTICATED_H
2-
#define _INC_EFIAUTHENTICATED_H
3-
#include <wincert.h>
1+
#pragma once
2+
3+
///
4+
/// The WIN_CERTIFICATE structure is part of the PE/COFF specification.
5+
///
6+
typedef struct {
7+
///
8+
/// The length of the entire certificate,
9+
/// including the length of the header, in bytes.
10+
///
11+
uint32_t dwLength;
12+
///
13+
/// The revision level of the WIN_CERTIFICATE
14+
/// structure. The current revision level is 0x0200.
15+
///
16+
uint16_t wRevision;
17+
///
18+
/// The certificate type. See WIN_CERT_TYPE_xxx for the UEFI
19+
/// certificate types. The UEFI specification reserves the range of
20+
/// certificate type values from 0x0EF0 to 0x0EFF.
21+
///
22+
uint16_t wCertificateType;
23+
///
24+
/// The following is the actual certificate. The format of
25+
/// the certificate depends on wCertificateType.
26+
///
27+
/// UINT8 bCertificate[ANYSIZE_ARRAY];
28+
///
29+
} WIN_CERTIFICATE;
30+
431
//***********************************************************************
532
// Signature Database
633
//***********************************************************************
734
///
835
/// The format of a signature database.
936
///
1037

11-
typedef UINT8 EFI_SHA256_HASH[32];
12-
typedef UINT8 EFI_SHA384_HASH[48];
13-
typedef UINT8 EFI_SHA512_HASH[64];
14-
15-
void USARTWrite(const void *object, size_t size)
16-
{
17-
const unsigned char *byte;
18-
for (byte = object; size--; byte++) {
19-
printf("%02X", *byte);
20-
}
21-
putchar('\n');
22-
}
23-
24-
25-
#pragma pack(1)
26-
2738
typedef struct {
28-
///
29-
/// An identifier which identifies the agent which added the signature to the list.
30-
///
31-
EFI_GUID SignatureOwner;
32-
///
33-
/// The format of the signature is defined by the SignatureType.
34-
///
35-
UINT8 SignatureData[1];
39+
///
40+
/// An identifier which identifies the agent which added the signature to the list.
41+
///
42+
EFI_GUID SignatureOwner;
43+
///
44+
/// The format of the signature is defined by the SignatureType.
45+
///
46+
uint8_t SignatureData[1];
3647
} EFI_SIGNATURE_DATA;
3748

3849
typedef struct {
39-
///
40-
/// Type of the signature. GUID signature types are defined in below.
41-
///
42-
EFI_GUID SignatureType;
43-
///
44-
/// Total size of the signature list, including this header.
45-
///
46-
UINT32 SignatureListSize;
47-
///
48-
/// Size of the signature header which precedes the array of signatures.
49-
///
50-
UINT32 SignatureHeaderSize;
51-
///
52-
/// Size of each signature.
53-
///
54-
UINT32 SignatureSize;
55-
///
56-
/// Header before the array of signatures. The format of this header is specified
57-
/// by the SignatureType.
58-
/// UINT8 SignatureHeader[SignatureHeaderSize];
59-
///
60-
/// An array of signatures. Each signature is SignatureSize bytes in length.
61-
/// EFI_SIGNATURE_DATA Signatures[][SignatureSize];
62-
///
50+
///
51+
/// Type of the signature. GUID signature types are defined in below.
52+
///
53+
EFI_GUID SignatureType;
54+
///
55+
/// Total size of the signature list, including this header.
56+
///
57+
uint32_t SignatureListSize;
58+
///
59+
/// Size of the signature header which precedes the array of signatures.
60+
///
61+
uint32_t SignatureHeaderSize;
62+
///
63+
/// Size of each signature.
64+
///
65+
uint32_t SignatureSize;
66+
///
67+
/// Header before the array of signatures. The format of this header is specified
68+
/// by the SignatureType.
69+
/// UINT8 SignatureHeader[SignatureHeaderSize];
70+
///
71+
/// An array of signatures. Each signature is SignatureSize bytes in length.
72+
/// EFI_SIGNATURE_DATA Signatures[][SignatureSize];
73+
///
6374
} EFI_SIGNATURE_LIST;
6475

65-
typedef struct {
66-
///
67-
/// The SHA256 hash of an X.509 certificate's To-Be-Signed contents.
68-
///
69-
EFI_SHA256_HASH ToBeSignedHash;
70-
///
71-
/// The time that the certificate shall be considered to be revoked.
72-
///
73-
EFI_TIME TimeOfRevocation;
74-
} EFI_CERT_X509_SHA256;
75-
76-
typedef struct {
77-
///
78-
/// The SHA384 hash of an X.509 certificate's To-Be-Signed contents.
79-
///
80-
EFI_SHA384_HASH ToBeSignedHash;
81-
///
82-
/// The time that the certificate shall be considered to be revoked.
83-
///
84-
EFI_TIME TimeOfRevocation;
85-
} EFI_CERT_X509_SHA384;
86-
87-
typedef struct {
88-
///
89-
/// The SHA512 hash of an X.509 certificate's To-Be-Signed contents.
90-
///
91-
EFI_SHA512_HASH ToBeSignedHash;
92-
///
93-
/// The time that the certificate shall be considered to be revoked.
94-
///
95-
EFI_TIME TimeOfRevocation;
96-
} EFI_CERT_X509_SHA512;
97-
98-
#pragma pack()
99-
10076
//
10177
// _WIN_CERTIFICATE.wCertificateType
10278
//
103-
#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
104-
#define WIN_CERT_TYPE_EFI_PKCS115 0x0EF0
105-
#define WIN_CERT_TYPE_EFI_GUID 0x0EF1
79+
#define WIN_CERT_TYPE_EFI_GUID 0x0ef1
10680

10781
#define EFI_CERT_X509_GUID \
108-
(EFI_GUID){ \
109-
0xa5c059a1, 0x94e4, 0x4aa7, {0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72} \
110-
}
111-
112-
#define EFI_CERT_RSA2048_GUID \
113-
(EFI_GUID){ \
114-
0x3c5766e8, 0x269c, 0x4e34, {0xaa, 0x14, 0xed, 0x77, 0x6e, 0x85, 0xb3, 0xb6} \
115-
}
116-
82+
(EFI_GUID) { \
83+
0xa5c059a1, 0x94e4, 0x4aa7, { 0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72 } \
84+
}
11785

11886
#define EFI_CERT_TYPE_PKCS7_GUID \
119-
(EFI_GUID){ \
120-
0x4aafd29d, 0x68df, 0x49ee, {0x8a, 0xa9, 0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7} \
121-
}
122-
123-
#define EFI_CERT_X509_SHA256_GUID \
124-
(EFI_GUID) { 0x3bd2a492, 0x96c0, 0x4079, \
125-
{ 0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed } }
126-
127-
#define EFI_CERT_X509_SHA384_GUID \
128-
(EFI_GUID) { 0x7076876e, 0x80c2, 0x4ee6, \
129-
{ 0xaa, 0xd2, 0x28, 0xb3, 0x49, 0xa6, 0x86, 0x5b } }
130-
131-
#define EFI_CERT_X509_SHA512_GUID \
132-
(EFI_GUID) { 0x446dbf63, 0x2502, 0x4cda, \
133-
{ 0xbc, 0xfa, 0x24, 0x65, 0xd2, 0xb0, 0xfe, 0x9d } }
134-
135-
///
136-
/// WIN_CERTIFICATE_UEFI_GUID.CertType
137-
///
138-
#define EFI_CERT_TYPE_RSA2048_SHA256_GUID \
139-
{0xa7717414, 0xc616, 0x4977, {0x94, 0x20, 0x84, 0x47, 0x12, 0xa7, 0x35, 0xbf } }
140-
141-
///
142-
/// WIN_CERTIFICATE_UEFI_GUID.CertData
143-
///
144-
typedef struct {
145-
EFI_GUID HashType;
146-
UINT8 PublicKey[256];
147-
UINT8 Signature[256];
148-
} EFI_CERT_BLOCK_RSA_2048_SHA256;
149-
150-
/// https://uefi.org/specs/UEFI/2.10/32_Secure_Boot_and_Driver_Signing.html
151-
///
152-
/// typedef struct {
153-
/// UINT32 dwLength;
154-
/// UINT16 wRevision;
155-
/// UINT16 wCertificateType;
156-
/// } WIN_CERTIFICATE;
157-
158-
///
159-
/// Certificate which encapsulates a GUID-specific digital signature
160-
///
161-
typedef struct {
162-
///
163-
/// This is the standard WIN_CERTIFICATE header, where
164-
/// wCertificateType is set to WIN_CERT_TYPE_UEFI_GUID.
165-
///
166-
WIN_CERTIFICATE Hdr;
167-
///
168-
/// This is the unique id which determines the
169-
/// format of the CertData. .
170-
///
171-
EFI_GUID CertType;
172-
///
173-
/// The following is the certificate data. The format of
174-
/// the data is determined by the CertType.
175-
/// If CertType is EFI_CERT_TYPE_RSA2048_SHA256_GUID,
176-
/// the CertData will be EFI_CERT_BLOCK_RSA_2048_SHA256 structure.
177-
///
178-
UINT8 CertData[1];
179-
} WIN_CERTIFICATE_UEFI_GUID;
180-
181-
182-
///
183-
/// Certificate which encapsulates the RSASSA_PKCS1-v1_5 digital signature.
184-
///
185-
/// The WIN_CERTIFICATE_UEFI_PKCS1_15 structure is derived from
186-
/// WIN_CERTIFICATE and encapsulate the information needed to
187-
/// implement the RSASSA-PKCS1-v1_5 digital signature algorithm as
188-
/// specified in RFC2437.
189-
///
190-
typedef struct {
191-
///
192-
/// This is the standard WIN_CERTIFICATE header, where
193-
/// wCertificateType is set to WIN_CERT_TYPE_UEFI_PKCS1_15.
194-
///
195-
WIN_CERTIFICATE Hdr;
196-
///
197-
/// This is the hashing algorithm which was performed on the
198-
/// UEFI executable when creating the digital signature.
199-
///
200-
EFI_GUID HashAlgorithm;
201-
///
202-
/// The following is the actual digital signature. The
203-
/// size of the signature is the same size as the key
204-
/// (1024-bit key is 128 bytes) and can be determined by
205-
/// subtracting the length of the other parts of this header
206-
/// from the total length of the certificate as found in
207-
/// Hdr.dwLength.
208-
///
209-
/// UINT8 Signature[];
210-
///
211-
} WIN_CERTIFICATE_EFI_PKCS1_15;
212-
213-
#define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field))
214-
215-
///
216-
/// Attributes of Authenticated Variable
217-
///
218-
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010
219-
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
220-
#define EFI_VARIABLE_APPEND_WRITE 0x00000040
221-
222-
///
223-
/// AuthInfo is a WIN_CERTIFICATE using the wCertificateType
224-
/// WIN_CERTIFICATE_UEFI_GUID and the CertType
225-
/// EFI_CERT_TYPE_RSA2048_SHA256_GUID. If the attribute specifies
226-
/// authenticated access, then the Data buffer should begin with an
227-
/// authentication descriptor prior to the data payload and DataSize
228-
/// should reflect the the data.and descriptor size. The caller
229-
/// shall digest the Monotonic Count value and the associated data
230-
/// for the variable update using the SHA-256 1-way hash algorithm.
231-
/// The ensuing the 32-byte digest will be signed using the private
232-
/// key associated w/ the public/private 2048-bit RSA key-pair. The
233-
/// WIN_CERTIFICATE shall be used to describe the signature of the
234-
/// Variable data *Data. In addition, the signature will also
235-
/// include the MonotonicCount value to guard against replay attacks.
236-
///
237-
typedef struct {
238-
///
239-
/// Included in the signature of
240-
/// AuthInfo.Used to ensure freshness/no
241-
/// replay. Incremented during each
242-
/// "Write" access.
243-
///
244-
UINT64 MonotonicCount;
245-
///
246-
/// Provides the authorization for the variable
247-
/// access. It is a signature across the
248-
/// variable data and the Monotonic Count
249-
/// value. Caller uses Private key that is
250-
/// associated with a public key that has been
251-
/// provisioned via the key exchange.
252-
///
253-
WIN_CERTIFICATE_UEFI_GUID AuthInfo;
254-
} EFI_VARIABLE_AUTHENTICATION;
255-
256-
///
257-
/// When the attribute EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS is
258-
/// set, then the Data buffer shall begin with an instance of a complete (and serialized)
259-
/// EFI_VARIABLE_AUTHENTICATION_2 descriptor. The descriptor shall be followed by the new
260-
/// variable value and DataSize shall reflect the combined size of the descriptor and the new
261-
/// variable value. The authentication descriptor is not part of the variable data and is not
262-
/// returned by subsequent calls to GetVariable().
263-
///
264-
typedef struct {
265-
///
266-
/// For the TimeStamp value, components Pad1, Nanosecond, TimeZone, Daylight and
267-
/// Pad2 shall be set to 0. This means that the time shall always be expressed in GMT.
268-
///
269-
EFI_TIME TimeStamp;
270-
///
271-
/// Only a CertType of EFI_CERT_TYPE_PKCS7_GUID is accepted.
272-
///
273-
WIN_CERTIFICATE_UEFI_GUID AuthInfo;
274-
} EFI_VARIABLE_AUTHENTICATION_2;
275-
276-
///
277-
/// Size of AuthInfo prior to the data payload.
278-
///
279-
#define AUTHINFO_SIZE ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION, AuthInfo)) + \
280-
(OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)) + \
281-
sizeof (EFI_CERT_BLOCK_RSA_2048_SHA256))
282-
283-
#define AUTHINFO2_SIZE(VarAuth2) ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo)) + \
284-
(UINTN) ((EFI_VARIABLE_AUTHENTICATION_2 *) (VarAuth2))->AuthInfo.Hdr.dwLength)
285-
286-
#define OFFSET_OF_AUTHINFO2_CERT_DATA ((OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo)) + \
287-
(OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)))
288-
289-
#endif
87+
(EFI_GUID) { \
88+
0x4aafd29d, 0x68df, 0x49ee, { 0x8a, 0xa9, 0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7 } \
89+
}

0 commit comments

Comments
 (0)