Commit Graph

209 Commits

Author SHA1 Message Date
Florian Schmaus 793d3c47ad Move TLS and SASL sync points into subclasses
In preperation of subclasses with different connection approaches.
2018-02-23 10:37:17 +01:00
Paul Schaub 9f47daa7ad
Add missing package-info descriptions. 2018-02-21 16:47:11 +01:00
Florian Schmaus 6dfc20ee5e Rename "Packet (Reader|Writer)" to just Reader or Writer 2018-02-09 10:26:42 +01:00
Florian Schmaus 34373e8710 Enable javadoc 'html' doclint
Also make all 'test' tasks depend on the 'javadoc' task.

Fixes SMACK-650.
2017-12-25 14:08:18 +01:00
Paul Schaub cb18056613 Fix minor codestyle issues 2017-12-17 11:03:46 +01:00
Florian Schmaus d804d4ed6d Do not abort if we could not get a KeyManagerFactory
using the default algorithm. Instead continue with 'null' as value of
the KeyManager[] array (kms). This makes the SSLContext.init() methods
to search the default security providers for implementations, which is
also OK.

This change is needed because it appears that on Android
KeyManagerFactory.getDefaultAlgorithm returns 'SunX509', which
subsequently results in

W/AbstractXMPPConnection: Connection XMPPTCPConnection[not-authenticated] (0) closed with error
  java.security.NoSuchAlgorithmException: KeyManagerFactory SunX509 implementation not found
      at org.apache.harmony.security.fortress.Engine.notFound(Engine.java:190)
      at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:139)
      at javax.net.ssl.KeyManagerFactory.getInstance(KeyManagerFactory.java:77)
      at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnection.java:747)
      at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1200(XMPPTCPConnection.java:149)
      at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1053)
      at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:980)
      at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:996)
      at java.lang.Thread.run(Thread.java:818)

Note that this is possibly because the Secuurity Provider was
not (yet) intialized.
2017-11-23 08:21:55 +01:00
Florian Schmaus 573358b459 Limit the scope of local variables in proceedTLSReceived() 2017-11-23 08:15:52 +01:00
Florian Schmaus 853324a998
Merge pull request #185 from mityada/sm-resumption-race-condition
Prevent race condition after stream resumption
2017-11-22 08:29:36 +01:00
Florian Schmaus 813a5ba63f
Merge pull request #184 from mityada/stream-management-exception
Drop stream management state on StreamManagementException
2017-11-21 21:15:41 +01:00
Florian Schmaus 9e11b68144 Add comment style checkstyle rule requiring a space 2017-11-20 08:53:19 +01:00
Dmitry Deshevoy 230a226424 Prevent race condition after stream resumption
New stanzas sent directly after stream resumption might have been added
to unacknowledgedStanzas before the old unacknowledged stanzas
are resent. This caused new stanzas to be sent twice and later led
to a StreamManagementCounterError.

Fixes SMACK-786
2017-11-18 19:37:07 +03:00
Dmitry Deshevoy 4f11dc5b14 Drop stream management state on StreamManagementException 2017-11-16 19:10:52 +03:00
Florian Schmaus 65b4f506dc Add SubscribeAnswer.ApproveAndAlsoRequestIfRequired 2017-11-06 22:41:28 +01:00
Florian Schmaus 1b2521269e Make END_TAG parsing more NPE robust
by calling String.equals() on the constant string and not on the
return value of parser.getName().

Also perform the access to 'parser' on a different LOC than
equals(). This should help debugging things like

