3

I'm running Tomcat 6. I was messing around with my keystore in order to try to fix some certificate chain problems, and I accidentally rm'd the production version instead of the .new file I was working with.

Now, Tomcat is still running and still able to serve HTTPS connections (I tested it in a web browser). Obviously there must be a copy of the private key that it still has access to. My first thought was to check /proc/PID/fd, so I ran sudo lsof | grep tomcat. This properly returns a list of open files:

$ sudo lsof | head -1; sudo lsof | grep tomcat
COMMAND     PID     USER   FD      TYPE             DEVICE  SIZE/OFF       NODE NAME
java       2599     root  cwd       DIR              202,1      4096     413699 /usr/share/apache-tomcat-6.0.44/bin
java       2599     root  mem       REG              202,1     51715     413777 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-fr.jar
java       2599     root  mem       REG              202,1    528303     413771 /usr/share/apache-tomcat-6.0.44/lib/jasper.jar
java       2599     root  mem       REG              202,1   1250454     413767 /usr/share/apache-tomcat-6.0.44/lib/catalina.jar
java       2599     root  mem       REG              202,1    132216     413765 /usr/share/apache-tomcat-6.0.44/lib/catalina-ha.jar
java       2599     root  mem       REG              202,1     54334     413778 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-ja.jar
java       2599     root  mem       REG              202,1   1830791     413768 /usr/share/apache-tomcat-6.0.44/lib/ecj-4.3.1.jar
java       2599     root  mem       REG              202,1     54624     413764 /usr/share/apache-tomcat-6.0.44/lib/catalina-ant.jar
java       2599     root  mem       REG              202,1     70563     413776 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-es.jar
java       2599     root  mem       REG              202,1    112521     413770 /usr/share/apache-tomcat-6.0.44/lib/jasper-el.jar
java       2599     root  mem       REG              202,1     76649     413772 /usr/share/apache-tomcat-6.0.44/lib/jsp-api.jar
java       2599     root  mem       REG              202,1     34622     413769 /usr/share/apache-tomcat-6.0.44/lib/el-api.jar
java       2599     root  mem       REG              202,1    253635     413775 /usr/share/apache-tomcat-6.0.44/lib/tomcat-dbcp.jar
java       2599     root  mem       REG              202,1     15250     413763 /usr/share/apache-tomcat-6.0.44/lib/annotations-api.jar
java       2599     root  mem       REG              202,1    801374     413774 /usr/share/apache-tomcat-6.0.44/lib/tomcat-coyote.jar
java       2599     root  mem       REG              202,1    239165     413766 /usr/share/apache-tomcat-6.0.44/lib/catalina-tribes.jar
java       2599     root  mem       REG              202,1    132240     413773 /usr/share/apache-tomcat-6.0.44/lib/servlet-api.jar
java       2599     root  mem       REG              202,1     32384     413759 /usr/share/apache-tomcat-6.0.44/bin/tomcat-juli.jar
java       2599     root  mem       REG              202,1     24283     413753 /usr/share/apache-tomcat-6.0.44/bin/commons-daemon.jar
java       2599     root  mem       REG              202,1     22807     413749 /usr/share/apache-tomcat-6.0.44/bin/bootstrap.jar
java       2599     root    1w      REG              202,1  17024956     413713 /usr/share/apache-tomcat-6.0.44/logs/catalina.out
java       2599     root    2w      REG              202,1  17024956     413713 /usr/share/apache-tomcat-6.0.44/logs/catalina.out
java       2599     root    4r      REG              202,1     22807     413749 /usr/share/apache-tomcat-6.0.44/bin/bootstrap.jar
java       2599     root    5r      REG              202,1     24283     413753 /usr/share/apache-tomcat-6.0.44/bin/commons-daemon.jar
java       2599     root    6r      REG              202,1     32384     413759 /usr/share/apache-tomcat-6.0.44/bin/tomcat-juli.jar
java       2599     root    7w      REG              202,1      4072     396419 /usr/share/apache-tomcat-6.0.44/logs/catalina.2016-04-21.log
java       2599     root    8w      REG              202,1      1182     396447 /usr/share/apache-tomcat-6.0.44/logs/localhost.2016-04-21.log
java       2599     root    9w      REG              202,1         0     396448 /usr/share/apache-tomcat-6.0.44/logs/manager.2016-04-21.log
java       2599     root   10w      REG              202,1         0     396455 /usr/share/apache-tomcat-6.0.44/logs/host-manager.2016-04-21.log
java       2599     root   11r      REG              202,1    239165     413766 /usr/share/apache-tomcat-6.0.44/lib/catalina-tribes.jar
java       2599     root   12r      REG              202,1    801374     413774 /usr/share/apache-tomcat-6.0.44/lib/tomcat-coyote.jar
java       2599     root   13r      REG              202,1    253635     413775 /usr/share/apache-tomcat-6.0.44/lib/tomcat-dbcp.jar
java       2599     root   14r      REG              202,1    132240     413773 /usr/share/apache-tomcat-6.0.44/lib/servlet-api.jar
java       2599     root   15r      REG              202,1     34622     413769 /usr/share/apache-tomcat-6.0.44/lib/el-api.jar
java       2599     root   16r      REG              202,1     76649     413772 /usr/share/apache-tomcat-6.0.44/lib/jsp-api.jar
java       2599     root   17r      REG              202,1    112521     413770 /usr/share/apache-tomcat-6.0.44/lib/jasper-el.jar
java       2599     root   18r      REG              202,1     70563     413776 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-es.jar
java       2599     root   19r      REG              202,1     54624     413764 /usr/share/apache-tomcat-6.0.44/lib/catalina-ant.jar
java       2599     root   20r      REG              202,1   1830791     413768 /usr/share/apache-tomcat-6.0.44/lib/ecj-4.3.1.jar
java       2599     root   21r      REG              202,1     54334     413778 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-ja.jar
java       2599     root   22r      REG              202,1     15250     413763 /usr/share/apache-tomcat-6.0.44/lib/annotations-api.jar
java       2599     root   23r      REG              202,1    132216     413765 /usr/share/apache-tomcat-6.0.44/lib/catalina-ha.jar
java       2599     root   24r      REG              202,1   1250454     413767 /usr/share/apache-tomcat-6.0.44/lib/catalina.jar
java       2599     root   25r      REG              202,1    528303     413771 /usr/share/apache-tomcat-6.0.44/lib/jasper.jar
java       2599     root   26r      REG              202,1     51715     413777 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-fr.jar
bash      29579 ec2-user  cwd       DIR              202,1      4096     413708 /usr/share/apache-tomcat-6.0.44/conf
sudo      30595     root  cwd       DIR              202,1      4096     413708 /usr/share/apache-tomcat-6.0.44/conf
grep      30596 ec2-user  cwd       DIR              202,1      4096     413708 /usr/share/apache-tomcat-6.0.44/conf
lsof      30597     root  cwd       DIR              202,1      4096     413708 /usr/share/apache-tomcat-6.0.44/conf
lsof      30598     root  cwd       DIR              202,1      4096     413708 /usr/share/apache-tomcat-6.0.44/conf

but unfortunately, my keystore isn't one of them. I guess Tomcat must have loaded it into memory and then closed the file descriptor. (The keystore was in /conf above, but those file descriptors are from my open shell, not from Tomcat itself.)

So: is there any way to recover my private key? I'm on Amazon Linux; uname -a returns Linux ip-10-0-0-105 4.4.5-15.26.amzn1.x86_64 #1 SMP Wed Mar 16 17:15:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux.

  • 1
    Attaching gdb to a process and running gcore should get you a dump of all data in the process. But better test it on an unimportant server first. Finding the key inside the dump is going to be a bit tricky. But it may become a lot easier if you have a public key to compare with. – kasperd Apr 26 '16 at 21:26
1

You can try using passe-partout.

I have successfully used it with Apache, not with Tomcat, but it's advertised to work with Tomcat 7.0.34 + apr 1.4.6 + jdk7-openjdk 7.u9.

  • I actually ended up finding a copy somewhere else (thank god!) but if no one else answers for a little bit, I'll go ahead and mark this as accepted. thanks. – strugee Apr 26 '16 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.