Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Kleopatra
Commits
549b08ed
Commit
549b08ed
authored
Aug 25, 2020
by
Ingo Klöcker
Browse files
Use ChangePinCommand also for OpenPGP cards
parent
49af5da5
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/commands/changepincommand.cpp
View file @
549b08ed
...
...
@@ -11,6 +11,7 @@
#include "cardcommand_p.h"
#include "smartcard/openpgpcard.h"
#include "smartcard/pivcard.h"
#include "smartcard/readerstatus.h"
...
...
@@ -113,6 +114,12 @@ static QString errorMessage(const std::string &keyRef, const QString &errorText)
if
(
keyRef
==
PIVCard
::
pukKeyRef
())
{
return
i18nc
(
"@info"
,
"Changing the PUK failed: %1"
,
errorText
);
}
if
(
keyRef
==
OpenPGPCard
::
adminPinKeyRef
())
{
return
i18nc
(
"@info"
,
"Changing the Admin PIN failed: %1"
,
errorText
);
}
if
(
keyRef
==
OpenPGPCard
::
resetCodeKeyRef
())
{
return
i18nc
(
"@info"
,
"Changing the Reset Code failed: %1"
,
errorText
);
}
return
i18nc
(
"@info"
,
"Changing the PIN failed: %1"
,
errorText
);
}
...
...
@@ -122,6 +129,12 @@ static QString successMessage(const std::string &keyRef)
if
(
keyRef
==
PIVCard
::
pukKeyRef
())
{
return
i18nc
(
"@info"
,
"PUK successfully changed."
);
}
if
(
keyRef
==
OpenPGPCard
::
adminPinKeyRef
())
{
return
i18nc
(
"@info"
,
"Admin PIN changed successfully."
);
}
if
(
keyRef
==
OpenPGPCard
::
resetCodeKeyRef
())
{
return
i18nc
(
"@info"
,
"Reset Code changed successfully."
);
}
return
i18nc
(
"@info"
,
"PIN changed successfully."
);
}
}
...
...
src/smartcard/openpgpcard.cpp
View file @
549b08ed
...
...
@@ -36,6 +36,24 @@ OpenPGPCard::OpenPGPCard(const std::string &serialno): OpenPGPCard()
setSerialNumber
(
serialno
);
}
// static
std
::
string
OpenPGPCard
::
pinKeyRef
()
{
return
std
::
string
(
"OPENPGP.1"
);
}
// static
std
::
string
OpenPGPCard
::
adminPinKeyRef
()
{
return
std
::
string
(
"OPENPGP.3"
);
}
// static
std
::
string
OpenPGPCard
::
resetCodeKeyRef
()
{
return
std
::
string
(
"OPENPGP.2"
);
}
std
::
string
OpenPGPCard
::
sigFpr
()
const
{
return
mMetaInfo
.
value
(
"SIGKEY-FPR"
);
...
...
src/smartcard/openpgpcard.h
View file @
549b08ed
...
...
@@ -23,6 +23,11 @@ class OpenPGPCard: public Card
public:
OpenPGPCard
();
OpenPGPCard
(
const
std
::
string
&
serialno
);
static
std
::
string
pinKeyRef
();
static
std
::
string
adminPinKeyRef
();
static
std
::
string
resetCodeKeyRef
();
void
setSerialNumber
(
const
std
::
string
&
sn
)
override
;
std
::
string
encFpr
()
const
;
...
...
src/view/pgpcardwidget.cpp
View file @
549b08ed
...
...
@@ -11,6 +11,8 @@
#include "kleopatra_debug.h"
#include "commands/changepincommand.h"
#include "smartcard/openpgpcard.h"
#include "smartcard/readerstatus.h"
...
...
@@ -44,6 +46,7 @@
#include <gpgme++/gpggencardkeyinteractor.h>
using
namespace
Kleo
;
using
namespace
Kleo
::
Commands
;
using
namespace
Kleo
::
SmartCard
;
namespace
{
...
...
@@ -185,17 +188,17 @@ PGPCardWidget::PGPCardWidget(QWidget *parent):
auto
pinButtton
=
new
QPushButton
(
i18n
(
"Change PIN"
));
pinButtton
->
setToolTip
(
i18n
(
"Change the PIN required to unblock the smartcard."
));
actionLayout
->
addWidget
(
pinButtton
);
connect
(
pinButtton
,
&
QPushButton
::
clicked
,
this
,
[
this
]
()
{
doChangePin
(
1
);});
connect
(
pinButtton
,
&
QPushButton
::
clicked
,
this
,
[
this
]
()
{
doChangePin
(
OpenPGPCard
::
pinKeyRef
()
);
});
auto
pukButton
=
new
QPushButton
(
i18n
(
"Change Admin PIN"
));
pukButton
->
setToolTip
(
i18n
(
"Change the PIN required to unlock the smartcard."
));
actionLayout
->
addWidget
(
pukButton
);
connect
(
pukButton
,
&
QPushButton
::
clicked
,
this
,
[
this
]
()
{
doChangePin
(
3
);});
connect
(
pukButton
,
&
QPushButton
::
clicked
,
this
,
[
this
]
()
{
doChangePin
(
OpenPGPCard
::
adminPinKeyRef
()
);
});
auto
resetCodeButton
=
new
QPushButton
(
i18n
(
"Change Reset Code"
));
pukButton
->
setToolTip
(
i18n
(
"Change the PIN required to reset the smartcard to an empty state."
));
actionLayout
->
addWidget
(
resetCodeButton
);
connect
(
resetCodeButton
,
&
QPushButton
::
clicked
,
this
,
[
this
]
()
{
doChangePin
(
2
);});
connect
(
resetCodeButton
,
&
QPushButton
::
clicked
,
this
,
[
this
]
()
{
doChangePin
(
OpenPGPCard
::
resetCodeKeyRef
()
);
});
actionLayout
->
addStretch
(
-
1
);
grid
->
addLayout
(
actionLayout
,
row
++
,
0
,
1
,
4
);
...
...
@@ -232,11 +235,16 @@ void PGPCardWidget::setCard(const OpenPGPCard *card)
mCardIsEmpty
=
card
->
authFpr
().
empty
()
&&
card
->
sigFpr
().
empty
()
&&
card
->
encFpr
().
empty
();
}
void
PGPCardWidget
::
doChangePin
(
int
slot
)
void
PGPCardWidget
::
doChangePin
(
const
std
::
string
&
keyRef
)
{
ReaderStatus
::
mutableInstance
()
->
startSimpleTransaction
(
QStringLiteral
(
"SCD PASSWD %1"
).
arg
(
slot
).
toUtf8
().
constData
(),
this
,
"changePinResult"
);
auto
cmd
=
new
ChangePinCommand
(
mRealSerial
,
this
);
this
->
setEnabled
(
false
);
connect
(
cmd
,
&
ChangePinCommand
::
finished
,
this
,
[
this
]()
{
this
->
setEnabled
(
true
);
});
cmd
->
setKeyRef
(
keyRef
);
cmd
->
start
();
}
void
PGPCardWidget
::
doGenKey
(
GenCardKeyDialog
*
dlg
)
...
...
@@ -330,21 +338,6 @@ void PGPCardWidget::genkeyRequested()
dlg
->
show
();
}
void
PGPCardWidget
::
changePinResult
(
const
GpgME
::
Error
&
err
)
{
if
(
err
)
{
KMessageBox
::
error
(
this
,
i18nc
(
"@info"
,
"PIN change failed: %1"
,
QString
::
fromLatin1
(
err
.
asString
())),
i18nc
(
"@title"
,
"Error"
));
return
;
}
if
(
!
err
.
isCanceled
())
{
KMessageBox
::
information
(
this
,
i18nc
(
"@info"
,
"Code successfully changed."
),
i18nc
(
"@title"
,
"Success"
));
}
}
void
PGPCardWidget
::
changeNameRequested
()
{
QString
text
=
mCardHolderLabel
->
text
();
...
...
src/view/pgpcardwidget.h
View file @
549b08ed
...
...
@@ -32,19 +32,18 @@ public:
explicit
PGPCardWidget
(
QWidget
*
parent
=
nullptr
);
void
setCard
(
const
SmartCard
::
OpenPGPCard
*
card
);
void
doChangePin
(
int
slot
);
void
doGenKey
(
GenCardKeyDialog
*
dlg
);
void
genKeyDone
(
const
GpgME
::
Error
&
err
,
const
std
::
string
&
backup
);
public
Q_SLOTS
:
void
genkeyRequested
();
void
changePinResult
(
const
GpgME
::
Error
&
err
);
void
changeNameRequested
();
void
changeNameResult
(
const
GpgME
::
Error
&
err
);
void
changeUrlRequested
();
void
changeUrlResult
(
const
GpgME
::
Error
&
err
);
private:
void
doChangePin
(
const
std
::
string
&
keyRef
);
void
updateKey
(
QLabel
*
label
,
const
std
::
string
&
fpr
);
QLabel
*
mSerialNumber
=
nullptr
,
*
mCardHolderLabel
=
nullptr
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment