Skip to content

Commit

Permalink
Continues the create new database feature, feature turned off till co…
Browse files Browse the repository at this point in the history
…mplete
  • Loading branch information
dannygb committed Apr 14, 2019
1 parent f9b3c7b commit 811d065
Show file tree
Hide file tree
Showing 16 changed files with 484 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
build/

/.project
/.vscode

*.user
*.log
*.err
6 changes: 5 additions & 1 deletion KeePit/KeePit.pro
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SOURCES += main.cpp \
hashedblockstream.cpp \
passwordentry.cpp \
readxmlfile.cpp \
writexmlfile.cpp \
salsa20.cpp \
sha256.cpp \
tinyxml2.cpp \
Expand Down Expand Up @@ -147,6 +148,7 @@ SOURCES += main.cpp \
aes.cpp \
filehandler.cpp \
bytestream.cpp \
hexx.cpp

RESOURCES += KeePit.qrc

Expand Down Expand Up @@ -176,6 +178,7 @@ HEADERS += \
hashedblockstream.h \
passwordentry.h \
readxmlfile.h \
writexmlfile.h \
salsa20.h \
sha256.h \
tinyxml2.h \
Expand Down Expand Up @@ -323,7 +326,8 @@ HEADERS += \
aes.h \
filehandler.h \
bytestream.h \
stdafx.h
stdafx.h \
hexx.h

LIBS += -L$$OUT_PWD/../ziplib/ -lziplib

Expand Down
8 changes: 8 additions & 0 deletions KeePit/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "base64.h"
#include <iostream>
#include <string.h>

static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Expand All @@ -34,6 +35,13 @@ Base64::Base64()
{
}

std::vector<char> Base64::base64_encode(std::string const& string) {
const char * buf = string.c_str();
std::string bStr = Base64::base64_encode(buf, string.length());
std::vector<char> data(bStr.begin(), bStr.end());
return data;
}

/// \brief Base64::base64_encode
/// Base64 encodes the given pointer to the char array
/// \param buf The buffer to encode
Expand Down
1 change: 1 addition & 0 deletions KeePit/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Base64 {

public:
Base64();
std::vector<char> base64_encode(std::string const& string);
std::string base64_encode(char const* buf, unsigned int bufLen);
std::vector<char> base64_decode(std::string const&);
};
Expand Down
5 changes: 5 additions & 0 deletions KeePit/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "passwordentry.h"
#include "base64.h"
#include "readkeyfile.h"
#include "writexmlfile.h"
#include "filehandler.h"
#include "bytestream.h"
#include "../ziplib/GZipHelper.h"
Expand Down Expand Up @@ -104,6 +105,10 @@ Database::Database(QObject *parent) :
Database::~Database() {
}

void Database::createNewDatabase(QString filePath) {
WriteXmlFile::CreateNewDatabase(filePath);
}

///
/// \brief Database::deleteFile
/// \param filePath
Expand Down
1 change: 1 addition & 0 deletions KeePit/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Database : public QObject
PasswordEntryModel* createModel();
Q_INVOKABLE void loadHome();
Q_INVOKABLE void deleteFile(QString);
Q_INVOKABLE void createNewDatabase(QString);

Q_SIGNALS:
void error(QString msg);
Expand Down
96 changes: 96 additions & 0 deletions KeePit/hexx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* This file is part of KeePit
*
* Copyright (C) 2016-2018 Dan Beavon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "hexx.h"

QString Hex::ByteArrayToHexString(QByteArray array)
{
int nLen = array.size();
if(nLen == 0) return QString();

QString sb;

unsigned char bt;
unsigned char btHigh;
unsigned char btLow;

for(int i = 0; i < nLen; ++i)
{
bt = array[i];
btHigh = bt; btHigh >>= 4;
btLow = (unsigned char)(bt & 0x0F);

if(btHigh >= 10) sb.append((char)('A' + btHigh - 10));
else sb.append((char)('0' + btHigh));

if(btLow >= 10) sb.append((char)('A' + btLow - 10));
else sb.append((char)('0' + btLow));
}

return sb;
}

QByteArray Hex::HexStringToByteArray(QString strHex)
{
std::vector<char> bytes;
std::string hex = strHex.toStdString();

for (unsigned int i = 0; i < hex.length(); i += 2) {
std::string byteString = hex.substr(i, 2);
char byte = (char) strtol(byteString.c_str(), NULL, 16);
bytes.push_back(byte);
}

QByteArray qb(reinterpret_cast<const char*>(bytes.data()), bytes.size()); // = new QByteArray(reinterpret_cast<const char*>(bytes.data()), bytes.size());
return qb;

/*int nStrLen = strHex.length();
const char *data = strHex.toStdString().c_str();
unsigned char *pb = new unsigned char[nStrLen / 2];
unsigned char bt;
char ch;
for(int i = 0; i < nStrLen; i += 2)
{
ch = data[i];
if((ch >= '0') && (ch <= '9'))
bt = (unsigned char)(ch - '0');
else if((ch >= 'a') && (ch <= 'f'))
bt = (unsigned char)(ch - 'a' + 10);
else if((ch >= 'A') && (ch <= 'F'))
bt = (unsigned char)(ch - 'A' + 10);
else { bt = 0; }
bt <<= 4;
ch = data[i + 1];
if((ch >= '0') && (ch <= '9'))
bt += (unsigned char)(ch - '0');
else if((ch >= 'a') && (ch <= 'f'))
bt += (unsigned char)(ch - 'a' + 10);
else if((ch >= 'A') && (ch <= 'F'))
bt += (unsigned char)(ch - 'A' + 10);
pb[i >> 1] = bt;
}
return QByteArray(reinterpret_cast<const char*>(pb));*/
}
33 changes: 33 additions & 0 deletions KeePit/hexx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* This file is part of KeePit
*
* Copyright (C) 2016-2018 Dan Beavon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef HEX_H
#define HEX_H

#include <QString>

class Hex
{
public:
Hex();
static QString ByteArrayToHexString(QByteArray array);
static QByteArray HexStringToByteArray(QString strHex);
};

#endif //HEX_H
29 changes: 13 additions & 16 deletions KeePit/qml/CreateDatabase.qml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ Item {
topMargin: pageHeader.height + units.gu(2)
}

Label {
text: i18n.tr("Database Name")
}

TextField {
id: databaseName
width: parent.width
text: "Q.xml"
}

Label {
text: i18n.tr("Master Password")
}
Expand All @@ -79,26 +89,14 @@ Item {

Label {
text: i18n.tr("Key file")
color: UbuntuColors.darkAubergine
}

TextField {
id: keyfile
readOnly: true
color: UbuntuColors.darkAubergine
width: parent.width
}

Button {
id: create_keyfile
text: i18n.tr("Create Key")
width: parent.width
onClicked: {
//Create an XML key file
//Save to the file application location
}
}

KeySelector {
id: combo
width: parent.width
Expand All @@ -115,16 +113,15 @@ Item {
}
}

/*Button {
Button {
id: save
text: i18n.tr("Save")
width: parent.width
color: UbuntuColors.green
onClicked: {
//Create an XML key file
//Save to the file application location
database.createNewDatabase(appLocation + "/" + databaseName.text)
}
}*/
}
}
}
}
4 changes: 2 additions & 2 deletions KeePit/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ MainView {
id: importer
}

/*CreateDatabase {
CreateDatabase {
id: createDatabase
}*/
}
}

/*Component {
Expand Down
Loading

0 comments on commit 811d065

Please sign in to comment.