mirror of
https://github.com/chris2511/xca.git
synced 2026-09-14 11:06:19 +05:00
unify password lengths
This commit is contained in:
parent
6f3932983a
commit
b3cece8ef3
@ -105,7 +105,7 @@ static void handle_option(QString opt)
|
||||
}
|
||||
}
|
||||
|
||||
int read_dump(const char *filename, db_base **dbs, char *md5)
|
||||
int read_dump(const char *filename, db_base **dbs, char *md5, int md5_len)
|
||||
{
|
||||
char *p;
|
||||
int ret = -1, retlen = 0;
|
||||
@ -158,7 +158,7 @@ int read_dump(const char *filename, db_base **dbs, char *md5)
|
||||
if (kv)
|
||||
md5sum = (!strcmp(p, "pwhash")) ? true : false;
|
||||
if (!kv && md5sum) {
|
||||
strncpy(md5, p, 50);
|
||||
strncpy(md5, p, md5_len);
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -58,17 +58,37 @@
|
||||
#include <Qt/qdir.h>
|
||||
#include <widgets/MainWindow.h>
|
||||
|
||||
char pki_key::passwd[40]={0,};
|
||||
char pki_key::oldpasswd[40]={0,};
|
||||
char pki_key::passwd[MAX_PASS_LENGTH]={0,};
|
||||
char pki_key::oldpasswd[MAX_PASS_LENGTH]={0,};
|
||||
|
||||
QString pki_key::passHash = QString();
|
||||
|
||||
QPixmap *pki_key::icon[2]= { NULL, NULL };
|
||||
|
||||
void pki_key::erasePasswd(){
|
||||
for (int i=0; i<40; i++)
|
||||
void pki_key::erasePasswd()
|
||||
{
|
||||
for (int i=0; i<MAX_PASS_LENGTH; i++)
|
||||
passwd[i] = 0;
|
||||
}
|
||||
|
||||
void pki_key::eraseOldPasswd()
|
||||
{
|
||||
for (int i=0; i<MAX_PASS_LENGTH; i++)
|
||||
oldpasswd[i] = 0;
|
||||
}
|
||||
|
||||
void pki_key::setPasswd(const char *pass)
|
||||
{
|
||||
strncpy(passwd, pass, MAX_PASS_LENGTH);
|
||||
passwd[MAX_PASS_LENGTH-1] = '\0';
|
||||
}
|
||||
|
||||
void pki_key::setOldPasswd(const char *pass)
|
||||
{
|
||||
strncpy(oldpasswd, pass, MAX_PASS_LENGTH);
|
||||
oldpasswd[MAX_PASS_LENGTH-1] = '\0';
|
||||
}
|
||||
|
||||
void pki_key::init(int type)
|
||||
{
|
||||
ucount = 0;
|
||||
|
||||
@ -60,7 +60,6 @@
|
||||
#define MAX_KEY_LENGTH 4096
|
||||
#define MAX_PASS_LENGTH 40
|
||||
|
||||
|
||||
class pki_key: public pki_base
|
||||
{
|
||||
|
||||
@ -80,6 +79,9 @@ class pki_key: public pki_base
|
||||
static char passwd[MAX_PASS_LENGTH];
|
||||
static char oldpasswd[MAX_PASS_LENGTH];
|
||||
static void erasePasswd();
|
||||
static void eraseOldPasswd();
|
||||
static void setPasswd(const char *pass);
|
||||
static void setOldPasswd(const char *pass);
|
||||
static QString md5passwd(const char *pass,
|
||||
char *md5 = NULL, int *len = NULL);
|
||||
void generate(int bits, int type, QProgressBar *progress);
|
||||
|
||||
@ -99,7 +99,7 @@ void MainWindow::load_database()
|
||||
|
||||
void MainWindow::import_dbdump()
|
||||
{
|
||||
extern int read_dump(const char *filename, db_base **dbs, char*buf);
|
||||
extern int read_dump(const char *, db_base **, char *, int);
|
||||
char buf[50];
|
||||
|
||||
db_base *dbl[] = { keys, reqs, certs, temps, crls };
|
||||
@ -126,7 +126,7 @@ void MainWindow::import_dbdump()
|
||||
return;
|
||||
pass = buf;
|
||||
try {
|
||||
read_dump(CCHAR(file), dbl, buf);
|
||||
read_dump(CCHAR(file), dbl, buf, 50);
|
||||
//printf("MD5:%s, r:%s\n", CCHAR(pki_key::md5passwd(CCHAR(pass))),buf);
|
||||
if (pki_key::md5passwd(CCHAR(pass)) != buf) {
|
||||
int ret = QMessageBox::warning(this, tr(XCA_TITLE),
|
||||
@ -135,8 +135,9 @@ void MainWindow::import_dbdump()
|
||||
if (ret)
|
||||
return;
|
||||
}
|
||||
strncpy(pki_key::oldpasswd, CCHAR(pass), 40);
|
||||
read_dump(CCHAR(file), dbl, NULL);
|
||||
pki_key::setOldPasswd(CCHAR(pass));
|
||||
read_dump(CCHAR(file), dbl, NULL, 0);
|
||||
pki_key::eraseOldPasswd();
|
||||
} catch (errorEx &err) {
|
||||
Error(err);
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ int MainWindow::initPass()
|
||||
}
|
||||
}
|
||||
if (pki_key::passHash.isEmpty()) {
|
||||
int keylen = passWrite((char *)pki_key::passwd, 25, 0, &p);
|
||||
int keylen = passWrite((char *)pki_key::passwd, MAX_PASS_LENGTH-1, 0, &p);
|
||||
if (keylen < 0)
|
||||
return 0;
|
||||
pki_key::passwd[keylen]='\0';
|
||||
@ -283,7 +283,7 @@ int MainWindow::initPass()
|
||||
tr("Password verify error, please try again"));
|
||||
p.setTitle(tr("Password"));
|
||||
p.setDescription(tr("Please enter the password for unlocking the database"));
|
||||
keylen = passRead(pki_key::passwd, 25, 0, &p);
|
||||
keylen = passRead(pki_key::passwd, MAX_PASS_LENGTH-1, 0, &p);
|
||||
if (keylen < 0)
|
||||
return 0;
|
||||
pki_key::passwd[keylen]='\0';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user