Skip to content

Commit

Permalink
Fix tlcp client; refactor SM2&SM3&SM4
Browse files Browse the repository at this point in the history
Add common api for SM2 key, sm2_key_new_from_raw_pub(), etc.
SM4 encryption add more modes, including CFB, OFB and CTR.
Re-sign test ca and subca certs, set valid days to 36500.
CI add support for macos.
  • Loading branch information
dongbeiouba committed Jul 8, 2024
1 parent a0d9549 commit e2f45e9
Show file tree
Hide file tree
Showing 39 changed files with 1,876 additions and 1,378 deletions.
33 changes: 24 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ jobs:
run: |
clang-format-15 --Werror --dry-run *.cpp *.h
build-on-linux:
runs-on: ubuntu-latest
unix:
strategy:
fail-fast: false
matrix:
os: [
macos-12,
macos-13,
ubuntu-20.04,
ubuntu-22.04,
]
runs-on: ${{ matrix.os }}
steps:
- name: checkout tongsuo
uses: actions/checkout@v3
Expand All @@ -37,24 +46,30 @@ jobs:
- name: build Tongsuo
working-directory: ./Tongsuo
run: |
./config --banner=Configured --prefix=${RUNNER_TEMP}/tongsuo enable-ntls
./config --banner=Configured --prefix=${RUNNER_TEMP}/tongsuo --libdir=${RUNNER_TEMP}/tongsuo/lib enable-ntls
make -s -j4
make install
- uses: actions/checkout@v3
- name: install QT
uses: jurplel/install-qt-action@v3
uses: jurplel/install-qt-action@v4
with:
version: 6.2.4
version: 6.4.3

- name: build tsapp
run: |
TONGSUO_HOME=${RUNNER_TEMP}/tongsuo PREFIX=${RUNNER_TEMP}/tsapp qmake
make -s -j4
make install
build-on-windows:
runs-on: windows-latest
windows:
strategy:
fail-fast: false
matrix:
os:
- windows-2019
- windows-2022
runs-on: ${{ matrix.os }}
steps:
- uses: ilammy/msvc-dev-cmd@v1
with:
Expand Down Expand Up @@ -82,9 +97,9 @@ jobs:
- uses: actions/checkout@v3
- name: install QT
uses: jurplel/install-qt-action@v3
uses: jurplel/install-qt-action@v4
with:
version: 6.2.4
version: 6.4.3

- name: build tsapp
shell: cmd
Expand Down
8 changes: 5 additions & 3 deletions TongsuoToolbox_v01.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SOURCES += \
main.cpp \
mainwindow.cpp \
randnum.cpp \
sm2.cpp \
sm2cert.cpp \
sm2encrypt.cpp \
sm2key.cpp \
Expand All @@ -28,6 +29,7 @@ HEADERS += \
home.h \
mainwindow.h \
randnum.h \
sm2.h \
sm2cert.h \
sm2encrypt.h \
sm2key.h \
Expand All @@ -42,17 +44,17 @@ target.path = $$(PREFIX)
!isEmpty(target.path): INSTALLS += target

win32: LIBS += -ladvapi32 -lcrypt32 -lgdi32 -luser32 -lws2_32 -L$$(TONGSUO_HOME)/lib -llibcrypto
else:unix: LIBS += -L$$(TONGSUO_HOME)/lib64 -lcrypto
else:unix: LIBS += -L$$(TONGSUO_HOME)/lib -lcrypto

win32: LIBS += -ladvapi32 -lcrypt32 -lgdi32 -luser32 -lws2_32 -L$$(TONGSUO_HOME)/lib -llibssl
else:unix: LIBS += -L$$(TONGSUO_HOME)/lib64 -lssl
else:unix: LIBS += -L$$(TONGSUO_HOME)/lib -lssl

INCLUDEPATH += $$(TONGSUO_HOME)/include
DEPENDPATH += $$(TONGSUO_HOME)/include

win32-g++: PRE_TARGETDEPS += $$(TONGSUO_HOME)/lib/libcrypto.lib.a
else:win32:!win32-g++: PRE_TARGETDEPS += $$(TONGSUO_HOME)/lib/libcrypto.lib
else:unix: PRE_TARGETDEPS += $$(TONGSUO_HOME)/lib64/libcrypto.a
else:unix: PRE_TARGETDEPS += $$(TONGSUO_HOME)/lib/libcrypto.a