okt 25, 2017 2:02:54 PM org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener
WARNING: Connection XMPPTCPConnection[***@***/***] (0) closed with error
java.lang.NullPointerException
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1194)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:982)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:998)
	at java.lang.Thread.run(Thread.java:745)

which where recently reported on the forums.
2017-10-27 17:48:00 +02:00
Florian Schmaus 685edde308 Don't hardcode "SunX509" as key algorithm
in XMPPTCPConnection. Instead use the default algorithm.

Fixes SMACK-771.
2017-07-02 18:30:53 +02:00
Florian Schmaus 3d032298a5 Deal with cases wehre HostAddress.fqdn is null
Fixes SMACK-772
2017-07-02 18:09:15 +02:00
Florian Schmaus 813219179f Add support for <text/> elements in SM's <failed/> element
Also introduce AbstractTextElement and StanzaErrorTextElement.

Fixes SMACK-760.
2017-06-17 11:43:49 +02:00
Florian Schmaus 08e897113d Add CustomImportOrder checkstyle rule
And matching ImportOrder settings for Eclipse in
resources/eclipse/smack.importorder
2017-06-14 17:12:43 +02:00
Florian Schmaus ce1cddc722 More checkstyle whitespace related checks 2017-05-24 14:42:38 +02:00
Florian Schmaus 3ce5973915 Also add stanzas to unacknowledgedStanzas while shutting down
This caused the WaitForClosingStreamElementTest integration test to
fail, because the last presences stanzas, which are send after done()
in the writer thread would return true, are not added to the
unacknowledgedStanzas queue.

The result was:

SEVERE: WaitForClosingStreamElementTest.waitForClosingStreamElementTest (LowLevel): Failed
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.igniterealtime.smack.inttest.SmackIntegrationTestFramework.invokeLowLevel(SmackIntegrationTestFramework.java:466)
        at org.igniterealtime.smack.inttest.SmackIntegrationTestFramework.runTests(SmackIntegrationTestFramework.java:375)
        at org.igniterealtime.smack.inttest.SmackIntegrationTestFramework.run(SmackIntegrationTestFramework.java:165)
        at org.igniterealtime.smack.inttest.SmackIntegrationTestFramework.main(SmackIntegrationTestFramework.java:84)
Caused by: java.lang.AssertionError: Sync poing yielded failure exception
        at org.jivesoftware.smack.WaitForClosingStreamElementTest.waitForClosingStreamElementTest(WaitForClosingStreamElementTest.java:46)
        ... 8 more
Caused by: org.jivesoftware.smack.sm.StreamManagementException$StreamManagementCounterError: There was an error regarding the Stream Mangement counters. Server reported 3 handled stanzas, which means that the 3 recently send stanzas by client are now acked by the server. But Smack had only 1 to acknowledge. The stanza id of the last acked outstanding stanza is FqL1X-144
        at org.jivesoftware.smack.tcp.XMPPTCPConnection.processHandledCount(XMPPTCPConnection.java:1847)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$2600(XMPPTCPConnection.java:149)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1176)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:980)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:996)
        at java.lang.Thread.run(Thread.java:745)
2017-03-18 17:49:38 +01:00
Florian Schmaus 4c646436a5 Bump "Error Prone" to 2.0.15
and fix a few things :)
2017-02-11 16:16:41 +01:00
Florian Schmaus 51d3c31766 Initialize Socket in TCP connection when proxy is used
Thanks to Grigory Fedorov for reporting this.
2017-01-08 22:58:23 +01:00
Florian Schmaus bfc14227ca Propagate stream errors on connect/login to the caller
Before this, if there was a stream error response by the server to our
stream open, that error response would only be handled in the reader
thread, and the user would get a message like:

"org.jivesoftware.smack.SmackException$NoResponseException: No
response received within reply timeout. Timeout was
5000ms (~5s). While waiting for SASL mechanisms stream feature from
server"

while the server may actually sent something like

<stream:stream
  xmlns='jabber:client'
  xmlns:stream='http://etherx.jabber.org/streams'
  id='6785787028201586334'
  from='jabbim.com'
  version='1.0'
  xml:lang='en'>
  <stream:error>
    <policy-violation xmlns='urn:ietf:params:xml:ns:xmpp-streams'>
	</policy-violation>
	<text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>
	  Too many (2) failed authentications from this IP
      address (1xx.66.xx.xxx). The address will be unblocked at 04:24:00
      06.01.2017 UTC
    </text>
  </stream:error>
</stream:stream>

It was necessary to change saslFeatureReceived from SmackException to
XMPPException in order to return the StreamErrorException at this sync
point. But this change in return required the introduction of a
tlsHandled sync point for SmackException (which just acts as a wrapper
for the various exception types that could occurn when establishing
TLS). The tlsHandled sync point is marked successful even if no TLS
was established in case none was required and/or if not supported by
the server.
2017-01-07 10:38:41 +01:00
Florian Schmaus e9bbe9a475 Fix OOB exception when setHostAddress(InetAddress) is used.
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
  at java.lang.String.charAt(String.java:658)
  at org.jivesoftware.smack.util.dns.HostAddress.<init>(HostAddress.java:48)
  at org.jivesoftware.smack.util.dns.HostAddress.<init>(HostAddress.java:62)
2017-01-04 15:35:47 +01:00
Florian Schmaus a8429d45f6 Do not wait for the closing stream element on instant shutdown 2017-01-03 11:44:44 +01:00
Florian Schmaus 90a5e289f8 s/processPacket/processStanza/ s/PacketCollector/StanzaCollector/ 2017-01-03 11:35:04 +01:00
Florian Schmaus b558a128c3 Merge remote-tracking branch 'my/master' 2016-12-07 21:20:02 +01:00
Florian Schmaus d976434bb3 Improve message of XMPPErrorException
by including the XMPP entity which send the XMPP error reply to us.

Also cleanup the no longer used constructors.
2016-11-29 16:40:08 +01:00
Florian Schmaus 1f1bc236fd Ads support for SCRAM-SHA-1-PLUS
Related to SMACK-398.
2016-11-20 19:34:17 +01:00
Florian Schmaus a9d5cd4a61 Move TLS Required check at the end of connect()
It was a *very* bad idea to perform the SecurityMode.Required check in
the connection's reader thread and not at the end of
AbstractXMPPConnectin's connect(). :/

This behavior dates back to 8e750912a7

Fixes SMACK-739
2016-11-12 11:59:06 +01:00
Florian Schmaus 013f4d630a Move duplicate code in AbstractXMPPConnection
from XMPP(TCP|BOSH)Connection.
2016-11-12 11:03:44 +01:00
Florian Schmaus a1630d033e Add support for DNSSEC/DANE
This closes the cycle which started with a GSOC 2015 project under the
umbrella of the XSF adding DNSSEC/DANE support to MiniDNS.

Fixes SMACK-366.
2016-10-31 10:45:38 +01:00
Florian Schmaus c379ae07d5 Initialize the Key Store
as otherwhise the following could happen:

WARNING: Connection XMPPTCPConnection[not-authenticated] (0) closed with error
java.security.KeyStoreException: Uninitialized keystore
	at java.security.KeyStore.aliases(KeyStore.java:1233)
	at sun.security.ssl.SunX509KeyManagerImpl.<init>(SunX509KeyManagerImpl.java:127)
	at sun.security.ssl.KeyManagerFactoryImpl$SunX509.engineInit(KeyManagerFactoryImpl.java:70)
	at javax.net.ssl.KeyManagerFactory.init(KeyManagerFactory.java:256)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnection.java:739)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1000(XMPPTCPConnection.java:146)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1026)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:960)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:975)
	at java.lang.Thread.run(Thread.java:745)

org.jivesoftware.smack.SmackException: java.security.KeyStoreException: Uninitialized keystore
  org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1033)
  org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:960)
  org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:975)
  java.lang.Thread.run(Thread.java:745)
java.security.KeyStoreException: Uninitialized keystore
  java.security.KeyStore.aliases(KeyStore.java:1233)
  sun.security.ssl.SunX509KeyManagerImpl.<init>(SunX509KeyManagerImpl.java:127)
  sun.security.ssl.KeyManagerFactoryImpl$SunX509.engineInit(KeyManagerFactoryImpl.java:70)
  javax.net.ssl.KeyManagerFactory.init(KeyManagerFactory.java:256)
  org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnection.java:739)
  org.jivesoftware.smack.tcp.XMPPTCPConnection.access$1000(XMPPTCPConnection.java:146)
  org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1026)
  org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:960)
  org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:975)
  java.lang.Thread.run(Thread.java:745)
2016-10-20 21:54:24 +02:00
Florian Schmaus 73fcbc6b27 Do not re-use the Socket after connect() failed
Fixes SMACK-724.
2016-06-21 21:23:30 +02:00
Florian Schmaus 30861fb7ce Add comment about dropping SM state on stream errors.
Related to SMACK-696.
2016-06-15 09:19:25 +02:00
Florian Schmaus 08c93da56a Delay notifyConnectionError in writer shutdown 2016-06-09 09:20:09 +02:00
Florian Schmaus 8deac592fb Finer logs in XMPPTCPConnection.shutdown() 2016-06-09 09:20:09 +02:00
Florian Schmaus 90f52fcc3b Suppress 'unused' warning in XMPPTCPConnection 2016-05-22 22:50:49 +02:00
Florian Schmaus b7211d5d67 Report illegal Stream Management state
Fixes SMACK-721.
2016-05-22 12:02:12 +02:00
Florian Schmaus 4c63cfafd7 Rework support for Proxy connections
in order to improve support for Tor connections.

This makes it possible to establish a connection to an .onion domain by
manually setting host and port in the ConnectionConfiguration and
configuring a Socks5Proxy pointing to a Tor node.

Fixes SMACK-720.
2016-05-10 18:57:04 +02:00
Florian Schmaus b94b2586e2 Smack 4.1.7
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQF8BAABCgBmBQJXD/2lXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w
 ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQxMzU3QjAxODY1QjI1MDNDMTg0NTNEMjA4
 Q0FDMkE5Njc4NTQ4RTM1AAoJEIysKpZ4VI41rggH/0DjBLpCfTSdjjKGFNChc+1V
 dW9PaPGFUiPuTt3T2NEa74jGYe4PsPpy5zDsJ8uYi2aq3LAiCQvfk+F5LXjRJFoa
 eftz0GtPvfP42oFg8wyDAebFtb0OtE7aJueSRkYGhA1+kzHBbJ9s6TxqDWcB0UWC
 puLh/DEWDFGX5njln+l10O7b10G0+bSrvece22eP0sQIv4hvZJoPQ5rOpCR1wibL
 ldp6wXI6C/b/oQS9MjHq9SV10S+5GykBqN/UzcFnwRVHLbasqnXeNFLGOnMtx0g9
 DmOolAYKGBN5m7m0rqEj9R+OyNgtefV8sCHE69iNAlpQhbmTqPd5rIhIXIII4U4=
 =yWKV
 -----END PGP SIGNATURE-----

Merge tag '4.1.7'

Smack 4.1.7
2016-04-14 22:30:34 +02:00
Tomas Nosek cf3024668e Fix XMPPTCPConnection.setEnabledSSL(Protocols|Ciphers)
The problem caused by opening input/ output stream before setting ssl
parameters to SSLSession and fixed by changing order of this operations.

Fixes SMACK-712.

Minor-Modifications-By: Florian Schmaus <flo@geekplace.eu>
2016-02-17 09:18:36 +01:00
Florian Schmaus 5c00172f6a Remove log statement
was added to diagnose an issue, should have never made it into master.
2016-02-10 14:54:32 +01:00
Florian Schmaus 529e1eb058 Fix 'test' dependencies
The previously used approach of

project(':smack-core').sourceSets.test.runtimeClasspath

caused the 'eclipse' target to produce duplicate classpath entries in
.classpath when run with Gradle >= 2.6. It also relied on Gradle
internals.

Instead we now use

project(path: ":smack-core", configuration: "testRuntime")
project(path: ":smack-core", configuration: "archives")

to be able to use test classes from other subprojects (usually
smack-core) in e.g. smack-extensions. The 'archives' configuration
includes the test jar.

See also https://discuss.gradle.org/t/11784

Thanks to Lari Hotari for helping with this issue.
2016-02-10 12:39:18 +01:00
Florian Schmaus e0cbb95b5d Check callbackHandler/keystorePath for null
before using it.
2016-01-23 14:16:38 +01:00
Florian Schmaus d5c7eb7349 Remove unnecessary code in XMPPTCPConnection 2016-01-23 14:16:37 +01:00
Florian Schmaus 085c3469e9 Fix XMPPTCPConnection.proceedTLSReceived()
The method was changed in c6594aec2f, but
this change causes issues if Smack is used on Android *without* a custom
SSLContext:

Caused by: java.security.KeyStoreException: java.security.NoSuchAlgorithmException: KeyStore jks implementation not found
 at java.security.KeyStore.getInstance(KeyStore.java:119)
 at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnection.java:697)

Caused by: java.security.NoSuchAlgorithmException: KeyManagerFactory SunX509 implementation not found
 at org.apache.harmony.security.fortress.Engine.notFound(Engine.java:177)
 at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:151)
 at javax.net.ssl.KeyManagerFactory.getInstance(KeyManagerFactory.java:77)
 at org.jivesoftware.smack.tcp.XMPPTCPConnection.proceedTLSReceived(XMPPTCPConnection.java:708)
2016-01-23 14:16:37 +01:00
Florian Schmaus 85e818cffb Smack 4.1.6
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQF8BAABCgBmBQJWo2DDXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w
 ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQxMzU3QjAxODY1QjI1MDNDMTg0NTNEMjA4
 Q0FDMkE5Njc4NTQ4RTM1AAoJEIysKpZ4VI41Q0AH/22s1WOI0mgFjQnuSRoZwtNQ
 WN7eudnKlnknmNrJwPcbW1EYO/kNj1SQnqv7ed2aVpyeFFOf1/CUIgq57K1hBjA0
 gTVtv0vK9pABZOmYY5UYURF6AZqKC2s5grHzOgIQbEhT0IOxc/Kz3/ubRxYwvxQl
 lKenkNw75NMViylC0wFQc673SUuwPKyS3PjFm44ASxhbHNIexqagsxNU3MICmCWr
 vGuyv2pGuVvVbILdqqoRGJhucHUs8HnYjA/H1lAlXH4FE0k3EXnjtztHaiLXQoxC
 I2MbunwlVWcE5099V85wcgBbtMWqgljyz+Yh8MmkPojZTVnWjYPUWybK4G8TREg=
 =1rYD
 -----END PGP SIGNATURE-----

Merge tag '4.1.6'

Smack 4.1.6
2016-01-23 13:27:16 +01:00
Florian Schmaus 57838f1ffe Enable Stream Management by default
Fixes SMACK-655.
2016-01-10 18:57:19 +01:00
Florian Schmaus 7845f21465 Only create the socket once
in XMPPTCPConnection.connectUsingConfiguration().
2016-01-10 18:34:54 +01:00