1 | /** @file
|
---|
2 | * IPRT - Crypto - PEM-file Reader & Writer.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2014 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___iprt_crypto_spc_h
|
---|
27 | #define ___iprt_crypto_spc_h
|
---|
28 |
|
---|
29 | #include <iprt/asn1.h>
|
---|
30 | #include <iprt/crypto/x509.h>
|
---|
31 | #include <iprt/crypto/pkcs7.h>
|
---|
32 | #include <iprt/md5.h>
|
---|
33 | #include <iprt/sha.h>
|
---|
34 |
|
---|
35 |
|
---|
36 | RT_C_DECLS_BEGIN
|
---|
37 |
|
---|
38 | /** @defgroup grp_rt_spc RTCrPem - PEM-file Reader & Writer
|
---|
39 | * @ingroup grp_rt_crypto
|
---|
40 | * @{
|
---|
41 | */
|
---|
42 |
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * One PEM marker word (use RT_STR_TUPLE to initialize).
|
---|
46 | */
|
---|
47 | typedef struct RTCRPEMMARKERWORD
|
---|
48 | {
|
---|
49 | /** The word string. */
|
---|
50 | const char *pszWord;
|
---|
51 | /** The length. */
|
---|
52 | uint32_t cchWord;
|
---|
53 | } RTCRPEMMARKERWORD;
|
---|
54 | /** Pointer to a const marker word. */
|
---|
55 | typedef RTCRPEMMARKERWORD const *PCRTCRPEMMARKERWORD;
|
---|
56 |
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * A PEM marker.
|
---|
60 | *
|
---|
61 | * This is an array of words with lengths, optimized for avoid unnecessary
|
---|
62 | * strlen() while searching the file content. It is ASSUMED that all PEM
|
---|
63 | * section markers starts with either 'BEGIN' or 'END', followed by the words
|
---|
64 | * in the this structure.
|
---|
65 | */
|
---|
66 | typedef struct RTCRPEMMARKER
|
---|
67 | {
|
---|
68 | /** Pointer to an array of marker words. */
|
---|
69 | PCRTCRPEMMARKERWORD paWords;
|
---|
70 | /** Number of works in the array papszWords points to. */
|
---|
71 | uint32_t cWords;
|
---|
72 | } RTCRPEMMARKER;
|
---|
73 | /** Pointer to a const PEM marker. */
|
---|
74 | typedef RTCRPEMMARKER const *PCRTCRPEMMARKER;
|
---|
75 |
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * A PEM section.
|
---|
79 | *
|
---|
80 | * The API works on linked lists of these.
|
---|
81 | */
|
---|
82 | typedef struct RTCRPEMSECTION
|
---|
83 | {
|
---|
84 | /** Pointer to the next file section. */
|
---|
85 | struct RTCRPEMSECTION const *pNext;
|
---|
86 | /** The marker for this section. NULL if binary file. */
|
---|
87 | PCRTCRPEMMARKER pMarker;
|
---|
88 | /** Pointer to the binary data. */
|
---|
89 | uint8_t *pbData;
|
---|
90 | /** The size of the binary data. */
|
---|
91 | size_t cbData;
|
---|
92 | /** Additional text preceeding the binary data. NULL if none. */
|
---|
93 | char *pszPreamble;
|
---|
94 | /** The length of the preamble. */
|
---|
95 | size_t cchPreamble;
|
---|
96 | } RTCRPEMSECTION;
|
---|
97 | /** Pointer to a PEM section. */
|
---|
98 | typedef RTCRPEMSECTION *PRTCRPEMSECTION;
|
---|
99 | /** Pointer to a const PEM section. */
|
---|
100 | typedef RTCRPEMSECTION const *PCRTCRPEMSECTION;
|
---|
101 |
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Frees sections returned by RTCrPemReadFile.
|
---|
105 | * @returns IPRT status code.
|
---|
106 | * @param pSectionHead The first section.
|
---|
107 | */
|
---|
108 | RTDECL(int) RTCrPemFreeSections(PCRTCRPEMSECTION pSectionHead);
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Reads the content of the given file and returns a list of binary sections
|
---|
112 | * found in the file.
|
---|
113 | *
|
---|
114 | * If the file isn't an ASCII file or if no markers were found, the entire file
|
---|
115 | * content is returned as one single section (with pMarker = NULL).
|
---|
116 | *
|
---|
117 | * @returns IPRT status code.
|
---|
118 | * @param pszFilename The path to the file to read.
|
---|
119 | * @param fFlags Flags reserved for future hacks.
|
---|
120 | * @param paMarkers Array of one or more section markers to look for.
|
---|
121 | * @param cMarkers Number of markers in the array.
|
---|
122 | * @param ppSectionHead Where to return the head of the section list.
|
---|
123 | * @param pErrInfo Where to return extend error info. Optional.
|
---|
124 | */
|
---|
125 | RTDECL(int) RTCrPemReadFile(const char *pszFilename, uint32_t fFlags, PCRTCRPEMMARKER paMarkers, size_t cMarkers,
|
---|
126 | PCRTCRPEMSECTION *ppSectionHead, PRTERRINFO pErrInfo);
|
---|
127 |
|
---|
128 | /** @} */
|
---|
129 |
|
---|
130 | RT_C_DECLS_END
|
---|
131 |
|
---|
132 | #endif
|
---|
133 |
|
---|