-
Notifications
You must be signed in to change notification settings - Fork 3
/
ConvertSignedKeySets(fromPFX).bat
111 lines (99 loc) · 3.37 KB
/
ConvertSignedKeySets(fromPFX).bat
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
@echo off
setLocal EnableDelayedExpansion
Rem
Rem <b>CreateSignedKeySets(fromPFX)</b> command file.
Rem @author Jack D. Pond
Rem @version 0.2 / Windows Batch Processor
Rem @see
Rem @description Create a pem key set (pem) from a pkcs#12 key (pfx)
Rem @param CertName - Name of the certificate corresponding to directory and certnames
call "etc/CertConfig.bat"
if exist %OpenSSLExe% goto :PickCertName
echo To use these utilities, you must have a running copy of OpenSSL running at the location specified in CertConfig.bat
echo You can download this open source system from: http://www.openssl.org/related/binaries.html
echo If you loaded the system into a non-standard directory, you will have to modify CertConfig.bat to specify the proper location
echo.
pause
exit
:PickCertName
if "%1" NEQ "" (
set CertName=%1
set TestVar=!CertName:~0,1!
set TestVar2="
if !TestVar!==!TestVar2! set CertName=!CertName:~1,-1!
if exist "!CertName!\!CertName!.pfx" goto :ValidCertName
)
FOR /F "usebackq delims=" %%i in (`dir /B/AD`) do (
if exist "%%i\%%i.pfx" (
set /a DirCount += 1
set v!DirCount!=%%i
echo !DirCount!^) %%~ni
if !DirCount! GTR 20 (
echo.
echo This utility can only handle up to 20 keys. You will only be able to select up to the first 20 keys.
echo.
pause
)
)
)
if not defined DirCount (
echo.
echo You do not have a valid public/private certificate ready for conversion. You need to have a private key ^(%%name%%\%%name%%.pfx^)
echo in a named sub directory ^(%%name%%^).
echo.
echo If you have not done so already, you can create a private certificate and follow the required instructions by using the RequestNewCert.bat command file.
echo.
pause
goto :eof
)
if %DirCount% == 1 (
set CertID=1
) else (
set /p CertID=From which Certificate pair do you wish to create a key set ^(by number^)?:
)
if %CertID% GTR 0 if %CertID% LEQ !DirCount! if %CertID% LEQ 20 (
if !CertID! == 1 set CertName=!V1!
if !CertID! == 2 set CertName=!V2!
if !CertID! == 3 set CertName=!V3!
if !CertID! == 4 set CertName=!V4!
if !CertID! == 5 set CertName=!V5!
if !CertID! == 6 set CertName=!V6!
if !CertID! == 7 set CertName=!V7!
if !CertID! == 8 set CertName=!V8!
if !CertID! == 9 set CertName=!V9!
if !CertID! == 10 set CertName=!V10!
if !CertID! == 11 set CertName=!V11!
if !CertID! == 12 set CertName=!V12!
if !CertID! == 13 set CertName=!V13!
if !CertID! == 14 set CertName=!V14!
if !CertID! == 15 set CertName=!V15!
if !CertID! == 16 set CertName=!V16!
if !CertID! == 17 set CertName=!V17!
if !CertID! == 18 set CertName=!V18!
if !CertID! == 19 set CertName=!V19!
if !CertID! == 20 set CertName=!V20!
) else (
echo Invalid Selection, must be 1-!%DirCount%! and Less than or equal to 20
echo.
goto :PickCertName
)
:ValidCertName
if exist "%CertName%\%CertName%.pem" (
set /p CertConfirm=Are you sure you want to create a new SSH2 key "%CertName%"^(KEY ALREADY EXISTS^)^(y,n^)[y]?:
) else (
set /p CertConfirm=Are you sure you want to create a new SSH2 key "%CertName%"^(y,n^)[y]?:
)
if "%CertConfirm%" == "" set CertConfirm=y
if not "%CertConfirm%" == "y" if not "%CertConfirm%" == "Y" (
echo You elected NOT to create the 509 private key "%CertName%"
pause
goto :eof
)
:CertNameEntered
%OpenSSLExe% pkcs12 -in "%CertName%\%CertName%.pfx" -out "%CertName%\%CertName%.pem"
echo.
echo The following file has been created:
echo PEM Key set - %CertName%.pem
echo.
pause
:eof