當(dāng)前位置:首頁 > IT技術(shù) > 其他 > 正文

實(shí)驗(yàn)二 電子公文傳輸系統(tǒng)安全-進(jìn)展2
2022-05-29 22:30:33

實(shí)驗(yàn)二 電子公文傳輸系統(tǒng)安全-進(jìn)展2

  • 上周任務(wù)完成情況(代碼鏈接,所寫文檔等)
  • 本周計(jì)劃

上周任務(wù)完成情況(代碼鏈接,所寫文檔等)

1.向編寫的數(shù)據(jù)庫插入關(guān)于上述14篇公文的一系列數(shù)據(jù),測(cè)試前端的運(yùn)行效果。

INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (1, '關(guān)于申請(qǐng)災(zāi)后圖書館新書購置資金的請(qǐng)示', '江寧縣第一中學(xué)辦公室', '張三', 0, '2012-07-01', 'documentImg/1.jpg', 'documentFile/1.pdf', 2, '請(qǐng)示', 'documentLyric/1.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (2, '學(xué)生代表座談會(huì)議紀(jì)要', '校團(tuán)委辦公室', '陳金金', 1, '2020-09-30', 'documentImg/2.jpg', 'documentFile/2.pdf', 14, '會(huì)議紀(jì)要', 'documentLyric/2.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (3, '關(guān)于商洽暑期支教活動(dòng)的函', '北京電子科技學(xué)院辦公室', '宋XX', 0, '2021-06-15', 'documentImg/3.jpg', 'documentFile/3.pdf', 13, '函', 'documentLyric/3.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (4, 'X省X縣教育局關(guān)于同意開展暑期支教活動(dòng)的函', 'X省X縣教育局辦公室', '王XX', 0, '2021-06-20', 'documentImg/4.jpg', 'documentFile/4.pdf', 13, '函', 'documentLyric/4.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (5, '北京電子科技學(xué)院關(guān)于關(guān)于組織開展2020-2021學(xué)年度第一學(xué)期團(tuán)支部考核的通知', '院團(tuán)委', '劉博雅', 0, '2021-02-20', 'documentImg/5.jpg', 'documentFile/5.pdf', 7, '通知', 'documentLyric/5.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (6, '北京電子科技學(xué)院2021年春季學(xué)期開學(xué)工作方案', '北京電子科技學(xué)院辦公室', '李四', 0, '2021-02-18', 'documentImg/6.jpg', 'documentFile/6.pdf', 9, '公告', 'documentLyric/6.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (7, '北京電子科技學(xué)院關(guān)于開展“學(xué)黨史、強(qiáng)信念、跟黨走”黨史學(xué)習(xí)教育的通知', '院團(tuán)委', '陳金金', 0, '2021-04-28', 'documentImg/7.jpg', 'documentFile/7.pdf', 7, '通知', 'documentLyric/7.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (8, '北京電子科技學(xué)院關(guān)于開展“我對(duì)母親有話說”主題團(tuán)日活動(dòng)的通知', '院團(tuán)委', '陳金金', 0, '2021-04-15', 'documentImg/8.jpg', 'documentFile/8.pdf', 7, '通知', 'documentLyric/8.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (9, '關(guān)于開展2020-2021年度首都大學(xué)、中職院?!跋蠕h杯”優(yōu)秀團(tuán)支部創(chuàng)建工作的通知', '院團(tuán)委', '陳金金', 0, '2020-11-11', 'documentImg/9.jpg', 'documentFile/9.pdf', 7, '通知', 'documentLyric/9.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (10, '關(guān)于開展第十七屆“挑戰(zhàn)杯”全國大學(xué)生課外學(xué)術(shù)科技作品競(jìng)賽紅色專項(xiàng)活動(dòng)的通知', '院團(tuán)委', '陳金金', 0, '2021-01-18', 'documentImg/10.jpg', 'documentFile/10.pdf', 7, '通知', 'documentLyric/10.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (11, '關(guān)于推薦 李昂 等 4 名同志為入黨積極分子的備案報(bào)告', '1812團(tuán)支部', '宋非凡', 1, '2020-10-02', 'documentImg/11.jpg', 'documentFile/11.pdf', 12, '報(bào)告', 'documentLyric/11.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (12, '關(guān)于推薦蔣嘉豪等8名同志為預(yù)備黨員發(fā)展對(duì)象的備案報(bào)告', '1812團(tuán)支部', '宋非凡', 1, '2020-10-02', 'documentImg/12.jpg', 'documentFile/12.pdf', 12, '報(bào)告', 'documentLyric/12.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (13, '關(guān)于推薦XXX等X名同志為入黨積極分子的備案報(bào)告', '1812團(tuán)支部', '宋非凡', 1, '2021-04-24', 'documentImg/13.jpg', 'documentFile/13.pdf', 12, '報(bào)告', 'documentLyric/13.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (14, '關(guān)于推薦XXX等X名同志為預(yù)備黨員發(fā)展對(duì)象的備案報(bào)告', '1812團(tuán)支部', '宋非凡', 1, '2021-04-24', 'documentImg/14.jpg', 'documentFile/14.pdf', 12, '報(bào)告', 'documentLyric/14.txt');

3.設(shè)計(jì)了訪問控制功能

? 我們?cè)O(shè)計(jì)了初步的訪問控制能力,其主要方式是非涉密人員看不到涉密文件,具體來說是非涉密人員根本就無法從前端頁面上看到涉密文件的任何信息,從名字到存儲(chǔ)路徑。簡(jiǎn)而言之就是非涉密人員根本不知道涉密文件的存在。

lALPD4PvNOgsqlDNAqPNBaU_1445_675.png

? 我們目前的加密是對(duì)文件存儲(chǔ)路徑的加密,簡(jiǎn)而言之就是數(shù)據(jù)庫里只放文件的存儲(chǔ)路徑,在我們的設(shè)計(jì)中,服務(wù)器應(yīng)該存放在一間安全的機(jī)房里,用戶通過安全連接來訪問數(shù)據(jù)庫,得到所需公文的路徑,進(jìn)而訪問公文。

4.在本地上安裝了項(xiàng)目所需環(huán)境,并進(jìn)行了測(cè)試

(1)安裝依賴庫

pip3 install filetype
pip3 install django-sslserver
pip3 install gmssl
pip3 install secrets

(2)調(diào)整本地MySQL

? 我在部署的時(shí)候出現(xiàn)了這個(gè)問題:

Django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password...

? 經(jīng)過王上查閱資料,得知這是由于Mysql 8.0 的部分語法,密碼的加密方式發(fā)生了改變,在8.0 中的用戶密碼采用的是cha2 加密方法,Django 對(duì)這種加密的密碼進(jìn)行編譯導(dǎo)致密碼設(shè)置錯(cuò)誤。

? 解決方法如下:

mysql -u root -p
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword'; 
FLUSH PRIVILEGES; 

修改密碼以后,重新執(zhí)行:

python manage.py runserver

(3)寫入加密測(cè)試代碼

import time
import base64
from gmssl import sm2,sm4
import codecs
SM2_PRIVATE_KEY = '00B9AB0B828FF68872F21A837FC303668428DEA11DCD1B24429D0C99E24EED83D5'
SM2_PUBLIC_KEY = 'B9C9A6E04E9C91F7BA880429273747D7EF5DDEB0BB2FF6317EB00BEF331A83081A6994B8993F3F5D6EADDDB81872266C87C018FB4162F5AF347B483E24620207'
sm2_crypt = sm2.CryptSM2(public_key=SM2_PUBLIC_KEY, private_key=SM2_PRIVATE_KEY)

SM4_KEY = b'3l5butlj26hvv313'
SM4_IV = b'x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00' #  bytes類型
sm4_crypt = sm4.CryptSM4()

def base64_en(png_org,png_en):
    with open(png_org, 'rb') as f:
        image_base64 = str(base64.b64encode(f.read()), encoding='utf-8')
    with open(png_en,'wt') as f_en:
        f_en.write(image_base64)

def base64_de(png_en,png_de):
    with open(png_en,"r") as f:
        imgdata = base64.b64decode(f.read())
    with open(png_de,'wb+') as f_de:
        f_de.write(imgdata)

def sm2_en(png_org,png_en):
    with open(png_org, 'rb') as f:
        image_base64 = base64.b64encode(f.read())
        image_sm2 = str(sm2_crypt.encrypt(image_base64))
    with open(png_en,'wt') as f_en:
        f_en.write(image_sm2)

def sm2_de(png_en,png_de):
    with open(png_en,"r") as f:
        image_sm2 = codecs.escape_decode(bytes(f.read()[2:-1],encoding="utf-8"), "hex-escape")[0]
        image_base64 = sm2_crypt.decrypt(image_sm2)
        imgdata = base64.b64decode(image_base64)
    with open(png_de,'wb') as f_de:
        f_de.write(imgdata)

def sm4_en(png_org,png_en):
    sm4_crypt.set_key(SM4_KEY, sm4.SM4_ENCRYPT)
    time_start = time.time()
    print(time_start)
    with open(png_org, 'rb') as f:
        image_base64 = base64.b64encode(f.read())
        time_1 = time.time()
        print(time_1-time_start)
        image_sm4 = str(sm4_crypt.crypt_ecb(image_base64))
        time_2 = time.time()
        print(time_2 - time_1)
    with open(png_en,'wt') as f_en:
        f_en.write(image_sm4)

def sm4_de(png_en,png_de):
    sm4_crypt.set_key(SM4_KEY, sm4.SM4_DECRYPT)
    with open(png_en,"r") as f:
        image_sm4 = codecs.escape_decode(bytes(f.read()[2:-1],encoding="utf-8"), "hex-escape")[0]
        image_base64 = sm4_crypt.crypt_ecb(image_sm4)
        imgdata = base64.b64decode(image_base64)
    with open(png_de,'wb') as f_de:
        f_de.write(imgdata)


if __name__ == '__main__':
    #f_org ='bas.txt'
    #f_en ='basen.txt'
    #f_de ='basde.txt'
    # f_org = '1.png'
    # f_en = '12321.txt'
    # f_de = '123321.png'
    # pngfile_base64_en(p_org,p_en)
    # pngfile_base64_de(p_en,p_de)
    f_org = 'abc.pdf'
    f_en = '2.txt'
    f_de = 'asdf+z44.pdf'
    #sm2_en(f_org,f_en)
    #sm2_de(f_en,f_de)
    time_start = time.time()
    sm4_en(f_org,f_en)
    time_mid = time.time()
    print(time_mid-time_start)
    sm4_de(f_en,f_de)
    time_end = time.time()
    print(time_end-time_mid)

下周計(jì)劃

(1)將加密加入代碼
(2)完善界面

本文摘自 :https://www.cnblogs.com/

開通會(huì)員,享受整站包年服務(wù)立即開通 >