Questa Applet richiede l'immissione da parte dell'utente:
- del nome che l'E.M. deve attribuire al profilo;
- dell'Authentication Code;
- del Reference Number;
- della password da utilizzare per la creazione del profilo.
Cliccare sull'immagine per ingrandire.
UtenteDaRegistrare.java:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import iaik.security.ssl.*;
import iaik.x509.X509Certificate;
import iaik.asn1.structures.Name;
import com.entrust.util.*;
import com.entrust.security.provider.*;
import com.entrust.*;
import com.entrust.x509.directory.*;
import com.entrust.toolkit.*;
import com.entrust.security.provider.EntrustProfile;
import com.entrust.security.provider.Entrust;
import com.entrust.security.exceptions.EntrustBaseException;
public class UtenteDaRegistrare extends Applet {
static String profilePass;
static String managerIP;
static int managerIO;
static boolean recoverMode;
static TextArea ProgressText;
static Label NomeFile, Segreto1, Segreto2, Password;
static TextField StringaNomeFile, StringaSegreto1, StringaSegreto2, StringaPassword;
static Button Crea,Recupera,Cancella = null;
private Frame statoConnessione = new StatoConnessione();
public void init(){
// Inizializzazione del gestore degli eventi
EventHandler GestoreEventi = new EventHandler();
// Inizializzazione layout
this.setLayout(null);
this.setBounds(0,0,500,250);
NomeFile= new Label(" Nome (da attribuire al) file di profilo:");
NomeFile.setBounds(10,2,480,25);
this.add(NomeFile);
StringaNomeFile= new TextField("");
StringaNomeFile.setBounds(10,27,480,25);
StringaNomeFile.addKeyListener(GestoreEventi);
this.add(StringaNomeFile);
Segreto1= new Label(" Reference Number:");
Segreto1.setBounds(10,52,480,25);
this.add(Segreto1);
StringaSegreto1= new TextField("");
StringaSegreto1.setBounds(10,77,480,25);
StringaSegreto1.addKeyListener(GestoreEventi);
this.add(StringaSegreto1);
Segreto2= new Label(" Authorization code:");
Segreto2.setBounds(10,102,480,25);
this.add(Segreto2);
StringaSegreto2=new TextField("");
StringaSegreto2.setBounds(10,127,480,25);
StringaSegreto2.addKeyListener(GestoreEventi);
this.add(StringaSegreto2);
Password= new Label(" Password:");
Password.setBounds(10,152,480,25);
this.add(Password);
StringaPassword=new TextField("");
StringaPassword.setBounds(10,177,480,25);
StringaPassword.addKeyListener(GestoreEventi);
this.add(StringaPassword);
Crea=new Button("Crea");
Crea.setBounds(90,214,100,25);
Crea.addActionListener(GestoreEventi);
this.add(Crea);
Recupera=new Button("Recupera");
Recupera.setBounds(200,214,100,25);
Recupera.addActionListener(GestoreEventi);
this.add(Recupera);
Cancella=new Button("Cancella");
Cancella.setBounds(310,214,100,25);
Cancella.addActionListener(GestoreEventi);
this.add(Cancella);
//Inizializzazione del JCE e dell' Entrust Toolkit
com.entrust.util.Util.initCiphers();
}
/********************************************************************
Questo metodo ottenute in ingresso le informazioni necessarie:
1) Nome da attribuire al file di profilo
2) Reference Number
3) Autorization Code
4) Password
crea o recupera un profilo per l'utente.
********************************************************************/
static public void CreateOrRecoverUser () {
EntrustManagerTransport transport = null;
FileOutputStream output = null;
EntrustProfile profile = null;
String fileName = null;
String refNum = null;
String authCode = null;
int signingAlg = 0;
boolean ackPending = false;
try {
// il fileName
fileName = StringaNomeFile.getText();
if ( fileName.equals( "" ) ) {
ProgressText.append( "-- Valid Filename Required\n" );
}
// il reference number
refNum = StringaSegreto1.getText();
if ( refNum.equals( "" ) ) {
ProgressText.append( "-- Valid Reference Number Required\n" );
}
// l' authorization code
authCode = StringaSegreto2.getText();
if ( authCode.equals( "" ) ) {
ProgressText.append( "-- Valid Authorization Code Required\n" );
}
// Set up del profilo per le operazioni di create o recover
ProgressText.append( " Logging on...\n" );
profile = new EntrustProfile();
// Set up esplicito della versione PKIX4
ProgressText.append( " Set up della versione del profilo...\n" );
profile.setPKIXVersion( profile.PKIXforEntrust4 );
// Set up dell'algoritmo della chiave di firma RSA
ProgressText.append( " Set up dell'algoritmo di cifratura...\n" );
signingAlg = profile.RSASignature;
// Si inizializza l'E.M. transport con gli indirizzi IP del manager e la porta
ProgressText.append( " Mi connetto al manager...\n" );
transport = new EntrustManagerTransport( managerIP, managerIO );
// Si invoca la create o la recover dell'oggetto profilo
if ( recoverMode ) {
ProgressText.append( " So recuperando l'utente...\n" );
profile.recover( new StringBuffer( refNum ),
new StringBuffer( authCode ),
new StringBuffer( StringaPassword.getText() ),
transport,
signingAlg,
null );
} else {
ProgressText.append( " Sto creando l'utente...\n" );
profile.create( new StringBuffer( refNum ),
new StringBuffer( authCode ),
new StringBuffer( StringaPassword.getText() ),
transport,
signingAlg,
null );
}
// I'E.M. aspetta l'acknowledgement
ackPending = true;
// Si crea lo stream col quale si scrive il profilo
output = new FileOutputStream( fileName );
// Si scrive il profilo
profile.write( output );
output.close();
ProgressText.append( " Profilo: "+fileName+" Scritto.\n" );
// Si informa l'E.M. che la memorizzazione del profilo è avvenuta con successo
profile.writeComplete( transport, true );
ProgressText.append( "-- Scrittura Profilo accordata.\n" );
} catch ( Exception e ) {
if ( ackPending ) {
// Si chiama writeComplete() con parametro "false"
// Nella versione 1.0 questa chiamata cancella lo stato del profilo.
// Per future compatibilità bisogna chiamarla necessariamente.
try {
// Si informa l'E.M. che la memorizzazione del profilo è fallita
ProgressText.append( "-- Scrittura Profilo non riuscita.\n" );
profile.writeComplete( transport, false );
} catch (Exception e1) {}
}
e.printStackTrace();
}
}
/********************************************************************
Si intercettettano gli eventi:
-> premendo il pulsante "Crea" viene creata il profilo
-> premendo il pulsante "Recupera" viene rigenerato il profilo
-> premendo "Cancella" viene cancellato l'attuale contenuto delle aree di input
********************************************************************/
class EventHandler implements ActionListener, KeyListener {
public void actionPerformed( ActionEvent ae ) {
if (ae.getActionCommand().equals( "Cancella" )) {
StringaNomeFile.setText("");
StringaSegreto1.setText("");
StringaSegreto2.setText("");
StringaPassword.setText("");
} else {
try {
// Connessione con il Server tramite il protocollo SSL
// inoltre scambio di informazioni criptate
if (ae.getActionCommand().equals( "Crea" )) recoverMode=false;
if (ae.getActionCommand().equals( "Recupera" )) recoverMode=true;
statoConnessione.setVisible(true);
CreateOrRecoverUser();
// si impone un leggero delay affinché l'utente possa leggere lo stato della connessione
this.wait(100);
statoConnessione.setVisible(false);
// una volta completata la registrazione si ritorna alla Home Page
AppletContext context = getAppletContext();
URL u = new URL(getCodeBase().toString()+"Home.html");
context.showDocument(u);
}
catch (MalformedURLException e) { e.printStackTrace(); }
catch (InterruptedException e) { e.printStackTrace(); }
}
}
public void keyPressed(KeyEvent e) {
// Ignora tutti i keyPressed KeyEvents
}
public void keyTyped(KeyEvent e) {
// Ignora tutti i keyTyped KeyEvents
}
public void keyReleased(KeyEvent e) {
// Ignora tutti i keyReleased KeyEvents
}
}
/******************************************************************** Inizializzazione del Frame nel quale verrà visualizzato lo stato delle operazioni effettuate durante la connessione. ********************************************************************/
static class StatoConnessione extends Frame{
public StatoConnessione() {
//Inizializzazione del layout del frame
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
this.setLayout(gridbag);
//Definizione delle dimensioni e del titolo
setSize(500,250);
setTitle("Stato della connessione:");
// Area di testo
ProgressText = new java.awt.TextArea();
ProgressText.setFont( new Font( "Courier", Font.PLAIN, 12 ) );
ProgressText.setEditable( false );
c.fill = c.BOTH;
c.anchor = c.NORTHWEST;
c.gridwidth = c.REMAINDER;
gridbag.setConstraints( ProgressText, c );
this.add( ProgressText );
}
}
}
|