Commit 956e2d9c authored by Rafael Monnerat's avatar Rafael Monnerat

Use openssl from the PATH and do not use tool property

parent c2e6a8ea
...@@ -48,6 +48,15 @@ def popenCommunicate(command_list, input=None, **kwargs): ...@@ -48,6 +48,15 @@ def popenCommunicate(command_list, input=None, **kwargs):
command_list, result)) command_list, result))
return result return result
def binary_search(binary):
env_path_list = [p for p in os.getenv('PATH', '').split(os.pathsep)
if os.path.isdir(p)]
mode = os.R_OK | os.X_OK
for path in env_path_list:
pathbin = os.path.join(path, binary)
if os.access(pathbin, mode) == 1:
return pathbin
class CertificateAuthorityBusy(Exception): class CertificateAuthorityBusy(Exception):
"""Exception raised when certificate authority is busy""" """Exception raised when certificate authority is busy"""
pass pass
...@@ -71,7 +80,7 @@ class CertificateAuthorityTool(BaseTool): ...@@ -71,7 +80,7 @@ class CertificateAuthorityTool(BaseTool):
isIndexable = 0 isIndexable = 0
certificate_authority_path = os.environ.get('CA_PATH', '') certificate_authority_path = os.environ.get('CA_PATH', '')
openssl_binary = os.environ.get('OPENSSL_BINARY', '') openssl_binary = binary_search('openssl')
manage_options = (({'label': 'Edit', manage_options = (({'label': 'Edit',
'action': 'manage_editCertificateAuthorityToolForm',}, 'action': 'manage_editCertificateAuthorityToolForm',},
...@@ -83,11 +92,6 @@ class CertificateAuthorityTool(BaseTool): ...@@ -83,11 +92,6 @@ class CertificateAuthorityTool(BaseTool):
'mode':'w', 'mode':'w',
'label':'Absolute path to certificate authority', 'label':'Absolute path to certificate authority',
}, },
{'id':'openssl_binary',
'type':'string',
'mode':'w',
'label':'Absolute path to OpenSSL binary'
},
) )
) )
...@@ -118,11 +122,7 @@ class CertificateAuthorityTool(BaseTool): ...@@ -118,11 +122,7 @@ class CertificateAuthorityTool(BaseTool):
raise CertificateAuthorityDamaged('Path to Certificate Authority %r is ' raise CertificateAuthorityDamaged('Path to Certificate Authority %r is '
'wrong' % self.certificate_authority_path) 'wrong' % self.certificate_authority_path)
if not self.openssl_binary: if not self.openssl_binary:
raise CertificateAuthorityDamaged('OpenSSL binary path is not ' raise CertificateAuthorityDamaged('OpenSSL binary was not found!')
'configured' % self.certificate_authority_path)
if not os.path.isfile(self.openssl_binary):
raise CertificateAuthorityDamaged('OpenSSL binary %r does not exists' %
self.openssl_binary)
self.serial = os.path.join(self.certificate_authority_path, 'serial') self.serial = os.path.join(self.certificate_authority_path, 'serial')
self.crl = os.path.join(self.certificate_authority_path, 'crlnumber') self.crl = os.path.join(self.certificate_authority_path, 'crlnumber')
self.index = os.path.join(self.certificate_authority_path, 'index.txt') self.index = os.path.join(self.certificate_authority_path, 'index.txt')
...@@ -159,7 +159,7 @@ class CertificateAuthorityTool(BaseTool): ...@@ -159,7 +159,7 @@ class CertificateAuthorityTool(BaseTool):
security.declareProtected(Permissions.ManageProperties, security.declareProtected(Permissions.ManageProperties,
'manage_editCertificateAuthorityTool') 'manage_editCertificateAuthorityTool')
def manage_editCertificateAuthorityTool(self, certificate_authority_path, def manage_editCertificateAuthorityTool(self, certificate_authority_path,
openssl_binary, RESPONSE=None): RESPONSE=None):
"""Edit the object""" """Edit the object"""
error_message = '' error_message = ''
...@@ -168,11 +168,6 @@ class CertificateAuthorityTool(BaseTool): ...@@ -168,11 +168,6 @@ class CertificateAuthorityTool(BaseTool):
else: else:
self.certificate_authority_path = certificate_authority_path self.certificate_authority_path = certificate_authority_path
if openssl_binary == '' or openssl_binary is None:
error_message += 'Invalid OpenSSL binary'
else:
self.openssl_binary = openssl_binary
#Redirect #Redirect
if RESPONSE is not None: if RESPONSE is not None:
if error_message != '': if error_message != '':
......
...@@ -396,8 +396,6 @@ class IntrospectionTool(LogMixin, BaseTool): ...@@ -396,8 +396,6 @@ class IntrospectionTool(LogMixin, BaseTool):
if certificate_authority is not None: if certificate_authority is not None:
collect_information_by_property(certificate_authority, collect_information_by_property(certificate_authority,
'certificate_authority_path') 'certificate_authority_path')
collect_information_by_property(certificate_authority,
'openssl_binary')
return connection_dict return connection_dict
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
......
...@@ -41,8 +41,6 @@ class TestCertificateAuthority(ERP5TypeTestCase): ...@@ -41,8 +41,6 @@ class TestCertificateAuthority(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
self.portal.portal_certificate_authority.certificate_authority_path = \ self.portal.portal_certificate_authority.certificate_authority_path = \
os.environ['TEST_CA_PATH'] os.environ['TEST_CA_PATH']
self.portal.portal_certificate_authority.openssl_binary = \
os.environ['OPENSSL_BINARY']
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
return ('erp5_base', 'erp5_certificate_authority') return ('erp5_base', 'erp5_certificate_authority')
......
...@@ -17,13 +17,6 @@ ...@@ -17,13 +17,6 @@
tal:attributes="value certificate_authority_path;" /> tal:attributes="value certificate_authority_path;" />
</td> </td>
</tr> </tr>
<tr>
<td>Absolute path to OpenSSL binary</td>
<td>
<input type="text" name="openssl_binary" value=""
tal:attributes="value openssl_binary;" />
</td>
</tr>
<tr> <tr>
<td colspan="2"> <td colspan="2">
<input type="submit" value="save"/> <input type="submit" value="save"/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment