Hi,
I'm developing a custom module for Oracle Access Manager. It needs to read some
attributes from a certificate.
The following code Works in a standalone c program, but crash (with a seg
fault) using it as a module. The crash occurs at line : X509_get_version(x), or
any method that uses x
char certificate[]="-BEGIN
CERTIFICATE-\nMIIF7TCCBNWgAwIBAgIQBP/1hLYXHqFL0JS0tW1F6DANBgkqhkiG9w0BAQUFADBc\nMQswCQYDVQQGEwJFUzEoMCYGA1UECgwfRElSRUNDSU9OIEdFTkVSQUwgREUgTEEg\nUE9MSUNJQTENMAsGA1UECwwERE5JRTEUMBIGA1UEAwwLQUMgRE5JRSAwMDEwHhcN\nMTAwNDIyMTgyNTU1WhcNMTIxMDIyMTgyNTQ4WjB/MQswCQYDVQQGEwJFUzESMBAG\nA1UEBRMJNDQwNDc0OTNEMQ8wDQYDVQQEDAZCRU5JVE8xFTATBgNVBCoMDE1JR1VF\nTCBBTkdFTDE0MDIGA1UEAwwrQkVOSVRPIFRPVkFSLCBNSUdVRUwgQU5HRUwgKEFV\nVEVOVElDQUNJw5NOKTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL7n\nkkMh6u0xNmanPHKYIwXFBiMqtWxy6q19G9lloQ2np41/XpQ73xNhJ3P4VYt7axAt\njNJuFU+yd8034Gj2ul33EFsJW4EV2Mz37foBnbCLU4z9QyJ5YlrAuNTRW+cuBjly\nF+BBw1B5QofYYnMtg9Sur291QgEEC/vA5n2GMGXKRoPA8MP5vbWDSx02jiJxtGOP\nHoB64/D33K8rBbN6f3jXOXbi0A+OHsvZ5apfb1R7a2UzzX7xVX+IRtRi4yM3Q1VR\nw276wjH7P1pf+mDaKLNWEJM4loyi6aj1wGSDC9TsyDNrey+ui04cIfWrwLkfBThj\nuh2wXKK8vP+aAl+8OQECAwEAAaOCAoYwggKCMAwGA1UdEwEB/wQCMAAwDgYDVR0P\nAQH/BAQDAgeAMB0GA1UdDgQWBBTp1lan8sd28P0De91YKYiEcdCcbjAfBgNVHSME\nGDAWgBQaiajF7o92XVV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Zjy9AhjcE3tDo5eO9Y9Yx3hZBbty3c3UMq\n2utP8v+jc9f530avKbX8swqXcERjFeH1GHmuA4xhlznM\n-END
CERTIFICATE-\n";
X509 *x = NULL;
BIO *mem =NULL;
FILE *fp;
fp = fopen("/tmp/testfilen_fn.txt","a+");
mem = BIO_new_mem_buf((void *)certificate,-1);
x=PEM_read_bio_X509 (mem,NULL,NULL,NULL);
BIO_free(mem);
if (x!=NULL){
fprintf(fp,"Version %d\n",(int)X509_get_version(x));
}
X509_free(x);
fclose(fp);
What is wrong?
Thanks