primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security\r
functionality enabling.\r
\r
-Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
@param[in] Cert Pointer to the DER-encoded X509 certificate.\r
@param[in] CertSize Size of the X509 certificate in bytes.\r
@param[out] CommonName Buffer to contain the retrieved certificate common\r
- name string. At most CommonNameSize bytes will be\r
+ name string (UTF8). At most CommonNameSize bytes will be\r
written and the string will be null terminated. May be\r
NULL in order to determine the size buffer needed.\r
@param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r
/** @file\r
X.509 Certificate Handler Wrapper Implementation over OpenSSL.\r
\r
-Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
@param[in] Cert Pointer to the DER-encoded X509 certificate.\r
@param[in] CertSize Size of the X509 certificate in bytes.\r
@param[out] CommonName Buffer to contain the retrieved certificate common\r
- name string. At most CommonNameSize bytes will be\r
+ name string (UTF8). At most CommonNameSize bytes will be\r
written and the string will be null terminated. May be\r
NULL in order to determine the size buffer needed.\r
@param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r
IN OUT UINTN *CommonNameSize\r
)\r
{\r
- RETURN_STATUS ReturnStatus;\r
- BOOLEAN Status;\r
- X509 *X509Cert;\r
- X509_NAME *X509Name;\r
- INTN Length;\r
+ RETURN_STATUS ReturnStatus;\r
+ BOOLEAN Status;\r
+ X509 *X509Cert;\r
+ X509_NAME *X509Name;\r
+ INT32 Index;\r
+ INTN Length;\r
+ X509_NAME_ENTRY *Entry;\r
+ ASN1_STRING *EntryData;\r
+ UINT8 *UTF8Name;\r
\r
ReturnStatus = RETURN_INVALID_PARAMETER;\r
+ UTF8Name = NULL;\r
\r
//\r
// Check input parameters.\r
//\r
// Retrieve the CommonName information from X.509 Subject\r
//\r
- Length = (INTN) X509_NAME_get_text_by_NID (X509Name, NID_commonName, CommonName, (int)(*CommonNameSize));\r
- if (Length < 0) {\r
+ Index = X509_NAME_get_index_by_NID (X509Name, NID_commonName, -1);\r
+ if (Index < 0) {\r
//\r
// No CommonName entry exists in X509_NAME object\r
//\r
goto _Exit;\r
}\r
\r
- *CommonNameSize = (UINTN)(Length + 1);\r
+ Entry = X509_NAME_get_entry (X509Name, Index);\r
+ if (Entry == NULL) {\r
+ //\r
+ // Fail to retrieve name entry data\r
+ //\r
+ *CommonNameSize = 0;\r
+ ReturnStatus = RETURN_NOT_FOUND;\r
+ goto _Exit;\r
+ }\r
+\r
+ EntryData = X509_NAME_ENTRY_get_data (Entry);\r
+\r
+ Length = ASN1_STRING_to_UTF8 (&UTF8Name, EntryData);\r
+ if (Length < 0) {\r
+ //\r
+ // Fail to convert the commonName string\r
+ //\r
+ *CommonNameSize = 0;\r
+ ReturnStatus = RETURN_INVALID_PARAMETER;\r
+ goto _Exit;\r
+ }\r
+\r
if (CommonName == NULL) {\r
+ *CommonNameSize = Length + 1;\r
ReturnStatus = RETURN_BUFFER_TOO_SMALL;\r
} else {\r
+ *CommonNameSize = MIN ((UINTN)Length, *CommonNameSize - 1) + 1;\r
+ CopyMem (CommonName, UTF8Name, *CommonNameSize - 1);\r
+ CommonName[*CommonNameSize - 1] = '\0';\r
ReturnStatus = RETURN_SUCCESS;\r
}\r
\r
if (X509Cert != NULL) {\r
X509_free (X509Cert);\r
}\r
+ if (UTF8Name != NULL) {\r
+ OPENSSL_free (UTF8Name);\r
+ }\r
\r
return ReturnStatus;\r
}\r
X.509 Certificate Handler Wrapper Implementation which does not provide\r
real capabilities.\r
\r
-Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
@param[in] Cert Pointer to the DER-encoded X509 certificate.\r
@param[in] CertSize Size of the X509 certificate in bytes.\r
@param[out] CommonName Buffer to contain the retrieved certificate common\r
- name string. At most CommonNameSize bytes will be\r
+ name string (UTF8). At most CommonNameSize bytes will be\r
written and the string will be null terminated. May be\r
NULL in order to determine the size buffer needed.\r
@param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r