/** * The TLS command execution. * @throws IOException If an I/O error occurs while sending * the command or performing the negotiation. * @return TRUE if the command and negotiation succeeded. */ public boolean execTLS() throws IOException { if (!SMTPReply.isPositiveCompletion(sendCommand("STARTTLS"))) { return false; //throw new SSLException(getReplyString()); } performSSLNegotiation(); return true; }
@Test public void startTlsShouldFailWhenFollowedByInjectedCommand() throws Exception { server = createServer(createProtocol(Optional.empty()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient(); server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); smtpsClient.sendCommand("STARTTLS\r\nRSET\r\n"); assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isFalse(); }
@Test public void startTlsShouldFailWhenFollowedByInjectedCommandAndNotAtBeginningOfLine() throws Exception { server = createServer(createProtocol(Optional.empty()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient(); server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); smtpsClient.sendCommand("RSET\r\nSTARTTLS\r\nRSET\r\n"); assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isFalse(); }
@Test public void startTlsShouldFailWhenFollowedByInjectedCommandAndNotAtBeginningOfLine() throws Exception { server = createServer(createProtocol(Optional.empty()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient(); server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); smtpsClient.sendCommand("RSET\r\nSTARTTLS\r\nRSET\r\n"); assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isFalse(); }
@Test public void startTlsShouldFailWhenFollowedByInjectedCommand() throws Exception { server = createServer(createProtocol(Optional.empty()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient(); server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); smtpsClient.sendCommand("STARTTLS\r\nRSET\r\n"); assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isFalse(); }
@Test public void startTlsShouldReturnTrueWhenServerSupportsIt() throws Exception { server = createServer(createProtocol(Optional.empty()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient(); server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); boolean execTLS = smtpsClient.execTLS(); assertThat(execTLS).isTrue(); }
@Test public void startTlsShouldReturnTrueWhenServerSupportsIt() throws Exception { server = createServer(createProtocol(Optional.empty()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient(); server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); boolean execTLS = smtpsClient.execTLS(); assertThat(execTLS).isTrue(); }
@Test public void ehloShouldReturnTrueWhenSendingTheCommand() throws Exception { server = createServer(createProtocol(Optional.empty()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient(); server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isTrue(); }
@Test public void ehloShouldReturnTrueWhenSendingTheCommand() throws Exception { server = createServer(createProtocol(Optional.empty()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient(); server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isTrue(); }
@Test public void startTlsShouldBeAnnouncedWhenServerSupportsIt() throws Exception { server = createServer(createProtocol(Optional.empty()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient(); server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); assertThat(new StartTLSAssert(smtpsClient)).isStartTLSAnnounced(); }
@Test public void startTlsShouldBeAnnouncedWhenServerSupportsIt() throws Exception { server = createServer(createProtocol(Optional.empty()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient(); server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); assertThat(new StartTLSAssert(smtpsClient)).isStartTLSAnnounced(); }