13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @file
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * IPRT - Cryptographic (Certificate) Store.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/*
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Copyright (C) 2006-2014 Oracle Corporation
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * available from http://www.virtualbox.org. This file is free software;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * General Public License (GPL) as published by the Free Software
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The contents of this file may alternatively be used under the terms
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * of the Common Development and Distribution License Version 1.0
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution, in which case the provisions of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * CDDL are applicable instead of those of the GPL.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * You may elect to license modified versions of this file under the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * terms and conditions of either the GPL or the CDDL or both.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#ifndef ___iprt_crypto_store_h
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define ___iprt_crypto_store_h
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include <iprt/crypto/x509.h>
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include <iprt/crypto/taf.h>
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRT_C_DECLS_BEGIN
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @defgroup grp_rt_crstore RTCrStore - Crypotgraphic (Certificate) Store.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @ingroup grp_rt_crypto
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * A certificate store search.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Used by the store provider to keep track of the current location of a
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * certificate search.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef struct RTCRSTORECERTSEARCH
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Opaque provider specific storage.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Provider restriction: The provider is only allowed to use the two first
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * entries for the find-all searches, because the front-end API may want the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * last two for implementing specific searches on top of it. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uintptr_t auOpaque[4];
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync} RTCRSTORECERTSEARCH;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Pointer to a certificate store search. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef RTCRSTORECERTSEARCH *PRTCRSTORECERTSEARCH;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTCrStoreCreateInMem(PRTCRSTORE phStore, uint32_t cSizeHint);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(uint32_t) RTCrStoreRetain(RTCRSTORE hStore);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(uint32_t) RTCrStoreRelease(RTCRSTORE hStore);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(PCRTCRCERTCTX) RTCrStoreCertByIssuerAndSerialNo(RTCRSTORE hStore, PCRTCRX509NAME pIssuer, PCRTASN1INTEGER pSerialNo);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTCrStoreCertAddEncoded(RTCRSTORE hStore, uint32_t fFlags, void const *pvSrc, size_t cbSrc, PRTERRINFO pErrInfo);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTCrStoreCertAddFromFile(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTCrStoreCertFindAll(RTCRSTORE hStore, PRTCRSTORECERTSEARCH pSearch);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTCrStoreCertFindBySubjectOrAltSubjectByRfc5280(RTCRSTORE hStore, PCRTCRX509NAME pSubject,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PRTCRSTORECERTSEARCH pSearch);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(PCRTCRCERTCTX) RTCrStoreCertSearchNext(RTCRSTORE hStore, PRTCRSTORECERTSEARCH pSearch);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTCrStoreCertSearchDestroy(RTCRSTORE hStore, PRTCRSTORECERTSEARCH pSearch);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTCrStoreConvertToOpenSslCertStore(RTCRSTORE hStore, uint32_t fFlags, void **ppvOpenSslStore);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTCrStoreConvertToOpenSslCertStack(RTCRSTORE hStore, uint32_t fFlags, void **ppvOpenSslStack);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @} */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @defgroup grp_rt_crcertctx RTCrCertCtx - (Store) Certificate Context.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @{ */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Certificate context.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This is returned by the certificate store APIs and is part of a larger
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * reference counted structure. All the data is read only.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef struct RTCRCERTCTX
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Flags, RTCRCERTCTX_F_XXX. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint32_t fFlags;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The size of the (DER) encoded certificate. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint32_t cbEncoded;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Pointer to the (DER) encoded certificate. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint8_t const *pabEncoded;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Pointer to the decoded X.509 representation of the certificate.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This can be NULL when pTaInfo is present. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PCRTCRX509CERTIFICATE pCert;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Pointer to the decoded TrustAnchorInfo for the certificate. This can be
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * NULL, even for trust anchors, as long as pCert isn't. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PCRTCRTAFTRUSTANCHORINFO pTaInfo;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Reserved for future use. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync void *paReserved[2];
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync} RTCRCERTCTX;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @name RTCRCERTCTX_F_XXX.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @{ */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Encoding mask. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define RTCRCERTCTX_F_ENC_MASK UINT32_C(0x000000ff)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** X.509 certificate, DER encoded. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define RTCRCERTCTX_F_ENC_X509_DER UINT32_C(0x00000000)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** RTF-5914 trust anchor info, DER encoded. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define RTCRCERTCTX_F_ENC_TAF_DER UINT32_C(0x00000001)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#if 0
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Extended certificate, DER encoded. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define RTCRCERTCTX_F_ENC_PKCS6_DER UINT32_C(0x00000002)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#endif
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @} */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(uint32_t) RTCrCertCtxRetain(PCRTCRCERTCTX pCertCtx);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(uint32_t) RTCrCertCtxRelease(PCRTCRCERTCTX pCertCtx);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @} */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRT_C_DECLS_END
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#endif
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync