Changeset 95604 in vbox for trunk/src/VBox/Runtime/common/crypto
- Timestamp:
- Jul 12, 2022 9:37:41 AM (3 years ago)
- Location:
- trunk/src/VBox/Runtime/common/crypto
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/crypto/iprt-openssl.cpp
r93115 r95604 37 37 # include <iprt/asn1.h> 38 38 # include <iprt/crypto/digest.h> 39 # include <iprt/crypto/pkcs7.h> 39 40 40 41 # include "internal/iprt-openssl.h" … … 139 140 } 140 141 142 DECLHIDDEN(int) rtCrOpenSslConvertPkcs7Attribute(void **ppvOsslAttrib, PCRTCRPKCS7ATTRIBUTE pAttrib, PRTERRINFO pErrInfo) 143 { 144 const unsigned char *pabEncoded; 145 uint32_t cbEncoded; 146 void *pvFree; 147 int rc = RTAsn1EncodeQueryRawBits(RTCrPkcs7Attribute_GetAsn1Core(pAttrib), 148 (const uint8_t **)&pabEncoded, &cbEncoded, &pvFree, pErrInfo); 149 if (RT_SUCCESS(rc)) 150 { 151 X509_ATTRIBUTE *pOsslAttrib = NULL; 152 X509_ATTRIBUTE *pOsslAttribRet = d2i_X509_ATTRIBUTE(&pOsslAttrib, &pabEncoded, cbEncoded); 153 RTMemTmpFree(pvFree); 154 if (pOsslAttribRet == pOsslAttrib) 155 { 156 *ppvOsslAttrib = pOsslAttrib; 157 return VINF_SUCCESS; 158 } 159 rc = RTErrInfoSet(pErrInfo, VERR_CR_X509_OSSL_D2I_FAILED, "d2i_X509_ATTRIBUTE"); 160 } 161 *ppvOsslAttrib = NULL; 162 return rc; 163 } 164 165 166 DECLHIDDEN(void) rtCrOpenSslFreeConvertedPkcs7Attribute(void *pvOsslAttrib) 167 { 168 X509_ATTRIBUTE_free((X509_ATTRIBUTE *)pvOsslAttrib); 169 } 170 171 141 172 #endif /* IPRT_WITH_OPENSSL */ 142 173 -
trunk/src/VBox/Runtime/common/crypto/pkcs7-sign.cpp
r95595 r95604 146 146 if (pCms != NULL) 147 147 { 148 RT_NOREF(pAdditionalAuthenticatedAttribs); /** @todo */ 149 if ( CMS_add1_signer(pCms, pOsslSigner, pEvpPrivateKey, pEvpMd, fOsslSign) != NULL)148 CMS_SignerInfo *pSignerInfo = CMS_add1_signer(pCms, pOsslSigner, pEvpPrivateKey, pEvpMd, fOsslSign); 149 if (pSignerInfo) 150 150 { 151 rc = CMS_final(pCms, pOsslData, NULL /*dcont*/, fOsslSign); 152 if (rc > 0) 151 if (pAdditionalAuthenticatedAttribs) 152 for (uint32_t i = 0; i < pAdditionalAuthenticatedAttribs->cItems && RT_SUCCESS(rc); i++) 153 { 154 PCRTCRPKCS7ATTRIBUTE pAttrib = pAdditionalAuthenticatedAttribs->papItems[i]; 155 X509_ATTRIBUTE *pOsslAttrib; 156 rc = rtCrOpenSslConvertPkcs7Attribute((void **)&pOsslAttrib, pAttrib, pErrInfo); 157 if (RT_SUCCESS(rc)) 158 { 159 rc = CMS_signed_add1_attr(pSignerInfo, pOsslAttrib); 160 rtCrOpenSslFreeConvertedPkcs7Attribute((void **)pOsslAttrib); 161 if (rc <= 0) 162 rc = RTErrInfoSet(pErrInfo, VERR_NO_MEMORY, "CMS_signed_add1_attr"); 163 } 164 } 165 if (RT_SUCCESS(rc)) 153 166 { 154 /* 155 * Get the output and copy it into the result buffer. 156 */ 157 BIO *pOsslResult = BIO_new(BIO_s_mem()); 158 if (pOsslResult) 167 rc = CMS_final(pCms, pOsslData, NULL /*dcont*/, fOsslSign); 168 if (rc > 0) 159 169 { 160 rc = i2d_CMS_bio(pOsslResult, pCms); 161 if (rc > 0) 170 /* 171 * Get the output and copy it into the result buffer. 172 */ 173 BIO *pOsslResult = BIO_new(BIO_s_mem()); 174 if (pOsslResult) 162 175 { 163 BUF_MEM *pBuf = NULL; 164 rc = (int)BIO_get_mem_ptr(pOsslResult, &pBuf); 176 rc = i2d_CMS_bio(pOsslResult, pCms); 165 177 if (rc > 0) 166 178 { 167 AssertPtr(pBuf); 168 size_t const cbResult = pBuf->length; 169 if ( cbResultBuf >= cbResult 170 && pvResult != NULL) 179 BUF_MEM *pBuf = NULL; 180 rc = (int)BIO_get_mem_ptr(pOsslResult, &pBuf); 181 if (rc > 0) 171 182 { 172 memcpy(pvResult, pBuf->data, cbResult); 173 rc = VINF_SUCCESS; 183 AssertPtr(pBuf); 184 size_t const cbResult = pBuf->length; 185 if ( cbResultBuf >= cbResult 186 && pvResult != NULL) 187 { 188 memcpy(pvResult, pBuf->data, cbResult); 189 rc = VINF_SUCCESS; 190 } 191 else 192 rc = VERR_BUFFER_OVERFLOW; 193 *pcbResult = cbResult; 174 194 } 175 195 else 176 rc = VERR_BUFFER_OVERFLOW; 177 *pcbResult = cbResult; 196 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "BIO_get_mem_ptr"); 178 197 } 179 198 else 180 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "BIO_get_mem_ptr"); 199 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "i2d_CMS_bio"); 200 BIO_free(pOsslResult); 181 201 } 182 202 else 183 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "i2d_CMS_bio"); 184 BIO_free(pOsslResult); 203 rc = RTErrInfoSet(pErrInfo, VERR_NO_MEMORY, "BIO_new/BIO_s_mem"); 185 204 } 186 205 else 187 rc = RTErrInfoSet(pErrInfo, VERR_ NO_MEMORY, "BIO_new/BIO_s_mem");206 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "CMS_final"); 188 207 } 189 else190 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "CMS_final");191 208 } 192 209 else
Note:
See TracChangeset
for help on using the changeset viewer.