FORMS += \
home.ui \
Expand Down
2 changes: 1 addition & 1 deletion certs.qrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<RCC>
<qresource prefix="/">
<file>certs/subca.pem</file>
<file>certs/subca_pkey.pem</file>
<file>certs/subca.key</file>
</qresource>
</RCC>
5 changes: 5 additions & 0 deletions certs/ca.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQgTSHZtff0A3YHhojG
HKIu0odvPip6+39lsguxDH3m+TmhRANCAARC7ZCfZAaqCbMEh1K3pEj2S6/ty2yN
C6x0zIbyxq+mib7qTssQcLrsPMe1EGb2FZQpGk4L9mOzBNlijoi1ocb5
-----END PRIVATE KEY-----
21 changes: 11 additions & 10 deletions certs/ca.pem
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
-----BEGIN CERTIFICATE-----
MIIB2zCCAYKgAwIBAgIBADAKBggqgRzPVQGDdTBFMQswCQYDVQQGEwJBQjELMAkG
MIIB3jCCAYSgAwIBAgIBAjAKBggqgRzPVQGDdTBFMQswCQYDVQQGEwJBQjELMAkG
A1UECAwCQ0QxCzAJBgNVBAoMAkdIMQswCQYDVQQLDAJJSjEPMA0GA1UEAwwGQ0Eg
U00yMB4XDTIzMTAyMjA4MTYzNVoXDTI0MTAyMTA4MTYzNVowRTELMAkGA1UEBhMC
QUIxCzAJBgNVBAgMAkNEMQswCQYDVQQKDAJHSDELMAkGA1UECwwCSUoxDzANBgNV
BAMMBkNBIFNNMjBZMBMGByqGSM49AgEGCCqBHM9VAYItA0IABGDEBzKqxehinDE1
yVmhtBg4RZl3yMdYbSQ1YCS4Oq39UpYnIPBQZJtFVcp/mzYkEatAFH3bULzZN9i2
tYKVG9OjYzBhMB0GA1UdDgQWBBSGjjM6h6hZvgui1qC/aWzcwA8DxTAfBgNVHSME
GDAWgBSGjjM6h6hZvgui1qC/aWzcwA8DxTAPBgNVHRMBAf8EBTADAQH/MA4GA1Ud
DwEB/wQEAwIBhjAKBggqgRzPVQGDdQNHADBEAiAG1lSJPjiucZM7Ono6Ym4cZRJ6
FkYkRCbmUsA7KGUurAIgPB75xE9nBCvjOA5mX0w6qTIxyca9ZZQW/fXKiD7rc9w=
-----END CERTIFICATE-----
U00yMCAXDTI0MDcwNzA0Mjc0NVoYDzIxMjQwNjEzMDQyNzQ1WjBFMQswCQYDVQQG
EwJBQjELMAkGA1UECAwCQ0QxCzAJBgNVBAoMAkdIMQswCQYDVQQLDAJJSjEPMA0G
A1UEAwwGQ0EgU00yMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEQu2Qn2QGqgmz
BIdSt6RI9kuv7ctsjQusdMyG8savpom+6k7LEHC67DzHtRBm9hWUKRpOC/ZjswTZ
Yo6ItaHG+aNjMGEwHQYDVR0OBBYEFGPkDCglafjEeeT2wufS/PqKqSP+MB8GA1Ud
IwQYMBaAFGPkDCglafjEeeT2wufS/PqKqSP+MA8GA1UdEwEB/wQFMAMBAf8wDgYD
VR0PAQH/BAQDAgGGMAoGCCqBHM9VAYN1A0gAMEUCIQDOKNIcpCOnL/qFC9nYHSY0
fHWiGgZLLVFkamCN0meRNgIgUfW1xK+7rZddJSHqJKIeHJp28PlKBXY8oIuGhhEz
EqQ=
-----END CERTIFICATE-----
5 changes: 0 additions & 5 deletions certs/ca_pkey.pem

This file was deleted.

5 changes: 5 additions & 0 deletions certs/subca.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQgC2yI3oPT4cnM8fGf
J/emyP9/Qr87/x1RO5sNMnm5ioqhRANCAAR73c9xN7bdOrqUQhe/77qxwerRbzZe
wZ65DXOMgIztuCiCEQLh0CfjPLV98LxHbUhTc1EJWhDGofTqh8VFQNYj
-----END PRIVATE KEY-----
22 changes: 11 additions & 11 deletions certs/subca.pem
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
-----BEGIN CERTIFICATE-----
MIIB4jCCAYigAwIBAgIBADAKBggqgRzPVQGDdTBFMQswCQYDVQQGEwJBQjELMAkG
MIIB4zCCAYqgAwIBAgIBAjAKBggqgRzPVQGDdTBFMQswCQYDVQQGEwJBQjELMAkG
A1UECAwCQ0QxCzAJBgNVBAoMAkdIMQswCQYD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9BoJkIiFNTb/gbPdjS
0kQ4AdEHkQ==
-----END CERTIFICATE-----
5 changes: 0 additions & 5 deletions certs/subca_pkey.pem

