Re: windows programming cryptography(problem in implementing a Sma



Hi all!
Thank you Mr.Mounir IDRASSI!

I read that article of page 12 to 18,which describes that "Base
CSP"(available by installing KB909520 package) matches user context to the
card,and Table 3 on page 14 shows 4 modes of this job!
I am to have only one container in my Smart Card CSP,which is an
EF(Elementary File) on my card,so I use second method of this table(i.e.
Container name=NULL(default container or EF is selected)with reader
name=OMNIKEY ...)

In the schemes are described in the article,we pass reader name to
CryptAcquireCnotext ourselves;

1.Is my understanding right?

My question specially is that:

2.How does Windows pass selected reader name to my CSP?

I have problems in "implementing" of selecting one reader between multiple
readers with Visual C++ 2008 in my CSP.dll?!

I have copied my CPAcquireContext code in my previous post,

3.How Can I implement selecting one reader between multiple readers in
"SCardListReaders" function?

Please help me!
Sincerely.

"Mounir IDRASSI" wrote:

Hi,

You can find answers to your questions by reading the document "Windows
Vista Smart Card Infrastructure" that can downloaded the following link :
http://www.microsoft.com/downloads/details.aspx?FamilyID=ac201438-3317-44d3-9638-07625fe397b9&displaylang=en

It contains detailed information about CSP behaviors, not only on Vista but
on XP too.
Specifically, concerning the mechanism used to select a specific reader on a
multi-reader system, you can have a look at page 14, Table 3, which specifies
how a reader name can be encoded on the container name. This document also
includes detailed scenarios of have Windows interacts with smart card CSPs
and what is their expected behavior.

I hope this will help.
Cheers,
--
Mounir IDRASSI
IDRIX
http://www.idrix.fr

To reach me: mounir_idrix_fr (replace the underscores with the at and dot
characters respectively)


"creative22" wrote:

Hi Dear all!
In My Smart Card CSP and into "CPAcquireContext" function,I have called
these functions in order:

1. SCardEstablishContext
2. SCardListReaders
3.. SCardConnect
4. SCardBeginTransaction

This is my "CPAcquireContext" function implementation:


BOOL WINAPI CPAcquireContext(
OUT HCRYPTPROV *phProv,
IN LPCSTR szContainer,
IN DWORD dwFlags,
IN PVTableProvStruc pVTable)
{
//pVTable->Version
//pVTable->FuncVerifyImage()
//pVTable->FuncReturnhWnd()
//pVTable->dwProvType
//pVTable->pbContextInfo
//pVTable->cbContextInfo


//pVTable->pszProvName




if(pVTable->dwProvType!=NULL)
SetLastError(NTE_INVALID_PARAMETER)

if(pVTable->pbContextInfo!=NULL)
SetLastError(NTE_INVALID_PARAMETER);

if(pVTable->cbContextInfo!=0)
SetLastError(NTE_INVALID_PARAMETER);

if(pVTable->pszProvName!=NULL)
SetLastError(NTE_INVALID_PARAMETER);

/////////////////////////
if(szContainer!=NULL)
SetLastError(NTE_BAD_KEYSET);

/////////////////////////
if(dwFlags!=CRYPT_MACHINE_KEYSET)
SetLastError(NTE_BAD_FLAGS);


mycsp=new MyCSP;
if(!mycsp)
printf("Allocation failure!");

LONG lReturn;

// 1.Establish the context.
lReturn = SCardEstablishContext(SCARD_SCOPE_USER,
NULL,
NULL,
&(mycsp->hContext));
if ( lReturn!=SCARD_S_SUCCESS)
SetLastError(lReturn);

//2.List readers.
lReturn = SCardListReaders(mycsp->hContext,
NULL,
m_ReaderBuff,
&m_ReaderBuffLen);
if ( SCARD_S_SUCCESS != lReturn )
SetLastError(lReturn);
else
{
CString Reader;
int nPtr=0;
// Try to parse the list. Each reader name is terminated by a null
// charactere ('\0'). The list is also terminated by a null character
// making the last entry have two '\0' at the end.
// e.g "ACS READER 0 (NULL) ACS READER 1 (NULL)(NULL)"

while(m_ReaderBuff[nPtr] != '\0')
{
Reader = "";
while(m_ReaderBuff[nPtr] != '\0')
{
Reader += m_ReaderBuff[nPtr];
nPtr++;
} // while do
nPtr++;
}// while do
}// End of else


//3.Connect to the card.
lReturn = SCardConnect(mycsp->hContext,
Reader,
//SCARD_SHARE_DIRECT,0,
SCARD_SHARE_EXCLUSIVE,
SCARD_PROTOCOL_T0|SCARD_PROTOCOL_T1,
&(mycsp->hCard),
&m_APrtocol);
if (lReturn != SCARD_S_SUCCESS)
SetLastError(lReturn);

//4.Begin Transaction.
lReturn = SCardBeginTransaction(hProv->hCard);
if (lReturn != SCARD_S_SUCCESS)
SetLastError(lReturn);
*phProv = (HCRYPTPROV)*mycsp;
return TRUE;


}



Now my question:
I have one Card reader(OMNIKEY CardMan 3121), so windows returns one
reader's name in the "SCardListReaders" function!

lReturn = SCardListReaders(mycsp->hContext,
NULL,
m_ReaderBuff,
&m_ReaderBuffLen);

Now,if I connect multiple Card readers to the computer,How can I select one
of them?
I mean If I insert my card in one of Multiple connected readers to the
computer,How does Windows return it's name or how is that reader selected or
how can this work be implemented?

How is this process's mechanism?
I think so:
When I insert my card in one reader,Windows gets it's ATR and then compare
it with ATR included in the registery and then passes the reader name to my
function!
Is my thought correct or not?
If so,how does Windows pass the reader's name to my CSP?

I greatly appreciate you,if you help me!


And is there a document about Windows machanism to detect the card in one
reader between several readers on Internet?


I found nothing about it in the MSDN library,that's why I ask it here!
And nobody could guide me,please help me!
Thank you in Advance.


.