XRootD
Loading...
Searching...
No Matches
XrdCryptosslFactory.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d C r y p t o S s l F a c t o r y . c c */
4/* */
5/* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* Produced by Gerri Ganis for CERN */
7/* */
8/* This file is part of the XRootD software suite. */
9/* */
10/* XRootD is free software: you can redistribute it and/or modify it under */
11/* the terms of the GNU Lesser General Public License as published by the */
12/* Free Software Foundation, either version 3 of the License, or (at your */
13/* option) any later version. */
14/* */
15/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
16/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
17/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
18/* License for more details. */
19/* */
20/* You should have received a copy of the GNU Lesser General Public License */
21/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
22/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
23/* */
24/* The copyright holder's institutional names and contributor's names may not */
25/* be used to endorse or promote products derived from this software without */
26/* specific prior written permission of the institution or contributor. */
27/******************************************************************************/
28
29/* ************************************************************************** */
30/* */
31/* Implementation of the OpenSSL crypto factory */
32/* */
33/* ************************************************************************** */
34
43
45#include "XrdSys/XrdSysError.hh"
46#include "XrdSut/XrdSutRndm.hh"
47
49
51
52#include "XrdVersion.hh"
53
54#include <openssl/rand.h>
55#include <openssl/ssl.h>
56
57//
58// For error logging and tracing
60static XrdSysError eDest(0,"cryptossl_");
61
62//______________________________________________________________________________
65{
66 // Constructor: init the needed components of the OpenSSL library
67
68 // Init SSL ...
69 //
70 static const char *eText = XrdTlsContext::Init();
71
72 // Make sure all went well (we need to possibly abort here)
73 //
74 if (eText)
75 {std::cerr <<"XrdCryptosslFactory: " <<eText <<std::endl;
76 abort();
77 }
78
79 // Init Random machinery
80 //
81 int klen = 32;
82 char *ktmp = XrdSutRndm::GetBuffer(klen);
83 if (ktmp) {
84 // Feed the random engine
85 RAND_seed(ktmp,klen);
86 delete[] ktmp;
87 }
88}
89
90//______________________________________________________________________________
92{
93 // Set trace flags according to 'trace'
94
95 //
96 // Initiate error logging and tracing
97 eDest.logger(&Logger);
98 if (!sslTrace)
100 if (sslTrace) {
101 // Set debug mask
102 sslTrace->What = 0;
103 // Low level only
104 if ((trace & sslTRACE_Notify))
105 sslTrace->What |= sslTRACE_Notify;
106 // Medium level
107 if ((trace & sslTRACE_Debug))
109 // High level
110 if ((trace & sslTRACE_Dump))
111 sslTrace->What |= sslTRACE_ALL;
112 }
113}
114
115//______________________________________________________________________________
117{
118 // Return an instance of an implementation of the PBKDF2 fun length.
119
120 return &XrdCryptosslKDFunLen;
121}
122
123//______________________________________________________________________________
125{
126 // Return an instance of an implementation of the PBKDF2 function.
127
128 return &XrdCryptosslKDFun;
129}
130
131//______________________________________________________________________________
133{
134 // Returns true if specified cipher is supported
135
137}
138
139//______________________________________________________________________________
141{
142 // Returns true if cipher padding is supported
143 return true;
144}
145
146//______________________________________________________________________________
148{
149 // Return an instance of a ssl implementation of XrdCryptoCipher.
150
151 XrdCryptoCipher *cip = new XrdCryptosslCipher(t,l);
152 if (cip) {
153 if (cip->IsValid())
154 return cip;
155 else
156 delete cip;
157 }
158 return (XrdCryptoCipher *)0;
159}
160
161//______________________________________________________________________________
163 int l, const char *k,
164 int liv, const char *iv)
165{
166 // Return an instance of a ssl implementation of XrdCryptoCipher.
167
168 XrdCryptoCipher *cip = new XrdCryptosslCipher(t,l,k,liv,iv);
169 if (cip) {
170 if (cip->IsValid())
171 return cip;
172 else
173 delete cip;
174 }
175 return (XrdCryptoCipher *)0;
176}
177
178//______________________________________________________________________________
180{
181 // Return an instance of a Local implementation of XrdCryptoCipher.
182
184 if (cip) {
185 if (cip->IsValid())
186 return cip;
187 else
188 delete cip;
189 }
190 return (XrdCryptoCipher *)0;
191}
192
193//______________________________________________________________________________
194XrdCryptoCipher *XrdCryptosslFactory::Cipher(bool padded, int b, char *p,
195 int l, const char *t)
196{
197 // Return an instance of a Ssl implementation of XrdCryptoCipher.
198
199 XrdCryptoCipher *cip = new XrdCryptosslCipher(padded, b,p,l,t);
200 if (cip) {
201 if (cip->IsValid())
202 return cip;
203 else
204 delete cip;
205 }
206 return (XrdCryptoCipher *)0;
207}
208
209//______________________________________________________________________________
211 int l, const char *t)
212{
213 // Return an instance of a Ssl implementation of XrdCryptoCipher.
214
215 XrdCryptoCipher *cip = new XrdCryptosslCipher(false,b,p,l,t);
216 if (cip) {
217 if (cip->IsValid())
218 return cip;
219 else
220 delete cip;
221 }
222 return (XrdCryptoCipher *)0;
223}
224
225//______________________________________________________________________________
227{
228 // Return an instance of a Ssl implementation of XrdCryptoCipher.
229
231 if (cip) {
232 if (cip->IsValid())
233 return cip;
234 else
235 delete cip;
236 }
237 return (XrdCryptoCipher *)0;
238}
239
240//______________________________________________________________________________
242{
243 // Returns true if specified digest is supported
244
246}
247
248//______________________________________________________________________________
250{
251 // Return an instance of a ssl implementation of XrdCryptoMsgDigest.
252
254 if (md) {
255 if (md->IsValid())
256 return md;
257 else
258 delete md;
259 }
260 return (XrdCryptoMsgDigest *)0;
261}
262
263//______________________________________________________________________________
265{
266 // Return an instance of a ssl implementation of XrdCryptoRSA.
267
268 XrdCryptoRSA *rsa = new XrdCryptosslRSA(bits,exp);
269 if (rsa) {
270 if (rsa->IsValid())
271 return rsa;
272 else
273 delete rsa;
274 }
275 return (XrdCryptoRSA *)0;
276}
277
278//______________________________________________________________________________
279XrdCryptoRSA *XrdCryptosslFactory::RSA(const char *pub, int lpub)
280{
281 // Return an instance of a ssl implementation of XrdCryptoRSA.
282
283 XrdCryptoRSA *rsa = new XrdCryptosslRSA(pub,lpub);
284 if (rsa) {
285 if (rsa->IsValid())
286 return rsa;
287 else
288 delete rsa;
289 }
290 return (XrdCryptoRSA *)0;
291}
292
293//______________________________________________________________________________
295{
296 // Return an instance of a Ssl implementation of XrdCryptoRSA.
297
298 XrdCryptoRSA *rsa = new XrdCryptosslRSA(*((XrdCryptosslRSA *)&r));
299 if (rsa) {
300 if (rsa->IsValid())
301 return rsa;
302 else
303 delete rsa;
304 }
305 return (XrdCryptoRSA *)0;
306}
307
308//______________________________________________________________________________
309XrdCryptoX509 *XrdCryptosslFactory::X509(const char *cf, const char *kf)
310{
311 // Return an instance of a ssl implementation of XrdCryptoX509.
312
313 XrdCryptoX509 *x509 = new XrdCryptosslX509(cf, kf);
314 if (x509) {
315 if (x509->Opaque())
316 return x509;
317 else
318 delete x509;
319 }
320 return (XrdCryptoX509 *)0;
321}
322
323//______________________________________________________________________________
325{
326 // Return an instance of a ssl implementation of XrdCryptoX509.
327
328 XrdCryptoX509 *x509 = new XrdCryptosslX509(b);
329 if (x509) {
330 if (x509->Opaque())
331 return x509;
332 else
333 delete x509;
334 }
335 return (XrdCryptoX509 *)0;
336}
337
338//______________________________________________________________________________
340{
341 // Return an instance of a ssl implementation of XrdCryptoX509Crl.
342
343 XrdCryptoX509Crl *x509Crl = new XrdCryptosslX509Crl(cf, opt);
344 if (x509Crl) {
345 if (x509Crl->Opaque())
346 return x509Crl;
347 else
348 delete x509Crl;
349 }
350 return (XrdCryptoX509Crl *)0;
351}
352
353//______________________________________________________________________________
355{
356 // Return an instance of a ssl implementation of XrdCryptoX509Crl.
357
358 XrdCryptoX509Crl *x509Crl = new XrdCryptosslX509Crl(ca);
359 if (x509Crl) {
360 if (x509Crl->Opaque())
361 return x509Crl;
362 else
363 delete x509Crl;
364 }
365 return (XrdCryptoX509Crl *)0;
366}
367
368//______________________________________________________________________________
370{
371 // Return an instance of a ssl implementation of XrdCryptoX509Crl.
372
373 XrdCryptoX509Req *x509Req = new XrdCryptosslX509Req(b);
374 if (x509Req) {
375 if (x509Req->Opaque())
376 return x509Req;
377 else
378 delete x509Req;
379 }
380 return (XrdCryptoX509Req *)0;
381}
382
383//______________________________________________________________________________
385{
386 // Return hook to the OpenSSL implementation of the verification
387 // function for X509 certificate.
388
390}
391
392//______________________________________________________________________________
394{
395 // Return hook to the OpenSSL implementation of the verification
396 // function for X509 certificate chains.
397
399}
400
401//______________________________________________________________________________
403{
404 // Return an instance of an implementation of a function
405 // to export a X509 certificate chain.
406
408}
409
410//______________________________________________________________________________
412{
413 // Return an instance of an implementation of a function
414 // to dump a X509 certificate chain to a file.
415
417}
418
419//______________________________________________________________________________
421{
422 // Return an instance of an implementation of a function
423 // to parse a file supposed to contain for X509 certificates.
424
426}
427
428//______________________________________________________________________________
430{
431 // Return an instance of an implementation of a function
432 // to parse a file supposed to contain for X509 certificates.
433
435}
436
437//______________________________________________________________________________
439{
440 // Return an instance of an implementation of a function
441 // to parse a file supposed to contain for X509 certificates.
442
444}
445
446//______________________________________________________________________________
448{
449 // Check if the proxyCertInfo extension exists
450
452}
453
454//______________________________________________________________________________
461
462//______________________________________________________________________________
464{
465 // Create a proxy certificate
466
468}
469
470//______________________________________________________________________________
477
478//______________________________________________________________________________
485
486//______________________________________________________________________________
488{
489 // Check consistency of a GSI 3 compliant proxy
490
492}
493
494//______________________________________________________________________________
496{
497 // Get VOMS attributes, if any
498
500}
501
502
503/******************************************************************************/
504/* X r d C r y p t o S s l F a c t o r y O b j e c t */
505/******************************************************************************/
506
508
509extern "C" {
511{
512 // Return a pointer to the instantiated Ssl factory singleton.
513 // Instantiate the singleton on the first call.
514
515 static XrdCryptosslFactory SslCryptoFactory;
516
517 return &SslCryptoFactory;
518}}
int kXR_int32
Definition XPtypes.hh:89
static XrdSysLogger Logger
static XrdSysError eDest(0,"crypto_")
int(* XrdCryptoKDFunLen_t)()
int(* XrdCryptoKDFun_t)(const char *pass, int plen, const char *salt, int slen, char *key, int klen)
int(* XrdCryptoX509ChainToFile_t)(XrdCryptoX509Chain *, const char *)
int(* XrdCryptoX509CreateProxy_t)(const char *, const char *, XrdProxyOpt_t *, XrdCryptogsiX509Chain *, XrdCryptoRSA **, const char *)
int(* XrdCryptoX509SignProxyReq_t)(XrdCryptoX509 *, XrdCryptoRSA *, XrdCryptoX509Req *, XrdCryptoX509 **)
bool(* XrdCryptoX509VerifyChain_t)(XrdCryptoX509Chain *chain, int &errcode)
XrdSutBucket *(* XrdCryptoX509ExportChain_t)(XrdCryptoX509Chain *, bool)
int(* XrdCryptoX509ParseBucket_t)(XrdSutBucket *, XrdCryptoX509Chain *)
bool(* XrdCryptoX509VerifyCert_t)(XrdCryptoX509 *c, XrdCryptoX509 *r)
int(* XrdCryptoX509GetVOMSAttr_t)(XrdCryptoX509 *, XrdOucString &)
void(* XrdCryptoSetPathLenConstraint_t)(void *, int)
int(* XrdCryptoX509ParseStack_t)(XrdTlsPeerCerts *pc, XrdCryptoX509Chain *c)
int(* XrdCryptoX509ParseFile_t)(const char *fname, XrdCryptoX509Chain *, const char *)
int(* XrdCryptoX509CreateProxyReq_t)(XrdCryptoX509 *, XrdCryptoX509Req **, XrdCryptoRSA **)
bool(* XrdCryptoProxyCertInfo_t)(const void *, int &, bool *)
int(* XrdCryptoX509CheckProxy3_t)(XrdCryptoX509 *, XrdOucString &)
int XrdCryptosslX509ParseBucket(XrdSutBucket *b, XrdCryptoX509Chain *chain)
int XrdCryptosslKDFunLen()
int XrdCryptosslX509ChainToFile(XrdCryptoX509Chain *ch, const char *fn)
XrdSutBucket * XrdCryptosslX509ExportChain(XrdCryptoX509Chain *chain, bool withprivatekey)
XrdOucTrace * sslTrace
int XrdCryptosslX509ParseStack(XrdTlsPeerCerts *pc, XrdCryptoX509Chain *chain)
int XrdCryptosslKDFun(const char *pass, int plen, const char *salt, int slen, char *key, int klen)
int XrdCryptosslX509ParseFile(const char *fname, XrdCryptoX509Chain *chain, const char *fkey)
bool XrdCryptosslX509VerifyChain(XrdCryptoX509Chain *chain, int &errcode)
bool XrdCryptosslX509VerifyCert(XrdCryptoX509 *cert, XrdCryptoX509 *ref)
void XrdCryptosslSetPathLenConstraint(void *ext, int pathlen)
int XrdCryptosslX509CheckProxy3(XrdCryptoX509 *, XrdOucString &)
#define sslTRACE_ALL
int XrdCryptosslX509SignProxyReq(XrdCryptoX509 *, XrdCryptoRSA *, XrdCryptoX509Req *, XrdCryptoX509 **)
bool XrdCryptosslProxyCertInfo(const void *ext, int &pathlen, bool *haspolicy=0)
#define sslTRACE_Dump
int XrdCryptosslX509CreateProxyReq(XrdCryptoX509 *, XrdCryptoX509Req **, XrdCryptoRSA **)
#define sslTRACE_Debug
#define sslTRACE_Notify
int XrdCryptosslX509CreateProxy(const char *, const char *, XrdProxyOpt_t *, XrdCryptogsiX509Chain *, XrdCryptoRSA **, const char *)
int XrdCryptosslX509GetVOMSAttr(XrdCryptoX509 *, XrdOucString &)
XrdCryptoFactory * XrdCryptosslFactoryObject()
static XrdSysError eDest(0,"cryptossl_")
XrdVERSIONINFO(XrdCryptosslFactoryObject, cryptossl)
#define XrdCryptosslFactoryID
virtual bool IsValid()
XrdCryptoFactory(const char *n="Unknown", int id=-1)
virtual XrdCryptoX509Crldata Opaque()
virtual XrdCryptoX509Reqdata Opaque()
virtual XrdCryptoX509data Opaque()
static bool IsSupported(const char *cip)
void SetTrace(kXR_int32 trace)
XrdCryptoX509CreateProxy_t X509CreateProxy()
XrdCryptoX509CreateProxyReq_t X509CreateProxyReq()
XrdCryptoSetPathLenConstraint_t SetPathLenConstraint()
XrdCryptoX509ChainToFile_t X509ChainToFile()
bool SupportedMsgDigest(const char *dgst)
XrdCryptoX509ParseFile_t X509ParseFile()
XrdCryptoX509VerifyCert_t X509VerifyCert()
XrdCryptoX509SignProxyReq_t X509SignProxyReq()
XrdCryptoX509ExportChain_t X509ExportChain()
XrdCryptoMsgDigest * MsgDigest(const char *dgst)
XrdCryptoX509GetVOMSAttr_t X509GetVOMSAttr()
XrdCryptoX509VerifyChain_t X509VerifyChain()
bool SupportedCipher(const char *t)
XrdCryptoKDFun_t KDFun()
XrdCryptoX509ParseStack_t X509ParseStack()
XrdCryptoX509ParseBucket_t X509ParseBucket()
XrdCryptoKDFunLen_t KDFunLen()
XrdCryptoX509Req * X509Req(XrdSutBucket *bck)
XrdCryptoX509CheckProxy3_t X509CheckProxy3()
XrdCryptoX509 * X509(const char *cf, const char *kf=0)
XrdCryptoX509Crl * X509Crl(const char *crlfile, int opt=0)
XrdCryptoCipher * Cipher(const char *t, int l=0)
XrdCryptoProxyCertInfo_t ProxyCertInfo()
XrdCryptoRSA * RSA(int bits=XrdCryptoDefRSABits, int exp=XrdCryptoDefRSAExp)
static bool IsSupported(const char *dgst)
static char * GetBuffer(int len, int opt=-1)
static const char * Init()