Skip to content

Commit de1f31d

Browse files
author
patrickpr
committed
Added pkcs12 options
1 parent 3c94899 commit de1f31d

6 files changed

Lines changed: 172 additions & 12 deletions

File tree

YetAnotherOpensslGui.pro

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ TARGET = YetAnotherOpensslGui
1313
TEMPLATE = app
1414

1515
SOURCES += src/app/main.cpp\
16+
#src/app/cx509extensions.cpp \
17+
src/app/dialogx509extensions.cpp \
1618
src/app/sslmainwindow.cpp \
1719
src/app/sslcertificates.cpp \
1820
src/app/dialoggeneratekey.cpp \
@@ -23,6 +25,8 @@ SOURCES += src/app/main.cpp\
2325
src/app/stackwindow.cpp
2426

2527
HEADERS += src/app/sslmainwindow.h \
28+
#src/app/cx509extensions.h \
29+
src/app/dialogx509extensions.h \
2630
src/app/sslcertificates.h \
2731
src/app/dialoggeneratekey.h \
2832
src/app/dialogsslerrors.h \
@@ -35,6 +39,7 @@ FORMS += src/app/sslmainwindow.ui \
3539
src/app/dialoggeneratekey.ui \
3640
src/app/dialogsslerrors.ui \
3741
src/app/dialogcertdate.ui \
42+
src/app/dialogx509extensions.ui \
3843
src/app/dialogx509v3extention.ui \
3944
src/app/cdialogpkcs12.ui \
4045
src/app/stackwindow.ui

