1
0
mirror of https://github.com/ArcticFoxes-net/ONC-Converter synced 2024-12-22 00:11:33 -05:00

Do key name extraction and key conversion separately

This commit is contained in:
thomkeh 2018-08-13 13:17:19 +01:00
parent 14739a0ae9
commit 529bcb295e

View File

@ -213,10 +213,10 @@
* Convert the keys from the parsed OVPN file into ONC keys * Convert the keys from the parsed OVPN file into ONC keys
* *
* @param {Object} keys Strings with keys, indexed by key name * @param {Object} keys Strings with keys, indexed by key name
* @param {Object} ovpn The parsed OVPN file * @param {Object} keynames Object with the key names
* @return {Object} ONC parameters and a list of converted certificates * @return {Object} ONC parameters and a list of converted certificates
*/ */
function convertKeys (keys, ovpn) { function convertKeys (keys, keyNames) {
let params = {} let params = {}
// Add certificates // Add certificates
@ -224,15 +224,16 @@
// Server certificate // Server certificate
// TODO: check whether the type should be 'Authority' // TODO: check whether the type should be 'Authority'
let [cas, caGuids] = constructCerts(keys, ovpn['ca'], 'Authority') let [cas, caGuids] = constructCerts(keys, keyNames.certificateAuthorities,
'Authority')
params['ServerCARefs'] = caGuids params['ServerCARefs'] = caGuids
certs = certs.concat(cas) certs = certs.concat(cas)
// Client certificate // Client certificate
if (keyNames.clientCertificates) {
// TODO: handle other types of client certificates // TODO: handle other types of client certificates
let [clientCerts, clientCertGuids] = constructCerts(keys, ovpn['cert'], let [clientCerts, clientCertGuids] = constructCerts(
'Authority') keys, keyNames.clientCertificates, 'Authority')
if (clientCerts) {
params['ClientCertType'] = 'Pattern' params['ClientCertType'] = 'Pattern'
params['ClientCertPattern'] = { params['ClientCertPattern'] = {
'IssuerCARef': clientCertGuids 'IssuerCARef': clientCertGuids
@ -243,8 +244,8 @@
} }
// TLS auth // TLS auth
if (ovpn['tls-auth']) { if (keyNames.tlsAuth) {
let authKey = ovpn['tls-auth'].split(' ') let authKey = keyNames.tlsAuth.split(' ')
let keyString = keys[authKey[0]] let keyString = keys[authKey[0]]
if (!keyString) { if (!keyString) {
alert(`Please provide the file '${authKey[0]}' in 'Certificates and keys'`) alert(`Please provide the file '${authKey[0]}' in 'Certificates and keys'`)
@ -323,7 +324,13 @@
conditionalSet('auth-retry', 'AuthRetry') conditionalSet('auth-retry', 'AuthRetry')
conditionalSet('reneg-sec', 'RenegSec', 'int') conditionalSet('reneg-sec', 'RenegSec', 'int')
return [host, params] const keyNames = {
'certificateAuthorities': ovpn['ca'],
'clientCertificates': ovpn['cert'],
'tlsAuth': ovpn['tls-auth'],
}
return [host, params, keyNames]
} }
@ -336,8 +343,8 @@
* @return {Object} The converted ONC structure * @return {Object} The converted ONC structure
*/ */
function constructOnc (name, ovpn, keys) { function constructOnc (name, ovpn, keys) {
let [host, params] = convertToOnc(ovpn) let [host, params, keyNames] = convertToOnc(ovpn)
let [certParams, certificates] = convertKeys(keys, ovpn) let [certParams, certificates] = convertKeys(keys, keyNames)
// merge parameters // merge parameters
params = Object.assign({}, params, certParams) params = Object.assign({}, params, certParams)