-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdSecProtocolgsi.cc
5508 lines (5045 loc) · 181 KB
/
XrdSecProtocolgsi.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************/
/* */
/* X r d S e c P r o t o c o l g s i . c c */
/* */
/* (c) 2005 G. Ganis / CERN */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/* */
/******************************************************************************/
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <strings.h>
#include <stdio.h>
#include <sys/param.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include "XrdVersion.hh"
#include "XrdNet/XrdNetAddr.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysLogger.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdOuc/XrdOucPinLoader.hh"
#include "XrdOuc/XrdOucStream.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdSut/XrdSutAux.hh"
#include "XrdCrypto/XrdCryptoMsgDigest.hh"
#include "XrdCrypto/XrdCryptoX509Chain.hh"
#include "XrdCrypto/XrdCryptoX509Req.hh"
#include "XrdSecgsi/XrdSecProtocolgsi.hh"
/******************************************************************************/
/* T r a c i n g I n i t O p t i o n s */
/******************************************************************************/
#ifndef NODEBUG
#define POPTS(t,y) {if (t) {t->Beg(epname); cerr <<y; t->End();}}
#else
#define POPTS(t,y)
#endif
/******************************************************************************/
/* S t a t i c D a t a */
/******************************************************************************/
static String Prefix = "xrd";
static String ProtoID = XrdSecPROTOIDENT;
static const kXR_int32 Version = XrdSecgsiVERSION;
static const char *gsiClientSteps[] = {
"kXGC_none",
"kXGC_certreq",
"kXGC_cert",
"kXGC_reserved"
};
static const char *gsiServerSteps[] = {
"kXGS_none",
"kXGS_init",
"kXGS_cert",
"kXGS_reserved"
};
static const char *gGSErrStr[] = {
"ErrParseBuffer", // 10000
"ErrDecodeBuffer", // 10001
"ErrLoadCrypto", // 10002
"ErrBadProtocol", // 10003
"ErrCreateBucket", // 10004
"ErrDuplicateBucket", // 10005
"ErrCreateBuffer", // 10006
"ErrSerialBuffer", // 10007
"ErrGenCipher", // 10008
"ErrExportPuK", // 10009
"ErrEncRndmTag", // 10010
"ErrBadRndmTag", // 10011
"ErrNoRndmTag", // 10012
"ErrNoCipher", // 10013
"ErrNoCreds", // 10014
"ErrBadOpt", // 10015
"ErrMarshal", // 10016
"ErrUnmarshal", // 10017
"ErrSaveCreds", // 10018
"ErrNoBuffer", // 10019
"ErrRefCipher", // 10020
"ErrNoPublic", // 10021
"ErrAddBucket", // 10022
"ErrFinCipher", // 10023
"ErrInit", // 10024
"ErrBadCreds", // 10025
"ErrError" // 10026
};
// One day in secs
static const int kOneDay = 86400;
static const char *gUsrPxyDef = "/tmp/x509up_u";
/******************************************************************************/
/* S t a t i c C l a s s D a t a */
/******************************************************************************/
XrdSysMutex XrdSecProtocolgsi::gsiContext;
String XrdSecProtocolgsi::CAdir = "/etc/grid-security/certificates/";
String XrdSecProtocolgsi::CRLdir = "/etc/grid-security/certificates/";
String XrdSecProtocolgsi::DefCRLext= ".r0";
String XrdSecProtocolgsi::GMAPFile = "/etc/grid-security/grid-mapfile";
String XrdSecProtocolgsi::SrvCert = "/etc/grid-security/xrd/xrdcert.pem";
String XrdSecProtocolgsi::SrvKey = "/etc/grid-security/xrd/xrdkey.pem";
String XrdSecProtocolgsi::UsrProxy;
String XrdSecProtocolgsi::UsrCert = "/.globus/usercert.pem";
String XrdSecProtocolgsi::UsrKey = "/.globus/userkey.pem";
String XrdSecProtocolgsi::PxyValid = "12:00";
int XrdSecProtocolgsi::DepLength= 0;
int XrdSecProtocolgsi::DefBits = 512;
int XrdSecProtocolgsi::CACheck = 1;
int XrdSecProtocolgsi::CRLCheck = 1;
int XrdSecProtocolgsi::CRLDownload = 0;
int XrdSecProtocolgsi::CRLRefresh = 86400;
int XrdSecProtocolgsi::GMAPOpt = 1;
bool XrdSecProtocolgsi::GMAPuseDNname = 0;
String XrdSecProtocolgsi::DefCrypto= "ssl";
String XrdSecProtocolgsi::DefCipher= "aes-128-cbc:bf-cbc:des-ede3-cbc";
String XrdSecProtocolgsi::DefMD = "sha1:md5";
String XrdSecProtocolgsi::DefError = "invalid credentials ";
int XrdSecProtocolgsi::PxyReqOpts = 0;
int XrdSecProtocolgsi::AuthzPxyWhat = -1;
int XrdSecProtocolgsi::AuthzPxyWhere = -1;
XrdSecgsiGMAP_t XrdSecProtocolgsi::GMAPFun = 0;
XrdSecgsiAuthz_t XrdSecProtocolgsi::AuthzFun = 0;
XrdSecgsiAuthzKey_t XrdSecProtocolgsi::AuthzKey = 0;
int XrdSecProtocolgsi::AuthzCertFmt = -1;
int XrdSecProtocolgsi::GMAPCacheTimeOut = -1;
int XrdSecProtocolgsi::AuthzCacheTimeOut = 43200; // 12h, default
String XrdSecProtocolgsi::SrvAllowedNames;
int XrdSecProtocolgsi::VOMSAttrOpt = 1;
XrdSecgsiAuthz_t XrdSecProtocolgsi::VOMSFun = 0;
int XrdSecProtocolgsi::VOMSCertFmt = -1;
int XrdSecProtocolgsi::MonInfoOpt = 0;
bool XrdSecProtocolgsi::HashCompatibility = 1;
bool XrdSecProtocolgsi::TrustDNS = true;
//
// Crypto related info
int XrdSecProtocolgsi::ncrypt = 0; // Number of factories
XrdCryptoFactory *XrdSecProtocolgsi::cryptF[XrdCryptoMax] = {0}; // their hooks
int XrdSecProtocolgsi::cryptID[XrdCryptoMax] = {0}; // their IDs
String XrdSecProtocolgsi::cryptName[XrdCryptoMax] = {0}; // their names
XrdCryptoCipher *XrdSecProtocolgsi::refcip[XrdCryptoMax] = {0}; // ref for session ciphers
//
// Caches
XrdSutCache XrdSecProtocolgsi::cacheCA; // Server certificates info cache (default size 144)
XrdSutCache XrdSecProtocolgsi::cacheCert(8,13); // Server certificates info cache (Fibonacci-based sizes)
XrdSutCache XrdSecProtocolgsi::cachePxy(8,13); // Client proxies cache (Fibonacci-based sizes)
XrdSutCache XrdSecProtocolgsi::cacheGMAPFun; // Entries mapped by GMAPFun (default size 144)
XrdSutCache XrdSecProtocolgsi::cacheAuthzFun; // Entities filled by AuthzFun (default size 144)
//
// Services
XrdOucGMap *XrdSecProtocolgsi::servGMap = 0; // Grid map service
//
// CA and CRL stacks
GSIStack<XrdCryptoX509Chain> XrdSecProtocolgsi::stackCA; // Stack of CA in use
GSIStack<XrdCryptoX509Crl> XrdSecProtocolgsi::stackCRL; // Stack of CRL in use
//
// GMAP control vars
time_t XrdSecProtocolgsi::lastGMAPCheck = -1; // Time of last check
XrdSysMutex XrdSecProtocolgsi::mutexGMAP; // Mutex to control GMAP reloads
//
// Running options / settings
int XrdSecProtocolgsi::Debug = 0; // [CS] Debug level
bool XrdSecProtocolgsi::Server = 1; // [CS] If server mode
int XrdSecProtocolgsi::TimeSkew = 300; // [CS] Allowed skew in secs for time stamps
//
// Debug an tracing
XrdSysError XrdSecProtocolgsi::eDest(0, "secgsi_");
XrdSysLogger XrdSecProtocolgsi::Logger;
XrdOucTrace *XrdSecProtocolgsi::GSITrace = 0;
XrdOucTrace *gsiTrace = 0;
/******************************************************************************/
/* S t a t i c F u n c t i o n s */
/******************************************************************************/
//_____________________________________________________________________________
static const char *ClientStepStr(int kclt)
{
// Return string with client step
static const char *ukn = "Unknown";
kclt = (kclt < 0) ? 0 : kclt;
kclt = (kclt > kXGC_reserved) ? 0 : kclt;
kclt = (kclt >= kXGC_certreq) ? (kclt - kXGC_certreq + 1) : kclt;
if (kclt < 0 || kclt > (kXGC_reserved - kXGC_certreq + 1))
return ukn;
else
return gsiClientSteps[kclt];
}
//_____________________________________________________________________________
static const char *ServerStepStr(int ksrv)
{
// Return string with server step
static const char *ukn = "Unknown";
ksrv = (ksrv < 0) ? 0 : ksrv;
ksrv = (ksrv > kXGS_reserved) ? 0 : ksrv;
ksrv = (ksrv >= kXGS_init) ? (ksrv - kXGS_init + 1) : ksrv;
if (ksrv < 0 || ksrv > (kXGS_reserved - kXGS_init + 1))
return ukn;
else
return gsiServerSteps[ksrv];
}
/******************************************************************************/
/* D u m p o f H a n d s h a k e v a r i a b l e s */
/******************************************************************************/
//_____________________________________________________________________________
void gsiHSVars::Dump(XrdSecProtocolgsi *p)
{
// Dump content
EPNAME("HSVars::Dump");
PRINT("----------------------------------------------------------------");
PRINT("protocol instance: "<<p);
PRINT("this: "<<this);
PRINT(" ");
PRINT("Time stamp: "<<TimeStamp);
PRINT("Crypto mod: "<<CryptoMod);
PRINT("Remote version: "<<RemVers);
PRINT("Ref cipher: "<<Rcip);
PRINT("Bucket for exp cert: "<<Cbck);
PRINT("Handshake ID: "<<ID);
PRINT("Cache reference: "<<Cref);
PRINT("Relevant file entry: "<<Pent);
PRINT("Chain pointer: "<<Chain);
PRINT("CRL pointer: "<<Crl);
PRINT("Proxy chain: "<<PxyChain);
PRINT("Rndm tag checked: "<<RtagOK);
PRINT("Last step: "<<LastStep);
PRINT("Options: "<<Options);
PRINT("----------------------------------------------------------------");
}
/******************************************************************************/
/* P r o t o c o l I n i t i a l i z a t i o n M e t h o d s */
/******************************************************************************/
//_____________________________________________________________________________
XrdSecProtocolgsi::XrdSecProtocolgsi(int opts, const char *hname,
XrdNetAddrInfo &endPoint,
const char *parms) : XrdSecProtocol("gsi")
{
// Default constructor
EPNAME("XrdSecProtocolgsi");
if (QTRACE(Authen)) { PRINT("constructing: "<<this); }
// Create instance of the handshake vars
if ((hs = new gsiHSVars())) {
// Update time stamp
hs->TimeStamp = time(0);
// Local handshake variables
hs->Tty = (isatty(0) == 0 || isatty(1) == 0) ? 0 : 1;
} else {
PRINT("could not create handshake vars object");
}
// Set host name and address
// The hostname is critical for the GSI protocol; it must match the potential
// names on the remote EEC. We default to the hostname requested by the user to
// the client (or proxy). However, as we may have been redirected to an IP
// address instead of an actual hostname, we must fallback to a reverse DNS lookup.
// As of time of testing (June 2018), EOS will redirect to an IP address to handle
// metadata commands and rely on the reverse DNS lookup for GSI security to function.
// Hence, this fallback likely needs to be kept for some time.
//
// We provide servers a switch and clients an environment variable to override all
// usage of DNS (processed on XrdSecProtocolgsiInit).
// Default is to fallback to DNS lookups in limited
// cases for backward compatibility.
if (TrustDNS) {
if (!hname || !XrdNetAddrInfo::isHostName(hname)) {
Entity.host = strdup(endPoint.Name(""));
} else {
// At this point, hname still may possibly be a non-qualified domain name.
// If there is a '.' character, then we assume it is a qualified domain name --
// otherwise, we use DNS.
//
// NOTE: We can definitively test whether this is a qualified domain name by
// simply appending a '.' to `hname` and performing a lookup. However, this
// causes DNS to be used by every lookup - meaning we rely on the security
// of DNS for all cases; we want to avoid this.
if (strchr(hname, '.')) {
// We have a valid hostname; proceed.
Entity.host = strdup(hname);
} else {
XrdNetAddr xrd_addr;
char canonname[256];
if (!xrd_addr.Set(hname) || (xrd_addr.Format(canonname, 256, XrdNetAddrInfo::fmtName, XrdNetAddrInfo::noPort) <= 0)) {
Entity.host = strdup(hname);
} else {
Entity.host = strdup(canonname);
}
}
}
} else {
// We have been told via environment variable to not trust DNS; use the exact
// hostname provided by the user.
Entity.host = strdup(hname);
}
epAddr = endPoint;
Entity.addrInfo = &epAddr;
// Init session variables
sessionCF = 0;
sessionKey = 0;
bucketKey = 0;
sessionMD = 0;
sessionKsig = 0;
sessionKver = 0;
sessionKver = 0;
proxyChain = 0;
//
// Notify, if required
DEBUG("constructing: host: "<< Entity.host);
DEBUG("p: "<<XrdSecPROTOIDENT<<", plen: "<<XrdSecPROTOIDLEN);
//
// basic settings
options = opts;
srvMode = 0;
//
// Mode specific initializations
if (Server) {
srvMode = 1;
DEBUG("mode: server");
} else {
DEBUG("mode: client");
//
// Decode received buffer
if (parms) {
XrdOucString p("&P=gsi,");
p += parms;
hs->Parms = new XrdSutBuffer(p.c_str(), p.length());
}
}
// We are done
String vers = Version;
vers.insert('.',vers.length()-2);
vers.insert('.',vers.length()-5);
DEBUG("object created: v"<<vers.c_str());
}
//_____________________________________________________________________________
char *XrdSecProtocolgsi::Init(gsiOptions opt, XrdOucErrInfo *erp)
{
// Static method to the configure the static part of the protocol
// Called once by XrdSecProtocolgsiInit
EPNAME("Init");
char *Parms = 0;
//
// Debug an tracing
Debug = (opt.debug > -1) ? opt.debug : Debug;
// We must have the tracing object at this point
// (initialized in XrdSecProtocolgsiInit)
if (!gsiTrace) {
ErrF(erp,kGSErrInit,"tracing object (gsiTrace) not initialized! cannot continue");
return Parms;
}
// Set debug mask ... also for auxilliary libs
int trace = 0, traceSut = 0, traceCrypto = 0;
if (Debug >= 3) {
trace = cryptoTRACE_Dump;
traceSut = sutTRACE_Dump;
traceCrypto = cryptoTRACE_Dump;
GSITrace->What = TRACE_ALL;
} else if (Debug >= 2) {
trace = cryptoTRACE_Debug;
traceSut = sutTRACE_Debug;
traceCrypto = cryptoTRACE_Debug;
GSITrace->What = TRACE_Debug;
GSITrace->What |= TRACE_Authen;
} else if (Debug >= 1) {
trace = cryptoTRACE_Debug;
traceSut = sutTRACE_Notify;
traceCrypto = cryptoTRACE_Notify;
GSITrace->What = TRACE_Debug;
}
// ... also for auxilliary libs
XrdSutSetTrace(traceSut);
XrdCryptoSetTrace(traceCrypto);
// Name hashing algorithm compatibility
if (opt.hashcomp == 0) HashCompatibility = 0;
//
// Operation mode
Server = (opt.mode == 's');
//
// CA verification level
//
// 0 do not verify
// 1 verify if self-signed; warn if not
// 2 verify in all cases; fail if not possible
//
if (opt.ca >= 0 && opt.ca <= 2)
CACheck = opt.ca;
DEBUG("option CACheck: "<<CACheck);
//
// Check existence of CA directory
struct stat st;
if (opt.certdir) {
DEBUG("testing CA dir(s): "<<opt.certdir);
String CAtmp;
String tmp = opt.certdir;
String dp;
int from = 0;
while ((from = tmp.tokenize(dp, from, ',')) != -1) {
if (dp.length() > 0) {
if (XrdSutExpand(dp) == 0) {
if (stat(dp.c_str(),&st) == -1) {
if (errno == ENOENT) {
ErrF(erp,kGSErrError,"CA directory non existing:",dp.c_str());
PRINT(erp->getErrText());
} else {
ErrF(erp,kGSErrError,"cannot stat CA directory:",dp.c_str());
PRINT(erp->getErrText());
}
} else {
if (!(dp.endswith('/'))) dp += '/';
if (!(CAtmp.endswith(','))) CAtmp += ',';
CAtmp += dp;
}
} else {
PRINT("Warning: could not expand: "<<dp);
}
}
}
if (CAtmp.length() > 0)
CAdir = CAtmp;
}
DEBUG("using CA dir(s): "<<CAdir);
//
// CRL check level
//
// 0 do not care
// 1 use if available
// 2 require
// 3 require not expired
// 12 require; try download if missing
// 13 require not expired; try download if missing
//
const char *cocrl[] = { "do-not-care", "use-if-available", "require", "require-not-expired" };
const char *codwld[] = { "no", "yes"};
if (opt.crl >= 10) {
CRLDownload = 1;
opt.crl %= 10;
}
if (opt.crl >= 0 && opt.crl <= 3)
CRLCheck = opt.crl;
DEBUG("option CRLCheck: "<<CRLCheck<<" ('"<<cocrl[CRLCheck]<<"'; download? "<<
codwld[CRLDownload]<<")");
//
// Check existence of CRL directory
if (opt.crldir) {
DEBUG("testing CRL dir(s): "<<opt.crldir);
String CRLtmp;
String tmp = opt.crldir;
String dp;
int from = 0;
while ((from = tmp.tokenize(dp, from, ',')) != -1) {
if (dp.length() > 0) {
if (XrdSutExpand(dp) == 0) {
if (stat(dp.c_str(),&st) == -1) {
if (errno == ENOENT) {
ErrF(erp,kGSErrError,"CRL directory non existing:",dp.c_str());
PRINT(erp->getErrText());
} else {
ErrF(erp,kGSErrError,"cannot stat CRL directory:",dp.c_str());
PRINT(erp->getErrText());
}
} else {
if (!(dp.endswith('/'))) dp += '/';
if (!(CRLtmp.endswith(','))) CRLtmp += ',';
CRLtmp += dp;
}
} else {
PRINT("Warning: could not expand: "<<dp);
}
}
}
if (CRLtmp.length() > 0)
CRLdir = CRLtmp;
} else {
// Use CAdir
CRLdir = CAdir;
}
if (CRLCheck > 0)
DEBUG("using CRL dir(s): "<<CRLdir);
//
// Default extension for CRL files
if (opt.crlext)
DefCRLext = opt.crlext;
//
// Refresh or expiration time for CRLs
if (opt.crlrefresh)
CRLRefresh = opt.crlrefresh;
DEBUG("CRL information refreshed every "<<CRLRefresh<<" secs");
//
// Server specific options
if (Server) {
//
// List of supported / wanted crypto modules
if (opt.clist)
DefCrypto = opt.clist;
//
// List of crypto modules
String cryptlist(DefCrypto,0,-1,64);
//
// Load crypto modules
XrdSutPFEntry ent;
XrdCryptoFactory *cf = 0;
if (cryptlist.length()) {
String ncpt = "";
int from = 0;
while ((from = cryptlist.tokenize(ncpt, from, '|')) != -1) {
if (ncpt.length() > 0 && ncpt[0] != '-') {
// Try loading
if ((cf = XrdCryptoFactory::GetCryptoFactory(ncpt.c_str()))) {
// Add it to the list
cryptF[ncrypt] = cf;
cryptID[ncrypt] = cf->ID();
cryptName[ncrypt].insert(cf->Name(),0,strlen(cf->Name())+1);
cf->SetTrace(trace);
cf->Notify();
// Ref cipher
if (!(refcip[ncrypt] = cf->Cipher(0,0,0))) {
PRINT("ref cipher for module "<<ncpt<<
" cannot be instantiated : disable");
from -= ncpt.length();
cryptlist.erase(ncpt);
} else {
ncrypt++;
if (ncrypt >= XrdCryptoMax) {
PRINT("max number of crypto modules ("
<< XrdCryptoMax <<") reached ");
break;
}
}
} else {
PRINT("cannot instantiate crypto factory "<<ncpt<<
": disable");
from -= ncpt.length();
cryptlist.erase(ncpt);
}
}
}
}
//
// We need at least one valid crypto module
if (ncrypt <= 0) {
ErrF(erp,kGSErrInit,"could not find any valid crypto module");
PRINT(erp->getErrText());
return Parms;
}
//
// List of supported / wanted ciphers
if (opt.cipher)
DefCipher = opt.cipher;
// make sure we support all of them
String cip = "";
int from = 0;
while ((from = DefCipher.tokenize(cip, from, ':')) != -1) {
if (cip.length() > 0) {
int i = 0;
for (; i < ncrypt; i++) {
if (!(cryptF[i]->SupportedCipher(cip.c_str()))) {
// Not supported: drop from the list
DEBUG("cipher type not supported ("<<cip<<") - disabling");
from -= cip.length();
DefCipher.erase(cip);
}
}
}
}
//
// List of supported / wanted Message Digest
if (opt.md)
DefMD = opt.md;
// make sure we support all of them
String md = "";
from = 0;
while ((from = DefMD.tokenize(md, from, ':')) != -1) {
if (md.length() > 0) {
int i = 0;
for (; i < ncrypt; i++) {
if (!(cryptF[i]->SupportedMsgDigest(md.c_str()))) {
// Not supported: drop from the list
PRINT("MD type not supported ("<<md<<") - disabling");
from -= md.length();
DefMD.erase(md);
}
}
}
}
//
// Load server certificate and key
if (opt.cert) {
String TmpCert = opt.cert;
if (XrdSutExpand(TmpCert) == 0) {
SrvCert = TmpCert;
} else {
PRINT("Could not expand: "<<opt.cert<<": use default");
}
}
if (opt.key) {
String TmpKey = opt.key;
if (XrdSutExpand(TmpKey) == 0) {
SrvKey = TmpKey;
} else {
PRINT("Could not expand: "<<opt.key<<": use default");
}
}
//
// Check if we can read the certificate key
if (access(SrvKey.c_str(), R_OK)) {
PRINT("WARNING: process has no permission to read the certificate key file: "<<SrvKey);
}
int i = 0;
String certcalist = ""; // list of CA for server certificates
XrdSutCERef ceref;
for (; i<ncrypt; i++) {
if (!GetSrvCertEnt(ceref, cryptF[i], time(0), certcalist)) {
PRINT("problems loading srv cert");
ceref.UnLock();
continue;
}
}
// Rehash cache
ceref.UnLock();
//
// We must have got at least one valid certificate
if (cacheCert.Num() <= 0) {
ErrF(erp,kGSErrError,"no valid server certificate found");
PRINT(erp->getErrText());
return Parms;
}
DEBUG("CA list: "<<certcalist);
//
// GRID map check option
//
// 0 do not use (DN hash will be used as identifier)
// 1 use if available; otherwise as 0
// 2 require
// 10 do not use (DN name will be used as identifier)
// 11 use if available; otherwise as 10
const char *cogmap[] = { "do-not-use", "use-if-available", "require" };
const char *codnnm[] = { "DN hash", "DN name"};
if (opt.ogmap >= 10) {
GMAPuseDNname = 1;
opt.ogmap %= 10;
}
if (opt.ogmap >= 0 && opt.ogmap <= 2)
GMAPOpt = opt.ogmap;
DEBUG("user mapping file option: "<<cogmap[GMAPOpt]);
if (GMAPOpt < 2)
DEBUG("default option for entity name if no mapping available: "<<codnnm[(int)GMAPuseDNname]);
//
// Check existence of GRID map file
if (opt.gridmap) {
String GMAPTmp = opt.gridmap;
if (XrdSutExpand(GMAPTmp) == 0) {
GMAPFile = GMAPTmp;
} else {
PRINT("Could not expand: "<<opt.gridmap<<": use default");
}
}
bool hasgmap = 0;
if (GMAPOpt > 0) {
// Initialize the GMap service
//
String pars;
if (Debug) pars += "dbg|";
if (opt.gmapto > 0) { pars += "to="; pars += (int)opt.gmapto; }
if (!(servGMap = XrdOucgetGMap(&eDest, GMAPFile.c_str(), pars.c_str()))) {
if (GMAPOpt > 1) {
ErrF(erp,kGSErrError,"error loading grid map file:",GMAPFile.c_str());
PRINT(erp->getErrText());
return Parms;
} else {
NOTIFY("Grid map file: "<<GMAPFile<<" cannot be 'access'ed: do not use");
}
} else {
DEBUG("using grid map file: "<<GMAPFile);
hasgmap = 1;
}
}
//
// Load function be used to map DN to usernames, if specified
bool hasgmapfun = 0;
if (opt.gmapfun && GMAPOpt > 0) {
if (!(GMAPFun = LoadGMAPFun((const char *) opt.gmapfun,
(const char *) opt.gmapfunparms))) {
ErrF(erp, kGSErrError, "GMAP plug-in could not be loaded", opt.gmapfun);
PRINT(erp->getErrText());
return Parms;
} else {
hasgmapfun = 1;
}
}
//
// Disable GMAP if neither a grid mapfile nor a GMAP function are available
if (!hasgmap && !hasgmapfun) {
if (GMAPOpt > 1) {
ErrF(erp,kGSErrError,"User mapping required, but neither a grid mapfile"
" nor a mapping function are available");
PRINT(erp->getErrText());
return Parms;
}
GMAPOpt = 0;
}
//
// Authorization function
bool hasauthzfun = 0;
if (opt.authzfun) {
if (!(AuthzFun = LoadAuthzFun((const char *) opt.authzfun,
(const char *) opt.authzfunparms, AuthzCertFmt))) {
ErrF(erp, kGSErrError, "Authz plug-in could not be loaded", opt.authzfun);
PRINT(erp->getErrText());
return Parms;
} else {
hasauthzfun = 1;
// Notify certificate format
if (AuthzCertFmt >= 0 && AuthzCertFmt <= 1) {
const char *ccfmt[] = { "raw", "PEM base64" };
DEBUG("authzfun: proxy certificate format: "<<ccfmt[AuthzCertFmt]);
} else {
NOTIFY("authzfun: proxy certificate format: unknown (code: "<<AuthzCertFmt<<")");
}
// Expiration of Authz related cache entries
if (opt.authzto > 0) {
AuthzCacheTimeOut = opt.authzto;
DEBUG("grid-map cache entries expire after "<<AuthzCacheTimeOut<<" secs");
}
}
}
//
// Expiration of GRIDMAP related cache entries
if (GMAPOpt > 0 && !hasauthzfun && opt.gmapto > 0) {
GMAPCacheTimeOut = opt.gmapto;
DEBUG("grid-map cache entries expire after "<<GMAPCacheTimeOut<<" secs");
}
//
// Request for proxy export for authorization
// authzpxy = opt_what*10 + opt_where
// opt_what = 0 full chain
// 1 last proxy only
// opt_where = 1 Entity.creds
// 2 Entity.endorsements
if (opt.authzpxy > 0) {
AuthzPxyWhat = opt.authzpxy / 10;
AuthzPxyWhere = opt.authzpxy % 10;
// Some notification
const char *capxy_what = (AuthzPxyWhat == 1) ? "'last proxy only'"
: "'full proxy chain'";
const char *capxy_where = (AuthzPxyWhere == 1) ? "XrdSecEntity.creds"
: "XrdSecEntity.endorsements";
DEBUG("Export proxy for authorization in '"<<capxy_where<<"': "<<capxy_what);
if (hasauthzfun) {
// Warn user about possible overwriting of Entity.creds or Entity.endorsements
PRINT("WARNING: proxy export for authz enabled: be aware that any setting of '"<<capxy_what<<
"' done by '"<<opt.authzfun<<"' will get overwritten with "<<capxy_what);
}
}
//
// Handle delegated proxies options
if (opt.dlgpxy == -1) {
// Will not accept any delegated proxies
DEBUG("Will not accept delegated proxies");
} else {
// Ask the client to sign a delegated proxy; client may decide to forward its proxy
if (opt.dlgpxy == 1)
PxyReqOpts |= kOptsSrvReq;
// Exporting options (default none: delegated proxy kept in memory, in proxyChain)
if (opt.exppxy) {
if (!strcmp(opt.exppxy, "=creds")) {
// register the delegated proxy in Entity.creds (in HEX format)
PxyReqOpts |= kOptsPxCred;
DEBUG("Delegated proxy saved in Entity.creds ");
} else {
String TmpProxy = gUsrPxyDef;
if (strcmp(opt.exppxy, "=default"))
TmpProxy = opt.exppxy;
if (XrdSutExpand(TmpProxy) == 0) {
UsrProxy = TmpProxy;
} else {
UsrProxy = gUsrPxyDef;
UsrProxy += "u<uid>";
}
DEBUG("File template for delegated proxy: "<<UsrProxy);
}
}
DEBUG("Delegated proxies options: "<<PxyReqOpts);
}
//
// VOMS attributes switch
// vomsat = 0 do not look for
// 1 extract if any (fill 'vorg', 'role'; the full string in 'endorsements');
// 2 require (fill 'vorg', 'role'; the full string in 'endorsements');
VOMSAttrOpt = (opt.vomsat <= 2 && opt.vomsat >= 0) ? opt.vomsat : VOMSAttrOpt;
//
// Alternative VOMS extraction function
if (opt.vomsfun) {
if (!(VOMSFun = LoadVOMSFun((const char *) opt.vomsfun,
(const char *) opt.vomsfunparms, VOMSCertFmt))) {
ErrF(erp, kGSErrError, "VOMS plug-in could not be loaded", opt.vomsfun);
PRINT(erp->getErrText());
return Parms;
} else {
// We at least check VOMS attributes if we have a function ...
if (VOMSAttrOpt < 1) VOMSAttrOpt = 1;
// Notify certificate format
if (VOMSCertFmt >= 0 && VOMSCertFmt <= 1) {
const char *ccfmt[] = { "raw", "PEM base64" };
DEBUG("vomsfun: proxy certificate format: "<<ccfmt[VOMSCertFmt]);
} else {
NOTIFY("vomsfun: proxy certificate format: unknown (code: "<<VOMSCertFmt<<")");
}
}
}
const char *cvomsat[3] = { "ignore", "extract", "require" };
DEBUG("VOMS attributes options: "<<cvomsat[VOMSAttrOpt]);
//
// Default moninfo option
// 0 nothing
// 1 DN
MonInfoOpt = opt.moninfo;
const char *cmoninfo = (MonInfoOpt == 1) ? "DN" : "none";
DEBUG("Monitor information options: "<<cmoninfo);
//
// Parms in the form:
// &P=gsi,v:<version>,c:<cryptomod>,ca:<list_of_srv_cert_ca>
Parms = new char[cryptlist.length()+3+12+certcalist.length()+5];
if (Parms) {
sprintf(Parms,"v:%d,c:%s,ca:%s",
Version,cryptlist.c_str(),certcalist.c_str());
} else {
ErrF(erp,kGSErrInit,"no system resources for 'Parms'");
PRINT(erp->getErrText());
}
// Some notification
DEBUG("available crypto modules: "<<cryptlist);
DEBUG("issuer CAs of server certs (hashes): "<<certcalist);
}
//
// Client specific options
if (!Server) {
// use default dir $(HOME)/.<prefix>
struct passwd *pw = getpwuid(getuid());
if (!pw) {
NOTIFY("WARNING: cannot get user information (uid:"<<getuid()<<")");
}
//
// Define user proxy file
UsrProxy = gUsrPxyDef;
if (opt.proxy) {
String TmpProxy = opt.proxy;
if (XrdSutExpand(TmpProxy) == 0) {
UsrProxy = TmpProxy;
} else {
PRINT("Could not expand: "<<opt.proxy<<": use default");
}
} else {
if (pw)
UsrProxy += (int)(pw->pw_uid);
}
// Define user certificate file
if (opt.cert) {
String TmpCert = opt.cert;
if (XrdSutExpand(TmpCert) == 0) {
UsrCert = TmpCert;
} else {
PRINT("Could not expand: "<<opt.cert<<": use default");
}
} else {
if (pw)
UsrCert.insert(XrdSutHome(),0);
}
// Define user private key file
if (opt.key) {
String TmpKey = opt.key;
if (XrdSutExpand(TmpKey) == 0) {
UsrKey = TmpKey;
} else {
PRINT("Could not expand: "<<opt.key<<": use default");
}
} else {
if (pw)
UsrKey.insert(XrdSutHome(),0);
}
// Define proxy validity at renewal
if (opt.valid)
PxyValid = opt.valid;
// Set depth of signature path
if (opt.deplen != DepLength)
DepLength = opt.deplen;
// Set number of bits for proxy key
if (opt.bits > DefBits)
DefBits = opt.bits;
//
// Delegate proxy options
if (opt.dlgpxy > 0) {
PxyReqOpts |= kOptsSigReq;
if (opt.dlgpxy == 2) {
PxyReqOpts |= kOptsFwdPxy;
} else {
PxyReqOpts |= kOptsDlgPxy;
}
}
//
// Define valid CNs for the server certificates; default is null, which means that
// the server CN must be in the form "*/<hostname>"
if (opt.srvnames)
SrvAllowedNames = opt.srvnames;
//
// Notify
TRACE(Authen, "using certificate file: "<<UsrCert);
TRACE(Authen, "using private key file: "<<UsrKey);
TRACE(Authen, "proxy: file: "<<UsrProxy);
TRACE(Authen, "proxy: validity: "<<PxyValid);
TRACE(Authen, "proxy: depth of signature path: "<<DepLength);
TRACE(Authen, "proxy: bits in key: "<<DefBits);
TRACE(Authen, "server cert: allowed names: "<<SrvAllowedNames);
// We are done
Parms = (char *)"";
}
// We are done
return Parms;
}