mirror of
https://github.com/ArcticFoxes-net/ONC-Converter
synced 2024-11-13 15:41:33 -05:00
Do key name extraction and key conversion separately
This commit is contained in:
parent
14739a0ae9
commit
529bcb295e
@ -212,11 +212,11 @@
|
|||||||
/**
|
/**
|
||||||
* 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
|
||||||
// TODO: handle other types of client certificates
|
if (keyNames.clientCertificates) {
|
||||||
let [clientCerts, clientCertGuids] = constructCerts(keys, ovpn['cert'],
|
// TODO: handle other types of client certificates
|
||||||
'Authority')
|
let [clientCerts, clientCertGuids] = constructCerts(
|
||||||
if (clientCerts) {
|
keys, keyNames.clientCertificates, 'Authority')
|
||||||
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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user