@@ -110,6 +110,9 @@ help_text ()
110110 68 - USER ERROR Disallow connection, missing sed.exe
111111 69 - USER ERROR Disallow connection, missing printf.exe
112112 70 - USER ERROR Disallow connection, missing rm.exe
113+ 87 - BUG Disallow connection, failed to create generic_metadata_file
114+ 88 - BUG Disallow connection, failed to create generic_metadata_file
115+ 89 - BUG Disallow connection, failed to create client_metadata_file
113116 101 - BUG Disallow connection, stale metadata file time-out.
114117 112 - BUG Disallow connection, invalid date
115118 113 - BUG Disallow connection, missing dependency file.
@@ -263,7 +266,7 @@ serial_status_via_crl ()
263266 fail_and_exit " SERIAL NUMBER UNKNOWN" 121
264267 ;;
265268 1)
266- client_passed_x509_tests_connection_allowed
269+ client_passed_x509_tests
267270 ;;
268271 * )
269272 die " Duplicate serial numbers: ${md_serial} " 127
@@ -298,7 +301,7 @@ serial_status_via_ca ()
298301 # Considering what has to be done, I don't like this
299302 case " ${client_cert_serno_status} " in
300303 Valid)
301- client_passed_x509_tests_connection_allowed
304+ client_passed_x509_tests
302305 ;;
303306 Revoked)
304307 client_passed_x509_tests_certificate_revoked
@@ -359,7 +362,7 @@ serial_status_via_pki_index ()
359362 then
360363 if [ $is_valid -eq 1 ]
361364 then
362- client_passed_x509_tests_connection_allowed
365+ client_passed_x509_tests
363366 else
364367 # Cert is not known
365368 insert_msg=" Serial number is not in the CA database:"
@@ -388,11 +391,10 @@ fn_search_revoked_pki_index ()
388391}
389392
390393# This is the long way to connect - X509
391- client_passed_x509_tests_connection_allowed ()
394+ client_passed_x509_tests ()
392395{
393396 insert_msg=" Client certificate is recognised and Valid:"
394397 update_status " ${insert_msg} ${md_serial} "
395- absolute_fail=0
396398}
397399
398400# This is the only way to fail for Revokation - X509
@@ -407,7 +409,14 @@ client_passed_x509_tests_certificate_revoked ()
407409client_passed_tls_tests_connection_allowed ()
408410{
409411 absolute_fail=0
410- update_status " TLS key is recognised and Valid: ${tlskey_serial} "
412+ update_status " connection allowed"
413+ }
414+
415+ # Allow connection
416+ connection_allowed ()
417+ {
418+ absolute_fail=0
419+ update_status " connection allowed"
411420}
412421
413422# Initialise
@@ -430,7 +439,7 @@ init ()
430439 tlskey_max_age=$(( 365 * 5 ))
431440
432441 # Defaults
433- EASYTLS_server_pid =$PPID
442+ EASYTLS_srv_pid =$PPID
434443
435444 # metadata file
436445 OPENVPN_METADATA_FILE=" ${metadata_file} "
@@ -457,6 +466,7 @@ init ()
457466 # Required binaries
458467 EASYTLS_OPENSSL=' openssl'
459468 EASYTLS_CAT=' cat'
469+ EASYTLS_CP=' cp'
460470 EASYTLS_DATE=' date'
461471 EASYTLS_GREP=' grep'
462472 EASYTLS_SED=' sed'
@@ -477,6 +487,7 @@ init ()
477487 [ -d " ${EASYTLS_ovpnbin_dir} " ] || exit 63
478488 [ -f " ${EASYTLS_ovpnbin_dir} /${EASYTLS_OPENSSL} .exe" ] || exit 64
479489 [ -f " ${EASYTLS_ersabin_dir} /${EASYTLS_CAT} .exe" ] || exit 65
490+ [ -f " ${EASYTLS_ersabin_dir} /${EASYTLS_CP} .exe" ] || exit 65
480491 [ -f " ${EASYTLS_ersabin_dir} /${EASYTLS_DATE} .exe" ] || exit 66
481492 [ -f " ${EASYTLS_ersabin_dir} /${EASYTLS_GREP} .exe" ] || exit 67
482493 [ -f " ${EASYTLS_ersabin_dir} /${EASYTLS_SED} .exe" ] || exit 68
@@ -847,7 +858,7 @@ warn_log
847858if [ ! $use_x509 ]
848859then
849860 # No X509 required
850- client_passed_tls_tests_connection_allowed
861+ update_status " client passed TLS tests "
851862else
852863
853864 # Verify CA cert is valid and/or set the CA identity
921932fi # => use_x509 ()
922933
923934# Save the client_metadata to temp file
924- client_metadata_file=" ${EASYTLS_tmp_dir} /${md_serial} .${EASYTLS_server_pid} "
935+ client_metadata_file=" ${EASYTLS_tmp_dir} /${md_serial} .${EASYTLS_srv_pid} "
936+ # client_metadata_file="${client_metadata_file}.tcv2md"
937+ generic_metadata_file=" ${EASYTLS_tmp_dir} /TCV2.${EASYTLS_srv_pid} "
925938
926939# If client_metadata_file exists then delete it if is stale
927940if [ -f " ${client_metadata_file} " ]
@@ -940,9 +953,29 @@ then
940953 failure_msg=" client_metadata_file age: ${md_file_age_sec} sec"
941954 fail_and_exit " STALE_METADATA_FILE" 101
942955else
943- " ${EASYTLS_PRINTF} " ' %s\n%s\n' \
944- " ${md_hwadds} " " ${md_opt} " > " ${client_metadata_file} " || \
945- die " Failed to write client_metadata file"
956+ # "${EASYTLS_PRINTF}" '%s %s %s\n' \
957+ # "${tlskey_serial}" "${md_hwadds}" "${md_opt}" > \
958+ # "${client_metadata_file}" || \
959+ # die "Failed to write client_metadata file"
960+ " ${EASYTLS_CP} " " ${OPENVPN_METADATA_FILE} " " ${client_metadata_file} " || \
961+ die " Failed to create client_metadata_file" 89
962+ update_status " Created client_metadata_file"
963+
964+ # Ugly generic_metadata_file hack
965+ if [ -f " ${generic_metadata_file} " ]
966+ then
967+ " ${EASYTLS_RM} " -f " ${generic_metadata_file} "
968+ update_status " Deleted generic_metadata_file"
969+ " ${EASYTLS_CP} " " ${OPENVPN_METADATA_FILE} " " ${generic_metadata_file} " || \
970+ die " Failed to create generic_metadata_file" 87
971+ update_status " Created generic_metadata_file"
972+ else
973+ " ${EASYTLS_CP} " " ${OPENVPN_METADATA_FILE} " " ${generic_metadata_file} " || \
974+ die " Failed to create generic_metadata_file" 88
975+ update_status " Created generic_metadata_file"
976+ fi
977+ # Allow connection
978+ connection_allowed
946979fi
947980
948981# Any failure_msg means fail_and_exit
956989if [ $absolute_fail -eq 0 ]
957990then
958991 # All is well
959- verbose_print " <EXOK> ${status_msg} "
992+ verbose_print "
993+ <EXOK> ${status_msg}
994+ "
960995 exit 0
961996fi
962997
0 commit comments