Form of SubjectName text in PDF export

Stimulsoft Reports.NET discussion
LukasT
Posts: 306
Joined: Mon May 03, 2010 2:50 am
Location: Czech Republic

Form of SubjectName text in PDF export

Post by LukasT »

Hello Ivan,
great!!! I will check it tomorrow...
Thank you and have a nice rest of day!
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

Form of SubjectName text in PDF export

Post by Andrew »

Ok! Let us know about the result.

Thank you.
LukasT
Posts: 306
Joined: Mon May 03, 2010 2:50 am
Location: Czech Republic

Form of SubjectName text in PDF export

Post by LukasT »

Hello,
I am afraid, but DocumentExport freeze if I put correct CN value. Than I have to restart application :-(
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Form of SubjectName text in PDF export

Post by Ivan »

Hello,

We couldn't reproduce this bug.
In the last build we use the following code:

Code: Select all

				#region FindCertificateInStore
				if ((certificateID != null) && (certificateID != string.Empty))
				{
					IntPtr SIGNER_NAME = Marshal.StringToBSTR(certificateID); 
					int certificateIsValid = 0;
					do
					{
						pCertContext = Win32.CertFindCertificateInStore(
							hStoreHandle, 
							ENCODING_TYPE,
							0,
							Win32.CERT_FIND_SUBJECT_NAME,
							SIGNER_NAME,
							pCertContext);

                        if (pCertContext == IntPtr.Zero)
                        {
                            pCertContext = Win32.CertFindCertificateInStore(
                                hStoreHandle,
                                ENCODING_TYPE,
                                0,
                                Win32.CERT_FIND_SUBJECT_STR,
                                SIGNER_NAME,
                                pCertContext);
                        }

                        if (pCertContext == IntPtr.Zero) ThrowDigitalSignError(2, "Certificate is not found", true);

						SignerCert = (Win32.CERT_CONTEXT)Marshal.PtrToStructure(pCertContext, typeof(Win32.CERT_CONTEXT)); 

						certificateIsValid = Win32.CertVerifyTimeValidity(IntPtr.Zero, SignerCert.pCertInfo);
					}
					while (certificateIsValid != 0);
				}
				else
				{
					ThrowDigitalSignError(2, "Subject name string is empty");
				}
				#endregion
Thank you.
LukasT
Posts: 306
Joined: Mon May 03, 2010 2:50 am
Location: Czech Republic

Form of SubjectName text in PDF export

Post by LukasT »

Hello,
you can't use IntPtr SIGNER_NAME as value for parameter CERT_FIND_SUBJECT_STR. You have to use CertNameToStr function to convert this to CERT_NAME_BLOB ... see documentations http://msdn.microsoft.com/en-us/library ... 85%29.aspx and http://msdn.microsoft.com/en-us/library ... 85%29.aspx ...
But this is not why it freeze... because if I put your code in my test project and use CN value, it finds correctly my certificate.

It looks like you have never been debuging your code... I understand, that this issue has low priority for you :-( but not for me... We have to sign PDF reports and would like to use your function...

Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Form of SubjectName text in PDF export

Post by Ivan »

Hello,

On the current moment we cannot find the certificate by by whole subjectName (CERT_FIND_SUBJECT_NAME). Maybe we do not take something into the account.
If you will improve our code, shown above, we will include these changes into our product.

Thank you.
LukasT
Posts: 306
Joined: Mon May 03, 2010 2:50 am
Location: Czech Republic

Form of SubjectName text in PDF export

Post by LukasT »

Better way will be for you to use functionality from System.Security.Cryptography instead of using P/Invoke of crypt32.dll...
For example:

Code: Select all

X509Store store = new X509Store(getStoreNameFromString(storename), StoreLocation.CurrentUser);
X509Certificate2Collection oCerts = new X509Certificate2Collection();
store.Open(OpenFlags.ReadWrite);
oCerts = (X509Certificate2Collection)store.Certificates.Find(X509FindType.FindBySubjectDistinguishedName, subjectName, false);
Except finding the certificate by whole subjectName is your code correct... but you have problem somewhere before this code... I cant tell you more, because we haven't licence with source code ...
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Form of SubjectName text in PDF export

Post by Ivan »

Hello,

We made some improvements in that direction.
Please check the next prerelease build when it will be available and let us know about the result.

Thank you.
LukasT
Posts: 306
Joined: Mon May 03, 2010 2:50 am
Location: Czech Republic

Form of SubjectName text in PDF export

Post by LukasT »

Hello Ivan,
great... I have made ticket TIA-283906, where we can personally communicate... When it is solved, I will close this ticket. Ok?
Thank you and I will check your improvement when it will be possible..
Post Reply