369 } |
370 } |
370 |
371 |
371 // ### add a test to verify that public keys are _decrypted_ correctly (by the ctor) |
372 // ### add a test to verify that public keys are _decrypted_ correctly (by the ctor) |
372 } |
373 } |
373 |
374 |
|
375 void tst_QSslKey::passphraseChecks() |
|
376 { |
|
377 { |
|
378 QString fileName(SRCDIR "/rsa-with-passphrase.pem"); |
|
379 QFile keyFile(fileName); |
|
380 QVERIFY(keyFile.exists()); |
|
381 { |
|
382 if (!keyFile.isOpen()) |
|
383 keyFile.open(QIODevice::ReadOnly); |
|
384 else |
|
385 keyFile.reset(); |
|
386 QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey); |
|
387 QVERIFY(key.isNull()); // null passphrase => should not be able to decode key |
|
388 } |
|
389 { |
|
390 if (!keyFile.isOpen()) |
|
391 keyFile.open(QIODevice::ReadOnly); |
|
392 else |
|
393 keyFile.reset(); |
|
394 QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, ""); |
|
395 QVERIFY(key.isNull()); // empty passphrase => should not be able to decode key |
|
396 } |
|
397 { |
|
398 if (!keyFile.isOpen()) |
|
399 keyFile.open(QIODevice::ReadOnly); |
|
400 else |
|
401 keyFile.reset(); |
|
402 QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "WRONG!"); |
|
403 QVERIFY(key.isNull()); // wrong passphrase => should not be able to decode key |
|
404 } |
|
405 { |
|
406 if (!keyFile.isOpen()) |
|
407 keyFile.open(QIODevice::ReadOnly); |
|
408 else |
|
409 keyFile.reset(); |
|
410 QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "123"); |
|
411 QVERIFY(!key.isNull()); // correct passphrase |
|
412 } |
|
413 } |
|
414 |
|
415 { |
|
416 // be sure and check a key without passphrase too |
|
417 QString fileName(SRCDIR "/rsa-without-passphrase.pem"); |
|
418 QFile keyFile(fileName); |
|
419 { |
|
420 if (!keyFile.isOpen()) |
|
421 keyFile.open(QIODevice::ReadOnly); |
|
422 else |
|
423 keyFile.reset(); |
|
424 QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey); |
|
425 QVERIFY(!key.isNull()); // null passphrase => should be able to decode key |
|
426 } |
|
427 { |
|
428 if (!keyFile.isOpen()) |
|
429 keyFile.open(QIODevice::ReadOnly); |
|
430 else |
|
431 keyFile.reset(); |
|
432 QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, ""); |
|
433 QVERIFY(!key.isNull()); // empty passphrase => should be able to decode key |
|
434 } |
|
435 { |
|
436 if (!keyFile.isOpen()) |
|
437 keyFile.open(QIODevice::ReadOnly); |
|
438 else |
|
439 keyFile.reset(); |
|
440 QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "xxx"); |
|
441 QVERIFY(!key.isNull()); // passphrase given but key is not encrypted anyway => should work |
|
442 } |
|
443 } |
|
444 } |
|
445 |
374 #endif |
446 #endif |
375 |
447 |
376 QTEST_MAIN(tst_QSslKey) |
448 QTEST_MAIN(tst_QSslKey) |
377 #include "tst_qsslkey.moc" |
449 #include "tst_qsslkey.moc" |