securityanddataprivacytools/securitytools/certapp/encdec/x509utils.cpp
changeset 65 970c0057d9bc
parent 8 35751d3474b7
child 102 deec7e509f66
equal deleted inserted replaced
60:11c66574c2a2 65:970c0057d9bc
   189 #else
   189 #else
   190 #define D2I_CONST
   190 #define D2I_CONST
   191 #endif
   191 #endif
   192 
   192 
   193 bool X509SubjectKeyId(EUseCertificateExtension aUseExtension, bool aUseRfc3280Algorithm,
   193 bool X509SubjectKeyId(EUseCertificateExtension aUseExtension, bool aUseRfc3280Algorithm,
   194 					  const std::string &aCert, 
   194 					  bool aIsCa, const std::string &aCert, 
   195 					  std::string &aSubject, TKeyIdentifier &aSubjectKeyId)
   195 					  std::string &aSubject, TKeyIdentifier &aSubjectKeyId)
   196 {
   196 {
   197 	bool done = false;
   197 	bool done = false;
   198 	prog << Log::Indent() << "X509SubjectKeyId - aUseExtension " << aUseExtension << " aUseRfc3280Algorithm " << aUseRfc3280Algorithm << " :-" << Log::Endl();
   198 	prog << Log::Indent() << "X509SubjectKeyId - aUseExtension " << aUseExtension << " aUseRfc3280Algorithm " << aUseRfc3280Algorithm << " :-" << Log::Endl();
   199 	AutoIndent ai(prog); // IncIndent, will DecIndent when it leaves scope
   199 	AutoIndent ai(prog); // IncIndent, will DecIndent when it leaves scope
   208 		}
   208 		}
   209 
   209 
   210 	// Return the Subject Name
   210 	// Return the Subject Name
   211 	prog << Log::Indent() << "Cert subject is '" << x509->name << "'" << Log::Endl();
   211 	prog << Log::Indent() << "Cert subject is '" << x509->name << "'" << Log::Endl();
   212 	aSubject = std::string(x509->name);
   212 	aSubject = std::string(x509->name);
   213 
   213 	TUint32 ver = X509_get_version(x509);
   214 	if(aUseExtension)
   214 	prog << Log::Indent() << "Cert version is '" << ver << "'" << Log::Endl();
       
   215 	
       
   216 	// if the ver is a v1 or v2 type then there is no way of knowing which is a CA, treat all certs as CA as done in the certificate recognizer.
       
   217 	bool treatAsCa = false;  
       
   218 	if ( ver < 3 || aIsCa )
       
   219 		{
       
   220 		treatAsCa = true;
       
   221 		}
       
   222 	
       
   223 	if(treatAsCa && aUseExtension)
   215 		{
   224 		{
   216 		// Attempt to read Subject Key Id extension
   225 		// Attempt to read Subject Key Id extension
   217 		ASN1_OCTET_STRING *subKeyId = (ASN1_OCTET_STRING *) X509_get_ext_d2i(x509, NID_subject_key_identifier, NULL, NULL);
   226 		ASN1_OCTET_STRING *subKeyId = (ASN1_OCTET_STRING *) X509_get_ext_d2i(x509, NID_subject_key_identifier, NULL, NULL);
   218 		if(subKeyId)
   227 		if(subKeyId)
   219 			{
   228 			{