Decoding windows certificate serial number in python

0

I'm trying to decode the serial number of a X.509 certificate, I opened with win32crypt in Python (http://timgolden.me.uk/pywin32-docs/PyCERT_CONTEXT.html)

import win32crypt
import sys

# lpszStoreProvider
CERT_STORE_PROV_SYSTEM = 0x0000000A

# dwFlags
CERT_SYSTEM_STORE_LOCAL_MACHINE = 0x00020000    

def main(*argv):
    store = win32crypt.CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, None, CERT_SYSTEM_STORE_LOCAL_MACHINE, "MY")
    for cert in store.CertEnumCertificatesInStore():
        print("1 Cert: " + str(cert))
        print("2 CertEnumCertificateContextProperties: " + str(cert.CertEnumCertificateContextProperties()))
        print("3 cert.Subject: " + win32crypt.CertNameToStr(cert.Subject))
        print("4 SerialNumber: " + str(cert.SerialNumber))



if __name__ == "__main__":
    print("Python {0:s} {1:d}bit on {2:s}\n".format(" ".join(item.strip() for item in sys.version.split("\n")), 64 if sys.maxsize > 0x100000000 else 32, sys.platform))
    main(*sys.argv[1:])
    print("\nDone.")

The representation in memory is as follows:

SerialNumber = b'\x07\x00\x00\x00\x00\x00\xc3o\x0c\xfbK\xf8\xdf\xbe\x07\x00\x00\x00*'

enter image description here

I just can't figure out, what kind of encoding is used and howto decode?!

Edit: (..the bytes into the correct serial number: 2a00000007bedff84bfb0c6fc3000000000007)

python
windows
certificate
pywin32
wincrypt
asked on Stack Overflow Apr 15, 2020 by sewe • edited Apr 16, 2020 by sewe

1 Answer

0

Answer: decoded = int.from_bytes(cert.SerialNumber,"little")

answered on Stack Overflow Apr 16, 2020 by sewe

User contributions licensed under CC BY-SA 3.0