我有指向 X509 结构的指针,我想将它转换为字符串,我该怎么做?我需要像在PEM_write_X509
函数中打印的那样获取字符串。
-----BEGIN CERTIFICATE-----
MIIIxjCCB66gAwIBAgIKah4k3wAAAAC/WTANBgkqhkiG9w0BAQUFADBbMRIwEAYK
CZImiZPyLGQBGRYCcnUxFjAUBgoJkiaJk/IsZAEZFgZ5YW5kZXgxEjAQBgoJkiaJ
k/IsZAEZFgJsZDEZMBcGA1UEAxMQWWFuZGV4RXh0ZXJuYWxDQTAeFw0xMjA5MDQx
NDEzMDhaFw0xNDAxMTcxNTE1NDZaMIGQMQswCQYDVQQGEwJSVTEPMA0GA1UECBMG
UnVzc2lhMQ8wDQYDVQQHEwZNb3Njb3cxDzANBgNVBAoTBllhbmRleDEMMAoGA1UE
CxMDSVRPMRQwEgYDVQQDEwtZYW5kZXggU2VycDEqMCgGCSqGSIb3DQEJARYbc2Vh
cmNoLWFkbWluQHlhbmRleC10ZWFtLnJ1MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
iQKBgQDBXfluaCox4R4D2Y/3mc6O9i3koHtGtHZmZjYm7XdsAA5xsOZAonLReJCL
J8BtgS6McmX9cGa9GF9ErxfWODC+1Wb3yayUNzOhr2ICu3T++ttf0aMVvMTeDF/Y
lfoZ+tgg1ITQ9yVtz7eteodjLNAy6AaC0z7ulSq4jvPbm1WuBQIDAQABo4IF2DCC
BdQwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMCBaAwggRbBgNVHREEggRSMIIEToIJ
eWFuZGV4LmJ5ggp5YW5kZXguY29tgg15YW5kZXguY29tLnRygg15YW5kZXguY29t
LnVhggl5YW5kZXgua3qCC3lhbmRleC5tb2Jpggp5YW5kZXgubmV0ggl5YW5kZXgu
cnWCCXlhbmRleC5zdIIJeWFuZGV4LnVhghBpbWFnZXMueWFuZGV4LmJ5ghFpbWFn
ZXMueWFuZGV4LmNvbYIUaW1hZ2VzLnlhbmRleC5jb20udHKCFGltYWdlcy55YW5k
ZXguY29tLn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LnlhbmRleC5jb20udWGC
DXd3dy55YW5kZXgua3qCD3d3dy55YW5kZXgubW9iaYIOd3d3LnlhbmRleC5uZXSC
DXd3dy55YW5kZXgucnWCDXd3dy55YW5kZXguc3SCDXd3dy55YW5kZXgudWEwHQYD
VR0OBBYEFDjrNQM8dYCWIlusgG7EqlAZ5D9lMB8GA1UdIwQYMBaAFNtBJzBPGvVb
PoRWyOyFmLNRLC0nMEwGA1UdHwRFMEMwQaA/oD2GO2h0dHA6Ly9jcmxzLnlhbmRl
eC5ydS9ZYW5kZXhFeHRlcm5hbENBL1lhbmRleEV4dGVybmFsQ0EuY3JsMFcGCCsG
AQUFBwEBBEswSTBHBggrBgEFBQcwAoY7aHR0cDovL2NybHMueWFuZGV4LnJ1L1lh
bmRleEV4dGVybmFsQ0EvWWFuZGV4RXh0ZXJuYWxDQS5kZXIwPwYJKwYBBAGCNxUH
BDIwMAYoKwYBBAGCNxUIhtyhJoWT1VWH/YEtg/nnAoOV0gQci62jzDeH/MC/KAIB
ZAIBBjATBgNVHSUEDDAKBggrBgEFBQcDATAbBgkrBgEEAYI3FQoEDjAMMAoGCCsG
AQUFBwMBMA0GCSqGSIb3DQEBBQUAA4IBAQDNo4rLhEWgj72wbpYO6lSuM6YHn6Bj
BsXJfumtchTyRHsY8RJGGKGZ6joeOQweqChsQXULTnVzadCJ1VqVJ2lTaII5R8Ii
N9jcYgFl4WOv1ynFJ0Jf3V6/ePQd9cqFFJTfFSODHsyZR/Dhgez81/QExfsG/SzS
u+ACIvsDbyu7NFcAK6ZM5CKz3lcisddT/pSPbTOi7AtqtNTrvKlV2AT+5mfNTEa7
rNv6chVl1He7RW8r7uCkK6AfFb0Z4LDhv2zkvmcUtaojmDOO/2AZSXym8efCSmHr
CL2rhv6+ER3c0x5uJlhAUr1ZM76/XnfvT/2SKekPXbGlVAE3v7tfRnW9
-----END CERTIFICATE-----
我试图在PEM_write_X509
openssl的源代码中查看函数,但我做不到,这么多宏和定义。
另外,如何查看证书类型?是 PEM 还是 DER?
更新:
struct x509_st
{
X509_CINF *cert_info;
X509_ALGOR *sig_alg;
ASN1_BIT_STRING *signature;
int valid;
int references;
char *name;
CRYPTO_EX_DATA ex_data;
/* These contain copies of various extension values */
long ex_pathlen;
long ex_pcpathlen;
unsigned long ex_flags;
unsigned long ex_kusage;
unsigned long ex_xkusage;
unsigned long ex_nscert;
ASN1_OCTET_STRING *skid;
AUTHORITY_KEYID *akid;
X509_POLICY_CACHE *policy_cache;
STACK_OF(DIST_POINT) *crldp;
STACK_OF(GENERAL_NAME) *altname;
NAME_CONSTRAINTS *nc;
#ifndef OPENSSL_NO_RFC3779
STACK_OF(IPAddressFamily) *rfc3779_addr;
struct ASIdentifiers_st *rfc3779_asid;
#endif
#ifndef OPENSSL_NO_SHA
unsigned char sha1_hash[SHA_DIGEST_LENGTH];
#endif
X509_CERT_AUX *aux;
} /* X509 */;