internal KeyTransRecipientInfo(SafeLocalAllocHandle pRecipientInfo, CAPI.CERT_INFO certInfo, uint index) : base(RecipientInfoType.KeyTransport, RecipientSubType.Pkcs7KeyTransport, pRecipientInfo, (object)certInfo, index) { int version = 2; byte *numPtr = (byte *)(void *)certInfo.SerialNumber.pbData; for (int index1 = 0; (long)index1 < (long)certInfo.SerialNumber.cbData; ++index1) { if ((int)*numPtr++ != 0) { version = 0; break; } } this.Reset(version); }
internal unsafe KeyTransRecipientInfo(SafeLocalAllocHandle pRecipientInfo, CAPI.CERT_INFO certInfo, uint index) : base(RecipientInfoType.KeyTransport, RecipientSubType.Pkcs7KeyTransport, pRecipientInfo, certInfo, index) { // If serial number is 0, then it is the special SKI encoding. int version = 2; byte *pb = (byte *)certInfo.SerialNumber.pbData; for (int i = 0; i < certInfo.SerialNumber.cbData; i++) { if (*pb++ != (byte)0) { version = 0; break; } } Reset(version); }
internal unsafe X509ExtensionCollection(SafeCertContextHandle safeCertContextHandle) { using (SafeCertContextHandle certContext = CAPI.CertDuplicateCertificateContext(safeCertContextHandle)) { CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT *)certContext.DangerousGetHandle()); CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO)Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); uint cExtensions = pCertInfo.cExtension; IntPtr rgExtensions = pCertInfo.rgExtension; for (uint index = 0; index < cExtensions; index++) { X509Extension extension = new X509Extension(new IntPtr((long)rgExtensions + (index * Marshal.SizeOf(typeof(CAPI.CERT_EXTENSION))))); X509Extension customExtension = CryptoConfig.CreateFromName(extension.Oid.Value) as X509Extension; if (customExtension != null) { customExtension.CopyFrom(extension); extension = customExtension; } Add(extension); } } }
internal SubjectIdentifier(CAPI.CERT_INFO certInfo) : this(certInfo.Issuer, certInfo.SerialNumber) { }
internal RecipientInfoCollection(SafeCryptMsgHandle safeCryptMsgHandle) { bool flag = PkcsUtils.CmsSupported(); uint num1 = 0U; uint num2 = (uint)Marshal.SizeOf(typeof(uint)); if (flag) { if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, 33U, 0U, new IntPtr((void *)&num1), new IntPtr((void *)&num2))) { throw new CryptographicException(Marshal.GetLastWin32Error()); } } else if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, 17U, 0U, new IntPtr((void *)&num1), new IntPtr((void *)&num2))) { throw new CryptographicException(Marshal.GetLastWin32Error()); } this.m_recipientInfos = new ArrayList(); for (uint index = 0U; index < num1; ++index) { if (flag) { SafeLocalAllocHandle pvData; uint cbData; PkcsUtils.GetParam(safeCryptMsgHandle, 36U, index, out pvData, out cbData); CAPI.CMSG_CMS_RECIPIENT_INFO cmsRecipientInfo = (CAPI.CMSG_CMS_RECIPIENT_INFO)Marshal.PtrToStructure(pvData.DangerousGetHandle(), typeof(CAPI.CMSG_CMS_RECIPIENT_INFO)); switch (cmsRecipientInfo.dwRecipientChoice) { case 1U: CAPI.CMSG_KEY_TRANS_RECIPIENT_INFO keyTrans = (CAPI.CMSG_KEY_TRANS_RECIPIENT_INFO)Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(CAPI.CMSG_KEY_TRANS_RECIPIENT_INFO)); this.m_recipientInfos.Add((object)new KeyTransRecipientInfo(pvData, keyTrans, index)); continue; case 2U: CAPI.CMSG_KEY_AGREE_RECIPIENT_INFO agreeRecipientInfo = (CAPI.CMSG_KEY_AGREE_RECIPIENT_INFO)Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(CAPI.CMSG_KEY_AGREE_RECIPIENT_INFO)); switch (agreeRecipientInfo.dwOriginatorChoice) { case 1U: CAPI.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO certIdRecipient = (CAPI.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO)Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(CAPI.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO)); for (uint subIndex = 0U; subIndex < certIdRecipient.cRecipientEncryptedKeys; ++subIndex) { this.m_recipientInfos.Add((object)new KeyAgreeRecipientInfo(pvData, certIdRecipient, index, subIndex)); } continue; case 2U: CAPI.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO publicKeyRecipient = (CAPI.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO)Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(CAPI.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO)); for (uint subIndex = 0U; subIndex < publicKeyRecipient.cRecipientEncryptedKeys; ++subIndex) { this.m_recipientInfos.Add((object)new KeyAgreeRecipientInfo(pvData, publicKeyRecipient, index, subIndex)); } continue; default: throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Cms_Invalid_Originator_Identifier_Choice"), agreeRecipientInfo.dwOriginatorChoice.ToString((IFormatProvider)CultureInfo.CurrentCulture)); } default: throw new CryptographicException(-2147483647); } } else { SafeLocalAllocHandle pvData; uint cbData; PkcsUtils.GetParam(safeCryptMsgHandle, 19U, index, out pvData, out cbData); CAPI.CERT_INFO certInfo = (CAPI.CERT_INFO)Marshal.PtrToStructure(pvData.DangerousGetHandle(), typeof(CAPI.CERT_INFO)); this.m_recipientInfos.Add((object)new KeyTransRecipientInfo(pvData, certInfo, index)); } } this.m_safeCryptMsgHandle = safeCryptMsgHandle; }
internal unsafe RecipientInfoCollection(SafeCryptMsgHandle safeCryptMsgHandle) { bool cmsSupported = PkcsUtils.CmsSupported(); uint dwRecipients = 0; uint cbCount = (uint)Marshal.SizeOf(typeof(uint)); // Use CMS if supported. if (cmsSupported) { // CMS. if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, CAPI.CMSG_CMS_RECIPIENT_COUNT_PARAM, 0, new IntPtr(&dwRecipients), new IntPtr(&cbCount))) { throw new CryptographicException(Marshal.GetLastWin32Error()); } } else { // PKCS7. if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, CAPI.CMSG_RECIPIENT_COUNT_PARAM, 0, new IntPtr(&dwRecipients), new IntPtr(&cbCount))) { throw new CryptographicException(Marshal.GetLastWin32Error()); } } m_recipientInfos = new ArrayList(); for (uint index = 0; index < dwRecipients; index++) { if (cmsSupported) { uint cbCmsRecipientInfo; SafeLocalAllocHandle pbCmsRecipientInfo; PkcsUtils.GetParam(safeCryptMsgHandle, CAPI.CMSG_CMS_RECIPIENT_INFO_PARAM, index, out pbCmsRecipientInfo, out cbCmsRecipientInfo); CAPI.CMSG_CMS_RECIPIENT_INFO cmsRecipientInfo = (CAPI.CMSG_CMS_RECIPIENT_INFO)Marshal.PtrToStructure(pbCmsRecipientInfo.DangerousGetHandle(), typeof(CAPI.CMSG_CMS_RECIPIENT_INFO)); switch (cmsRecipientInfo.dwRecipientChoice) { case CAPI.CMSG_KEY_TRANS_RECIPIENT: CAPI.CMSG_KEY_TRANS_RECIPIENT_INFO keyTrans = (CAPI.CMSG_KEY_TRANS_RECIPIENT_INFO)Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(CAPI.CMSG_KEY_TRANS_RECIPIENT_INFO)); m_recipientInfos.Add(new KeyTransRecipientInfo(pbCmsRecipientInfo, keyTrans, index)); break; case CAPI.CMSG_KEY_AGREE_RECIPIENT: CAPI.CMSG_KEY_AGREE_RECIPIENT_INFO keyAgree = (CAPI.CMSG_KEY_AGREE_RECIPIENT_INFO)Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(CAPI.CMSG_KEY_AGREE_RECIPIENT_INFO)); switch (keyAgree.dwOriginatorChoice) { case CAPI.CMSG_KEY_AGREE_ORIGINATOR_CERT: CAPI.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO certIdRecipient = (CAPI.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO)Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(CAPI.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO)); for (uint cRecipient = 0; cRecipient < certIdRecipient.cRecipientEncryptedKeys; cRecipient++) { m_recipientInfos.Add(new KeyAgreeRecipientInfo(pbCmsRecipientInfo, certIdRecipient, index, cRecipient)); } break; case CAPI.CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY: CAPI.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO publicKeyRecipient = (CAPI.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO)Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(CAPI.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO)); for (uint cRecipient = 0; cRecipient < publicKeyRecipient.cRecipientEncryptedKeys; cRecipient++) { m_recipientInfos.Add(new KeyAgreeRecipientInfo(pbCmsRecipientInfo, publicKeyRecipient, index, cRecipient)); } break; default: throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Cms_Invalid_Originator_Identifier_Choice"), keyAgree.dwOriginatorChoice.ToString(CultureInfo.CurrentCulture)); } break; default: throw new CryptographicException(CAPI.E_NOTIMPL); } } else { uint cbCertInfo; SafeLocalAllocHandle pbCertInfo; PkcsUtils.GetParam(safeCryptMsgHandle, CAPI.CMSG_RECIPIENT_INFO_PARAM, index, out pbCertInfo, out cbCertInfo); CAPI.CERT_INFO certInfo = (CAPI.CERT_INFO)Marshal.PtrToStructure(pbCertInfo.DangerousGetHandle(), typeof(CAPI.CERT_INFO)); m_recipientInfos.Add(new KeyTransRecipientInfo(pbCertInfo, certInfo, index)); } } m_safeCryptMsgHandle = safeCryptMsgHandle; }