Changeset 84248 in vbox for trunk/src/VBox/Runtime/common/crypto/pkcs7-sign.cpp
- Timestamp:
- May 11, 2020 11:46:40 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 137857
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/crypto/pkcs7-sign.cpp
r84235 r84248 85 85 86 86 RTDECL(int) RTCrPkcs7SimpleSignSignedData(uint32_t fFlags, PCRTCRX509CERTIFICATE pSigner, RTCRKEY hPrivateKey, 87 void const *pvData, size_t cbData, RT CRSTORE hAdditionalCerts,88 void *pvResult, size_t *pcbResult, PRTERRINFO pErrInfo)87 void const *pvData, size_t cbData, RTDIGESTTYPE enmDigestType, 88 RTCRSTORE hAdditionalCerts, void *pvResult, size_t *pcbResult, PRTERRINFO pErrInfo) 89 89 { 90 90 size_t const cbResultBuf = *pcbResult; 91 91 *pcbResult = 0; 92 92 AssertReturn(!(fFlags & ~RTCRPKCS7SIGN_SD_F_VALID_MASK), VERR_INVALID_FLAGS); 93 #if defined(IPRT_WITH_OPENSSL)93 #ifdef IPRT_WITH_OPENSSL 94 94 AssertReturn((int)cbData >= 0 && (unsigned)cbData == cbData, VERR_TOO_MUCH_DATA); 95 96 /* 97 * Resolve the digest type. 98 */ 99 const EVP_MD *pEvpMd = NULL; 100 if (enmDigestType != RTDIGESTTYPE_UNKNOWN) 101 { 102 pEvpMd = (const EVP_MD *)rtCrOpenSslConvertDigestType(enmDigestType, pErrInfo); 103 AssertReturn(pEvpMd, pErrInfo ? pErrInfo->rc : VERR_INVALID_PARAMETER); 104 } 95 105 96 106 /* … … 125 135 * Do the signing. 126 136 */ 127 unsigned int fOsslSign = CMS_BINARY ;137 unsigned int fOsslSign = CMS_BINARY | CMS_PARTIAL; 128 138 if (fFlags & RTCRPKCS7SIGN_SD_F_DEATCHED) 129 139 fOsslSign |= CMS_DETACHED; 130 140 if (fFlags & RTCRPKCS7SIGN_SD_F_NO_SMIME_CAP) 131 141 fOsslSign |= CMS_NOSMIMECAP; 132 CMS_ContentInfo *pCms = CMS_sign( pOsslSigner, pEvpPrivateKey, pOsslAdditionalCerts, pOsslData, fOsslSign);133 if (pCms )142 CMS_ContentInfo *pCms = CMS_sign(NULL, NULL, pOsslAdditionalCerts, NULL, fOsslSign); 143 if (pCms != NULL) 134 144 { 135 /* 136 * Get the output and copy it into the result buffer. 137 */ 138 BIO *pOsslResult = BIO_new(BIO_s_mem()); 139 if (pOsslResult) 145 if (CMS_add1_signer(pCms, pOsslSigner, pEvpPrivateKey, pEvpMd, fOsslSign) != NULL) 140 146 { 141 rc = i2d_CMS_bio(pOsslResult, pCms);147 rc = CMS_final(pCms, pOsslData, NULL /*dcont*/, fOsslSign); 142 148 if (rc > 0) 143 149 { 144 BUF_MEM *pBuf = NULL; 145 rc = (int)BIO_get_mem_ptr(pOsslResult, &pBuf); 146 if (rc > 0) 150 /* 151 * Get the output and copy it into the result buffer. 152 */ 153 BIO *pOsslResult = BIO_new(BIO_s_mem()); 154 if (pOsslResult) 147 155 { 148 AssertPtr(pBuf); 149 size_t const cbResult = pBuf->length; 150 if ( cbResultBuf >= cbResult 151 && pvResult != NULL) 156 rc = i2d_CMS_bio(pOsslResult, pCms); 157 if (rc > 0) 152 158 { 153 memcpy(pvResult, pBuf->data, cbResult); 154 rc = VINF_SUCCESS; 159 BUF_MEM *pBuf = NULL; 160 rc = (int)BIO_get_mem_ptr(pOsslResult, &pBuf); 161 if (rc > 0) 162 { 163 AssertPtr(pBuf); 164 size_t const cbResult = pBuf->length; 165 if ( cbResultBuf >= cbResult 166 && pvResult != NULL) 167 { 168 memcpy(pvResult, pBuf->data, cbResult); 169 rc = VINF_SUCCESS; 170 } 171 else 172 rc = VERR_BUFFER_OVERFLOW; 173 *pcbResult = cbResult; 174 } 175 else 176 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "BIO_get_mem_ptr"); 155 177 } 156 178 else 157 rc = VERR_BUFFER_OVERFLOW;158 *pcbResult = cbResult;179 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "i2d_CMS_bio"); 180 BIO_free(pOsslResult); 159 181 } 160 182 else 161 rc = RTErrInfoSet(pErrInfo, VERR_ GENERAL_FAILURE, "BIO_get_mem_ptr");183 rc = RTErrInfoSet(pErrInfo, VERR_NO_MEMORY, "BIO_new/BIO_s_mem"); 162 184 } 163 185 else 164 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "i2d_CMS_bio"); 165 BIO_free(pOsslResult); 186 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "CMS_final"); 166 187 } 167 188 else 168 rc = RTErrInfoSet(pErrInfo, VERR_ NO_MEMORY, "BIO_new/BIO_s_mem");189 rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "CMS_add1_signer"); 169 190 CMS_ContentInfo_free(pCms); 170 191 } … … 180 201 return rc; 181 202 #else 182 RT_NOREF(fFlags, pSigner, hPrivateKey, pvData, cbData, hAdditionalCerts, pvResult, pErrInfo, cbResultBuf);203 RT_NOREF(fFlags, pSigner, hPrivateKey, pvData, cbData, enmDigestType, hAdditionalCerts, pvResult, pErrInfo, cbResultBuf); 183 204 *pcbResult = 0; 184 205 return VERR_NOT_IMPLEMENTED;
Note:
See TracChangeset
for help on using the changeset viewer.