]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Application/Cryptest/RsaVerify2.c
CryptoPkg: Add new API to retrieve commonName of X.509 certificate
[mirror_edk2.git] / CryptoPkg / Application / Cryptest / RsaVerify2.c
index 98b5aad9009808fd74d3d932889731bcbf4bd5e7..9db43d6eef7aed481a1674b2f24b36d29e6e21d9 100644 (file)
@@ -204,13 +204,17 @@ ValidateCryptRsa2 (
   VOID\r
   )\r
 {\r
-  BOOLEAN  Status;\r
-  VOID     *RsaPrivKey;\r
-  VOID     *RsaPubKey;\r
-  UINT8    *Signature;\r
-  UINTN    SigSize;\r
-  UINT8    *Subject;\r
-  UINTN    SubjectSize;\r
+  BOOLEAN        Status;\r
+  VOID           *RsaPrivKey;\r
+  VOID           *RsaPubKey;\r
+  UINT8          *Signature;\r
+  UINTN          SigSize;\r
+  UINT8          *Subject;\r
+  UINTN          SubjectSize;\r
+  RETURN_STATUS  ReturnStatus;\r
+  CHAR8          CommonName[64];\r
+  CHAR16         CommonNameUnicode[64];\r
+  UINTN          CommonNameSize;\r
 \r
   Print (L"\nUEFI-OpenSSL RSA Key Retrieving Testing: ");\r
 \r
@@ -286,6 +290,20 @@ ValidateCryptRsa2 (
     Print (L"[Pass]");\r
   }\r
 \r
+  //\r
+  // Get CommonName from X509 Certificate Subject\r
+  //\r
+  CommonNameSize = 64;\r
+  ZeroMem (CommonName, CommonNameSize);\r
+  ReturnStatus = X509GetCommonName (TestCert, sizeof (TestCert), CommonName, &CommonNameSize);\r
+  if (RETURN_ERROR (ReturnStatus)) {\r
+    Print (L"\n  - Retrieving Common Name - [Fail]");\r
+    return EFI_ABORTED;\r
+  } else {\r
+    AsciiStrToUnicodeStrS (CommonName, CommonNameUnicode, CommonNameSize);\r
+    Print (L"\n  - Retrieving Common Name = \"%s\" (Size = %d)", CommonNameUnicode, CommonNameSize);\r
+  }\r
+\r
   //\r
   // X509 Certificate Verification.\r
   //\r