34 #include <sys/types.h>
44 #include <openssl/pem.h>
50 EPNAME(
"X509Req::XrdCryptosslX509Req_bio");
62 DEBUG(
"got undefined opaque buffer");
68 BIO *bmem = BIO_new(BIO_s_mem());
70 DEBUG(
"unable to create BIO for memory operations");
75 int nw = BIO_write(bmem,(
const void *)(buck->
buffer),buck->
size);
76 if (nw != buck->
size) {
77 DEBUG(
"problems writing data to memory BIO (nw: "<<nw<<
")");
82 if (!PEM_read_bio_X509_REQ(bmem,&creq,0,0)) {
83 DEBUG(
"unable to read certificate request to memory BIO");
94 EVP_PKEY *evpp = X509_REQ_get_pubkey(creq);
101 DEBUG(
"could not access the public key");
109 EPNAME(
"X509Req::XrdCryptosslX509Req_x509");
121 DEBUG(
"got undefined X509 object");
132 EVP_PKEY *evpp = X509_REQ_get_pubkey(creq);
139 DEBUG(
"could not access the public key");
149 if (creq) X509_REQ_free(creq);
158 EPNAME(
"X509Req::Subject");
161 if (subject.
length() <= 0) {
165 DEBUG(
"WARNING: no certificate available - cannot extract subject name");
166 return (
const char *)0;
174 return (subject.
length() > 0) ? subject.
c_str() : (
const char *)0;
183 EPNAME(
"X509::SubjectHash");
187 if (subjectoldhash.
length() <= 0) {
190 char chash[30] = {0};
191 snprintf(chash,
sizeof(chash),
192 "%08lx.0",X509_NAME_hash_old(X509_REQ_get_subject_name(creq)));
193 subjectoldhash = chash;
195 DEBUG(
"WARNING: no certificate available - cannot extract subject hash (md5)");
199 return (subjectoldhash.
length() > 0) ? subjectoldhash.
c_str() : (
const char *)0;
203 if (subjecthash.
length() <= 0) {
207 char chash[30] = {0};
208 snprintf(chash,
sizeof(chash),
209 "%08lx.0",X509_NAME_hash(X509_REQ_get_subject_name(creq)));
212 DEBUG(
"WARNING: no certificate available - cannot extract subject hash (default)");
217 return (subjecthash.
length() > 0) ? subjecthash.
c_str() : (
const char *)0;
224 EPNAME(
"X509Req::GetExtension");
229 DEBUG(
"OID string not defined");
235 DEBUG(
"certificate is not initialized");
240 STACK_OF(X509_EXTENSION) *esk = X509_REQ_get_extensions(creq);
242 int numext = sk_X509_EXTENSION_num(esk);
244 DEBUG(
"certificate has got no extensions");
247 DEBUG(
"certificate request has "<<numext<<
" extensions");
251 int nid = OBJ_sn2nid(oid);
252 bool usenid = (nid > 0);
256 X509_EXTENSION *wext = 0;
257 for (i = 0; i< numext; i++) {
258 wext = sk_X509_EXTENSION_value(esk, i);
260 int enid = OBJ_obj2nid(X509_EXTENSION_get_object(wext));
266 OBJ_obj2txt(s,
sizeof(s), X509_EXTENSION_get_object(wext), 1);
275 DEBUG(
"Extension "<<oid<<
" not found");
287 EPNAME(
"X509Req::Export");
291 DEBUG(
"serialization already performed:"
292 " return previous result ("<<bucket->
size<<
" bytes)");
298 DEBUG(
"certificate is not initialized");
304 BIO *bmem = BIO_new(BIO_s_mem());
306 DEBUG(
"unable to create BIO for memory operations");
311 if (!PEM_write_bio_X509_REQ(bmem, creq)) {
312 DEBUG(
"unable to write certificate request to memory BIO");
318 int blen = BIO_get_mem_data(bmem, &bdata);
319 DEBUG(
"BIO data: "<<blen<<
" bytes at 0x"<<(
int *)bdata);
325 bucket->
SetBuf(bdata, blen);
326 DEBUG(
"result of serialization: "<<bucket->
size<<
" bytes");
328 DEBUG(
"unable to create bucket for serialized format");
344 EPNAME(
"X509Req::Verify");
351 int rc = X509_REQ_verify(creq,X509_REQ_get_pubkey(creq));
356 DEBUG(
"signature not OK");
359 DEBUG(
"could not verify signature");
void * XrdCryptoX509Reqdata
void XrdCryptosslNameOneLine(X509_NAME *nm, XrdOucString &s)
const char * SubjectHash()
XrdCryptosslX509Req(XrdSutBucket *bck)
XrdCryptoX509Reqdata GetExtension(const char *oid)
virtual ~XrdCryptosslX509Req()
const char * c_str() const
int SetBuf(const char *nb=0, int ns=0)