[prev in list] [next in list] [prev in thread] [next in thread]
List: ms-cryptoapi
Subject: Re: Where is CertStrToName (it wasn't there)
From: Jean Renard Ward <jrward () WORLD ! STD ! COM>
Date: 1999-01-18 15:04:02
[Download RAW message or body]
We had the same problem, and concluded that the function was just missing.
We wrote our own equivalent function:
Here is the source code -- it uses a couple of in-house string classes, but you might \
be able to implement your own, using it as a guide.
#if !defined _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
// ----- includes ------------------------------------------------------------
#include "WinWarnDisable.h" // suppress Level-4 warnings in Microsoft slop
#include <windows.h> // For IsBadStringPtr(...)
#include "WinWarnDefault.h"
#include <stdio.h>
#include <time.h>
#include "EXTENDEDassert.h"
#include "macros.h"
#include "LcpStatExc.h"
#include "asn1.h"
#include "util.h"
#include "CryptoUtils.h"
#include "CertUtils.h"
// ----- functions ------------------------------------------------------------
// ----------------------------------------------------------------------------
// SimpleCertStrToName - Simple substitute for the CertStrToName function in
// older (IE3.02) environments. Takes a parameter in the form 'CN=<common name>'
// For simplicity the function skips everything until the first '=' and
// treats the given string _always_ as a common name.
// As characters are only alphanumeric chars and ' ' (blank), '_' (underscore)
// and '=' (equal sign) allowed.
//
// Simple ASN1 encoding for name:
//
// SEQUENCE
// {
// SET
// {
// SEQUENCE
// {
// OBJECT IDENTIFIER
// ANY
// }
// ...
// }
// ...
// }
//
//
// ----------------------------------------------------------------------------
lcp_status_t
SimpleCertStrToName(const TCHAR* CommonName,
COctetString& osEncName)
{
bool fAlphaCharFound = false;
TCHAR* pTc = (TCHAR*)CommonName;
BYTE oid_CN[] = { OID_COMMON_NAME };
int len = 0;
// -- sanity check
if(NULL == pTc || 0 == (len = (int) _tcslen(pTc)))
return LCP_E_BAD_ARG;
// -- spell check
for(int i=0; i<len; i++)
{
TCHAR c = pTc[i];
// .. check for alphanumeric chars first ..
if(
(c >= _T('A') && c <= _T('Z'))
|| (c >= _T('a') && c <= _T('z'))
|| (c >= _T('0') && c <= _T('9'))
)
{
fAlphaCharFound = true;
continue;
}
// .. otherwise for the allowed special chars ..
if( !(
c == _T(' ')
|| c == _T('.')
|| c == _T('/')
|| c == _T('(')
|| c == _T(')')
|| c == _T('+')
|| c == _T('-')
|| c == _T('=')
)
)
return LCP_E_BAD_ARG;
}
// -- skip leading white spaces
while(pTc[i] == _T(' ') || pTc[i] == _T('\t'))
pTc++;
// .. adjust length ..
len = _tcslen(pTc);
if(0 == len) return LCP_E_BAD_ARG;
// -- remove the CN= part ...
// .. search for '=' ..
pTc = _tcschr(CommonName, _T('='));
if(NULL != pTc)
{
pTc++; // skip '='
len = _tcslen(pTc); // adjust length
if(0 == len) return LCP_E_BAD_ARG;
// .. skip leading white spaces ..
while(*pTc == _T(' ') || *pTc == _T('\t'))
pTc++;
// .. adjust length ..
len = _tcslen(pTc);
if(0 == len) return LCP_E_BAD_ARG;
}
else
pTc = (TCHAR*)CommonName; // no '=' found
COctetString osOidCN(sizeof(oid_CN), oid_CN);
COctetString osName(len*sizeof(TCHAR), (BYTE*)pTc);
osEncName = SEQUENCE(SET(SEQUENCE(osOidCN + PrintableString(osName))));
return LCP_S_OK;
}
"McCarthy, James (NZ)" wrote:
>
> According to Microsoft's documentation, CertStrToName is available under NT
> SP3 or IE 3.02. I have IE 3.02 installed on a NT SP3 machine but the
> version of crypt32.dll I have does not have this method in it
> (CertNameToString is present though). The version number of crypt32.dll is
> 4.
>
> Does anyone have any information about this? Do we have to reload SP3 after
> installing IE 3.02?
>
> Thanks,
>
> Jim
--
=============================================================
Jean Renard Ward "My comments reflect only
mailto:jrward@gmx.de my own ignorance, and not
mailto:jrward@alum.mit.edu necessarily that of my
mailto:JeanRenard.Ward@sbs.siemens.com current employer."
http://www.erols.com/rwservices Boston, USA
=============================================================
----------------------------------------------------------------
Users Guide http://www.microsoft.com/workshop/essentials/mail.asp
contains important info including how to unsubscribe. Save time, search
the archives at http://discuss.microsoft.com/archives/index.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic