| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  | /*! @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>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  | // implements a status cycle for text user interface
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  | class TextualCycle: public suisseid::StatusCycle { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // just pass the card to parent
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |     TextualCycle(mrw::Shared<suisseid::Card> card): | 
					
						
							|  |  |  |         StatusCycle(card) { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   protected: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |     // callback: ask user for transport pin 
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |     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; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |     // callback: ask user for puk
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |     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; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |     // callback: tell user that transport pin is locked
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |     virtual void transportPinLocked() { | 
					
						
							|  |  |  |       std::cout<<"Transport PIN is Locked!"<<std::endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |     // callback: tell user that pkcs15 pin is locked
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |     virtual void pkcs15PinLocked() { | 
					
						
							|  |  |  |       std::cout<<"PKCS#15 PIN is Locked!"<<std::endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |     // callback: tell user that digital signature pin is locked
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |     virtual void sigGPinLocked() { | 
					
						
							|  |  |  |       std::cout<<"SigG PIN is Locked!"<<std::endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |     // callback: tell user that puk is locked
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |     virtual void pukLocked() { | 
					
						
							|  |  |  |       std::cout<<"PUK is Locked!"<<std::endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |     // callback: tell user that certificates will expire soon
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |     virtual void certsExpireSoon() { | 
					
						
							|  |  |  |       std::cout<<"Certificates Expire Soon!"<<std::endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |     // callback: tell user that certificates have expired
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |     virtual void certsExpired() { | 
					
						
							|  |  |  |       std::cout<<"Certificates Expired!"<<std::endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |     // callback: tell user that certificates have been revoked
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |     virtual void certsRevoked() { | 
					
						
							|  |  |  |       std::cout<<"Certificates Revoked!"<<std::endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |     // install certificates on the card
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |     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 { | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |         // log into the card using the user's pin
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |         session.login(pin); | 
					
						
							|  |  |  |       } catch (const cryptoki::wrong_pin& x) { | 
					
						
							|  |  |  |         std::cout<<"**** Wrong PIN!"<<std::endl; | 
					
						
							|  |  |  |         std::cout<<x.what()<<std::endl; | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2014-01-31 13:32:31 +00:00
										 |  |  |       // now store certificates on the card
 | 
					
						
							| 
									
										
										
										
											2013-11-06 12:24:52 +00:00
										 |  |  |       std::cout<<"**** Not implemented"<<std::endl; | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |