为什么在使用Python获取发行方名称时会发生名称倒序?

huangapple go评论80阅读模式
英文:

why the issuer name is reversed when i get it using python?

问题

I have a certificate and when I use Python to get the issuer name of the certificate, I get the issuer name reversed:

The correct issuer name: CN=PEZEINVOICESCA2-CA,DC=extgazt,DC=gov,DC=local

The issuer name that I get: DC=local,DC=gov,DC=extgazt,CN=PEZEINVOICESCA2-CA

This is the code that I use to get the issuer name:

import cryptography.x509

your_Certificate = open("cert.txt","rb")
Certificate = your_Certificate.read().decode()
your_Certificate.close()

the_certificate = cryptography.x509.load_pem_x509_certificate("-----BEGIN CERTIFICATE-----\n{}\n-----END CERTIFICATE-----".format(Certificate).encode())
issuer_name = (str(the_certificate.issuer).split("(")[-1].split(")")[0])
print(issuer_name)

And this is the website that I get the correct issuer name from: https://certlogik.com/

This is my certificate:

MIIFGTCCBMCgAwIBAgITbQAABwotIOM7hEGkOwAAAAAHCjAKBggqhkjOPQQDAjBiMRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxEzARBgoJkiaJk/IsZAEZFgNnb3YxFzAVBgoJkiaJk/IsZAEZFgdleHRnYXp0MRswGQYDVQQDExJQRVpFSU5WT0lDRVNDQTItQ0EwHhcNMjMwNTIxMDkxMjE3WhcNMjMwODA4MTIyNjQ2WjBZMQswCQYDVQQGEwJTQTEhMB8GA1UEChMYTW9oYW1tZWQgYWxtYWxraSBjb21wYW55MREwDwYDVQQLEwhtb2hhbW1lZDEUMBIGA1UEAxMLZGV2aWNlIG11c2EwVjAQBgcqhkjOPQIBBgUrgQQACgNCAAStYLyBf9nWo3vWtzUkM2itMt/8euVz4Kao8fqz8SqUKl46RzqyhUUjR4gij3HvA6gBbHT1ai2O5JaAeaj1/4G3o4IDXzCCA1swJwYJKwYBBAGCNxUKBBowGDAKBggrBgEFBQcDAjAKBggrBgEFBQcDAzA8BgkrBgEEAYI3FQcELzAtBiUrBgEEAYI3FQiBhqgdhND7EobtnSSHzvsZ08BVZoGc2C2D5cVdAgFkAgETMIHNBggrBgE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yE+QdNH5AF4CGqIA+wpBYe9vVngMdGlvOwJA==

I know that I can write it reversed again, but I want it to come out correctly from Python itself.

英文:

i have a certificate and when i use python to get the issuer name of the certificate i get the issuer name reversed :

the correct issuer name : CN=PEZEINVOICESCA2-CA,DC=extgazt,DC=gov,DC=local

the issuer name that i get : DC=local,DC=gov,DC=extgazt,CN=PEZEINVOICESCA2-CA

this is the code that i use to get the issuer name :

import cryptography.x509

your_Certificate = open("cert.txt","rb")
Certificate = your_Certificate.read().decode()
your_Certificate.close()


the_certificate = cryptography.x509.load_pem_x509_certificate("-----BEGIN CERTIFICATE-----\n{}\n-----END CERTIFICATE-----".format(Certificate).encode())
issuer_name = (str(the_certificate.issuer).split("(")[-1].split(")")[0])
print(issuer_name)

and this is the website that i get the correct issuer name from : https://certlogik.com/

this is my certificate :

> MIIFGTCCBMCgAwIBAgITbQAABwotIOM7hEGkOwAAAAAHCjAKBggqhkjOPQQDAjBiMRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxEzARBgoJkiaJk/IsZAEZFgNnb3YxFzAVBgoJkiaJk/IsZAEZFgdleHRnYXp0MRswGQYDVQQDExJQRVpFSU5WT0lDRVNDQTItQ0EwHhcNMjMwNTIxMDkxMjE3WhcNMjMwODA4MTIyNjQ2WjBZMQswCQYDVQQGEwJTQTEhMB8GA1UEChMYTW9oYW1tZWQgYWxtYWxraSBjb21wYW55MREwDwYDVQQLEwhtb2hhbW1lZDEUMBIGA1UEAxMLZGV2aWNlIG11c2EwVjAQBgcqhkjOPQIBBgUrgQQACgNCAAStYLyBf9nWo3vWtzUkM2itMt/8euVz4Kao8fqz8SqUKl46RzqyhUUjR4gij3HvA6gBbHT1ai2O5JaAeaj1/4G3o4IDXzCCA1swJwYJKwYBBAGCNxUKBBowGDAKBggrBgEFBQcDAjAKBggrBgEFBQcDAzA8BgkrBgEEAYI3FQcELzAtBiUrBgEEAYI3FQiBhqgdhND7EobtnSSHzvsZ08BVZoGc2C2D5cVdAgFkAgETMIHNBgg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/YVPyE+QdNH5AF4CGqIA+wpBYe9vVngMdGlvOwJA==

i know that i can write it reversed agin but i want it comes correct from python itself.

答案1

得分: 2

你可以使用rfc4514_string()来获得所需的顺序,它根据RFC 4514,sec. 2.1(逆序,逗号分隔)返回数据:

print(the_certificate.issuer.rfc4514_string())

得到的结果是:

CN=PEZEINVOICESCA2-CA,DC=extgazt,DC=gov,DC=local
英文:

You get the desired order with rfc4514_string(), which returns the data according to RFC 4514, sec. 2.1 (reverse order, comma separated):

print(the_certificate.issuer.rfc4514_string())

gives

CN=PEZEINVOICESCA2-CA,DC=extgazt,DC=gov,DC=local

huangapple
  • 本文由 发表于 2023年5月21日 21:28:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76300143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定