实验二 电子公文传输系统安全-进展2

实验二 电子公文传输系统安全-进展2

  • 上周任务完成情况(代码链接,所写文档等)
  • 本周计划

上周任务完成情况(代码链接,所写文档等)

1.向编写的数据库插入关于上述14篇公文的一系列数据,测试前端的运行效果。

INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (1, '关于申请灾后图书馆新书购置资金的请示', '江宁县第一中学办公室', '张三', 0, '2012-07-01', 'documentImg/1.jpg', 'documentFile/1.pdf', 2, '请示', 'documentLyric/1.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (2, '学生代表座谈会议纪要', '校团委办公室', '陈金金', 1, '2020-09-30', 'documentImg/2.jpg', 'documentFile/2.pdf', 14, '会议纪要', 'documentLyric/2.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (3, '关于商洽暑期支教活动的函', '北京电子科技学院办公室', '宋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县教育局关于同意开展暑期支教活动的函', '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, '北京电子科技学院关于关于组织开展2020-2021学年度第一学期团支部考核的通知', '院团委', '刘博雅', 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, '北京电子科技学院2021年春季学期开学工作方案', '北京电子科技学院办公室', '李四', 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, '北京电子科技学院关于开展“学党史、强信念、跟党走”党史学习教育的通知', '院团委', '陈金金', 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, '北京电子科技学院关于开展“我对母亲有话说”主题团日活动的通知', '院团委', '陈金金', 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, '关于开展2020-2021年度首都大学、中职院校“先锋杯”优秀团支部创建工作的通知', '院团委', '陈金金', 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, '关于开展第十七届“挑战杯”全国大学生课外学术科技作品竞赛红色专项活动的通知', '院团委', '陈金金', 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, '关于推荐 李昂 等 4 名同志为入党积极分子的备案报告', '1812团支部', '宋非凡', 1, '2020-10-02', 'documentImg/11.jpg', 'documentFile/11.pdf', 12, '报告', 'documentLyric/11.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (12, '关于推荐蒋嘉豪等8名同志为预备党员发展对象的备案报告', '1812团支部', '宋非凡', 1, '2020-10-02', 'documentImg/12.jpg', 'documentFile/12.pdf', 12, '报告', 'documentLyric/12.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (13, '关于推荐XXX等X名同志为入党积极分子的备案报告', '1812团支部', '宋非凡', 1, '2021-04-24', 'documentImg/13.jpg', 'documentFile/13.pdf', 12, '报告', 'documentLyric/13.txt');
INSERT INTO `index_document`(`id`, `name`, `office`, `person`, `Classification`, `time`, `img`, `file`, `label_id`, `type`, `lyrics`) VALUES (14, '关于推荐XXX等X名同志为预备党员发展对象的备案报告', '1812团支部', '宋非凡', 1, '2021-04-24', 'documentImg/14.jpg', 'documentFile/14.pdf', 12, '报告', 'documentLyric/14.txt');

3.设计了访问控制功能

​ 我们设计了初步的访问控制能力,其主要方式是非涉密人员看不到涉密文件,具体来说是非涉密人员根本就无法从前端页面上看到涉密文件的任何信息,从名字到存储路径。简而言之就是非涉密人员根本不知道涉密文件的存在。

lALPD4PvNOgsqlDNAqPNBaU_1445_675.png

​ 我们目前的加密是对文件存储路径的加密,简而言之就是数据库里只放文件的存储路径,在我们的设计中,服务器应该存放在一间安全的机房里,用户通过安全连接来访问数据库,得到所需公文的路径,进而访问公文。

4.在本地上安装了项目所需环境,并进行了测试

(1)安装依赖库

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

(2)调整本地MySQL

​ 我在部署的时候出现了这个问题:

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

​ 经过王上查阅资料,得知这是由于Mysql 8.0 的部分语法,密码的加密方式发生了改变,在8.0 中的用户密码采用的是cha2 加密方法,Django 对这种加密的密码进行编译导致密码设置错误。

​ 解决方法如下:

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

修改密码以后,重新执行:

python manage.py runserver

(3)写入加密测试代码

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'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' #  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)

下周计划

(1)将加密加入代码
(2)完善界面

posted @ 2022-05-29 21:21  20191204李浩鹏  阅读(73)  评论(0编辑  收藏  举报