DECLARE @signerName sysname
SELECT @signerName = name FROM SYS.CERTIFICATES WHERE thumbprint =  0x7BDA87E7F63ACF7BCA7BAFD20292E5551ED73126
IF @signerName IS NOT NULL
BEGIN

	DECLARE @s nvarchar(1024)
	SELECT @s  = 'DROP SIGNATURE FROM DATABASE::' + db_name() + ' BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] '
	EXECUTE(@s)
	IF (@@error <> 0)
	BEGIN
		RAISERROR('Cannot drop signatures by certificate [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] ', 16, 1)
		RETURN
	END

	SELECT @s  = 'DROP CERTIFICATE [' + @signerName + '] '
	EXECUTE(@s)
	IF (@@error <> 0)
	BEGIN
		RAISERROR('Cannot drop certificate [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] ', 16, 1)
		RETURN
	END
END
GO

DECLARE @master_file NVARCHAR(1024)
SELECT @master_file = physical_name FROM master.sys.database_files WHERE name = 'master'
DECLARE @wmsde_schema_path NVARCHAR(1024)
SET @wmsde_schema_path = REPLACE(@master_file, 'Data\master.mdf', '') + N'SchemaSig'

DECLARE @s nvarchar(1024)
SELECT @s  = 'CREATE CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] FROM FILE = ''' + @wmsde_schema_path + '\' + 'wsrmsign.cer'''

EXECUTE(@s)
IF (@@error <> 0)
BEGIN
	RAISERROR('Cannot create certificate from file wsrmsign.cer', 16, 1)
	RETURN
END

SELECT @s  = 'ALTER CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] ATTESTED BY ''' + @wmsde_schema_path + '\' + 'wsrmsign.dll'''

EXECUTE(@s)
IF (@@error <> 0)
BEGIN
	RAISERROR('Cannot add attested DLL to certificate from file wsrmsign.dll', 16, 1)
	RETURN
END
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[getIdentity] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0x1C8AD9147B4838ADCCD09564BEBAB560983F80547359565325D9A9D5E2108B49AEAE911E92E7630E41A8F1D68DF7A2E16E897384C52A53DD3704742668AC8E8526441D818F10B021AD567A7C442447E3A85205B4F43ED41C7517D1FA3F769C6B21997B7CBFA0DB75CAA20A570CD856063555E7AD84906B56567504426718901F'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[getIdentityF] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0xD790AA97DEEEB979218AAF02C531295E37BA6A5664C78F159F694A3866495D9671D9134B284A53C85DBF1A84D0F26EC0EBCB7EA050CA4C4F4876AF9D74D8ECD8AAD6C88F6FD3938AEAFDCB9FDACB568FA4AA205FD57DDC24BFB321B56F053AC2455C1CFB91D8BF5678DC3D9339592DCCEE7B406B35556AE50BE8B4573D16795F'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[getTotalCount] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0x0770C38196B5BF2645C02B3CF632605FA658A78716A68D129256B738C3C9063FB0370B3EC31A2D247F2A2070F1D75B4ADF590FEA92372ED6C792D7D109A5D6D54E1AB133F520EB19728A933A82B1D5AD1FB6C308B374CC030B1EB8C38244E02E839FD6A15B501272D923A8AE2F504ACB82433F57C566F7616C4A0BEE6B395B0A'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[getLiveProcCount] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0xFF74C9E1DA43C2B641900676DA461E204F566CCB93C5495BEF87E64E068DF8513ACCA3E7E332A90162338502473DC89ACA330BA367C4D002D88A0D054DE98F45A8F0EEECE0142BADCBA2EE2ED88D6178F70063893BFBD642DEE54B4BD0DB48091F985BF61FCBB043081B7F820FE0920EBAEFCB7D2F15FFEF287FBE15B1F42682'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[InsertStatRow] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0xA9EE39547D2C41A9EECB068FE5A5FEEC88F045BE06DA261F51A6548FBD389EC36E27F8CFC7CDC4B73D02DACA8AD5C9516710E94BD5EB49967D9F02EC6F11E166DF69F5FB8CD43BF10B4538D51C145917C2C55AB1C77C7B70FD3D2CA4D071A1240E21AA96AB51E07EDBA7A0A4A9E9BED56478DC4122A5D4AFBAF3533DF5CAA48C'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[InsertDynaRow] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0x920CAF628130141268967C095FE2D66E622499112D44FACFD3F86E9B27105E2484F9BC96D620794B2393F9E5A7E08515C14702DE935FE46A807FA5444AFD7CFE3A9928417D308ED1C0076F8F7E2945623598B34186DD91175BFD38B14DA6E8F8EEF97813FDB039D07A490F6907D1703B07A7D4EC3180B79366DCC38FD777705D'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[checkAndInsertDynaRow] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0xD5CC31FB9B68C937921C0630DFC7A2EC5353AF55B43D1A9C0524FE775875C0C1D55B64F3FE0317BED189D52CA5CFD9F565019FEEF4335D93A95B18ED322EBE472AF355D17167278571707B4AD92FE601E5B43D7C9382337110C978F8199868E69D7165C784F3082EAFF1607C50EA257F5CD676196EF71434A30D0A1E7525A249'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[updateEndTime] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0x791293183C7BEB2B9B38DC74E09B2447AC130D6D98A5EAFC72856161F4B34D69E764EEC963CA428C366873E8BA2491F8F74011FE6AB24E6FDB2923FF96C435DBA02693C9DFD06D599134F027AF5702F77CBC9DF1E9B53DFEF48A1EBEDC4675F4723498CB83F8370D74A610880CABBF6349839F12B7B206BFC4C6B569D9177019'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[updateEndTime2] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0x070BE21B764C37D56C6C1B27322F17D6E157A2360C0586D0C982C7B81940AE03B0A0821C1CC12F1995598830213A26BD8F33C5F6863414D96C8EECCC1FBC782A0B55F3F832F10EB175D7F0C073D084C127D6335908343D4B27DEB71F3CD956B39A0C877594579B3686B1A051CCD7EA0DC5F129175AA439F0B83E8465D402773D'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[getRawDataForArchiving] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0xAF6F43DA3CBB67DCF2A840B1CA5C1638AEC2FB36565D2B58B6EF23CFB60C7C0958C878467A43AE2A314EF02FCFFCC3C5B36EEA7BB3C15BF470A93515875C5782BCCB292722AA216E736F23CAC7640A3B58C4711BA226810CEEB086FFDEE52A33771AF748D216A1E337FF0FCBB8FD9C8EB77ED9EE6A57980A17F1982F7096EF08'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[getRunningProcessMap] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0xE7EE96DED48792D2C7790AF076082F8694537B06E9F01E38B44FE4CC24F7B0FF1979E5F60321D3D288038AFA4C9A02841156672DA00C1485C722420F3E484AD8244C6E527AE17F76BAFB05BADDA9DC35AADB79214B914A44033D76D1DA10BFDC030B8F487EBC302B1BA5DA8687D898B497159035F4107ED4FD544F9484CEA332'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[genericSelectQuery] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0x8A355D0549B61C540A49512DBEB93A8FE40B66C8A2E01B5D45B1F0EC507DCA4F0C8A7F95FABE87EF40AFC89CBC24F6EA50C6DCE3CB93153FAC797DEC0F86BDFBDB38D17F46F963D813A5AA3BDD078C6ED6258139783272ECB08E84DA0AA107DCED9DCB8A2F89C2EF607225335D6FFAD769BAF7A58E0465E4E3D80932DE73365E'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[deleteDataOfMachine] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0xF7469A5F074E435A2D72036F866717BABDBAA62E928B47A017A01822765C08399D5D5E69AD42FF5FDF7601C1C797AB24BA828ED34736F2F7EB65947C1C3B9E2E4141C904A8C5EFC3F2DA52D76D8F06612276DA959D1C2AABB7F35538A771B42477366C4D7F123E8807BC6A899E56F275D4959C2ECF8A199DD5EBB688A2189104'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[deleteData] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0xF066EFB5B9B3DFE893AFC219BC0E5229B3C7553288D09C5C216B29F063DAA439840815ED2E74BEDE7C09B7DCC384907E8EA4E68EEE6E6E59C9146FAAF35FE74D017E13F9ACFF5FECA42BAF13CA703BDE82EC565720140BBC9AB6B4FF08381F14A686A2FCF9B6ED0CFA2C74BA19CE2B3C08B046BB2F8664CE069A9ABB32467F20'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[AddMachineAccount] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0x0D45BD92DCAA5FEF4DE066DAA6347BF608FD938F667B33E530CABE38955956D6A0C074E34E3F64523889526AA0A307AA8537E4C6250B005737ED5A1737F2773A71DDDF1F9512A86DF90F604E0A9D1D131981890F88AEAA6E58086BF73AEAA3E30D850EA0846EA1B2B374052EF3413AD13232B8C71DC76F7183D4C5489D2A354F'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[PROCINFO] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0xB3A7EF46B0629BCB28F92260D5271562D813C3D7DBC1D7BC58A706665EAF7FC5FD1E636C3BD04F45BC0BEE39E720873DE340B58430B162D358BCC9B8A3E952AE115082AC01832212FBD2195A7FAE81A974AAA6E73FAAB99289D18655946435BA19A45E4896EA4B6A975668874382BA8497D9F509A97A5D091DF525AF5648C570'
EXECUTE(@s)
GO

DECLARE @s nvarchar(max)
set @s = 'ADD SIGNATURE TO [dbo].[DYNAINFO] BY CERTIFICATE [MS_SchemaSigningCertificate7B64C7C0D151CE608C7010A2590E664DBF131BA6] WITH SIGNATURE = 0x2A6AE3EFD7DB1F8C4B5F9086B9A6D7EAC519D90273C0F4AB7FF083E3EF439029FBD89052381E68B887CCCBE6AAA3C3F724919BCC971CF849311FDE5D2DDCF370E82732DB0432031F3C6B0F85C3D4BEE441637EBEBB9E8180380A94569A29796643F234C4024FC78AE36E12AC2E8D477E5AAC98EE8A3F5DDCA94A43EB9264C53A'
EXECUTE(@s)
GO
