VirtualBox

Changeset 57572 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Aug 28, 2015 1:31:29 AM (9 years ago)
Author:
vboxsync
Message:

IPRT: Started on accessing system certificate stores to get SSL roots for cURL.

Location:
trunk/include/iprt
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cdefs.h

    r57433 r57572  
    14521452 *
    14531453 * @param   a_szConst   String constant.
     1454 * @sa      RTSTRTUPLE
    14541455 */
    14551456#define RT_STR_TUPLE(a_szConst)  a_szConst, (sizeof(a_szConst) - 1)
  • trunk/include/iprt/crypto/pem.h

    r56291 r57572  
    117117 * @returns IPRT status code.
    118118 * @param   pszFilename     The path to the file to read.
    119  * @param   fFlags          Flags reserved for future hacks.
     119 * @param   fFlags          RTCRPEMREADFILE_F_XXX.
    120120 * @param   paMarkers       Array of one or more section markers to look for.
    121121 * @param   cMarkers        Number of markers in the array.
     
    125125RTDECL(int) RTCrPemReadFile(const char *pszFilename, uint32_t fFlags, PCRTCRPEMMARKER paMarkers, size_t cMarkers,
    126126                            PCRTCRPEMSECTION *ppSectionHead, PRTERRINFO pErrInfo);
     127/** @name RTCRPEMREADFILE_F_XXX - Flags for RTCrPemReadFile
     128 * @{ */
     129/** Continue on encoding error. */
     130#define RTCRPEMREADFILE_F_CONTINUE_ON_ENCODING_ERROR    RT_BIT(0)
     131/** @} */
    127132
    128133/** @} */
  • trunk/include/iprt/crypto/store.h

    r56291 r57572  
    5858
    5959
     60/**
     61 * Standard store identifiers.
     62 *
     63 * This is a least common denominator approach to system specific certificate
     64 * stores, could be extended to include things other than certificates later if
     65 * we need it.
     66 *
     67 * Windows has lots of different stores, they'll be combined by the
     68 * implementation, possibly leading to duplicates.  The user stores on Windows
     69 * seems to be unioned with the system (machine) stores.
     70 *
     71 * Linux may have different stores depending on the distro/version/installation,
     72 * in which case we'll combine them, which will most likely lead to
     73 * duplicates just like on windows.  Haven't found any easily accessible
     74 * per-user certificate stores on linux yet, so they'll all be empty.
     75 *
     76 * Mac OS X seems a lot simpler, at least from the GUI point of view.  Each
     77 * keychains as a "Certificates" folder (the "My Certificates" folder seems to
     78 * only be a matching of "Keys" and "Certificates"). However, there are two
     79 * system keychains that we need to combine, "System" and "System Roots".  As
     80 * with Windows and Linux, there is a possibility for duplicates here.
     81 *
     82 * On solaris we have currently no idea where to look for a certificate store,
     83 * so that doesn't yet work.
     84 *
     85 * Because of the OS X setup, we do not provide any purpose specific
     86 */
     87typedef enum RTCRSTOREID
     88{
     89    /** Mandatory invalid zero value. */
     90    RTCRSTOREID_INVALID = 0,
     91    /** Open the certificate store of the current user containing trusted
     92     * CAs and certificates.
     93     * @remarks This may or may not include all the certificates in the system
     94     *          store, that's host dependent.  So, you better look in both. */
     95    RTCRSTOREID_USER_TRUSTED_CAS_AND_CERTIFICATES,
     96    /** Open the certificate store of the system containg trusted CAs
     97     * and certificates. */
     98    RTCRSTOREID_SYSTEM_TRUSTED_CAS_AND_CERTIFICATES,
     99    /** End of valid values. */
     100    RTCRSTOREID_END,
     101    /** Traditional enum type compression prevention hack. */
     102    RTCRSTOREID_32BIT_HACK = 0x7fffffff
     103} RTCRSTOREID;
     104
     105/**
     106 * Creates a snapshot of a standard store.
     107 *
     108 * This will return an in-memory store containing all data from the given store.
     109 * There will be no duplicates in this one.
     110 *
     111 * @returns IPRT status code.
     112 * @retval  VWRN_ALREADY_EXISTS if the certificate is already present and
     113 *          RTCRCERTCTX_F_ADD_IF_NOT_FOUND was specified.
     114 * @param   phStore             Where to return the store handle. Use
     115 *                              RTCrStoreRelease to release it.
     116 * @param   enmStoreId          The store to snapshot.
     117 * @param   pErrInfo            Where to return additional error/warning info.
     118 *                              Optional.
     119 */
     120RTDECL(int) RTCrStoreCreateSnapshotById(PRTCRSTORE phStore, RTCRSTOREID enmStoreId, PRTERRINFO pErrInfo);
     121
    60122RTDECL(int) RTCrStoreCreateInMem(PRTCRSTORE phStore, uint32_t cSizeHint);
    61123
     
    63125RTDECL(uint32_t) RTCrStoreRelease(RTCRSTORE hStore);
    64126RTDECL(PCRTCRCERTCTX) RTCrStoreCertByIssuerAndSerialNo(RTCRSTORE hStore, PCRTCRX509NAME pIssuer, PCRTASN1INTEGER pSerialNo);
     127
     128/**
     129 * Add a certificate to the store.
     130 *
     131 * @returns IPRT status code.
     132 * @retval  VWRN_ALREADY_EXISTS if the certificate is already present and
     133 *          RTCRCERTCTX_F_ADD_IF_NOT_FOUND was specified.
     134 * @retval  VERR_WRITE_PROTECT if the store doesn't support adding.
     135 * @param   hStore              The store to add the certificate to.
     136 * @param   fFlags              RTCRCERTCTX_F_XXX. Encoding must be specified.
     137 *                              RTCRCERTCTX_F_ADD_IF_NOT_FOUND is supported.
     138 * @param   pvSrc               The encoded certificate bytes.
     139 * @param   cbSrc               The size of the encoded certificate.
     140 * @param   pErrInfo            Where to return additional error/warning info.
     141 *                              Optional.
     142 */
    65143RTDECL(int) RTCrStoreCertAddEncoded(RTCRSTORE hStore, uint32_t fFlags, void const *pvSrc, size_t cbSrc, PRTERRINFO pErrInfo);
     144
     145/**
     146 * Adds certificates from the specified file.
     147 *
     148 * @returns IPRT status code.  Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is
     149 *          used, an error is returned as an error (and not a warning).
     150 *
     151 * @param   hStore              The store to add the certificate(s) to.
     152 * @param   fFlags              RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or
     153 *                              RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR.
     154 * @param   pszFilename         The filename.
     155 * @param   pErrInfo            Where to return additional error/warning info.
     156 *                              Optional.
     157 */
    66158RTDECL(int) RTCrStoreCertAddFromFile(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo);
     159
     160/**
     161 * Adds certificates from files in the specified directory.
     162 *
     163 * @returns IPRT status code.  Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is
     164 *          used, an error is returned as an error (and not a warning).
     165 *
     166 * @param   hStore              The store to add the certificate(s) to.
     167 * @param   fFlags              RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or
     168 *                              RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR.
     169 * @param   pszDir              The path to the directory.
     170 * @param   paSuffixes          List of suffixes of files to process.
     171 * @param   cSuffixes           Number of suffixes.  If this is 0, all files are
     172 *                              processed.
     173 * @param   pErrInfo            Where to return additional error/warning info.
     174 *                              Optional.
     175 */
     176RTDECL(int) RTCrStoreCertAddFromDir(RTCRSTORE hStore, uint32_t fFlags, const char *pszDir,
     177                                    PCRTSTRTUPLE paSuffixes, size_t cSuffixes, PRTERRINFO pErrInfo);
     178
     179/**
     180 * Adds all certificates from @a hStoreSrc into @a hStore.
     181 *
     182 * @returns IPRT status code.  Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is
     183 *          used, an error is returned as an error (and not a warning).
     184 *
     185 * @param   hStore              The destination store.
     186 * @param   fFlags              RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or
     187 *                              RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR.
     188 * @param   hStoreSrc           The source store.
     189 */
     190RTDECL(int) RTCrStoreCertAddFromStore(RTCRSTORE hStore, uint32_t fFlags, RTCRSTORE hStoreSrc);
     191
     192/**
     193 * Exports the certificates in the store to a PEM file
     194 *
     195 * @returns IPRT status code.
     196 * @param   hStore              The store which certificates should be exported.
     197 * @param   fFlags              Reserved for the future, MBZ.
     198 * @param   pszFilename         The name of the destination PEM file.  This will
     199 *                              be truncated.
     200 */
     201RTDECL(int) RTCrStoreCertExportAsPem(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename);
    67202
    68203RTDECL(int) RTCrStoreCertFindAll(RTCRSTORE hStore, PRTCRSTORECERTSEARCH pSearch);
     
    119254#define RTCRCERTCTX_F_ENC_PKCS6_DER    UINT32_C(0x00000002)
    120255#endif
     256/** Mask containing the flags that ends up in the certificate context. */
     257#define RTCRCERTCTX_F_MASK             UINT32_C(0x000000ff)
     258
     259/** Add APIs: Add the certificate if not found. */
     260#define RTCRCERTCTX_F_ADD_IF_NOT_FOUND          UINT32_C(0x00010000)
     261/** Add APIs: Continue on error when possible. */
     262#define RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR     UINT32_C(0x00020000)
    121263/** @} */
    122264
  • trunk/include/iprt/crypto/x509.h

    r56291 r57572  
    165165
    166166/**
    167  * Matches the directory name against a comma separated list of the comonent
     167 * Matches the directory name against a comma separated list of the component
    168168 * strings (case sensitive).
    169169 *
  • trunk/include/iprt/mangling.h

    r57079 r57572  
    10501050# define RTPathCopyComponents                           RT_MANGLER(RTPathCopyComponents)
    10511051# define RTPathCountComponents                          RT_MANGLER(RTPathCountComponents)
     1052# define RTPathEnsureTrailingSeparator                  RT_MANGLER(RTPathEnsureTrailingSeparator)
    10521053# define RTPathExecDir                                  RT_MANGLER(RTPathExecDir)
    10531054# define RTPathExists                                   RT_MANGLER(RTPathExists)
     
    13441345# define RTSgBufGetNextSegment                          RT_MANGLER(RTSgBufGetNextSegment)
    13451346# define RTSha1                                         RT_MANGLER(RTSha1)
     1347# define RTSha1Check                                    RT_MANGLER(RTSha1Check)
    13461348# define RTSha1Digest                                   RT_MANGLER(RTSha1Digest)
    13471349# define RTSha1DigestFromFile                           RT_MANGLER(RTSha1DigestFromFile)
     
    13521354# define RTSha1Update                                   RT_MANGLER(RTSha1Update)
    13531355# define RTSha224                                       RT_MANGLER(RTSha224)
     1356# define RTSha224Check                                  RT_MANGLER(RTSha224Check)
    13541357# define RTSha224Final                                  RT_MANGLER(RTSha224Final)
    13551358# define RTSha224FromString                             RT_MANGLER(RTSha224FromString)
     
    13601363# define RTSha224DigestFromFile                         RT_MANGLER(RTSha224DigestFromFile)
    13611364# define RTSha256                                       RT_MANGLER(RTSha256)
     1365# define RTSha256Check                                  RT_MANGLER(RTSha256Check)
    13621366# define RTSha256Final                                  RT_MANGLER(RTSha256Final)
    13631367# define RTSha256FromString                             RT_MANGLER(RTSha256FromString)
     
    13681372# define RTSha256DigestFromFile                         RT_MANGLER(RTSha256DigestFromFile)
    13691373# define RTSha384                                       RT_MANGLER(RTSha384)
     1374# define RTSha384Check                                  RT_MANGLER(RTSha384Check)
    13701375# define RTSha384Final                                  RT_MANGLER(RTSha384Final)
    13711376# define RTSha384FromString                             RT_MANGLER(RTSha384FromString)
     
    13741379# define RTSha384Update                                 RT_MANGLER(RTSha384Update)
    13751380# define RTSha512                                       RT_MANGLER(RTSha512)
     1381# define RTSha512Check                                  RT_MANGLER(RTSha512Check)
    13761382# define RTSha512Final                                  RT_MANGLER(RTSha512Final)
    13771383# define RTSha512FromString                             RT_MANGLER(RTSha512FromString)
     
    13801386# define RTSha512Update                                 RT_MANGLER(RTSha512Update)
    13811387# define RTSha512t224                                   RT_MANGLER(RTSha512t224)
     1388# define RTSha512t224Check                              RT_MANGLER(RTSha512t224Check)
    13821389# define RTSha512t224Final                              RT_MANGLER(RTSha512t224Final)
    13831390# define RTSha512t224FromString                         RT_MANGLER(RTSha512t224FromString)
     
    13861393# define RTSha512t224Update                             RT_MANGLER(RTSha512t224Update)
    13871394# define RTSha512t256                                   RT_MANGLER(RTSha512t256)
     1395# define RTSha512t256Check                              RT_MANGLER(RTSha512t256Check)
    13881396# define RTSha512t256Final                              RT_MANGLER(RTSha512t256Final)
    13891397# define RTSha512t256FromString                         RT_MANGLER(RTSha512t256FromString)
     
    28922900# define RTCrStoreRetain                                RT_MANGLER(RTCrStoreRetain)
    28932901# define RTCrStoreCreateInMem                           RT_MANGLER(RTCrStoreCreateInMem)
     2902# define RTCrStoreCreateSnapshotById                    RT_MANGLER(RTCrStoreCreateSnapshotById)
    28942903# define RTCrStoreCertAddFromFile                       RT_MANGLER(RTCrStoreCertAddFromFile)
     2904# define RTCrStoreCertAddFromDir                        RT_MANGLER(RTCrStoreCertAddFromDir)
     2905# define RTCrStoreCertAddFromStore                      RT_MANGLER(RTCrStoreCertAddFromStore)
     2906# define RTCrStoreCertExportAsPem                       RT_MANGLER(RTCrStoreCertExportAsPem)
    28952907# define RTErrInfoAdd                                   RT_MANGLER(RTErrInfoAdd)
    28962908# define RTErrInfoAddF                                  RT_MANGLER(RTErrInfoAddF)
  • trunk/include/iprt/path.h

    r56291 r57572  
    357357 */
    358358RTDECL(size_t) RTPathStripTrailingSlash(char *pszPath);
     359
     360/**
     361 * Ensures that the path has a trailing path separator such that file names can
     362 * be appended without further work.
     363 *
     364 * This can be helpful when preparing for efficiently combining a directory path
     365 * with the filenames returned by RTDirRead.  The return value gives you the
     366 * position at which you copy the RTDIRENTRY::szName to construct a valid path
     367 * to it.
     368 *
     369 * @returns The length of the path, 0 on buffer overflow.
     370 * @param   pszPath     The path.
     371 * @param   cbPath      The length of the path buffer @a pszPath points to.
     372 */
     373RTDECL(size_t) RTPathEnsureTrailingSeparator(char *pszPath, size_t cbPath);
    359374
    360375/**
  • trunk/include/iprt/sha.h

    r56291 r57572  
    6969
    7070/**
     71 * Computes the SHA-1 hash for the given data comparing it with the one given.
     72 *
     73 * @returns true on match, false on mismatch.
     74 * @param   pvBuf       Pointer to the data.
     75 * @param   cbBuf       The amount of data (in bytes).
     76 * @param   pabHash     The hash to verify. (What is passed is a pointer to the
     77 *                      caller's buffer.)
     78 */
     79RTDECL(bool) RTSha1Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA1_HASH_SIZE]);
     80
     81/**
    7182 * Initializes the SHA-1 context.
    7283 *
     
    177188
    178189/**
     190 * Computes the SHA-256 hash for the given data comparing it with the one given.
     191 *
     192 * @returns true on match, false on mismatch.
     193 * @param   pvBuf       Pointer to the data.
     194 * @param   cbBuf       The amount of data (in bytes).
     195 * @param   pabHash     The hash to verify. (What is passed is a pointer to the
     196 *                      caller's buffer.)
     197 */
     198RTDECL(bool) RTSha256Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA256_HASH_SIZE]);
     199
     200/**
    179201 * Initializes the SHA-256 context.
    180202 *
     
    275297
    276298/**
     299 * Computes the SHA-224 hash for the given data comparing it with the one given.
     300 *
     301 * @returns true on match, false on mismatch.
     302 * @param   pvBuf       Pointer to the data.
     303 * @param   cbBuf       The amount of data (in bytes).
     304 * @param   pabHash     The hash to verify. (What is passed is a pointer to the
     305 *                      caller's buffer.)
     306 */
     307RTDECL(bool) RTSha224Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA224_HASH_SIZE]);
     308
     309/**
    277310 * Initializes the SHA-224 context.
    278311 *
     
    383416
    384417/**
     418 * Computes the SHA-512 hash for the given data comparing it with the one given.
     419 *
     420 * @returns true on match, false on mismatch.
     421 * @param   pvBuf       Pointer to the data.
     422 * @param   cbBuf       The amount of data (in bytes).
     423 * @param   pabHash     The hash to verify. (What is passed is a pointer to the
     424 *                      caller's buffer.)
     425 */
     426RTDECL(bool) RTSha512Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA512_HASH_SIZE]);
     427
     428/**
    385429 * Initializes the SHA-512 context.
    386430 *
     
    438482    typedef RTSHA512CONTEXT *RT_CONCAT3(PRTSHA,a_UName,CONTEXT); \
    439483    RTDECL(void) RT_CONCAT(RTSha,a_Name)(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RT_CONCAT3(RTSHA,a_UName,_HASH_SIZE)]); \
     484    RTDECL(bool) RT_CONCAT3(RTSha,a_Name,Check)(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RT_CONCAT3(RTSHA,a_UName,_HASH_SIZE)]); \
    440485    RTDECL(void) RT_CONCAT3(RTSha,a_Name,Init)(RT_CONCAT3(PRTSHA,a_UName,CONTEXT) pCtx); \
    441486    RTDECL(void) RT_CONCAT3(RTSha,a_Name,Update)(RT_CONCAT3(PRTSHA,a_UName,CONTEXT) pCtx, const void *pvBuf, size_t cbBuf); \
  • trunk/include/iprt/types.h

    r57004 r57572  
    21762176
    21772177/**
     2178 * String tuple to go with the RT_STR_TUPLE macro.
     2179 */
     2180typedef struct RTSTRTUPLE
     2181{
     2182    /** The string. */
     2183    const char *psz;
     2184    /** The string length. */
     2185    size_t      cch;
     2186} RTSTRTUPLE;
     2187/** Pointer to a string tuple. */
     2188typedef RTSTRTUPLE *PRTSTRTUPLE;
     2189/** Pointer to a const string tuple. */
     2190typedef RTSTRTUPLE const *PCRTSTRTUPLE;
     2191
     2192/**
    21782193 * Wait for ever if we have to.
    21792194 */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette