-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (60 loc) · 1.91 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var java = require("java");
var path = require('path');
var Keystore = function (keystore, storepass) {
if (!keystore) {
throw new Error('Keystore: keystore - must not be empty.');
}
if (!storepass) {
throw new Error('Keystore: storepass - must not be empty.');
}
// Get SSL Cert from Java Keystore Lib
java.classpath.push("commons-lang3-3.1.jar");
java.classpath.push("commons-io.jar");
java.classpath.push(path.resolve(__dirname, './SSLKeystore.jar'));
var _class = java.newInstanceSync("GetData");
var getCert = function(alias){
if(!alias){
throw new Error("Keystore: getCert: alias - must not be empty");
}
var _certificate;
try {
// JAR file call to retrieve the certificate from keystore
_certificate = java.callMethodSync(_class, "getCert",
keystore,
storepass,
alias);
if(!_certificate){
throw new Error('Cannot find cert for alias:' + alias);
}
}
catch (error) {
throw error;
}
return _certificate;
}
var getPrivateKey = function(alias){
if(!alias){
throw new Error("Keystore: getPrivateKey: alias - must not be empty");
}
var _privateKey;
try {
// JAR file call to retrieve the certificate from keystore
_privateKey = java.callMethodSync(_class, "getPrivateKey",
keystore,
storepass,
alias);
if(!_privateKey){
throw new Error('Cannot find privateKey for alias:' + alias);
}
}
catch (error) {
throw error;
}
return _privateKey;
}
return {
getCert: getCert,
getPrivateKey: getPrivateKey
}
};
module.exports = Keystore;