001: /*
002: * Conditions Of Use
003: *
004: * This software was developed by employees of the National Institute of
005: * Standards and Technology (NIST), and others.
006: * This software is has been contributed to the public domain.
007: * As a result, a formal license is not needed to use the software.
008: *
009: * This software is provided "AS IS."
010: * NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
011: * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
012: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
013: * AND DATA ACCURACY. NIST does not warrant or make any representations
014: * regarding the use of the software or the results thereof, including but
015: * not limited to the correctness, accuracy, reliability or usefulness of
016: * the software.
017: *
018: *
019: */
020: /**
021: *
022: */package test.tck.msgflow.callflows.tls;
023:
024: import java.util.EventObject;
025:
026: import javax.sip.DialogTerminatedEvent;
027: import javax.sip.IOExceptionEvent;
028: import javax.sip.RequestEvent;
029: import javax.sip.ResponseEvent;
030: import javax.sip.SipListener;
031: import javax.sip.SipProvider;
032: import javax.sip.TimeoutEvent;
033: import javax.sip.TransactionTerminatedEvent;
034:
035: import org.apache.log4j.Logger;
036:
037: import test.tck.msgflow.callflows.ScenarioHarness;
038:
039: /**
040: * @author M. Ranganathan
041: *
042: */
043: public class TlsTest extends ScenarioHarness implements SipListener {
044:
045: protected Shootist shootist;
046:
047: private Shootme shootme;
048:
049: private static Logger logger = Logger.getLogger("test.tck");
050:
051: static {
052: if (!logger.isAttached(console))
053: logger.addAppender(console);
054: }
055:
056: private SipListener getSipListener(EventObject sipEvent) {
057: SipProvider source = (SipProvider) sipEvent.getSource();
058: SipListener listener = (SipListener) providerTable.get(source);
059: assertTrue(listener != null);
060: return listener;
061: }
062:
063: public TlsTest() {
064: super ("tlstest", true);
065: }
066:
067: public void setUp() {
068:
069: try {
070: // setup TLS properties
071: System.setProperty("javax.net.ssl.keyStore", TlsTest.class
072: .getResource("testkeys").getPath());
073: System.setProperty("javax.net.ssl.trustStore",
074: TlsTest.class.getResource("testkeys").getPath());
075: System.setProperty("javax.net.ssl.keyStorePassword",
076: "passphrase");
077: System.setProperty("javax.net.ssl.keyStoreType", "jks");
078:
079: this .transport = "tls";
080:
081: super .setUp();
082: shootist = new Shootist(riProtocolObjects);
083: SipProvider shootistProvider = shootist.createSipProvider();
084: providerTable.put(shootistProvider, shootist);
085:
086: shootme = new Shootme(tiProtocolObjects);
087: SipProvider shootmeProvider = shootme.createSipProvider();
088: providerTable.put(shootmeProvider, shootme);
089: shootistProvider.addSipListener(this );
090: shootmeProvider.addSipListener(this );
091:
092: riProtocolObjects.start();
093: if (tiProtocolObjects != riProtocolObjects)
094: tiProtocolObjects.start();
095: } catch (Exception ex) {
096: ex.printStackTrace();
097: fail("unexpected exception ");
098: }
099: }
100:
101: public void testSendInvite() {
102: this .shootist.sendInvite();
103: }
104:
105: public void tearDown() {
106: try {
107: Thread.sleep(2000);
108: this .shootist.checkState();
109: this .shootme.checkState();
110: tiProtocolObjects.destroy();
111: if (tiProtocolObjects != riProtocolObjects)
112: riProtocolObjects.destroy();
113: Thread.sleep(1000);
114: this .providerTable.clear();
115:
116: System.clearProperty("javax.net.ssl.keyStore");
117: System.clearProperty("javax.net.ssl.trustStore");
118: System.clearProperty("javax.net.ssl.keyStorePassword");
119: System.clearProperty("javax.net.ssl.keyStoreType");
120:
121: logTestCompleted();
122: } catch (Exception ex) {
123: ex.printStackTrace();
124: }
125:
126: }
127:
128: public void processRequest(RequestEvent requestEvent) {
129: getSipListener(requestEvent).processRequest(requestEvent);
130:
131: }
132:
133: public void processResponse(ResponseEvent responseEvent) {
134: getSipListener(responseEvent).processResponse(responseEvent);
135:
136: }
137:
138: public void processTimeout(TimeoutEvent timeoutEvent) {
139: getSipListener(timeoutEvent).processTimeout(timeoutEvent);
140: }
141:
142: public void processIOException(IOExceptionEvent exceptionEvent) {
143: fail("unexpected exception");
144:
145: }
146:
147: public void processTransactionTerminated(
148: TransactionTerminatedEvent transactionTerminatedEvent) {
149: getSipListener(transactionTerminatedEvent)
150: .processTransactionTerminated(
151: transactionTerminatedEvent);
152:
153: }
154:
155: public void processDialogTerminated(
156: DialogTerminatedEvent dialogTerminatedEvent) {
157: getSipListener(dialogTerminatedEvent).processDialogTerminated(
158: dialogTerminatedEvent);
159:
160: }
161:
162: }
|