PowerBuilder
PowerBuilder
Get Certificate User Principal Name (UPN)
See more Certificates Examples
Demonstrates how to get a certificate's UPN from the SAN (Subject Alternative Name). Most certificates do not have a UPN. This example only applies to those certificates that have a User Principal Name.Note: This example requires Chilkat v9.5.0.90 or greater due to fixes made in getting the UPN from the SAN.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Cert
oleobject loo_Xml
string ls_Upn
li_Success = 0
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
if li_rc < 0 then
destroy loo_Cert
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Cert.LoadFromFile("qa_data/certs/sample.cer")
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Cert
return
end if
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
loo_Xml.LoadXml(loo_Cert.SubjectAlternativeName)
Write-Debug loo_Xml.GetXml()
// A certificate with a User Principal Name in the SAN might have this:
// <SubjectAltName>
// <rfc822Name>joe@example.com</rfc822Name>
// <name type="oid" oid="1.3.6.1.4.1.311.20.2.3">joe@example.com</name>
// </SubjectAltName>
// The OID 1.3.6.1.4.1.311.20.2.3 is for the User Principal Name.
ls_Upn = loo_Xml.ChilkatPath("/A/name,oid,1.3.6.1.4.1.311.20.2.3|*")
if loo_Xml.LastMethodSuccess = 0 then
Write-Debug "No user principle name."
else
Write-Debug "User Principle Name = " + ls_Upn
end if
destroy loo_Cert
destroy loo_Xml