Page 2 of 2

Form of SubjectName text in PDF export

Posted: Mon Aug 23, 2010 10:29 am
by LukasT
Hello Ivan,
great!!! I will check it tomorrow...
Thank you and have a nice rest of day!

Form of SubjectName text in PDF export

Posted: Mon Aug 23, 2010 1:59 pm
by Andrew
Ok! Let us know about the result.

Thank you.

Form of SubjectName text in PDF export

Posted: Tue Aug 24, 2010 9:17 am
by LukasT
Hello,
I am afraid, but DocumentExport freeze if I put correct CN value. Than I have to restart application :-(

Form of SubjectName text in PDF export

Posted: Wed Aug 25, 2010 3:27 am
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.

Form of SubjectName text in PDF export

Posted: Wed Aug 25, 2010 4:26 am
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...


Form of SubjectName text in PDF export

Posted: Wed Aug 25, 2010 5:17 am
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.

Form of SubjectName text in PDF export

Posted: Thu Aug 26, 2010 7:38 am
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 ...

Form of SubjectName text in PDF export

Posted: Tue Aug 31, 2010 4:14 am
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.

Form of SubjectName text in PDF export

Posted: Tue Aug 31, 2010 8:11 am
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..