Groups | Blog | Home
all groups > dotnet security > august 2004 >

dotnet security : Signing a manifest without using XMLSign


Scott
8/3/2004 1:22:31 PM
Anyone have an idea how to sign a manifest.xml file with an X.509
certificate without having to use that buggy XMLSign utility?

shawnfa NO[at]SPAM online.microsoft.com (
8/5/2004 9:51:54 PM
If you want to do it from code, you could use the System.Security.Cryptography.Xml.SignedXml class to accomplish this. X509 support wasn't
added to this class until Whidbey though, so you'll need to grab the beta of .NET 2.0 to make it work. For further details check out:

http://blogs.msdn.com/shawnfa/archive/2004/01/22/61779.aspx

-Shawn
http://blogs.msdn.com/shawnfa

--

This posting is provided "AS IS" with no warranties, and confers no rights.
Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they
originated.
--------------------
[quoted text, click to view]

Scott
8/6/2004 8:34:21 AM
Hmmm... Just received beta .NET 2.0 - have not installed yet.

This would then require the end user to also have .NET Framework 2.0
installed?


[quoted text, click to view]
System.Security.Cryptography.Xml.SignedXml class to accomplish this. X509
support wasn't
[quoted text, click to view]
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09
..phx.gbl
[quoted text, click to view]

Scott
8/6/2004 11:51:12 AM
Paul,

Is this also for NET 2.0?

What I have is this:
Reference to System.Security & Microsoft.Web.Services2
Imports...

Imports System.Security.Cryptography.X509Certificates

Dim sCertSubject As String

Dim oStore As X509CertificateStore

Dim oCert As Microsoft.Web.Services.Security.X509.X509Certificate = Nothing

Dim oCerts As X509CertificateCollection

Dim oKey As RSA

Dim xmlManifest As XmlDocument

Dim signedXml As SignedXml

Dim refManifest As Reference

But all of the Dim'ed objects are not valid namespaces (in NET 1.1)

[quoted text, click to view]

Paul
8/6/2004 1:20:29 PM
Scott,

You can use the X509CertificateStore object from WSE 1.0
(Microsoft.Web.Services.Security.X509) to open the desired cert store and
extract your cert. Then assign the cert key to an RSA object from
System.Security.Cryptography.

Dim sCertSubject As String
Dim oStore As X509CertificateStore
Dim oCert As Microsoft.Web.Services.Security.X509.X509Certificate = Nothing
Dim oCerts As X509CertificateCollection
Dim oKey As RSA
Dim xmlManifest As XmlDocument
Dim signedXml As SignedXml
Dim refManifest As Reference

sCertSubject = "some subject string"

' get the key from the cert store
oStore =
X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore)
oStore.OpenRead()

' find the subject
oCerts = oStore.FindCertificateBySubjectName(sCertSubject)

' make sure you found the cert you were looking for...
If oCerts.Count > 0 Then ' Obtain the first matching certificate.
oCert = CType(oCerts(0),
Microsoft.Web.Services.Security.X509.X509Certificate)
Else ' No certificates matched the search criteria.
' throw an exception, etc...
End If

' close the X.509 certificate store.
oStore.Close()

' create the RSA object and assign the cert key
oKey = oCert.Key

Now use the SignedXML object to create your signature...

' load the XML into a DOM
xmlManifest = New XmlDocument
xmlManifest.Load("manifest.xml")

' create the SignedXml object and assign the key
signedXml = New SignedXml(xmlManifest)
signedXml.SigningKey = oKey

' add Reference, transformation, envelope, etc. to the signed XML node per
your requirements...
refManifest = New Reference
refManifest.Uri = ""
Dim env As New XmlDsigEnvelopedSignatureTransform
refManifest.AddTransform(env)
Dim trans As New XmlDsigC14NTransform
refManifest.AddTransform(trans)
signedXml.AddReference(refManifest)

' add KeyInfo object per your requirements...
Dim keyInfo As New KeyInfo
keyInfo.AddClause(New RSAKeyValue(oKey))
signedXml.KeyInfo = keyInfo

' calculate signature
signedXml.ComputeSignature()

' get signature from SignedXml object
Dim xmlDigitalSignature As XmlElement = signedXml.GetXml()

' add the signature element to the orginal manifest xml using AppendChild,
InsertAfter, etc...


HTH,

- Paul


[quoted text, click to view]

shawnfa NO[at]SPAM online.microsoft.com (
8/6/2004 4:58:01 PM
Yes, any code you write with .NET 2.0 will also require the 2.0 CLR to be installed on the user's machine.

-Shawn
http://blogs.msdn.com/shawnfa

--

This posting is provided "AS IS" with no warranties, and confers no rights.
Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they
originated.
--------------------
[quoted text, click to view]

Scott
8/10/2004 8:02:31 AM
Paul,

Thanks! Much less "complaints"

Now only complaining about
Dim xmlManifest As XmlDocument

type XmlDocument is not defined



Scott

scottbusse@wcpci.com



[quoted text, click to view]

Paul
8/10/2004 8:17:15 AM
[quoted text, click to view]

Nope! Mine works in 1.1...

[quoted text, click to view]

The catch is that it is only compatible with WSE 1.0 SP1 (never tried it w/o
the SP). Microsoft pulled some functionality out of WSE when they released
2.0 (I don't know why). WSE 1.0 and 2.0 can be run in parallel...

Set the references to "Microsoft.Web.Services"

[quoted text, click to view]

What object(s) is it complaining about?

- Paul


[quoted text, click to view]

Paul
8/10/2004 8:25:54 AM
More info...

Here is my Imports list:

Imports Microsoft.Web.Services.Security.X509
Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml

HTH

- Paul


[quoted text, click to view]

Scott
8/10/2004 8:48:34 AM
Way Good!

[quoted text, click to view]

Paul
8/10/2004 11:20:12 AM
That's standard .NET XML stuff...

Just make sure you're referencing System.XML and import System.XML.

Sorry, I trimmed that one (import) off my list of imports when I cut/pasted
them into my last message. The complete list is much longer, but mostly
specific to my app...

- Paul


[quoted text, click to view]

AddThis Social Bookmark Button