Skip to content

Commit ae179b5

Browse files
committed
crypto: default keystore is pkcs12 if no file ext
1 parent 4bddab6 commit ae179b5

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/crypto/fan/Crypto.fan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const mixin Crypto
101101
** - '.p12', '.pfx': PKCS12 format
102102
** - '.jks': Java KeyStore (JAVA only)
103103
**
104+
** If the file does not have an extension, then PKCS12 format will be assumed.
104105
** Other formats may be supported depending on the runtime implementation. Throws
105106
** an Err if the format is not supported or there is a problem loading the keystore.
106107
**

src/cryptoJava/java/JKeyStorePeer.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,29 @@ public class JKeyStorePeer
3434

3535
public static JKeyStore load(File file, Map opts)
3636
{
37-
String format = null;
38-
String ext = "p12";
39-
if (file != null) ext = file.ext();
40-
switch(ext)
37+
// format option trumps file extension
38+
String format = (String)opts.get("format");
39+
if (format == null)
4140
{
42-
case "p12":
43-
case "pfx":
44-
format = "pkcs12";
45-
break;
46-
case "jks":
47-
format = "jks";
48-
break;
49-
default:
50-
throw UnsupportedErr.make("Unsupported file ext: " + file.ext());
41+
String ext = "p12";
42+
if (file != null)
43+
{
44+
// If the file doesn't have an extension, then default is pkcs12
45+
ext = file.ext();
46+
if (ext == null) ext = "p12";
47+
}
48+
switch(ext)
49+
{
50+
case "p12":
51+
case "pfx":
52+
format = "pkcs12";
53+
break;
54+
case "jks":
55+
format = "jks";
56+
break;
57+
default:
58+
throw UnsupportedErr.make("Unsupported file ext: " + file.ext());
59+
}
5160
}
5261
return file == null
5362
? JKeyStore.make(format, ConcurrentMap.make())

0 commit comments

Comments
 (0)