This file was deleted.

4 changes: 2 additions & 2 deletions home.ui
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
Expand Down
Binary file modified images/HomeBackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#include "mainwindow.h"
#include <openssl/ssl.h>
#include <QApplication>

BIO *bio_err = NULL;

int main(int argc, char *argv[])
{
if (!OPENSSL_init_ssl(OPENSSL_INIT_NO_LOAD_CONFIG, NULL))
return 1;

bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);

QApplication a(argc, argv);
MainWindow w;
w.show();
Expand Down
12 changes: 6 additions & 6 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
/* 主界面设置 */
this->setGeometry(480, 200, 800, 480);
this->setGeometry(100, 100, 1200, 800);
this->setWindowIcon(QIcon(":/images/TongSuoIcon.png"));
this->setWindowTitle(QString("TongSuo"));
this->setWindowTitle(QString("铜锁密码工具箱"));
/* widget 小部件实例化 */
widget = new QWidget(this);
/* 设置居中 */
Expand Down Expand Up @@ -40,11 +40,11 @@ MainWindow::MainWindow(QWidget *parent)
strListWidgetList << "首页"
<< "随机数生成"
<< "SM2密钥生成"
<< "SM2加解密"
<< "SM3哈希"
<< "SM2签名验签"
<< "SM2加解密"
<< "SM3杂凑"
<< "SM4加解密"
<< "SM2签发证书"
<< "双证书签发"
<< "TLCP客户端";
for (int i = 0; i < 9; i++) {
/* listWidget 插入项 */
Expand All @@ -54,9 +54,9 @@ MainWindow::MainWindow(QWidget *parent)
stackedWidget->addWidget(tsHome);
stackedWidget->addWidget(rdNum);
stackedWidget->addWidget(sm2Key);
stackedWidget->addWidget(sm2SignVerify);
stackedWidget->addWidget(sm2Encry);
stackedWidget->addWidget(sm3Hash);
stackedWidget->addWidget(sm2SignVerify);
stackedWidget->addWidget(sm4Encry);
stackedWidget->addWidget(sm2Cer);
stackedWidget->addWidget(tlcpClient);
Expand Down
40 changes: 25 additions & 15 deletions randnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ RandNum::RandNum(QWidget *parent)
, ui(new Ui::RandNum)
{
ui->setupUi(this);
/* 限制只能输入整数且范围为[1,256]*/
/* 限制只能输入整数且范围为[1,128 * 1024]*/
QIntValidator *aIntValidator = new QIntValidator;
aIntValidator->setRange(1, 256);
aIntValidator->setRange(1, 131072);
ui->lineEditInput->setValidator(aIntValidator);
}

Expand All @@ -19,22 +19,32 @@ RandNum::~RandNum()

void RandNum::on_pushButtonGen_clicked()
{
/* 获取用户输入 */
QString inputByte = this->ui->lineEditInput->text();
int randNumByte = inputByte.toInt();
std::unique_ptr<unsigned char> buf(new unsigned char[randNumByte]);
/* 获取随机数输出栏 */
QTextBrowser *outputNum = this->ui->textBrowserOutput;
/* 调用随机数生成函数 */
int ret = RAND_bytes(buf.get(), randNumByte);
size_t len = randNumByte * 2 + 1;
std::vector<unsigned char> buf;
std::vector<char> str;

buf.reserve(randNumByte);

int ret = RAND_bytes((unsigned char *) buf.data(), randNumByte);

if (ret == 0) {
/* 生成失败弹窗 */
getError();
return;
printTSError();
} else {
/* 生成成功将结果写到输出框 */
std::shared_ptr<char> outBuf(OPENSSL_buf2hexstr(buf.get(), randNumByte),
[](char *outbuf) { OPENSSL_free(outbuf); });
outputNum->setText(QString(outBuf.get()));
str.reserve(len);

if (OPENSSL_buf2hexstr_ex(str.data(),
len,
NULL,
(unsigned char *) buf.data(),
randNumByte,
'\0')
!= 1)
return;

this->ui->textBrowserOutput->setText(QString::fromStdString(std::string(str.data(), len)));
}

return;
}
1 change: 1 addition & 0 deletions randnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "tserror.h"
#include <memory>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#include <QIntValidator>
#include <QLineEdit>
Expand Down
Loading

0 comments on commit e2f45e9

Please sign in to comment.