VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/crypto/x509-file.cpp@ 59620

最後變更 在這個檔案從59620是 59620,由 vboxsync 提交於 9 年 前

IPRT: Added 'off' parameter to RTVfsIoStrmSgWrite and RTVfsIoStrmSgRead so it's easier to write passthru layers. Added RTVfsIoStrmReadAll, RTVfsIoStrmReadAllFree, RTVfsIoStrmFromBuffer, RTManifestPtIosIsInstanceOf, RTCrX509Certificate_ReadFromBuffer and RTCrDigestUpdateFromVfsFile. Updated the manifest passthru read code to handle ReadAt requests which skips parts and jumps back to re-read stuff on streams/files which are seekable.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 5.9 KB
 
1/* $Id: x509-file.cpp 59620 2016-02-10 00:47:33Z vboxsync $ */
2/** @file
3 * IPRT - Crypto - X.509, File related APIs.
4 */
5
6/*
7 * Copyright (C) 2006-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "internal/iprt.h"
32#include <iprt/crypto/x509.h>
33
34#include <iprt/assert.h>
35#include <iprt/err.h>
36#include <iprt/path.h>
37#include <iprt/crypto/pem.h>
38
39
40/*********************************************************************************************************************************
41* Global Variables *
42*********************************************************************************************************************************/
43static RTCRPEMMARKERWORD const g_aWords_Certificate[] = { { RT_STR_TUPLE("CERTIFICATE") } };
44/** X509 Certificate markers. */
45static RTCRPEMMARKER const g_aCertificateMarkers[] = { { g_aWords_Certificate, RT_ELEMENTS(g_aWords_Certificate) } };
46
47
48RTDECL(int) RTCrX509Certificate_ReadFromFile(PRTCRX509CERTIFICATE pCertificate, const char *pszFilename, uint32_t fFlags,
49 PCRTASN1ALLOCATORVTABLE pAllocator, PRTERRINFO pErrInfo)
50{
51 AssertReturn(!fFlags, VERR_INVALID_FLAGS);
52 PCRTCRPEMSECTION pSectionHead;
53 int rc = RTCrPemReadFile(pszFilename, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), &pSectionHead, pErrInfo);
54 if (RT_SUCCESS(rc))
55 {
56 RTCRX509CERTIFICATE TmpCert;
57 RTASN1CURSORPRIMARY PrimaryCursor;
58 RTAsn1CursorInitPrimary(&PrimaryCursor, pSectionHead->pbData, (uint32_t)RT_MIN(pSectionHead->cbData, UINT32_MAX),
59 pErrInfo, pAllocator, RTASN1CURSOR_FLAGS_DER, RTPathFilename(pszFilename));
60 rc = RTCrX509Certificate_DecodeAsn1(&PrimaryCursor.Cursor, 0, &TmpCert, "Cert");
61 if (RT_SUCCESS(rc))
62 {
63 rc = RTCrX509Certificate_CheckSanity(&TmpCert, 0, pErrInfo, "Cert");
64 if (RT_SUCCESS(rc))
65 {
66 rc = RTCrX509Certificate_Clone(pCertificate, &TmpCert, &g_RTAsn1DefaultAllocator);
67 if (RT_SUCCESS(rc))
68 {
69 if (pSectionHead->pNext || PrimaryCursor.Cursor.cbLeft)
70 rc = VINF_ASN1_MORE_DATA;
71 }
72 }
73 RTCrX509Certificate_Delete(&TmpCert);
74 }
75 RTCrPemFreeSections(pSectionHead);
76 }
77 return rc;
78}
79
80
81RTDECL(int) RTCrX509Certificate_ReadFromBuffer(PRTCRX509CERTIFICATE pCertificate, const void *pvBuf, size_t cbBuf,
82 uint32_t fFlags, PCRTASN1ALLOCATORVTABLE pAllocator,
83 PRTERRINFO pErrInfo, const char *pszErrorTag)
84{
85 AssertReturn(!fFlags, VERR_INVALID_FLAGS);
86 PCRTCRPEMSECTION pSectionHead;
87 int rc = RTCrPemParseContent(pvBuf, cbBuf, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers),
88 &pSectionHead, pErrInfo);
89 if (RT_SUCCESS(rc))
90 {
91 RTCRX509CERTIFICATE TmpCert;
92 RTASN1CURSORPRIMARY PrimaryCursor;
93 RTAsn1CursorInitPrimary(&PrimaryCursor, pSectionHead->pbData, (uint32_t)RT_MIN(pSectionHead->cbData, UINT32_MAX),
94 pErrInfo, pAllocator, RTASN1CURSOR_FLAGS_DER, pszErrorTag);
95 rc = RTCrX509Certificate_DecodeAsn1(&PrimaryCursor.Cursor, 0, &TmpCert, "Cert");
96 if (RT_SUCCESS(rc))
97 {
98 rc = RTCrX509Certificate_CheckSanity(&TmpCert, 0, pErrInfo, "Cert");
99 if (RT_SUCCESS(rc))
100 {
101 rc = RTCrX509Certificate_Clone(pCertificate, &TmpCert, &g_RTAsn1DefaultAllocator);
102 if (RT_SUCCESS(rc))
103 {
104 if (pSectionHead->pNext || PrimaryCursor.Cursor.cbLeft)
105 rc = VINF_ASN1_MORE_DATA;
106 }
107 }
108 RTCrX509Certificate_Delete(&TmpCert);
109 }
110 RTCrPemFreeSections(pSectionHead);
111 }
112 return rc;
113}
114
115
116
117#if 0
118RTDECL(int) RTCrX509Certificates_ReadFromFile(const char *pszFilename, uint32_t fFlags,
119 PRTCRX509CERTIFICATES pCertificates, PRTERRINFO pErrInfo)
120{
121 AssertReturn(!fFlags, VERR_INVALID_FLAGS);
122 PCRTCRPEMSECTION pSectionHead;
123 int rc = RTCrPemReadFile(pszFilename, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), &pSectionHead, pErrInfo);
124 if (RT_SUCCESS(rc))
125 {
126 pCertificates->Allocation
127
128 PCRTCRPEMSECTION pCurSec = pSectionHead;
129 while (pCurSec)
130 {
131
132 pCurSec = pCurSec->pNext;
133 }
134
135 RTCrPemFreeSections(pSectionHead);
136 }
137 return rc;
138}
139#endif
140
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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