Example #1
0
        private static SIGNER_SIGN_EX2_PARAMS GetSignerSignEx2ParametersPointer(string timestampUrl, SignMode type,
                                                                                IntPtr subjectInfo, IntPtr signerCertificate, IntPtr provider, out GCHandle?signerSignHandle, string timestampAlgorithmOid)
        {
            // signature info
            var signatureInfo = new SIGNER_SIGNATURE_INFO
            {
                cbSize            = (uint)Marshal.SizeOf <SIGNER_SIGNATURE_INFO>(),
                algidHash         = Constants.CALG_SHA_256,
                dwAttrChoice      = Constants.DONT_CARE,
                pAttrAuthCode     = IntPtr.Zero,
                psAuthenticated   = IntPtr.Zero,
                psUnauthenticated = IntPtr.Zero,
            };

            var signatureHandle = Marshal.AllocHGlobal(Marshal.SizeOf <SIGNER_SIGNATURE_INFO>());

            Marshal.StructureToPtr(signatureInfo, signatureHandle, false);

            // signer sign ex params
            var signerSignEx2Params = new SIGNER_SIGN_EX2_PARAMS
            {
                dwFlags        = Constants.DONT_CARE,
                pSubjectInfo   = subjectInfo,
                pSigningCert   = signerCertificate,
                pSignatureInfo = signatureHandle,
                pProviderInfo  = provider,
            };

            if (!string.IsNullOrEmpty(timestampUrl))
            {
                signerSignEx2Params.pwszTimestampURL = Marshal.StringToHGlobalUni(timestampUrl);
                if (string.IsNullOrEmpty(timestampAlgorithmOid))
                {
                    signerSignEx2Params.dwTimestampFlags = Constants.SIGNER_TIMESTAMP_AUTHENTICODE;
                }
                else
                {
                    signerSignEx2Params.dwTimestampFlags = Constants.SIGNER_TIMESTAMP_RFC3161;
                    signerSignEx2Params.pszAlgorithmOid  = Marshal.StringToHGlobalAnsi(timestampAlgorithmOid);
                }
            }

            signerSignHandle = null;
            if (type == SignMode.APPX)
            {
                var sipData = new APPX_SIP_CLIENT_DATA();
                signerSignHandle = GCHandle.Alloc(signerSignEx2Params, GCHandleType.Pinned);

                sipData.pSignerParams = signerSignHandle.Value.AddrOfPinnedObject();

                var sipHandle = Marshal.AllocHGlobal(Marshal.SizeOf <APPX_SIP_CLIENT_DATA>());
                Marshal.StructureToPtr(sipData, sipHandle, false);

                signerSignEx2Params.pSipData = sipHandle;
            }

            return(signerSignEx2Params);
        }
Example #2
0
 private static unsafe void FillAppxExtension(
     ref APPX_SIP_CLIENT_DATA clientData,
     SignerSignEx3Flags flags,
     SignerSignTimeStampFlags timestampFlags,
     SIGNER_SUBJECT_INFO *signerSubjectInfo,
     SIGNER_CERT *signerCert,
     SIGNER_SIGNATURE_INFO *signatureInfo,
     IntPtr *signerContext,
     char *timestampUrl,
     byte *timestampOid,
     SIGN_INFO *signInfo
     )
 {
     clientData.pSignerParams->dwFlags                  = flags;
     clientData.pSignerParams->dwTimestampFlags         = timestampFlags;
     clientData.pSignerParams->pSubjectInfo             = signerSubjectInfo;
     clientData.pSignerParams->pSignerCert              = signerCert;
     clientData.pSignerParams->pSignatureInfo           = signatureInfo;
     clientData.pSignerParams->ppSignerContext          = signerContext;
     clientData.pSignerParams->pwszHttpTimeStamp        = timestampUrl;
     clientData.pSignerParams->pszTimestampAlgorithmOid = timestampOid;
     clientData.pSignerParams->pSignCallBack            = signInfo;
 }