Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.io.FileNotFoundException: (Operation not permitted) error with ./keytool -import on mac osx (el capitan) - Java 6

Trying to import a CA Cert to my Java 6 truststore and am running into this error:

./keytool -v -import -trustcacerts -alias Rapidssl -file /Users/spurr/Desktop/rapidssl.cer -keystore /System/Library/Java/Support/CoreDeploy.bundle/Contents/Home/lib/security/cacerts
Enter keystore password:
Certificate was added to keystore
[Storing /System/Library/Java/Support/CoreDeploy.bundle/Contents/Home/lib/security/cacerts]
keytool error: java.io.FileNotFoundException: /System/Library/Java/Support/CoreDeploy.bundle/Contents/Home/lib/security/cacerts (Operation not permitted)
java.io.FileNotFoundException: /System/Library/Java/Support/CoreDeploy.bundle/Contents/Home/lib/security/cacerts (Operation not permitted)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:84)
at sun.security.tools.KeyTool.doCommands(KeyTool.java:902)
at sun.security.tools.KeyTool.run(KeyTool.java:172)
at sun.security.tools.KeyTool.main(KeyTool.java:166)

I'm running that command as root as well so I'd think I have access to that cacerts keystore location. Using Java 6.

like image 669
PurrBiscuit Avatar asked Jan 19 '17 16:01

PurrBiscuit


2 Answers

I was hit by similar issue on MacOS Big Sur while starting an jnlp file:

CouldNotLoadArgumentException[ Could not load file/URL specified: /Users/jhartman/Documents/Favorities/NCC/NCC 123.jnlp]
....
Caused by: java.io.FileNotFoundException: /Users/jhartman/Documents/Favorities/NCC/NCC 123.jnlp (Operation not permitted)

Solution for this was:

  • Give Java (/usr/bin/java) Full Disk access
  • Give Java (/usr/bin/java) Files and Folders access to Downloads, Documents and Folders

Steps

  1. Open /usr/bin in Finder, e.g. by invoking from Terminal:
jhartman@MBP ~ % open /usr/bin
  1. Localise java (and keytool)

  2. Open System Preferences and Security & Privacy. Open Full Disk Access tab and authorise

  3. Drag java and keytool from Finder window opened in step 1 and drop onto the App list in Full Disk Access

enter image description here

  1. Go to Security & Privacy -> Files and Folders, tick Downloads Folder and Document Folder for java and keytool

enter image description here

It was solution for my problem but I hope it should also sort out keytool issue.

like image 65
Jarek Avatar answered Oct 17 '22 17:10

Jarek


This seems to be a mac specific issue when the exception states (Operation not permitted) -

For anyone else having this problem you need to reboot your mac and press ⌘+R when booting up. Then go into Utilities > Terminal and type the following commands:

csrutil disable
reboot

You should be able to import cacerts to your Java keystore following that. Don't forget to reenable csrutil after you've imported that cacert. Reboot, press ⌘+R when booting up, Utilities > Terminal, enter:

csrutil enable
reboot
like image 6
PurrBiscuit Avatar answered Oct 17 '22 19:10

PurrBiscuit