This library provides a simple and nice C++ wrapper around these libraries, so that programmers can concentrate on functionality. It offers general support for PCSC-lite, OpenSSL, PKCS#11, plus specific functionality for the SuisseID.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.0 KiB
111 lines
3.0 KiB
11 years ago
|
/*! @file
|
||
|
|
||
|
@id $Id$
|
||
|
*/
|
||
|
// 1 2 3 4 5 6 7 8
|
||
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||
|
|
||
|
#ifndef SUISSE_ID_DEMO_HXX
|
||
|
#define SUISSE_ID_DEMO_HXX
|
||
|
|
||
|
#include <suisseid.hxx>
|
||
|
#include <iostream>
|
||
|
#include <cassert>
|
||
|
|
||
11 years ago
|
// implements a status cycle for text user interface
|
||
11 years ago
|
class TextualCycle: public suisseid::StatusCycle {
|
||
|
|
||
|
public:
|
||
11 years ago
|
|
||
|
// just pass the card to parent
|
||
11 years ago
|
TextualCycle(std::shared_ptr<suisseid::Card> card):
|
||
11 years ago
|
StatusCycle(card) {
|
||
|
}
|
||
|
|
||
|
protected:
|
||
|
|
||
11 years ago
|
// callback: ask user for transport pin
|
||
11 years ago
|
virtual PinPukChange pinChangeTransportPin() {
|
||
|
PinPukChange pinpuk;
|
||
|
std::cout<<"Enter Transport PIN: ";
|
||
|
std::cin>>pinpuk.oldpin;
|
||
|
std::cout<<"Enter New PIN: ";
|
||
|
std::cin>>pinpuk.newpin;
|
||
|
return pinpuk;
|
||
|
}
|
||
|
|
||
11 years ago
|
// callback: ask user for puk
|
||
11 years ago
|
virtual PinPukChange pinChangePuk() {
|
||
|
PinPukChange pinpuk;
|
||
|
std::cout<<"Enter PUK to unlock PKCS#15 PIN: ";
|
||
|
std::cin>>pinpuk.oldpin;
|
||
|
std::cout<<"Enter New PKCS#15 PIN: ";
|
||
|
std::cin>>pinpuk.newpin;
|
||
|
return pinpuk;
|
||
|
}
|
||
|
|
||
11 years ago
|
// callback: tell user that transport pin is locked
|
||
11 years ago
|
virtual void transportPinLocked() {
|
||
|
std::cout<<"Transport PIN is Locked!"<<std::endl;
|
||
|
}
|
||
|
|
||
11 years ago
|
// callback: tell user that pkcs15 pin is locked
|
||
11 years ago
|
virtual void pkcs15PinLocked() {
|
||
|
std::cout<<"PKCS#15 PIN is Locked!"<<std::endl;
|
||
|
}
|
||
|
|
||
11 years ago
|
// callback: tell user that digital signature pin is locked
|
||
11 years ago
|
virtual void sigGPinLocked() {
|
||
|
std::cout<<"SigG PIN is Locked!"<<std::endl;
|
||
|
}
|
||
|
|
||
11 years ago
|
// callback: tell user that puk is locked
|
||
11 years ago
|
virtual void pukLocked() {
|
||
|
std::cout<<"PUK is Locked!"<<std::endl;
|
||
|
}
|
||
|
|
||
11 years ago
|
// callback: tell user that certificates will expire soon
|
||
11 years ago
|
virtual void certsExpireSoon() {
|
||
|
std::cout<<"Certificates Expire Soon!"<<std::endl;
|
||
|
}
|
||
|
|
||
11 years ago
|
// callback: tell user that certificates have expired
|
||
11 years ago
|
virtual void certsExpired() {
|
||
|
std::cout<<"Certificates Expired!"<<std::endl;
|
||
|
}
|
||
|
|
||
11 years ago
|
// callback: tell user that certificates have been revoked
|
||
11 years ago
|
virtual void certsRevoked() {
|
||
|
std::cout<<"Certificates Revoked!"<<std::endl;
|
||
|
}
|
||
|
|
||
|
public:
|
||
|
|
||
11 years ago
|
// install certificates on the card
|
||
11 years ago
|
virtual bool installCerts(bool force = true) {
|
||
|
std::cout<<"Installing Certificates ..."<<std::endl;
|
||
|
std::string pin;
|
||
|
std::cout<<"Enter PIN (x to abort): ";
|
||
|
std::cin>>pin;
|
||
|
if (pin=="x") {
|
||
|
std::cout<<std::endl<<"User aborted"<<std::endl;
|
||
|
return false; // user aborts
|
||
|
}
|
||
|
cryptoki::Session session(card()->slot());
|
||
|
try {
|
||
11 years ago
|
// log into the card using the user's pin
|
||
11 years ago
|
session.login(pin);
|
||
|
} catch (const cryptoki::wrong_pin& x) {
|
||
|
std::cout<<"**** Wrong PIN!"<<std::endl;
|
||
|
std::cout<<x.what()<<std::endl;
|
||
|
return false;
|
||
|
}
|
||
11 years ago
|
// now store certificates on the card
|
||
11 years ago
|
std::cout<<"**** Not implemented"<<std::endl;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
#endif
|