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
|
variable LOGOUTS
variable REPORTDIR
variable INSTALLDIR
variable SCRATCHDIR
variable CADIR
variable _initted
variable _logdescriptor
variable _cadir
variable _capath
variable _certdir
variable _vomsdir
proc _cleanproxy {} {
set filename "/tmp/x509up_u[exec id -u]"
file delete $filename
}
proc _proxyname {} {
return "/tmp/x509up_u[exec id -u]"
}
proc _activateCert {cert} {
file mkdir $::env(HOME)/.globus2
file copy -force "$::_certdir/$cert-cert.pem" $::env(HOME)/.globus2/usercert.pem
file copy -force "$::_certdir/$cert-key.pem" $::env(HOME)/.globus2/userkey.pem
exec chmod 644 $::env(HOME)/.globus2/usercert.pem
exec chmod 400 $::env(HOME)/.globus2/userkey.pem
}
proc _activateHostCertificate {cert} {
file mkdir $::INSTALLDIR/certs
file copy -force "$::_certdir/$cert-cert.pem" $::INSTALLDIR/certs/hostcert.pem
file copy -force "$::_certdir/$cert-key.pem" $::INSTALLDIR/certs/hostkey.pem
exec chmod 644 $::INSTALLDIR/certs/hostcert.pem
exec chmod 400 $::INSTALLDIR/certs/hostkey.pem
}
proc _getcert {cert} {
return "$::_certdir/$cert-cert.pem"
}
proc _getkey {cert} {
return "$::_certdir/$cert-key.pem"
}
proc _getdn {cert} {
regexp {subject= (.*)} [exec openssl x509 -subject -noout -in [_getcert $cert]] dummy value
return $value
}
proc _getdnfile {cert} {
regexp {subject= (.*)} [exec openssl x509 -subject -noout -in $cert] dummy value
return $value
}
proc _getca {cert} {
regexp {issuer= (.*)} [exec openssl x509 -issuer -noout -in [_getcert $cert]] dummy value
return $value
}
proc _revoke_cert { cert name } {
exec openssl ca -config $::_capath/$name/$name.cnf -revoke $::_certdir/$cert-cert.pem -batch 2>/dev/null
}
proc _do_ca_dir_setup {} {
set ::_cadir $::ETC_DIR/grid-security/certificates
set ::_capath $::INSTALLDIR/ca
set ::_certdir $::INSTALLDIR/certs
catch { file delete -force $::_capath }
catch { file delete -force $::_cadir }
catch { file delete -force $::_certdir }
file mkdir $::_capath
file mkdir $::_cadir
file mkdir $::_certdir
set ::CADIR ::_cadir
}
proc _make_crl { ca } {
exec openssl ca -gencrl -config $::_capath/$ca/$ca.cnf -out $::_capath/$ca/$ca.crl 2>/dev/null
# some versions of openssl are buggy and return 1 in case of CRL hash success.
# so we get the hashname from the corresponding CA certificate
set hashname [exec openssl x509 -hash -noout -in $::_capath/$ca/cacert.pem ]
file copy -force $::_capath/$ca/$ca.crl $::_cadir/$hashname.r0
}
proc _make_ca { dn name len { day 365 } {condsubject "" }} {
if [expr ![file exists "$::_capath/$name"]] then {
file mkdir $::_capath/$name
file mkdir $::_capath/$name/private
if [string equal $len "-1"] then {
_ca_make_config $dn $name "$::_capath/$name" ""
} else {
_ca_make_config $dn $name "$::_capath/$name" $len
}
exec touch $::_capath/$name/index.txt
set id [open "$::_capath/$name/serial" w+]
puts $id "00"
flush $id
close $id
exec openssl req -config $::_capath/$name/$name.cnf -new -x509 -nodes -keyout $::_capath/$name/certkey.pem -out $::_capath/$name/cacertreq.pem -batch 2>/dev/null
file copy $::_capath/$name/cacertreq.pem $::_capath/$name/cacert.pem
if [expr $day < 0] then {
set seconds [clock scan [exec date -u]]
set expireddate [clock format [expr $seconds + (86400 * $day)] -format "%y%m%d%H%M%SZ" ]
set startdate [clock format [expr $seconds + (86400 * ($day - 1))] -format "%y%m%d%H%M%SZ" ]
exec openssl ca -config $::_capath/$name/$name.cnf -startdate "$startdate" -enddate "$expireddate" -ss_cert $::_capath/$name/cacertreq.pem -extensions usrca_cert -out $::_capath/$name/cacert.pem -batch 2>/dev/null
} else {
exec openssl ca -config $::_capath/$name/$name.cnf -days $day -ss_cert $::_capath/$name/cacertreq.pem -extensions usrca_cert -out $::_capath/$name/cacert.pem -batch 2>/dev/null
}
set hashname [exec openssl x509 -hash -noout -in $::_capath/$name/cacert.pem]
file copy -force $::_capath/$name/cacert.pem $::_cadir/$hashname.0
set dn [_getdnfile $::_cadir/$hashname.0]
set id [open "$::_cadir/$hashname.signing_policy" w+]
set out "/C=IT/*"
if {[string bytelength $condsubject]} then {
set out $condsubject
}
puts $id "access_id_CA X509 '$dn'
pos_rights globus CA:sign
cond_subjects globus '\"$out\"'"
flush $id
close $id
set id [open "$::_cadir/$hashname.namespaces" w+]
puts $id "TO ISSUER SELF PERMIT SUBJECT \"$out\""
flush $id
close $id
}
}
proc _make_ca_from_ca { dn fathername name len {day 365 } {condsubject ""}} {
if [expr ![file exists "$::_capath/$name"]] then {
file mkdir $::_capath/$name
file mkdir $::_capath/$name/private
_ca_make_config $dn $name "$::_capath/$name" ""
exec touch $::_capath/$name/index.txt
set id [open "$::_capath/$name/serial" w+]
puts $id "00"
flush $id
close $id
set id [open "$::_capath/$name/extfile" w+]
if [string equal $len "-1"] then {
puts $id "basicConstraints=CA:TRUE"
} else {
puts $id "basicConstraints=CA:TRUE,pathlen:$len"
}
puts $id "nsComment = \"OpenSSL Generated Certificate for VOMS testing purposes\""
puts $id "subjectKeyIdentifier=hash"
puts $id "authorityKeyIdentifier=keyid,issuer:always"
puts $id "keyUsage = critical, keyCertSign, cRLSign"
close $id
exec openssl req -config $::_capath/$fathername/$fathername.cnf -new -nodes -keyout $::_capath/$name/certkey.pem -subj "$dn" -out $::_capath/$name/careq.pem -extensions usrca_cert -batch 2>/dev/null
if [expr $day >= 0] then {
exec openssl ca -config $::_capath/$fathername/$fathername.cnf -days $day -policy policy_anything -days 2 -out $::_capath/$name/cacert.pem -in $::_capath/$name/careq.pem -extfile $::_capath/$name/extfile -batch 2>/dev/null
} else {
set seconds [clock scan [exec date -u]]
set expireddate [clock format [expr $seconds + (86400 * $day)] -format "%y%m%d%H%M%SZ" ]
set startdate [clock format [expr $seconds + (86400 * ($day - 1))] -format "%y%m%d%H%M%SZ" ]
exec openssl ca -config $::_capath/$fathername/$fathername.cnf -startdate "$startdate" -enddate "$expireddate" -policy policy_anything -days 2 -out $::_capath/$name/cacert.pem -in $::_capath/$name/careq.pem -extfile $::_capath/$name/extfile -batch 2>/dev/null
}
set hashname [exec openssl x509 -hash -noout -in $::_capath/$name/cacert.pem]
file copy -force $::_capath/$name/cacert.pem $::_cadir/$hashname.0
set dn [_getdnfile $::_cadir/$hashname.0]
set id [open "$::_cadir/$hashname.signing_policy" w+]
set out "/C=IT/*"
if {[string bytelength $condsubject]} then {
set out $consubject
}
puts $id "access_id_CA X509 '$dn'
pos_rights globus CA:sign
cond_subjects globus '\"$out\"'"
flush $id
close $id
set id [open "$::_cadir/$hashname.namespaces" w+]
puts $id "TO ISSUER \"$dn\" PERMIT SUBJECT \"$out\""
flush $id
close $id
file copy $::_capath/$name/cacert.pem $::_certdir/$name-cert.pem
file copy $::_capath/$name/certkey.pem $::_certdir/$name-key.pem
}
}
proc _protect_key { certname { password "password" } } {
exec openssl rsa -in $::_certdir/$certname-key.pem -out $::_certdir/$certname-key.pem -inform PEM -outform PEM -des3 -passout "pass:$password" 2>/dev/null
}
proc _make_cert_from_ca { dn name certname {day 2}} {
if [expr ![file exists "$::_capath/$name"]] then {
puts "CA $name does not exist!"
exit
}
if [expr ![file exists "$::_certdir"]] then {
file mkdir $::_certdir
}
exec openssl req -config $::_capath/$name/$name.cnf -new -nodes -keyout $::_certdir/$certname-key.pem -subj "$dn" -out $::_certdir/$certname-cert.req -batch 2>/dev/null
if [expr $day < 0 ] then {
set seconds [clock scan [exec date -u]]
set expireddate [clock format [expr $seconds + (86400 * $day)] -format "%y%m%d%H%M%SZ" ]
set startdate [clock format [expr $seconds + (86400 * ($day - 1))] -format "%y%m%d%H%M%SZ" ]
exec openssl ca -config $::_capath/$name/$name.cnf -policy policy_anything -startdate "$startdate" -enddate "$expireddate" -out $::_certdir/$certname-cert.pem -in $::_certdir/$certname-cert.req -batch 2>/dev/null
} else {
exec openssl ca -config $::_capath/$name/$name.cnf -policy policy_anything -days $day -out $::_certdir/$certname-cert.pem -in $::_certdir/$certname-cert.req -batch 2>/dev/null
}
}
proc _ca_make_config { dn name path {len ""}} {
if [catch {set cadesc [open $path/$name.cnf w+]}] then {
puts "ERROR"
exit
}
set CVAL ""
set STVAL ""
set OVAL ""
set OUVAL ""
set CNVAL ""
set EVAL ""
set LVAL ""
regexp {.*/C=([^/]*).*} $dn dummy CVAL
regexp {.*/ST=([^/]*).*} $dn dummy STVAL
regexp {.*/O=([^/]*).*} $dn dummy OVAL
regexp {.*/OU=([^/]*).*} $dn dummy OUVAL
regexp {.*/CN=([^/]*).*} $dn dummy CNVAL
regexp {.*/Email=([^/]*).*} $dn dummy EVAL
regexp {.*/L=([^/]*).*} $dn dummy LVAL
if [string length $len] then {
set PATHLEN ", pathlen:$len"
} else {
set PATHLEN ""
}
#
# OpenSSL example configuration file.
# This is mostly being used for generation of certificate requests.
#
puts $cadesc "
HOME = $path
RANDFILE = \$ENV::HOME/.rnd
oid_section = new_oids
\[ new_oids \]
\[ ca \]
default_ca = CA_default # The default ca section
\[ CA_default \]
dir = $path # Where everything is kept
certs = \$dir # Where the issued certs are kept
crl_dir = \$dir # Where the issued crl are kept
database = \$dir/index.txt # database index file.
new_certs_dir = \$dir # default place for new certs.
certificate = \$dir/cacert.pem # The CA certificate
serial = \$dir/serial # The current serial number
crl = \$dir/crl.pem # The current CRL
private_key = \$dir/certkey.pem # The private key
RANDFILE = \$dir/private/.rand # private random number file
x509_extensions = usr_cert # The extentions to add to the cert
name_opt = ca_default # Subject Name options
cert_opt = ca_default # Certificate field options
default_days = 365 # how long to certify for
default_crl_days= 30 # how long before next CRL
default_md = sha1 # which md to use.
preserve = no # keep passed DN ordering
policy = policy_anything
basicConstraints = CA:TRUE$PATHLEN
\[ policy_match \]
countryName = match
stateOrProvinceName = match
organizationName = match
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
\[ policy_anything \]
countryName = optional
stateOrProvinceName = optional
localityName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
\[req\]
default_bits = 2048
default_keyfile = privkey.pem
distinguished_name=req_distinguished_name
#attributes = req_attributes
x509_extensions = v3_ca # The extentions to add to the self signed cert
string_mask = nombstr
\[req_distinguished_name\]
countryName = Country Name (2 letter code)
countryName_default = $CVAL
countryName_min = 2
countryName_max = 2
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = $STVAL
localityName = Locality Name (eg, city)
localityName_default = $LVAL
0.organizationName = Organization Name (eg, company)
0.organizationName_default = $OVAL
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = $OUVAL
commonName = Common Name (eg, your name or your server\'s hostname)
commonName_default = $CNVAL
commonName_max = 64
emailAddress = Email Address
emailAddress_default = $EVAL
emailAddress_max = 64
\[ req_attributes \]
challengePassword = A challenge password
challengePassword_min = 4
challengePassword_max = 20
unstructuredName = An optional company name
\[ usr_cert \]
basicConstraints=CA:FALSE$PATHLEN
nsComment = \"OpenSSL Generated Certificate for VOMS testing purposes\"
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer:always
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
\[ usrca_cert \]
basicConstraints=CA:TRUE$PATHLEN
nsComment = \"OpenSSL Generated Certificate for VOMS testing purposes\"
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer:always
keyUsage = critical, keyCertSign, cRLSign
\[ v3_req \]
basicConstraints = CA:FALSE$PATHLEN
keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
\[ v3_ca \]
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer:always
basicConstraints = CA:TRUE$PATHLEN
\[ crl_ext \]
authorityKeyIdentifier=keyid,issuer:always"
flush $cadesc
close $cadesc
}
|