src/app/cdialogpkcs12.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,25 @@ CDialogPKCS12::CDialogPKCS12(SSLCertificates *Certificate, QString Filename, boo
3838
this->ui->pushButtonImportCert->hide();
3939
this->ui->pushButtonImportMain->hide();
4040
this->ui->pushButtonPushAll->hide();
41+
for (unsigned long long i=0; i<this->cert->p12Encrypt.size();i++)
42+
{
43+
this->ui->comboBoxCertEncryption->addItem(QString::fromStdString(this->cert->p12Encrypt[i].second),QVariant(this->cert->p12Encrypt[i].first));
44+
this->ui->comboBoxKeyEncryption->addItem(QString::fromStdString(this->cert->p12Encrypt[i].second),QVariant(this->cert->p12Encrypt[i].first));
45+
}
46+
for (unsigned long long i=0; i<this->cert->p12KeyType.size();i++)
47+
{
48+
this->ui->comboBoxKeyType->addItem(QString::fromStdString(this->cert->p12KeyType[i].second),QVariant(this->cert->p12KeyType[i].first));
49+
}
4150
}
4251
else
4352
{
53+
this->ui->comboBoxCertEncryption->hide();
54+
this->ui->labelCertEncryption->hide();
55+
this->ui->comboBoxKeyEncryption->hide();
56+
this->ui->labelKeyEncryption->hide();
57+
this->ui->comboBoxKeyType->hide();
58+
this->ui->labelKeyType->hide();
59+
4460
this->ui->lineEditPassword->hide();
4561
this->ui->labelPassword->hide();
4662
this->ui->pushButtonLoadCert->hide();
@@ -179,7 +195,37 @@ void CDialogPKCS12::on_pushButtonSaveAs_clicked()
179195
QString pass=ui->lineEditPassword->text();
180196
ui->lineEditPassword->setText(" ");
181197
ui->lineEditPassword->setText("");
182-
switch (this->cert->save_to_pkcs12(file,name.toLocal8Bit().data(),pass.toLocal8Bit().data()))
198+
199+
int keyType,certEncrypt,keyEncrypt = 0;
200+
if (ui->comboBoxKeyType->currentData().canConvert(QMetaType::Int))
201+
{
202+
keyType = ui->comboBoxKeyType->currentData().toInt();
203+
}
204+
else
205+
{
206+
QMessageBox::warning(this,tr("Error in keytype"),tr("Invalid key type : ")+ui->comboBoxKeyType->currentData().toString());
207+
return;
208+
}
209+
if (ui->comboBoxCertEncryption->currentData().canConvert(QMetaType::Int))
210+
{
211+
certEncrypt = ui->comboBoxCertEncryption->currentData().toInt();
212+
}
213+
else
214+
{
215+
QMessageBox::warning(this,tr("Error in keytype"),tr("Invalid key type : ")+ui->comboBoxCertEncryption->currentData().toString());
216+
return;
217+
}
218+
if (ui->comboBoxKeyEncryption->currentData().canConvert(QMetaType::Int))
219+
{
220+
keyEncrypt = ui->comboBoxKeyEncryption->currentData().toInt();
221+
}
222+
else
223+
{
224+
QMessageBox::warning(this,tr("Error in keytype"),tr("Invalid key type : ")+ui->comboBoxKeyEncryption->currentData().toString());
225+
return;
226+
}
227+
228+
switch (this->cert->save_to_pkcs12(file,name.toLocal8Bit().data(),pass.toLocal8Bit().data(),keyEncrypt,certEncrypt,0,0,keyType))
183229
{
184230
case 0:
185231
QMessageBox::information(this,tr("Saved"),tr("File saved"));

src/app/cdialogpkcs12.ui

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>492</width>
10-
<height>411</height>
10+
<height>471</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -152,7 +152,7 @@
152152
<property name="geometry">
153153
<rect>
154154
<x>20</x>
155-
<y>370</y>
155+
<y>430</y>
156156
<width>461</width>
157157
<height>31</height>
158158
</rect>
@@ -194,6 +194,75 @@
194194
</item>
195195
</layout>
196196
</widget>
197+
<widget class="QComboBox" name="comboBoxKeyType">
198+
<property name="geometry">
199+
<rect>
200+
<x>20</x>
201+
<y>360</y>
202+
<width>90</width>
203+
<height>22</height>
204+
</rect>
205+
</property>
206+
</widget>
207+
<widget class="QLabel" name="labelKeyType">
208+
<property name="geometry">
209+
<rect>
210+
<x>20</x>
211+
<y>340</y>
212+
<width>80</width>
213+
<height>16</height>
214+
</rect>
215+
</property>
216+
<property name="text">
217+
<string>Private key flag</string>
218+
</property>
219+
</widget>
220+
<widget class="QLabel" name="labelKeyEncryption">
221+
<property name="geometry">
222+
<rect>
223+
<x>22</x>
224+
<y>383</y>
225+
<width>80</width>
226+
<height>16</height>
227+
</rect>
228+
</property>
229+
<property name="text">
230+
<string>Key encryption</string>
231+
</property>
232+
</widget>
233+
<widget class="QLabel" name="labelCertEncryption">
234+
<property name="geometry">
235+
<rect>
236+
<x>130</x>
237+
<y>340</y>
238+
<width>91</width>
239+
<height>16</height>
240+
</rect>
241+
</property>
242+
<property name="text">
243+
<string>Cert encryption</string>
244+
</property>
245+
</widget>
246+
<widget class="QComboBox" name="comboBoxKeyEncryption">
247+
<property name="geometry">
248+
<rect>
249+
<x>20</x>
250+
<y>402</y>
251+
<width>201</width>
252+
<height>22</height>
253+
</rect>
254+
</property>
255+
</widget>
256+
<widget class="QComboBox" name="comboBoxCertEncryption">
257+
<property name="geometry">
258+
<rect>
259+
<x>130</x>
260+
<y>360</y>
261+
<width>231</width>
262+
<height>22</height>
263+
</rect>
264+
</property>
265+
</widget>
197266
</widget>
198267
<resources/>
199268
<connections/>

src/app/sslcertificates.cpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,20 +1116,45 @@ int SSLCertificates::get_key_params(keyTypes* keytype,std::string &keyTypeString
11161116
return 1;
11171117
}
11181118

1119-
int SSLCertificates::save_to_pkcs12(FILE *file, char* name,char* pass)
1119+
/**
1120+
* @brief SSLCertificates::save_to_pkcs12
1121+
* @param file FILE Handler to file
1122+
* @param name char* Friendly name of p12
1123+
* @param pass char* password
1124+
* @param keyEcrypt int Key encryption NID or 0 for default
1125+
* @param certEcrypt int Certificate encryption NID or 0 for default
1126+
* @param keyIterations int Number of key iterations or 0 for default (PKCS12_DEFAULT_ITER)
1127+
* @param macIterations int Number of MAC iterations or 0 for default (1)
1128+
* @parma keyType int 0 = none, KEY_SIG = Signature key, KEY_EX = Export key
1129+
* @return int 1=error generating key, 2=error saving file, 0=OK
1130+
*/
1131+
int SSLCertificates::save_to_pkcs12(FILE *file, char* name,char* pass,
1132+
int keyEcrypt, int certEcrypt, int keyIterations, int macIterations, int keyType )
11201133
{
11211134
PKCS12 *newkey;
1135+
if (keyIterations == 0 ) keyIterations = PKCS12_DEFAULT_ITER;
1136+
switch (keyType)
1137+
{
1138+
case 0: break;
1139+
case KEY_SIG : break;
1140+
case KEY_EX : break;
1141+
default:
1142+
// Error message TODO
1143+
return 1;
1144+
break;
1145+
}
1146+
11221147
newkey = PKCS12_create(
11231148
pass, //char *pass
11241149
name, // char *name
11251150
this->pkey, //EVP_PKEY *pkey
11261151
this->x509, //X509 *cert,
11271152
this->ca, //STACK_OF(X509) *ca,
1128-
0, // int nid_key
1129-
0, // int nid_cert
1130-
PKCS12_DEFAULT_ITER, // int iter
1131-
0, // int mac_iter
1132-
NID_key_usage); // int keytype
1153+
keyEcrypt, // int nid_key
1154+
certEcrypt, // int nid_cert
1155+
keyIterations, // int iter
1156+
macIterations, // int mac_iter
1157+
keyType); // int keytype
11331158
if (newkey==nullptr)
11341159
{
11351160
this->get_ssl_errors();

src/app/sslcertificates.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,29 @@ class SSLCertificates
182182
* check ssl errors
183183
*/
184184
int set_cert_PEM(const char* Skey, const char *password=nullptr);
185+
186+
std::vector<std::pair<int,std::string>> p12Encrypt =
187+
{{0,"Default"},
188+
{NID_pbe_WithSHA1And3_Key_TripleDES_CBC,LN_pbe_WithSHA1And3_Key_TripleDES_CBC},
189+
{NID_pbe_WithSHA1And2_Key_TripleDES_CBC,LN_pbe_WithSHA1And2_Key_TripleDES_CBC},
190+
{NID_pbe_WithSHA1And128BitRC4,LN_pbe_WithSHA1And128BitRC4},
191+
{NID_pbe_WithSHA1And40BitRC4,LN_pbe_WithSHA1And40BitRC4}
192+
};
193+
194+
std::vector<std::pair<int,std::string>> p12KeyType =
195+
{{0,"None"},
196+
{KEY_EX, "Exchange key"},
197+
{KEY_SIG, "Signature key"}
198+
};
185199
/**
186200
* @brief save_to_pkcs12 : save cert and key to pkcs12 file
187201
* @param file : opened file descriptor
188202
* @param name : fancy name of P12
189203
* @param pass : password
190204
* @return 0: success, 1: error creating p12 struct, 2 : error writing p12
191205
*/
192-
int save_to_pkcs12(FILE* file, char *name, char *pass);
206+
int save_to_pkcs12(FILE* file, char *name, char *pass,
207+
int keyEcrypt = 0, int certEcrypt = 0, int keyIterations = 0, int macIterations = 0, int keyType = 0 );
193208
/**
194209
* @brief find_friendly_name : copy of SSL Demo pkread.c to find name of pkcs12 structure
195210
* @param p12 : pkcs12 structure

src/app/sslmainwindow.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#include "cdialogpkcs12.h"
2626
#include "stackwindow.h"
2727

28-
#define YAOGVERSION "1.1.1"
29-
#define YAOGVERSIONF "01010100"
28+
#define YAOGVERSION "1.1.2"
29+
#define YAOGVERSIONF "01010200"
3030
#define YAOGPLATFORM "W64"
3131
#define UPDATESRC "https://www.proy.org/yaog/update.php"
3232

0 commit comments

Comments
 (0)