<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 05/15/2013 01:36 PM, Ana Krivokapic
      wrote:<br>
    </div>
    <blockquote cite="mid:51937353.3090501@redhat.com" type="cite">
      <pre wrap="">On 05/15/2013 12:29 PM, Petr Viktorin wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">On 05/15/2013 12:04 PM, Tomas Babej wrote:
</pre>
        <blockquote type="cite">
          <pre wrap="">On 05/15/2013 11:40 AM, Ana Krivokapic wrote:
</pre>
          <blockquote type="cite">
            <pre wrap="">Hello,

See the commit message for details.

<a class="moz-txt-link-freetext" href="https://fedorahosted.org/freeipa/ticket/3594">https://fedorahosted.org/freeipa/ticket/3594</a>



_______________________________________________
Freeipa-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Freeipa-devel@redhat.com">Freeipa-devel@redhat.com</a>
<a class="moz-txt-link-freetext" href="https://www.redhat.com/mailman/listinfo/freeipa-devel">https://www.redhat.com/mailman/listinfo/freeipa-devel</a>
</pre>
          </blockquote>
          <pre wrap="">
+    def regenerate_ca_file(self, ca_file):
+        dm_pwd_fd, dm_pwd_fname = tempfile.mkstemp()
+        keydb_pwd_fd, keydb_pwd_fname = tempfile.mkstemp()
+
+        os.write(dm_pwd_fd, self.dirman_password)
+        os.close(dm_pwd_fd)
+
+        keydb_pwd = ''
+        with open('/etc/pki/pki-tomcat/password.conf') as f:
+            for line in f.readlines():
+                key, value = line.strip().split('=')
+                if key == 'internal':
+                    keydb_pwd = value
+                    break
+
+        os.write(keydb_pwd_fd, keydb_pwd)
+        os.close(keydb_pwd_fd)
+
+        ipautil.run([
+            '/usr/bin/PKCS12Export',
+            '-d', '/etc/pki/pki-tomcat/alias/',
+            '-p', keydb_pwd_fname,
+            '-w', dm_pwd_fname,
+            '-o', ca_file
+        ])
+

If the PKCS12Export call fails (returns non-zero code), we raise
exception here, and the temporary files are never removed.

+        os.remove(dm_pwd_fname)
+        os.remove(keydb_pwd_fname)

This might not be a big issue since mkstemp() call creates temporary
file readable and writable only be given user ID,
however, we should not leave files with passwords in plaintext on the
disk if it is not necessary.

This can be easily prevented by wrapping the call up with
try-chatch-finally block, or using raiseonerr=False options of run
method.
</pre>
        </blockquote>
        <pre wrap="">
Or by using ipautil.write_tmp_file() – the file it creates is always
removed after it's closed/garbage collected, and it has a name attribute.

</pre>
      </blockquote>
      <pre wrap="">
Updated patch uses `ipautil.write_tmp_file()`.

</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Freeipa-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Freeipa-devel@redhat.com">Freeipa-devel@redhat.com</a>
<a class="moz-txt-link-freetext" href="https://www.redhat.com/mailman/listinfo/freeipa-devel">https://www.redhat.com/mailman/listinfo/freeipa-devel</a></pre>
    </blockquote>
    I'm testing on a fairly updated F19 VM:<br>
    <br>
    I'm getting the following error when preparing the replica info
    file:<br>
    <br>
    [root@vm-002 ~]# ipa-replica-prepare vm-003.ipa.com --ip-address
    192.168.122.213<br>
    Directory Manager (existing master) password: <br>
    <br>
    Preparing replica for vm-003.ipa.com from vm-002.ipa.com<br>
    Command '/usr/bin/PKCS12Export -d /etc/pki/pki-tomcat/alias/ -p
    /tmp/tmp15Je9R -w /tmp/tmpCGD5Sr -o /root/cacert.p12' returned non<br>
    <br>
    When trying that manually:<br>
    <br>
    [root@vm-002 ~]# /usr/bin/PKCS12Export -d /etc/pki/pki-tomcat/alias/
    -p /tmp/tmp15Je9R -w /tmp/tmpCGD5Sr -o /root/cacert.p12<br>
    Exception in thread "main" java.lang.NoClassDefFoundError:
    org/mozilla/jss/util/PasswordCallback<br>
        at java.lang.Class.getDeclaredMethods0(Native Method)<br>
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)<br>
        at java.lang.Class.getMethod0(Class.java:2694)<br>
        at java.lang.Class.getMethod(Class.java:1622)<br>
        at
    sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)<br>
        at
    sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)<br>
    Caused by: java.lang.ClassNotFoundException:
    org.mozilla.jss.util.PasswordCallback<br>
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)<br>
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)<br>
        at java.security.AccessController.doPrivileged(Native Method)<br>
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)<br>
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)<br>
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)<br>
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)<br>
        ... 6 more<br>
    <br>
    We might need to investigate what causes this, and if the issue is
    not on our side, file appropriate bugs.<br>
    <br>
    Tomas<br>
  </body>
</html>