/** * Copyright (C) 2008 by Sericon Technology Inc. * http://www.sericontech.com * All rights reserved. * * This software is supplied under the terms of a licence agreement or * non-disclosure agreement with Sericon Technology Inc. and may not be * copied nor disclosed except in accordance with the terms of that agreement. * * * Module Name: * * SampleAutoSSLApp.java * * Abstract: * * Example of how to create an AutoSSL application * */ package com.Sericon.ProductAgents.Sample; import java.util.*; import com.Sericon.ProductAgents.AutoSSLAgent.*; /** * An example AutoSSL application * * This example assumes that the product is running in a GUI, and all interaction * with the user is through the GUI. * * @author Sander Smith */ public class SampleAutoSSLApp { // this is the location of the AutoSSL server private static String autoSSLServerHost; private static int autoSSLServerPort; /** * Entry point into the application * @param args arguments passed on the command line */ public static void main(String[] args) { autoSSLServerHost = "apps.autossl.com"; autoSSLServerPort = 80; if (args.length != 1) { showUsage(); System.exit(1); } // The keystore is a file on the local file system that contains the private // information for the certificate. // Pass in the directory that this file should be kept. String keystoreDir = args[0]; autoSSLStartup(keystoreDir); } private static void autoSSLStartup(String keystoreDir) { // Create an instance of a StatusCheck object // This will be used to give the user feedback from the AutoSSL agent SampleStatusCheck iChecker = new SampleStatusCheck(); try { ProductRegistrationAgentKeystore productRegistrationAgent = new ProductRegistrationAgentKeystore(iChecker, autoSSLServerHost, autoSSLServerPort, "Sample AutoSSL Application", "Version 1.0", keystoreDir, Locale.US); // check that the SSL certificate that this product has is still valid // if there is no certificate, contact the AutoSSL server and provision one // if the certificate has expired, contact the AutoSSL server and provision a new one if (!productRegistrationAgent.hasCertificate()) { String reservationID = productRegistrationAgent.reserveServerID("autossl.com", iChecker.getServerID(), "password"); productRegistrationAgent.provisionSSLCertificate (reservationID, iChecker.getAuthorizationInformation(), iChecker.getBasicCustomerInformation(), 1); } else { // there is a certificate that was previously provisioned // check to see when it expires int daysToExpiration = productRegistrationAgent.daysUntilCertificateExpires(); // if it will expire soon, then renew if (daysToExpiration < 30) { productRegistrationAgent.renewSSLCertificate(iChecker.getAuthorizationInformation(), productRegistrationAgent.getCustomerInformation(), 1); } } // contact the AutoSSL naming server to ensure that the DNS resolution for this // installation is still correct // this will happen periodically since this network may be on a dynamic IP address productRegistrationAgent.registerForPeriodicServices(null); // Wait 10 seconds to simulate the product being used. // in reality, this is where the product would begin accepting and servicing connections Thread.sleep(10000); // have a look at the certificate we created System.out.println(productRegistrationAgent.getSSLCertificate().toString()); // we're done - clean up productRegistrationAgent.applicationFinished(); System.out.println("Finished !!!!!"); } catch (Exception e) { e.printStackTrace(); } } private static void showUsage() { System.out.println("Usage: java SampleAutoSSLApp "); } }