@return: list of tuples of the token type and the public crypto token
"""
+ getents = runtime.GetEnts()
_VALID_CERT_FILES = [pathutils.NODED_CERT_FILE,
pathutils.NODED_CLIENT_CERT_FILE,
pathutils.NODED_CLIENT_CERT_FILE_TMP]
utils.GenerateNewSslCert(
True, cert_filename, serial_no,
- "Create new client SSL certificate in %s." % cert_filename)
+ "Create new client SSL certificate in %s." % cert_filename,
+ uid=getents.masterd_uid, gid=getents.masterd_gid)
tokens.append((token_type,
utils.GetCertificateDigest(
cert_filename=cert_filename)))
getent.noded_uid, getent.masterd_gid, False),
(pathutils.NODED_CERT_FILE, FILE, pathutils.NODED_CERT_MODE,
getent.masterd_uid, getent.masterd_gid, False),
+ (pathutils.NODED_CLIENT_CERT_FILE, FILE, pathutils.NODED_CERT_MODE,
+ getent.masterd_uid, getent.masterd_gid, False),
(pathutils.WATCHER_PAUSEFILE, FILE, 0644,
getent.masterd_uid, getent.masterd_gid, False),
]
return cert.digest("sha1")
-def GenerateNewSslCert(new_cert, cert_filename, serial_no, log_msg):
+def GenerateNewSslCert(new_cert, cert_filename, serial_no, log_msg,
+ uid=-1, gid=-1):
"""Creates a new SSL certificate and backups the old one.
@type new_cert: boolean
@param serial_no: serial number of the certificate
@type log_msg: string
@param log_msg: log message to be written on certificate creation
+ @type uid: int
+ @param uid: the user ID of the user who will be owner of the certificate file
+ @type gid: int
+ @param gid: the group ID of the group who will own the certificate file
"""
cert_exists = os.path.exists(cert_filename)
io.CreateBackup(cert_filename)
logging.debug(log_msg)
- x509.GenerateSelfSignedSslCert(cert_filename, serial_no)
+ x509.GenerateSelfSignedSslCert(cert_filename, serial_no, uid=uid, gid=gid)
def VerifyCertificate(filename):
def GenerateSelfSignedSslCert(filename, serial_no,
common_name=constants.X509_CERT_CN,
- validity=constants.X509_CERT_DEFAULT_VALIDITY):
+ validity=constants.X509_CERT_DEFAULT_VALIDITY,
+ uid=-1, gid=-1):
"""Legacy function to generate self-signed X509 certificate.
@type filename: str
@param common_name: commonName value
@type validity: int
@param validity: validity of certificate in number of days
+ @type uid: int
+ @param uid: the user ID of the user who will be owner of the certificate file
+ @type gid: int
+ @param gid: the group ID of the group who will own the certificate file
@return: a tuple of strings containing the PEM-encoded private key and
certificate
(key_pem, cert_pem) = GenerateSelfSignedX509Cert(
common_name, validity * 24 * 60 * 60, serial_no)
- utils_io.WriteFile(filename, mode=0400, data=key_pem + cert_pem)
+ utils_io.WriteFile(filename, mode=0440, data=key_pem + cert_pem,
+ uid=uid, gid=gid)
return (key_pem, cert_pem)