Esempio n. 1
0
        public static AbstractBlob CreateFromStream(ReadingContext SR)
        {
            // Read the magic and length (common to all blobs)
            UInt32 Magic = SR.ReadUInt32();
            UInt32 Length = SR.ReadUInt32();

            AbstractBlob Result;

            switch (Magic)
            {
                case CSMAGIC_CODEDIRECTORY:
                    Result = new CodeDirectoryBlob();
                    break;
                case CSMAGIC_CODEDIR_SIGNATURE:
                    Result = new CodeDirectorySignatureBlob();
                    break;
                case CSMAGIC_ENTITLEMENTS:
                    Result = new EntitlementsBlob();
                    break;
                case CSMAGIC_REQUIREMENTS_TABLE:
                    Result = new RequirementsBlob();
                    break;
                case CSMAGIC_EMBEDDED_SIGNATURE:
                    Result = new CodeSigningTableBlob();
                    break;
                case CSMAGIC_REQUIREMENT:
                default:
                    Result = new OpaqueBlob();
                    break;
            }
            Result.MyMagic = Magic;
            Result.UnpackageData(SR, Length);

            if (Config.bCodeSignVerbose)
            {
                Console.WriteLine("[Read blob with magic 0x{0:X} and length={1}]\n{2}", Magic, Length, Result.ToString());
            }

            return Result;
        }
Esempio n. 2
0
		public static CodeDirectoryBlob Create(string ApplicationID, int SignedFileLength)
		{
			CodeDirectoryBlob Blob = new CodeDirectoryBlob();
			Blob.Allocate(ApplicationID, SignedFileLength);

			return Blob;
		}
Esempio n. 3
0
		/// <summary>
		/// Populates this CMS blob with the data from signing a code directory
		/// </summary>
		public void SignCodeDirectory(X509Certificate2 SigningCert, DateTime SigningTime, CodeDirectoryBlob CodeDirectory)
		{
			// Create a signer
			CmsSigner Signer = new CmsSigner(SigningCert);
			Signer.IncludeOption = X509IncludeOption.WholeChain;
			Signer.SignerIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber;
			Signer.DigestAlgorithm = new Oid(CryptoConfig.MapNameToOID("SHA1"), "SHA1");

			// A Pkcs9ContentType and Pkcs9MessageDigest will automatically be added, and it fails to
			// compute a signature if they are added manually, so only the signing time needs to be added
			Signer.SignedAttributes.Add(new Pkcs9SigningTime(SigningTime));

			// Sign the data (in a detached manner, so only the digest of the CodeDirectory is
			// stored in the CMS blob and not the whole CodeDirectory blob)
			bool bDetached = true;
			bool bSilent = true;
			ContentInfo CodeDirContentInfo = new ContentInfo(CodeDirectory.GetBlobBytes());
			SignedCms CMS = new SignedCms(CodeDirContentInfo, bDetached);
			CMS.ComputeSignature(Signer, bSilent);

			MyData = CMS.Encode();
		}
		public static CodeDirectoryBlob Create(string ApplicationID, string TeamID, int SignedFileLength, uint Version = cVersion2)
		{
			CodeDirectoryBlob Blob = new CodeDirectoryBlob();
			Blob.Allocate(ApplicationID, TeamID, SignedFileLength);

			return Blob;
		}