|
I hope for your sake that you have a flame proof suit cuz you are about to get flamed for spamming the board.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
Hi,
I've been searching far and wide on how to setup a client certficate so that my application can access a https server using winhttp.
Ultimate goal
Application uses the https server for storage and updating of personal statistics information. This data can be accessed from any machine with this application, using it's internal memory certficate, eg, the certficate shouldn't be stored in a windows certficate store, user identification is done on protocols internal to the script running on the server address.
Problem
The documentation on how to setup and use a client certifcate (p12) with password for a certificate store, is very poor to non-existent.
If I try to load a p12 certificate through:
m_hCertStore = CertOpenStore(
CERT_STORE_PROV_FILENAME,
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
NULL,
0,
L"my-client.p12"
);
The function fails, and as far as I can see, this is the only way to load a certificate for my application to use internally.
As mentioned above the ultimate goal is to have the certificate entirely in memory, but in the meantime it's acceptable to just load it from a file.
Solution?
Can anyone give some pointers on how to use a p12 file or other client certificate setup with a certifcate store?
When i test this same certifcate through IE it asks for the password contained in the file. So I'd imagine I'd have to supply this password through an API to load it into my certficate store, but there's no information how to work with this.
Any advice welcome, I'm completely stumped!!!
|
|
|
|
|
You have probably solved this by now, but, here are the key ideas for the client:
Read the .p12 into memory.
Use PFXImportCertStore to put it into a certstore
Use WinHttpSetOption with the WINHTTP_OPTION_CLIENT_CERT_CONTEXT parameter.
HCERTSTORE PFXImportCertStoreTCHAR( CRYPT_DATA_BLOB *PFX, const TCHAR * password )
{
#if defined UNICODE || defined _UNICODE
return ::PFXImportCertStore( PFX, password, 0 );
#endif
// Have to convert char * password to wchar_t *
size_t sizeInWords= 999;
wchar_t wcstr[999];
size_t count= strlen( password );
size_t returnValue;
errno_t err= mbstowcs_s( &returnValue, wcstr, sizeInWords, (const char *)password, count );
return ::PFXImportCertStore( PFX, wcstr, 0 );
}
// Use a .pfx certificate and private key
// Note that the certificate must be associated with a private key to avoid a ERROR_WINHTTP_CLIENT_CERT_NO_PRIVATE_KEY error.
//
void setClientCertificate( const std::vector< unsigned char > & clientPfx, const TCHAR * szPassword )
{
if ( 0 == (openFlags & WINHTTP_FLAG_SECURE) ) return; // No need to send a client certificate if using plain http
// Convert a .pfx or .p12 file image to a Certificate store
CRYPT_DATA_BLOB PFX;
PFX.pbData= (BYTE *)&clientPfx[0];
PFX.cbData= clientPfx.size();
HCERTSTORE pfxStore= PFXImportCertStoreTCHAR( &PFX, szPassword );
if ( NULL == pfxStore ) throw std::pair<int,int>( __LINE__, ::GetLastError() );
// Extract the certificate from the store and pass it to WinHttp
PCCERT_CONTEXT pcontext= NULL, clientCertContext;
while ( pcontext = ::CertEnumCertificatesInStore( pfxStore, pcontext ) ){
clientCertContext= ::CertDuplicateCertificateContext( pcontext ); // CertEnumCertificatesInStore frees its passed in pcontext !
BOOL stat= ::WinHttpSetOption( hRequest, WINHTTP_OPTION_CLIENT_CERT_CONTEXT, (LPVOID)clientCertContext, sizeof(CERT_CONTEXT) );
if ( FALSE == stat ) throw std::pair<int,int>( __LINE__, ::GetLastError() );
return; // Success
}
throw std::pair<int,int>( __LINE__, ::GetLastError() ); // No certificates in the store created from the pfx/p12
}
|
|
|
|
|
Hi.
I have an MSI package which works with 2000, XP and Vista Home Premium; after installation, in each case the ShellNew process works perfectly (a right click on the desktop and explorer offers the creation of a new file based on a template which is fully qualified; and life is good). However, under Ultimate the popup menu does not contain the option. I have tried adding the template (removing the qualified path from the Reg ShellNew entry) to the system ShellNew directory, but whatever I do; it simply will not work. Has something changed under Ultimate or is there an additional setting that I need to consider. Any help or comment would be much appreciated.
My best regards, in hopeful and optimistic anticipation.
James.
modified on Wednesday, February 4, 2009 5:10 PM
|
|
|
|
|
hi guys,
i been working on a worm scanner lately... i got a funtion that list all the files in a directory.. but the the filename is on vector<wstring> but i need to list them in a list box. but when i compile there is no problem but when i run it there is problem showing :
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format.
Below is my coding :
if (ListFiles(directory, L"*", files)) {
for (vector<wstring>::iterator it = files.begin();
it != files.end();
++it) {
std::string filename = WStringToString(it->c_str());;
std::string s=filename;
String ^someString= gcnew String(s.c_str());
listBox1->Items->Add(String::Format(someString,"\n"));
// wcout << it->c_str() << endl;
}
}
Kidly help me plz...
Regards,
Thilek
|
|
|
|
|
I suppose you don't need to convert the std::wstring to a std::string before assigning it to a System.String , moreover AFAIK the first argument to String::Format should be the requested format. Anyway you'll eventually get better help in the (Managed) C++/CLI [^] forum.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
okies... thanks a lot ya... i posted there ready.. hope someone help me there..
|
|
|
|
|
Thilek wrote: i got a funtion that list all the files in a directory.. but the the filename is on vector but i need to list them in a list box.
Why can't you just send the listbox a LB_DIR message?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi all,
I'm embarking on a fairly complex project (I know. Please don't say simply "Google for it". I already did).
What I want is to implement an OLE DB layer between a physical DB (connection via standard OLE DB interface) and a client application.
The aim is to implement row level security and additional functions (such as logging) in the OLE DB layer.
So the architecture should be like this (top-down):
Client Application <- Ole DB consumer application (MFC, .NET, Excel...)<br />
-----------------------<br />
OLE DB Provider <- On the client. Dumb connection to my service via the Network layer<br />
-----------------------<br />
<br />
Network layer <- I really don't know how to pass through this<br />
<br />
-----------------------<br />
OLE DB Consumer/Provider service <- This should be on a network server. Here I'm implementing row level security. This service acts as an OLE DB consumer for the DB and exposes data to the client.<br />
-----------------------<br />
Physical DB <- Any OLE DB-compliant database (mainly SQL Server or Oracle)<br />
-----------------------
My question is: what is the best way to implement the Network layer?
I found an OLE DB Remoting Provider by Microsoft, but seems outdated and not supported ATM. If using this, I should implement OLE DB Provider interfaces into the Service on the server.
Any suggestions?
(cross posted on the COM forum)
|
|
|
|
|
When our application is used on a Japanese system, we are encountering a DBCS problem. When entering text into one of the edit controls, there may be several instances of the shift-out/shift-in pair intermingled with "normal" text. For example:
SoXXXXXXSiXSoXXXXXXSi
When I call GetTextLength() on this text, it returns 13. If this text is saved to a text file (e.g., using Notepad since it's all I can understand on a Japanese system), the size is reported as 13 (I guess the 2 SoSi pair did not get saved). Now for the problem: when I send this text and its length (13) to the AS/400 system for processing, it complains about a mismatched SoSi pair. Debugging on the AS/400 end, we can change the length to 17 and it works fine. I've no clue how to handle this. If the above example were doubled, then GetTextLength() would return 26, yet we'd have to change the value to 34 in order for it to work.
Any clues?
- DC
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
GetTextLength() is returning the length in characters.
How are you determining the number of bytes to write to the file?
For DBCS, length in characters is not the same as length in bytes.
DavidCrow wrote: Any clues?
You've considered using Unicode, I assume?
If not, you may have to write your own strlen , hunting from the start to a terminating zero, to get the number of bytes.
|
|
|
|
|
Graham Bradshaw wrote: How are you determining the number of bytes to write to the file?
I'm not. I just paste the text into Notepad and save it.
Graham Bradshaw wrote: You've considered using Unicode, I assume?
Yes, but I've read nothing thus far that says it would solve the problem. The application is 10+ years old so retooling it for Unicode would be no small undertaking.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
DavidCrow wrote: save it.
Save it how? Which encoding did you select?
|
|
|
|
|
Graham Bradshaw wrote: Save it how?
The Save option from the File menu.
Graham Bradshaw wrote: Which encoding did you select?
Once as ANSI (13 bytes) and another as UTF-8 (22 bytes).
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
So the text isn't 13 bytes long. It's more than that (UTF-8 encoding is not the same as DCBS, so the length of the ex-Notepad file is not relevant).
DavidCrow wrote: when I send this text and its length (13) to the AS/400 system for processing, it complains about a mismatched SoSi pair.
And that 13 is surely the problem. You need to send the length in bytes to the AS/400, together with all the text, not the length in characters. This assumes, of course, that the AS/400 understands DBCS encoding.
|
|
|
|
|
Graham Bradshaw wrote: You need to send the length in bytes to the AS/400, together with all the text, not the length in characters.
How do I go about doing this (since WM_GETTEXTLENGTH is giving me the latter)?
Graham Bradshaw wrote: This assumes, of course, that the AS/400 understands DBCS encoding.
It does. That's why it works (i.e., no data is lost) when I manually change the text length during debugging.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
DavidCrow wrote: How do I go about doing this (since WM_GETTEXTLENGTH is giving me the latter)?
You're working in C++?
If so, you must have a pointer to the start of the character buffer, so you can send it to the AS/400. Just hunt through byte by byte until you hit a zero, counting as you go.
|
|
|
|
|
The only way I know to calculate the number of bytes of DBCS string in a given encoding is:
1. Translate the string to Unicode (MultiByteToWideChar)
2. Translate the Unicode string to the previous encoding (WideCharToMultiByte) this function return the size of DBCS string in bytes.
This work (in all the case that I know of) .
Good luck.
|
|
|
|
|
Hi,
I want to create GroupBox on dialog box dynamically, can any one help me how to do that..?
Thanks
Venkatesh.
|
|
|
|
|
Group boxes are actually buttons with the BS_GROUPBOX[^] style set. I hope that helps.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Well, I sure know it helps me a ton! Thank you!
|
|
|
|
|
Yourwelcome. Nice to see old posts can still be helpful.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
hi if u got to how to create groupbox dynamicaly pls let me know
Thanks
|
|
|
|
|
I use visual studio 2005 MFC dialog based
I try to use these method to help but it doesn't give me a correct position.
void CMy3DGUIDlg::OnStnClickedPic1()
{
CWnd* prnt = GetDlgItem(IDC_PIC1);
CPoint p1;
GetCursorPos(&p1);
ClientToScreen(&p1);
prnt->ScreenToClient(&p1);
CDC *pdc = prnt->GetDC();
pdc->MoveTo(0,0);
pdc->LineTo(p1.x,p1.y);
}
Thank you for helping
|
|
|
|
|
z01e wrote: ...but it doesn't give me a correct position.
Position of what?
Have you tried GetMessagePos() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|