22 #include "config-plasma.h"
26 #ifdef ENABLE_REMOTE_WIDGETS
31 #include <kstandarddirs.h>
33 #define REQUIRED_FEATURES "rsa,sha1,pkey"
37 class CredentialsPrivate {
43 CredentialsPrivate(
const QString &
id,
const QString &name,
44 const QString &pemKey,
bool isPrivateKey)
48 #ifdef ENABLE_REMOTE_WIDGETS
55 privateKey = QCA::PrivateKey::fromPEM(pemKey);
56 publicKey = privateKey.toPublicKey();
58 publicKey = QCA::PublicKey::fromPEM(pemKey);
70 #ifdef ENABLE_REMOTE_WIDGETS
71 QCA::PublicKey publicKey;
72 QCA::PrivateKey privateKey;
77 const QString &key,
bool isPrivateKey)
78 : d(
new CredentialsPrivate(
id, name, key, isPrivateKey))
83 : d(new CredentialsPrivate())
88 : d(new CredentialsPrivate())
106 #ifdef ENABLE_REMOTE_WIDGETS
112 QCA::KeyGenerator generator;
113 QCA::PrivateKey key = generator.createRSA(2048);
114 QString pemKey(key.toPublicKey().toPEM());
115 QString
id = QCA::Hash(
"sha1").hashToString(pemKey.toLatin1());
140 #ifdef ENABLE_REMOTE_WIDGETS
146 if (d->publicKey.isNull()) {
149 QString
id = QCA::Hash(
"sha1").hashToString(d->publicKey.toPEM().toLatin1());
150 return (
id == d->id);
153 kDebug() <<
"libplasma is compiled without support for remote widgets. Key invalid.";
170 #ifdef ENABLE_REMOTE_WIDGETS
176 if (d->publicKey.canVerify()) {
178 kDebug() <<
"Key is null?";
180 QCA::PublicKey publicKey = QCA::PublicKey::fromPEM(d->publicKey.toPEM());
181 publicKey.startVerify( QCA::EMSA3_MD5 );
182 publicKey.update(payload);
183 return ( publicKey.validSignature( signature ) );
185 kDebug() <<
"Can't verify?";
195 #ifdef ENABLE_REMOTE_WIDGETS
201 return d->privateKey.canSign();
209 #ifdef ENABLE_REMOTE_WIDGETS
211 kDebug() <<
"RSA not supported";
215 d->privateKey.startSign( QCA::EMSA3_MD5 );
216 d->privateKey.update( message );
217 QByteArray signature = d->privateKey.signature();
229 #ifdef ENABLE_REMOTE_WIDGETS
231 result.d->privateKey = QCA::PrivateKey();
240 #ifdef ENABLE_REMOTE_WIDGETS
246 QString privateKeyPem;
247 QString publicKeyPem;
249 if (!myObj.d->privateKey.isNull()) {
250 privateKeyPem = myObj.d->privateKey.toPEM();
252 if (!myObj.d->publicKey.isNull()) {
253 publicKeyPem = myObj.d->publicKey.toPEM();
256 out << 1 << myObj.d->id << myObj.d->name << privateKeyPem << publicKeyPem;
264 #ifdef ENABLE_REMOTE_WIDGETS
270 QString privateKeyString;
271 QString publicKeyString;
274 in >> version >> myObj.d->id >> myObj.d->name >> privateKeyString >> publicKeyString;
275 QCA::ConvertResult conversionResult;
277 if (!privateKeyString.isEmpty()) {
278 myObj.d->privateKey = QCA::PrivateKey::fromPEM(privateKeyString,
279 QByteArray(), &conversionResult);
282 if (!publicKeyString.isEmpty()) {
283 myObj.d->publicKey = QCA::PublicKey::fromPEM(publicKeyString, &conversionResult);
286 if (conversionResult != QCA::ConvertGood) {
287 kDebug() <<
"Unsuccessfull conversion of key?";
static Credentials createCredentials(const QString &name)
Create a new identity with a new set of random public/private keys.
unsigned int version()
The runtime version of libplasma.
Credentials & operator=(const Credentials &other)
QDataStream & operator<<(QDataStream &out, const Credentials &myObj)
Streaming operators for sending/storing identities.
bool isValidSignature(const QByteArray &signature, const QByteArray &message)
The credentials are valid.
Credentials toPublicCredentials() const
TrustLevel trustLevel() const
QDataStream & operator>>(QDataStream &in, Credentials &myObj)
This class encapsules someone's identity.
#define REQUIRED_FEATURES
QByteArray signMessage(const QByteArray &message)
Credentials()
Default constructor.