Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Security / November 2007

Tip: Looking for answers? Try searching our database.

CAPICOM and .NET signedCms.CheckSignature

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wim - 29 Nov 2007 10:01 GMT
Hello,
We have a program which is signing files with CAPICOM. Those signed files
(detachted) can't be verified by the .NET classes. I receive "Invalid
Signature".
When I watch the signedCms.certificates(0) I see the certificate but the
CheckSignature is failing.

I see that the signed file there are linebreaks after 64 characters.
When I sign the file with .NET the linebreaks are on 74 characters.

How can I verify signed files by capicom with the .NET assemblies ?

--CAPICOM code
   SignedData = New CAPICOM.SignedDataClass
   Signer = New CAPICOM.SignerClass

   bs = BReader.ReadBytes(System.Convert.ToInt32(BReader.BaseStream.Length))

   Dim h As GCHandle = GCHandle.Alloc(bs, GCHandleType.Pinned)

   Dim ptr As System.IntPtr = Marshal.UnsafeAddrOfPinnedArrayElement(bs, 0)

   SignedData.Content = ptr

   h.Free()

   Signer.Certificate = c

   strSignString = SignedData.Sign(Signer, True,
CAPICOM.CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64)

   Dim sw As New System.IO.StreamWriter(SignedFile)
   sw.Write(strSignString)
   sw.Close()

   SignedFile.Close()
   'BReader.Close()

--.NET verify code to verify the signed file
   Dim bufferfile As Byte() = File.ReadAllBytes(strDataFileName)
     Dim strSignedFile64 As String = File.ReadAllText(strSignedFile)
     'Place signature buffer in a ContentInfo object.

     Dim contentInfo As ContentInfo = New ContentInfo(bufferfile)

     'Now Instantiate a SignedCms object with the ContentInfo above. Set
the detached content file upon which the signature is based.

     Dim signedCms As SignedCms = New SignedCms(contentInfo, True)

     'Decode buffersignature bytes into the pkcs7 object.

     signedCms.Decode(Convert.FromBase64String(strSignedFile64))

     'Now check for the detached signature; the CheckSignature function
should return a 'true' value.

     signedCms.CheckSignature(True)
Signature

Thanks,
Wim

Dominick Baier - 29 Nov 2007 10:11 GMT
IIRC CAPICOM and .NET X.509 support is not compatible - meaning CAPICOM is
doing something non-standard. But I can't remember the details.

-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

> Hello,
> We have a program which is signing files with CAPICOM. Those signed
[quoted text clipped - 53 lines]
>
> signedCms.CheckSignature(True)
Jonas - 30 Nov 2007 10:58 GMT
CAPICOM requires an even byte length for the data to be signed and
will pad the data if it is uneven. Try converting what you are signing
to a Base64 string and then to a byte array (thus ensuring it is even
in length) before you send it to CAPICOM for singing. It not that
pretty but it should do the trick.

//Jonas

> Hello,
> We have a program which is signing files with CAPICOM. Those signed files
[quoted text clipped - 57 lines]
> Thanks,
> Wim

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.