internal static RecipientInfoType GetRecipientInfoType(X509Certificate2 certificate) { RecipientInfoType unknown = RecipientInfoType.Unknown; if (certificate == null) { return(unknown); } System.Security.Cryptography.CAPI.CERT_CONTEXT cert_context = (System.Security.Cryptography.CAPI.CERT_CONTEXT)Marshal.PtrToStructure(System.Security.Cryptography.X509Certificates.X509Utils.GetCertContext(certificate).DangerousGetHandle(), typeof(System.Security.Cryptography.CAPI.CERT_CONTEXT)); System.Security.Cryptography.CAPI.CERT_INFO cert_info = (System.Security.Cryptography.CAPI.CERT_INFO)Marshal.PtrToStructure(cert_context.pCertInfo, typeof(System.Security.Cryptography.CAPI.CERT_INFO)); switch (System.Security.Cryptography.X509Certificates.X509Utils.OidToAlgId(cert_info.SubjectPublicKeyInfo.Algorithm.pszObjId)) { case 0xa400: return(RecipientInfoType.KeyTransport); case 0xaa01: case 0xaa02: return(RecipientInfoType.KeyAgreement); } return(RecipientInfoType.Unknown); }
internal SubjectIdentifier(System.Security.Cryptography.CAPI.CERT_INFO certInfo) : this(certInfo.Issuer, certInfo.SerialNumber) { }
internal unsafe RecipientInfoCollection(System.Security.Cryptography.SafeCryptMsgHandle safeCryptMsgHandle) { bool flag = PkcsUtils.CmsSupported(); uint num = 0; uint num2 = (uint)Marshal.SizeOf(typeof(uint)); if (flag) { if (!System.Security.Cryptography.CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, 0x21, 0, new IntPtr((void *)&num), new IntPtr((void *)&num2))) { throw new CryptographicException(Marshal.GetLastWin32Error()); } } else if (!System.Security.Cryptography.CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, 0x11, 0, new IntPtr((void *)&num), new IntPtr((void *)&num2))) { throw new CryptographicException(Marshal.GetLastWin32Error()); } this.m_recipientInfos = new ArrayList(); for (uint i = 0; i < num; i++) { uint num4; System.Security.Cryptography.SafeLocalAllocHandle handle; System.Security.Cryptography.CAPI.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO cmsg_key_agree_public_key_recipient_info; uint num7; System.Security.Cryptography.SafeLocalAllocHandle handle2; if (!flag) { goto Label_020B; } PkcsUtils.GetParam(safeCryptMsgHandle, 0x24, i, out handle, out num4); System.Security.Cryptography.CAPI.CMSG_CMS_RECIPIENT_INFO cmsg_cms_recipient_info = (System.Security.Cryptography.CAPI.CMSG_CMS_RECIPIENT_INFO)Marshal.PtrToStructure(handle.DangerousGetHandle(), typeof(System.Security.Cryptography.CAPI.CMSG_CMS_RECIPIENT_INFO)); switch (cmsg_cms_recipient_info.dwRecipientChoice) { case 1: { System.Security.Cryptography.CAPI.CMSG_KEY_TRANS_RECIPIENT_INFO keyTrans = (System.Security.Cryptography.CAPI.CMSG_KEY_TRANS_RECIPIENT_INFO)Marshal.PtrToStructure(cmsg_cms_recipient_info.pRecipientInfo, typeof(System.Security.Cryptography.CAPI.CMSG_KEY_TRANS_RECIPIENT_INFO)); this.m_recipientInfos.Add(new KeyTransRecipientInfo(handle, keyTrans, i)); continue; } case 2: { System.Security.Cryptography.CAPI.CMSG_KEY_AGREE_RECIPIENT_INFO cmsg_key_agree_recipient_info = (System.Security.Cryptography.CAPI.CMSG_KEY_AGREE_RECIPIENT_INFO)Marshal.PtrToStructure(cmsg_cms_recipient_info.pRecipientInfo, typeof(System.Security.Cryptography.CAPI.CMSG_KEY_AGREE_RECIPIENT_INFO)); switch (cmsg_key_agree_recipient_info.dwOriginatorChoice) { case 2: goto Label_0192; } throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Cms_Invalid_Originator_Identifier_Choice"), cmsg_key_agree_recipient_info.dwOriginatorChoice.ToString(CultureInfo.CurrentCulture)); } default: throw new CryptographicException(-2147483647); } System.Security.Cryptography.CAPI.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO certIdRecipient = (System.Security.Cryptography.CAPI.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO)Marshal.PtrToStructure(cmsg_cms_recipient_info.pRecipientInfo, typeof(System.Security.Cryptography.CAPI.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO)); for (uint j = 0; j < certIdRecipient.cRecipientEncryptedKeys; j++) { this.m_recipientInfos.Add(new KeyAgreeRecipientInfo(handle, certIdRecipient, i, j)); } continue; Label_0192: cmsg_key_agree_public_key_recipient_info = (System.Security.Cryptography.CAPI.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO)Marshal.PtrToStructure(cmsg_cms_recipient_info.pRecipientInfo, typeof(System.Security.Cryptography.CAPI.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO)); for (uint k = 0; k < cmsg_key_agree_public_key_recipient_info.cRecipientEncryptedKeys; k++) { this.m_recipientInfos.Add(new KeyAgreeRecipientInfo(handle, cmsg_key_agree_public_key_recipient_info, i, k)); } continue; Label_020B: PkcsUtils.GetParam(safeCryptMsgHandle, 0x13, i, out handle2, out num7); System.Security.Cryptography.CAPI.CERT_INFO certInfo = (System.Security.Cryptography.CAPI.CERT_INFO)Marshal.PtrToStructure(handle2.DangerousGetHandle(), typeof(System.Security.Cryptography.CAPI.CERT_INFO)); this.m_recipientInfos.Add(new KeyTransRecipientInfo(handle2, certInfo, i)); } this.m_safeCryptMsgHandle = safeCryptMsgHandle; }
internal unsafe KeyTransRecipientInfo(System.Security.Cryptography.SafeLocalAllocHandle pRecipientInfo, System.Security.Cryptography.CAPI.CERT_INFO certInfo, uint index) : base(RecipientInfoType.KeyTransport, RecipientSubType.Pkcs7KeyTransport, pRecipientInfo, certInfo, index) { int version = 2; byte *pbData = (byte *)certInfo.SerialNumber.pbData; for (int i = 0; i < certInfo.SerialNumber.cbData; i++) { pbData++; if (pbData[0] != 0) { version = 0; break; } } this.Reset(version); }